From 58bc927eeff6b154ba3c1e876a1f83f612d0081a Mon Sep 17 00:00:00 2001 From: Akhil Repala Date: Mon, 30 Jun 2025 02:05:03 -0500 Subject: [PATCH 1/2] feat(ledger): Added GetScriptRef() support across eras to expose ScriptRef in TransactionOutput Signed-off-by: Akhil Repala --- ledger/alonzo/alonzo.go | 4 ++++ ledger/babbage/babbage.go | 10 ++++++++++ ledger/byron/byron.go | 4 ++++ ledger/common/tx.go | 1 + ledger/mary/mary.go | 4 ++++ ledger/shelley/shelley.go | 4 ++++ 6 files changed, 27 insertions(+) diff --git a/ledger/alonzo/alonzo.go b/ledger/alonzo/alonzo.go index 6a483234..7b166bba 100644 --- a/ledger/alonzo/alonzo.go +++ b/ledger/alonzo/alonzo.go @@ -324,6 +324,10 @@ func (o AlonzoTransactionOutput) Address() common.Address { return o.OutputAddress } +func (o AlonzoTransactionOutput) GetScriptRef() *cbor.LazyValue { + return nil +} + func (o AlonzoTransactionOutput) Amount() uint64 { return o.OutputAmount.Amount } diff --git a/ledger/babbage/babbage.go b/ledger/babbage/babbage.go index e0e758b7..69fc409e 100644 --- a/ledger/babbage/babbage.go +++ b/ledger/babbage/babbage.go @@ -486,6 +486,16 @@ func (o BabbageTransactionOutput) Address() common.Address { return o.OutputAddress } +func (o BabbageTransactionOutput) GetScriptRef() *cbor.LazyValue { + if o.ScriptRef == nil { + return nil + } + if lazyVal, ok := o.ScriptRef.Content.(*cbor.LazyValue); ok { + return lazyVal + } + return nil +} + func (o BabbageTransactionOutput) Amount() uint64 { return o.OutputAmount.Amount } diff --git a/ledger/byron/byron.go b/ledger/byron/byron.go index 8f2dc04f..cfebdf4c 100644 --- a/ledger/byron/byron.go +++ b/ledger/byron/byron.go @@ -414,6 +414,10 @@ func (o ByronTransactionOutput) Address() common.Address { return o.OutputAddress } +func (o ByronTransactionOutput) GetScriptRef() *cbor.LazyValue { + return nil +} + func (o ByronTransactionOutput) Amount() uint64 { return o.OutputAmount } diff --git a/ledger/common/tx.go b/ledger/common/tx.go index 78aa48df..ab077538 100644 --- a/ledger/common/tx.go +++ b/ledger/common/tx.go @@ -71,6 +71,7 @@ type TransactionOutput interface { DatumHash() *Blake2b256 Cbor() []byte Utxorpc() (*utxorpc.TxOutput, error) + GetScriptRef() *cbor.LazyValue } type TransactionWitnessSet interface { diff --git a/ledger/mary/mary.go b/ledger/mary/mary.go index 729ef33b..ab363983 100644 --- a/ledger/mary/mary.go +++ b/ledger/mary/mary.go @@ -446,6 +446,10 @@ func (o MaryTransactionOutput) Address() common.Address { return o.OutputAddress } +func (txo MaryTransactionOutput) GetScriptRef() *cbor.LazyValue { + return nil +} + func (o MaryTransactionOutput) Amount() uint64 { return o.OutputAmount.Amount } diff --git a/ledger/shelley/shelley.go b/ledger/shelley/shelley.go index 1df99bd5..c63e95f8 100644 --- a/ledger/shelley/shelley.go +++ b/ledger/shelley/shelley.go @@ -388,6 +388,10 @@ func (o ShelleyTransactionOutput) Address() common.Address { return o.OutputAddress } +func (o ShelleyTransactionOutput) GetScriptRef() *cbor.LazyValue { + return nil +} + func (o ShelleyTransactionOutput) Amount() uint64 { return o.OutputAmount } From 75be3daad87c35b413e5f93d49738c1f93995690 Mon Sep 17 00:00:00 2001 From: Akhil Repala Date: Thu, 3 Jul 2025 01:35:58 -0500 Subject: [PATCH 2/2] feat(ledger): Modified the GetScriptRef() to ScriptRef() for constistency and to be idiomatic Go Signed-off-by: Akhil Repala --- ledger/alonzo/alonzo.go | 2 +- ledger/babbage/babbage.go | 8 ++++---- ledger/byron/byron.go | 2 +- ledger/common/tx.go | 2 +- ledger/mary/mary.go | 2 +- ledger/shelley/shelley.go | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) diff --git a/ledger/alonzo/alonzo.go b/ledger/alonzo/alonzo.go index 7b166bba..c83c7104 100644 --- a/ledger/alonzo/alonzo.go +++ b/ledger/alonzo/alonzo.go @@ -324,7 +324,7 @@ func (o AlonzoTransactionOutput) Address() common.Address { return o.OutputAddress } -func (o AlonzoTransactionOutput) GetScriptRef() *cbor.LazyValue { +func (o AlonzoTransactionOutput) ScriptRef() *cbor.LazyValue { return nil } diff --git a/ledger/babbage/babbage.go b/ledger/babbage/babbage.go index 69fc409e..0af3d3a1 100644 --- a/ledger/babbage/babbage.go +++ b/ledger/babbage/babbage.go @@ -423,7 +423,7 @@ type BabbageTransactionOutput struct { OutputAddress common.Address `cbor:"0,keyasint,omitempty"` OutputAmount mary.MaryTransactionOutputValue `cbor:"1,keyasint,omitempty"` DatumOption *BabbageTransactionOutputDatumOption `cbor:"2,keyasint,omitempty"` - ScriptRef *cbor.Tag `cbor:"3,keyasint,omitempty"` + TxScriptRef *cbor.Tag `cbor:"3,keyasint,omitempty"` legacyOutput bool } @@ -486,11 +486,11 @@ func (o BabbageTransactionOutput) Address() common.Address { return o.OutputAddress } -func (o BabbageTransactionOutput) GetScriptRef() *cbor.LazyValue { - if o.ScriptRef == nil { +func (o BabbageTransactionOutput) ScriptRef() *cbor.LazyValue { + if o.TxScriptRef == nil { return nil } - if lazyVal, ok := o.ScriptRef.Content.(*cbor.LazyValue); ok { + if lazyVal, ok := o.TxScriptRef.Content.(*cbor.LazyValue); ok { return lazyVal } return nil diff --git a/ledger/byron/byron.go b/ledger/byron/byron.go index cfebdf4c..65756231 100644 --- a/ledger/byron/byron.go +++ b/ledger/byron/byron.go @@ -414,7 +414,7 @@ func (o ByronTransactionOutput) Address() common.Address { return o.OutputAddress } -func (o ByronTransactionOutput) GetScriptRef() *cbor.LazyValue { +func (o ByronTransactionOutput) ScriptRef() *cbor.LazyValue { return nil } diff --git a/ledger/common/tx.go b/ledger/common/tx.go index ab077538..388317dd 100644 --- a/ledger/common/tx.go +++ b/ledger/common/tx.go @@ -71,7 +71,7 @@ type TransactionOutput interface { DatumHash() *Blake2b256 Cbor() []byte Utxorpc() (*utxorpc.TxOutput, error) - GetScriptRef() *cbor.LazyValue + ScriptRef() *cbor.LazyValue } type TransactionWitnessSet interface { diff --git a/ledger/mary/mary.go b/ledger/mary/mary.go index ab363983..99b6c389 100644 --- a/ledger/mary/mary.go +++ b/ledger/mary/mary.go @@ -446,7 +446,7 @@ func (o MaryTransactionOutput) Address() common.Address { return o.OutputAddress } -func (txo MaryTransactionOutput) GetScriptRef() *cbor.LazyValue { +func (txo MaryTransactionOutput) ScriptRef() *cbor.LazyValue { return nil } diff --git a/ledger/shelley/shelley.go b/ledger/shelley/shelley.go index c63e95f8..858f5e11 100644 --- a/ledger/shelley/shelley.go +++ b/ledger/shelley/shelley.go @@ -388,7 +388,7 @@ func (o ShelleyTransactionOutput) Address() common.Address { return o.OutputAddress } -func (o ShelleyTransactionOutput) GetScriptRef() *cbor.LazyValue { +func (o ShelleyTransactionOutput) ScriptRef() *cbor.LazyValue { return nil }