Fix proposal marshaling, make Proposal extend ProposalBase
This commit is contained in:
parent
333066efa8
commit
81735debe5
|
@ -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
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue