Skip to content

Commit 33ce3ea

Browse files
authored
feat: Support getting ScriptRef from TransactionOutput interface (#1051)
* feat(ledger): Added GetScriptRef() support across eras to expose ScriptRef in TransactionOutput Signed-off-by: Akhil Repala <[email protected]> * feat(ledger): Modified the GetScriptRef() to ScriptRef() for constistency and to be idiomatic Go Signed-off-by: Akhil Repala <[email protected]> --------- Signed-off-by: Akhil Repala <[email protected]>
1 parent b275c23 commit 33ce3ea

File tree

6 files changed

+28
-1
lines changed

6 files changed

+28
-1
lines changed

ledger/alonzo/alonzo.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,10 @@ func (o AlonzoTransactionOutput) Address() common.Address {
324324
return o.OutputAddress
325325
}
326326

327+
func (o AlonzoTransactionOutput) ScriptRef() *cbor.LazyValue {
328+
return nil
329+
}
330+
327331
func (o AlonzoTransactionOutput) Amount() uint64 {
328332
return o.OutputAmount.Amount
329333
}

ledger/babbage/babbage.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ type BabbageTransactionOutput struct {
423423
OutputAddress common.Address `cbor:"0,keyasint,omitempty"`
424424
OutputAmount mary.MaryTransactionOutputValue `cbor:"1,keyasint,omitempty"`
425425
DatumOption *BabbageTransactionOutputDatumOption `cbor:"2,keyasint,omitempty"`
426-
ScriptRef *cbor.Tag `cbor:"3,keyasint,omitempty"`
426+
TxScriptRef *cbor.Tag `cbor:"3,keyasint,omitempty"`
427427
legacyOutput bool
428428
}
429429

@@ -486,6 +486,16 @@ func (o BabbageTransactionOutput) Address() common.Address {
486486
return o.OutputAddress
487487
}
488488

489+
func (o BabbageTransactionOutput) ScriptRef() *cbor.LazyValue {
490+
if o.TxScriptRef == nil {
491+
return nil
492+
}
493+
if lazyVal, ok := o.TxScriptRef.Content.(*cbor.LazyValue); ok {
494+
return lazyVal
495+
}
496+
return nil
497+
}
498+
489499
func (o BabbageTransactionOutput) Amount() uint64 {
490500
return o.OutputAmount.Amount
491501
}

ledger/byron/byron.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,10 @@ func (o ByronTransactionOutput) Address() common.Address {
414414
return o.OutputAddress
415415
}
416416

417+
func (o ByronTransactionOutput) ScriptRef() *cbor.LazyValue {
418+
return nil
419+
}
420+
417421
func (o ByronTransactionOutput) Amount() uint64 {
418422
return o.OutputAmount
419423
}

ledger/common/tx.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ type TransactionOutput interface {
7171
DatumHash() *Blake2b256
7272
Cbor() []byte
7373
Utxorpc() (*utxorpc.TxOutput, error)
74+
ScriptRef() *cbor.LazyValue
7475
}
7576

7677
type TransactionWitnessSet interface {

ledger/mary/mary.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,10 @@ func (o MaryTransactionOutput) Address() common.Address {
446446
return o.OutputAddress
447447
}
448448

449+
func (txo MaryTransactionOutput) ScriptRef() *cbor.LazyValue {
450+
return nil
451+
}
452+
449453
func (o MaryTransactionOutput) Amount() uint64 {
450454
return o.OutputAmount.Amount
451455
}

ledger/shelley/shelley.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,10 @@ func (o ShelleyTransactionOutput) Address() common.Address {
388388
return o.OutputAddress
389389
}
390390

391+
func (o ShelleyTransactionOutput) ScriptRef() *cbor.LazyValue {
392+
return nil
393+
}
394+
391395
func (o ShelleyTransactionOutput) Amount() uint64 {
392396
return o.OutputAmount
393397
}

0 commit comments

Comments
 (0)