-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoder.go
33 lines (28 loc) · 1.38 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
package simulation
import (
"bytes"
"fmt"
"github.com/furyaxyz/fuxchain/libs/cosmos-sdk/codec"
"github.com/furyaxyz/fuxchain/libs/ibc-go/modules/core/03-connection/types"
host "github.com/furyaxyz/fuxchain/libs/ibc-go/modules/core/24-host"
"github.com/furyaxyz/fuxchain/libs/ibc-go/modules/core/common"
"github.com/furyaxyz/fuxchain/libs/tendermint/libs/kv"
)
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
// Value to the corresponding connection type.
func NewDecodeStore(cdc *codec.CodecProxy, kvA, kvB kv.Pair) (string, bool) {
switch {
case bytes.HasPrefix(kvA.Key, host.KeyClientStorePrefix) && bytes.HasSuffix(kvA.Key, []byte(host.KeyConnectionPrefix)):
var clientConnectionsA, clientConnectionsB types.ClientPaths
cdc.GetProtocMarshal().MustUnmarshalBinaryBare(kvA.Value, &clientConnectionsA)
cdc.GetProtocMarshal().MustUnmarshalBinaryBare(kvB.Value, &clientConnectionsB)
return fmt.Sprintf("ClientPaths A: %v\nClientPaths B: %v", clientConnectionsA, clientConnectionsB), true
case bytes.HasPrefix(kvA.Key, []byte(host.KeyConnectionPrefix)):
var connectionA, connectionB types.ConnectionEnd
connectionA = *common.MustUnmarshalConnection(cdc, kvA.Value)
connectionB = *common.MustUnmarshalConnection(cdc, kvB.Value)
return fmt.Sprintf("ConnectionEnd A: %v\nConnectionEnd B: %v", connectionA, connectionB), true
default:
return "", false
}
}