Skip to content

Commit

Permalink
add invoice version to deal with edits
Browse files Browse the repository at this point in the history
  • Loading branch information
alexlyp committed Aug 12, 2020
1 parent c08e17b commit bd07a20
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 14 deletions.
13 changes: 7 additions & 6 deletions mdstream/mdstream.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,12 +536,13 @@ func DecodeDCCSupportOpposition(payload []byte) ([]DCCSupportOpposition, error)
// InvoiceProposalApprove represents an invoice status change and is stored
// in the metadata IDInvoiceProposalApprove in politeiad.
type InvoiceProposalApprove struct {
Version uint `json:"version"` // Version of the struct
PublicKey string `json:"publickey"` // Identity of the administrator
Signature string `json:"signature"` // Signature of the line item payload included
Token string `json:"token"` // Token of the invoice
Timestamp int64 `json:"timestamp"`
LineItems []byte `json:"lineitems"` // json payload of line items that are being approved
Version uint `json:"version"` // Version of the struct
PublicKey string `json:"publickey"` // Identity of the administrator
Signature string `json:"signature"` // Signature of the line item payload included
Token string `json:"token"` // Token of the invoice
Timestamp int64 `json:"timestamp"`
LineItems []byte `json:"lineitems"` // json payload of line items that are being approved
InvoiceVersion string `json:"invoiceversion"` // Version of the invoice that is being approved
}

// EncodeInvoiceProposalApprove encodes a InvoiceProposalApprove into a
Expand Down
9 changes: 7 additions & 2 deletions politeiawww/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -1078,11 +1078,16 @@ func convertRecordToDatabaseInvoice(p pd.Record) (*cmsdatabase.Invoice, error) {
}
var approvedProposals []string
for _, s := range ipa {
// Check to see if the approved invoice version doesn't match
// current invoice version. If so, the proposal owner needs to
// approve again.
if s.InvoiceVersion != r.Version {
continue
}
if approvedProposals == nil {
approvedProposals = make([]string, 0, 1048)
} else {
approvedProposals = append(approvedProposals, s.Token)
}
approvedProposals = append(approvedProposals, s.Token)
}
default:
// Log error but proceed
Expand Down
13 changes: 7 additions & 6 deletions politeiawww/invoices.go
Original file line number Diff line number Diff line change
Expand Up @@ -2162,12 +2162,13 @@ func (p *politeiawww) processProposalInvoiceApprove(poa cms.ProposalOwnerApprove

// Create the change record.
c := mdstream.InvoiceProposalApprove{
Version: mdstream.VersionInvoiceProposalApprove,
PublicKey: u.PublicKey(),
Timestamp: time.Now().Unix(),
Signature: poa.Signature,
Token: poa.Token,
LineItems: b,
Version: mdstream.VersionInvoiceProposalApprove,
PublicKey: u.PublicKey(),
Timestamp: time.Now().Unix(),
Signature: poa.Signature,
Token: poa.Token,
LineItems: b,
InvoiceVersion: invRec.Version,
}
blob, err := mdstream.EncodeInvoiceProposalApprove(c)
if err != nil {
Expand Down

0 comments on commit bd07a20

Please sign in to comment.