mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-04 13:55:23 -05:00
script/signingprovider: introduce a MultiSigningProvider
It is sometimes useful to interface with multiple signing providers at once. For instance when inferring a descriptor with solving information being provided from multiple sources (see next commit). Instead of inneficiently copying the information from one provider into the other, introduce a new signing provider that takes a list of pointers to existing providers.
This commit is contained in:
parent
fa7c46b503
commit
8d870a9873
2 changed files with 70 additions and 0 deletions
|
@ -225,6 +225,61 @@ CKeyID GetKeyForDestination(const SigningProvider& store, const CTxDestination&
|
|||
}
|
||||
return CKeyID();
|
||||
}
|
||||
|
||||
void MultiSigningProvider::AddProvider(std::unique_ptr<SigningProvider> provider)
|
||||
{
|
||||
m_providers.push_back(std::move(provider));
|
||||
}
|
||||
|
||||
bool MultiSigningProvider::GetCScript(const CScriptID& scriptid, CScript& script) const
|
||||
{
|
||||
for (const auto& provider: m_providers) {
|
||||
if (provider->GetCScript(scriptid, script)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MultiSigningProvider::GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const
|
||||
{
|
||||
for (const auto& provider: m_providers) {
|
||||
if (provider->GetPubKey(keyid, pubkey)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool MultiSigningProvider::GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const
|
||||
{
|
||||
for (const auto& provider: m_providers) {
|
||||
if (provider->GetKeyOrigin(keyid, info)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MultiSigningProvider::GetKey(const CKeyID& keyid, CKey& key) const
|
||||
{
|
||||
for (const auto& provider: m_providers) {
|
||||
if (provider->GetKey(keyid, key)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MultiSigningProvider::GetTaprootSpendData(const XOnlyPubKey& output_key, TaprootSpendData& spenddata) const
|
||||
{
|
||||
for (const auto& provider: m_providers) {
|
||||
if (provider->GetTaprootSpendData(output_key, spenddata)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool MultiSigningProvider::GetTaprootBuilder(const XOnlyPubKey& output_key, TaprootBuilder& builder) const
|
||||
{
|
||||
for (const auto& provider: m_providers) {
|
||||
if (provider->GetTaprootBuilder(output_key, builder)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*static*/ TaprootBuilder::NodeInfo TaprootBuilder::Combine(NodeInfo&& a, NodeInfo&& b)
|
||||
{
|
||||
NodeInfo ret;
|
||||
|
|
|
@ -298,4 +298,19 @@ public:
|
|||
/** Return the CKeyID of the key involved in a script (if there is a unique one). */
|
||||
CKeyID GetKeyForDestination(const SigningProvider& store, const CTxDestination& dest);
|
||||
|
||||
/** A signing provider to be used to interface with multiple signing providers at once. */
|
||||
class MultiSigningProvider: public SigningProvider {
|
||||
std::vector<std::unique_ptr<SigningProvider>> m_providers;
|
||||
|
||||
public:
|
||||
void AddProvider(std::unique_ptr<SigningProvider> provider);
|
||||
|
||||
bool GetCScript(const CScriptID& scriptid, CScript& script) const override;
|
||||
bool GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const override;
|
||||
bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override;
|
||||
bool GetKey(const CKeyID& keyid, CKey& key) const override;
|
||||
bool GetTaprootSpendData(const XOnlyPubKey& output_key, TaprootSpendData& spenddata) const override;
|
||||
bool GetTaprootBuilder(const XOnlyPubKey& output_key, TaprootBuilder& builder) const override;
|
||||
};
|
||||
|
||||
#endif // BITCOIN_SCRIPT_SIGNINGPROVIDER_H
|
||||
|
|
Loading…
Add table
Reference in a new issue