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

Class DestinationEncoder

src/key_io.cpp:21–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19namespace
20{
21class DestinationEncoder : public boost::static_visitor<std::string>
22{
23private:
24 const CChainParams& m_params;
25
26public:
27 DestinationEncoder(const CChainParams& params) : m_params(params) {}
28
29 std::string operator()(const CKeyID& id) const
30 {
31 std::vector<unsigned char> data = m_params.Base58Prefix(CChainParams::PUBKEY_ADDRESS);
32 data.insert(data.end(), id.begin(), id.end());
33 return EncodeBase58Check(data);
34 }
35
36 std::string operator()(const CScriptID& id) const
37 {
38 std::vector<unsigned char> data = m_params.Base58Prefix(CChainParams::SCRIPT_ADDRESS);
39 data.insert(data.end(), id.begin(), id.end());
40 return EncodeBase58Check(data);
41 }
42
43 std::string operator()(const WitnessV0KeyHash& id) const
44 {
45 std::vector<unsigned char> data = {0};
46 data.reserve(33);
47 ConvertBits<8, 5, true>([&](unsigned char c) { data.push_back(c); }, id.begin(), id.end());
48 return bech32::Encode(m_params.Bech32HRP(), data);
49 }
50
51 std::string operator()(const WitnessV0ScriptHash& id) const
52 {
53 std::vector<unsigned char> data = {0};
54 data.reserve(53);
55 ConvertBits<8, 5, true>([&](unsigned char c) { data.push_back(c); }, id.begin(), id.end());
56 return bech32::Encode(m_params.Bech32HRP(), data);
57 }
58
59 std::string operator()(const WitnessUnknown& id) const
60 {
61 if (id.version < 1 || id.version > 16 || id.length < 2 || id.length > 40) {
62 return {};
63 }
64 std::vector<unsigned char> data = {(unsigned char)id.version};
65 data.reserve(1 + (id.length * 8 + 4) / 5);
66 ConvertBits<8, 5, true>([&](unsigned char c) { data.push_back(c); }, id.program, id.program + id.length);
67 return bech32::Encode(m_params.Bech32HRP(), data);
68 }
69
70 std::string operator()(const CNoDestination& no) const { return {}; }
71};
72
73CTxDestination DecodeDestination(const std::string& str, const CChainParams& params)
74{

Callers 1

EncodeDestinationFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected