xrpld
Loading...
Searching...
No Matches
jtx/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::test::jtx {
12
13class IOU;
14
17{
18private:
19 // Tag for access to private contr
21 {
22 };
23
24public:
26 static Account const kMaster;
27
28 Account() = delete;
29 Account(Account&&) = default;
30 Account(Account const&) = default;
31 Account&
32 operator=(Account const&) = default;
33 Account&
34 operator=(Account&&) = default;
35
39
40 Account(char const* name, KeyType type = KeyType::Secp256k1) : Account(std::string(name), type)
41 {
42 }
43
44 // This constructor needs to be public so `std::pair` can use it when
45 // emplacing into the cache. However, it is logically `private`. This is
46 // enforced with the `privateTag` parameter.
48
50
53 explicit Account(std::string name, AccountID const& id);
54
57 Account(AcctStringType stringType, std::string base58SeedStr);
58
60 [[nodiscard]] std::string const&
61 name() const
62 {
63 return name_;
64 }
65
67 [[nodiscard]] PublicKey const&
68 pk() const
69 {
70 return pk_;
71 }
72
74 [[nodiscard]] SecretKey const&
75 sk() const
76 {
77 return sk_;
78 }
79
84 [[nodiscard]] AccountID
85 id() const
86 {
87 return id_;
88 }
89
91 [[nodiscard]] std::string const&
92 human() const
93 {
94 return human_;
95 }
96
102 operator AccountID() const
103 {
104 return id_;
105 }
106
108 IOU
109 operator[](std::string const& s) const;
110
111private:
113
114 // Return the account from the cache & add it to the cache if needed
115 static Account
117
122 std::string human_; // base58 public key string
123};
124
125inline bool
126operator==(Account const& lhs, Account const& rhs) noexcept
127{
128 return lhs.id() == rhs.id();
129}
130
131template <class Hasher>
132void
133hash_append(Hasher& h, Account const& v) noexcept // NOLINT(readability-identifier-naming)
134{
135 hash_append(h, v.id());
136}
137
138inline auto
139operator<=>(Account const& lhs, Account const& rhs) noexcept
140{
141 return lhs.id() <=> rhs.id();
142}
143
144} // namespace xrpl::test::jtx
A public key.
Definition PublicKey.h:42
A secret key.
Definition SecretKey.h:18
Immutable cryptographic account descriptor.
Definition jtx/Account.h:17
Account(Account &&)=default
SecretKey const & sk() const
Return the secret key.
Definition jtx/Account.h:75
static Account fromCache(AcctStringType stringType, std::string name, KeyType type)
std::string const & human() const
Returns the human readable public key.
Definition jtx/Account.h:92
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:61
PublicKey const & pk() const
Return the public key.
Definition jtx/Account.h:68
Account(Account const &)=default
static Account const kMaster
The master account.
Definition jtx/Account.h:26
IOU operator[](std::string const &s) const
Returns an IOU for the specified gateway currency.
AccountID id() const
Returns the Account ID.
Definition jtx/Account.h:85
Account & operator=(Account &&)=default
Account(char const *name, KeyType type=KeyType::Secp256k1)
Definition jtx/Account.h:40
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:28