Skip to content

Commit 808ea9d

Browse files
committed
feat: helper function to convert TransactionInput to PlutusData
NOTE: this updates the required Go version to 1.24 because plutigo requires it Fixes #1099 Signed-off-by: Aurora Gaffney <[email protected]>
1 parent e08f93d commit 808ea9d

File tree

8 files changed

+88
-9
lines changed

8 files changed

+88
-9
lines changed

.github/workflows/go-test.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ jobs:
1616
name: go-test
1717
strategy:
1818
matrix:
19-
go-version: [1.23.x, 1.24.x]
19+
# TODO: go back to last 2 versions once 1.25 is released
20+
go-version: [1.24.x]
2021
platform: [ubuntu-latest]
2122
runs-on: ${{ matrix.platform }}
2223
steps:

.github/workflows/golangci-lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ jobs:
1818
- uses: actions/checkout@v4
1919
- uses: actions/setup-go@v5
2020
with:
21-
go-version: 1.23.x
21+
go-version: 1.24.x
2222
- name: golangci-lint
2323
uses: golangci/golangci-lint-action@v8

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
module github.com/blinklabs-io/gouroboros
22

3-
go 1.23.6
3+
go 1.24.0
44

55
toolchain go1.24.1
66

77
require (
88
filippo.io/edwards25519 v1.1.0
99
github.com/blinklabs-io/ouroboros-mock v0.3.8
10+
github.com/blinklabs-io/plutigo v0.0.2-0.20250716022656-7418e5ead692
1011
github.com/btcsuite/btcd/btcutil v1.1.6
1112
github.com/fxamacker/cbor/v2 v2.8.0
1213
github.com/jinzhu/copier v0.4.0
1314
github.com/stretchr/testify v1.10.0
1415
github.com/utxorpc/go-codegen v0.16.0
1516
go.uber.org/goleak v1.3.0
16-
golang.org/x/crypto v0.39.0
17+
golang.org/x/crypto v0.40.0
1718
)
1819

1920
require (
@@ -22,7 +23,7 @@ require (
2223
github.com/kr/text v0.2.0 // indirect
2324
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
2425
github.com/x448/float16 v0.8.4 // indirect
25-
golang.org/x/sys v0.33.0 // indirect
26+
golang.org/x/sys v0.34.0 // indirect
2627
google.golang.org/protobuf v1.36.3 // indirect
2728
gopkg.in/yaml.v3 v3.0.1 // indirect
2829
)

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4
33
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
44
github.com/blinklabs-io/ouroboros-mock v0.3.8 h1:+DAt2rx0ouZUxee5DBMgZq3I1+ZdxFSHG9g3tYl/FKU=
55
github.com/blinklabs-io/ouroboros-mock v0.3.8/go.mod h1:UwQIf4KqZwO13P9d90fbi3UL/X7JaJfeEbqk+bEeFQA=
6+
github.com/blinklabs-io/plutigo v0.0.2-0.20250716022656-7418e5ead692 h1:irMl0GGNv5heP8LpYBG4Z+a/RYqmmHVESZEa/Ba/67s=
7+
github.com/blinklabs-io/plutigo v0.0.2-0.20250716022656-7418e5ead692/go.mod h1:Bh2zD801zEN90MIFv78HF1d3c/RpG/GD18wQrbdeN+0=
68
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
79
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
810
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A=
@@ -95,8 +97,8 @@ go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
9597
golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
9698
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
9799
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
98-
golang.org/x/crypto v0.39.0 h1:SHs+kF4LP+f+p14esP5jAoDpHU8Gu/v9lFRK6IT5imM=
99-
golang.org/x/crypto v0.39.0/go.mod h1:L+Xg3Wf6HoL4Bn4238Z6ft6KfEpN0tJGo53AAPC632U=
100+
golang.org/x/crypto v0.40.0 h1:r4x+VvoG5Fm+eJcxMaY8CQM7Lb0l1lsmjGBQ6s8BfKM=
101+
golang.org/x/crypto v0.40.0/go.mod h1:Qr1vMER5WyS2dfPHAlsOj01wgLbsyWtFn/aY+5+ZdxY=
100102
golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
101103
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
102104
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
@@ -112,8 +114,8 @@ golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7w
112114
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
113115
golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
114116
golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
115-
golang.org/x/sys v0.33.0 h1:q3i8TbbEz+JRD9ywIRlyRAQbM0qF7hu24q3teo2hbuw=
116-
golang.org/x/sys v0.33.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
117+
golang.org/x/sys v0.34.0 h1:H5Y5sJ2L2JRdyv7ROF1he/lPdvFsd0mJHFw2ThKHxLA=
118+
golang.org/x/sys v0.34.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
117119
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
118120
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
119121
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=

ledger/byron/byron.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import (
1919
"errors"
2020
"fmt"
2121
"math"
22+
"math/big"
2223

2324
"github.com/blinklabs-io/gouroboros/cbor"
2425
"github.com/blinklabs-io/gouroboros/ledger/common"
26+
"github.com/blinklabs-io/plutigo/pkg/data"
2527
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
2628
)
2729

@@ -377,6 +379,16 @@ func (i ByronTransactionInput) Utxorpc() (*utxorpc.TxInput, error) {
377379
}, nil
378380
}
379381

