Skip to content

Commit

Permalink
feat: TX donation attribute (#642)
Browse files Browse the repository at this point in the history
This adds a method to retrieve the donation attribute from a TX

Fixes #627
  • Loading branch information
agaffney authored May 20, 2024
1 parent e4d1ad8 commit 4be9f59
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ This is not an exhaustive list of existing and planned features, but it covers t
- [X] Voting procedures
- [X] Proposal procedures
- [X] Current treasury value
- [ ] Donation
- [X] Donation
- [ ] Testing
- [X] Test framework for mocking Ouroboros conversations
- [ ] CBOR deserialization and serialization
Expand Down
4 changes: 4 additions & 0 deletions ledger/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,10 @@ func (t AllegraTransaction) CurrentTreasuryValue() int64 {
return t.Body.CurrentTreasuryValue()
}

func (t AllegraTransaction) Donation() uint64 {
return t.Body.Donation()
}

func (t AllegraTransaction) Metadata() *cbor.LazyValue {
return t.TxMetadata
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,10 @@ func (t AlonzoTransaction) CurrentTreasuryValue() int64 {
return t.Body.CurrentTreasuryValue()
}

func (t AlonzoTransaction) Donation() uint64 {
return t.Body.Donation()
}

func (t AlonzoTransaction) Metadata() *cbor.LazyValue {
return t.TxMetadata
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,6 +496,10 @@ func (t BabbageTransaction) CurrentTreasuryValue() int64 {
return t.Body.CurrentTreasuryValue()
}

func (t BabbageTransaction) Donation() uint64 {
return t.Body.Donation()
}

func (t BabbageTransaction) Metadata() *cbor.LazyValue {
return t.TxMetadata
}
Expand Down
5 changes: 5 additions & 0 deletions ledger/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,11 @@ func (t *ByronTransaction) CurrentTreasuryValue() int64 {
return 0
}

func (t *ByronTransaction) Donation() uint64 {
// No donation in Byron
return 0
}

func (t *ByronTransaction) Metadata() *cbor.LazyValue {
return t.Attributes
}
Expand Down
10 changes: 9 additions & 1 deletion ledger/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ type ConwayTransactionBody struct {
TxVotingProcedures VotingProcedures `cbor:"19,keyasint,omitempty"`
TxProposalProcedures []ProposalProcedure `cbor:"20,keyasint,omitempty"`
TxCurrentTreasuryValue int64 `cbor:"21,keyasint,omitempty"`
Donation uint64 `cbor:"22,keyasint,omitempty"`
TxDonation uint64 `cbor:"22,keyasint,omitempty"`
}

func (b *ConwayTransactionBody) UnmarshalCBOR(cborData []byte) error {
Expand All @@ -143,6 +143,10 @@ func (b *ConwayTransactionBody) CurrentTreasuryValue() int64 {
return b.TxCurrentTreasuryValue
}

func (b *ConwayTransactionBody) Donation() uint64 {
return b.TxDonation
}

// VotingProcedures is a convenience type to avoid needing to duplicate the full type definition everywhere
type VotingProcedures map[*Voter]map[*GovActionId]VotingProcedure

Expand Down Expand Up @@ -405,6 +409,10 @@ func (t ConwayTransaction) CurrentTreasuryValue() int64 {
return t.Body.CurrentTreasuryValue()
}

func (t ConwayTransaction) Donation() uint64 {
return t.Body.Donation()
}

func (t ConwayTransaction) Metadata() *cbor.LazyValue {
return t.TxMetadata
}
Expand Down
4 changes: 4 additions & 0 deletions ledger/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,10 @@ func (t MaryTransaction) CurrentTreasuryValue() int64 {
return t.Body.CurrentTreasuryValue()
}

func (t MaryTransaction) Donation() uint64 {
return t.Body.Donation()
}

func (t MaryTransaction) Metadata() *cbor.LazyValue {
return t.TxMetadata
}
Expand Down
9 changes: 9 additions & 0 deletions ledger/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,11 @@ func (b *ShelleyTransactionBody) CurrentTreasuryValue() int64 {
return 0
}

func (b *ShelleyTransactionBody) Donation() uint64 {
// No donation in Shelley
return 0
}

func (b *ShelleyTransactionBody) Utxorpc() *utxorpc.Tx {
var txi []*utxorpc.TxInput
var txo []*utxorpc.TxOutput
Expand Down Expand Up @@ -473,6 +478,10 @@ func (t ShelleyTransaction) CurrentTreasuryValue() int64 {
return t.Body.CurrentTreasuryValue()
}

func (t ShelleyTransaction) Donation() uint64 {
return t.Body.Donation()
}

func (t ShelleyTransaction) Metadata() *cbor.LazyValue {
return t.TxMetadata
}
Expand Down
1 change: 1 addition & 0 deletions ledger/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ type TransactionBody interface {
VotingProcedures() VotingProcedures
ProposalProcedures() []ProposalProcedure
CurrentTreasuryValue() int64
Donation() uint64
Utxorpc() *utxorpc.Tx
}

Expand Down

0 comments on commit 4be9f59

Please sign in to comment.