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 <boost/optional.hpp>
30 #include <cstddef>
31 #include <mutex>
32 #include <string>
33 
34 namespace ripple {
35 
36 namespace detail {
37 
39 {
40 public:
41  explicit AccountIDTag() = default;
42 };
43 
44 } // namespace detail
45 
48 
51 toBase58(AccountID const& v);
52 
56 template <>
57 boost::optional<AccountID>
58 parseBase58(std::string const& s);
59 
60 // Compatibility with legacy code
61 bool
62 deprecatedParseBase58(AccountID& account, Json::Value const& jv);
63 
71 template <>
72 boost::optional<AccountID>
73 parseHex(std::string const& s);
74 
79 template <>
80 boost::optional<AccountID>
82 
90 // VFALCO In PublicKey.h for now
91 // AccountID
92 // calcAccountID (PublicKey const& pk);
93 
95 AccountID const&
96 xrpAccount();
97 
99 AccountID const&
100 noAccount();
101 
106 // DEPRECATED
107 bool
109 
110 // DEPRECATED Should be checking the currency or native flag
111 inline bool
112 isXRP(AccountID const& c)
113 {
114  return c == beast::zero;
115 }
116 
117 // DEPRECATED
118 inline std::string
119 to_string(AccountID const& account)
120 {
121  return toBase58(account);
122 }
123 
124 // DEPRECATED
125 inline std::ostream&
127 {
128  os << to_string(x);
129  return os;
130 }
131 
132 //------------------------------------------------------------------------------
133 
142 {
143 private:
148 
149 public:
150  AccountIDCache(AccountIDCache const&) = delete;
152  operator=(AccountIDCache const&) = delete;
153 
154  explicit AccountIDCache(std::size_t capacity);
155 
165  toBase58(AccountID const&) const;
166 };
167 
168 } // namespace ripple
169 
170 //------------------------------------------------------------------------------
171 
172 namespace std {
173 
174 // DEPRECATED
175 // VFALCO Use beast::uhash or a hardened container
176 template <>
178 {
179  explicit hash() = default;
180 };
181 
182 } // namespace std
183 
184 #endif
std::string
STL class.
ripple::AccountIDCache::capacity_
std::size_t capacity_
Definition: AccountID.h:145
ripple::AccountIDCache::AccountIDCache
AccountIDCache(AccountIDCache const &)=delete
ripple::toBase58
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition: AccountID.cpp:29
ripple::parseHex
boost::optional< AccountID > parseHex(std::string const &s)
Parse AccountID from hexadecimal string.
Definition: AccountID.cpp:62
ripple::to_string
std::string to_string(ListDisposition disposition)
Definition: ValidatorList.cpp:42
ripple::operator<<
std::ostream & operator<<(std::ostream &os, TOffer< TIn, TOut > const &offer)
Definition: Offer.h:242
ripple::AccountIDCache
Caches the base58 representations of AccountIDs.
Definition: AccountID.h:141
ripple::base_uint
Definition: base_uint.h:63
ripple::AccountIDCache::m1_
hash_map< AccountID, std::string > m1_
Definition: AccountID.h:147
ripple::AccountIDCache::mutex_
std::mutex mutex_
Definition: AccountID.h:144
std::ostream
STL class.
ripple::detail::AccountIDTag::AccountIDTag
AccountIDTag()=default
cstddef
ripple::xrpAccount
AccountID const & xrpAccount()
Compute AccountID from public key.
Definition: AccountID.cpp:130
ripple::detail::AccountIDTag
Definition: AccountID.h:38
ripple::isXRP
bool isXRP(AccountID const &c)
Definition: AccountID.h:112
ripple::AccountIDCache::m0_
hash_map< AccountID, std::string > m0_
Definition: AccountID.h:146
ripple::AccountIDCache::operator=
AccountIDCache & operator=(AccountIDCache const &)=delete
ripple::base_uint< 160, detail::AccountIDTag >::hasher
hardened_hash<> hasher
Value hashing function.
Definition: base_uint.h:148
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
ripple::parseHexOrBase58
boost::optional< AccountID > parseHexOrBase58(std::string const &s)
Parse AccountID from hex or checked base58 string.
Definition: AccountID.cpp:74
std
STL namespace.
mutex
std::size_t
ripple::deprecatedParseBase58
bool deprecatedParseBase58(AccountID &account, Json::Value const &jv)
Definition: AccountID.cpp:49
std::unordered_map
STL class.
ripple::parseBase58
boost::optional< AccountID > parseBase58(std::string const &s)
Parse AccountID from checked, base58 string.
Definition: AccountID.cpp:36
ripple::noAccount
AccountID const & noAccount()
A placeholder for empty accounts.
Definition: AccountID.cpp:137
Json::Value
Represents a JSON value.
Definition: json_value.h:145
std::hash
ripple::AccountIDCache::toBase58
std::string toBase58(AccountID const &) const
Return ripple::toBase58 for the AccountID.
Definition: AccountID.cpp:177
ripple::to_issuer
bool to_issuer(AccountID &, std::string const &)
Convert hex or base58 string to AccountID.
Definition: AccountID.cpp:144
string