rippled
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 <ripple/protocol/tokens.h>
24 // VFALCO Uncomment when the header issues are resolved
25 //#include <ripple/protocol/PublicKey.h>
26 #include <ripple/basics/UnorderedContainers.h>
27 #include <ripple/basics/base_uint.h>
28 #include <ripple/json/json_value.h>
29 #include <ripple/protocol/json_get_or_throw.h>
30 
31 #include <cstddef>
32 #include <mutex>
33 #include <optional>
34 #include <string>
35 
36 namespace ripple {
37 
38 namespace detail {
39 
41 {
42 public:
43  explicit AccountIDTag() = default;
44 };
45 
46 } // namespace detail
47 
50 
53 toBase58(AccountID const& v);
54 
58 template <>
60 parseBase58(std::string const& s);
61 
69 // VFALCO In PublicKey.h for now
70 // AccountID
71 // calcAccountID (PublicKey const& pk);
72 
74 AccountID const&
75 xrpAccount();
76 
78 AccountID const&
79 noAccount();
80 
85 // DEPRECATED
86 bool
88 
89 // DEPRECATED Should be checking the currency or native flag
90 inline bool
91 isXRP(AccountID const& c)
92 {
93  return c == beast::zero;
94 }
95 
96 // DEPRECATED
97 inline std::string
98 to_string(AccountID const& account)
99 {
100  return toBase58(account);
101 }
102 
103 // DEPRECATED
104 inline std::ostream&
106 {
107  os << to_string(x);
108  return os;
109 }
110 
123 void
125 
126 } // namespace ripple
127 
128 //------------------------------------------------------------------------------
129 namespace Json {
130 template <>
131 inline ripple::AccountID
132 getOrThrow(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 
145 namespace std {
146 
147 // DEPRECATED
148 // VFALCO Use beast::uhash or a hardened container
149 template <>
151 {
152  explicit hash() = default;
153 };
154 
155 } // namespace std
156 
157 #endif
std::string
STL class.
ripple::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:104
Json::getOrThrow
ripple::AccountID getOrThrow(Json::Value const &v, ripple::SField const &field)
Definition: AccountID.h:132
ripple::operator<<
std::ostream & operator<<(std::ostream &os, TOffer< TIn, TOut > const &offer)
Definition: Offer.h:303
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:82
Json
JSON (JavaScript Object Notation).
Definition: DeliverMax.h:28
std::ostream
STL class.
ripple::detail::AccountIDTag::AccountIDTag
AccountIDTag()=default
cstddef
ripple::xrpAccount
AccountID const & xrpAccount()
Compute AccountID from public key.
Definition: AccountID.cpp:168
ripple::hardened_hash
Seed functor once per construction.
Definition: hardened_hash.h:96
ripple::detail::AccountIDTag
Definition: AccountID.h:40
ripple::isXRP
bool isXRP(AccountID const &c)
Definition: AccountID.h:91
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::initAccountIdCache
void initAccountIdCache(std::size_t count)
Initialize the global cache used to map AccountID to base58 conversions.
Definition: AccountID.cpp:97
ripple::SField
Identifies fields.
Definition: SField.h:139
std
STL namespace.
optional
mutex
std::size_t
ripple::to_string
std::string to_string(Manifest const &m)
Format the specified manifest to a string for debugging purposes.
Definition: app/misc/impl/Manifest.cpp:41
ripple::parseBase58
std::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
Definition: AccountID.cpp:114
ripple::noAccount
AccountID const & noAccount()
A placeholder for empty accounts.
Definition: AccountID.cpp:175
Json::Value
Represents a JSON value.
Definition: json_value.h:145
std::hash
ripple::to_issuer
bool to_issuer(AccountID &, std::string const &)
Convert hex or base58 string to AccountID.
Definition: AccountID.cpp:182
string