rippled
Loading...
Searching...
No Matches
AccountID.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2014 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_PROTOCOL_ACCOUNTID_H_INCLUDED
21#define RIPPLE_PROTOCOL_ACCOUNTID_H_INCLUDED
22
23#include <xrpl/protocol/tokens.h>
24// VFALCO Uncomment when the header issues are resolved
25// #include <ripple/protocol/PublicKey.h>
26#include <xrpl/basics/UnorderedContainers.h>
27#include <xrpl/basics/base_uint.h>
28#include <xrpl/json/json_value.h>
29#include <xrpl/protocol/json_get_or_throw.h>
30
31#include <cstddef>
32#include <mutex>
33#include <optional>
34#include <string>
35
36namespace ripple {
37
38namespace detail {
39
41{
42public:
43 explicit AccountIDTag() = default;
44};
45
46} // namespace detail
47
50
53toBase58(AccountID const& v);
54
58template <>
60parseBase58(std::string const& s);
61
69// VFALCO In PublicKey.h for now
70// AccountID
71// calcAccountID (PublicKey const& pk);
72
74AccountID const&
76
78AccountID const&
79noAccount();
80
85// DEPRECATED
86bool
88
89// DEPRECATED Should be checking the currency or native flag
90inline bool
92{
93 return c == beast::zero;
94}
95
96// DEPRECATED
97inline std::string
98to_string(AccountID const& account)
99{
100 return toBase58(account);
101}
102
103// DEPRECATED
105operator<<(std::ostream& os, AccountID const& x)
106{
107 os << to_string(x);
108 return os;
109}
110
123void
125
126} // namespace ripple
127
128//------------------------------------------------------------------------------
129namespace Json {
130template <>
132getOrThrow(Json::Value const& v, ripple::SField const& field)
133{
134 using namespace ripple;
135
136 std::string const b58 = getOrThrow<std::string>(v, field);
137 if (auto const r = parseBase58<AccountID>(b58))
138 return *r;
139 Throw<JsonTypeMismatchError>(field.getJsonName(), "AccountID");
140}
141} // namespace Json
142
143//------------------------------------------------------------------------------
144
145namespace std {
146
147// DEPRECATED
148// VFALCO Use beast::uhash or a hardened container
149template <>
151{
152 explicit hash() = default;
153};
154
155} // namespace std
156
157#endif
Represents a JSON value.
Definition: json_value.h:148
Identifies fields.
Definition: SField.h:144
Seed functor once per construction.
Definition: hardened_hash.h:97
JSON (JavaScript Object Notation).
Definition: json_errors.h:25
ripple::AccountID getOrThrow(Json::Value const &v, ripple::SField const &field)
Definition: AccountID.h:132
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
AccountID const & noAccount()
A placeholder for empty accounts.
Definition: AccountID.cpp:185
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:114
bool isXRP(AccountID const &c)
Definition: AccountID.h:91
AccountID const & xrpAccount()
Compute AccountID from public key.
Definition: AccountID.cpp:178
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
Definition: AccountID.cpp:124
bool to_issuer(AccountID &, std::string const &)
Convert hex or base58 string to AccountID.
Definition: AccountID.cpp:192
void initAccountIdCache(std::size_t count)
Initialize the global cache used to map AccountID to base58 conversions.
Definition: AccountID.cpp:107
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
Definition: base_uint.h:637
std::string to_string(base_uint< Bits, Tag > const &a)
Definition: base_uint.h:630
STL namespace.