github.com/cosmos/cosmos-sdk@v0.50.10/x/authz/simulation/decoder.go (about) 1 package simulation 2 3 import ( 4 "bytes" 5 "fmt" 6 7 "github.com/cosmos/cosmos-sdk/codec" 8 "github.com/cosmos/cosmos-sdk/types/kv" 9 "github.com/cosmos/cosmos-sdk/x/authz" 10 "github.com/cosmos/cosmos-sdk/x/authz/keeper" 11 ) 12 13 // NewDecodeStore returns a decoder function closure that umarshals the KVPair's 14 // Value to the corresponding authz type. 15 func NewDecodeStore(cdc codec.Codec) func(kvA, kvB kv.Pair) string { 16 return func(kvA, kvB kv.Pair) string { 17 switch { 18 case bytes.Equal(kvA.Key[:1], keeper.GrantKey): 19 var grantA, grantB authz.Grant 20 cdc.MustUnmarshal(kvA.Value, &grantA) 21 cdc.MustUnmarshal(kvB.Value, &grantB) 22 return fmt.Sprintf("%v\n%v", grantA, grantB) 23 case bytes.Equal(kvA.Key[:1], keeper.GrantQueuePrefix): 24 var grantA, grantB authz.GrantQueueItem 25 cdc.MustUnmarshal(kvA.Value, &grantA) 26 cdc.MustUnmarshal(kvB.Value, &grantB) 27 return fmt.Sprintf("%v\n%v", grantA, grantB) 28 default: 29 panic(fmt.Sprintf("invalid authz key %X", kvA.Key)) 30 } 31 } 32 }