0g-chain/x/committee/simulation/decoder.go

44 lines
1.4 KiB
Go
Raw Normal View History

package simulation
import (
"bytes"
"fmt"
"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"
"github.com/kava-labs/kava/x/committee/types"
)
// 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 {
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]))
}
}