diff --git a/libraries/wallet/wallet.cpp b/libraries/wallet/wallet.cpp index 575db736..7a0608b7 100644 --- a/libraries/wallet/wallet.cpp +++ b/libraries/wallet/wallet.cpp @@ -649,15 +649,49 @@ public: ("wallet.chain_id", _wallet.chain_id) ("chain_id", _chain_id) ); - vector< account_id_type > my_account_ids; - my_account_ids.reserve( _wallet.my_accounts.size() ); - for( const account_object& acct : _wallet.my_accounts ) - my_account_ids.push_back( acct.id ); - // TODO: Batch requests using _remote_db->get_accounts() - // to reduce number of round-trips. Remember get_accounts() has - // a limit of 100 results per call! - for( const account_id_type& acct_id : my_account_ids ) - _wallet.update_account( get_account( acct_id ) ); + size_t account_pagination = 100; + vector< account_id_type > account_ids_to_send; + size_t n = _wallet.my_accounts.size(); + account_ids_to_send.reserve( std::min( account_pagination, n ) ); + auto it = _wallet.my_accounts.begin(); + + for( size_t start=0; start start ); + account_ids_to_send.clear(); + std::vector< account_object > old_accounts; + for( size_t i=start; i > accounts = _remote_db->get_accounts(account_ids_to_send); + // server response should be same length as request + FC_ASSERT( accounts.size() == account_ids_to_send.size() ); + size_t i = 0; + for( const optional< account_object >& acct : accounts ) + { + account_object& old_acct = old_accounts[i]; + if( !acct.valid() ) + { + elog( "Could not find account ${id} : \"${name}\" does not exist on the chain!", ("id", old_acct.id)("name", old_acct.name) ); + i++; + continue; + } + // this check makes sure the server didn't send results + // in a different order, or accounts we didn't request + FC_ASSERT( acct->id == old_acct.id ); + if( fc::json::to_string(*acct) != fc::json::to_string(old_acct) ) + { + wlog( "Account ${id} : \"${name}\" updated on chain", ("id", acct->id)("name", acct->name) ); + } + _wallet.update_account( *acct ); + i++; + } + } return true; }