xrpld
Loading...
Searching...
No Matches
jtx/Account.h
1#pragma once
2
3#include <xrpl/beast/hash/uhash.h>
4#include <xrpl/protocol/AccountID.h>
5#include <xrpl/protocol/KeyType.h>
6#include <xrpl/protocol/PublicKey.h>
7#include <xrpl/protocol/SecretKey.h>
8
9#include <string>
10#include <unordered_map>
11#include <utility>
12
13namespace xrpl::test::jtx {
14
15class IOU;
16
21{
22private:
23 // Tag for access to private contr
25 {
26 };
27
28public:
32 static Account const kMaster;
33
34 Account() = delete;
35 Account(Account&&) = default;
36 Account(Account const&) = default;
37 Account&
38 operator=(Account const&) = default;
39 Account&
40 operator=(Account&&) = default;
41
47
48 Account(char const* name, KeyType type = KeyType::Secp256k1) : Account(std::string(name), type)
49 {
50 }
51
52 // This constructor needs to be public so `std::pair` can use it when
53 // emplacing into the cache. However, it is logically `private`. This is
54 // enforced with the `privateTag` parameter.
56
58
63 explicit Account(std::string name, AccountID const& id);
64
69 Account(AcctStringType stringType, std::string base58SeedStr);
70
74 [[nodiscard]] std::string const&
75 name() const
76 {
77 return name_;
78 }
79
83 [[nodiscard]] PublicKey const&
84 pk() const
85 {
86 return pk_;
87 }
88
92 [[nodiscard]] SecretKey const&
93 sk() const
94 {
95 return sk_;
96 }
97
103 [[nodiscard]] AccountID
104 id() const
105 {
106 return id_;
107 }
108
112 [[nodiscard]] std::string const&
113 human() const
114 {
115 return human_;
116 }
117
124 operator AccountID() const
125 {
126 return id_;
127 }
128
132 IOU
133 operator[](std::string const& s) const;
134
135private:
137
138 // Return the account from the cache & add it to the cache if needed
139 static Account
141
146 std::string human_; // base58 public key string
147};
148
149inline bool
150operator==(Account const& lhs, Account const& rhs) noexcept
151{
152 return lhs.id() == rhs.id();
153}
154
155template <class Hasher>
156void
157hash_append(Hasher& h, Account const& v) noexcept // NOLINT(readability-identifier-naming)
158{
159 hash_append(h, v.id());
160}
161
162inline auto
163operator<=>(Account const& lhs, Account const& rhs) noexcept
164{
165 return lhs.id() <=> rhs.id();
166}
167
168} // namespace xrpl::test::jtx
A public key.
Definition PublicKey.h:53
A secret key.
Definition SecretKey.h:24
Immutable cryptographic account descriptor.
Definition jtx/Account.h:21
Account(Account &&)=default
SecretKey const & sk() const
Return the secret key.
Definition jtx/Account.h:93
static Account fromCache(AcctStringType stringType, std::string name, KeyType type)
std::string const & human() const
Returns the human readable public key.
static std::unordered_map< std::pair< std::string, KeyType >, Account, beast::Uhash<> > cache
Account & operator=(Account const &)=default
std::string const & name() const
Return the name.
Definition jtx/Account.h:75
PublicKey const & pk() const
Return the public key.
Definition jtx/Account.h:84
Account(Account const &)=default
static Account const kMaster
The master account.
Definition jtx/Account.h:32
IOU operator[](std::string const &s) const
Returns an IOU for the specified gateway currency.
AccountID id() const
Returns the Account ID.
Account & operator=(Account &&)=default
Account(char const *name, KeyType type=KeyType::Secp256k1)
Definition jtx/Account.h:48
Converts to IOU Issue or STAmount.
STL namespace.
void hash_append(Hasher &h, Account const &v) noexcept
auto operator<=>(Account const &lhs, Account const &rhs) noexcept
bool operator==(Account const &lhs, Account const &rhs) noexcept
KeyType
Definition KeyType.h:8
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:34