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#include <string>
28#include <unordered_map>
29
30namespace ripple {
31namespace test {
32namespace jtx {
33
34class IOU;
35
38{
39private:
40 // Tag for access to private contr
42 {
43 };
44
45public:
47 static Account const master;
48
49 Account() = delete;
50 Account(Account&&) = default;
51 Account(Account const&) = default;
52 Account&
53 operator=(Account const&) = default;
54 Account&
55 operator=(Account&&) = default;
56
60
62 : Account(std::string(name), type)
63 {
64 }
65
66 // This constructor needs to be public so `std::pair` can use it when
67 // emplacing into the cache. However, it is logically `private`. This is
68 // enforced with the `privateTag` parameter.
69 Account(
73
78 Account(AcctStringType stringType, std::string base58SeedStr);
79
81 std::string const&
82 name() const
83 {
84 return name_;
85 }
86
88 PublicKey const&
89 pk() const
90 {
91 return pk_;
92 }
93
95 SecretKey const&
96 sk() const
97 {
98 return sk_;
99 }
100
106 id() const
107 {
108 return id_;
109 }
110
112 std::string const&
113 human() const
114 {
115 return human_;
116 }
117
123 operator AccountID() const
124 {
125 return id_;
126 }
127
129 IOU
130 operator[](std::string const& s) const;
131
132private:
133 static std::
134 unordered_map<std::pair<std::string, KeyType>, Account, beast::uhash<>>
136
137 // Return the account from the cache & add it to the cache if needed
138 static Account
140
145 std::string human_; // base58 public key string
146};
147
148inline bool
149operator==(Account const& lhs, Account const& rhs) noexcept
150{
151 return lhs.id() == rhs.id();
152}
153
154template <class Hasher>
155void
156hash_append(Hasher& h, Account const& v) noexcept
157{
158 hash_append(h, v.id());
159}
160
161inline auto
162operator<=>(Account const& lhs, Account const& rhs) noexcept
163{
164 return lhs.id() <=> rhs.id();
165}
166
167} // namespace jtx
168} // namespace test
169} // namespace ripple
170
171#endif
A public key.
Definition: PublicKey.h:62
A secret key.
Definition: SecretKey.h:37
Immutable cryptographic account descriptor.
Definition: Account.h:38
PublicKey const & pk() const
Return the public key.
Definition: Account.h:89
Account(char const *name, KeyType type=KeyType::secp256k1)
Definition: Account.h:61
AccountID id() const
Returns the Account ID.
Definition: Account.h:106
Account(Account &&)=default
static Account const master
The master account.
Definition: Account.h:47
Account(Account const &)=default
std::string const & name() const
Return the name.
Definition: Account.h:82
Account & operator=(Account &&)=default
IOU operator[](std::string const &s) const
Returns an IOU for the specified gateway currency.
Definition: Account.cpp:89
static std::unordered_map< std::pair< std::string, KeyType >, Account, beast::uhash<> > cache_
Definition: Account.h:135
SecretKey const & sk() const
Return the secret key.
Definition: Account.h:96
Account & operator=(Account const &)=default
static Account fromCache(AcctStringType stringType, std::string name, KeyType type)
Definition: Account.cpp:49
std::string const & human() const
Returns the human readable public key.
Definition: Account.h:113
Converts to IOU Issue or STAmount.
void hash_append(Hasher &h, Account const &v) noexcept
Definition: Account.h:156
auto operator<=>(Account const &lhs, Account const &rhs) noexcept
Definition: Account.h:162
bool operator==(Account const &lhs, Account const &rhs) noexcept
Definition: Account.h:149
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition: algorithm.h:26
base_uint< 160, detail::AccountIDTag > AccountID
A 160-bit unsigned that uniquely identifies an account.
Definition: AccountID.h:49
KeyType
Definition: KeyType.h:28
STL namespace.