mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-04-27 20:31:44 +02:00
refactor: rename scriptPubKey in VerifyWitnessProgram to exec_script
The old name is confusing, as it doesn't store a scriptPubKey, but the actually executed script.
This commit is contained in:
parent
107b57df9f
commit
8bd2b4e784
@ -1524,7 +1524,7 @@ static bool ExecuteWitnessScript(const Span<const valtype>& stack_span, const CS
|
|||||||
|
|
||||||
static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion, const std::vector<unsigned char>& program, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror)
|
static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion, const std::vector<unsigned char>& program, unsigned int flags, const BaseSignatureChecker& checker, ScriptError* serror)
|
||||||
{
|
{
|
||||||
CScript scriptPubKey;
|
CScript exec_script; //!< Actually executed script (last stack item in P2WSH; implied P2PKH script in P2WPKH)
|
||||||
Span<const valtype> stack{witness.stack};
|
Span<const valtype> stack{witness.stack};
|
||||||
|
|
||||||
if (witversion == 0) {
|
if (witversion == 0) {
|
||||||
@ -1534,20 +1534,20 @@ static bool VerifyWitnessProgram(const CScriptWitness& witness, int witversion,
|
|||||||
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_WITNESS_EMPTY);
|
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_WITNESS_EMPTY);
|
||||||
}
|
}
|
||||||
const valtype& script_bytes = SpanPopBack(stack);
|
const valtype& script_bytes = SpanPopBack(stack);
|
||||||
scriptPubKey = CScript(script_bytes.begin(), script_bytes.end());
|
exec_script = CScript(script_bytes.begin(), script_bytes.end());
|
||||||
uint256 hashScriptPubKey;
|
uint256 hash_exec_script;
|
||||||
CSHA256().Write(&scriptPubKey[0], scriptPubKey.size()).Finalize(hashScriptPubKey.begin());
|
CSHA256().Write(&exec_script[0], exec_script.size()).Finalize(hash_exec_script.begin());
|
||||||
if (memcmp(hashScriptPubKey.begin(), program.data(), 32)) {
|
if (memcmp(hash_exec_script.begin(), program.data(), 32)) {
|
||||||
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
|
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH);
|
||||||
}
|
}
|
||||||
return ExecuteWitnessScript(stack, scriptPubKey, flags, SigVersion::WITNESS_V0, checker, serror);
|
return ExecuteWitnessScript(stack, exec_script, flags, SigVersion::WITNESS_V0, checker, serror);
|
||||||
} else if (program.size() == WITNESS_V0_KEYHASH_SIZE) {
|
} else if (program.size() == WITNESS_V0_KEYHASH_SIZE) {
|
||||||
// Special case for pay-to-pubkeyhash; signature + pubkey in witness
|
// Special case for pay-to-pubkeyhash; signature + pubkey in witness
|
||||||
if (stack.size() != 2) {
|
if (stack.size() != 2) {
|
||||||
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH); // 2 items in witness
|
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_MISMATCH); // 2 items in witness
|
||||||
}
|
}
|
||||||
scriptPubKey << OP_DUP << OP_HASH160 << program << OP_EQUALVERIFY << OP_CHECKSIG;
|
exec_script << OP_DUP << OP_HASH160 << program << OP_EQUALVERIFY << OP_CHECKSIG;
|
||||||
return ExecuteWitnessScript(stack, scriptPubKey, flags, SigVersion::WITNESS_V0, checker, serror);
|
return ExecuteWitnessScript(stack, exec_script, flags, SigVersion::WITNESS_V0, checker, serror);
|
||||||
} else {
|
} else {
|
||||||
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_WRONG_LENGTH);
|
return set_error(serror, SCRIPT_ERR_WITNESS_PROGRAM_WRONG_LENGTH);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user