From e773bc26e7657f78dc4aad7d9d39f2dec85b78d7 Mon Sep 17 00:00:00 2001 From: Aurora Gaffney Date: Mon, 20 May 2024 15:32:54 -0500 Subject: [PATCH] feat: TX current treasury value attribute This adds a method for retrieving the current treasury value attribute from a TX Fixes #626 --- ledger/allegra.go | 4 ++++ ledger/alonzo.go | 4 ++++ ledger/babbage.go | 4 ++++ ledger/byron.go | 5 +++++ ledger/conway.go | 16 ++++++++++++---- ledger/mary.go | 4 ++++ ledger/shelley.go | 9 +++++++++ ledger/tx.go | 1 + 8 files changed, 43 insertions(+), 4 deletions(-) diff --git a/ledger/allegra.go b/ledger/allegra.go index 69f93f5a..18e66b6b 100644 --- a/ledger/allegra.go +++ b/ledger/allegra.go @@ -210,6 +210,10 @@ func (t AllegraTransaction) ProposalProcedures() []ProposalProcedure { return t.Body.ProposalProcedures() } +func (t AllegraTransaction) CurrentTreasuryValue() int64 { + return t.Body.CurrentTreasuryValue() +} + func (t AllegraTransaction) Metadata() *cbor.LazyValue { return t.TxMetadata } diff --git a/ledger/alonzo.go b/ledger/alonzo.go index ad8ec194..6d769ce5 100644 --- a/ledger/alonzo.go +++ b/ledger/alonzo.go @@ -324,6 +324,10 @@ func (t AlonzoTransaction) ProposalProcedures() []ProposalProcedure { return t.Body.ProposalProcedures() } +func (t AlonzoTransaction) CurrentTreasuryValue() int64 { + return t.Body.CurrentTreasuryValue() +} + func (t AlonzoTransaction) Metadata() *cbor.LazyValue { return t.TxMetadata } diff --git a/ledger/babbage.go b/ledger/babbage.go index b599a550..d41c8dda 100644 --- a/ledger/babbage.go +++ b/ledger/babbage.go @@ -492,6 +492,10 @@ func (t BabbageTransaction) ProposalProcedures() []ProposalProcedure { return t.Body.ProposalProcedures() } +func (t BabbageTransaction) CurrentTreasuryValue() int64 { + return t.Body.CurrentTreasuryValue() +} + func (t BabbageTransaction) Metadata() *cbor.LazyValue { return t.TxMetadata } diff --git a/ledger/byron.go b/ledger/byron.go index 1590e37f..02fb0e3b 100644 --- a/ledger/byron.go +++ b/ledger/byron.go @@ -235,6 +235,11 @@ func (t *ByronTransaction) ProposalProcedures() []ProposalProcedure { return nil } +func (t *ByronTransaction) CurrentTreasuryValue() int64 { + // No current treasury value in Byron + return 0 +} + func (t *ByronTransaction) Metadata() *cbor.LazyValue { return t.Attributes } diff --git a/ledger/conway.go b/ledger/conway.go index 2700c817..a1dc6ef1 100644 --- a/ledger/conway.go +++ b/ledger/conway.go @@ -121,10 +121,10 @@ func (h *ConwayBlockHeader) Era() Era { type ConwayTransactionBody struct { BabbageTransactionBody - TxVotingProcedures VotingProcedures `cbor:"19,keyasint,omitempty"` - TxProposalProcedures []ProposalProcedure `cbor:"20,keyasint,omitempty"` - CurrentTreasuryValue int64 `cbor:"21,keyasint,omitempty"` - Donation uint64 `cbor:"22,keyasint,omitempty"` + TxVotingProcedures VotingProcedures `cbor:"19,keyasint,omitempty"` + TxProposalProcedures []ProposalProcedure `cbor:"20,keyasint,omitempty"` + TxCurrentTreasuryValue int64 `cbor:"21,keyasint,omitempty"` + Donation uint64 `cbor:"22,keyasint,omitempty"` } func (b *ConwayTransactionBody) UnmarshalCBOR(cborData []byte) error { @@ -139,6 +139,10 @@ func (b *ConwayTransactionBody) ProposalProcedures() []ProposalProcedure { return b.TxProposalProcedures } +func (b *ConwayTransactionBody) CurrentTreasuryValue() int64 { + return b.TxCurrentTreasuryValue +} + // VotingProcedures is a convenience type to avoid needing to duplicate the full type definition everywhere type VotingProcedures map[*Voter]map[*GovActionId]VotingProcedure @@ -397,6 +401,10 @@ func (t ConwayTransaction) ProposalProcedures() []ProposalProcedure { return t.Body.ProposalProcedures() } +func (t ConwayTransaction) CurrentTreasuryValue() int64 { + return t.Body.CurrentTreasuryValue() +} + func (t ConwayTransaction) Metadata() *cbor.LazyValue { return t.TxMetadata } diff --git a/ledger/mary.go b/ledger/mary.go index 04e83ead..d0aa4df5 100644 --- a/ledger/mary.go +++ b/ledger/mary.go @@ -227,6 +227,10 @@ func (t MaryTransaction) ProposalProcedures() []ProposalProcedure { return t.Body.ProposalProcedures() } +func (t MaryTransaction) CurrentTreasuryValue() int64 { + return t.Body.CurrentTreasuryValue() +} + func (t MaryTransaction) Metadata() *cbor.LazyValue { return t.TxMetadata } diff --git a/ledger/shelley.go b/ledger/shelley.go index c1b68286..cb67acd8 100644 --- a/ledger/shelley.go +++ b/ledger/shelley.go @@ -278,6 +278,11 @@ func (b *ShelleyTransactionBody) ProposalProcedures() []ProposalProcedure { return nil } +func (b *ShelleyTransactionBody) CurrentTreasuryValue() int64 { + // No current treasury value in Shelley + return 0 +} + func (b *ShelleyTransactionBody) Utxorpc() *utxorpc.Tx { var txi []*utxorpc.TxInput var txo []*utxorpc.TxOutput @@ -464,6 +469,10 @@ func (t ShelleyTransaction) ProposalProcedures() []ProposalProcedure { return t.Body.ProposalProcedures() } +func (t ShelleyTransaction) CurrentTreasuryValue() int64 { + return t.Body.CurrentTreasuryValue() +} + func (t ShelleyTransaction) Metadata() *cbor.LazyValue { return t.TxMetadata } diff --git a/ledger/tx.go b/ledger/tx.go index da76a3dd..9915b06d 100644 --- a/ledger/tx.go +++ b/ledger/tx.go @@ -53,6 +53,7 @@ type TransactionBody interface { ScriptDataHash() *Blake2b256 VotingProcedures() VotingProcedures ProposalProcedures() []ProposalProcedure + CurrentTreasuryValue() int64 Utxorpc() *utxorpc.Tx }