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