Skip to content

Commit 44eb8bd

Browse files
authored
feat: Babbage era 'Utxo' validation rules (#930)
Fixes #879 Signed-off-by: Aurora Gaffney <[email protected]>
1 parent 99ef8cb commit 44eb8bd

File tree

6 files changed

+1929
-25
lines changed

6 files changed

+1929
-25
lines changed

ledger/allegra/rules.go

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,16 +111,7 @@ func UtxoValidateValueNotConservedUtxo(
111111
ls common.LedgerState,
112112
pp common.ProtocolParameters,
113113
) error {
114-
tmpPparams, ok := pp.(*AllegraProtocolParameters)
115-
if !ok {
116-
return errors.New("pparams are not expected type")
117-
}
118-
return shelley.UtxoValidateValueNotConservedUtxo(
119-
tx,
120-
slot,
121-
ls,
122-
&tmpPparams.ShelleyProtocolParameters,
123-
)
114+
return shelley.UtxoValidateValueNotConservedUtxo(tx, slot, ls, pp)
124115
}
125116

126117
func UtxoValidateOutputTooSmallUtxo(

ledger/alonzo/rules.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,16 +192,13 @@ func UtxoValidateNoCollateralInputs(tx common.Transaction, slot uint64, ls commo
192192
}
193193
return NoCollateralInputsError{}
194194
}
195+
195196
func UtxoValidateBadInputsUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
196197
return shelley.UtxoValidateBadInputsUtxo(tx, slot, ls, pp)
197198
}
198199

199200
func UtxoValidateValueNotConservedUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {
200-
tmpPparams, ok := pp.(*AlonzoProtocolParameters)
201-
if !ok {
202-
return errors.New("pparams are not expected type")
203-
}
204-
return shelley.UtxoValidateValueNotConservedUtxo(tx, slot, ls, &tmpPparams.ShelleyProtocolParameters)
201+
return shelley.UtxoValidateValueNotConservedUtxo(tx, slot, ls, pp)
205202
}
206203

207204
func UtxoValidateOutputTooSmallUtxo(tx common.Transaction, slot uint64, ls common.LedgerState, pp common.ProtocolParameters) error {

ledger/babbage/errors.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 babbage
16+
17+
import (
18+
"fmt"
19+
"strings"
20+
21+
"github.com/blinklabs-io/gouroboros/ledger/common"
22+
)
23+
24+
type NonDisjointRefInputsError struct {
25+
Inputs []common.TransactionInput
26+
}
27+
28+
func (e NonDisjointRefInputsError) Error() string {
29+
tmpInputs := make([]string, 0, len(e.Inputs))
30+
for idx, tmpInput := range e.Inputs {
31+
tmpInputs[idx] = tmpInput.String()
32+
}
33+
return "non-disjoint reference inputs: " + strings.Join(tmpInputs, ", ")
34+
}
35+
36+
type TooManyCollateralInputsError struct {
37+
Provided uint
38+
Max uint
39+
}
40+
41+
func (e TooManyCollateralInputsError) Error() string {
42+
return fmt.Sprintf(
43+
"too many collateral inputs: provided %d, maximum %d",
44+
e.Provided,
45+
e.Max,
46+
)
47+
}
48+
49+
type IncorrectTotalCollateralFieldError struct {
50+
Provided uint64
51+
TotalCollateral uint64
52+
}
53+
54+
func (e IncorrectTotalCollateralFieldError) Error() string {
55+
return fmt.Sprintf(
56+
"incorrect total collateral field: provided %d, total collateral %d",
57+
e.Provided,
58+
e.TotalCollateral,
59+
)
60+
}

0 commit comments

Comments
 (0)