mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-01-10 20:03:34 -03:00
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:
parent
6a9c429084
commit
dc174881ad
7 changed files with 21 additions and 32 deletions
|
@ -118,20 +118,12 @@ public:
|
|||
}
|
||||
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) {
|
||||
return provider->GetPubKey(address, pub_key);
|
||||
}
|
||||
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
|
||||
{
|
||||
return m_wallet->SignMessage(message, pkhash, str_sig);
|
||||
|
|
|
@ -85,9 +85,6 @@ public:
|
|||
//! Get public key.
|
||||
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
|
||||
virtual SigningResult signMessage(const std::string& message, const PKHash& pkhash, std::string& str_sig) = 0;
|
||||
|
||||
|
|
|
@ -2962,7 +2962,7 @@ static UniValue listunspent(const JSONRPCRequest& request)
|
|||
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 (scriptPubKey.IsPayToScriptHash()) {
|
||||
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("solvable", out.fSolvable);
|
||||
if (out.fSolvable) {
|
||||
std::unique_ptr<SigningProvider> provider = pwallet->GetSigningProvider(scriptPubKey);
|
||||
std::unique_ptr<SigningProvider> provider = pwallet->GetSolvingProvider(scriptPubKey);
|
||||
if (provider) {
|
||||
auto descriptor = InferDescriptor(scriptPubKey, *provider);
|
||||
entry.pushKV("desc", descriptor->ToString());
|
||||
|
@ -3716,7 +3716,7 @@ static UniValue DescribeWalletAddress(const CWallet* const pwallet, const CTxDes
|
|||
CScript script = GetScriptForDestination(dest);
|
||||
std::unique_ptr<SigningProvider> provider = nullptr;
|
||||
if (pwallet) {
|
||||
provider = pwallet->GetSigningProvider(script);
|
||||
provider = pwallet->GetSolvingProvider(script);
|
||||
}
|
||||
ret.pushKVs(detail);
|
||||
ret.pushKVs(boost::apply_visitor(DescribeWalletAddressVisitor(provider.get()), dest));
|
||||
|
@ -3818,7 +3818,7 @@ UniValue getaddressinfo(const JSONRPCRequest& request)
|
|||
CScript scriptPubKey = GetScriptForDestination(dest);
|
||||
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);
|
||||
ret.pushKV("ismine", bool(mine & ISMINE_SPENDABLE));
|
||||
|
|
|
@ -478,7 +478,7 @@ int64_t LegacyScriptPubKeyMan::GetTimeFirstKey() const
|
|||
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);
|
||||
}
|
||||
|
|
|
@ -206,10 +206,10 @@ public:
|
|||
|
||||
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
|
||||
* sigdata, can produce a valid signature.
|
||||
/** Whether this ScriptPubKeyMan can provide a SigningProvider (via GetSolvingProvider) that, combined with
|
||||
* sigdata, can produce solving data.
|
||||
*/
|
||||
virtual bool CanProvide(const CScript& script, SignatureData& sigdata) { return false; }
|
||||
|
||||
|
@ -356,7 +356,7 @@ public:
|
|||
|
||||
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;
|
||||
|
||||
|
@ -461,7 +461,7 @@ public:
|
|||
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
|
||||
{
|
||||
private:
|
||||
|
@ -472,8 +472,8 @@ public:
|
|||
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 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 HaveKey(const CKeyID &address) const override { return m_spk_man.HaveKey(address); }
|
||||
bool GetKey(const CKeyID &address, CKey& key) const override { return false; }
|
||||
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); }
|
||||
};
|
||||
|
||||
|
|
|
@ -1407,7 +1407,7 @@ bool CWallet::DummySignInput(CTxIn &tx_in, const CTxOut &txout, bool use_max_sig
|
|||
const CScript& scriptPubKey = txout.scriptPubKey;
|
||||
SignatureData sigdata;
|
||||
|
||||
std::unique_ptr<SigningProvider> provider = GetSigningProvider(scriptPubKey);
|
||||
std::unique_ptr<SigningProvider> provider = GetSolvingProvider(scriptPubKey);
|
||||
if (!provider) {
|
||||
// We don't know about this scriptpbuKey;
|
||||
return false;
|
||||
|
@ -2171,7 +2171,7 @@ void CWallet::AvailableCoins(interfaces::Chain::Lock& locked_chain, std::vector<
|
|||
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 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;
|
||||
}
|
||||
|
||||
std::unique_ptr<SigningProvider> CWallet::GetSigningProvider(const CScript& script) const
|
||||
std::unique_ptr<SigningProvider> CWallet::GetSolvingProvider(const CScript& script) const
|
||||
{
|
||||
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) {
|
||||
if (spk_man_pair.second->CanProvide(script, sigdata)) {
|
||||
return spk_man_pair.second->GetSigningProvider(script);
|
||||
return spk_man_pair.second->GetSolvingProvider(script);
|
||||
}
|
||||
}
|
||||
return nullptr;
|
||||
|
|
|
@ -1182,8 +1182,8 @@ public:
|
|||
std::set<ScriptPubKeyMan*> GetScriptPubKeyMans(const CScript& script, SignatureData& sigdata) const;
|
||||
|
||||
//! Get the SigningProvider for a script
|
||||
std::unique_ptr<SigningProvider> GetSigningProvider(const CScript& script) const;
|
||||
std::unique_ptr<SigningProvider> GetSigningProvider(const CScript& script, SignatureData& sigdata) const;
|
||||
std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script) const;
|
||||
std::unique_ptr<SigningProvider> GetSolvingProvider(const CScript& script, SignatureData& sigdata) const;
|
||||
|
||||
//! Get the LegacyScriptPubKeyMan which is used for all types, internal, and external.
|
||||
LegacyScriptPubKeyMan* GetLegacyScriptPubKeyMan() const;
|
||||
|
|
Loading…
Reference in a new issue