-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
x/ibc: migrate 02-client to use proto encoded/decoded client states (#…
…6948) * begin migration * make client state a pointer * fix build * fixes from self review and rename cdctypes -> codectypes * add godoc
- Loading branch information
1 parent
392121e
commit 1a531cb
Showing
22 changed files
with
157 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package keeper | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/cosmos/cosmos-sdk/codec" | ||
"github.com/cosmos/cosmos-sdk/x/ibc/02-client/exported" | ||
) | ||
|
||
// MustUnmarshalClientState attempts to decode and return an ClientState object from | ||
// raw encoded bytes. It panics on error. | ||
func (k Keeper) MustUnmarshalClientState(bz []byte) exported.ClientState { | ||
clientState, err := k.UnmarshalClientState(bz) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to decode client state: %w", err)) | ||
} | ||
|
||
return clientState | ||
} | ||
|
||
// MustMarshalClientState attempts to encode an ClientState object and returns the | ||
// raw encoded bytes. It panics on error. | ||
func (k Keeper) MustMarshalClientState(clientState exported.ClientState) []byte { | ||
bz, err := k.MarshalClientState(clientState) | ||
if err != nil { | ||
panic(fmt.Errorf("failed to encode client state: %w", err)) | ||
} | ||
|
||
return bz | ||
} | ||
|
||
// MarshalClientState marshals an ClientState interface. If the given type implements | ||
// the Marshaler interface, it is treated as a Proto-defined message and | ||
// serialized that way. | ||
func (k Keeper) MarshalClientState(clientStateI exported.ClientState) ([]byte, error) { | ||
return codec.MarshalAny(k.cdc, clientStateI) | ||
} | ||
|
||
// UnmarshalClientState returns an ClientState interface from raw encoded clientState | ||
// bytes of a Proto-based ClientState type. An error is returned upon decoding | ||
// failure. | ||
func (k Keeper) UnmarshalClientState(bz []byte) (exported.ClientState, error) { | ||
var clientState exported.ClientState | ||
if err := codec.UnmarshalAny(k.cdc, &clientState, bz); err != nil { | ||
return nil, err | ||
} | ||
|
||
return clientState, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.