MCPcopy Create free account
hub / github.com/ElementsProject/elements / ExtractDestination

Function ExtractDestination

src/script/standard.cpp:236–292  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
237{
238 std::vector<valtype> vSolutions;
239 TxoutType whichType = Solver(scriptPubKey, vSolutions);
240
241 switch (whichType) {
242 case TxoutType::PUBKEY: {
243 CPubKey pubKey(vSolutions[0]);
244 if (!pubKey.IsValid())
245 return false;
246
247 addressRet = PKHash(pubKey);
248 return true;
249 }
250 case TxoutType::PUBKEYHASH: {
251 addressRet = PKHash(uint160(vSolutions[0]));
252 return true;
253 }
254 case TxoutType::SCRIPTHASH: {
255 addressRet = ScriptHash(uint160(vSolutions[0]));
256 return true;
257 }
258 case TxoutType::WITNESS_V0_KEYHASH: {
259 WitnessV0KeyHash hash;
260 std::copy(vSolutions[0].begin(), vSolutions[0].end(), hash.begin());
261 addressRet = hash;
262 return true;
263 }
264 case TxoutType::WITNESS_V0_SCRIPTHASH: {
265 WitnessV0ScriptHash hash;
266 std::copy(vSolutions[0].begin(), vSolutions[0].end(), hash.begin());
267 addressRet = hash;
268 return true;
269 }
270 case TxoutType::WITNESS_V1_TAPROOT: {
271 WitnessV1Taproot tap;
272 std::copy(vSolutions[0].begin(), vSolutions[0].end(), tap.begin());
273 addressRet = tap;
274 return true;
275 }
276 case TxoutType::WITNESS_UNKNOWN: {
277 WitnessUnknown unk;
278 unk.version = vSolutions[0][0];
279 std::copy(vSolutions[1].begin(), vSolutions[1].end(), unk.program);
280 unk.length = vSolutions[1].size();
281 addressRet = unk;
282 return true;
283 }
284 case TxoutType::MULTISIG:
285 case TxoutType::NULL_DATA:
286 case TxoutType::NONSTANDARD:
287 case TxoutType::OP_TRUE: // ELEMENTS (no address type)
288 case TxoutType::FEE: // ELEMENTS (no address type)
289 return false;
290 } // no default case, so the compiler can warn about missing cases
291 assert(false);
292}
293

Callers 15

GetNewDestinationMethod · 0.85
MarkUnusedAddressesMethod · 0.85
spend.cppFile · 0.85
SetSpentKeyStateMethod · 0.85
IsSpentKeyMethod · 0.85
ImportScriptPubKeysMethod · 0.85
MarkDestinationsDirtyMethod · 0.85
AddWalletDescriptorMethod · 0.85
ScriptIsChangeFunction · 0.85
CachedTxGetAmountsFunction · 0.85

Calls 8

SolverFunction · 0.85
PKHashClass · 0.85
ScriptHashClass · 0.85
uint160Class · 0.50
IsValidMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
sizeMethod · 0.45

Tested by 3

BOOST_AUTO_TEST_CASEFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68
FUZZ_TARGET_INITFunction · 0.68