rippled
Loading...
Searching...
No Matches
Account.h
1#ifndef XRPL_TEST_JTX_ACCOUNT_H_INCLUDED
2#define XRPL_TEST_JTX_ACCOUNT_H_INCLUDED
3
4#include <xrpl/beast/hash/uhash.h>
5#include <xrpl/protocol/KeyType.h>
6#include <xrpl/protocol/SecretKey.h>
7#include <xrpl/protocol/UintTypes.h>
8
9#include <string>
10#include <unordered_map>
11
12namespace ripple {
13namespace test {
14namespace jtx {
15
16class IOU;
17
20{
21private:
22 // Tag for access to private contr
24 {
25 };
26
27public:
29 static Account const master;
30
31 Account() = delete;
32 Account(Account&&) = default;
33 Account(Account const&) = default;
34 Account&
35 operator=(Account const&) = default;
36 Account&
37 operator=(Account&&) = default;
38
42
44 : Account(std::string(name), type)
45 {
46 }
47
48 // This constructor needs to be public so `std::pair` can use it when
49 // emplacing into the cache. However, it is logically `private`. This is
50 // enforced with the `privateTag` parameter.
51 Account(
55
60 explicit Account(std::string name, AccountID const& id);
61
64 Account(AcctStringType stringType, std::string base58SeedStr);
65
67 std::string const&
68 name() const
69 {
70 return name_;
71 }
72
74 PublicKey const&
75 pk() const
76 {
77 return pk_;
78 }
79
81 SecretKey const&
82 sk() const
83 {
84 return sk_;
85 }
86
92 id() const
93 {
94 return id_;
95 }
96
98 std::string const&
99 human() const
100 {
101 return human_;
102 }
103
109 operator AccountID() const
110 {
111 return id_;
112 }
113
115 IOU
116 operator[](std::string const& s) const;
117
118private:
119 static std::
122
123 // Return the account from the cache & add it to the cache if needed
124 static Account
126
131 std::string human_; // base58 public key string
132};
133
134inline bool
135operator==(Account const& lhs, Account const& rhs) noexcept
136{
137 return lhs.id() == rhs.id();
138}
139
140template <class Hasher>
141void
142hash_append(Hasher& h, Account const& v) noexcept
143{
144 hash_append(h, v.id());
145}
146
147inline auto
148operator<=>(Account const& lhs, Account const& rhs) noexcept
149{
150 return lhs.id() <=> rhs.id();
151}
152
153} // namespace jtx
154} // namespace test
155} // namespace ripple
156
157#endif
A public key.
Definition PublicKey.h:43
A secret key.
Definition SecretKey.h:19
Immutable cryptographic account descriptor.
Definition Account.h:20
PublicKey const & pk() const
Return the public key.
Definition Account.h:75
Account(char const *name, KeyType type=KeyType::secp256k1)
Definition Account.h:43
AccountID id() const
Returns the Account ID.
Definition Account.h:92
Account(Account &&)=default
static Account const master
The master account.
Definition Account.h:29
Account(Account const &)=default
std::string const & name() const
Return the name.
Definition Account.h:68
Account & operator=(Account &&)=default
IOU operator[](std::string const &s) const
Returns an IOU for the specified gateway currency.
Definition Account.cpp:79
static std::unordered_map< std::pair< std::string, KeyType >, Account, beast::uhash<> > cache_
Definition Account.h:121
SecretKey const & sk() const
Return the secret key.
Definition Account.h:82
Account & operator=(Account const &)=default
static Account fromCache(AcctStringType stringType, std::string name, KeyType type)
Definition Account.cpp:31
std::string const & human() const
Returns the human readable public key.
Definition Account.h:99
Converts to IOU Issue or STAmount.
T is_same_v
void hash_append(Hasher &h, Account const &v) noexcept
Definition Account.h:142
auto operator<=>(Account const &lhs, Account const &rhs) noexcept
Definition Account.h:148
bool operator==(Account const &lhs, Account const &rhs) noexcept
Definition Account.h:135
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:29
KeyType
Definition KeyType.h:9
STL namespace.