/
decoder.go
36 lines (30 loc) · 1.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
package simulation
import (
"bytes"
"fmt"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/crypto-org-chain/cronos/x/cronos/types"
"github.com/ethereum/go-ethereum/common"
)
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
// value to the corresponding cronos type.
func NewDecodeStore() func(kvA, kvB kv.Pair) string {
return func(kvA, kvB kv.Pair) string {
switch {
case bytes.Equal(kvA.Key[:1], types.KeyPrefixDenomToExternalContract):
contractA := common.BytesToAddress(kvA.Value).String()
contractB := common.BytesToAddress(kvB.Value).String()
return fmt.Sprintf("%v\n%v", contractA, contractB)
case bytes.Equal(kvA.Key[:1], types.KeyPrefixDenomToAutoContract):
contractA := common.BytesToAddress(kvA.Value).String()
contractB := common.BytesToAddress(kvB.Value).String()
return fmt.Sprintf("%v\n%v", contractA, contractB)
case bytes.Equal(kvA.Key[:1], types.KeyPrefixContractToDenom):
denomA := string(kvA.Value)
denomB := string(kvB.Value)
return fmt.Sprintf("%v\n%v", denomA, denomB)
default:
panic(fmt.Sprintf("invalid evm key prefix %X", kvA.Key[:1]))
}
}
}