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

Method IsCollateralValid

src/darksend.cpp:954–1004  ·  view source on GitHub ↗

check to make sure the collateral provided by the client is valid

Source from the content-addressed store, hash-verified

952
953// check to make sure the collateral provided by the client is valid
954bool CDarkSendPool::IsCollateralValid(const CTransaction& txCollateral) {
955 if (txCollateral.vout.size() < 1) return false;
956 if (txCollateral.nLockTime != 0) return false;
957
958 int64_t nValueIn = 0;
959 int64_t nValueOut = 0;
960 bool missingTx = false;
961
962 for (const CTxOut o : txCollateral.vout) {
963 nValueOut += o.nValue;
964
965 if (!o.scriptPubKey.IsNormalPaymentScript()) {
966 LogPrintf ("CDarkSendPool::IsCollateralValid - Invalid Script %s\n", txCollateral.ToString().c_str());
967 return false;
968 }
969 }
970
971 for (const CTxIn i : txCollateral.vin) {
972 CTransaction tx2;
973 uint256 hash;
974 if (GetTransaction(i.prevout.hash, tx2, Params().GetConsensus(), hash)) {
975 if (tx2.vout.size() > i.prevout.n) {
976 nValueIn += tx2.vout[i.prevout.n].nValue;
977 }
978 } else {
979 missingTx = true;
980 }
981 }
982
983 if (missingTx) {
984 if (fDebug) LogPrintf ("CDarkSendPool::IsCollateralValid - Unknown inputs in collateral transaction - %s\n", txCollateral.ToString().c_str());
985 return false;
986 }
987
988 //collateral transactions are required to pay out DARKSEND_COLLATERAL as a fee to the miners
989 if (nValueIn - nValueOut < DARKSEND_COLLATERAL) {
990 if (fDebug) LogPrintf ("CDarkSendPool::IsCollateralValid - did not include enough fees in transaction %d\n%s\n", nValueOut - nValueIn, txCollateral.ToString().c_str());
991 return false;
992 }
993
994 if (fDebug) LogPrintf("CDarkSendPool::IsCollateralValid %s\n", txCollateral.ToString().c_str());
995
996 CValidationState state;
997 bool* pfMissingInputs = nullptr;
998 if (!AcceptableInputs(mempool, state, txCollateral, false, pfMissingInputs)) {
999 if (fDebug) LogPrintf ("CDarkSendPool::IsCollateralValid - didn't pass IsAcceptable\n");
1000 return false;
1001 }
1002
1003 return true;
1004}
1005
1006
1007//

Callers

nothing calls this directly

Calls 6

GetTransactionFunction · 0.85
AcceptableInputsFunction · 0.85
IsNormalPaymentScriptMethod · 0.80
ParamsClass · 0.70
sizeMethod · 0.45
ToStringMethod · 0.45

Tested by

no test coverage detected