diff --git a/src/keystore.h b/src/keystore.h --- a/src/keystore.h +++ b/src/keystore.h @@ -84,4 +84,9 @@ typedef std::map>> CryptedKeyMap; +/** + * Return the CKeyID of the key involved in a script (if there is a unique one). + */ +CKeyID GetKeyForDestination(const CKeyStore &store, const CTxDestination &dest); + #endif // BITCOIN_KEYSTORE_H diff --git a/src/keystore.cpp b/src/keystore.cpp --- a/src/keystore.cpp +++ b/src/keystore.cpp @@ -144,3 +144,12 @@ LOCK(cs_KeyStore); return (!setWatchOnly.empty()); } + +CKeyID GetKeyForDestination(const CKeyStore &store, + const CTxDestination &dest) { + // Only supports destinations which map to single public keys, i.e. P2PKH. + if (auto id = boost::get(&dest)) { + return *id; + } + return CKeyID(); +}