xrpld
Toggle main menu visibility
Loading...
Searching...
No Matches
test
jtx
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
13
namespace
xrpl::test::jtx
{
14
15
class
IOU
;
16
20
class
Account
21
{
22
private
:
23
// Tag for access to private contr
24
struct
PrivateCtorTag
25
{
26
};
27
28
public
:
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
46
Account
(
std::string
name
,
KeyType
type =
KeyType::Secp256k1
);
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.
55
Account
(
std::string
name
,
std::pair<PublicKey, SecretKey>
const
& keys,
Account::PrivateCtorTag
);
56
58
63
explicit
Account
(
std::string
name
,
AccountID
const
&
id
);
64
65
enum class
AcctStringType
{
Base58Seed
,
Other
};
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
135
private
:
136
static
std::unordered_map<std::pair<std::string, KeyType>
,
Account
,
beast::Uhash<>
>
cache
;
137
138
// Return the account from the cache & add it to the cache if needed
139
static
Account
140
fromCache
(
AcctStringType
stringType,
std::string
name
,
KeyType
type);
141
142
std::string
name_
;
143
PublicKey
pk_
;
144
SecretKey
sk_
;
145
AccountID
id_
;
146
std::string
human_
;
// base58 public key string
147
};
148
149
inline
bool
150
operator==
(
Account
const
& lhs,
Account
const
& rhs)
noexcept
151
{
152
return
lhs.id() == rhs.id();
153
}
154
155
template
<
class
Hasher>
156
void
157
hash_append
(Hasher& h,
Account
const
& v)
noexcept
// NOLINT(readability-identifier-naming)
158
{
159
hash_append
(h, v.id());
160
}
161
162
inline
auto
163
operator<=>
(
Account
const
& lhs,
Account
const
& rhs)
noexcept
164
{
165
return
lhs.id() <=> rhs.id();
166
}
167
168
}
// namespace xrpl::test::jtx
std::string
xrpl::PublicKey
A public key.
Definition
PublicKey.h:53
xrpl::SecretKey
A secret key.
Definition
SecretKey.h:24
xrpl::test::jtx::Account
Immutable cryptographic account descriptor.
Definition
jtx/Account.h:21
xrpl::test::jtx::Account::Account
Account(Account &&)=default
xrpl::test::jtx::Account::human_
std::string human_
Definition
jtx/Account.h:146
xrpl::test::jtx::Account::sk
SecretKey const & sk() const
Return the secret key.
Definition
jtx/Account.h:93
xrpl::test::jtx::Account::fromCache
static Account fromCache(AcctStringType stringType, std::string name, KeyType type)
Definition
jtx/impl/Account.cpp:44
xrpl::test::jtx::Account::sk_
SecretKey sk_
Definition
jtx/Account.h:144
xrpl::test::jtx::Account::human
std::string const & human() const
Returns the human readable public key.
Definition
jtx/Account.h:113
xrpl::test::jtx::Account::cache
static std::unordered_map< std::pair< std::string, KeyType >, Account, beast::Uhash<> > cache
Definition
jtx/Account.h:136
xrpl::test::jtx::Account::pk_
PublicKey pk_
Definition
jtx/Account.h:143
xrpl::test::jtx::Account::id_
AccountID id_
Definition
jtx/Account.h:145
xrpl::test::jtx::Account::operator=
Account & operator=(Account const &)=default
xrpl::test::jtx::Account::name
std::string const & name() const
Return the name.
Definition
jtx/Account.h:75
xrpl::test::jtx::Account::pk
PublicKey const & pk() const
Return the public key.
Definition
jtx/Account.h:84
xrpl::test::jtx::Account::Account
Account(Account const &)=default
xrpl::test::jtx::Account::Account
Account()=delete
xrpl::test::jtx::Account::kMaster
static Account const kMaster
The master account.
Definition
jtx/Account.h:32
xrpl::test::jtx::Account::name_
std::string name_
Definition
jtx/Account.h:142
xrpl::test::jtx::Account::AcctStringType
AcctStringType
Definition
jtx/Account.h:65
xrpl::test::jtx::Account::AcctStringType::Base58Seed
@ Base58Seed
Definition
jtx/Account.h:65
xrpl::test::jtx::Account::AcctStringType::Other
@ Other
Definition
jtx/Account.h:65
xrpl::test::jtx::Account::operator[]
IOU operator[](std::string const &s) const
Returns an IOU for the specified gateway currency.
Definition
jtx/impl/Account.cpp:92
xrpl::test::jtx::Account::id
AccountID id() const
Returns the Account ID.
Definition
jtx/Account.h:104
xrpl::test::jtx::Account::operator=
Account & operator=(Account &&)=default
xrpl::test::jtx::Account::Account
Account(char const *name, KeyType type=KeyType::Secp256k1)
Definition
jtx/Account.h:48
xrpl::test::jtx::IOU
Converts to IOU Issue or STAmount.
Definition
src/test/jtx/amount.h:404
std
STL namespace.
xrpl::test::jtx
Definition
Oracle_test.cpp:34
xrpl::test::jtx::hash_append
void hash_append(Hasher &h, Account const &v) noexcept
Definition
jtx/Account.h:157
xrpl::test::jtx::operator<=>
auto operator<=>(Account const &lhs, Account const &rhs) noexcept
Definition
jtx/Account.h:163
xrpl::test::jtx::operator==
bool operator==(Account const &lhs, Account const &rhs) noexcept
Definition
jtx/Account.h:150
xrpl::KeyType
KeyType
Definition
KeyType.h:8
xrpl::KeyType::Secp256k1
@ Secp256k1
Definition
KeyType.h:9
xrpl::AccountID
BaseUInt< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition
AccountID.h:34
std::pair
string
beast::Uhash
Definition
uhash.h:11
xrpl::test::jtx::Account::PrivateCtorTag
Definition
jtx/Account.h:25
unordered_map
utility
Generated by
1.17.0