Skip to content

Commit dc17488

Browse files
committed
Replace GetSigningProvider with GetSolvingProvider
Not all ScriptPubKeyMans will be able to provide private keys, but pubkeys and scripts should be. So only provide public-only SigningProviders, i.e. ones that can help with Solving.
1 parent 6a9c429 commit dc17488

File tree

7 files changed

+21
-32
lines changed

7 files changed

+21
-32
lines changed

src/interfaces/wallet.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -118,20 +118,12 @@ class WalletImpl : public Wallet
118118
}
119119
bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) override
120120
{
121-
std::unique_ptr<SigningProvider> provider = m_wallet->GetSigningProvider(script);
121+
std::unique_ptr<SigningProvider> provider = m_wallet->GetSolvingProvider(script);
122122
if (provider) {
123123
return provider->GetPubKey(address, pub_key);
124124
}
125125
return false;
126126
}
127-
bool getPrivKey(const CScript& script, const CKeyID& address, CKey& key) override
128-
{
129-
std::unique_ptr<SigningProvider> provider = m_wallet->GetSigningProvider(script);
130-
if (provider) {
131-
return provider->GetKey(address, key);
132-
}
133-
return false;
134-
}
135127
SigningResult signMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) override
136128
{
137129
return m_wallet->SignMessage(message, pkhash, str_sig);

src/interfaces/wallet.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,6 @@ class Wallet
8585
//! Get public key.
8686
virtual bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) = 0;
8787

88-
//! Get private key.
89-
virtual bool getPrivKey(const CScript& script, const CKeyID& address, CKey& key) = 0;
90-
9188
//! Sign message
9289
virtual SigningResult signMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) = 0;
9390

src/wallet/rpcwallet.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2962,7 +2962,7 @@ static UniValue listunspent(const JSONRPCRequest& request)
29622962
entry.pushKV("label", i->second.name);
29632963
}
29642964

