Skip to content

Commit 4be9f59

Browse files
authored
feat: TX donation attribute (#642)
This adds a method to retrieve the donation attribute from a TX Fixes #627
1 parent e4d1ad8 commit 4be9f59

File tree

9 files changed

+41
-2
lines changed

9 files changed

+41
-2
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ This is not an exhaustive list of existing and planned features, but it covers t
135135
- [X] Voting procedures
136136
- [X] Proposal procedures
137137
- [X] Current treasury value
138-
- [ ] Donation
138+
- [X] Donation
139139
- [ ] Testing
140140
- [X] Test framework for mocking Ouroboros conversations
141141
- [ ] CBOR deserialization and serialization

ledger/allegra.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,10 @@ func (t AllegraTransaction) CurrentTreasuryValue() int64 {
214214
return t.Body.CurrentTreasuryValue()
215215
}
216216

217+
func (t AllegraTransaction) Donation() uint64 {
218+
return t.Body.Donation()
219+
}
220+
217221
func (t AllegraTransaction) Metadata() *cbor.LazyValue {
218222
return t.TxMetadata
219223
}

ledger/alonzo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,10 @@ func (t AlonzoTransaction) CurrentTreasuryValue() int64 {
328328
return t.Body.CurrentTreasuryValue()
329329
}
330330

331+
func (t AlonzoTransaction) Donation() uint64 {
332+
return t.Body.Donation()
333+
}
334+
331335
func (t AlonzoTransaction) Metadata() *cbor.LazyValue {
332336
return t.TxMetadata
333337
}

ledger/babbage.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,10 @@ func (t BabbageTransaction) CurrentTreasuryValue() int64 {
496496
return t.Body.CurrentTreasuryValue()
497497
}
498498

499+
func (t BabbageTransaction) Donation() uint64 {
500+
return t.Body.Donation()
501+
}
502+
499503
func (t BabbageTransaction) Metadata() *cbor.LazyValue {
500504
return t.TxMetadata
501505
}

ledger/byron.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,11 @@ func (t *ByronTransaction) CurrentTreasuryValue() int64 {
240240
return 0
241241
}
242242

243+
func (t *ByronTransaction) Donation() uint64 {
244+
// No donation in Byron
245+
return 0
246+
}
247+
243248
func (t *ByronTransaction) Metadata() *cbor.LazyValue {
244249
return t.Attributes
245250
}

ledger/conway.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ type ConwayTransactionBody struct {
124124
TxVotingProcedures VotingProcedures `cbor:"19,keyasint,omitempty"`
125125
TxProposalProcedures []ProposalProcedure `cbor:"20,keyasint,omitempty"`
126126
TxCurrentTreasuryValue int64 `cbor:"21,keyasint,omitempty"`
127-
Donation uint64 `cbor:"22,keyasint,omitempty"`
127+
TxDonation uint64 `cbor:"22,keyasint,omitempty"`
128128
}
129129

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

146+
func (b *ConwayTransactionBody) Donation() uint64 {
147+
return b.TxDonation
148+
}
149+
146150
// VotingProcedures is a convenience type to avoid needing to duplicate the full type definition everywhere
147151
type VotingProcedures map[*Voter]map[*GovActionId]VotingProcedure
148152

@@ -405,6 +409,10 @@ func (t ConwayTransaction) CurrentTreasuryValue() int64 {
405409
return t.Body.CurrentTreasuryValue()
406410
}
407411

412+
func (t ConwayTransaction) Donation() uint64 {
413+
return t.Body.Donation()
414+
}
415+
408416
func (t ConwayTransaction) Metadata() *cbor.LazyValue {
409417
return t.TxMetadata
410418
}

ledger/mary.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,10 @@ func (t MaryTransaction) CurrentTreasuryValue() int64 {
231231
return t.Body.CurrentTreasuryValue()
232232
}
233233

234+
func (t MaryTransaction) Donation() uint64 {
235+
return t.Body.Donation()
236+
}
237+
234238
func (t MaryTransaction) Metadata() *cbor.LazyValue {
235239
return t.TxMetadata
236240
}

ledger/shelley.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,11 @@ func (b *ShelleyTransactionBody) CurrentTreasuryValue() int64 {
283283
return 0
284284
}
285285

286+
func (b *ShelleyTransactionBody) Donation() uint64 {
287+
// No donation in Shelley
288+
return 0
289+
}
290+
286291
func (b *ShelleyTransactionBody) Utxorpc() *utxorpc.Tx {
287292
var txi []*utxorpc.TxInput
288293
var txo []*utxorpc.TxOutput
@@ -473,6 +478,10 @@ func (t ShelleyTransaction) CurrentTreasuryValue() int64 {
473478
return t.Body.CurrentTreasuryValue()
474479
}
475480

481+
func (t ShelleyTransaction) Donation() uint64 {
482+
return t.Body.Donation()
483+
}
484+
476485
func (t ShelleyTransaction) Metadata() *cbor.LazyValue {
477486
return t.TxMetadata
478487
}

ledger/tx.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ type TransactionBody interface {
5454
VotingProcedures() VotingProcedures
5555
ProposalProcedures() []ProposalProcedure
5656
CurrentTreasuryValue() int64
57+
Donation() uint64
5758
Utxorpc() *utxorpc.Tx
5859
}
5960

0 commit comments

Comments
 (0)