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 
67 // VFALCO In PublicKey.h for now
68 // AccountID
69 // calcAccountID (PublicKey const& pk);
70 
72 AccountID const&
73 xrpAccount();
74 
76 AccountID const&
77 noAccount();
78 
83 // DEPRECATED
84 bool
86 
87 // DEPRECATED Should be checking the currency or native flag
88 inline bool
89 isXRP(AccountID const& c)
90 {
91  return c == beast::zero;
92 }
93 
94 // DEPRECATED
95 inline std::string
96 to_string(AccountID const& account)
97 {
98  return toBase58(account);
99 }
100 
101 // DEPRECATED
102 inline std::ostream&
104 {
105  os << to_string(x);
106  return os;
107 }
108 
109 //------------------------------------------------------------------------------
110 
119 {
120 private:
125 
126 public:
127  AccountIDCache(AccountIDCache const&) = delete;
129  operator=(AccountIDCache const&) = delete;
130 
131  explicit AccountIDCache(std::size_t capacity);
132 
142  toBase58(AccountID const&) const;
143 };
144 
145 } // namespace ripple
146 
147 //------------------------------------------------------------------------------
148 
149 namespace std {
150 
151 // DEPRECATED
152 // VFALCO Use beast::uhash or a hardened container
153 template <>
155 {
156  explicit hash() = default;
157 };
158 
159 } // namespace std
160 
161 #endif
std::string
STL class.
ripple::AccountIDCache::capacity_
std::size_t capacity_
Definition: AccountID.h:122
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::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:118
ripple::base_uint
Integers of any length that is a multiple of 32-bits.
Definition: base_uint.h:73
ripple::AccountIDCache::m1_
hash_map< AccountID, std::string > m1_
Definition: AccountID.h:124
ripple::AccountIDCache::mutex_
std::mutex mutex_
Definition: AccountID.h:121
std::ostream
STL class.
ripple::detail::AccountIDTag::AccountIDTag
AccountIDTag()=default
cstddef
ripple::xrpAccount
AccountID const & xrpAccount()
Compute AccountID from public key.
Definition: AccountID.cpp:90
ripple::detail::AccountIDTag
Definition: AccountID.h:38
ripple::isXRP
bool isXRP(AccountID const &c)
Definition: AccountID.h:89
ripple::AccountIDCache::m0_
hash_map< AccountID, std::string > m0_
Definition: AccountID.h:123
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:158
ripple
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: RCLCensorshipDetector.h:29
std
STL namespace.
mutex
std::size_t
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:97
std::hash
ripple::AccountIDCache::toBase58
std::string toBase58(AccountID const &) const
Return ripple::toBase58 for the AccountID.
Definition: AccountID.cpp:134
ripple::to_issuer
bool to_issuer(AccountID &, std::string const &)
Convert hex or base58 string to AccountID.
Definition: AccountID.cpp:104
string