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/base_uint.h>
27 #include <ripple/basics/UnorderedContainers.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 } // detail
45 
47 using AccountID = base_uint<
49 
52 toBase58 (AccountID const& v);
53 
57 template<>
58 boost::optional<AccountID>
59 parseBase58 (std::string const& s);
60 
61 // Parses AccountID using Bitcoin's alphabet
62 // This is to catch user error. Likely not needed
63 // DEPRECATED
64 boost::optional<AccountID>
66 
67 // Compatibility with legacy code
68 bool
70  Json::Value const& jv);
71 
79 template<>
80 boost::optional<AccountID>
81 parseHex (std::string const& s);
82 
87 template<>
88 boost::optional<AccountID>
89 parseHexOrBase58 (std::string const& s);
90 
98 // VFALCO In PublicKey.h for now
99 //AccountID
100 //calcAccountID (PublicKey const& pk);
101 
103 AccountID const&
104 xrpAccount();
105 
107 AccountID const&
108 noAccount();
109 
114 // DEPRECATED
115 bool
116 to_issuer (AccountID&, std::string const&);
117 
118 // DEPRECATED Should be checking the currency or native flag
119 inline
120 bool
121 isXRP(AccountID const& c)
122 {
123  return c == beast::zero;
124 }
125 
126 // DEPRECATED
127 inline
129 to_string (AccountID const& account)
130 {
131  return toBase58(account);
132 }
133 
134 // DEPRECATED
136 {
137  os << to_string (x);
138  return os;
139 }
140 
141 //------------------------------------------------------------------------------
142 
151 {
152 private:
156  std::string> mutable m0_;
158  std::string> mutable m1_;
159 
160 public:
161  AccountIDCache(AccountIDCache const&) = delete;
162  AccountIDCache& operator= (AccountIDCache const&) = delete;
163 
164  explicit
165  AccountIDCache (std::size_t capacity);
166 
176  toBase58 (AccountID const&) const;
177 };
178 
179 } // ripple
180 
181 //------------------------------------------------------------------------------
182 
183 namespace std {
184 
185 // DEPRECATED
186 // VFALCO Use beast::uhash or a hardened container
187 template <>
188 struct hash <ripple::AccountID> : ripple::AccountID::hasher
189 {
190  explicit hash() = default;
191 };
192 
193 } // std
194 
195 #endif
std::string
STL class.
ripple::AccountIDCache::capacity_
std::size_t capacity_
Definition: AccountID.h:154
ripple::AccountIDCache::AccountIDCache
AccountIDCache(AccountIDCache const &)=delete
ripple::AccountID
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:48
ripple::deprecatedParseBitcoinAccountID
boost::optional< AccountID > deprecatedParseBitcoinAccountID(std::string const &s)
Definition: AccountID.cpp:50
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:79
ripple::base_uint< 160, detail::AccountIDTag >::hasher
hardened_hash<> hasher
Value hashing function.
Definition: base_uint.h:116
ripple::to_string
std::string to_string(ListDisposition disposition)
Definition: ValidatorList.cpp:41
ripple::operator<<
std::ostream & operator<<(std::ostream &os, TOffer< TIn, TOut > const &offer)
Definition: Offer.h:237
ripple::AccountIDCache
Caches the base58 representations of AccountIDs.
Definition: AccountID.h:150
ripple::base_uint
Definition: base_uint.h:65
ripple::AccountIDCache::m1_
hash_map< AccountID, std::string > m1_
Definition: AccountID.h:158
ripple::AccountIDCache::mutex_
std::mutex mutex_
Definition: AccountID.h:153
std::ostream
STL class.
ripple::detail::AccountIDTag::AccountIDTag
AccountIDTag()=default
cstddef
ripple::xrpAccount
AccountID const & xrpAccount()
Compute AccountID from public key.
Definition: AccountID.cpp:149
ripple::detail::AccountIDTag
Definition: AccountID.h:38
ripple::isXRP
bool isXRP(AccountID const &c)
Definition: AccountID.h:121
ripple::AccountIDCache::m0_
hash_map< AccountID, std::string > m0_
Definition: AccountID.h:156
ripple::AccountIDCache::operator=
AccountIDCache & operator=(AccountIDCache const &)=delete
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:91
std
STL namespace.
mutex
std::size_t
ripple::deprecatedParseBase58
bool deprecatedParseBase58(AccountID &account, Json::Value const &jv)
Definition: AccountID.cpp:64
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:156
Json::Value
Represents a JSON value.
Definition: json_value.h:141
std::hash
ripple::AccountIDCache::toBase58
std::string toBase58(AccountID const &) const
Return ripple::toBase58 for the AccountID.
Definition: AccountID.cpp:199
ripple::to_issuer
bool to_issuer(AccountID &, std::string const &)
Convert hex or base58 string to AccountID.
Definition: AccountID.cpp:163
string