-
Notifications
You must be signed in to change notification settings - Fork 1
/
decoder.go
58 lines (48 loc) · 2.13 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package simulation
import (
"bytes"
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/gridiron-zone/huddle/x/profiles/types"
)
// NewDecodeStore returns a new decoder that unmarshals the KVPair's Value
// to the corresponding relationships type
func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string {
return func(kvA, kvB kv.Pair) string {
switch {
case bytes.HasPrefix(kvA.Key, types.DTagPrefix):
addressA := sdk.AccAddress(kvA.Value).String()
addressB := sdk.AccAddress(kvB.Value).String()
return fmt.Sprintf("DTagAddressA: %s\nDTagAddressB: %s\n", addressA, addressB)
case bytes.HasPrefix(kvA.Key, types.DTagTransferRequestPrefix):
var requestA, requestB types.DTagTransferRequest
cdc.MustUnmarshal(kvA.Value, &requestA)
cdc.MustUnmarshal(kvB.Value, &requestB)
return fmt.Sprintf("RequestA: %s\nRequestB: %s\n", requestA, requestB)
case bytes.HasPrefix(kvA.Key, types.ChainLinksPrefix):
var chainLinkA, chainLinkB types.ChainLink
cdc.MustUnmarshal(kvA.Value, &chainLinkA)
cdc.MustUnmarshal(kvB.Value, &chainLinkB)
return fmt.Sprintf("ChainLinkA: %s\nChainLinkB: %s\n", chainLinkA, chainLinkB)
case bytes.HasPrefix(kvA.Key, types.ApplicationLinkPrefix):
var applicationLinkA, applicationLinkB types.ApplicationLink
cdc.MustUnmarshal(kvA.Value, &applicationLinkA)
cdc.MustUnmarshal(kvB.Value, &applicationLinkB)
return fmt.Sprintf("ApplicationLinkA: %s\nApplicationLinkB: %s\n", &applicationLinkA, &applicationLinkB)
case bytes.HasPrefix(kvA.Key, types.ExpiringAppLinkTimePrefix):
var clientIDA, clientIDB string
clientIDA = string(kvA.Value)
clientIDB = string(kvB.Value)
return fmt.Sprintf("ExpiringClientIDA: %s\nExpiringClientIDB: %s\n",
clientIDA, clientIDB)
case bytes.HasPrefix(kvA.Key, types.DefaultExternalAddressPrefix):
addressA := string(kvA.Value)
addressB := string(kvB.Value)
return fmt.Sprintf("ExternalAddressA: %s\nExternalAddressB: %s\n", addressA, addressB)
default:
panic(fmt.Sprintf("unexpected %s key %X (%s)", types.ModuleName, kvA.Key, kvA.Key))
}
}
}