diff options
| author | Andrew Chow <[email protected]> | 2017-07-10 18:31:57 -0700 |
|---|---|---|
| committer | Andrew Chow <[email protected]> | 2017-07-27 15:04:00 -0700 |
| commit | e222dc2aee263bf28cf19689b9c9ed97da054682 (patch) | |
| tree | de4ea9cb1cb903a0916c7b355cebd98e51545a76 /src | |
| parent | Merge #10747: [rpc] fix verbose argument for getblock in bitcoin-cli (diff) | |
| download | discoin-e222dc2aee263bf28cf19689b9c9ed97da054682.tar.xz discoin-e222dc2aee263bf28cf19689b9c9ed97da054682.zip | |
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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/wallet/rpcwallet.cpp | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/src/wallet/rpcwallet.cpp b/src/wallet/rpcwallet.cpp index 867ccd424..246d81fd5 100644 --- a/src/wallet/rpcwallet.cpp +++ b/src/wallet/rpcwallet.cpp @@ -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; |