| 223 | namespace |
| 224 | { |
| 225 | class DestinationEncoder : public boost::static_visitor<std::string> |
| 226 | { |
| 227 | private: |
| 228 | const CChainParams& m_params; |
| 229 | |
| 230 | public: |
| 231 | DestinationEncoder(const CChainParams& params) : m_params(params) {} |
| 232 | |
| 233 | std::string operator()(const CKeyID& id) const |
| 234 | { |
| 235 | std::vector<unsigned char> data = m_params.Base58Prefix(CChainParams::PUBKEY_ADDRESS); |
| 236 | data.insert(data.end(), id.begin(), id.end()); |
| 237 | return EncodeBase58Check(data); |
| 238 | } |
| 239 | |
| 240 | std::string operator()(const CScriptID& id) const |
| 241 | { |
| 242 | std::vector<unsigned char> data = m_params.Base58Prefix(CChainParams::SCRIPT_ADDRESS); |
| 243 | data.insert(data.end(), id.begin(), id.end()); |
| 244 | return EncodeBase58Check(data); |
| 245 | } |
| 246 | |
| 247 | std::string operator()(const WitnessV0KeyHash& id) const |
| 248 | { |
| 249 | std::vector<unsigned char> data = {0}; |
| 250 | ConvertBits<8, 5, true>(data, id.begin(), id.end()); |
| 251 | return bech32::Encode(m_params.Bech32HRP(), data); |
| 252 | } |
| 253 | |
| 254 | std::string operator()(const WitnessV0ScriptHash& id) const |
| 255 | { |
| 256 | std::vector<unsigned char> data = {0}; |
| 257 | ConvertBits<8, 5, true>(data, id.begin(), id.end()); |
| 258 | return bech32::Encode(m_params.Bech32HRP(), data); |
| 259 | } |
| 260 | |
| 261 | std::string operator()(const WitnessUnknown& id) const |
| 262 | { |
| 263 | if (id.version < 1 || id.version > 16 || id.length < 2 || id.length > 40) { |
| 264 | return {}; |
| 265 | } |
| 266 | std::vector<unsigned char> data = {(unsigned char)id.version}; |
| 267 | ConvertBits<8, 5, true>(data, id.program, id.program + id.length); |
| 268 | return bech32::Encode(m_params.Bech32HRP(), data); |
| 269 | } |
| 270 | |
| 271 | std::string operator()(const CNoDestination& no) const { return {}; } |
| 272 | }; |
| 273 | |
| 274 | CTxDestination DecodeDestination(const std::string& str, const CChainParams& params) |
| 275 | { |