Skip to content

Commit 8d870a9

Browse files
committed
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.
1 parent fa7c46b commit 8d870a9

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

src/script/signingprovider.cpp

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,61 @@ CKeyID GetKeyForDestination(const SigningProvider& store, const CTxDestination&
225225
}
226226
return CKeyID();
227227
}
228+
229+
void MultiSigningProvider::AddProvider(std::unique_ptr<SigningProvider> provider)
230+
{
231+
m_providers.push_back(std::move(provider));
232+
}
233+
234+
bool MultiSigningProvider::GetCScript(const CScriptID& scriptid, CScript& script) const
235+
{
236+
for (const auto& provider: m_providers) {
237+
if (provider->GetCScript(scriptid, script)) return true;
238+
}
239+
return false;
240+
}
241+
242+
bool MultiSigningProvider::GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const
243+
{
244+
for (const auto& provider: m_providers) {
245+
if (provider->GetPubKey(keyid, pubkey)) return true;
246+
}
247+
return false;
248+
}
249+
250+
251+
bool MultiSigningProvider::GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const
252+
{
253+
for (const auto& provider: m_providers) {
254+
if (provider->GetKeyOrigin(keyid, info)) return true;
255+
}
256+
return false;
257+
}
258+
259+
bool MultiSigningProvider::GetKey(const CKeyID& keyid, CKey& key) const
260+
{
261+
for (const auto& provider: m_providers) {
262+
if (provider->GetKey(keyid, key)) return true;
263+
}
264+
return false;
265+
}
266+
267+
bool MultiSigningProvider::GetTaprootSpendData(const XOnlyPubKey& output_key, TaprootSpendData& spenddata) const
268+
{
269+
for (const auto& provider: m_providers) {
270+
if (provider->GetTaprootSpendData(output_key, spenddata)) return true;
271+
}
272+
return false;
273+
}
274+
275+
bool MultiSigningProvider::GetTaprootBuilder(const XOnlyPubKey& output_key, TaprootBuilder& builder) const
276+
{
277+
for (const auto& provider: m_providers) {
278+
if (provider->GetTaprootBuilder(output_key, builder)) return true;
279+
}
280+
return false;
281+
}
282+
228283
/*static*/ TaprootBuilder::NodeInfo TaprootBuilder::Combine(NodeInfo&& a, NodeInfo&& b)
229284
{
230285
NodeInfo ret;

src/script/signingprovider.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,4 +298,19 @@ class FillableSigningProvider : public SigningProvider
298298
/** Return the CKeyID of the key involved in a script (if there is a unique one). */
299299
CKeyID GetKeyForDestination(const SigningProvider& store, const CTxDestination& dest);
300300

301+
/** A signing provider to be used to interface with multiple signing providers at once. */
302+
class MultiSigningProvider: public SigningProvider {
303+
std::vector<std::unique_ptr<SigningProvider>> m_providers;
304+
305+
public:
306+
void AddProvider(std::unique_ptr<SigningProvider> provider);
307+
308+
bool GetCScript(const CScriptID& scriptid, CScript& script) const override;
309+
bool GetPubKey(const CKeyID& keyid, CPubKey& pubkey) const override;
310+
bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const override;
311+
bool GetKey(const CKeyID& keyid, CKey& key) const override;
312+
bool GetTaprootSpendData(const XOnlyPubKey& output_key, TaprootSpendData& spenddata) const override;
313+
bool GetTaprootBuilder(const XOnlyPubKey& output_key, TaprootBuilder& builder) const override;
314+
};
315+
301316
#endif // BITCOIN_SCRIPT_SIGNINGPROVIDER_H

0 commit comments

Comments
 (0)