MCPcopy Create free account
hub / github.com/LUX-Core/lux / CheckTransaction

Function CheckTransaction

src/main.cpp:868–925  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

866}
867
868bool CheckTransaction(const CTransaction& tx, CValidationState& state)
869{
870 // Basic checks that don't depend on any context
871 if (tx.vin.empty())
872 return state.DoS(10, false, REJECT_INVALID, "bad-txns-vin-empty");
873
874 if (tx.vout.empty())
875 return state.DoS(10, false, REJECT_INVALID, "bad-txns-vout-empty");
876
877 // Size limits (this doesn't take the witness into account, as that hasn't been checked for malleability)
878 if (::GetSerializeSize(tx, SER_NETWORK, PROTOCOL_VERSION | SERIALIZE_TRANSACTION_NO_WITNESS) > MAX_BLOCK_BASE_SIZE)
879 return state.DoS(100, false, REJECT_INVALID, "bad-txns-oversize");
880
881 // Check for negative or overflow output values
882 CAmount nValueOut = 0;
883 for (const auto& txout : tx.vout) {
884 if (txout.nValue < 0)
885 return state.DoS(100, false, REJECT_INVALID, "bad-txns-vout-negative");
886
887 if (txout.nValue > MAX_MONEY)
888 return state.DoS(100, false, REJECT_INVALID, "bad-txns-vout-toolarge");
889
890 nValueOut += txout.nValue;
891 if (!MoneyRange(nValueOut))
892 return state.DoS(100, false, REJECT_INVALID, "bad-txns-txouttotal-toolarge");
893
894 /////////////////////////////////////////////////////////// // lux
895 if (txout.scriptPubKey.HasOpCall() || txout.scriptPubKey.HasOpCreate()) {
896 std::vector<valtype> vSolutions;
897 txnouttype whichType;
898 if (!Solver(txout.scriptPubKey, whichType, vSolutions, true)) {
899 return state.DoS(100, false, REJECT_INVALID, "bad-txns-contract-nonstandard");
900 }
901 }
902 ///////////////////////////////////////////////////////////
903 }
904
905
906 // Check for duplicate inputs
907 set<COutPoint> vInOutPoints;
908 for (const CTxIn& txin : tx.vin) {
909 if (vInOutPoints.count(txin.prevout))
910 return state.DoS(100, error("CheckTransaction() : duplicate inputs"),
911 REJECT_INVALID, "bad-txns-inputs-duplicate");
912 vInOutPoints.insert(txin.prevout);
913 }
914
915 if (tx.IsCoinBase()) {
916 if (/*tx.vin[0].scriptSig.size() < 2 || */ tx.vin[0].scriptSig.size() > 150)
917 return state.DoS(100, false, REJECT_INVALID, "bad-cb-length");
918 } else {
919 for (const CTxIn& txin : tx.vin)
920 if (txin.prevout.IsNull())
921 return state.DoS(10, false, REJECT_INVALID, "bad-txns-prevout-null");
922 }
923
924 return true;
925}

Callers 4

ReadKeyValueFunction · 0.70
AcceptToMemoryPoolFunction · 0.70
AcceptableInputsFunction · 0.70
CheckBlockFunction · 0.70

Calls 13

GetSerializeSizeFunction · 0.85
MoneyRangeFunction · 0.85
SolverFunction · 0.85
errorFunction · 0.85
DoSMethod · 0.80
HasOpCallMethod · 0.80
HasOpCreateMethod · 0.80
emptyMethod · 0.45
countMethod · 0.45
insertMethod · 0.45
IsCoinBaseMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected