| 189 | } |
| 190 | |
| 191 | CKeyID GetKeyForDestination(const SigningProvider& store, const CTxDestination& dest) |
| 192 | { |
| 193 | // Only supports destinations which map to single public keys: |
| 194 | // P2PKH, P2WPKH, P2SH-P2WPKH, P2TR |
| 195 | if (auto id = std::get_if<PKHash>(&dest)) { |
| 196 | return ToKeyID(*id); |
| 197 | } |
| 198 | if (auto witness_id = std::get_if<WitnessV0KeyHash>(&dest)) { |
| 199 | return ToKeyID(*witness_id); |
| 200 | } |
| 201 | if (auto script_hash = std::get_if<ScriptHash>(&dest)) { |
| 202 | CScript script; |
| 203 | CScriptID script_id(*script_hash); |
| 204 | CTxDestination inner_dest; |
| 205 | if (store.GetCScript(script_id, script) && ExtractDestination(script, inner_dest)) { |
| 206 | if (auto inner_witness_id = std::get_if<WitnessV0KeyHash>(&inner_dest)) { |
| 207 | return ToKeyID(*inner_witness_id); |
| 208 | } |
| 209 | } |
| 210 | } |
| 211 | if (auto output_key = std::get_if<WitnessV1Taproot>(&dest)) { |
| 212 | TaprootSpendData spenddata; |
| 213 | CPubKey pub; |
| 214 | if (store.GetTaprootSpendData(*output_key, spenddata) |
| 215 | && !spenddata.internal_key.IsNull() |
| 216 | && spenddata.merkle_root.IsNull() |
| 217 | && store.GetPubKeyByXOnly(spenddata.internal_key, pub)) { |
| 218 | return pub.GetID(); |
| 219 | } |
| 220 | } |
| 221 | return CKeyID(); |
| 222 | } |