* Update x/gov to use Any * Fixes * Remove MsgSubmitProposalLegacy * Update CHANGELOG.md * Add RegisterInterfaces for x/distribution, x/params, & x/upgrade * Fix query JSON issue * Fix gov tests * Revert custom Any Equals * Re-remove types * Rename receivers * Fix imports in gov * Sort imports * Make amino JSON signing work with Any * Run proto-gen * Create full amino wrapper * Fix errors * Fixes * Fix tests * Test fixes * Fix tests * Linting * Update ADR 019 and CHANGELOG * Updated ADR 019 * Extract Marshal/UnmarshalProposal * fix error * lint * linting * linting * Update client/keys/parse.go Co-authored-by: Marko <marbar3778@yahoo.com> * linting * Update docs/architecture/adr-019-protobuf-state-encoding.md Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * Update docs/architecture/adr-019-protobuf-state-encoding.md Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com> * Address review feedback * Add godocs * Fix errors * fix errors * revert file * Address review feedback * Address review feedback * Stacktrace debug flag * Fix tests * Address review feedback Co-authored-by: sahith-narahari <sahithnarahari@gmail.com> Co-authored-by: Marko <marbar3778@yahoo.com> Co-authored-by: Alexander Bezobchuk <alexanderbez@users.noreply.github.com>
56 lines
1.7 KiB
Go
56 lines
1.7 KiB
Go
package simulation
|
|
|
|
import (
|
|
"bytes"
|
|
"encoding/binary"
|
|
"fmt"
|
|
|
|
tmkv "github.com/tendermint/tendermint/libs/kv"
|
|
|
|
"github.com/cosmos/cosmos-sdk/codec"
|
|
"github.com/cosmos/cosmos-sdk/x/gov/types"
|
|
)
|
|
|
|
// NewDecodeStore returns a decoder function closure that unmarshals the KVPair's
|
|
// Value to the corresponding gov type.
|
|
func NewDecodeStore(cdc codec.Marshaler) func(kvA, kvB tmkv.Pair) string {
|
|
return func(kvA, kvB tmkv.Pair) string {
|
|
switch {
|
|
case bytes.Equal(kvA.Key[:1], types.ProposalsKeyPrefix):
|
|
var proposalA types.Proposal
|
|
err := cdc.UnmarshalBinaryBare(kvA.Value, &proposalA)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
var proposalB types.Proposal
|
|
err = cdc.UnmarshalBinaryBare(kvA.Value, &proposalB)
|
|
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):
|
|
var depositA, depositB types.Deposit
|
|
cdc.MustUnmarshalBinaryBare(kvA.Value, &depositA)
|
|
cdc.MustUnmarshalBinaryBare(kvB.Value, &depositB)
|
|
return fmt.Sprintf("%v\n%v", depositA, depositB)
|
|
|
|
case bytes.Equal(kvA.Key[:1], types.VotesKeyPrefix):
|
|
var voteA, voteB types.Vote
|
|
cdc.MustUnmarshalBinaryBare(kvA.Value, &voteA)
|
|
cdc.MustUnmarshalBinaryBare(kvB.Value, &voteB)
|
|
return fmt.Sprintf("%v\n%v", voteA, voteB)
|
|
|
|
default:
|
|
panic(fmt.Sprintf("invalid governance key prefix %X", kvA.Key[:1]))
|
|
}
|
|
}
|
|
}
|