Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"update_existing_accounts" option for RPC wallet_representative_set #1531

Merged
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -567,6 +567,46 @@ TEST (rpc, wallet_representative_set)
ASSERT_EQ (key.pub, system.nodes[0]->wallets.items.begin ()->second->store.representative (transaction));
}

TEST (rpc, wallet_representative_set_force)
{
nano::system system (24000, 1);
nano::rpc rpc (system.io_ctx, *system.nodes[0], nano::rpc_config (true));
system.wallet (0)->insert_adhoc (nano::test_genesis_key.prv);
rpc.start ();
boost::property_tree::ptree request;
std::string wallet;
system.nodes[0]->wallets.items.begin ()->first.encode_hex (wallet);
request.put ("wallet", wallet);
nano::keypair key;
request.put ("action", "wallet_representative_set");
request.put ("representative", key.pub.to_account ());
request.put ("force", true);
test_response response (request, rpc, system.io_ctx);
system.deadline_set (5s);
while (response.status == 0)
{
ASSERT_NO_ERROR (system.poll ());
}
ASSERT_EQ (200, response.status);
{
auto transaction (system.nodes[0]->wallets.tx_begin ());
ASSERT_EQ (key.pub, system.nodes[0]->wallets.items.begin ()->second->store.representative (transaction));
}
nano::account representative (0);
while (representative != key.pub)
{
auto transaction (system.nodes[0]->store.tx_begin_read ());
nano::account_info info;
if (!system.nodes[0]->store.account_get (transaction, nano::test_genesis_key.pub, info))
{
auto block (system.nodes[0]->store.block_get (transaction, info.rep_block));
assert (block != nullptr);
representative = block->representative ();
}
ASSERT_NO_ERROR (system.poll ());
}
}

TEST (rpc, account_list)
{
nano::system system (24000, 1);
@@ -3486,8 +3486,36 @@ void nano::rpc_handler::wallet_representative_set ()
nano::account representative;
if (!representative.decode_account (representative_text))
{
auto transaction (node.store.tx_begin_write ());
wallet->store.representative_set (transaction, representative);
{
auto transaction (node.store.tx_begin_write ());
wallet->store.representative_set (transaction, representative);
}
// Change representative for all wallet accounts
if (request.get<bool> ("force", false))
This conversation was marked as resolved by cryptocode

This comment has been minimized.

Copy link
@cryptocode

cryptocode Jan 2, 2019

Collaborator

Since the current semantics of wallet_representative_set is to set representative for new accounts only, what do you think about calling this parameter update_existing_accounts ?

This comment has been minimized.

Copy link
@SergiySW

SergiySW Jan 2, 2019

Author Collaborator

makes sense

{
std::deque<nano::account> accounts;
This conversation was marked as resolved by SergiySW

This comment has been minimized.

Copy link
@wezrule

wezrule Jan 2, 2019

Collaborator

I'm not sure std::deque is the right data structure to use here, it is generally only used when popping from the front is required, I think std::vector should be used.

{
auto transaction (node.store.tx_begin_read ());
for (auto i (wallet->store.begin (transaction)), n (wallet->store.end ()); i != n; ++i)
{
nano::account account (i->first);
nano::account_info info;
if (!node.store.account_get (transaction, account, info))
{
auto block (node.store.block_get (transaction, info.rep_block));
assert (block != nullptr);
if (block->representative () != representative)
{
accounts.push_back (account);
}
}
}
}
for (auto & account : accounts)
{
wallet->change_async (account, representative, [](std::shared_ptr<nano::block>) {}, false);
}
}
response_l.put ("set", "1");
}
else
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.