/
decoder.go
44 lines (39 loc) · 1.77 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
package simulation
import (
"bytes"
"encoding/binary"
"fmt"
tmkv "github.com/tendermint/tendermint/libs/kv"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/terra-project/core/x/wasm/internal/types"
)
// DecodeStore unmarshals the KVPair's Value to the corresponding distribution type
func DecodeStore(cdc *codec.Codec, kvA, kvB tmkv.Pair) string {
switch {
case bytes.Equal(kvA.Key[:1], types.LastCodeIDKey):
lastCodeIDA := binary.LittleEndian.Uint64(kvA.Value)
lastCodeIDB := binary.LittleEndian.Uint64(kvB.Value)
return fmt.Sprintf("lastCodeIDA: %d\nlastCodeIDB: %d", lastCodeIDA, lastCodeIDB)
case bytes.Equal(kvA.Key[:1], types.LastInstanceIDKey):
lastInstanceIDKeyA := binary.LittleEndian.Uint64(kvA.Value)
lastInstanceIDKeyB := binary.LittleEndian.Uint64(kvB.Value)
return fmt.Sprintf("lastInstanceIDA: %d\nlastInstanceIDB: %d", lastInstanceIDKeyA, lastInstanceIDKeyB)
case bytes.Equal(kvA.Key[:1], types.CodeKey):
var codeInfoA, codeInfoB types.CodeInfo
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &codeInfoA)
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &codeInfoB)
return fmt.Sprintf("%v\n%v", codeInfoA, codeInfoB)
case bytes.Equal(kvA.Key[:1], types.ContractInfoKey):
var contractInfoA, contractInfoB types.ContractInfo
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &contractInfoA)
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &contractInfoB)
return fmt.Sprintf("%v\n%v", contractInfoA, contractInfoB)
case bytes.Equal(kvA.Key[:1], types.ContractStoreKey):
var rawDataA, rawDataB []byte
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &rawDataA)
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &rawDataB)
return fmt.Sprintf("%v\n%v", rawDataA, rawDataB)
default:
panic(fmt.Sprintf("invalid wasm key prefix %X", kvA.Key[:1]))
}
}