Remove unnecessary genesis hash check in IsConfirmedBitcoinBlock

This commit is contained in:
Jonas Nick 2017-09-11 18:09:23 +02:00
parent 42b6330e14
commit 25c8a49b32
4 changed files with 9 additions and 21 deletions

View file

@ -178,27 +178,15 @@ UniValue CallRPC(const std::string& strMethod, const UniValue& params, bool conn
return reply; return reply;
} }
bool IsConfirmedBitcoinBlock(const uint256& genesishash, const uint256& hash, int nMinConfirmationDepth) bool IsConfirmedBitcoinBlock(const uint256& hash, int nMinConfirmationDepth)
{ {
try { try {
UniValue params(UniValue::VARR); UniValue params(UniValue::VARR);
params.push_back(UniValue(0)); params.push_back(hash.GetHex());
UniValue reply = CallRPC("getblockhash", params, true); UniValue reply = CallRPC("getblockheader", params, true);
if (!find_value(reply, "error").isNull()) if (!find_value(reply, "error").isNull())
return false; return false;
UniValue result = find_value(reply, "result"); UniValue result = find_value(reply, "result");
if (!result.isStr())
return false;
if (result.get_str() != genesishash.GetHex())
return false;
params = UniValue(UniValue::VARR);
params.push_back(hash.GetHex());
reply = CallRPC("getblockheader", params, true);
if (!find_value(reply, "error").isNull())
return false;
result = find_value(reply, "result");
if (!result.isObject()) if (!result.isObject())
return false; return false;
result = find_value(result.get_obj(), "confirmations"); result = find_value(result.get_obj(), "confirmations");

View file

@ -35,6 +35,6 @@ public:
}; };
UniValue CallRPC(const std::string& strMethod, const UniValue& params, bool connectToMainchain=false); UniValue CallRPC(const std::string& strMethod, const UniValue& params, bool connectToMainchain=false);
bool IsConfirmedBitcoinBlock(const uint256& genesishash, const uint256& hash, int nMinConfirmationDepth); bool IsConfirmedBitcoinBlock(const uint256& hash, int nMinConfirmationDepth);
#endif // BITCOIN_CALLRPC_H #endif // BITCOIN_CALLRPC_H

View file

@ -1580,7 +1580,7 @@ bool EvalScript(vector<vector<unsigned char> >& stack, const CScript& script, un
return set_error(serror, SCRIPT_ERR_WITHDRAW_VERIFY_OUTPUT_SCRIPT); return set_error(serror, SCRIPT_ERR_WITHDRAW_VERIFY_OUTPUT_SCRIPT);
#ifndef BITCOIN_SCRIPT_NO_CALLRPC #ifndef BITCOIN_SCRIPT_NO_CALLRPC
if (GetBoolArg("-validatepegin", DEFAULT_VALIDATE_PEGIN) && !checker.IsConfirmedBitcoinBlock(genesishash, merkleBlock.header.GetHash(), flags & SCRIPT_VERIFY_INCREASE_CONFIRMATIONS_REQUIRED, GetArg("-peginconfirmationdepth", DEFAULT_PEGIN_CONFIRMATION_DEPTH))) if (GetBoolArg("-validatepegin", DEFAULT_VALIDATE_PEGIN) && !checker.IsConfirmedBitcoinBlock(merkleBlock.header.GetHash(), flags & SCRIPT_VERIFY_INCREASE_CONFIRMATIONS_REQUIRED, GetArg("-peginconfirmationdepth", DEFAULT_PEGIN_CONFIRMATION_DEPTH)))
return set_error(serror, SCRIPT_ERR_WITHDRAW_VERIFY_BLOCKCONFIRMED); return set_error(serror, SCRIPT_ERR_WITHDRAW_VERIFY_BLOCKCONFIRMED);
#endif #endif
} catch (std::exception& e) { } catch (std::exception& e) {
@ -1975,10 +1975,10 @@ CConfidentialValue TransactionSignatureChecker::GetValueInPrevIn() const
return amountPreviousInput; return amountPreviousInput;
} }
bool TransactionSignatureChecker::IsConfirmedBitcoinBlock(const uint256& genesishash, const uint256& hash, bool fConservativeConfirmationRequirements, uint32_t nConfirmationsRequired) const bool TransactionSignatureChecker::IsConfirmedBitcoinBlock(const uint256& hash, bool fConservativeConfirmationRequirements, uint32_t nConfirmationsRequired) const
{ {
#ifndef BITCOIN_SCRIPT_NO_CALLRPC #ifndef BITCOIN_SCRIPT_NO_CALLRPC
return ::IsConfirmedBitcoinBlock(genesishash, hash, nConfirmationsRequired + (fConservativeConfirmationRequirements ? 2 : 0)); return ::IsConfirmedBitcoinBlock(hash, nConfirmationsRequired + (fConservativeConfirmationRequirements ? 2 : 0));
#else #else
return true; return true;
#endif #endif

View file

@ -171,7 +171,7 @@ public:
return -1; return -1;
} }
virtual bool IsConfirmedBitcoinBlock(const uint256& genesishash, const uint256& hash, bool fConservativeConfirmationRequirements, uint32_t nConfirmationsRequired) const virtual bool IsConfirmedBitcoinBlock(const uint256& hash, bool fConservativeConfirmationRequirements, uint32_t nConfirmationsRequired) const
{ {
return false; return false;
} }
@ -219,7 +219,7 @@ public:
COutPoint GetPrevOut() const; COutPoint GetPrevOut() const;
CConfidentialValue GetValueIn() const; CConfidentialValue GetValueIn() const;
CConfidentialValue GetValueInPrevIn() const; CConfidentialValue GetValueInPrevIn() const;
bool IsConfirmedBitcoinBlock(const uint256& genesishash, const uint256& hash, bool fConservativeConfirmationRequirements, uint32_t nConfirmationsRequired) const; bool IsConfirmedBitcoinBlock(const uint256& hash, bool fConservativeConfirmationRequirements, uint32_t nConfirmationsRequired) const;
virtual CScript GetFedpegScript() const virtual CScript GetFedpegScript() const
{ {
return fedpegScript; return fedpegScript;