2020-04-30 08:07:43 -07:00
|
|
|
package simulation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
|
|
sdk "github.com/cosmos/cosmos-sdk/types"
|
2020-07-30 07:53:02 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/kv"
|
2020-04-30 08:07:43 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/capability/types"
|
|
|
|
)
|
|
|
|
|
|
|
|
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
|
|
|
|
// Value to the corresponding capaility type.
|
2020-07-30 07:53:02 -07:00
|
|
|
func NewDecodeStore(cdc codec.Marshaler) func(kvA, kvB kv.Pair) string {
|
|
|
|
return func(kvA, kvB kv.Pair) string {
|
2020-04-30 08:07:43 -07:00
|
|
|
switch {
|
|
|
|
case bytes.Equal(kvA.Key, types.KeyIndex):
|
|
|
|
idxA := sdk.BigEndianToUint64(kvA.Value)
|
|
|
|
idxB := sdk.BigEndianToUint64(kvB.Value)
|
|
|
|
return fmt.Sprintf("Index A: %d\nIndex B: %d\n", idxA, idxB)
|
|
|
|
|
|
|
|
case bytes.HasPrefix(kvA.Key, types.KeyPrefixIndexCapability):
|
|
|
|
var capOwnersA, capOwnersB types.CapabilityOwners
|
|
|
|
cdc.MustUnmarshalBinaryBare(kvA.Value, &capOwnersA)
|
|
|
|
cdc.MustUnmarshalBinaryBare(kvB.Value, &capOwnersB)
|
|
|
|
return fmt.Sprintf("CapabilityOwners A: %v\nCapabilityOwners B: %v\n", capOwnersA, capOwnersB)
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("invalid %s key prefix %X (%s)", types.ModuleName, kvA.Key, string(kvA.Key)))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|