-
Notifications
You must be signed in to change notification settings - Fork 38
/
decoder.go
52 lines (41 loc) · 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package simulation
import (
"bytes"
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/kv"
protobuftypes "github.com/gogo/protobuf/types"
"github.com/sentinel-official/hub/x/session/types"
)
func NewStoreDecoder(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string {
return func(kvA, kvB kv.Pair) string {
switch {
case bytes.Equal(kvA.Key[:1], types.CountKey):
var countA, countB protobuftypes.UInt64Value
cdc.MustUnmarshalBinaryBare(kvA.Value, &countA)
cdc.MustUnmarshalBinaryBare(kvB.Value, &countB)
return fmt.Sprintf("%v\n%v", &countA, &countB)
case bytes.Equal(kvA.Key[:1], types.SessionKeyPrefix):
var sessionA, sessionB types.Session
cdc.MustUnmarshalBinaryBare(kvA.Value, &sessionA)
cdc.MustUnmarshalBinaryBare(kvB.Value, &sessionB)
return fmt.Sprintf("%v\n%v", &sessionA, &sessionB)
case bytes.Equal(kvA.Key[:1], types.InactiveSessionForAddressKeyPrefix):
var inactiveSessionForAddressA, inactiveSessionForAddressB protobuftypes.BoolValue
cdc.MustUnmarshalBinaryBare(kvA.Value, &inactiveSessionForAddressA)
cdc.MustUnmarshalBinaryBare(kvB.Value, &inactiveSessionForAddressB)
return fmt.Sprintf("%v\n%v", &inactiveSessionForAddressA, &inactiveSessionForAddressB)
case bytes.Equal(kvA.Key[:1], types.ActiveSessionForAddressKeyPrefix):
var activeSessionForAddressA, activeSessionForAddressB protobuftypes.BoolValue
cdc.MustUnmarshalBinaryBare(kvA.Value, &activeSessionForAddressA)
cdc.MustUnmarshalBinaryBare(kvB.Value, &activeSessionForAddressB)
return fmt.Sprintf("%v\n%v", &activeSessionForAddressA, &activeSessionForAddressB)
case bytes.Equal(kvA.Key[:1], types.InactiveSessionAtKeyPrefix):
var inactiveSessionAtA, inactiveSessionAtB protobuftypes.BoolValue
cdc.MustUnmarshalBinaryBare(kvA.Value, &inactiveSessionAtA)
cdc.MustUnmarshalBinaryBare(kvB.Value, &inactiveSessionAtB)
return fmt.Sprintf("%v\n%v", &inactiveSessionAtA, &inactiveSessionAtB)
}
panic(fmt.Sprintf("invalid key prefix %X", kvA.Key[:1]))
}
}