aboutsummaryrefslogtreecommitdiff
path: root/src/keystore.cpp
diff options
context:
space:
mode:
authorPieter Wuille <pieter.wuille@gmail.com>2017-11-30 16:48:41 -0800
committerPieter Wuille <pieter.wuille@gmail.com>2018-01-03 05:43:06 -0800
commit30a27dc5b18a3ab82a9768710b24d4e7e9661658 (patch)
tree79f7a63cf8fe7ddc821a529ac7a20e0359184dcf /src/keystore.cpp
parent985c79552ceb6a5f5812d421dc5c86fa3b1cc41d (diff)
downloadbitcoin-30a27dc5b18a3ab82a9768710b24d4e7e9661658.tar.xz
Expose method to find key for a single-key destination
Diffstat (limited to 'src/keystore.cpp')
-rw-r--r--src/keystore.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/src/keystore.cpp b/src/keystore.cpp
index 4ab089e032..cbcc6d7ca9 100644
--- a/src/keystore.cpp
+++ b/src/keystore.cpp
@@ -136,3 +136,25 @@ bool CBasicKeyStore::HaveWatchOnly() const
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,
+ // P2WPKH, and P2SH-P2WPKH.
+ if (auto id = boost::get<CKeyID>(&dest)) {
+ return *id;
+ }
+ if (auto witness_id = boost::get<WitnessV0KeyHash>(&dest)) {
+ return CKeyID(*witness_id);
+ }
+ if (auto script_id = boost::get<CScriptID>(&dest)) {
+ CScript script;
+ CTxDestination inner_dest;
+ if (store.GetCScript(*script_id, script) && ExtractDestination(script, inner_dest)) {
+ if (auto inner_witness_id = boost::get<WitnessV0KeyHash>(&inner_dest)) {
+ return CKeyID(*inner_witness_id);
+ }
+ }
+ }
+ return CKeyID();
+}