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.
This commit is contained in:
Andrew Chow committed 2020-03-09 11:16:20 -04:00
1 parent 6a9c429084
commit dc174881ad
7 files changed
+21 -32

No files matched your search

+1 -9
View File
@@ -118,20 +118,12 @@ public:
} }
bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) override bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) override
{ {
std::unique_ptr<SigningProvider> provider = m_wallet->GetSigningProvider(script); std::unique_ptr<SigningProvider> provider = m_wallet->GetSolvingProvider(script);
if (provider) { if (provider) {
return provider->GetPubKey(address, pub_key); return provider->GetPubKey(address, pub_key);
} }
return false; return false;
} }
bool getPrivKey(const CScript& script, const CKeyID& address, CKey& key) override
{
std::unique_ptr<SigningProvider> provider = m_wallet->GetSigningProvider(script);
if (provider) {
return provider->GetKey(address, key);
}
return false;
}
SigningResult signMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) override SigningResult signMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) override
{ {
return m_wallet->SignMessage(message, pkhash, str_sig); return m_wallet->SignMessage(message, pkhash, str_sig);
-3
View File
@@ -85,9 +85,6 @@ public:
//! Get public key. //! Get public key.
virtual bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) = 0; virtual bool getPubKey(const CScript& script, const CKeyID& address, CPubKey& pub_key) = 0;
//! Get private key.
virtual bool getPrivKey(const CScript& script, const CKeyID& address, CKey& key) = 0;
//! Sign message //! Sign message
virtual SigningResult signMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) = 0; virtual SigningResult signMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) = 0;
+4 -4
View File
@@ -2962,7 +2962,7 @@ static UniValue listunspent(const JSONRPCRequest& request)
entry.pushKV("label", i->second.name); entry.pushKV("label", i->second.name);
} }
std::unique_ptr<SigningProvider> provider = pwallet->GetSigningProvider(scriptPubKey); std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
if (provider) { if (provider) {
if (scriptPubKey.IsPayToScriptHash()) { if (scriptPubKey.IsPayToScriptHash()) {
const CScriptID& hash = CScriptID(boost::get<ScriptHash>(address)); const CScriptID& hash = CScriptID(boost::get<ScriptHash>(address));
@@ -3002,7 +3002,7 @@ static UniValue listunspent(const JSONRPCRequest& request)
entry.pushKV("spendable", out.fSpendable); entry.pushKV("spendable", out.fSpendable);
entry.pushKV("solvable", out.fSolvable); entry.pushKV("solvable", out.fSolvable);
if (out.fSolvable) { if (out.fSolvable) {
std::unique_ptr<SigningProvider> provider = pwallet->GetSigningProvider(scriptPubKey); std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
if (provider) { if (provider) {
auto descriptor = InferDescriptor(scriptPubKey, *provider); auto descriptor = InferDescriptor(scriptPubKey, *provider);
entry.pushKV("desc", descriptor->ToString()); entry.pushKV("desc", descriptor->ToString());
@@ -3716,7 +3716,7 @@ static UniValue DescribeWalletAddress(const CWallet* const pwallet, const CTxDes
CScript script = GetScriptForDestination(dest); CScript script = GetScriptForDestination(dest);
std::unique_ptr<SigningProvider> provider = nullptr; std::unique_ptr<SigningProvider> provider = nullptr;
if (pwallet) { if (pwallet) {
provider = pwallet->GetSigningProvider(script); provider = pwallet->GetSolvingProvider(script);
} }
ret.pushKVs(detail); ret.pushKVs(detail);
ret.pushKVs(boost::apply_visitor(DescribeWalletAddressVisitor(provider.get()), dest)); ret.pushKVs(boost::apply_visitor(DescribeWalletAddressVisitor(provider.get()), dest));
@@ -3818,7 +3818,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
CScript scriptPubKey = GetScriptForDestination(dest); CScript scriptPubKey = GetScriptForDestination(dest);
ret.pushKV("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end())); ret.pushKV("scriptPubKey", HexStr(scriptPubKey.begin(), scriptPubKey.end()));
std::unique_ptr<SigningProvider> provider = pwallet->GetSigningProvider(scriptPubKey); std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
isminetype mine = pwallet->IsMine(dest); isminetype mine = pwallet->IsMine(dest);
ret.pushKV("ismine", bool(mine & ISMINE_SPENDABLE)); ret.pushKV("ismine", bool(mine & ISMINE_SPENDABLE));
+1 -1
View File
@@ -478,7 +478,7 @@ int64_t LegacyScriptPubKeyMan::GetTimeFirstKey() const
return nTimeFirstKey; return nTimeFirstKey;
} }
std::unique_ptr<SigningProvider> LegacyScriptPubKeyMan::GetSigningProvider(const CScript& script) const std::unique_ptr<SigningProvider> LegacyScriptPubKeyMan::GetSolvingProvider(const CScript& script) const
{ {
return MakeUnique<LegacySigningProvider>(*this); return MakeUnique<LegacySigningProvider>(*this);
} }
+7 -7
View File
@@ -206,10 +206,10 @@ public:
virtual const CKeyMetadata* GetMetadata(const CTxDestination& dest) const { return nullptr; } virtual const CKeyMetadata* GetMetadata(const CTxDestination& dest) const { return nullptr; }
virtual std::unique_ptr<SigningProvider> GetSigningProvider(const CScript& script) const { return nullptr; } virtual std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const { return nullptr; }
/** Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSigningProvider) that, combined with /** Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that, combined with
* sigdata, can produce a valid signature. * sigdata, can produce solving data.
*/ */
virtual bool CanProvide(const CScript& script, SignatureData& sigdata) { return false; } virtual bool CanProvide(const CScript& script, SignatureData& sigdata) { return false; }
@@ -356,7 +356,7 @@ public:
bool CanGetAddresses(bool internal = false) const override; bool CanGetAddresses(bool internal = false) const override;
std::unique_ptr<SigningProvider> GetSigningProvider(const CScript& script) const override; std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const override;
bool CanProvide(const CScript& script, SignatureData& sigdata) override; bool CanProvide(const CScript& script, SignatureData& sigdata) override;
@@ -461,7 +461,7 @@ public:
std::set<CKeyID> GetKeys() const override; std::set<CKeyID> GetKeys() const override;
}; };
/** Wraps a LegacyScriptPubKeyMan so that it can be returned in a new unique_ptr */ /** Wraps a LegacyScriptPubKeyMan so that it can be returned in a new unique_ptr. Does not provide privkeys */
class LegacySigningProvider : public SigningProvider class LegacySigningProvider : public SigningProvider
{ {
private: private:
@@ -472,8 +472,8 @@ public:
bool GetCScript(const CScriptID &scriptid, CScript& script) const override { return m_spk_man.GetCScript(scriptid, script); } bool GetCScript(const CScriptID &scriptid, CScript& script) const override { return m_spk_man.GetCScript(scriptid, script); }
bool HaveCScript(const CScriptID &scriptid) const override { return m_spk_man.HaveCScript(scriptid); } bool HaveCScript(const CScriptID &scriptid) const override { return m_spk_man.HaveCScript(scriptid); }
bool GetPubKey(const CKeyID &address, CPubKey& pubkey) const override { return m_spk_man.GetPubKey(address, pubkey); } bool GetPubKey(const CKeyID &address, CPubKey& pubkey) const override { return m_spk_man.GetPubKey(address, pubkey); }
bool GetKey(const CKeyID &address, CKey& key) const override { return m_spk_man.GetKey(address, key); } bool GetKey(const CKeyID &address, CKey& key) const override { return false; }
bool HaveKey(const CKeyID &address) const override { return m_spk_man.HaveKey(address); } bool HaveKey(const CKeyID &address) const override { return false; }
bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override { return m_spk_man.GetKeyOrigin(keyid, info); } bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override { return m_spk_man.GetKeyOrigin(keyid, info); }
}; };
+6 -6
View File
@@ -1407,7 +1407,7 @@ bool CWallet::DummySignInput(CTxIn &tx_in, const CTxOut &txout, bool use_max_sig
const CScript& scriptPubKey = txout.scriptPubKey; const CScript& scriptPubKey = txout.scriptPubKey;
SignatureData sigdata; SignatureData sigdata;
std::unique_ptr<SigningProvider> provider = GetSigningProvider(scriptPubKey); std::unique_ptr<SigningProvider> provider = GetSolvingProvider(scriptPubKey);
if (!provider) { if (!provider) {
// We don't know about this scriptpbuKey; // We don't know about this scriptpbuKey;
return false; return false;
@@ -2171,7 +2171,7 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<
continue; continue;
} }
std::unique_ptr<SigningProvider> provider = GetSigningProvider(wtx.tx->vout[i].scriptPubKey); std::unique_ptr<SigningProvider> provider = GetSolvingProvider(wtx.tx->vout[i].scriptPubKey);
bool solvable = provider ? IsSolvable(*provider, wtx.tx->vout[i].scriptPubKey) : false; bool solvable = provider ? IsSolvable(*provider, wtx.tx->vout[i].scriptPubKey) : false;
bool spendable = ((mine & ISMINE_SPENDABLE) != ISMINE_NO) || (((mine & ISMINE_WATCH_ONLY) != ISMINE_NO) && (coinControl && coinControl->fAllowWatchOnly && solvable)); 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
return nullptr; return nullptr;
} }
std::unique_ptr<SigningProvider> CWallet::GetSigningProvider(const CScript& script) const std::unique_ptr<SigningProvider> CWallet::GetSolvingProvider(const CScript& script) const
{ {
SignatureData sigdata; SignatureData sigdata;
return GetSigningProvider(script, sigdata); return GetSolvingProvider(script, sigdata);
} }
std::unique_ptr<SigningProvider> CWallet::GetSigningProvider(const CScript& script, SignatureData& sigdata) const std::unique_ptr<SigningProvider> CWallet::GetSolvingProvider(const CScript& script, SignatureData& sigdata) const
{ {
for (const auto& spk_man_pair : m_spk_managers) { for (const auto& spk_man_pair : m_spk_managers) {
if (spk_man_pair.second->CanProvide(script, sigdata)) { if (spk_man_pair.second->CanProvide(script, sigdata)) {
return spk_man_pair.second->GetSigningProvider(script); return spk_man_pair.second->GetSolvingProvider(script);
} }
} }
return nullptr; return nullptr;
+2 -2
View File
@@ -1182,8 +1182,8 @@ public:
std::set<ScriptPubKeyMan*> GetScriptPubKeyMans(const CScript& script, SignatureData& sigdata) const; std::set<ScriptPubKeyMan*> GetScriptPubKeyMans(const CScript& script, SignatureData& sigdata) const;
//! Get the SigningProvider for a script //! Get the SigningProvider for a script
std::unique_ptr<SigningProvider> GetSigningProvider(const CScript& script) const; std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const;
std::unique_ptr<SigningProvider> GetSigningProvider(const CScript& script, SignatureData& sigdata) const; std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script, SignatureData& sigdata) const;
//! Get the LegacyScriptPubKeyMan which is used for all types, internal, and external. //! Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
LegacyScriptPubKeyMan* GetLegacyScriptPubKeyMan() const; LegacyScriptPubKeyMan* GetLegacyScriptPubKeyMan() const;