mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-25 10:43:19 -03:00
Make DummySignatureCreator a singleton
This commit is contained in:
parent
190b8d2dcf
commit
be67831210
4 changed files with 26 additions and 33 deletions
|
@ -146,7 +146,7 @@ isminetype IsMine(const CKeyStore &keystore, const CScript& scriptPubKey, bool&
|
||||||
if (keystore.HaveWatchOnly(scriptPubKey)) {
|
if (keystore.HaveWatchOnly(scriptPubKey)) {
|
||||||
// TODO: This could be optimized some by doing some work after the above solver
|
// TODO: This could be optimized some by doing some work after the above solver
|
||||||
SignatureData sigs;
|
SignatureData sigs;
|
||||||
return ProduceSignature(keystore, DummySignatureCreator(), scriptPubKey, sigs) ? ISMINE_WATCH_SOLVABLE : ISMINE_WATCH_UNSOLVABLE;
|
return ProduceSignature(keystore, DUMMY_SIGNATURE_CREATOR, scriptPubKey, sigs) ? ISMINE_WATCH_SOLVABLE : ISMINE_WATCH_UNSOLVABLE;
|
||||||
}
|
}
|
||||||
return ISMINE_NO;
|
return ISMINE_NO;
|
||||||
}
|
}
|
||||||
|
|
|
@ -392,39 +392,37 @@ SignatureData CombineSignatures(const CScript& scriptPubKey, const BaseSignature
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
/** Dummy signature checker which accepts all signatures. */
|
/** Dummy signature checker which accepts all signatures. */
|
||||||
class DummySignatureChecker : public BaseSignatureChecker
|
class DummySignatureChecker final : public BaseSignatureChecker
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
DummySignatureChecker() {}
|
DummySignatureChecker() {}
|
||||||
|
bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const override { return true; }
|
||||||
|
};
|
||||||
|
const DummySignatureChecker DUMMY_CHECKER;
|
||||||
|
|
||||||
bool CheckSig(const std::vector<unsigned char>& scriptSig, const std::vector<unsigned char>& vchPubKey, const CScript& scriptCode, SigVersion sigversion) const override
|
class DummySignatureCreator final : public BaseSignatureCreator {
|
||||||
|
public:
|
||||||
|
DummySignatureCreator() {}
|
||||||
|
const BaseSignatureChecker& Checker() const override { return DUMMY_CHECKER; }
|
||||||
|
bool CreateSig(const SigningProvider& provider, std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const override
|
||||||
{
|
{
|
||||||
|
// Create a dummy signature that is a valid DER-encoding
|
||||||
|
vchSig.assign(72, '\000');
|
||||||
|
vchSig[0] = 0x30;
|
||||||
|
vchSig[1] = 69;
|
||||||
|
vchSig[2] = 0x02;
|
||||||
|
vchSig[3] = 33;
|
||||||
|
vchSig[4] = 0x01;
|
||||||
|
vchSig[4 + 33] = 0x02;
|
||||||
|
vchSig[5 + 33] = 32;
|
||||||
|
vchSig[6 + 33] = 0x01;
|
||||||
|
vchSig[6 + 33 + 32] = SIGHASH_ALL;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const DummySignatureChecker dummyChecker;
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
const BaseSignatureChecker& DummySignatureCreator::Checker() const
|
|
||||||
{
|
|
||||||
return dummyChecker;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DummySignatureCreator::CreateSig(const SigningProvider& provider, std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const
|
const BaseSignatureCreator& DUMMY_SIGNATURE_CREATOR = DummySignatureCreator();
|
||||||
{
|
|
||||||
// Create a dummy signature that is a valid DER-encoding
|
|
||||||
vchSig.assign(72, '\000');
|
|
||||||
vchSig[0] = 0x30;
|
|
||||||
vchSig[1] = 69;
|
|
||||||
vchSig[2] = 0x02;
|
|
||||||
vchSig[3] = 33;
|
|
||||||
vchSig[4] = 0x01;
|
|
||||||
vchSig[4 + 33] = 0x02;
|
|
||||||
vchSig[5 + 33] = 32;
|
|
||||||
vchSig[6 + 33] = 0x01;
|
|
||||||
vchSig[6 + 33 + 32] = SIGHASH_ALL;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool IsSolvable(const SigningProvider& provider, const CScript& script)
|
bool IsSolvable(const SigningProvider& provider, const CScript& script)
|
||||||
{
|
{
|
||||||
|
@ -432,14 +430,13 @@ bool IsSolvable(const SigningProvider& provider, const CScript& script)
|
||||||
// if we were to have the private keys. This is just to make sure that the script is valid and that,
|
// 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,
|
// 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.
|
// it will reject witness outputs that require signing with an uncompressed public key.
|
||||||
static const DummySignatureCreator creator;
|
|
||||||
SignatureData sigs;
|
SignatureData sigs;
|
||||||
// Make sure that STANDARD_SCRIPT_VERIFY_FLAGS includes SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, the most
|
// Make sure that STANDARD_SCRIPT_VERIFY_FLAGS includes SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, the most
|
||||||
// important property this function is designed to test for.
|
// 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");
|
static_assert(STANDARD_SCRIPT_VERIFY_FLAGS & SCRIPT_VERIFY_WITNESS_PUBKEYTYPE, "IsSolvable requires standard script flags to include WITNESS_PUBKEYTYPE");
|
||||||
if (ProduceSignature(provider, creator, script, sigs)) {
|
if (ProduceSignature(provider, DUMMY_SIGNATURE_CREATOR, script, sigs)) {
|
||||||
// VerifyScript check is just defensive, and should never fail.
|
// VerifyScript check is just defensive, and should never fail.
|
||||||
assert(VerifyScript(sigs.scriptSig, script, &sigs.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, creator.Checker()));
|
assert(VerifyScript(sigs.scriptSig, script, &sigs.scriptWitness, STANDARD_SCRIPT_VERIFY_FLAGS, DUMMY_CHECKER));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -58,11 +58,7 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
/** A signature creator that just produces 72-byte empty signatures. */
|
/** A signature creator that just produces 72-byte empty signatures. */
|
||||||
class DummySignatureCreator : public BaseSignatureCreator {
|
extern const BaseSignatureCreator& DUMMY_SIGNATURE_CREATOR;
|
||||||
public:
|
|
||||||
const BaseSignatureChecker& Checker() const override;
|
|
||||||
bool CreateSig(const SigningProvider& provider, std::vector<unsigned char>& vchSig, const CKeyID& keyid, const CScript& scriptCode, SigVersion sigversion) const override;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SignatureData {
|
struct SignatureData {
|
||||||
CScript scriptSig;
|
CScript scriptSig;
|
||||||
|
|
|
@ -1535,7 +1535,7 @@ bool CWallet::DummySignInput(CTxIn &tx_in, const CTxOut &txout) const
|
||||||
const CScript& scriptPubKey = txout.scriptPubKey;
|
const CScript& scriptPubKey = txout.scriptPubKey;
|
||||||
SignatureData sigdata;
|
SignatureData sigdata;
|
||||||
|
|
||||||
if (!ProduceSignature(*this, DummySignatureCreator(), scriptPubKey, sigdata))
|
if (!ProduceSignature(*this, DUMMY_SIGNATURE_CREATOR, scriptPubKey, sigdata))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Add table
Reference in a new issue