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)
|
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{}
|
stdProposal := &cosmos_sdk_x_v1.StdProposal{}
|
||||||
if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, stdProposal); err != nil {
|
if err := c.Marshaler.UnmarshalBinaryLengthPrefixed(bz, stdProposal); err != nil {
|
||||||
return nil, err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return types.Proposal{
|
*p = types.Proposal{
|
||||||
//Content: stdProposal.Content.GetContent(),
|
Content: stdProposal.Content.GetContent(),
|
||||||
ProposalBase: stdProposal.ProposalBase,
|
ProposalBase: stdProposal.ProposalBase,
|
||||||
}, nil
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
|
@ -17,29 +17,21 @@ const DefaultStartingProposalID uint64 = 1
|
||||||
// on network changes.
|
// on network changes.
|
||||||
type Proposal struct {
|
type Proposal struct {
|
||||||
Content `json:"content" yaml:"content"` // Proposal content interface
|
Content `json:"content" yaml:"content"` // Proposal content interface
|
||||||
|
ProposalBase
|
||||||
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
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProposal creates a new Proposal instance
|
// NewProposal creates a new Proposal instance
|
||||||
func NewProposal(content Content, id uint64, submitTime, depositEndTime time.Time) Proposal {
|
func NewProposal(content Content, id uint64, submitTime, depositEndTime time.Time) Proposal {
|
||||||
return Proposal{
|
return Proposal{
|
||||||
Content: content,
|
Content: content,
|
||||||
|
ProposalBase: ProposalBase{
|
||||||
ProposalID: id,
|
ProposalID: id,
|
||||||
Status: StatusDepositPeriod,
|
Status: StatusDepositPeriod,
|
||||||
FinalTallyResult: EmptyTallyResult(),
|
FinalTallyResult: EmptyTallyResult(),
|
||||||
TotalDeposit: sdk.NewCoins(),
|
TotalDeposit: sdk.NewCoins(),
|
||||||
SubmitTime: submitTime,
|
SubmitTime: submitTime,
|
||||||
DepositEndTime: depositEndTime,
|
DepositEndTime: depositEndTime,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -78,7 +70,6 @@ func (p Proposals) String() string {
|
||||||
type (
|
type (
|
||||||
// ProposalQueue defines a queue for proposal ids
|
// ProposalQueue defines a queue for proposal ids
|
||||||
ProposalQueue []uint64
|
ProposalQueue []uint64
|
||||||
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// ProposalStatusFromString turns a string into a ProposalStatus
|
// ProposalStatusFromString turns a string into a ProposalStatus
|
||||||
|
|
|
@ -69,14 +69,25 @@ message ProposalBase {
|
||||||
option (gogoproto.goproto_stringer) = true;
|
option (gogoproto.goproto_stringer) = true;
|
||||||
option (gogoproto.face) = true;
|
option (gogoproto.face) = true;
|
||||||
uint64 proposal_id = 1 [(gogoproto.customname) = "ProposalID"
|
uint64 proposal_id = 1 [(gogoproto.customname) = "ProposalID"
|
||||||
,(gogoproto.moretags) = "yaml:\"proposal_id\""];
|
,(gogoproto.moretags) = "yaml:\"id\""];
|
||||||
ProposalStatus status = 2;
|
ProposalStatus status = 2 [(gogoproto.moretags) = "yaml:\"proposal_status\""];
|
||||||
TallyResult final_tally_result = 3 [(gogoproto.nullable) = false];
|
TallyResult final_tally_result = 3 [(gogoproto.nullable) = false
|
||||||
google.protobuf.Timestamp submit_time = 4 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
|
,(gogoproto.moretags) = "yaml:\"final_tally_result\""];
|
||||||
google.protobuf.Timestamp deposit_end_time = 5 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
|
google.protobuf.Timestamp submit_time = 4 [(gogoproto.stdtime) = true
|
||||||
repeated cosmos_sdk.v1.Coin total_deposit = 6 [(gogoproto.nullable) = false, (gogoproto.castrepeated) = "github.com/cosmos/cosmos-sdk/types.Coins"];
|
,(gogoproto.nullable) = false
|
||||||
google.protobuf.Timestamp voting_start_time = 7 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
|
,(gogoproto.moretags) = "yaml:\"submit_time\""];
|
||||||
google.protobuf.Timestamp voting_end_time = 8 [(gogoproto.stdtime) = true, (gogoproto.nullable) = false];
|
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
|
// ProposalStatus is a type alias that represents a proposal status as a byte
|
||||||
|
|
Loading…
Reference in New Issue