mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-11-11 14:38:29 +01:00
Abstract out IsSolvable from Witnessifier
This commit is contained in:
@@ -422,3 +422,22 @@ bool DummySignatureCreator::CreateSig(std::vector<unsigned char>& vchSig, const
|
||||
vchSig[6 + 33 + 32] = SIGHASH_ALL;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsSolvable(const CKeyStore& store, const CScript& script)
|
||||
{
|
||||
// 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 transaction. In particular,
|
||||
// it will reject witness outputs that require signing with an uncompressed public key.
|
||||
DummySignatureCreator creator(&store);
|
||||
SignatureData sigs;
|
||||
// Make sure that STANDARD_SCRIPT_VERIFY_FLAGS includes SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, the most
|
||||
// important property this function is designed to test for.
|
||||
static_assert(STANDARD_SCRIPT_VERIFY_FLAGS & SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, "IsSolvable requires standard script flags to include WITNESS_PUBKEYTYPE");
|
||||
if (ProduceSignature(creator, script, sigs)) {
|
||||
// VerifyScript check is just defensive, and should never fail.
|
||||
assert(VerifyScript(sigs.scriptSig, script, &sigs.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker()));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -81,4 +81,10 @@ SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignature
|
||||
SignatureData DataFromTransaction(const CMutableTransaction& tx, unsigned int nIn);
|
||||
void UpdateTransaction(CMutableTransaction& tx, unsigned int nIn, const SignatureData& data);
|
||||
|
||||
/* Check whether we know how to sign for an output like this, assuming we
|
||||
* have all private keys. While this function does not need private keys, the passed
|
||||
* keystore is used to look up public keys and redeemscripts by hash.
|
||||
* Solvability is unrelated to whether we consider this output to be ours. */
|
||||
bool IsSolvable(const CKeyStore& store, const CScript& script);
|
||||
|
||||
#endif // BITCOIN_SCRIPT_SIGN_H
|
||||
|
||||
Reference in New Issue
Block a user