rippled
Loading...
Searching...
No Matches
Account.h
1#pragma once
2
3#include <xrpl/beast/hash/uhash.h>
4#include <xrpl/protocol/KeyType.h>
5#include <xrpl/protocol/SecretKey.h>
6#include <xrpl/protocol/UintTypes.h>
7
8#include <string>
9#include <unordered_map>
10
11namespace xrpl {
12namespace test {
13namespace jtx {
14
15class IOU;
16
19{
20private:
21 // Tag for access to private contr
23 {
24 };
25
26public:
28 static Account const master;
29
30 Account() = delete;
31 Account(Account&&) = default;
32 Account(Account const&) = default;
33 Account&
34 operator=(Account const&) = default;
35 Account&
36 operator=(Account&&) = default;
37
41
42 Account(char const* name, KeyType type = KeyType::secp256k1) : Account(std::string(name), type)
43 {
44 }
45
46 // This constructor needs to be public so `std::pair` can use it when
47 // emplacing into the cache. However, it is logically `private`. This is
48 // enforced with the `privateTag` parameter.
50
55 explicit Account(std::string name, AccountID const& id);
56
59 Account(AcctStringType stringType, std::string base58SeedStr);
60
62 std::string const&
63 name() const
64 {
65 return name_;
66 }
67
69 PublicKey const&
70 pk() const
71 {
72 return pk_;
73 }
74
76 SecretKey const&
77 sk() const
78 {
79 return sk_;
80 }
81
87 id() const
88 {
89 return id_;
90 }
91
93 std::string const&
94 human() const
95 {
96 return human_;
97 }
98
104 operator AccountID() const
105 {
106 return id_;
107 }
108
110 IOU
111 operator[](std::string const& s) const;
112
113private:
115
116 // Return the account from the cache & add it to the cache if needed
117 static Account
119
124 std::string human_; // base58 public key string
125};
126
127inline bool
128operator==(Account const& lhs, Account const& rhs) noexcept
129{
130 return lhs.id() == rhs.id();
131}
132
133template <class Hasher>
134void
135hash_append(Hasher& h, Account const& v) noexcept
136{
137 hash_append(h, v.id());
138}
139
140inline auto
141operator<=>(Account const& lhs, Account const& rhs) noexcept
142{
143 return lhs.id() <=> rhs.id();
144}
145
146} // namespace jtx
147} // namespace test
148} // namespace xrpl
A public key.
Definition PublicKey.h:42
A secret key.
Definition SecretKey.h:18
Immutable cryptographic account descriptor.
Definition Account.h:19
Account(Account &&)=default
SecretKey const & sk() const
Return the secret key.
Definition Account.h:77
static Account fromCache(AcctStringType stringType, std::string name, KeyType type)
Definition Account.cpp:23
std::string const & human() const
Returns the human readable public key.
Definition Account.h:94
static std::unordered_map< std::pair< std::string, KeyType >, Account, beast::uhash<> > cache_
Definition Account.h:114
Account & operator=(Account const &)=default
std::string const & name() const
Return the name.
Definition Account.h:63
Account(char const *name, KeyType type=KeyType::secp256k1)
Definition Account.h:42
PublicKey const & pk() const
Return the public key.
Definition Account.h:70
static Account const master
The master account.
Definition Account.h:28
Account(Account const &)=default
IOU operator[](std::string const &s) const
Returns an IOU for the specified gateway currency.
Definition Account.cpp:67
AccountID id() const
Returns the Account ID.
Definition Account.h:87
Account & operator=(Account &&)=default
Converts to IOU Issue or STAmount.
STL namespace.
void hash_append(Hasher &h, Account const &v) noexcept
Definition Account.h:135
auto operator<=>(Account const &lhs, Account const &rhs) noexcept
Definition Account.h:141
bool operator==(Account const &lhs, Account const &rhs) noexcept
Definition Account.h:128
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:5
KeyType
Definition KeyType.h:8
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:28