Skip to content
This repository has been archived by the owner on Feb 21, 2019. It is now read-only.

Commit

Permalink
merge insufficent funds patch
Browse files Browse the repository at this point in the history
  • Loading branch information
bitsha256 committed Jul 25, 2014
2 parents 6821986 + 95d1943 commit 00a93cf
Showing 1 changed file with 25 additions and 31 deletions.
56 changes: 25 additions & 31 deletions libraries/wallet/wallet.cpp
Expand Up @@ -256,7 +256,7 @@ namespace bts { namespace wallet {
bool scan_ask( wallet_transaction_record& trx_rec, const ask_operation& op );
bool scan_short( wallet_transaction_record& trx_rec, const short_operation& op );

bool sync_balance_with_blockchain( const balance_id_type& balance_id );
void sync_balance_with_blockchain( const balance_id_type& balance_id );

vector<wallet_transaction_record> get_pending_transactions()const;

Expand Down Expand Up @@ -630,8 +630,8 @@ namespace bts { namespace wallet {
trx_rec.ledger_entries.push_back( entry );
}
}
sync_balance_with_blockchain( op.balance_id );

sync_balance_with_blockchain( op.balance_id );
return true;
}
return false;
Expand Down Expand Up @@ -968,32 +968,17 @@ namespace bts { namespace wallet {
break;
}
}
if( cache_deposit )
{
if( !sync_balance_with_blockchain( op.balance_id() ) )
{
elog( "unable to cache balance ${b}", ("b",op) );
}
}
return cache_deposit;

if( cache_deposit ) sync_balance_with_blockchain( op.balance_id() );
return cache_deposit;
} FC_RETHROW_EXCEPTIONS( warn, "", ("op",op) ) } // wallet_impl::scan_deposit

bool wallet_impl::sync_balance_with_blockchain( const balance_id_type& balance_id )
void wallet_impl::sync_balance_with_blockchain( const balance_id_type& balance_id )
{
auto bal_rec = _blockchain->get_balance_record( balance_id );
if( !bal_rec.valid() )
{
// wlog( "blockchain doesn't know about balance id: ${balance_id}",
// ("balance_id",balance_id) );
_wallet_db.remove_balance( balance_id );
return false;
}
else
{
_wallet_db.cache_balance( *bal_rec );
return true;
}
const auto pending_state = _blockchain->get_pending_state();
const auto balance_record = pending_state->get_balance_record( balance_id );
if( !balance_record.valid() ) _wallet_db.remove_balance( balance_id );
else _wallet_db.cache_balance( *balance_record );
}

void wallet_impl::reschedule_relocker()
Expand Down Expand Up @@ -1161,12 +1146,13 @@ namespace bts { namespace wallet {
close();
my->_wallet_db.open( wallet_file_path );
my->_current_wallet_path = wallet_file_path;

const auto tmp_balances = my->_wallet_db.get_balances();
for( const auto& item : tmp_balances )
my->sync_balance_with_blockchain( item.first );

my->_blockchain->set_priority_fee( get_priority_fee().amount );

for( const auto& balance_item : my->_wallet_db.get_balances() )
{
const auto balance_id = balance_item.first;
my->sync_balance_with_blockchain( balance_id );
}
}
catch( ... )
{
Expand Down Expand Up @@ -1793,7 +1779,8 @@ namespace bts { namespace wallet {
void wallet::sign_and_cache_transaction(
signed_transaction& transaction,
const std::unordered_set<address>& required_signatures,
wallet_transaction_record& record )
wallet_transaction_record& record
)
{ try {
sign_transaction( transaction, required_signatures );
my->_blockchain->store_pending_transaction( transaction, true );
Expand All @@ -1803,8 +1790,15 @@ namespace bts { namespace wallet {
record.is_virtual = false;
record.is_confirmed = false;
record.trx = transaction;
record.created_time = record.received_time = now;
record.created_time = now;
record.received_time = now;
my->_wallet_db.store_transaction( record );

for( const auto& balance_item : my->_wallet_db.get_balances() )
{
const auto balance_id = balance_item.first;
my->sync_balance_with_blockchain( balance_id );
}
} FC_RETHROW_EXCEPTIONS( warn, "" ) }

slate_id_type wallet::select_slate( signed_transaction& transaction, const asset_id_type& deposit_asset_id, vote_selection_method selection_method )
Expand Down

0 comments on commit 00a93cf

Please sign in to comment.