2020-03-30 15:02:43 +00:00
|
|
|
package simulation
|
|
|
|
|
|
|
|
import (
|
2020-04-01 15:27:38 +00:00
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
|
2020-04-23 16:35:58 +00:00
|
|
|
tmbytes "github.com/tendermint/tendermint/libs/bytes"
|
|
|
|
"github.com/tendermint/tendermint/libs/kv"
|
|
|
|
|
2020-03-30 15:02:43 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2020-04-01 15:27:38 +00:00
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/bep3/types"
|
2020-03-30 15:02:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// DecodeStore unmarshals the KVPair's Value to the module's corresponding type
|
2020-04-23 16:35:58 +00:00
|
|
|
func DecodeStore(cdc *codec.Codec, kvA, kvB kv.Pair) string {
|
2020-04-01 15:27:38 +00:00
|
|
|
switch {
|
|
|
|
case bytes.Equal(kvA.Key[:1], types.AtomicSwapKeyPrefix):
|
2020-04-06 22:45:46 +00:00
|
|
|
var swapA, swapB types.AtomicSwap
|
2020-04-01 15:27:38 +00:00
|
|
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &swapA)
|
|
|
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &swapB)
|
|
|
|
return fmt.Sprintf("%v\n%v", swapA, swapB)
|
|
|
|
|
|
|
|
case bytes.Equal(kvA.Key[:1], types.AtomicSwapByBlockPrefix),
|
|
|
|
bytes.Equal(kvA.Key[:1], types.AtomicSwapLongtermStoragePrefix):
|
2020-04-23 16:35:58 +00:00
|
|
|
var bytesA tmbytes.HexBytes = kvA.Value
|
|
|
|
var bytesB tmbytes.HexBytes = kvA.Value
|
2020-04-01 15:27:38 +00:00
|
|
|
return fmt.Sprintf("%s\n%s", bytesA.String(), bytesB.String())
|
2020-08-17 15:06:59 +00:00
|
|
|
case bytes.Equal(kvA.Key[:1], types.AssetSupplyPrefix):
|
|
|
|
var supplyA, supplyB types.AssetSupply
|
|
|
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &supplyA)
|
|
|
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &supplyB)
|
|
|
|
return fmt.Sprintf("%s\n%s", supplyA, supplyB)
|
2020-04-01 15:27:38 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1]))
|
|
|
|
}
|
2020-03-30 15:02:43 +00:00
|
|
|
}
|