18 class DestinationEncoder {
26 std::string operator()(
const PKHash &
id)
const {
27 std::vector<uint8_t> data =
29 data.insert(data.end(),
id.begin(),
id.end());
33 std::string operator()(
const ScriptHash &
id)
const {
34 std::vector<uint8_t> data =
36 data.insert(data.end(),
id.begin(),
id.end());
40 std::string operator()(
const CNoDestination &no)
const {
return {}; }
45 std::vector<uint8_t> data;
54 const std::vector<uint8_t> &pubkey_prefix =
56 if (data.size() == hash.
size() + pubkey_prefix.size() &&
57 std::equal(pubkey_prefix.begin(), pubkey_prefix.end(), data.begin())) {
58 std::copy(data.begin() + pubkey_prefix.size(), data.end(),
65 const std::vector<uint8_t> &script_prefix =
67 if (data.size() == hash.
size() + script_prefix.size() &&
68 std::equal(script_prefix.begin(), script_prefix.end(), data.begin())) {
69 std::copy(data.begin() + script_prefix.size(), data.end(),
83 std::vector<uint8_t> data;
85 const std::vector<uint8_t> &privkey_prefix =
87 if ((data.size() == 32 + privkey_prefix.size() ||
88 (data.size() == 33 + privkey_prefix.size() && data.back() == 1)) &&
89 std::equal(privkey_prefix.begin(), privkey_prefix.end(),
91 bool compressed = data.size() == 33 + privkey_prefix.size();
92 key.
Set(data.begin() + privkey_prefix.size(),
93 data.begin() + privkey_prefix.size() + 32, compressed);
109 data.insert(data.end(), key.
begin(), key.
end());
120 std::vector<uint8_t> data;
122 const std::vector<uint8_t> &
prefix =
125 std::equal(
prefix.begin(),
prefix.end(), data.begin())) {
133 std::vector<uint8_t> data =
135 size_t size = data.size();
137 key.
Encode(data.data() + size);
144 std::vector<uint8_t> data;
146 const std::vector<uint8_t> &
prefix =
149 std::equal(
prefix.begin(),
prefix.end(), data.begin())) {
157 std::vector<uint8_t> data =
159 size_t size = data.size();
161 key.
Encode(data.data() + size);
190 return std::visit(DestinationEncoder(params), dest);
195 return DecodeLegacyDestination(str, params);
std::string EncodeBase58Check(Span< const uint8_t > input)
Encode a byte span into a base58-encoded string, including checksum.
static bool DecodeBase58Check(const char *psz, std::vector< uint8_t > &vchRet, int max_ret_len)
std::string EncodeCashAddr(const CTxDestination &dst, const CChainParams ¶ms)
CTxDestination DecodeCashAddr(const std::string &addr, const CChainParams ¶ms)
const CChainParams & Params()
Return the currently selected parameters.
CChainParams defines various tweakable parameters of a given instance of the Bitcoin system.
const std::vector< uint8_t > & Base58Prefix(Base58Type type) const
Return the list of hostnames to look up for DNS seeds.
An encapsulated secp256k1 private key.
const uint8_t * begin() const
bool IsValid() const
Check whether this private key is valid.
bool IsCompressed() const
Check whether the public key corresponding to this private key is (to be) compressed.
void Set(const T pbegin, const T pend, bool fCompressedIn)
Initialize using begin and end iterators to byte data.
const uint8_t * end() const
virtual bool UseCashAddrEncoding() const =0
virtual const CChainParams & GetChainParams() const =0
unsigned int size() const
void memory_cleanse(void *ptr, size_t len)
Secure overwrite a buffer (possibly containing secret data) with zero-bytes.
std::string EncodeDestination(const CTxDestination &dest, const Config &config)
bool IsValidDestinationString(const std::string &str, const CChainParams ¶ms)
std::string EncodeExtKey(const CExtKey &key)
CExtPubKey DecodeExtPubKey(const std::string &str)
std::string EncodeSecret(const CKey &key)
CTxDestination DecodeDestination(const std::string &addr, const CChainParams ¶ms)
CKey DecodeSecret(const std::string &str)
std::string EncodeExtPubKey(const CExtPubKey &key)
CTxDestination DecodeLegacyAddr(const std::string &str, const CChainParams ¶ms)
std::string EncodeLegacyAddr(const CTxDestination &dest, const CChainParams ¶ms)
CExtKey DecodeExtKey(const std::string &str)
const CChainParams & m_params
const unsigned int BIP32_EXTKEY_SIZE
bool IsValidDestination(const CTxDestination &dest)
Check whether a CTxDestination is a CNoDestination.
std::variant< CNoDestination, PKHash, ScriptHash > CTxDestination
A txout script template with a specific destination.
void Encode(uint8_t code[BIP32_EXTKEY_SIZE]) const
void Decode(const uint8_t code[BIP32_EXTKEY_SIZE])
void Encode(uint8_t code[BIP32_EXTKEY_SIZE]) const
void Decode(const uint8_t code[BIP32_EXTKEY_SIZE])