2965-
std::unique_ptr<SigningProvider> provider = pwallet->GetSigningProvider(scriptPubKey);
2965+
std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
29662966
if (provider) {
29672967
if (scriptPubKey.IsPayToScriptHash()) {
29682968
const CScriptID& hash = CScriptID(boost::get<ScriptHash>(address));
@@ -3002,7 +3002,7 @@ static UniValue listunspent(const JSONRPCRequest& request)
30023002
entry.pushKV("spendable", out.fSpendable);
30033003
entry.pushKV("solvable", out.fSolvable);
30043004
if (out.fSolvable) {
3005-
std::unique_ptr<SigningProvider> provider = pwallet->GetSigningProvider(scriptPubKey);
3005+
std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
30063006
if (provider) {
30073007
auto descriptor = InferDescriptor(scriptPubKey, *provider);
30083008
entry.pushKV("desc", descriptor->ToString());
@@ -3716,7 +3716,7 @@ static UniValue DescribeWalletAddress(const CWallet* const pwallet, const CTxDes
37163716
CScript script = GetScriptForDestination(dest);
37173717
std::unique_ptr<SigningProvider> provider = nullptr;
37183718
if (pwallet) {
3719-
provider = pwallet->GetSigningProvider(script);
3719+
provider = pwallet->GetSolvingProvider(script);
37203720
}
37213721
ret.pushKVs(detail);
37223722
ret.pushKVs(boost::apply_visitor(DescribeWalletAddressVisitor(provider.get()), dest));
@@ -3818,7 +3818,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
38183818
CScript scriptPubKey = GetScriptForDestination(dest);
38193819
ret.pushKV("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end()));
38203820

3821-
std::unique_ptr<SigningProvider> provider = pwallet->GetSigningProvider(scriptPubKey);
3821+
std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
38223822

38233823
isminetype mine = pwallet->IsMine(dest);
38243824
ret.pushKV("ismine", bool(mine & ISMINE_SPENDABLE));

src/wallet/scriptpubkeyman.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,7 @@ int64_t LegacyScriptPubKeyMan::GetTimeFirstKey() const
478478
return nTimeFirstKey;
479479
}
480480

481-
std::unique_ptr<SigningProvider> LegacyScriptPubKeyMan::GetSigningProvider(const CScript& script) const
481+
std::unique_ptr<SigningProvider> LegacyScriptPubKeyMan::GetSolvingProvider(const CScript& script) const
482482
{
483483
return MakeUnique<LegacySigningProvider>(*this);
484484
}

src/wallet/scriptpubkeyman.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -206,10 +206,10 @@ class ScriptPubKeyMan
206206

207207
virtual const CKeyMetadata* GetMetadata(const CTxDestination& dest) const { return nullptr; }
208208

209-
virtual std::unique_ptr<SigningProvider> GetSigningProvider(const CScript& script) const { return nullptr; }
209+
virtual std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const { return nullptr; }
210210

211-
/** Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSigningProvider) that, combined with
212-
* sigdata, can produce a valid signature.
211+
/** Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that, combined with
212+
* sigdata, can produce solving data.
213213
*/
214214
virtual bool CanProvide(const CScript& script, SignatureData& sigdata) { return false; }
215215

@@ -356,7 +356,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
356356

357357
bool CanGetAddresses(bool internal = false) const override;
358358

359-
std::unique_ptr<SigningProvider> GetSigningProvider(const CScript& script) const override;
359+
std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const override;
360360

361361
bool CanProvide(const CScript& script, SignatureData& sigdata) override;
362362

@@ -461,7 +461,7 @@ class LegacyScriptPubKeyMan : public ScriptPubKeyMan, public FillableSigningProv
461461
std::set<CKeyID> GetKeys() const override;
462462
};
463463

464-
/** Wraps a LegacyScriptPubKeyMan so that it can be returned in a new unique_ptr */
464+
/** Wraps a LegacyScriptPubKeyMan so that it can be returned in a new unique_ptr. Does not provide privkeys */
465465
class LegacySigningProvider : public SigningProvider
466466
{
467467
private:
@@ -472,8 +472,8 @@ class LegacySigningProvider : public SigningProvider
472472
bool GetCScript(const CScriptID &scriptid, CScript& script) const override { return m_spk_man.GetCScript(scriptid, script); }
473473
bool HaveCScript(const CScriptID &scriptid) const override { return m_spk_man.HaveCScript(scriptid); }
474474
bool GetPubKey(const CKeyID &address, CPubKey& pubkey) const override { return m_spk_man.GetPubKey(address, pubkey); }
475-
bool GetKey(const CKeyID &address, CKey& key) const override { return m_spk_man.GetKey(address, key); }
476-
bool HaveKey(const CKeyID &address) const override { return m_spk_man.HaveKey(address); }
475+
bool GetKey(const CKeyID &address, CKey& key) const override { return false; }
476+
bool HaveKey(const CKeyID &address) const override { return false; }
477477
bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override { return m_spk_man.GetKeyOrigin(keyid, info); }
478478
};
479479

src/wallet/wallet.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1407,7 +1407,7 @@ bool CWallet::DummySignInput(CTxIn &tx_in, const CTxOut &txout, bool use_max_sig
14071407
const CScript& scriptPubKey = txout.scriptPubKey;
14081408
SignatureData sigdata;
14091409

1410-
std::unique_ptr<SigningProvider> provider = GetSigningProvider(scriptPubKey);
1410+
std::unique_ptr<SigningProvider> provider = GetSolvingProvider(scriptPubKey);
14111411
if (!provider) {
14121412
// We don't know about this scriptpbuKey;
14131413
return false;
@@ -2171,7 +2171,7 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<
21712171
continue;
21722172
}
21732173

2174-
std::unique_ptr<SigningProvider> provider = GetSigningProvider(wtx.tx->vout[i].scriptPubKey);
2174+
std::unique_ptr<SigningProvider> provider = GetSolvingProvider(wtx.tx->vout[i].scriptPubKey);
21752175

21762176
bool solvable = provider ? IsSolvable(*provider, wtx.tx->vout[i].scriptPubKey) : false;
21772177
bool spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable));
@@ -4307,17 +4307,17 @@ ScriptPubKeyMan* CWallet::GetScriptPubKeyMan(const uint256& id) const
43074307
return nullptr;
43084308
}
43094309

4310-
std::unique_ptr<SigningProvider> CWallet::GetSigningProvider(const CScript& script) const
4310+
std::unique_ptr<SigningProvider> CWallet::GetSolvingProvider(const CScript& script) const
43114311
{
43124312
SignatureData sigdata;
4313-
return GetSigningProvider(script, sigdata);
4313+
return GetSolvingProvider(script, sigdata);
43144314
}
43154315

4316-
std::unique_ptr<SigningProvider> CWallet::GetSigningProvider(const CScript& script, SignatureData& sigdata) const
4316+
std::unique_ptr<SigningProvider> CWallet::GetSolvingProvider(const CScript& script, SignatureData& sigdata) const
43174317
{
43184318
for (const auto& spk_man_pair : m_spk_managers) {
43194319
if (spk_man_pair.second->CanProvide(script, sigdata)) {
4320-
return spk_man_pair.second->GetSigningProvider(script);
4320+
return spk_man_pair.second->GetSolvingProvider(script);
43214321
}
43224322
}
43234323
return nullptr;

src/wallet/wallet.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,8 +1182,8 @@ class CWallet final : public WalletStorage, private interfaces::Chain::Notificat
11821182
std::set<ScriptPubKeyMan*> GetScriptPubKeyMans(const CScript& script, SignatureData& sigdata) const;
11831183

11841184
//! Get the SigningProvider for a script
1185-
std::unique_ptr<SigningProvider> GetSigningProvider(const CScript& script) const;
1186-
std::unique_ptr<SigningProvider> GetSigningProvider(const CScript& script, SignatureData& sigdata) const;
1185+
std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const;
1186+
std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script, SignatureData& sigdata) const;
11871187

11881188
//! Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
11891189
LegacyScriptPubKeyMan* GetLegacyScriptPubKeyMan() const;

0 commit comments

Comments
 (0)