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 <optional>
33#include <string>
34
35namespace ripple {
36
37namespace detail {
38
40{
41public:
42 explicit AccountIDTag() = default;
43};
44
45} // namespace detail
46
49
52toBase58(AccountID const& v);
53
57template <>
59parseBase58(std::string const& s);
60
68// VFALCO In PublicKey.h for now
69// AccountID
70// calcAccountID (PublicKey const& pk);
71
73AccountID const&
75
77AccountID const&
78noAccount();
79
84// DEPRECATED
85bool
87
88// DEPRECATED Should be checking the currency or native flag
89inline bool
91{
92 return c == beast::zero;
93}
94
95// DEPRECATED
96inline std::string
97to_string(AccountID const& account)
98{
99 return toBase58(account);
100}
101
102// DEPRECATED
104operator<<(std::ostream& os, AccountID const& x)
105{
106 os << to_string(x);
107 return os;
108}
109
122void
124
125} // namespace ripple
126
127//------------------------------------------------------------------------------
128namespace Json {
129template <>
131getOrThrow(Json::Value const& v, ripple::SField const& field)
132{
133 using namespace ripple;
134
135 std::string const b58 = getOrThrow<std::string>(v, field);
136 if (auto const r = parseBase58<AccountID>(b58))
137 return *r;
138 Throw<JsonTypeMismatchError>(field.getJsonName(), "AccountID");
139}
140} // namespace Json
141
142//------------------------------------------------------------------------------
143
144namespace std {
145
146// DEPRECATED
147// VFALCO Use beast::uhash or a hardened container
148template <>
150{
151 hash() = default;
152};
153
154} // namespace std
155
156#endif
Represents a JSON value.
Definition json_value.h:149
Identifies fields.
Definition SField.h:146
Seed functor once per construction.
JSON (JavaScript Object Notation).
Definition json_errors.h:25
ripple::AccountID getOrThrow(Json::Value const &v, ripple::SField const &field)
Definition AccountID.h:131
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
AccountID const & noAccount()
A placeholder for empty accounts.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
bool isXRP(AccountID const &c)
Definition AccountID.h:90
AccountID const & xrpAccount()
Compute AccountID from public key.
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
bool to_issuer(AccountID &, std::string const &)
Convert hex or base58 string to AccountID.
void initAccountIdCache(std::size_t count)
Initialize the global cache used to map AccountID to base58 conversions.
std::ostream & operator<<(std::ostream &out, base_uint< Bits, Tag > const &u)
Definition base_uint.h:647
std::string to_string(base_uint< Bits, Tag > const &a)
Definition base_uint.h:630
STL namespace.