mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-12 23:18:14 +01:00
Replace ismine with producesignature check in witnessifier
Instead of using ismine to check whether an address can be spent by us, make the witness version of the script or address first and then use ProduceSignature with the DummySignatureCreator to check if we can solve for the script. Also fixes test cases to reflect this change.
This commit is contained in:
@@ -1067,11 +1067,15 @@ public:
|
||||
bool operator()(const CKeyID &keyID) {
|
||||
if (pwallet) {
|
||||
CScript basescript = GetScriptForDestination(keyID);
|
||||
isminetype typ;
|
||||
typ = IsMine(*pwallet, basescript, SIGVERSION_WITNESS_V0);
|
||||
if (typ != ISMINE_SPENDABLE && typ != ISMINE_WATCH_SOLVABLE)
|
||||
return false;
|
||||
CScript witscript = GetScriptForWitness(basescript);
|
||||
SignatureData sigs;
|
||||
// This check is to make sure that the script we created can actually be solved for and signed by us
|
||||
// if we were to have the private keys. This is just to make sure that the script is valid and that,
|
||||
// if found in a transaction, we would still accept and relay that transcation.
|
||||
if (!ProduceSignature(DummySignatureCreator(pwallet), witscript, sigs) ||
|
||||
!VerifyScript(sigs.scriptSig, witscript, &sigs.scriptWitness, MANDATORY_SCRIPT_VERIFY_FLAGS | SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, DummySignatureCreator(pwallet).Checker())) {
|
||||
return false;
|
||||
}
|
||||
pwallet->AddCScript(witscript);
|
||||
result = CScriptID(witscript);
|
||||
return true;
|
||||
@@ -1088,11 +1092,15 @@ public:
|
||||
result = scriptID;
|
||||
return true;
|
||||
}
|
||||
isminetype typ;
|
||||
typ = IsMine(*pwallet, subscript, SIGVERSION_WITNESS_V0);
|
||||
if (typ != ISMINE_SPENDABLE && typ != ISMINE_WATCH_SOLVABLE)
|
||||
return false;
|
||||
CScript witscript = GetScriptForWitness(subscript);
|
||||
SignatureData sigs;
|
||||
// This check is to make sure that the script we created can actually be solved for and signed by us
|
||||
// if we were to have the private keys. This is just to make sure that the script is valid and that,
|
||||
// if found in a transaction, we would still accept and relay that transcation.
|
||||
if (!ProduceSignature(DummySignatureCreator(pwallet), witscript, sigs) ||
|
||||
!VerifyScript(sigs.scriptSig, witscript, &sigs.scriptWitness, MANDATORY_SCRIPT_VERIFY_FLAGS | SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, DummySignatureCreator(pwallet).Checker())) {
|
||||
return false;
|
||||
}
|
||||
pwallet->AddCScript(witscript);
|
||||
result = CScriptID(witscript);
|
||||
return true;
|
||||
|
||||
Reference in New Issue
Block a user