xrpld
Loading...
Searching...
No Matches
AccountID.h
1#pragma once
2
3#include <xrpl/protocol/tokens.h>
4// VFALCO Uncomment when the header issues are resolved
5// #include <xrpl/protocol/PublicKey.h>
6#include <xrpl/basics/base_uint.h>
7#include <xrpl/basics/contract.h>
8#include <xrpl/beast/utility/Zero.h>
9#include <xrpl/json/json_value.h>
10#include <xrpl/protocol/SField.h>
11#include <xrpl/protocol/json_get_or_throw.h>
12
13#include <cstddef>
14#include <functional>
15#include <optional>
16#include <ostream>
17#include <string>
18
19namespace xrpl {
20
21namespace detail {
22
24{
25public:
26 explicit AccountIDTag() = default;
27};
28
29} // namespace detail
30
35
40toBase58(AccountID const& v);
41
46template <>
48parseBase58(std::string const& s);
49
57// VFALCO In PublicKey.h for now
58// AccountID
59// calcAccountID (PublicKey const& pk);
60
64AccountID const&
66
70AccountID const&
71noAccount();
72
78// DEPRECATED
79bool
81
82// DEPRECATED Should be checking the currency or native flag
83inline bool
85{
86 return c == beast::kZero;
87}
88
89// DEPRECATED
90inline std::string
91to_string(AccountID const& account)
92{
93 return toBase58(account);
94}
95
96// DEPRECATED
99{
100 os << to_string(x);
101 return os;
102}
103
117void
119
120} // namespace xrpl
121
122//------------------------------------------------------------------------------
123namespace json {
124template <>
125inline xrpl::AccountID
126getOrThrow(json::Value const& v, xrpl::SField const& field)
127{
128 using namespace xrpl;
129
130 std::string const b58 = getOrThrow<std::string>(v, field);
131 if (auto const r = parseBase58<AccountID>(b58))
132 return *r;
133 Throw<JsonTypeMismatchError>(field.getJsonName(), "AccountID");
134}
135} // namespace json
136
137//------------------------------------------------------------------------------
138
139namespace std {
140
141// DEPRECATED
142// VFALCO Use beast::uhash or a hardened container
143template <>
145{
146 hash() = default;
147};
148
149} // namespace std
Represents a JSON value.
Definition json_value.h:117
Integers of any length that is a multiple of 32-bits.
Definition base_uint.h:82
Identifies fields.
Definition SField.h:132
json::StaticString const & getJsonName() const
Definition SField.h:210
constexpr Zero kZero
Definition Zero.h:30
JSON (JavaScript Object Notation).
Definition json_errors.h:5
xrpl::AccountID getOrThrow(json::Value const &v, xrpl::SField const &field)
Definition AccountID.h:126
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
bool isXRP(AccountID const &c)
Definition AccountID.h:84
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:95
std::ostream & operator<<(std::ostream &out, BaseUInt< Bits, Tag > const &u)
Definition base_uint.h:666
std::string to_string(BaseUInt< Bits, Tag > const &a)
Definition base_uint.h:651
void initAccountIdCache(std::size_t count)
Initialize the global cache used to map AccountID to base58 conversions.
Definition AccountID.cpp:88
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34
AccountID const & noAccount()
A placeholder for empty accounts.
AccountID const & xrpAccount()
Compute AccountID from public key.
bool toIssuer(AccountID &, std::string const &)
Convert hex or base58 string to AccountID.
XRPL_NO_SANITIZE_ADDRESS void Throw(Args &&... args)
Definition contract.h:52