From e4d61e6bbe598ef32f2375216ca6d255a9019622 Mon Sep 17 00:00:00 2001 From: Sergey Kroshnin Date: Sat, 26 Jan 2019 18:46:07 +0300 Subject: [PATCH] Add wallet locked check to RPC wallet_representative_set (#1627) * Add wallet locked check to PRC wallet_representative_set Required after https://github.com/nanocurrency/nano-node/pull/1531 if existing accounts are updated * Move update_existing_accounts get --- nano/node/rpc.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/nano/node/rpc.cpp b/nano/node/rpc.cpp index 1c158433..625a6260 100644 --- a/nano/node/rpc.cpp +++ b/nano/node/rpc.cpp @@ -3543,17 +3543,26 @@ void nano::rpc_handler::wallet_representative_set () nano::account representative; if (!representative.decode_account (representative_text)) { + bool update_existing_accounts (request.get ("update_existing_accounts", false)); { auto transaction (node.wallets.tx_begin_write ()); - wallet->store.representative_set (transaction, representative); + if (wallet->store.valid_password (transaction) || !update_existing_accounts) + { + wallet->store.representative_set (transaction, representative); + response_l.put ("set", "1"); + } + else + { + ec = nano::error_common::wallet_locked; + } } // Change representative for all wallet accounts - if (request.get ("update_existing_accounts", false)) + if (!ec && update_existing_accounts) { std::vector accounts; { auto transaction (node.wallets.tx_begin_read ()); - auto block_transaction (node.store.tx_begin_write ()); + auto block_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); @@ -3574,7 +3583,6 @@ void nano::rpc_handler::wallet_representative_set () wallet->change_async (account, representative, [](std::shared_ptr) {}, 0, false); } } - response_l.put ("set", "1"); } else {