From 205b6faf6a7588dcf114f52a9089ceb54d6e00f3 Mon Sep 17 00:00:00 2001 From: Aurora Gaffney Date: Wed, 15 May 2024 17:05:09 -0500 Subject: [PATCH] feat: TX required signers attribute (#630) This adds a method to retrieve the required signers for a TX Fixes #339 --- ledger/allegra.go | 4 ++++ ledger/alonzo.go | 16 ++++++++++++---- ledger/babbage.go | 4 ++++ ledger/byron.go | 5 +++++ ledger/conway.go | 4 ++++ 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 fbf4ed43..e1735aa1 100644 --- a/ledger/allegra.go +++ b/ledger/allegra.go @@ -178,6 +178,10 @@ func (t AllegraTransaction) Withdrawals() map[*Address]uint64 { return t.Body.Withdrawals() } +func (t AllegraTransaction) RequiredSigners() []Blake2b224 { + return t.Body.RequiredSigners() +} + func (t AllegraTransaction) VotingProcedures() VotingProcedures { return t.Body.VotingProcedures() } diff --git a/ledger/alonzo.go b/ledger/alonzo.go index 38988db3..1eaf47d8 100644 --- a/ledger/alonzo.go +++ b/ledger/alonzo.go @@ -128,10 +128,10 @@ type AlonzoTransactionBody struct { ProtocolParamUpdates map[Blake2b224]AlonzoProtocolParameterUpdate Epoch uint64 } `cbor:"6,keyasint,omitempty"` - ScriptDataHash Blake2b256 `cbor:"11,keyasint,omitempty"` - TxCollateral []ShelleyTransactionInput `cbor:"13,keyasint,omitempty"` - RequiredSigners []Blake2b224 `cbor:"14,keyasint,omitempty"` - NetworkId uint8 `cbor:"15,keyasint,omitempty"` + ScriptDataHash Blake2b256 `cbor:"11,keyasint,omitempty"` + TxCollateral []ShelleyTransactionInput `cbor:"13,keyasint,omitempty"` + TxRequiredSigners []Blake2b224 `cbor:"14,keyasint,omitempty"` + NetworkId uint8 `cbor:"15,keyasint,omitempty"` } func (b *AlonzoTransactionBody) UnmarshalCBOR(cborData []byte) error { @@ -155,6 +155,10 @@ func (b *AlonzoTransactionBody) Collateral() []TransactionInput { return ret } +func (b *AlonzoTransactionBody) RequiredSigners() []Blake2b224 { + return b.TxRequiredSigners[:] +} + type AlonzoTransactionOutput struct { cbor.StructAsArray cbor.DecodeStoreCbor @@ -288,6 +292,10 @@ func (t AlonzoTransaction) Withdrawals() map[*Address]uint64 { return t.Body.Withdrawals() } +func (t AlonzoTransaction) RequiredSigners() []Blake2b224 { + return t.Body.RequiredSigners() +} + func (t AlonzoTransaction) VotingProcedures() VotingProcedures { return t.Body.VotingProcedures() } diff --git a/ledger/babbage.go b/ledger/babbage.go index d0d1edfc..1e60a241 100644 --- a/ledger/babbage.go +++ b/ledger/babbage.go @@ -468,6 +468,10 @@ func (t BabbageTransaction) VotingProcedures() VotingProcedures { return t.Body.VotingProcedures() } +func (t BabbageTransaction) RequiredSigners() []Blake2b224 { + return t.Body.RequiredSigners() +} + func (t BabbageTransaction) ProposalProcedures() []ProposalProcedure { return t.Body.ProposalProcedures() } diff --git a/ledger/byron.go b/ledger/byron.go index 70116d96..d56e3cf4 100644 --- a/ledger/byron.go +++ b/ledger/byron.go @@ -200,6 +200,11 @@ func (t *ByronTransaction) Withdrawals() map[*Address]uint64 { return nil } +func (t *ByronTransaction) RequiredSigners() []Blake2b224 { + // No required signers in Byron + return nil +} + func (t *ByronTransaction) VotingProcedures() VotingProcedures { // No voting procedures in Byron return nil diff --git a/ledger/conway.go b/ledger/conway.go index c8ead3d1..516d6284 100644 --- a/ledger/conway.go +++ b/ledger/conway.go @@ -369,6 +369,10 @@ func (t ConwayTransaction) Withdrawals() map[*Address]uint64 { return t.Body.Withdrawals() } +func (t ConwayTransaction) RequiredSigners() []Blake2b224 { + return t.Body.RequiredSigners() +} + func (t ConwayTransaction) VotingProcedures() VotingProcedures { return t.Body.VotingProcedures() } diff --git a/ledger/mary.go b/ledger/mary.go index f6ea4505..967254c0 100644 --- a/ledger/mary.go +++ b/ledger/mary.go @@ -195,6 +195,10 @@ func (t MaryTransaction) Withdrawals() map[*Address]uint64 { return t.Body.Withdrawals() } +func (t MaryTransaction) RequiredSigners() []Blake2b224 { + return t.Body.RequiredSigners() +} + func (t MaryTransaction) VotingProcedures() VotingProcedures { return t.Body.VotingProcedures() } diff --git a/ledger/shelley.go b/ledger/shelley.go index 11af97ae..603c7e60 100644 --- a/ledger/shelley.go +++ b/ledger/shelley.go @@ -244,6 +244,11 @@ func (b *ShelleyTransactionBody) Withdrawals() map[*Address]uint64 { return b.TxWithdrawals } +func (b *ShelleyTransactionBody) RequiredSigners() []Blake2b224 { + // No required signers in Shelley + return nil +} + func (t *ShelleyTransactionBody) VotingProcedures() VotingProcedures { // No voting procedures in Shelley return nil @@ -412,6 +417,10 @@ func (t ShelleyTransaction) Withdrawals() map[*Address]uint64 { return t.Body.Withdrawals() } +func (t ShelleyTransaction) RequiredSigners() []Blake2b224 { + return t.Body.RequiredSigners() +} + func (t ShelleyTransaction) VotingProcedures() VotingProcedures { return t.Body.VotingProcedures() } diff --git a/ledger/tx.go b/ledger/tx.go index 39c77987..897ca5a8 100644 --- a/ledger/tx.go +++ b/ledger/tx.go @@ -46,6 +46,7 @@ type TransactionBody interface { TotalCollateral() uint64 Certificates() []Certificate Withdrawals() map[*Address]uint64 + RequiredSigners() []Blake2b224 VotingProcedures() VotingProcedures ProposalProcedures() []ProposalProcedure Utxorpc() *utxorpc.Tx