diff --git a/src/script/signingprovider.cpp b/src/script/signingprovider.cpp index f3a69e5d21e..168b3030cc9 100644 --- a/src/script/signingprovider.cpp +++ b/src/script/signingprovider.cpp @@ -225,6 +225,61 @@ CKeyID GetKeyForDestination(const SigningProvider& store, const CTxDestination& } return CKeyID(); } + +void MultiSigningProvider::AddProvider(std::unique_ptr 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; diff --git a/src/script/signingprovider.h b/src/script/signingprovider.h index 712e2e73d1b..32983763896 100644 --- a/src/script/signingprovider.h +++ b/src/script/signingprovider.h @@ -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> m_providers; + +public: + void AddProvider(std::unique_ptr 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