From 81735debe58322dd4e5515d3fc63d1ec7a74fd7c Mon Sep 17 00:00:00 2001 From: Aaron Craelius Date: Wed, 26 Feb 2020 20:47:45 -0500 Subject: [PATCH] Fix proposal marshaling, make Proposal extend ProposalBase --- simapp/codec/codec.go | 11 ++++++----- x/gov/types/proposal.go | 29 ++++++++++------------------- x/gov/types/types.proto | 27 +++++++++++++++++++-------- 3 files changed, 35 insertions(+), 32 deletions(-) diff --git a/simapp/codec/codec.go b/simapp/codec/codec.go index 0c9f910e6..284e934e9 100644 --- a/simapp/codec/codec.go +++ b/simapp/codec/codec.go @@ -161,16 +161,17 @@ func (c *Codec) MarshalProposal(p types.Proposal) ([]byte, error) { return c.Marshaler.MarshalBinaryBare(stdProposal) } -func (c *Codec) UnmarshalProposal(bz []byte) (types.Proposal, error) { +func (c *Codec) UnmarshalProposal(bz []byte, p *types.Proposal) error { stdProposal := &cosmos_sdk_x_v1.StdProposal{} if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, stdProposal); err != nil { - return nil, err + return err } - return types.Proposal{ - //Content: stdProposal.Content.GetContent(), + *p = types.Proposal{ + Content: stdProposal.Content.GetContent(), ProposalBase: stdProposal.ProposalBase, - }, nil + } + return nil } // ---------------------------------------------------------------------------- diff --git a/x/gov/types/proposal.go b/x/gov/types/proposal.go index 66658cd67..15d23ddf7 100644 --- a/x/gov/types/proposal.go +++ b/x/gov/types/proposal.go @@ -17,29 +17,21 @@ const DefaultStartingProposalID uint64 = 1 // on network changes. type Proposal struct { Content `json:"content" yaml:"content"` // Proposal content interface - - ProposalID uint64 `json:"id" yaml:"id"` // ID of the proposal - Status ProposalStatus `json:"proposal_status" yaml:"proposal_status"` // Status of the Proposal {Pending, Active, Passed, Rejected} - FinalTallyResult TallyResult `json:"final_tally_result" yaml:"final_tally_result"` // Result of Tallys - - SubmitTime time.Time `json:"submit_time" yaml:"submit_time"` // Time of the block where TxGovSubmitProposal was included - DepositEndTime time.Time `json:"deposit_end_time" yaml:"deposit_end_time"` // Time that the Proposal would expire if deposit amount isn't met - TotalDeposit sdk.Coins `json:"total_deposit" yaml:"total_deposit"` // Current deposit on this proposal. Initial value is set at InitialDeposit - - VotingStartTime time.Time `json:"voting_start_time" yaml:"voting_start_time"` // Time of the block where MinDeposit was reached. -1 if MinDeposit is not reached - VotingEndTime time.Time `json:"voting_end_time" yaml:"voting_end_time"` // Time that the VotingPeriod for this proposal will end and votes will be tallied + ProposalBase } // NewProposal creates a new Proposal instance func NewProposal(content Content, id uint64, submitTime, depositEndTime time.Time) Proposal { return Proposal{ - Content: content, - ProposalID: id, - Status: StatusDepositPeriod, - FinalTallyResult: EmptyTallyResult(), - TotalDeposit: sdk.NewCoins(), - SubmitTime: submitTime, - DepositEndTime: depositEndTime, + Content: content, + ProposalBase: ProposalBase{ + ProposalID: id, + Status: StatusDepositPeriod, + FinalTallyResult: EmptyTallyResult(), + TotalDeposit: sdk.NewCoins(), + SubmitTime: submitTime, + DepositEndTime: depositEndTime, + }, } } @@ -78,7 +70,6 @@ func (p Proposals) String() string { type ( // ProposalQueue defines a queue for proposal ids ProposalQueue []uint64 - ) // ProposalStatusFromString turns a string into a ProposalStatus diff --git a/x/gov/types/types.proto b/x/gov/types/types.proto index 0eaa5c60b..967b847d5 100644 --- a/x/gov/types/types.proto +++ b/x/gov/types/types.proto @@ -69,14 +69,25 @@ message ProposalBase { option (gogoproto.goproto_stringer) = true; option (gogoproto.face) = true; uint64 proposal_id = 1 [(gogoproto.customname) = "ProposalID" - ,(gogoproto.moretags) = "yaml:\"proposal_id\""]; - ProposalStatus status = 2; - TallyResult final_tally_result = 3 [(gogoproto.nullable) = false]; - google.protobuf.Timestamp submit_time = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; - google.protobuf.Timestamp deposit_end_time = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; - repeated cosmos_sdk.v1.Coin total_deposit = 6 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"]; - google.protobuf.Timestamp voting_start_time = 7 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; - google.protobuf.Timestamp voting_end_time = 8 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false]; + ,(gogoproto.moretags) = "yaml:\"id\""]; + ProposalStatus status = 2 [(gogoproto.moretags) = "yaml:\"proposal_status\""]; + TallyResult final_tally_result = 3 [(gogoproto.nullable) = false + ,(gogoproto.moretags) = "yaml:\"final_tally_result\""]; + google.protobuf.Timestamp submit_time = 4 [(gogoproto.stdtime) = true + ,(gogoproto.nullable) = false + ,(gogoproto.moretags) = "yaml:\"submit_time\""]; + google.protobuf.Timestamp deposit_end_time = 5 [(gogoproto.stdtime) = true + ,(gogoproto.nullable) = false + ,(gogoproto.moretags) = "yaml:\"deposit_end_time\""]; + repeated cosmos_sdk.v1.Coin total_deposit = 6 [(gogoproto.nullable) = false + ,(gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins" + ,(gogoproto.moretags) = "yaml:\"total_deposit\""]; + google.protobuf.Timestamp voting_start_time = 7 [(gogoproto.stdtime) = true + ,(gogoproto.nullable) = false + ,(gogoproto.moretags) = "yaml:\"voting_start_time\""]; + google.protobuf.Timestamp voting_end_time = 8 [(gogoproto.stdtime) = true + ,(gogoproto.nullable) = false + ,(gogoproto.moretags) = "yaml:\"voting_end_time\""]; } // ProposalStatus is a type alias that represents a proposal status as a byte