github.com/Finschia/finschia-sdk@v0.48.1/x/capability/simulation/decoder.go (about) 1 package simulation 2 3 import ( 4 "bytes" 5 "fmt" 6 7 "github.com/Finschia/finschia-sdk/codec" 8 sdk "github.com/Finschia/finschia-sdk/types" 9 "github.com/Finschia/finschia-sdk/types/kv" 10 "github.com/Finschia/finschia-sdk/x/capability/types" 11 ) 12 13 // NewDecodeStore returns a decoder function closure that unmarshals the KVPair's 14 // Value to the corresponding capability 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, types.KeyIndex): 19 idxA := sdk.BigEndianToUint64(kvA.Value) 20 idxB := sdk.BigEndianToUint64(kvB.Value) 21 return fmt.Sprintf("Index A: %d\nIndex B: %d\n", idxA, idxB) 22 23 case bytes.HasPrefix(kvA.Key, types.KeyPrefixIndexCapability): 24 var capOwnersA, capOwnersB types.CapabilityOwners 25 cdc.MustUnmarshal(kvA.Value, &capOwnersA) 26 cdc.MustUnmarshal(kvB.Value, &capOwnersB) 27 return fmt.Sprintf("CapabilityOwners A: %v\nCapabilityOwners B: %v\n", capOwnersA, capOwnersB) 28 29 default: 30 panic(fmt.Sprintf("invalid %s key prefix %X (%s)", types.ModuleName, kvA.Key, string(kvA.Key))) 31 } 32 } 33 }