@@ -812,65 +812,60 @@ unsigned int GetP2SHSigOpCount(const CTransaction& tx, const CCoinsViewCache& in
812812
813813
814814
815+ namespace Consensus {
815816
817+ const ValidationResult CheckTx (const CTransaction& tx);
816818
819+ } // namespace Consensus
817820
818-
819- bool CheckTransaction (const CTransaction& tx, CValidationState &state)
821+ const ValidationResult Consensus::CheckTx (const CTransaction& tx)
820822{
821823 // Basic checks that don't depend on any context
822824 if (tx.vin .empty ())
823- return state.DoS (10 , error (" CheckTransaction() : vin empty" ),
824- REJECT_INVALID, " bad-txns-vin-empty" );
825+ return ValidationResult (10 , false , strprintf (" %s: vin empty" , __func__), REJECT_INVALID, " bad-txns-vin-empty" );
825826 if (tx.vout .empty ())
826- return state.DoS (10 , error (" CheckTransaction() : vout empty" ),
827- REJECT_INVALID, " bad-txns-vout-empty" );
827+ return ValidationResult (10 , false , strprintf (" %s: vout empty" , __func__), REJECT_INVALID, " bad-txns-vout-empty" );
828828 // Size limits
829829 if (::GetSerializeSize (tx, SER_NETWORK, PROTOCOL_VERSION) > MAX_BLOCK_SIZE)
830- return state.DoS (100 , error (" CheckTransaction() : size limits failed" ),
831- REJECT_INVALID, " bad-txns-oversize" );
830+ return ValidationResult (100 , false , strprintf (" %s: size limits failed" , __func__), REJECT_INVALID, " bad-txns-oversize" );
832831
833832 // Check for negative or overflow output values
834833 CAmount nValueOut = 0 ;
835- BOOST_FOREACH (const CTxOut& txout, tx.vout )
836- {
837- if (txout.nValue < 0 )
838- return state.DoS (100 , error (" CheckTransaction() : txout.nValue negative" ),
839- REJECT_INVALID, " bad-txns-vout-negative" );
840- if (txout.nValue > MAX_MONEY)
841- return state.DoS (100 , error (" CheckTransaction() : txout.nValue too high" ),
842- REJECT_INVALID, " bad-txns-vout-toolarge" );
843- nValueOut += txout.nValue ;
834+ for (unsigned int i = 0 ; i < tx.vout .size (); i++) {
835+ if (tx.vout [i].nValue < 0 )
836+ return ValidationResult (100 , false , strprintf (" %s: txout.nValue negative" , __func__), REJECT_INVALID, " bad-txns-vout-negative" );
837+ if (tx.vout [i].nValue > MAX_MONEY)
838+ return ValidationResult (100 , false , strprintf (" %s: txout.nValue too high" , __func__), REJECT_INVALID, " bad-txns-vout-toolarge" );
839+ nValueOut += tx.vout [i].nValue ;
844840 if (!MoneyRange (nValueOut))
845- return state.DoS (100 , error (" CheckTransaction() : txout total out of range" ),
846- REJECT_INVALID, " bad-txns-txouttotal-toolarge" );
841+ return ValidationResult (100 , false , strprintf (" %s: txout total out of range" , __func__), REJECT_INVALID, " bad-txns-txouttotal-toolarge" );
847842 }
848843
849844 // Check for duplicate inputs
850- set<COutPoint> vInOutPoints;
851- BOOST_FOREACH (const CTxIn& txin, tx.vin )
852- {
853- if (vInOutPoints.count (txin.prevout ))
854- return state.DoS (100 , error (" CheckTransaction() : duplicate inputs" ),
855- REJECT_INVALID, " bad-txns-inputs-duplicate" );
856- vInOutPoints.insert (txin.prevout );
845+ std::set<COutPoint> vInOutPoints;
846+ for (unsigned int i = 0 ; i < tx.vin .size (); i++) {
847+ if (vInOutPoints.count (tx.vin [i].prevout ))
848+ return ValidationResult (100 , false , strprintf (" %s: duplicate inputs" , __func__), REJECT_INVALID, " bad-txns-inputs-duplicate" );
849+ vInOutPoints.insert (tx.vin [i].prevout );
857850 }
858851
859852 if (tx.IsCoinBase ())
860853 {
861854 if (tx.vin [0 ].scriptSig .size () < 2 || tx.vin [0 ].scriptSig .size () > 100 )
862- return state.DoS (100 , error (" CheckTransaction() : coinbase script size" ),
863- REJECT_INVALID, " bad-cb-length" );
855+ return ValidationResult (100 , false , strprintf (" %s: coinbase script size" , __func__), REJECT_INVALID, " bad-cb-length" );
864856 }
865857 else
866858 {
867- BOOST_FOREACH (const CTxIn& txin, tx.vin )
868- if (txin.prevout .IsNull ())
869- return state.DoS (10 , error (" CheckTransaction() : prevout is null" ),
870- REJECT_INVALID, " bad-txns-prevout-null" );
859+ for (unsigned int i = 0 ; i < tx.vin .size (); i++)
860+ if (tx.vin [i].prevout .IsNull ())
861+ return ValidationResult (10 , false , strprintf (" %s: prevout is null" , __func__), REJECT_INVALID, " bad-txns-prevout-null" );
871862 }
863+ return ValidationResult (0 , true );
864+ }
872865
873- return true ;
866+ bool CheckTransaction (const CTransaction& tx, CValidationState &state)
867+ {
868+ return state.ApplyResult (Consensus::CheckTx (tx));
874869}
875870
876871CAmount GetMinRelayFee (const CTransaction& tx, unsigned int nBytes, bool fAllowFree )
0 commit comments