Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ledger/allegra/allegra.go
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ func (b *AllegraTransactionBody) AuxDataHash() *common.Blake2b256 {
}

func (b *AllegraTransactionBody) Utxorpc() (*utxorpc.Tx, error) {
return common.TransactionBodyToUtxorpc(b), nil
return common.TransactionBodyToUtxorpc(b)
}

type AllegraTransaction struct {
Expand Down
4 changes: 2 additions & 2 deletions ledger/allegra/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func TestAllegraTransactionBody_Utxorpc(t *testing.T) {
// Run Utxorpc conversion
actual, err := txBody.Utxorpc()
if err != nil {
t.Errorf("Failed to convert the transaction")
t.Fatalf("Could not convert transaction body to utxorpc format: %v", err)
}

// Check that the fee matches
Expand Down Expand Up @@ -227,7 +227,7 @@ func TestAllegraTransaction_Utxorpc(t *testing.T) {
// Run Utxorpc conversion
actual, err := tx.Utxorpc()
if err != nil {
t.Errorf("Failed to convert the transaction")
t.Fatalf("Could not convert transaction to utxorpc format: %v", err)
}
// Assertion checks
if actual.Fee != tx.Fee() {
Expand Down
2 changes: 1 addition & 1 deletion ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ func (b *AlonzoTransactionBody) ScriptDataHash() *common.Blake2b256 {
}

func (b *AlonzoTransactionBody) Utxorpc() (*utxorpc.Tx, error) {
return common.TransactionBodyToUtxorpc(b), nil
return common.TransactionBodyToUtxorpc(b)
}

type AlonzoTransactionOutput struct {
Expand Down
7 changes: 5 additions & 2 deletions ledger/alonzo/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,9 @@ func TestScientificNotationInCostModels(t *testing.T) {
}

expected := []int64{2477736, 1500000, 1000000}
if params.CostModels == nil || params.CostModels[alonzo.PlutusV1Key] == nil {
t.Fatal("CostModels not properly initialized")
}
for i := range 3 {
if params.CostModels[alonzo.PlutusV1Key][i] != expected[i] {
t.Errorf("parameter %d conversion failed: got %d, want %d",
Expand Down Expand Up @@ -517,7 +520,7 @@ func TestAlonzoTransactionBody_Utxorpc(t *testing.T) {
// Run Utxorpc conversion
got, err := body.Utxorpc()
if err != nil {
t.Errorf("Failed to convert the transaction")
t.Fatalf("Could not convert transaction body to utxorpc format: %v", err)
}

// Assertion checks
Expand Down Expand Up @@ -580,7 +583,7 @@ func TestAlonzoTransaction_Utxorpc(t *testing.T) {
// Run Utxorpc conversion
got, err := tx.Utxorpc()
if err != nil {
t.Errorf("Failed to convert the transaction")
t.Fatalf("Could not convert transaction to utxorpc format: %v", err)
}

// Assertion checks
Expand Down
2 changes: 1 addition & 1 deletion ledger/babbage/babbage.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ func (b *BabbageTransactionBody) TotalCollateral() uint64 {
}

func (b *BabbageTransactionBody) Utxorpc() (*utxorpc.Tx, error) {
return common.TransactionBodyToUtxorpc(b), nil
return common.TransactionBodyToUtxorpc(b)
}

const (
Expand Down
4 changes: 2 additions & 2 deletions ledger/babbage/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,7 @@ func TestBabbageTransactionBody_Utxorpc(t *testing.T) {

got, err := body.Utxorpc()
if err != nil {
t.Fatalf("Utxorpc() conversion failed: %v", err)
t.Fatalf("Could not convert transaction body to utxorpc format: %v", err)
}
if got.Fee != 100 {
t.Errorf("Fee mismatch: got %d, want 100", got.Fee)
Expand Down Expand Up @@ -682,7 +682,7 @@ func TestBabbageTransaction_Utxorpc(t *testing.T) {

got, err := tx.Utxorpc()
if err != nil {
t.Fatalf("Utxorpc() failed: %v", err)
t.Fatalf("Could not convert transaction to utxorpc format: %v", err)
}
if got.Fee != 150 {
t.Errorf("Fee mismatch: got %d, want 150", got.Fee)
Expand Down
6 changes: 5 additions & 1 deletion ledger/common/script_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,13 @@ func TestScriptRefDecodeEncode(t *testing.T) {
}

func TestNativeScriptHash(t *testing.T) {
testScriptBytes, _ := hex.DecodeString(
testScriptBytes, err := hex.DecodeString(
"820181830301838200581c058a5ab0c66647dcce82d7244f80bfea41ba76c7c9ccaf86a41b00fe8200581c45cbc234959cb619ef54e36c16e7719318592e627cdf1a39bd3d64398200581c85fd53e110449649b709ef0fa93e86d99535bdce5db306ce0e7418fc",
)
// Make nilaway happy
if err != nil {
t.Fatalf("failed to decode hex string: %v", err)
}
expectedScriptHash := "1c0053ec18e2c0f7bd4d007fe14243ca220563f9c124381f75c43704"
var testScript common.NativeScript
if err := testScript.UnmarshalCBOR(testScriptBytes); err != nil {
Expand Down
16 changes: 8 additions & 8 deletions ledger/common/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,25 +195,25 @@ func (b *TransactionBodyBase) Donation() uint64 {
return 0
}

func (b *TransactionBodyBase) Utxorpc() *utxorpc.Tx {
return nil
func (b *TransactionBodyBase) Utxorpc() (*utxorpc.Tx, error) {
return nil, nil
}

// TransactionBodyToUtxorpc is a common helper for converting TransactionBody to utxorpc.Tx
func TransactionBodyToUtxorpc(tx TransactionBody) *utxorpc.Tx {
func TransactionBodyToUtxorpc(tx TransactionBody) (*utxorpc.Tx, error) {
txi := []*utxorpc.TxInput{}
txo := []*utxorpc.TxOutput{}
for _, i := range tx.Inputs() {
input, err := i.Utxorpc()
if err != nil {
return nil
return nil, err
}
txi = append(txi, input)
}
for _, o := range tx.Outputs() {
output, err := o.Utxorpc()
if err != nil {
return nil
return nil, err
}
txo = append(txo, output)
}
Expand All @@ -236,17 +236,17 @@ func TransactionBodyToUtxorpc(tx TransactionBody) *utxorpc.Tx {
for _, ri := range tx.ReferenceInputs() {
input, err := ri.Utxorpc()
if err != nil {
return nil
return nil, err
}
ret.ReferenceInputs = append(ret.ReferenceInputs, input)
}
for _, c := range tx.Certificates() {
cert, err := c.Utxorpc()
if err != nil {
return nil
return nil, err
}
ret.Certificates = append(ret.Certificates, cert)
}

return ret
return ret, nil
}
2 changes: 1 addition & 1 deletion ledger/conway/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,7 @@ func (b *ConwayTransactionBody) Donation() uint64 {
}

func (b *ConwayTransactionBody) Utxorpc() (*utxorpc.Tx, error) {
return common.TransactionBodyToUtxorpc(b), nil
return common.TransactionBodyToUtxorpc(b)
}

type ConwayTransaction struct {
Expand Down
4 changes: 2 additions & 2 deletions ledger/conway/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@ func TestConwayTransactionBody_Utxorpc(t *testing.T) {

got, err := body.Utxorpc()
if err != nil {
t.Errorf("Could not get the transaction input")
t.Fatalf("Could not convert the transaction body to utxorpc format %v", err)
}

if got.Fee != 1000 {
Expand Down Expand Up @@ -733,7 +733,7 @@ func TestConwayTransaction_Utxorpc(t *testing.T) {

got, err := tx.Utxorpc()
if err != nil {
t.Errorf("Could not get the transaction input")
t.Fatalf("Could not convert transaction to utxorpc format: %v", err)
}

if got.Fee != 1000 {
Expand Down
2 changes: 1 addition & 1 deletion ledger/mary/mary.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ func (b *MaryTransactionBody) AssetMint() *common.MultiAsset[common.MultiAssetTy
}

func (b *MaryTransactionBody) Utxorpc() (*utxorpc.Tx, error) {
return common.TransactionBodyToUtxorpc(b), nil
return common.TransactionBodyToUtxorpc(b)
}

type MaryTransaction struct {
Expand Down
4 changes: 2 additions & 2 deletions ledger/mary/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ func TestMaryTransactionBody_Utxorpc(t *testing.T) {

got, err := body.Utxorpc()
if err != nil {
t.Errorf("Could not get correct UTxorpc input")
t.Fatalf("Could not convert the transaction body to utxorpc format %v", err)
}

if got.Fee != 100 {
Expand Down Expand Up @@ -262,7 +262,7 @@ func TestMaryTransaction_Utxorpc(t *testing.T) {

got, err := tx.Utxorpc()
if err != nil {
t.Errorf("Could not get correct UTxorpc input")
t.Fatalf("Could not convert transaction to utxorpc format: %v", err)
}

if got.Fee != 25 {
Expand Down
4 changes: 2 additions & 2 deletions ledger/shelley/pparams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ func TestShelleyTransactionBody_Utxorpc(t *testing.T) {
// Convert the transaction body to utxorpc format
actual, err := txBody.Utxorpc()
if err != nil {
t.Errorf("Could not convert the transaction body to utxorpc format")
t.Fatalf("Could not convert the transaction body to utxorpc format %v", err)
}

// Check that the fee matches
Expand Down Expand Up @@ -339,7 +339,7 @@ func TestShelleyTransaction_Utxorpc(t *testing.T) {
// Invoke Utxorpc conversion
got, err := tx.Utxorpc()
if err != nil {
t.Errorf("Could not Invoke Utxorpc conversion")
t.Fatalf("Could not convert transaction to utxorpc format: %v", err)
}

// Verify the fee
Expand Down
2 changes: 1 addition & 1 deletion ledger/shelley/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,7 @@ func (b *ShelleyTransactionBody) AuxDataHash() *common.Blake2b256 {
}

func (b *ShelleyTransactionBody) Utxorpc() (*utxorpc.Tx, error) {
return common.TransactionBodyToUtxorpc(b), nil
return common.TransactionBodyToUtxorpc(b)
}

type ShelleyTransactionInputSet struct {
Expand Down