MCPcopy Create free account
hub / github.com/BTCGPU/BTCGPU / DecodeDestination

Function DecodeDestination

src/key_io.cpp:73–130  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

71};
72
73CTxDestination DecodeDestination(const std::string& str, const CChainParams& params)
74{
75 std::vector<unsigned char> data;
76 uint160 hash;
77 if (DecodeBase58Check(str, data)) {
78 // base58-encoded Bitcoin addresses.
79 // Public-key-hash-addresses have version 0 (or 111 testnet).
80 // The data vector contains RIPEMD160(SHA256(pubkey)), where pubkey is the serialized public key.
81 const std::vector<unsigned char>& pubkey_prefix = params.Base58Prefix(CChainParams::PUBKEY_ADDRESS);
82 if (data.size() == hash.size() + pubkey_prefix.size() && std::equal(pubkey_prefix.begin(), pubkey_prefix.end(), data.begin())) {
83 std::copy(data.begin() + pubkey_prefix.size(), data.end(), hash.begin());
84 return CKeyID(hash);
85 }
86 // Script-hash-addresses have version 5 (or 196 testnet).
87 // The data vector contains RIPEMD160(SHA256(cscript)), where cscript is the serialized redemption script.
88 const std::vector<unsigned char>& script_prefix = params.Base58Prefix(CChainParams::SCRIPT_ADDRESS);
89 if (data.size() == hash.size() + script_prefix.size() && std::equal(script_prefix.begin(), script_prefix.end(), data.begin())) {
90 std::copy(data.begin() + script_prefix.size(), data.end(), hash.begin());
91 return CScriptID(hash);
92 }
93 }
94 data.clear();
95 auto bech = bech32::Decode(str);
96 if (bech.second.size() > 0 && bech.first == params.Bech32HRP()) {
97 // Bech32 decoding
98 int version = bech.second[0]; // The first 5 bit symbol is the witness version (0-16)
99 // The rest of the symbols are converted witness program bytes.
100 data.reserve(((bech.second.size() - 1) * 5) / 8);
101 if (ConvertBits<5, 8, false>([&](unsigned char c) { data.push_back(c); }, bech.second.begin() + 1, bech.second.end())) {
102 if (version == 0) {
103 {
104 WitnessV0KeyHash keyid;
105 if (data.size() == keyid.size()) {
106 std::copy(data.begin(), data.end(), keyid.begin());
107 return keyid;
108 }
109 }
110 {
111 WitnessV0ScriptHash scriptid;
112 if (data.size() == scriptid.size()) {
113 std::copy(data.begin(), data.end(), scriptid.begin());
114 return scriptid;
115 }
116 }
117 return CNoDestination();
118 }
119 if (version > 16 || data.size() < 2 || data.size() > 40) {
120 return CNoDestination();
121 }
122 WitnessUnknown unk;
123 unk.version = version;
124 std::copy(data.begin(), data.end(), unk.program);
125 unk.length = data.size();
126 return unk;
127 }
128 }
129 return CNoDestination();
130}

Callers 15

MutateTxAddOutAddrFunction · 0.85
IsValidDestinationStringFunction · 0.85
setlabelFunction · 0.85
getaccountFunction · 0.85
sendtoaddressFunction · 0.85
signmessageFunction · 0.85
getreceivedbyaddressFunction · 0.85
sendfromFunction · 0.85
sendmanyFunction · 0.85
addwitnessaddressFunction · 0.85
ListReceivedFunction · 0.85
listunspentFunction · 0.85

Calls 12

DecodeBase58CheckFunction · 0.85
DecodeFunction · 0.85
CNoDestinationClass · 0.85
CKeyIDClass · 0.70
CScriptIDClass · 0.70
ParamsClass · 0.70
sizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
clearMethod · 0.45
reserveMethod · 0.45
push_backMethod · 0.45

Tested by 2

BOOST_AUTO_TEST_CASEFunction · 0.68
BOOST_AUTO_TEST_CASEFunction · 0.68