2019-08-13 15:16:03 -07:00
|
|
|
package simulation
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"encoding/binary"
|
|
|
|
"fmt"
|
|
|
|
|
2020-05-19 13:17:29 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
2020-07-30 07:53:02 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/types/kv"
|
2019-08-13 15:16:03 -07:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
2021-12-13 10:48:44 -08:00
|
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types/v1beta1"
|
2019-08-13 15:16:03 -07:00
|
|
|
)
|
|
|
|
|
2020-04-21 14:33:56 -07:00
|
|
|
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
|
|
|
|
// Value to the corresponding gov type.
|
2021-04-29 03:46:22 -07:00
|
|
|
func NewDecodeStore(cdc codec.Codec) 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.ProposalsKeyPrefix):
|
2021-12-13 10:48:44 -08:00
|
|
|
var proposalA v1beta1.Proposal
|
2021-04-29 03:46:22 -07:00
|
|
|
err := cdc.Unmarshal(kvA.Value, &proposalA)
|
2020-04-21 14:33:56 -07:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2021-12-13 10:48:44 -08:00
|
|
|
var proposalB v1beta1.Proposal
|
2021-04-29 03:46:22 -07:00
|
|
|
err = cdc.Unmarshal(kvB.Value, &proposalB)
|
2020-04-21 14:33:56 -07:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
|
|
|
return fmt.Sprintf("%v\n%v", proposalA, proposalB)
|
|
|
|
|
|
|
|
case bytes.Equal(kvA.Key[:1], types.ActiveProposalQueuePrefix),
|
|
|
|
bytes.Equal(kvA.Key[:1], types.InactiveProposalQueuePrefix),
|
|
|
|
bytes.Equal(kvA.Key[:1], types.ProposalIDKey):
|
|
|
|
proposalIDA := binary.LittleEndian.Uint64(kvA.Value)
|
|
|
|
proposalIDB := binary.LittleEndian.Uint64(kvB.Value)
|
|
|
|
return fmt.Sprintf("proposalIDA: %d\nProposalIDB: %d", proposalIDA, proposalIDB)
|
|
|
|
|
|
|
|
case bytes.Equal(kvA.Key[:1], types.DepositsKeyPrefix):
|
2021-12-13 10:48:44 -08:00
|
|
|
var depositA, depositB v1beta1.Deposit
|
2021-04-29 03:46:22 -07:00
|
|
|
cdc.MustUnmarshal(kvA.Value, &depositA)
|
|
|
|
cdc.MustUnmarshal(kvB.Value, &depositB)
|
2020-04-21 14:33:56 -07:00
|
|
|
return fmt.Sprintf("%v\n%v", depositA, depositB)
|
|
|
|
|
|
|
|
case bytes.Equal(kvA.Key[:1], types.VotesKeyPrefix):
|
2021-12-13 10:48:44 -08:00
|
|
|
var voteA, voteB v1beta1.Vote
|
2021-04-29 03:46:22 -07:00
|
|
|
cdc.MustUnmarshal(kvA.Value, &voteA)
|
|
|
|
cdc.MustUnmarshal(kvB.Value, &voteB)
|
2020-04-21 14:33:56 -07:00
|
|
|
return fmt.Sprintf("%v\n%v", voteA, voteB)
|
|
|
|
|
|
|
|
default:
|
|
|
|
panic(fmt.Sprintf("invalid governance key prefix %X", kvA.Key[:1]))
|
|
|
|
}
|
2019-08-13 15:16:03 -07:00
|
|
|
}
|
|
|
|
}
|