forked from cosmos/cosmos-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decoder.go
32 lines (29 loc) · 978 Bytes
/
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
package simulation
import (
"bytes"
"fmt"
"github.com/verzth/cosmos-sdk/codec"
"github.com/verzth/cosmos-sdk/types/kv"
"github.com/verzth/cosmos-sdk/x/authz"
"github.com/verzth/cosmos-sdk/x/authz/keeper"
)
// NewDecodeStore returns a decoder function closure that umarshals the KVPair's
// Value to the corresponding authz type.
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], keeper.GrantKey):
var grantA, grantB authz.Grant
cdc.MustUnmarshal(kvA.Value, &grantA)
cdc.MustUnmarshal(kvB.Value, &grantB)
return fmt.Sprintf("%v\n%v", grantA, grantB)
case bytes.Equal(kvA.Key[:1], keeper.GrantQueuePrefix):
var grantA, grantB authz.GrantQueueItem
cdc.MustUnmarshal(kvA.Value, &grantA)
cdc.MustUnmarshal(kvB.Value, &grantB)
return fmt.Sprintf("%v\n%v", grantA, grantB)
default:
panic(fmt.Sprintf("invalid authz key %X", kvA.Key))
}
}
}