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 // Parses AccountID using Bitcoin's alphabet
61 // This is to catch user error. Likely not needed
62 // DEPRECATED
63 boost::optional<AccountID>
65 
66 // Compatibility with legacy code
67 bool
68 deprecatedParseBase58(AccountID& account, Json::Value const& jv);
69 
77 template <>
78 boost::optional<AccountID>
79 parseHex(std::string const& s);
80 
85 template <>
86 boost::optional<AccountID>
88 
96 // VFALCO In PublicKey.h for now
97 // AccountID
98 // calcAccountID (PublicKey const& pk);
99 
101 AccountID const&
102 xrpAccount();
103 
105 AccountID const&
106 noAccount();
107 
112 // DEPRECATED
113 bool
115 
116 // DEPRECATED Should be checking the currency or native flag
117 inline bool
118 isXRP(AccountID const& c)
119 {
120  return c == beast::zero;
121 }
122 
123 // DEPRECATED
124 inline std::string
125 to_string(AccountID const& account)
126 {
127  return toBase58(account);
128 }
129 
130 // DEPRECATED
131 inline std::ostream&
133 {
134  os << to_string(x);
135  return os;
136 }
137 
138 //------------------------------------------------------------------------------
139 
148 {
149 private:
154 
155 public:
156  AccountIDCache(AccountIDCache const&) = delete;
158  operator=(AccountIDCache const&) = delete;
159 
160  explicit AccountIDCache(std::size_t capacity);
161 
171  toBase58(AccountID const&) const;
172 };
173 
174 } // namespace ripple
175 
176 //------------------------------------------------------------------------------
177 
178 namespace std {
179 
180 // DEPRECATED
181 // VFALCO Use beast::uhash or a hardened container
182 template <>
184 {
185  explicit hash() = default;
186 };
187 
188 } // namespace std
189 
190 #endif
std::string
STL class.
ripple::AccountIDCache::capacity_
std::size_t capacity_
Definition: AccountID.h:151
ripple::AccountIDCache::AccountIDCache
AccountIDCache(AccountIDCache const &)=delete
ripple::deprecatedParseBitcoinAccountID
boost::optional< AccountID > deprecatedParseBitcoinAccountID(std::string const &s)
Definition: AccountID.cpp:49
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:75
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:147
ripple::base_uint
Definition: base_uint.h:63
ripple::AccountIDCache::m1_
hash_map< AccountID, std::string > m1_
Definition: AccountID.h:153
ripple::AccountIDCache::mutex_
std::mutex mutex_
Definition: AccountID.h:150
std::ostream
STL class.
ripple::detail::AccountIDTag::AccountIDTag
AccountIDTag()=default
cstddef
ripple::xrpAccount
AccountID const & xrpAccount()
Compute AccountID from public key.
Definition: AccountID.cpp:143
ripple::detail::AccountIDTag
Definition: AccountID.h:38
ripple::isXRP
bool isXRP(AccountID const &c)
Definition: AccountID.h:118
ripple::AccountIDCache::m0_
hash_map< AccountID, std::string > m0_
Definition: AccountID.h:152
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:87
std
STL namespace.
mutex
std::size_t
ripple::deprecatedParseBase58
bool deprecatedParseBase58(AccountID &account, Json::Value const &jv)
Definition: AccountID.cpp:62
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:150
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:190
ripple::to_issuer
bool to_issuer(AccountID &, std::string const &)
Convert hex or base58 string to AccountID.
Definition: AccountID.cpp:157
string