File tree Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Expand file tree Collapse file tree 2 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -136,3 +136,25 @@ bool CBasicKeyStore::HaveWatchOnly() const
136
136
LOCK (cs_KeyStore);
137
137
return (!setWatchOnly.empty ());
138
138
}
139
+
140
+ CKeyID GetKeyForDestination (const CKeyStore& store, const CTxDestination& dest)
141
+ {
142
+ // Only supports destinations which map to single public keys, i.e. P2PKH,
143
+ // P2WPKH, and P2SH-P2WPKH.
144
+ if (auto id = boost::get<CKeyID>(&dest)) {
145
+ return *id;
146
+ }
147
+ if (auto witness_id = boost::get<WitnessV0KeyHash>(&dest)) {
148
+ return CKeyID (*witness_id);
149
+ }
150
+ if (auto script_id = boost::get<CScriptID>(&dest)) {
151
+ CScript script;
152
+ CTxDestination inner_dest;
153
+ if (store.GetCScript (*script_id, script) && ExtractDestination (script, inner_dest)) {
154
+ if (auto inner_witness_id = boost::get<WitnessV0KeyHash>(&inner_dest)) {
155
+ return CKeyID (*inner_witness_id);
156
+ }
157
+ }
158
+ }
159
+ return CKeyID ();
160
+ }
Original file line number Diff line number Diff line change @@ -78,4 +78,7 @@ class CBasicKeyStore : public CKeyStore
78
78
typedef std::vector<unsigned char , secure_allocator<unsigned char > > CKeyingMaterial;
79
79
typedef std::map<CKeyID, std::pair<CPubKey, std::vector<unsigned char > > > CryptedKeyMap;
80
80
81
+ /* * Return the CKeyID of the key involved in a script (if there is a unique one). */
82
+ CKeyID GetKeyForDestination (const CKeyStore& store, const CTxDestination& dest);
83
+
81
84
#endif // BITCOIN_KEYSTORE_H
You can’t perform that action at this time.
0 commit comments