36 static std::mt19937 g_randomNumberGenerator(
utcTime());
37 static Mutex x_rngMutex;
39 vector<Address> AccountHolder::allAccounts()
const 41 vector<Address> accounts;
42 accounts += realAccounts();
43 for (
auto const& pair: m_proxyAccounts)
44 if (!isRealAccount(pair.first))
45 accounts.push_back(pair.first);
49 Address const& AccountHolder::defaultTransactAccount()
const 51 auto accounts = realAccounts();
54 Address const* bestMatch = &*accounts.begin();
55 for (
auto const& account: accounts)
56 if (m_client()->balanceAt(account) > m_client()->balanceAt(*bestMatch))
61 int AccountHolder::addProxyAccount(
const Address& _account)
64 int id = std::uniform_int_distribution<int>(1)(g_randomNumberGenerator);
66 if (isProxyAccount(_account) ||
id == 0 || m_transactionQueues.count(
id))
68 m_proxyAccounts.insert(make_pair(_account,
id));
69 m_transactionQueues[id].first = _account;
73 bool AccountHolder::removeProxyAccount(
unsigned _id)
75 if (!m_transactionQueues.count(_id))
77 m_proxyAccounts.erase(m_transactionQueues[_id].first);
78 m_transactionQueues.erase(_id);
84 if (!m_proxyAccounts.count(_transaction.
from))
86 int id = m_proxyAccounts[_transaction.
from];
87 m_transactionQueues[id].second.push_back(_transaction);
90 vector<TransactionSkeleton>
const& AccountHolder::queuedTransactions(
int _id)
const 92 if (!m_transactionQueues.count(_id))
94 return m_transactionQueues.at(_id).second;
97 void AccountHolder::clearQueue(
int _id)
99 if (m_transactionQueues.count(_id))
100 m_transactionQueues.at(_id).second.clear();
105 return m_keyManager.accountsHash();
112 if (m_unlockedAccounts.count(_t.
from))
115 chrono::seconds
duration(m_unlockedAccounts[_t.
from].second);
117 if (start < end && chrono::steady_clock::now() < end)
120 ret.
r = TransactionRepercussion::Locked;
121 if (locked && m_getAuthorisation)
123 if (m_getAuthorisation(_t, isProxyAccount(_t.
from)))
126 ret.
r = TransactionRepercussion::Refused;
130 if (isRealAccount(_t.
from))
132 if (
Secret s = m_keyManager.secret(_t.
from, [&](){ return m_getPassword(_t.from); }))
134 ret.
r = TransactionRepercussion::Success;
135 tie(ret.
hash, ret.
created) = m_client()->submitTransaction(_t, s);
138 ret.
r = TransactionRepercussion::Locked;
140 else if (isProxyAccount(_t.
from))
142 ret.
r = TransactionRepercussion::ProxySuccess;
143 queueTransaction(_t);
146 ret.
r = TransactionRepercussion::UnknownAccount;
150 bool SimpleAccountHolder::unlockAccount(
Address const& _account,
string const& _password,
unsigned _duration)
152 if (!m_keyManager.hasAccount(_account))
157 m_unlockedAccounts[_account].second = 0;
159 m_keyManager.notePassword(_password);
163 if (!m_keyManager.secret(_account, [&] { return _password; },
false))
170 m_unlockedAccounts[_account] = make_pair(chrono::steady_clock::now(), _duration);
178 if (isRealAccount(_t.
from))
180 if (m_accounts.count(_t.
from))
182 ret.
r = TransactionRepercussion::Success;
183 tie(ret.
hash, ret.
created) = m_client()->submitTransaction(_t, m_accounts[_t.
from]);
186 ret.
r = TransactionRepercussion::Locked;
188 else if (isProxyAccount(_t.
from))
190 ret.
r = TransactionRepercussion::ProxySuccess;
191 queueTransaction(_t);
194 ret.
r = TransactionRepercussion::UnknownAccount;
Adapted from code found on http://stackoverflow.com/questions/180947/base64-decode-snippet-in-c Origi...
uint64_t utcTime()
Get the current time in seconds since the epoch in UTC.
std::hash for asio::adress
vector< TransactionSkeleton > g_emptyQueue
std::lock_guard< std::mutex > Guard
Address ZeroAddress
The zero address.
vector_ref< byte const > bytesConstRef
Fixed-size raw-byte array container type, with an API optimised for storing hashes.
boost::multiprecision::number< boost::multiprecision::cpp_int_backend< 256, 256, boost::multiprecision::unsigned_magnitude, boost::multiprecision::unchecked, void >> u256
TransactionRepercussion r
clock::time_point time_point
bool sha3(bytesConstRef _input, bytesRef o_output)
Calculate SHA3-256 hash of the given input and load it into the given output.
std::unordered_set< h160 > AddressHash
A hash set of Ethereum addresses.