@@ -904,50 +904,37 @@ func (eval *BlockEvaluator) ResetTxnBytes() {
904
904
eval .blockTxBytes = 0
905
905
}
906
906
907
- // TestEvalContext defines the evaluation context required by TestBlockEvaluator
908
- // to check for well-formedness and duplicate detection.
909
- type TestEvalContext interface {
910
- Proto () config.ConsensusParams
911
- Specials () transactions.SpecialAddresses
912
- TxnContext () transactions.TxnContext
913
- CheckDup (firstValid , lastValid basics.Round , txid transactions.Txid , txl ledgercore.Txlease ) error
914
- }
915
-
916
- // Proto implements the TestEvalContext interface.
917
- func (eval * BlockEvaluator ) Proto () config.ConsensusParams { return eval .proto }
918
-
919
- // Specials implements the TestEvalContext interface.
920
- func (eval * BlockEvaluator ) Specials () transactions.SpecialAddresses { return eval .specials }
921
-
922
- // TxnContext implements the TestEvalContext interface.
923
- func (eval * BlockEvaluator ) TxnContext () transactions.TxnContext { return eval .block }
924
-
925
- // CheckDup implements the TestEvalContext interface.
926
- func (eval * BlockEvaluator ) CheckDup (firstValid , lastValid basics.Round , txid transactions.Txid , txl ledgercore.Txlease ) error {
927
- return eval .state .checkDup (firstValid , lastValid , txid , txl )
928
- }
929
-
930
907
// TestTransactionGroup is only called by tests.
931
908
func (eval * BlockEvaluator ) TestTransactionGroup (txgroup []transactions.SignedTxn ) error {
932
- return TestBlockEvaluator {eval }.TestTransactionGroup (txgroup )
909
+ return TransactionGroupTester {
910
+ Proto : eval .proto ,
911
+ Specials : eval .specials ,
912
+ TxnContext : eval .block ,
913
+ CheckDup : eval .state .checkDup ,
914
+ }.TestTransactionGroup (txgroup )
933
915
}
934
916
935
- // TestBlockEvaluator uses a TestEvalContext to perform basic transaction checks.
936
- type TestBlockEvaluator struct { TestEvalContext }
917
+ // TransactionGroupTester performs basic transaction checks for well-formedness and duplicate detection.
918
+ type TransactionGroupTester struct {
919
+ CheckDup func (firstValid , lastValid basics.Round , txid transactions.Txid , txl ledgercore.Txlease ) error
920
+ TxnContext transactions.TxnContext
921
+ Proto config.ConsensusParams
922
+ Specials transactions.SpecialAddresses
923
+ }
937
924
938
925
// TestTransactionGroup performs basic duplicate detection and well-formedness checks
939
926
// on a transaction group, but does not actually add the transactions to the block
940
927
// evaluator, or modify the block evaluator state in any other visible way.
941
928
// It uses a TestEvalContext to access needed recent ledger state.
942
- func (eval TestBlockEvaluator ) TestTransactionGroup (txgroup []transactions.SignedTxn ) error {
929
+ func (eval TransactionGroupTester ) TestTransactionGroup (txgroup []transactions.SignedTxn ) error {
943
930
// Nothing to do if there are no transactions.
944
931
if len (txgroup ) == 0 {
945
932
return nil
946
933
}
947
934
948
- if len (txgroup ) > eval .Proto () .MaxTxGroupSize {
935
+ if len (txgroup ) > eval .Proto .MaxTxGroupSize {
949
936
return & ledgercore.TxGroupMalformedError {
950
- Msg : fmt .Sprintf ("group size %d exceeds maximum %d" , len (txgroup ), eval .Proto () .MaxTxGroupSize ),
937
+ Msg : fmt .Sprintf ("group size %d exceeds maximum %d" , len (txgroup ), eval .Proto .MaxTxGroupSize ),
951
938
Reason : ledgercore .TxGroupMalformedErrorReasonExceedMaxSize ,
952
939
}
953
940
}
@@ -998,14 +985,14 @@ func (eval TestBlockEvaluator) TestTransactionGroup(txgroup []transactions.Signe
998
985
// TestTransaction performs basic duplicate detection and well-formedness checks
999
986
// on a single transaction, but does not actually add the transaction to the block
1000
987
// evaluator, or modify the block evaluator state in any other visible way.
1001
- func (eval TestBlockEvaluator ) TestTransaction (txn transactions.SignedTxn ) error {
988
+ func (eval TransactionGroupTester ) TestTransaction (txn transactions.SignedTxn ) error {
1002
989
// Transaction valid (not expired)?
1003
- err := txn .Txn .Alive (eval .TxnContext () )
990
+ err := txn .Txn .Alive (eval .TxnContext )
1004
991
if err != nil {
1005
992
return err
1006
993
}
1007
994
1008
- err = txn .Txn .WellFormed (eval .Specials () , eval .Proto () )
995
+ err = txn .Txn .WellFormed (eval .Specials , eval .Proto )
1009
996
if err != nil {
1010
997
txnErr := ledgercore .TxnNotWellFormedError (fmt .Sprintf ("transaction %v: malformed: %v" , txn .ID (), err ))
1011
998
return & txnErr
0 commit comments