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 std::string name,
21 : name_(std::move(name))
22 , pk_(keys.first)
23 , sk_(keys.second)
24 , id_(calcAccountID(pk_))
25 , human_(toBase58(id_))
26{
27}
28
31{
32 auto p = std::make_pair(name, type); // non-const so it can be moved from
33 auto const iter = cache_.find(p);
34 if (iter != cache_.end())
35 return iter->second;
36
37 auto const keys = [stringType, &name, type]() {
38 // Special handling for base58Seeds.
39 if (stringType == base58Seed)
40 {
41 std::optional<Seed> const seed = parseBase58<Seed>(name);
42 if (!seed.has_value())
43 Throw<std::runtime_error>("Account:: invalid base58 seed");
44
45 return generateKeyPair(type, *seed);
46 }
47 return generateKeyPair(type, generateSeed(name));
48 }();
49 auto r = cache_.emplace(
51 std::forward_as_tuple(std::move(p)),
52 std::forward_as_tuple(std::move(name), keys, privateCtorTag{}));
53 return r.first->second;
54}
55
57 : Account(fromCache(Account::other, std::move(name), type))
58{
59}
60
62 : Account(fromCache(Account::base58Seed, std::move(base58SeedStr), KeyType::secp256k1))
63{
64}
65
68{
69 // override the randomly generated values
70 id_ = id;
72}
73
74IOU
76{
77 auto const currency = to_currency(s);
78 assert(currency != noCurrency());
79 return IOU(*this, currency);
80}
81
82} // namespace jtx
83} // namespace test
84} // namespace xrpl
Immutable cryptographic account descriptor.
Definition Account.h:19
static Account fromCache(AcctStringType stringType, std::string name, KeyType type)
Definition Account.cpp:30
static std::unordered_map< std::pair< std::string, KeyType >, Account, beast::uhash<> > cache_
Definition Account.h:114
std::string const & name() const
Return the name.
Definition Account.h:63
static Account const master
The master account.
Definition Account.h:28
IOU operator[](std::string const &s) const
Returns an IOU for the specified gateway currency.
Definition Account.cpp:75
AccountID id() const
Returns the Account ID.
Definition Account.h:87
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:5
KeyType
Definition KeyType.h:8
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:64
T has_value(T... args)
T piecewise_construct