Add accounts parameter to wallet_change_seed (#775)
* Add accounts parameter to wallet_change_seed * Fix merge * Update lmdb * merge fix * merge fix * Disable work generation for change_seed & use optional "count" in RPC wallet_change_seed * Typo
This commit is contained in:
parent
bfd89e87b3
commit
ba6196ca86
3 changed files with 26 additions and 23 deletions
|
@ -3187,10 +3187,11 @@ void nano::rpc_handler::wallet_change_seed ()
|
|||
nano::raw_key seed;
|
||||
if (!seed.data.decode_hex (seed_text))
|
||||
{
|
||||
auto count (count_optional_impl ());
|
||||
auto transaction (node.store.tx_begin_write ());
|
||||
if (wallet->store.valid_password (transaction))
|
||||
{
|
||||
wallet->change_seed (transaction, seed);
|
||||
wallet->change_seed (transaction, seed, count);
|
||||
response_l.put ("success", "");
|
||||
}
|
||||
else
|
||||
|
|
|
@ -1207,40 +1207,42 @@ void nano::wallet::init_free_accounts (nano::transaction const & transaction_a)
|
|||
}
|
||||
}
|
||||
|
||||
nano::public_key nano::wallet::change_seed (nano::transaction const & transaction_a, nano::raw_key const & prv_a)
|
||||
nano::public_key nano::wallet::change_seed (nano::transaction const & transaction_a, nano::raw_key const & prv_a, uint32_t count)
|
||||
{
|
||||
store.seed_set (transaction_a, prv_a);
|
||||
auto account = deterministic_insert (transaction_a);
|
||||
uint32_t count (0);
|
||||
for (uint32_t i (1), n (64); i < n; ++i)
|
||||
if (count == 0)
|
||||
{
|
||||
nano::raw_key prv;
|
||||
store.deterministic_key (prv, transaction_a, i);
|
||||
nano::keypair pair (prv.data.to_string ());
|
||||
// Check if account received at least 1 block
|
||||
auto latest (wallets.node.ledger.latest (transaction_a, pair.pub));
|
||||
if (!latest.is_zero ())
|
||||
for (uint32_t i (1), n (64); i < n; ++i)
|
||||
{
|
||||
count = i;
|
||||
// i + 64 - Check additional 64 accounts
|
||||
// i/64 - Check additional accounts for large wallets. I.e. 64000/64 = 1000 accounts to check
|
||||
n = i + 64 + (i / 64);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if there are pending blocks for account
|
||||
for (auto ii (wallets.node.store.pending_begin (transaction_a, nano::pending_key (pair.pub, 0))); nano::pending_key (ii->first).account == pair.pub; ++ii)
|
||||
nano::raw_key prv;
|
||||
store.deterministic_key (prv, transaction_a, i);
|
||||
nano::keypair pair (prv.data.to_string ());
|
||||
// Check if account received at least 1 block
|
||||
auto latest (wallets.node.ledger.latest (transaction_a, pair.pub));
|
||||
if (!latest.is_zero ())
|
||||
{
|
||||
count = i;
|
||||
// i + 64 - Check additional 64 accounts
|
||||
// i/64 - Check additional accounts for large wallets. I.e. 64000/64 = 1000 accounts to check
|
||||
n = i + 64 + (i / 64);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Check if there are pending blocks for account
|
||||
for (auto ii (wallets.node.store.pending_begin (transaction_a, nano::pending_key (pair.pub, 0))); nano::pending_key (ii->first).account == pair.pub; ++ii)
|
||||
{
|
||||
count = i;
|
||||
n = i + 64 + (i / 64);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (uint32_t i (0); i < count; ++i)
|
||||
{
|
||||
// Generate work for first 4 accounts only to prevent weak CPU nodes stuck
|
||||
account = deterministic_insert (transaction_a, i < 4);
|
||||
// Disable work generation to prevent weak CPU nodes stuck
|
||||
account = deterministic_insert (transaction_a, false);
|
||||
}
|
||||
|
||||
return account;
|
||||
|
|
|
@ -151,7 +151,7 @@ public:
|
|||
bool search_pending ();
|
||||
void init_free_accounts (nano::transaction const &);
|
||||
/** Changes the wallet seed and returns the first account */
|
||||
nano::public_key change_seed (nano::transaction const & transaction_a, nano::raw_key const & prv_a);
|
||||
nano::public_key change_seed (nano::transaction const & transaction_a, nano::raw_key const & prv_a, uint32_t = 0);
|
||||
bool live ();
|
||||
std::unordered_set<nano::account> free_accounts;
|
||||
std::function<void(bool, bool)> lock_observer;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue