-
Notifications
You must be signed in to change notification settings - Fork 44
/
decoder.go
77 lines (63 loc) · 2.95 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package simulation
import (
"bytes"
"fmt"
"github.com/cosmos/cosmos-sdk/codec"
"github.com/cosmos/cosmos-sdk/types/kv"
"github.com/desmos-labs/desmos/v7/x/subspaces/types"
)
// NewDecodeStore returns a new decoder that unmarshals the KVPair's Value
// to the corresponding subspaces 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, types.SubspaceIDKey):
var idA, idB uint64
idA = types.GetSubspaceIDFromBytes(kvA.Value)
idB = types.GetSubspaceIDFromBytes(kvB.Value)
return fmt.Sprintf("SubspaceIDA: %d\nSubspaceIDB: %d\n", idA, idB)
case bytes.HasPrefix(kvA.Key, types.SubspacePrefix):
var subspaceA, subspaceB types.Subspace
cdc.MustUnmarshal(kvA.Value, &subspaceA)
cdc.MustUnmarshal(kvB.Value, &subspaceB)
return fmt.Sprintf("SubspaceA: %s\nSubspaceB: %s\n", &subspaceA, &subspaceB)
case bytes.HasPrefix(kvA.Key, types.GroupIDPrefix):
var groupIDA, groupIDB uint32
groupIDA = types.GetGroupIDFromBytes(kvA.Value)
groupIDB = types.GetGroupIDFromBytes(kvB.Value)
return fmt.Sprintf("GroupIDA: %d\nGroupIDB: %d\n", groupIDA, groupIDB)
case bytes.HasPrefix(kvA.Key, types.GroupsPrefix):
var groupA, groupB types.UserGroup
cdc.MustUnmarshal(kvA.Value, &groupA)
cdc.MustUnmarshal(kvB.Value, &groupB)
return fmt.Sprintf("GroupA: %s\nGroupB: %s\n", &groupA, &groupB)
case bytes.HasPrefix(kvA.Key, types.GroupsMembersPrefix):
return fmt.Sprintf("GroupMemberKeyA: %s\nGroupMemberKeyB: %s\n", kvA.Key, kvB.Key)
case bytes.HasPrefix(kvA.Key, types.UserPermissionsStorePrefix):
var permissionA, permissionB types.UserPermission
cdc.MustUnmarshal(kvA.Value, &permissionA)
cdc.MustUnmarshal(kvB.Value, &permissionB)
return fmt.Sprintf("PermissionA: %s\nPermissionB: %s\n", &permissionA, &permissionB)
case bytes.HasPrefix(kvA.Key, types.SectionIDPrefix):
var sectionIDA, sectionIDB uint32
sectionIDA = types.GetSectionIDFromBytes(kvA.Value)
sectionIDB = types.GetSectionIDFromBytes(kvB.Value)
return fmt.Sprintf("SectionIDA: %d\nSectionIDB: %d\n", sectionIDA, sectionIDB)
case bytes.HasPrefix(kvA.Key, types.SectionsPrefix):
var sectionA, sectionB types.Section
cdc.MustUnmarshal(kvA.Value, §ionA)
cdc.MustUnmarshal(kvB.Value, §ionB)
return fmt.Sprintf("SectionA: %s\nSectionB: %s\n", §ionA, §ionB)
case bytes.HasPrefix(kvA.Key, types.UserAllowancePrefix) ||
bytes.HasPrefix(kvA.Key, types.GroupAllowancePrefix):
var grantA, grantB types.Grant
cdc.MustUnmarshal(kvA.Value, &grantA)
cdc.MustUnmarshal(kvB.Value, &grantB)
return fmt.Sprintf("GrantA: %s\nGrantB: %s\n", &grantA, &grantB)
case bytes.HasPrefix(kvA.Key, types.ExpiringAllowanceQueuePrefix):
return fmt.Sprintf("Expiring Allowance statusA: %X\nExpiring Allowance statusB: %X", kvA.Value, kvB.Value)
default:
panic(fmt.Sprintf("unexpected %s key %X (%s)", types.ModuleName, kvA.Key, kvA.Key))
}
}
}