rippled
Loading...
Searching...
No Matches
Account.cpp
1#include <test/jtx/Account.h>
2#include <test/jtx/amount.h>
3
4#include <xrpl/protocol/UintTypes.h>
5
6namespace xrpl {
7namespace test {
8namespace jtx {
9
11
12Account const Account::master(
13 "master",
15 Account::privateCtorTag{});
16
18 : name_(std::move(name)), pk_(keys.first), sk_(keys.second), id_(calcAccountID(pk_)), human_(toBase58(id_))
19{
20}
21
24{
25 auto p = std::make_pair(name, type); // non-const so it can be moved from
26 auto const iter = cache_.find(p);
27 if (iter != cache_.end())
28 return iter->second;
29
30 auto const keys = [stringType, &name, type]() {
31 // Special handling for base58Seeds.
32 if (stringType == base58Seed)
33 {
34 std::optional<Seed> const seed = parseBase58<Seed>(name);
35 if (!seed.has_value())
36 Throw<std::runtime_error>("Account:: invalid base58 seed");
37
38 return generateKeyPair(type, *seed);
39 }
40 return generateKeyPair(type, generateSeed(name));
41 }();
42 auto r = cache_.emplace(
44 std::forward_as_tuple(std::move(p)),
45 std::forward_as_tuple(std::move(name), keys, privateCtorTag{}));
46 return r.first->second;
47}
48
49Account::Account(std::string name, KeyType type) : Account(fromCache(Account::other, std::move(name), type))
50{
51}
52
54 : Account(fromCache(Account::base58Seed, std::move(base58SeedStr), KeyType::secp256k1))
55{
56}
57
60{
61 // override the randomly generated values
62 id_ = id;
64}
65
66IOU
68{
69 auto const currency = to_currency(s);
70 assert(currency != noCurrency());
71 return IOU(*this, currency);
72}
73
74} // namespace jtx
75} // namespace test
76} // namespace xrpl
Immutable cryptographic account descriptor.
Definition Account.h:20
static Account fromCache(AcctStringType stringType, std::string name, KeyType type)
Definition Account.cpp:23
static std::unordered_map< std::pair< std::string, KeyType >, Account, beast::uhash<> > cache_
Definition Account.h:115
std::string const & name() const
Return the name.
Definition Account.h:64
static Account const master
The master account.
Definition Account.h:29
IOU operator[](std::string const &s) const
Returns an IOU for the specified gateway currency.
Definition Account.cpp:67
AccountID id() const
Returns the Account ID.
Definition Account.h:88
Converts to IOU Issue or STAmount.
T forward_as_tuple(T... args)
T make_pair(T... args)
STL namespace.
Use hash_* containers for keys that do not need a cryptographically secure hashing algorithm.
Definition algorithm.h:6
KeyType
Definition KeyType.h:9
std::pair< PublicKey, SecretKey > randomKeyPair(KeyType type)
Create a key pair using secure random numbers.
std::string toBase58(AccountID const &v)
Convert AccountID to base58 checked string.
Definition AccountID.cpp:92
Seed generateSeed(std::string const &passPhrase)
Generate a seed deterministically.
Definition Seed.cpp:57
std::pair< PublicKey, SecretKey > generateKeyPair(KeyType type, Seed const &seed)
Generate a key pair deterministically.
AccountID calcAccountID(PublicKey const &pk)
Currency const & noCurrency()
A placeholder for empty currencies.
bool to_currency(Currency &, std::string const &)
Tries to convert a string to a Currency, returns true on success.
Definition UintTypes.cpp:62
T has_value(T... args)
T piecewise_construct