Skip to content

Commit 00b7802

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 9875c89 commit 00b7802

File tree

4 files changed

+182
-48
lines changed

4 files changed

+182
-48
lines changed

src/wallet/scriptpubkeyman.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -496,6 +496,34 @@ int64_t LegacyScriptPubKeyMan::GetTimeFirstKey() const
496496
return nTimeFirstKey;
497497
}
498498

499+
const SigningProvider* LegacyScriptPubKeyMan::GetSigningProvider(const CScript& script) const
500+
{
501+
return this;
502+
}
503+
504+
bool LegacyScriptPubKeyMan::CanProvide(const CScript& script, SignatureData& sigdata)
505+
{
506+
if (IsMine(script) != ISMINE_NO) {
507+
// If it IsMine, we can always provide in some way
508+
return true;
509+
} else if (HaveCScript(CScriptID(script))) {
510+
// We can still provide some stuff if we have the script, but IsMine failed because we don't have keys
511+
return true;
512+
} else {
513+
// If, given the stuff in sigdata, we could make a valid sigature, then we can provide for this script
514+
ProduceSignature(*this, DUMMY_SIGNATURE_CREATOR, script, sigdata);
515+
if (!sigdata.signatures.empty()) {
516+
// If we could make signatures, make sure we have a private key to actually make a signature
517+
bool has_privkeys = false;
518+
for (const auto& key_sig_pair : sigdata.signatures) {
519+
has_privkeys |= HaveKey(key_sig_pair.first);
520+
}
521+
return has_privkeys;
522+
}
523+
return false;
524+
}
525+
}
526+
499527
const CKeyMetadata* LegacyScriptPubKeyMan::GetMetadata(uint160 id) const
500528
{
501529
LOCK(cs_KeyStore);
@@ -511,6 +539,11 @@ const CKeyMetadata* LegacyScriptPubKeyMan::GetMetadata(uint160 id) const
511539
return nullptr;
512540
}
513541

542+
uint256 LegacyScriptPubKeyMan::GetID() const
543+
{
544+
return uint256S("0000000000000000000000000000000000000000000000000000000000000001");
545+
}
546+
514547
/**
515548
* Update wallet first key creation time. This should be called whenever keys
516549
* are added to the wallet, with the oldest key creation time.

src/wallet/scriptpubkeyman.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,15 @@ class ScriptPubKeyMan
197197
virtual int64_t GetTimeFirstKey() const { return 0; }
198198

199199
virtual const CKeyMetadata* GetMetadata(uint160 id) 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(); }
200209
};
201210

202211
class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProvider
@@ -320,6 +329,12 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
320329

321330
bool CanGetAddresses(bool internal = false) override;
322331

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

0 commit comments

Comments
 (0)