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 Account(AcctStringType stringType, std::string base58SeedStr);
80
82 std::string const&
83 name() const
84 {
85 return name_;
86 }
87
89 PublicKey const&
90 pk() const
91 {
92 return pk_;
93 }
94
96 SecretKey const&
97 sk() const
98 {
99 return sk_;
100 }
101
107 id() const
108 {
109 return id_;
110 }
111
113 std::string const&
114 human() const
115 {
116 return human_;
117 }
118
124 operator AccountID() const
125 {
126 return id_;
127 }
128
130 IOU
131 operator[](std::string const& s) const;
132
133private:
134 static std::
135 unordered_map<std::pair<std::string, KeyType>, Account, beast::uhash<>>
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
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 jtx
169} // namespace test
170} // namespace ripple
171
172#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:90
Account(char const *name, KeyType type=KeyType::secp256k1)
Definition: Account.h:62
AccountID id() const
Returns the Account ID.
Definition: Account.h:107
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:83
Account & operator=(Account &&)=default
IOU operator[](std::string const &s) const
Returns an IOU for the specified gateway currency.
Definition: Account.cpp:90
static std::unordered_map< std::pair< std::string, KeyType >, Account, beast::uhash<> > cache_
Definition: Account.h:136
SecretKey const & sk() const
Return the secret key.
Definition: Account.h:97
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:114
Converts to IOU Issue or STAmount.
void hash_append(Hasher &h, Account const &v) noexcept
Definition: Account.h:157
auto operator<=>(Account const &lhs, Account const &rhs) noexcept
Definition: Account.h:163
bool operator==(Account const &lhs, Account const &rhs) noexcept
Definition: Account.h:150
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.