From 0392437eb75aab3e6b114b05eb0bc8dc3f425175 Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Sat, 30 Mar 2024 10:53:20 -0400 Subject: [PATCH] feat: reference inputs in utxorpc for babbage/conway Signed-off-by: Chris Gianelloni --- ledger/babbage.go | 37 +++++++++++++++++++++++++++++++++++++ ledger/shelley.go | 6 +++--- 2 files changed, 40 insertions(+), 3 deletions(-) diff --git a/ledger/babbage.go b/ledger/babbage.go index 4eaeaac8..141fedd3 100644 --- a/ledger/babbage.go +++ b/ledger/babbage.go @@ -208,6 +208,43 @@ func (b *BabbageTransactionBody) ReferenceInputs() []TransactionInput { return ret } +func (b *BabbageTransactionBody) Utxorpc() *utxorpc.Tx { + var txi, txri []*utxorpc.TxInput + var txo []*utxorpc.TxOutput + for _, i := range b.Inputs() { + input := i.Utxorpc() + txi = append(txi, input) + } + for _, o := range b.Outputs() { + output := o.Utxorpc() + txo = append(txo, output) + } + for _, ri := range b.ReferenceInputs() { + input := ri.Utxorpc() + txri = append(txri, input) + } + tmpHash, err := hex.DecodeString(b.Hash()) + if err != nil { + return &utxorpc.Tx{} + } + tx := &utxorpc.Tx{ + Inputs: txi, + Outputs: txo, + // Certificates: b.Certificates(), + // Withdrawals: b.Withdrawals(), + // Mint: b.Mint(), + ReferenceInputs: txri, + // Witnesses: b.Witnesses(), + // Collateral: b.Collateral(), + Fee: b.Fee(), + // Successful: b.Successful(), + // Auxiliary: b.AuxData(), + // Validity: b.Validity(), + Hash: tmpHash, + } + return tx +} + const ( DatumOptionTypeHash = 0 DatumOptionTypeData = 1 diff --git a/ledger/shelley.go b/ledger/shelley.go index fafd66ca..82150c06 100644 --- a/ledger/shelley.go +++ b/ledger/shelley.go @@ -239,14 +239,14 @@ func (b *ShelleyTransactionBody) Utxorpc() *utxorpc.Tx { tx := &utxorpc.Tx{ Inputs: txi, Outputs: txo, - Fee: b.Fee(), - Hash: tmpHash, // Certificates: b.Certificates(), - // Validity: b.Validity(), // Withdrawals: b.Withdrawals(), // Witnesses: b.Witnesses(), + Fee: b.Fee(), + // Validity: b.Validity(), // Successful: b.Successful(), // Auxiliary: b.AuxData(), + Hash: tmpHash, } return tx }