rippled
Loading...
Searching...
No Matches
Account.h
1//------------------------------------------------------------------------------
2/*
3 This file is part of rippled: https://github.com/ripple/rippled
4 Copyright (c) 2012-2015 Ripple Labs Inc.
5
6 Permission to use, copy, modify, and/or distribute this software for any
7 purpose with or without fee is hereby granted, provided that the above
8 copyright notice and this permission notice appear in all copies.
9
10 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 ANY SPECIAL , DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17*/
18//==============================================================================
19
20#ifndef RIPPLE_TEST_JTX_ACCOUNT_H_INCLUDED
21#define RIPPLE_TEST_JTX_ACCOUNT_H_INCLUDED
22
23#include <xrpl/beast/hash/uhash.h>
24#include <xrpl/protocol/KeyType.h>
25#include <xrpl/protocol/SecretKey.h>
26#include <xrpl/protocol/UintTypes.h>
27
28#include <string>
29#include <unordered_map>
30
31namespace ripple {
32namespace test {
33namespace jtx {
34
35class IOU;
36
39{
40private:
41 // Tag for access to private contr
43 {
44 };
45
46public:
48 static Account const master;
49
50 Account() = delete;
51 Account(Account&&) = default;
52 Account(Account const&) = default;
53 Account&
54 operator=(Account const&) = default;
55 Account&
56 operator=(Account&&) = default;
57
61
63 : Account(std::string(name), type)
64 {
65 }
66
67 // This constructor needs to be public so `std::pair` can use it when
68 // emplacing into the cache. However, it is logically `private`. This is
69 // enforced with the `privateTag` parameter.
70 Account(
74
79 explicit Account(std::string name, AccountID const& id);
80
83 Account(AcctStringType stringType, std::string base58SeedStr);
84
86 std::string const&
87 name() const
88 {
89 return name_;
90 }
91
93 PublicKey const&
94 pk() const
95 {
96 return pk_;
97 }
98
100 SecretKey const&
101 sk() const
102 {
103 return sk_;
104 }
105
111 id() const
112 {
113 return id_;
114 }
115
117 std::string const&
118 human() const
119 {
120 return human_;
121 }
122
128 operator AccountID() const
129 {
130 return id_;
131 }
132
134 IOU
135 operator[](std::string const& s) const;
136
137private:
138 static std::
141
142 // Return the account from the cache & add it to the cache if needed
143 static Account
145
150 std::string human_; // base58 public key string
151};
152
153inline bool
154operator==(Account const& lhs, Account const& rhs) noexcept
155{
156 return lhs.id() == rhs.id();
157}
158
159template <class Hasher>
160void
161hash_append(Hasher& h, Account const& v) noexcept
162{
163 hash_append(h, v.id());
164}
165
166inline auto
167operator<=>(Account const& lhs, Account const& rhs) noexcept
168{
169 return lhs.id() <=> rhs.id();
170}
171
172} // namespace jtx
173} // namespace test
174} // namespace ripple
175
176#endif
A public key.
Definition PublicKey.h:62
A secret key.
Definition SecretKey.h:38
Immutable cryptographic account descriptor.
Definition Account.h:39
PublicKey const & pk() const
Return the public key.
Definition Account.h:94
Account(char const *name, KeyType type=KeyType::secp256k1)
Definition Account.h:62
AccountID id() const
Returns the Account ID.
Definition Account.h:111
Account(Account &&)=default
static Account const master
The master account.
Definition Account.h:48
Account(Account const &)=default
std::string const & name() const
Return the name.
Definition Account.h:87
Account & operator=(Account &&)=default
IOU operator[](std::string const &s) const
Returns an IOU for the specified gateway currency.
Definition Account.cpp:98
static std::unordered_map< std::pair< std::string, KeyType >, Account, beast::uhash<> > cache_
Definition Account.h:140
SecretKey const & sk() const
Return the secret key.
Definition Account.h:101
Account & operator=(Account const &)=default
static Account fromCache(AcctStringType stringType, std::string name, KeyType type)
Definition Account.cpp:50
std::string const & human() const
Returns the human readable public key.
Definition Account.h:118
Converts to IOU Issue or STAmount.
T is_same_v
void hash_append(Hasher &h, Account const &v) noexcept
Definition Account.h:161
auto operator<=>(Account const &lhs, Account const &rhs) noexcept
Definition Account.h:167
bool operator==(Account const &lhs, Account const &rhs) noexcept
Definition Account.h:154
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:25
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition AccountID.h:48
KeyType
Definition KeyType.h:28
STL namespace.