From dd3c07acce7ab67f32a79393abf6227009bd440d Mon Sep 17 00:00:00 2001 From: Andrew Chow Date: Thu, 12 Apr 2018 17:04:49 -0400 Subject: [PATCH] Separate HaveKey function that checks whether a key is in a keystore --- src/keystore.cpp | 7 +++++++ src/keystore.h | 3 +++ 2 files changed, 10 insertions(+) diff --git a/src/keystore.cpp b/src/keystore.cpp index e69d518890f..ea93ed69fa9 100644 --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -195,3 +195,10 @@ CKeyID GetKeyForDestination(const CKeyStore& store, const CTxDestination& dest) } return CKeyID(); } + +bool HaveKey(const CKeyStore& store, const CKey& key) +{ + CKey key2; + key2.Set(key.begin(), key.end(), !key.IsCompressed()); + return store.HaveKey(key.GetPubKey().GetID()) || store.HaveKey(key2.GetPubKey().GetID()); +} diff --git a/src/keystore.h b/src/keystore.h index c56e4751de8..cd5ded92038 100644 --- a/src/keystore.h +++ b/src/keystore.h @@ -80,4 +80,7 @@ typedef std::map > > Crypt /** Return the CKeyID of the key involved in a script (if there is a unique one). */ CKeyID GetKeyForDestination(const CKeyStore& store, const CTxDestination& dest); +/** Checks if a CKey is in the given CKeyStore compressed or otherwise*/ +bool HaveKey(const CKeyStore& store, const CKey& key); + #endif // BITCOIN_KEYSTORE_H