github.com/fibonacci-chain/fbc@v0.0.0-20231124064014-c7636198c1e9/libs/ibc-go/modules/core/02-client/simulation/decoder.go (about) 1 package simulation 2 3 import ( 4 "bytes" 5 "fmt" 6 7 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/02-client/keeper" 8 host "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/24-host" 9 "github.com/fibonacci-chain/fbc/libs/ibc-go/modules/core/exported" 10 "github.com/fibonacci-chain/fbc/libs/tendermint/libs/kv" 11 ) 12 13 var _ ClientUnmarshaler = (*keeper.Keeper)(nil) 14 15 // ClientUnmarshaler defines an interface for unmarshaling ICS02 interfaces. 16 type ClientUnmarshaler interface { 17 MustUnmarshalClientState([]byte) exported.ClientState 18 MustUnmarshalConsensusState([]byte) exported.ConsensusState 19 } 20 21 // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's 22 // Value to the corresponding client type. 23 func NewDecodeStore(cdc ClientUnmarshaler, kvA, kvB kv.Pair) (string, bool) { 24 switch { 25 case bytes.HasPrefix(kvA.Key, host.KeyClientStorePrefix) && bytes.HasSuffix(kvA.Key, []byte(host.KeyClientState)): 26 clientStateA := cdc.MustUnmarshalClientState(kvA.Value) 27 clientStateB := cdc.MustUnmarshalClientState(kvB.Value) 28 return fmt.Sprintf("ClientState A: %v\nClientState B: %v", clientStateA, clientStateB), true 29 30 case bytes.HasPrefix(kvA.Key, host.KeyClientStorePrefix) && bytes.Contains(kvA.Key, []byte(host.KeyConsensusStatePrefix)): 31 consensusStateA := cdc.MustUnmarshalConsensusState(kvA.Value) 32 consensusStateB := cdc.MustUnmarshalConsensusState(kvB.Value) 33 return fmt.Sprintf("ConsensusState A: %v\nConsensusState B: %v", consensusStateA, consensusStateB), true 34 35 default: 36 return "", false 37 } 38 }