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
3 changes: 2 additions & 1 deletion .github/workflows/go-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ jobs:
name: go-test
strategy:
matrix:
go-version: [1.23.x, 1.24.x]
# TODO: go back to last 2 versions once 1.25 is released
go-version: [1.24.x]
platform: [ubuntu-latest]
runs-on: ${{ matrix.platform }}
steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ jobs:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: 1.23.x
go-version: 1.24.x
- name: golangci-lint
uses: golangci/golangci-lint-action@v8
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
module github.com/blinklabs-io/gouroboros

go 1.23.6
go 1.24.0

toolchain go1.24.1

require (
filippo.io/edwards25519 v1.1.0
github.com/blinklabs-io/ouroboros-mock v0.3.8
github.com/blinklabs-io/plutigo v0.0.2-0.20250716022656-7418e5ead692
github.com/btcsuite/btcd/btcutil v1.1.6
github.com/fxamacker/cbor/v2 v2.9.0
github.com/jinzhu/copier v0.4.0
Expand Down
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4
github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII=
github.com/blinklabs-io/ouroboros-mock v0.3.8 h1:+DAt2rx0ouZUxee5DBMgZq3I1+ZdxFSHG9g3tYl/FKU=
github.com/blinklabs-io/ouroboros-mock v0.3.8/go.mod h1:UwQIf4KqZwO13P9d90fbi3UL/X7JaJfeEbqk+bEeFQA=
github.com/blinklabs-io/plutigo v0.0.1 h1:IBM3+dm7Sy92zgm9SBvIwVXN/73Jvg/ipDwbgRDeVFo=
github.com/blinklabs-io/plutigo v0.0.1/go.mod h1:N7id3F9kjRcvm/BMxwZsBWUSJTGsUEwVRfFz3Tt5LPM=
github.com/blinklabs-io/plutigo v0.0.2-0.20250716022656-7418e5ead692 h1:irMl0GGNv5heP8LpYBG4Z+a/RYqmmHVESZEa/Ba/67s=
github.com/blinklabs-io/plutigo v0.0.2-0.20250716022656-7418e5ead692/go.mod h1:Bh2zD801zEN90MIFv78HF1d3c/RpG/GD18wQrbdeN+0=
github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ=
github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M=
github.com/btcsuite/btcd v0.23.5-0.20231215221805-96c9fd8078fd/go.mod h1:nm3Bko6zh6bWP60UxwoT5LzdGJsQJaPo6HjduXq9p6A=
Expand Down
13 changes: 13 additions & 0 deletions ledger/byron/byron.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import (
"errors"
"fmt"
"math"
"math/big"

"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/blinklabs-io/plutigo/pkg/data"
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

Expand Down Expand Up @@ -377,6 +379,17 @@ func (i ByronTransactionInput) Utxorpc() (*utxorpc.TxInput, error) {
}, nil
}

func (i ByronTransactionInput) ToPlutusData() data.PlutusData {
// This will never actually get called, but it's identical to Shelley
return data.NewConstr(
0,
[]data.PlutusData{
data.NewByteString(i.TxId.Bytes()),
data.NewInteger(big.NewInt(int64(i.OutputIndex))),
},
)
}

func (i ByronTransactionInput) String() string {
return fmt.Sprintf("%s#%d", i.TxId, i.OutputIndex)
}
Expand Down
2 changes: 2 additions & 0 deletions ledger/common/tx.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package common

import (
"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/plutigo/pkg/data"
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

Expand Down Expand Up @@ -61,6 +62,7 @@ type TransactionInput interface {
Index() uint32
String() string
Utxorpc() (*utxorpc.TxInput, error)
ToPlutusData() data.PlutusData
}

type TransactionOutput interface {
Expand Down
12 changes: 12 additions & 0 deletions ledger/shelley/shelley.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ import (
"errors"
"fmt"
"math"
"math/big"

"github.com/blinklabs-io/gouroboros/cbor"
"github.com/blinklabs-io/gouroboros/ledger/common"
"github.com/blinklabs-io/plutigo/pkg/data"
utxorpc "github.com/utxorpc/go-codegen/utxorpc/v1alpha/cardano"
)

Expand Down Expand Up @@ -367,6 +369,16 @@ func (i ShelleyTransactionInput) Utxorpc() (*utxorpc.TxInput, error) {
}, nil
}

func (i ShelleyTransactionInput) ToPlutusData() data.PlutusData {
return data.NewConstr(
0,
[]data.PlutusData{
data.NewByteString(i.TxId.Bytes()),
data.NewInteger(big.NewInt(int64(i.OutputIndex))),
},
)
}

func (i ShelleyTransactionInput) String() string {
return fmt.Sprintf("%s#%d", i.TxId, i.OutputIndex)
}
Expand Down
49 changes: 49 additions & 0 deletions ledger/shelley/tx_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// 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.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package shelley_test

import (
"encoding/hex"
"math/big"
"reflect"
"testing"

"github.com/blinklabs-io/gouroboros/ledger/shelley"
"github.com/blinklabs-io/plutigo/pkg/data"
)

func TestShelleyTransactionInputToPlutusData(t *testing.T) {
testTxIdHex := "1639f61ed08f5e489dd64db20f86451a0db06e83d21ea39c73ea0a93b478a370"
testTxOutputIdx := 2
testInput := shelley.NewShelleyTransactionInput(
testTxIdHex,
testTxOutputIdx,
)
testTxId, err := hex.DecodeString(testTxIdHex)
if err != nil {
t.Fatalf("unexpected error: %s", err)
}
expectedData := data.NewConstr(
0,
[]data.PlutusData{
data.NewByteString(testTxId),
data.NewInteger(big.NewInt(int64(testTxOutputIdx))),
},
)
tmpData := testInput.ToPlutusData()
if !reflect.DeepEqual(tmpData, expectedData) {
t.Fatalf("did not get expected PlutusData\n got: %#v\n wanted: %#v", tmpData, expectedData)
}
}