Skip to content

Commit 5ac0b20

Browse files
authored
feat(ledger): verify transaction function (#1306)
Signed-off-by: Chris Gianelloni <[email protected]>
1 parent ff1094d commit 5ac0b20

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

ledger/common/rules.go

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

1717
type UtxoValidationRuleFunc func(Transaction, uint64, LedgerState, ProtocolParameters) error
1818

19+
// VerifyTransaction validates a transaction against the given validation rules.
20+
// It runs all provided UtxoValidationRuleFunc functions and returns the first error encountered,
21+
// or nil if all validations pass.
22+
func VerifyTransaction(
23+
tx Transaction,
24+
slot uint64,
25+
ledgerState LedgerState,
26+
protocolParams ProtocolParameters,
27+
validationRules []UtxoValidationRuleFunc,
28+
) error {
29+
for _, rule := range validationRules {
30+
if err := rule(tx, slot, ledgerState, protocolParams); err != nil {
31+
return err
32+
}
33+
}
34+
return nil
35+
}
36+
1937
// CalculateMinFee computes the minimum fee for a transaction body given its CBOR-encoded size
2038
// and the protocol parameters MinFeeA and MinFeeB
2139
func CalculateMinFee(bodySize int, minFeeA uint, minFeeB uint) uint64 {

0 commit comments

Comments
 (0)