382+
func (i ByronTransactionInput) ToPlutusData() data.PlutusData {
383+
// This will never actually get called, but it's identical to Shelley
384+
return data.NewConstr(
385+
0,
386+
[]data.PlutusData{
387+
data.NewByteString(i.TxId.Bytes()),
388+
data.NewInteger(big.NewInt(int64(i.OutputIndex))),
389+
},
390+
)
391+
}
380392
func (i ByronTransactionInput) String() string {
381393
return fmt.Sprintf("%s#%d", i.TxId, i.OutputIndex)
382394
}

ledger/common/tx.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ package common
1616

1717
import (
1818
"github.com/blinklabs-io/gouroboros/cbor"
19+
"github.com/blinklabs-io/plutigo/pkg/data"
1920
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
2021
)
2122

@@ -61,6 +62,7 @@ type TransactionInput interface {
6162
Index() uint32
6263
String() string
6364
Utxorpc() (*utxorpc.TxInput, error)
65+
ToPlutusData() data.PlutusData
6466
}
6567

6668
type TransactionOutput interface {

ledger/shelley/shelley.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@ import (
1919
"errors"
2020
"fmt"
2121
"math"
22+
"math/big"
2223

2324
"github.com/blinklabs-io/gouroboros/cbor"
2425
"github.com/blinklabs-io/gouroboros/ledger/common"
26+
"github.com/blinklabs-io/plutigo/pkg/data"
2527
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
2628
)
2729

@@ -367,6 +369,16 @@ func (i ShelleyTransactionInput) Utxorpc() (*utxorpc.TxInput, error) {
367369
}, nil
368370
}
369371

372+
func (i ShelleyTransactionInput) ToPlutusData() data.PlutusData {
373+
return data.NewConstr(
374+
0,
375+
[]data.PlutusData{
376+
data.NewByteString(i.TxId.Bytes()),
377+
data.NewInteger(big.NewInt(int64(i.OutputIndex))),
378+
},
379+
)
380+
}
381+
370382
func (i ShelleyTransactionInput) String() string {
371383
return fmt.Sprintf("%s#%d", i.TxId, i.OutputIndex)
372384
}

ledger/shelley/tx_test.go

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright 2025 Blink Labs Software
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package shelley_test
16+
17+
import (
18+
"encoding/hex"
19+
"math/big"
20+
"reflect"
21+
"testing"
22+
23+
"github.com/blinklabs-io/gouroboros/ledger/shelley"
24+
"github.com/blinklabs-io/plutigo/pkg/data"
25+
)
26+
27+
func TestShelleyTransactionInputToPlutusData(t *testing.T) {
28+
testTxIdHex := "1639f61ed08f5e489dd64db20f86451a0db06e83d21ea39c73ea0a93b478a370"
29+
testTxOutputIdx := 2
30+
testInput := shelley.NewShelleyTransactionInput(
31+
testTxIdHex,
32+
testTxOutputIdx,
33+
)
34+
testTxId, err := hex.DecodeString(testTxIdHex)
35+
if err != nil {
36+
t.Fatalf("unexpected error: %s", err)
37+
}
38+
expectedData := data.NewConstr(
39+
0,
40+
[]data.PlutusData{
41+
data.NewByteString(testTxId),
42+
data.NewInteger(big.NewInt(int64(testTxOutputIdx))),
43+
},
44+
)
45+
tmpData := testInput.ToPlutusData()
46+
if !reflect.DeepEqual(tmpData, expectedData) {
47+
t.Fatalf("did not get expected PlutusData\n got: %#v\n wanted: %#v", tmpData, expectedData)
48+
}
49+
}

0 commit comments

Comments
 (0)