aboutsummaryrefslogtreecommitdiff
path: root/src/script/signingprovider.h
diff options
context:
space:
mode:
authorAndrew Chow <achow101-github@achow101.com>2021-06-28 15:00:33 -0400
committerAndrew Chow <achow101-github@achow101.com>2021-08-23 21:38:34 -0400
commitd9d3ec07cfe45cfa55028cc879dc8a55aecb4d3c (patch)
tree32cb83e14faad38a733c603196d2625349cfac58 /src/script/signingprovider.h
parentdbcb5742c48fd26f77e500291d7083e12eec741b (diff)
downloadbitcoin-d9d3ec07cfe45cfa55028cc879dc8a55aecb4d3c.tar.xz
Consolidate XOnlyPubKey lookup hack
The places where we need to lookup information for a XOnlyPubKey currently implement a hack which makes both serializations of the full pubkey in order to try the CKeyIDs for the lookup functions. Instead of duplicating this everywhere it is needed, we can consolidate the CKeyID generation into a function, and then have wrappers around GetPubKey, GetKey, and GetKeyOrigin which takes the XOnlyPubKey, retrieves all of the CKeyIDs (using the new GetKeyIDs() function in XOnlyPubKey), and tries their respective underlying lookup function.
Diffstat (limited to 'src/script/signingprovider.h')
-rw-r--r--src/script/signingprovider.h24
1 files changed, 24 insertions, 0 deletions
diff --git a/src/script/signingprovider.h b/src/script/signingprovider.h
index 939ae10622..fbce61c6a9 100644
--- a/src/script/signingprovider.h
+++ b/src/script/signingprovider.h
@@ -26,6 +26,30 @@ public:
virtual bool HaveKey(const CKeyID &address) const { return false; }
virtual bool GetKeyOrigin(const CKeyID& keyid, KeyOriginInfo& info) const { return false; }
virtual bool GetTaprootSpendData(const XOnlyPubKey& output_key, TaprootSpendData& spenddata) const { return false; }
+
+ bool GetKeyByXOnly(const XOnlyPubKey& pubkey, CKey& key) const
+ {
+ for (const auto& id : pubkey.GetKeyIDs()) {
+ if (GetKey(id, key)) return true;
+ }
+ return false;
+ }
+
+ bool GetPubKeyByXOnly(const XOnlyPubKey& pubkey, CPubKey& out) const
+ {
+ for (const auto& id : pubkey.GetKeyIDs()) {
+ if (GetPubKey(id, out)) return true;
+ }
+ return false;
+ }
+
+ bool GetKeyOriginByXOnly(const XOnlyPubKey& pubkey, KeyOriginInfo& info) const
+ {
+ for (const auto& id : pubkey.GetKeyIDs()) {
+ if (GetKeyOrigin(id, info)) return true;
+ }
+ return false;
+ }
};
extern const SigningProvider& DUMMY_SIGNING_PROVIDER;