| 22 | namespace |
| 23 | { |
| 24 | class DestinationEncoder |
| 25 | { |
| 26 | private: |
| 27 | const CChainParams& m_params; |
| 28 | // ELEMENTS: |
| 29 | const bool for_parent; |
| 30 | |
| 31 | public: |
| 32 | explicit DestinationEncoder(const CChainParams& params, const bool for_parent) : m_params(params), for_parent(for_parent) {} |
| 33 | |
| 34 | std::string operator()(const PKHash& id) const |
| 35 | { |
| 36 | if (id.blinding_pubkey.IsFullyValid()) { |
| 37 | std::vector<unsigned char> data = m_params.Base58Prefix(CChainParams::BLINDED_ADDRESS); |
| 38 | // Blinded addresses have the actual address type prefix inside the payload. |
| 39 | std::vector<unsigned char> prefix = m_params.Base58Prefix(CChainParams::PUBKEY_ADDRESS); |
| 40 | data.insert(data.end(), prefix.begin(), prefix.end()); |
| 41 | data.insert(data.end(), id.blinding_pubkey.begin(), id.blinding_pubkey.end()); |
| 42 | data.insert(data.end(), id.begin(), id.end()); |
| 43 | return EncodeBase58Check(data); |
| 44 | } |
| 45 | |
| 46 | CChainParams::Base58Type type = for_parent ? CChainParams::PARENT_PUBKEY_ADDRESS : CChainParams::PUBKEY_ADDRESS; |
| 47 | std::vector<unsigned char> data = m_params.Base58Prefix(type); |
| 48 | data.insert(data.end(), id.begin(), id.end()); |
| 49 | return EncodeBase58Check(data); |
| 50 | } |
| 51 | |
| 52 | std::string operator()(const ScriptHash& id) const |
| 53 | { |
| 54 | if (id.blinding_pubkey.IsFullyValid()) { |
| 55 | std::vector<unsigned char> data = m_params.Base58Prefix(CChainParams::BLINDED_ADDRESS); |
| 56 | // Blinded addresses have the actual address type prefix inside the payload. |
| 57 | std::vector<unsigned char> prefix = m_params.Base58Prefix(CChainParams::SCRIPT_ADDRESS); |
| 58 | data.insert(data.end(), prefix.begin(), prefix.end()); |
| 59 | data.insert(data.end(), id.blinding_pubkey.begin(), id.blinding_pubkey.end()); |
| 60 | data.insert(data.end(), id.begin(), id.end()); |
| 61 | return EncodeBase58Check(data); |
| 62 | } |
| 63 | |
| 64 | CChainParams::Base58Type type = for_parent ? CChainParams::PARENT_SCRIPT_ADDRESS : CChainParams::SCRIPT_ADDRESS; |
| 65 | std::vector<unsigned char> data = m_params.Base58Prefix(type); |
| 66 | data.insert(data.end(), id.begin(), id.end()); |
| 67 | return EncodeBase58Check(data); |
| 68 | } |
| 69 | |
| 70 | std::string operator()(const WitnessV0KeyHash& id) const |
| 71 | { |
| 72 | std::vector<unsigned char> data = {0}; |
| 73 | data.reserve(53); |
| 74 | if (id.blinding_pubkey.IsFullyValid()) { |
| 75 | std::vector<unsigned char> bytes(id.blinding_pubkey.begin(), id.blinding_pubkey.end()); |
| 76 | bytes.insert(bytes.end(), id.begin(), id.end()); |
| 77 | ConvertBits<8, 5, true>([&](unsigned char c) { data.push_back(c); }, bytes.begin(), bytes.end()); |
| 78 | const std::string& hrp = for_parent ? m_params.ParentBlech32HRP() : m_params.Blech32HRP(); |
| 79 | return blech32::Encode(blech32::Encoding::BLECH32, hrp, data); |
| 80 | } |
| 81 |
no outgoing calls
no test coverage detected