/
decoder.go
58 lines (47 loc) · 1.66 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/types/kv"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/shentufoundation/shentu/v2/x/cvm/types"
)
// DecodeStore unmarshals the KVPair's value to the corresponding type of cvm module.
func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string {
return func(kvA, kvB kv.Pair) string {
switch {
case bytes.Equal(kvA.Key[:1], types.StorageStoreKeyPrefix):
var valueA, valueB []byte
valueA = kvA.Value
valueB = kvB.Value
return fmt.Sprintf("%b\n%b", valueA, valueB)
case bytes.Equal(kvA.Key[:1], types.BlockHashStoreKeyPrefix):
var hashA, hashB []byte
hashA = kvA.Value
hashB = kvB.Value
return fmt.Sprintf("%b\n%b", hashA, hashB)
case bytes.Equal(kvA.Key[:1], types.CodeStoreKeyPrefix):
var evmCodeA, evmCodeB []byte
evmCodeA = kvA.Value
evmCodeB = kvB.Value
return fmt.Sprintf("%b\n%b", evmCodeA, evmCodeB)
case bytes.Equal(kvA.Key[:1], types.AbiStoreKeyPrefix):
var abiA, abiB []byte
abiA = kvA.Value
abiB = kvB.Value
return fmt.Sprintf("%b\n%b", abiA, abiB)
case bytes.Equal(kvA.Key[:1], types.MetaHashStoreKeyPrefix):
var metadataA, metadataB string
metadataA = string(kvA.Value)
metadataB = string(kvB.Value)
return fmt.Sprintf("%s\n%s", metadataA, metadataB)
case bytes.Equal(kvA.Key[:1], types.AddressMetaHashStoreKeyPrefix):
var metadataA, metadataB types.ContractMetas
cdc.MustUnmarshal(kvA.Value, &metadataA)
cdc.MustUnmarshal(kvB.Value, &metadataB)
return fmt.Sprintf("%v\n%v", metadataA, metadataB)
default:
panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1]))
}
}
}