Skip to content

Commit c729afd

Browse files
committed
Box the wallet: Add multiple keyman maps and loops
Add wallet logic for dealing with multiple ScriptPubKeyMan instances. This doesn't change current behavior because there is still only a single LegacyScriptPubKeyMan. But in the future the new logic will be used to support descriptor wallets.
1 parent 4977c30 commit c729afd

File tree

4 files changed

+177
-44
lines changed

4 files changed

+177
-44
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,34 @@ int64_t LegacyScriptPubKeyMan::GetTimeFirstKey() const
470470
return nTimeFirstKey;
471471
}
472472

473+
const SigningProvider* LegacyScriptPubKeyMan::GetSigningProvider(const CScript& script) const
474+
{
475+
return this;
476+
}
477+
478+
bool LegacyScriptPubKeyMan::CanProvide(const CScript& script, SignatureData& sigdata)
479+
{
480+
if (IsMine(script) != ISMINE_NO) {
481+
// If it IsMine, we can always provide in some way
482+
return true;
483+
} else if (HaveCScript(CScriptID(script))) {
484+
// We can still provide some stuff if we have the script, but IsMine failed because we don't have keys
485+
return true;
486+
} else {
487+
// If, given the stuff in sigdata, we could make a valid sigature, then we can provide for this script
488+
ProduceSignature(*this, DUMMY_SIGNATURE_CREATOR, script, sigdata);
489+
if (!sigdata.signatures.empty()) {
490+
// If we could make signatures, make sure we have a private key to actually make a signature
491+
bool has_privkeys = false;
492+
for (const auto& key_sig_pair : sigdata.signatures) {
493+
has_privkeys |= HaveKey(key_sig_pair.first);
494+
}
495+
return has_privkeys;
496+
}
497+
return false;
498+
}
499+
}
500+
473501
const CKeyMetadata* LegacyScriptPubKeyMan::GetMetadata(const CTxDestination& dest) const
474502
{
475503
LOCK(cs_KeyStore);
@@ -491,6 +519,11 @@ const CKeyMetadata* LegacyScriptPubKeyMan::GetMetadata(const CTxDestination& des
491519
return nullptr;
492520
}
493521

522+
uint256 LegacyScriptPubKeyMan::GetID() const
523+
{
524+
return UINT256_ONE();
525+
}
526+
494527
/**
495528
* Update wallet first key creation time. This should be called whenever keys
496529
* are added to the wallet, with the oldest key creation time.

src/wallet/scriptpubkeyman.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,16 @@ class ScriptPubKeyMan
196196

197197
virtual int64_t GetTimeFirstKey() const { return 0; }
198198

199-
//! Return address metadata
200199
virtual const CKeyMetadata* GetMetadata(const CTxDestination& dest) const { return nullptr; }
200+
201+
virtual const SigningProvider* GetSigningProvider(const CScript& script) const { return nullptr; }
202+
203+
/** Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSigningProvider) that, combined with
204+
* sigdata, can produce a valid signature.
205+
*/
206+
virtual bool CanProvide(const CScript& script, SignatureData& sigdata) { return false; }
207+
208+
virtual uint256 GetID() const { return uint256(); }
201209
};
202210

203211
class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProvider
@@ -319,6 +327,12 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
319327

320328
bool CanGetAddresses(bool internal = false) override;
321329

330+
const SigningProvider* GetSigningProvider(const CScript& script) const override;
331+
332+
bool CanProvide(const CScript& script, SignatureData& sigdata) override;
333+
334+
uint256 GetID() const override;
335+
322336
// Map from Key ID to key metadata.
323337
std::map<CKeyID, CKeyMetadata> mapKeyMetadata GUARDED_BY(cs_KeyStore);
324338

0 commit comments

Comments
 (0)