diff --git a/ledger/allegra.go b/ledger/allegra.go index 742dcdc2..cfd4f566 100644 --- a/ledger/allegra.go +++ b/ledger/allegra.go @@ -178,6 +178,14 @@ func (t AllegraTransaction) IsValid() bool { return true } +func (t AllegraTransaction) Consumed() []TransactionInput { + return t.Inputs() +} + +func (t AllegraTransaction) Produced() []TransactionOutput { + return t.Outputs() +} + func (t *AllegraTransaction) ProtocolParametersUpdate() map[Blake2b224]any { updateMap := make(map[Blake2b224]any) for k, v := range t.Body.Update.ProtocolParamUpdates { diff --git a/ledger/alonzo.go b/ledger/alonzo.go index 7bdd95c9..5a5cd842 100644 --- a/ledger/alonzo.go +++ b/ledger/alonzo.go @@ -284,6 +284,23 @@ func (t AlonzoTransaction) IsValid() bool { return t.IsTxValid } +func (t AlonzoTransaction) Consumed() []TransactionInput { + if t.IsValid() { + return t.Inputs() + } else { + return t.Collateral() + } +} + +func (t AlonzoTransaction) Produced() []TransactionOutput { + if t.IsValid() { + return t.Outputs() + } else { + // No collateral return in Alonzo + return []TransactionOutput{} + } +} + func (t *AlonzoTransaction) ProtocolParametersUpdate() map[Blake2b224]any { updateMap := make(map[Blake2b224]any) for k, v := range t.Body.Update.ProtocolParamUpdates { diff --git a/ledger/babbage.go b/ledger/babbage.go index 6d875d38..105a6764 100644 --- a/ledger/babbage.go +++ b/ledger/babbage.go @@ -450,6 +450,25 @@ func (t BabbageTransaction) IsValid() bool { return t.IsTxValid } +func (t BabbageTransaction) Consumed() []TransactionInput { + if t.IsValid() { + return t.Inputs() + } else { + return t.Collateral() + } +} + +func (t BabbageTransaction) Produced() []TransactionOutput { + if t.IsValid() { + return t.Outputs() + } else { + if t.CollateralReturn() == nil { + return []TransactionOutput{} + } + return []TransactionOutput{t.CollateralReturn()} + } +} + func (t *BabbageTransaction) ProtocolParametersUpdate() map[Blake2b224]any { updateMap := make(map[Blake2b224]any) for k, v := range t.Body.Update.ProtocolParamUpdates { diff --git a/ledger/byron.go b/ledger/byron.go index c8cb5055..c03e1668 100644 --- a/ledger/byron.go +++ b/ledger/byron.go @@ -193,6 +193,14 @@ func (t *ByronTransaction) IsValid() bool { return true } +func (t *ByronTransaction) Consumed() []TransactionInput { + return t.Inputs() +} + +func (t *ByronTransaction) Produced() []TransactionOutput { + return t.Outputs() +} + func (t *ByronTransaction) Utxorpc() *utxorpc.Tx { return &utxorpc.Tx{} } diff --git a/ledger/conway.go b/ledger/conway.go index 63de2bd8..3b4930ce 100644 --- a/ledger/conway.go +++ b/ledger/conway.go @@ -180,6 +180,25 @@ func (t ConwayTransaction) IsValid() bool { return t.IsTxValid } +func (t ConwayTransaction) Consumed() []TransactionInput { + if t.IsValid() { + return t.Inputs() + } else { + return t.Collateral() + } +} + +func (t ConwayTransaction) Produced() []TransactionOutput { + if t.IsValid() { + return t.Outputs() + } else { + if t.CollateralReturn() == nil { + return []TransactionOutput{} + } + return []TransactionOutput{t.CollateralReturn()} + } +} + func (t *ConwayTransaction) ProtocolParametersUpdate() map[Blake2b224]any { updateMap := make(map[Blake2b224]any) for k, v := range t.Body.Update.ProtocolParamUpdates { diff --git a/ledger/mary.go b/ledger/mary.go index 28819004..85e2080b 100644 --- a/ledger/mary.go +++ b/ledger/mary.go @@ -191,6 +191,14 @@ func (t MaryTransaction) IsValid() bool { return true } +func (t MaryTransaction) Consumed() []TransactionInput { + return t.Inputs() +} + +func (t MaryTransaction) Produced() []TransactionOutput { + return t.Outputs() +} + func (t *MaryTransaction) ProtocolParametersUpdate() map[Blake2b224]any { updateMap := make(map[Blake2b224]any) for k, v := range t.Body.Update.ProtocolParamUpdates { diff --git a/ledger/shelley.go b/ledger/shelley.go index d7e8f656..08c41515 100644 --- a/ledger/shelley.go +++ b/ledger/shelley.go @@ -385,6 +385,14 @@ func (t ShelleyTransaction) IsValid() bool { return true } +func (t ShelleyTransaction) Consumed() []TransactionInput { + return t.Inputs() +} + +func (t ShelleyTransaction) Produced() []TransactionOutput { + return t.Outputs() +} + func (t ShelleyTransaction) Utxorpc() *utxorpc.Tx { return t.Body.Utxorpc() } diff --git a/ledger/tx.go b/ledger/tx.go index ee1e62e6..f19fcc4d 100644 --- a/ledger/tx.go +++ b/ledger/tx.go @@ -28,6 +28,8 @@ type Transaction interface { TransactionBody Metadata() *cbor.Value IsValid() bool + Consumed() []TransactionInput + Produced() []TransactionOutput ProtocolParametersUpdate() map[Blake2b224]any }