Skip to content
Open
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
5 changes: 2 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ require (
github.com/fxamacker/cbor/v2 v2.9.0
github.com/jinzhu/copier v0.4.0
github.com/stretchr/testify v1.11.1
github.com/utxorpc/go-codegen v0.17.0
github.com/utxorpc/go-codegen v0.18.1
Copy link
Contributor

@coderabbitai coderabbitai bot Nov 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

Verify utxorpc/go-codegen v0.18.1 doesn't introduce breaking changes.

This is a minor version bump (v0.17.0 → v0.18.1). While generally safe under semantic versioning, code generation tools can have subtle breaking changes.

Please confirm:

  • Release notes or changelog for v0.18.1 and any intermediate versions don't indicate breaking changes
  • Generated code (if any) has been regenerated with the new version and is correct
  • All tests pass with the updated code generator

🌐 Web query:

utxorpc/go-codegen v0.18.1 release notes breaking changes

💡 Result:

I couldn't find a release named v0.18.1 for utxorpc/go-codegen. The repository's Releases list shows v0.17.0 as the latest (tagged Jul 7, 2025). [1][2]

If you meant a different tag/branch or a pre-release, tell me the exact tag or paste the release link and I’ll inspect it for breaking-change notes.

Sources:

  • utxorpc/go-codegen GitHub — Releases (shows v0.17.0 latest). [1]
  • Libraries.io entry for github.com/utxorpc/go-codegen. [2]

Dependency version v0.18.1 does not exist in utxorpc/go-codegen repository.

The latest release in the utxorpc/go-codegen repository is v0.17.0, but the PR updates go.mod to v0.18.1. This version does not appear to exist. Verify the intended target version and correct go.mod accordingly—either revert to v0.17.0 or use the correct version number if this is a typo.

🤖 Prompt for AI Agents
In go.mod around line 15, the dependency is set to github.com/utxorpc/go-codegen
v0.18.1 which does not exist; confirm the intended release (likely v0.17.0) by
checking the repository tags/releases, then update go.mod to the correct
existing version (e.g., v0.17.0) and run go get
github.com/utxorpc/go-codegen@<correct-version> followed by go mod tidy to
update go.sum and ensure the dependency resolves.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect. That version was released this morning.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🌐 Web query:

utxorpc go-codegen v0.18.1 November 2025 release

💡 Result:

Yes — utxorpc/go-codegen v0.18.1 was released on November 3, 2025. Changes are primarily dependency bumps (google.golang.org/protobuf and connectrpc/connect via dependabot). [1][2]

Sources:

  • GitHub Releases — utxorpc/go-codegen v0.18.1 (Nov 3, 2025). [1]
  • Libraries.io package page for github.com/utxorpc/go-codegen. [2]

@wolf31o2, you're absolutely right—I apologize for the incorrect information. v0.18.1 was indeed released on November 3, 2025, and the changes are primarily dependency bumps for google.golang.org/protobuf and connectrpc/connect.

The version bump looks good, and since it's a maintenance release with dependency updates, there shouldn't be any breaking changes to worry about. Thank you for the correction!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests are failing. Some changes may be necessary in the ledger/common package.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

# Find the ledger/common package files
echo "=== Files in ledger/common package ==="
fd -t f . ledger/common

echo -e "\n=== Searching for utxorpc imports in the codebase ==="
rg -n --type=go "github.com/utxorpc/go-codegen" -A 2

echo -e "\n=== Examining ledger/common package code for utxorpc usage ==="
fd -t f -e go . ledger/common --exec cat {}

echo -e "\n=== Checking for any test files in ledger/common ==="
fd -t f -e go . ledger/common | grep -i test

Length of output: 230971


🏁 Script executed:

#!/bin/bash

# Check if there's a go.sum to see the actual dependency changes
echo "=== Checking go.sum for utxorpc changes ==="
git diff HEAD go.sum | grep utxorpc || echo "No utxorpc changes visible in go.sum diff"

echo -e "\n=== Looking for utxorpc changelog or recent changes ==="
# Try to get release notes from GitHub
gh api repos/utxorpc/go-codegen/releases --jq '.[] | select(.tag_name == "v0.18.1" or .tag_name == "v0.18.0" or .tag_name == "v0.17.0") | {tag: .tag_name, date: .published_at, body: .body}' 2>/dev/null || echo "Could not fetch release notes"

echo -e "\n=== Checking for test failures by running tests ==="
# Run tests in ledger/common package to see actual errors
go test -v ./ledger/common/... 2>&1 | head -100

Length of output: 3911


🏁 Script executed:

#!/bin/bash

echo "=== Examining error locations in certs.go ==="
sed -n '585,600p' ledger/common/certs.go
echo ""
sed -n '755,770p' ledger/common/certs.go

echo -e "\n=== Examining error location in tx.go ==="
sed -n '235,245p' ledger/common/tx.go

echo -e "\n=== Searching for BigInt type definition in utxorpc ==="
# Look for BigInt in the downloaded utxorpc package
fd -t f -e go . $(go env GOPATH)/pkg/mod/github.com/utxorpc/go-codegen* 2>/dev/null | head -5 | xargs grep -l "type BigInt" 2>/dev/null | head -1 | xargs cat 2>/dev/null | grep -A 10 "type BigInt"

echo -e "\n=== Checking if there's a BigInt conversion helper ==="
rg -n "func.*BigInt" $(go env GOPATH)/pkg/mod/github.com/utxorpc/go-codegen* 2>/dev/null | head -10

Length of output: 3780


🏁 Script executed:

#!/bin/bash

echo "=== Looking for BigInt constructor patterns ==="
rg -A 5 "BigInt{" $(go env GOPATH)/pkg/mod/github.com/utxorpc/[email protected] 2>/dev/null | head -30

echo -e "\n=== Checking existing usage in other ledger eras ==="
# Check if other eras already handle this conversion
rg -n "BigInt" ledger/*/pparams.go ledger/*/babbage.go ledger/*/shelley.go 2>/dev/null | head -10

echo -e "\n=== Examining the full PoolRegistrationCert definition ==="
rg -A 20 "type PoolRegistrationCert struct" $(go env GOPATH)/pkg/mod/github.com/utxorpc/[email protected]/utxorpc/v1alpha/cardano/cardano.pb.go 2>/dev/null | head -30

echo -e "\n=== Examining the Tx Fee field definition ==="
rg -B 5 -A 5 "Fee.*BigInt" $(go env GOPATH)/pkg/mod/github.com/utxorpc/[email protected]/utxorpc/v1alpha/cardano/cardano.pb.go 2>/dev/null | head -20

Length of output: 4301


@wolf31o2, I've identified the test failures. The utxorpc/go-codegen v0.18.1 update changed several numeric fields from uint64/int64 to *cardano.BigInt pointers. Here are the specific changes needed in the ledger/common package:

Required Changes

File: ledger/common/certs.go

Lines 592-593 (PoolRegistrationCert):

// Change from:
Pledge:     c.Pledge,
Cost:       c.Cost,

// To:
Pledge:     &utxorpc.BigInt{BigInt: &utxorpc.BigInt_Int{Int: int64(c.Pledge)}},
Cost:       &utxorpc.BigInt{BigInt: &utxorpc.BigInt_Int{Int: int64(c.Cost)}},

Line 763 (MirCert):

// Change from:
DeltaCoin: int64(deltaCoin),

// To:
DeltaCoin: &utxorpc.BigInt{BigInt: &utxorpc.BigInt_Int{Int: int64(deltaCoin)}},

File: ledger/common/tx.go

Line 239 (Tx):

// Change from:
Fee: tx.Fee(),

// To:
Fee: &utxorpc.BigInt{BigInt: &utxorpc.BigInt_Int{Int: int64(tx.Fee())}},

Optional: Helper Function

For cleaner code, you could add a helper function at the top of ledger/common/certs.go:

// uint64ToBigInt converts a uint64 to a cardano.BigInt pointer
func uint64ToBigInt(val uint64) *utxorpc.BigInt {
	return &utxorpc.BigInt{BigInt: &utxorpc.BigInt_Int{Int: int64(val)}}
}

Then use it like:

Pledge: uint64ToBigInt(c.Pledge),
Cost:   uint64ToBigInt(c.Cost),

The changes are straightforward - the protobuf schema now uses BigInt to support arbitrarily large numbers, but for Cardano's typical values, they fit comfortably in int64, so we use the BigInt_Int variant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After making the requested changes, the tests are still failing.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash

echo "=== Running tests to see current failures ==="
go test -v ./ledger/common/... 2>&1 | head -150

echo -e "\n=== Checking current code at the error locations ==="
echo "--- certs.go lines 585-600 ---"
sed -n '585,600p' ledger/common/certs.go

echo -e "\n--- certs.go lines 755-770 ---"
sed -n '755,770p' ledger/common/certs.go

echo -e "\n--- tx.go lines 235-245 ---"
sed -n '235,245p' ledger/common/tx.go

echo -e "\n=== Searching for all utxorpc.BigInt usage patterns in codebase ==="
rg -n "utxorpc\.BigInt" --type=go -A 2 -B 2

echo -e "\n=== Checking the BigInt protobuf definition ==="
rg -A 15 "message BigInt" $(go env GOPATH)/pkg/mod/github.com/utxorpc/[email protected] 2>/dev/null | head -30

echo -e "\n=== Looking for all PoolRegistrationCert instantiations ==="
rg -n "PoolRegistrationCert\{" ledger/common/ -A 10

Length of output: 21312


🏁 Script executed:

#!/bin/bash

echo "=== Running complete test suite for ledger/common ==="
go test ./ledger/common/... 2>&1

echo -e "\n=== Test exit code: $? ==="

echo -e "\n=== Also checking if there are any test failures in other packages ==="
go test ./... 2>&1 | grep -E "(FAIL|PASS:|^ok |^FAIL)" | tail -50

Length of output: 1674


🏁 Script executed:

#!/bin/bash

echo "=== Checking build errors in ledger era packages ==="
echo "--- allegra ---"
go test -c ./ledger/allegra 2>&1 | head -20

echo -e "\n--- alonzo ---"
go test -c ./ledger/alonzo 2>&1 | head -20

echo -e "\n--- babbage ---"
go test -c ./ledger/babbage 2>&1 | head -20

echo -e "\n--- byron ---"
go test -c ./ledger/byron 2>&1 | head -20

echo -e "\n--- conway ---"
go test -c ./ledger/conway 2>&1 | head -20

echo -e "\n--- mary ---"
go test -c ./ledger/mary 2>&1 | head -20

echo -e "\n--- shelley ---"
go test -c ./ledger/shelley 2>&1 | head -20

echo -e "\n=== Checking localstatequery test failure ==="
go test -v ./protocol/localstatequery 2>&1

Length of output: 8595


@wolf31o2, I see the issue now. The ledger/common package tests pass, but the test files in all the ledger era packages (allegra, alonzo, babbage, byron, conway, mary, shelley) need to be updated to work with the new *cardano.BigInt type. Here's what needs to be done:

Required Test File Updates

The errors fall into two categories:

1. Creating BigInt values in test structs

When creating test PParams or Tx structs, integer literals need to be wrapped:

Pattern to find and replace:

// OLD:
MinFeeConstant: 500,
StakeKeyDeposit: 2000,
Fee: 100,
Coin: amount,

// NEW:
MinFeeConstant: &utxorpc.BigInt{BigInt: &utxorpc.BigInt_Int{Int: 500}},
StakeKeyDeposit: &utxorpc.BigInt{BigInt: &utxorpc.BigInt_Int{Int: 2000}},
Fee: &utxorpc.BigInt{BigInt: &utxorpc.BigInt_Int{Int: 100}},
Coin: &utxorpc.BigInt{BigInt: &utxorpc.BigInt_Int{Int: int64(amount)}},

2. Comparing BigInt values in assertions

Pattern to find and replace:

// OLD:
if got.Fee != 100 { ... }
if got.Outputs[0].Coin != 5000 { ... }
if actual.Fee != tx.Fee() { ... }

// NEW:
if got.Fee.BigInt.(*utxorpc.BigInt_Int).Int != 100 { ... }
if got.Outputs[0].Coin.BigInt.(*utxorpc.BigInt_Int).Int != 5000 { ... }
if got.Fee.BigInt.(*utxorpc.BigInt_Int).Int != int64(tx.Fee()) { ... }

3. Helper function for tests (recommended)

Add this helper function at the top of each *_test.go file that needs it:

// Helper function to create BigInt for tests
func testBigInt(val int64) *utxorpc.BigInt {
	return &utxorpc.BigInt{BigInt: &utxorpc.BigInt_Int{Int: val}}
}

// Helper function to extract int64 from BigInt for comparisons
func bigIntToInt64(bi *utxorpc.BigInt) int64 {
	if bi == nil {
		return 0
	}
	if i, ok := bi.BigInt.(*utxorpc.BigInt_Int); ok {
		return i.Int
	}
	return 0
}

Then use them like:

// Creating values:
MinFeeConstant: testBigInt(500),
Fee: testBigInt(100),
Coin: testBigInt(int64(amount)),

// Comparing values:
if bigIntToInt64(got.Fee) != 100 { ... }
if bigIntToInt64(got.Outputs[0].Coin) != 5000 { ... }

Affected Files

Based on the errors, you need to update these test files:

  • ledger/allegra/pparams_test.go (lines 96, 97, 101, 102, 174, 236)
  • ledger/alonzo/pparams_test.go (lines 377, 379, 380, 383, 384, 399, 479, 531, 547, 594+)
  • ledger/babbage/pparams_test.go (lines 484, 486, 487, 490, 491, 506, 603, 645, 654, 690+)
  • ledger/byron/byron_test.go (lines 66, 103)
  • ledger/conway/pparams_test.go (lines 529, 531, 532, 535, 536, 551, 665, 674, 742, 751+)
  • ledger/mary/pparams_test.go (lines 99, 100, 104, 105, 181, 223, 232, 271, 280, 480+)
  • ledger/shelley/pparams_test.go (lines 131, 132, 135, 136, 223, 281, 349)

Would you like me to generate the specific fixes for these files, or would you prefer to apply the patterns systematically yourself?

Note: The protocol/localstatequery test failure is unrelated to this PR—it's missing a test fixture file and appears to be a pre-existing issue.

go.uber.org/goleak v1.3.0
golang.org/x/crypto v0.43.0
google.golang.org/protobuf v1.36.10
)

require (
Expand All @@ -25,12 +26,10 @@ require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/decred/dcrd/crypto/blake256 v1.1.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.3.0 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/sys v0.37.0 // indirect
google.golang.org/protobuf v1.36.6 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEW
github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/gorilla/websocket v1.5.0/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
Expand Down Expand Up @@ -103,8 +103,8 @@ github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXl
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc=
github.com/utxorpc/go-codegen v0.17.0 h1:cJ7Df9r8Az39lveIcmzcRciIDc3UJFdMSmXg8IAtBPM=
github.com/utxorpc/go-codegen v0.17.0/go.mod h1:LBVGFns4YAHMhy+Pc8tF5ExkU+N8Wm3srst4omKZy4g=
github.com/utxorpc/go-codegen v0.18.1 h1:2eenzXCkqvB2+g8MCq70MBR6koWs9CeTihZ0AqUvLDY=
github.com/utxorpc/go-codegen v0.18.1/go.mod h1:DFij3zIGDM39BYCuzrz1rSuO3kTIIiHglWV0043wQxo=
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
Expand Down Expand Up @@ -143,8 +143,8 @@ google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQ
google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE=
google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo=
google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU=
google.golang.org/protobuf v1.36.6 h1:z1NpPI8ku2WgiWnf+t9wTPsn6eP1L7ksHUlkfLvd9xY=
google.golang.org/protobuf v1.36.6/go.mod h1:jduwjTPXsFjZGTmRluh+L6NjiWu7pchiJ2/5YcXBHnY=
google.golang.org/protobuf v1.36.10 h1:AYd7cD/uASjIL6Q9LiTjz8JLcrh/88q5UObnmY3aOOE=
google.golang.org/protobuf v1.36.10/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
Expand Down
24 changes: 18 additions & 6 deletions ledger/allegra/block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package allegra_test
import (
"bytes"
"encoding/hex"
"math/big"
"strings"
"testing"

Expand Down Expand Up @@ -150,12 +151,23 @@ func TestAllegraUtxorpcBlock(t *testing.T) {
0,
"Transaction should have outputs",
)
assert.Greater(
t,
firstRpcTx.Fee,
uint64(0),
"Transaction fee should be positive",
)
fee := firstRpcTx.Fee
if fee.GetInt() != 0 {
assert.Greater(
t,
fee.GetInt(),
int64(0),
"Transaction fee should be positive",
)
} else {
feeBigInt := new(big.Int).SetBytes(fee.GetBigUInt())
assert.Greater(
t,
feeBigInt.Sign(),
0,
"Transaction fee should be positive",
)
}
}
})
}
36 changes: 18 additions & 18 deletions ledger/allegra/pparams_test.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 Blink Labs Software
// Copyright 2025 Blink Labs Software
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
Expand All @@ -24,7 +24,7 @@ import (
"github.com/blinklabs-io/gouroboros/ledger/allegra"
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/blinklabs-io/gouroboros/ledger/shelley"
"github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

func TestAllegraProtocolParamsUpdate(t *testing.T) {
Expand Down Expand Up @@ -92,29 +92,29 @@ func TestAllegraUtxorpc(t *testing.T) {
MinUtxoValue: 1000000,
}

expectedUtxorpc := &cardano.PParams{
MinFeeCoefficient: 500,
MinFeeConstant: 2,
MaxBlockBodySize: 65536,
MaxTxSize: 16384,
MaxBlockHeaderSize: 1024,
StakeKeyDeposit: 2000,
PoolDeposit: 500000,
expectedUtxorpc := &utxorpc.PParams{
MinFeeCoefficient: common.ToUtxorpcBigInt(500),
MinFeeConstant: common.ToUtxorpcBigInt(2),
MaxBlockBodySize: 65536,
MaxTxSize: 16384,
MaxBlockHeaderSize: 1024,
StakeKeyDeposit: common.ToUtxorpcBigInt(2000),
PoolDeposit: common.ToUtxorpcBigInt(500000),
PoolRetirementEpochBound: 2160,
DesiredNumberOfPools: 100,
PoolInfluence: &cardano.RationalNumber{
PoolInfluence: &utxorpc.RationalNumber{
Numerator: int32(1),
Denominator: uint32(2),
},
MonetaryExpansion: &cardano.RationalNumber{
MonetaryExpansion: &utxorpc.RationalNumber{
Numerator: int32(3),
Denominator: uint32(4),
},
TreasuryExpansion: &cardano.RationalNumber{
TreasuryExpansion: &utxorpc.RationalNumber{
Numerator: int32(5),
Denominator: uint32(6),
},
ProtocolVersion: &cardano.ProtocolVersion{
ProtocolVersion: &utxorpc.ProtocolVersion{
Major: 8,
Minor: 0,
},
Expand Down Expand Up @@ -171,10 +171,10 @@ func TestAllegraTransactionBody_Utxorpc(t *testing.T) {
}

// Check that the fee matches
if actual.Fee != txBody.Fee() {
if actual.Fee.GetInt() != int64(txBody.Fee()) {
t.Errorf(
"AllegraTransactionBody.Utxorpc() fee mismatch\nGot: %d\nWant: %d",
actual.Fee,
actual.Fee.GetInt(),
txBody.Fee(),
)
}
Expand Down Expand Up @@ -233,10 +233,10 @@ func TestAllegraTransaction_Utxorpc(t *testing.T) {
t.Fatalf("Could not convert transaction to utxorpc format: %v", err)
}
// Assertion checks
if actual.Fee != tx.Fee() {
if actual.Fee.GetInt() != int64(tx.Fee()) {
t.Errorf(
"AllegraTransaction.Utxorpc() fee mismatch\nGot: %d\nWant: %d",
actual.Fee,
actual.Fee.GetInt(),
tx.Fee(),
)
}
Expand Down
8 changes: 5 additions & 3 deletions ledger/alonzo/alonzo.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,8 +454,10 @@ func (o AlonzoTransactionOutput) Utxorpc() (*utxorpc.TxOutput, error) {
for _, assetName := range tmpAssets.Assets(policyId) {
amount := tmpAssets.Asset(policyId, assetName)
asset := &utxorpc.Asset{
Name: assetName,
OutputCoin: amount,
Name: assetName,
Quantity: &utxorpc.Asset_OutputCoin{
OutputCoin: common.ToUtxorpcBigInt(amount),
},
}
ma.Assets = append(ma.Assets, asset)
}
Expand All @@ -476,7 +478,7 @@ func (o AlonzoTransactionOutput) Utxorpc() (*utxorpc.TxOutput, error) {

return &utxorpc.TxOutput{
Address: addressBytes,
Coin: o.Amount(),
Coin: common.ToUtxorpcBigInt(o.Amount()),
Assets: assets,
Datum: &utxorpc.Datum{
Hash: datumHash,
Expand Down
60 changes: 37 additions & 23 deletions ledger/alonzo/pparams.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/blinklabs-io/gouroboros/ledger/mary"
cardano "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

// Constants for Plutus version mapping
Expand Down Expand Up @@ -274,59 +274,73 @@ func (u *AlonzoProtocolParameterUpdate) UnmarshalCBOR(cborData []byte) error {
return nil
}

func (p *AlonzoProtocolParameters) Utxorpc() (*cardano.PParams, error) {
func (p *AlonzoProtocolParameters) Utxorpc() (*utxorpc.PParams, error) {
// sanity check
if p.A0.Num().Int64() > math.MaxInt32 ||
if p.A0 == nil ||
p.A0.Num().Int64() < math.MinInt32 ||
p.A0.Num().Int64() > math.MaxInt32 ||
p.A0.Denom().Int64() < 0 ||
p.A0.Denom().Int64() > math.MaxUint32 {
return nil, errors.New("invalid A0 rational number values")
}
if p.Rho.Num().Int64() > math.MaxInt32 ||
if p.Rho == nil ||
p.Rho.Num().Int64() < math.MinInt32 ||
p.Rho.Num().Int64() > math.MaxInt32 ||
p.Rho.Denom().Int64() < 0 ||
p.Rho.Denom().Int64() > math.MaxUint32 {
return nil, errors.New("invalid Rho rational number values")
}
if p.Tau.Num().Int64() > math.MaxInt32 ||
if p.Tau == nil ||
p.Tau.Num().Int64() < math.MinInt32 ||
p.Tau.Num().Int64() > math.MaxInt32 ||
p.Tau.Denom().Int64() < 0 ||
p.Tau.Denom().Int64() > math.MaxUint32 {
return nil, errors.New("invalid Tau rational number values")
}
if p.ExecutionCosts.MemPrice.Num().Int64() > math.MaxInt32 ||
if p.ExecutionCosts.MemPrice == nil ||
p.ExecutionCosts.MemPrice.Num().Int64() < math.MinInt32 ||
p.ExecutionCosts.MemPrice.Num().Int64() > math.MaxInt32 ||
p.ExecutionCosts.MemPrice.Denom().Int64() < 0 ||
p.ExecutionCosts.MemPrice.Denom().Int64() > math.MaxUint32 {
return nil, errors.New("invalid memory price rational number values")
}
if p.ExecutionCosts.StepPrice.Num().Int64() > math.MaxInt32 ||
if p.ExecutionCosts.StepPrice == nil ||
p.ExecutionCosts.StepPrice.Num().Int64() < math.MinInt32 ||
p.ExecutionCosts.StepPrice.Num().Int64() > math.MaxInt32 ||
p.ExecutionCosts.StepPrice.Denom().Int64() < 0 ||
p.ExecutionCosts.StepPrice.Denom().Int64() > math.MaxUint32 {
return nil, errors.New("invalid step price rational number values")
}
if p.MaxTxExUnits.Memory < 0 || p.MaxTxExUnits.Steps < 0 ||
p.MaxBlockExUnits.Memory < 0 || p.MaxBlockExUnits.Steps < 0 {
return nil, errors.New("invalid execution unit values")
}
// #nosec G115
return &cardano.PParams{
CoinsPerUtxoByte: p.AdaPerUtxoByte,
return &utxorpc.PParams{
CoinsPerUtxoByte: common.ToUtxorpcBigInt(p.AdaPerUtxoByte),
MaxTxSize: uint64(p.MaxTxSize),
MinFeeCoefficient: uint64(p.MinFeeA),
MinFeeConstant: uint64(p.MinFeeB),
MinFeeCoefficient: common.ToUtxorpcBigInt(uint64(p.MinFeeA)),
MinFeeConstant: common.ToUtxorpcBigInt(uint64(p.MinFeeB)),
MaxBlockBodySize: uint64(p.MaxBlockBodySize),
MaxBlockHeaderSize: uint64(p.MaxBlockHeaderSize),
StakeKeyDeposit: uint64(p.KeyDeposit),
PoolDeposit: uint64(p.PoolDeposit),
StakeKeyDeposit: common.ToUtxorpcBigInt(uint64(p.KeyDeposit)),
PoolDeposit: common.ToUtxorpcBigInt(uint64(p.PoolDeposit)),
MinPoolCost: common.ToUtxorpcBigInt(p.MinPoolCost),
PoolRetirementEpochBound: uint64(p.MaxEpoch),
DesiredNumberOfPools: uint64(p.NOpt),
PoolInfluence: &cardano.RationalNumber{
PoolInfluence: &utxorpc.RationalNumber{
Numerator: int32(p.A0.Num().Int64()),
Denominator: uint32(p.A0.Denom().Int64()),
},
MonetaryExpansion: &cardano.RationalNumber{
MonetaryExpansion: &utxorpc.RationalNumber{
Numerator: int32(p.Rho.Num().Int64()),
Denominator: uint32(p.Rho.Denom().Int64()),
},
TreasuryExpansion: &cardano.RationalNumber{
TreasuryExpansion: &utxorpc.RationalNumber{
Numerator: int32(p.Tau.Num().Int64()),
Denominator: uint32(p.Tau.Denom().Int64()),
},
MinPoolCost: p.MinPoolCost,
ProtocolVersion: &cardano.ProtocolVersion{
ProtocolVersion: &utxorpc.ProtocolVersion{
Major: uint32(p.ProtocolMajor),
Minor: uint32(p.ProtocolMinor),
},
Expand All @@ -336,21 +350,21 @@ func (p *AlonzoProtocolParameters) Utxorpc() (*cardano.PParams, error) {
CostModels: common.ConvertToUtxorpcCardanoCostModels(
p.CostModels,
),
Prices: &cardano.ExPrices{
Memory: &cardano.RationalNumber{
Prices: &utxorpc.ExPrices{
Memory: &utxorpc.RationalNumber{
Numerator: int32(p.ExecutionCosts.MemPrice.Num().Int64()),
Denominator: uint32(p.ExecutionCosts.MemPrice.Denom().Int64()),
},
Steps: &cardano.RationalNumber{
Steps: &utxorpc.RationalNumber{
Numerator: int32(p.ExecutionCosts.StepPrice.Num().Int64()),
Denominator: uint32(p.ExecutionCosts.StepPrice.Denom().Int64()),
},
},
MaxExecutionUnitsPerTransaction: &cardano.ExUnits{
MaxExecutionUnitsPerTransaction: &utxorpc.ExUnits{
Memory: uint64(p.MaxTxExUnits.Memory),
Steps: uint64(p.MaxTxExUnits.Steps),
},
MaxExecutionUnitsPerBlock: &cardano.ExUnits{
MaxExecutionUnitsPerBlock: &utxorpc.ExUnits{
Memory: uint64(p.MaxBlockExUnits.Memory),
Steps: uint64(p.MaxBlockExUnits.Steps),
},
Expand Down
Loading
Loading