MCPcopy Create free account
hub / github.com/bitcoin/bitcoin / ExtractDestination

Function ExtractDestination

src/addresstype.cpp:49–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

47}
48
49bool ExtractDestination(const CScript& scriptPubKey, CTxDestination& addressRet)
50{
51 std::vector<valtype> vSolutions;
52 TxoutType whichType = Solver(scriptPubKey, vSolutions);
53
54 switch (whichType) {
55 case TxoutType::PUBKEY: {
56 CPubKey pubKey(vSolutions[0]);
57 if (!pubKey.IsValid()) {
58 addressRet = CNoDestination(scriptPubKey);
59 } else {
60 addressRet = PubKeyDestination(pubKey);
61 }
62 return false;
63 }
64 case TxoutType::PUBKEYHASH: {
65 addressRet = PKHash(uint160(vSolutions[0]));
66 return true;
67 }
68 case TxoutType::SCRIPTHASH: {
69 addressRet = ScriptHash(uint160(vSolutions[0]));
70 return true;
71 }
72 case TxoutType::WITNESS_V0_KEYHASH: {
73 WitnessV0KeyHash hash;
74 std::copy(vSolutions[0].begin(), vSolutions[0].end(), hash.begin());
75 addressRet = hash;
76 return true;
77 }
78 case TxoutType::WITNESS_V0_SCRIPTHASH: {
79 WitnessV0ScriptHash hash;
80 std::copy(vSolutions[0].begin(), vSolutions[0].end(), hash.begin());
81 addressRet = hash;
82 return true;
83 }
84 case TxoutType::WITNESS_V1_TAPROOT: {
85 WitnessV1Taproot tap;
86 std::copy(vSolutions[0].begin(), vSolutions[0].end(), tap.begin());
87 addressRet = tap;
88 return true;
89 }
90 case TxoutType::ANCHOR: {
91 addressRet = PayToAnchor();
92 return true;
93 }
94 case TxoutType::WITNESS_UNKNOWN: {
95 addressRet = WitnessUnknown{vSolutions[0][0], vSolutions[1]};
96 return true;
97 }
98 case TxoutType::MULTISIG:
99 case TxoutType::NULL_DATA:
100 case TxoutType::NONSTANDARD:
101 addressRet = CNoDestination(scriptPubKey);
102 return false;
103 } // no default case, so the compiler can warn about missing cases
104 assert(false);
105}
106

Callers 15

ScriptToUnivFunction · 0.85
GetNewDestinationMethod · 0.85
MarkUnusedAddressesMethod · 0.85
ListCoinsFunction · 0.85
CreateTransactionFunction · 0.85
SetSpentKeyStateMethod · 0.85
IsSpentKeyMethod · 0.85
MarkDestinationsDirtyMethod · 0.85
AddWalletDescriptorMethod · 0.85
ApplyMigrationDataMethod · 0.85
ScriptIsChangeFunction · 0.85

Calls 10

SolverFunction · 0.85
CNoDestinationClass · 0.85
PubKeyDestinationClass · 0.85
PKHashClass · 0.85
ScriptHashClass · 0.85
PayToAnchorClass · 0.85
uint160Class · 0.70
IsValidMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68