/
decoder.go
37 lines (30 loc) · 1.2 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
package simulation
import (
"bytes"
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/desmos-labs/desmos/v6/x/tokenfactory/types"
)
// NewDecodeStore returns a new decoder that unmarshals the KVPair's Value
// to the corresponding tokenfactory 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, []byte(types.DenomsPrefixKey)):
var metadataA, metadataB types.DenomAuthorityMetadata
cdc.MustUnmarshal(kvA.Value, &metadataA)
cdc.MustUnmarshal(kvB.Value, &metadataB)
return fmt.Sprintf("Authority MetadataA: %s\nAuthority MetadataB: %s\n", metadataA, metadataB)
case bytes.HasPrefix(kvA.Key, []byte(types.CreatorPrefixKey)):
return fmt.Sprintf("DenomA: %s\nDenomB: %s\n", kvA.Value, kvB.Value)
case bytes.HasPrefix(kvA.Key, []byte(types.ParamsPrefixKey)):
var paramA, paramB types.Params
cdc.MustUnmarshal(kvA.Value, ¶mA)
cdc.MustUnmarshal(kvA.Value, ¶mB)
return fmt.Sprintf("ParamsA: %s\nParamsB: %s\n", paramA, paramB)
default:
panic(fmt.Sprintf("unexpected %s key %X (%s)", types.ModuleName, kvA.Key, kvA.Key))
}
}
}