2020-03-29 19:50:32 +00:00
|
|
|
package simulation
|
|
|
|
|
|
|
|
import (
|
2020-05-04 21:17:20 +00:00
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
|
2020-03-29 19:50:32 +00:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2020-04-30 14:23:41 +00:00
|
|
|
|
2020-04-27 18:19:05 +00:00
|
|
|
"github.com/tendermint/tendermint/libs/kv"
|
2020-05-04 21:17:20 +00:00
|
|
|
|
|
|
|
"github.com/kava-labs/kava/x/committee/types"
|
2020-03-29 19:50:32 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// DecodeStore unmarshals the KVPair's Value to the corresponding module type
|
2020-04-27 18:19:05 +00:00
|
|
|
func DecodeStore(cdc *codec.Codec, kvA, kvB kv.Pair) string {
|
2020-05-04 21:17:20 +00:00
|
|
|
switch {
|
|
|
|
case bytes.Equal(kvA.Key[:1], types.CommitteeKeyPrefix):
|
|
|
|
var committeeA, committeeB types.Committee
|
|
|
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &committeeA)
|
|
|
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &committeeB)
|
|
|
|
return fmt.Sprintf("%v\n%v", committeeA, committeeB)
|
|
|
|
|
|
|
|
case bytes.Equal(kvA.Key[:1], types.ProposalKeyPrefix):
|
|
|
|
var proposalA, proposalB types.Proposal
|
|
|
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &proposalA)
|
|
|
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &proposalB)
|
|
|
|
return fmt.Sprintf("%v\n%v", proposalA, proposalB)
|
|
|
|
|
|
|
|
case bytes.Equal(kvA.Key[:1], types.VoteKeyPrefix):
|
|
|
|
var voteA, voteB types.Vote
|
|
|
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvA.Value, &voteA)
|
|
|
|
cdc.MustUnmarshalBinaryLengthPrefixed(kvB.Value, &voteB)
|
|
|
|
return fmt.Sprintf("%v\n%v", voteA, voteB)
|
|
|
|
|
|
|
|
case bytes.Equal(kvA.Key[:1], types.NextProposalIDKey):
|
|
|
|
proposalIDA := types.Uint64FromBytes(kvA.Value)
|
|
|
|
proposalIDB := types.Uint64FromBytes(kvB.Value)
|
|
|
|
return fmt.Sprintf("%d\n%d", proposalIDA, proposalIDB)
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("invalid %s key prefix %X", types.ModuleName, kvA.Key[:1]))
|
|
|
|
}
|
2020-03-29 19:50:32 +00:00
|
|
|
}
|