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
15 changes: 0 additions & 15 deletions ledger/babbage/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,8 @@ package babbage

import (
"fmt"
"strings"

"github.com/blinklabs-io/gouroboros/ledger/common"
)

type NonDisjointRefInputsError struct {
Inputs []common.TransactionInput
}

func (e NonDisjointRefInputsError) Error() string {
tmpInputs := make([]string, 0, len(e.Inputs))
for idx, tmpInput := range e.Inputs {
tmpInputs[idx] = tmpInput.String()
}
return "non-disjoint reference inputs: " + strings.Join(tmpInputs, ", ")
}

type TooManyCollateralInputsError struct {
Provided uint
Max uint
Expand Down
19 changes: 0 additions & 19 deletions ledger/babbage/rules.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import (
)

var UtxoValidationRules = []common.UtxoValidationRuleFunc{
UtxoValidateDisjointRefInputs,
UtxoValidateOutsideValidityIntervalUtxo,
UtxoValidateInputSetEmptyUtxo,
UtxoValidateFeeTooSmallUtxo,
Expand All @@ -46,24 +45,6 @@ var UtxoValidationRules = []common.UtxoValidationRuleFunc{
UtxoValidateTooManyCollateralInputs,
}

func UtxoValidateDisjointRefInputs(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
commonInputs := []common.TransactionInput{}
for _, refInput := range tx.ReferenceInputs() {
for _, input := range tx.Inputs() {
if refInput.String() != input.String() {
continue
}
commonInputs = append(commonInputs, input)
}
}
if len(commonInputs) == 0 {
return nil
}
return NonDisjointRefInputsError{
Inputs: commonInputs,
}
}

func UtxoValidateOutsideValidityIntervalUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
return allegra.UtxoValidateOutsideValidityIntervalUtxo(tx, slot, ls, pp)
}
Expand Down
71 changes: 0 additions & 71 deletions ledger/babbage/rules_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1290,77 +1290,6 @@ func TestUtxoValidateExUnitsTooBigUtxo(t *testing.T) {
)
}

func TestUtxoValidateDisjointRefInputs(t *testing.T) {
testInputTxId := "d228b482a1aae768e4a796380f49e021d9c21f70d3c12cb186b188dedfc0ee22"
testTx := &babbage.BabbageTransaction{
Body: babbage.BabbageTransactionBody{},
}
testLedgerState := testLedgerState{}
testSlot := uint64(0)
testProtocolParams := &babbage.BabbageProtocolParameters{}
// Non-disjoint ref inputs
t.Run(
"non-disjoint ref inputs",
func(t *testing.T) {
testTx.Body.TxInputs = shelley.NewShelleyTransactionInputSet(
[]shelley.ShelleyTransactionInput{
shelley.NewShelleyTransactionInput(testInputTxId, 0),
},
)
testTx.Body.TxReferenceInputs = []shelley.ShelleyTransactionInput{
shelley.NewShelleyTransactionInput(testInputTxId, 0),
}
err := babbage.UtxoValidateDisjointRefInputs(
testTx,
testSlot,
testLedgerState,
testProtocolParams,
)
if err == nil {
t.Errorf(
"UtxoValidateDisjointRefInputs should fail when inputs and ref inputs are duplicated",
)
return
}
testErrType := babbage.NonDisjointRefInputsError{}
assert.IsType(
t,
testErrType,
err,
"did not get expected error type: got %T, wanted %T",
err,
testErrType,
)
},
)
// Disjoint ref inputs
t.Run(
"disjoint ref inputs",
func(t *testing.T) {
testTx.Body.TxInputs = shelley.NewShelleyTransactionInputSet(
[]shelley.ShelleyTransactionInput{
shelley.NewShelleyTransactionInput(testInputTxId, 0),
},
)
testTx.Body.TxReferenceInputs = []shelley.ShelleyTransactionInput{
shelley.NewShelleyTransactionInput(testInputTxId, 1),
}
err := babbage.UtxoValidateDisjointRefInputs(
testTx,
testSlot,
testLedgerState,
testProtocolParams,
)
if err != nil {
t.Errorf(
"UtxoValidateDisjointRefInputs should succeed when inputs and ref inputs are not duplicated\n got error: %v",
err,
)
}
},
)
}

func TestUtxoValidateCollateralEqBalance(t *testing.T) {
testInputTxId := "d228b482a1aae768e4a796380f49e021d9c21f70d3c12cb186b188dedfc0ee22"
var testInputAmount uint64 = 20_000_000
Expand Down
14 changes: 14 additions & 0 deletions ledger/conway/conway.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,15 @@ type ConwayTransactionInputSet struct {
items []shelley.ShelleyTransactionInput
}

func NewConwayTransactionInputSet(
items []shelley.ShelleyTransactionInput,
) ConwayTransactionInputSet {
s := ConwayTransactionInputSet{
items: items,
}
return s
}

func (s *ConwayTransactionInputSet) UnmarshalCBOR(data []byte) error {
// This overrides the Shelley behavior that explicitly disallowed tag-wrapped sets
var tmpData []shelley.ShelleyTransactionInput
Expand All @@ -250,6 +259,11 @@ func (s *ConwayTransactionInputSet) Items() []shelley.ShelleyTransactionInput {
return s.items
}

func (s *ConwayTransactionInputSet) SetItems(items []shelley.ShelleyTransactionInput) {
s.items = make([]shelley.ShelleyTransactionInput, len(items))
copy(s.items, items)
}

type ConwayTransactionBody struct {
babbage.BabbageTransactionBody
TxInputs ConwayTransactionInputSet `cbor:"0,keyasint,omitempty"`
Expand Down
33 changes: 33 additions & 0 deletions ledger/conway/errors.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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 conway

import (
"strings"

"github.com/blinklabs-io/gouroboros/ledger/common"
)

type NonDisjointRefInputsError struct {
Inputs []common.TransactionInput
}

func (e NonDisjointRefInputsError) Error() string {
tmpInputs := make([]string, 0, len(e.Inputs))
for idx, tmpInput := range e.Inputs {
tmpInputs[idx] = tmpInput.String()
}
return "non-disjoint reference inputs: " + strings.Join(tmpInputs, ", ")
}
Loading