2019-08-13 15:16:03 -07:00
|
|
|
package simulation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
|
2020-07-30 07:53:02 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/kv"
|
2020-05-12 10:35:05 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/bank/exported"
|
2020-04-20 08:22:12 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/bank/types"
|
2019-08-13 15:16:03 -07:00
|
|
|
)
|
|
|
|
|
2020-08-21 01:52:46 -07:00
|
|
|
// SupplyUnmarshaler defines the expected encoding store functions.
|
|
|
|
type SupplyUnmarshaler interface {
|
2020-05-12 10:35:05 -07:00
|
|
|
UnmarshalSupply([]byte) (exported.SupplyI, error)
|
|
|
|
}
|
|
|
|
|
2020-04-21 14:33:56 -07:00
|
|
|
// NewDecodeStore returns a function closure that unmarshals the KVPair's values
|
|
|
|
// to the corresponding types.
|
2020-08-21 01:52:46 -07:00
|
|
|
func NewDecodeStore(cdc SupplyUnmarshaler) func(kvA, kvB kv.Pair) string {
|
2020-07-30 07:53:02 -07:00
|
|
|
return func(kvA, kvB kv.Pair) string {
|
2020-04-21 14:33:56 -07:00
|
|
|
switch {
|
|
|
|
case bytes.Equal(kvA.Key[:1], types.SupplyKey):
|
|
|
|
supplyA, err := cdc.UnmarshalSupply(kvA.Value)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2020-02-18 04:50:13 -08:00
|
|
|
|
2020-04-21 14:33:56 -07:00
|
|
|
supplyB, err := cdc.UnmarshalSupply(kvB.Value)
|
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fmt.Sprintf("%v\n%v", supplyA, supplyB)
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("unexpected %s key %X (%s)", types.ModuleName, kvA.Key, kvA.Key))
|
|
|
|
}
|
2019-08-13 15:16:03 -07:00
|
|
|
}
|
|
|
|
}
|