Skip to content

Commit

Permalink
Merge pull request #13 from EOSLaoMao/hotfix/creditor-balance
Browse files Browse the repository at this point in the history
Hotfix/creditor balance
  • Loading branch information
datudou authored Oct 20, 2018
2 parents 937a3e5 + d854856 commit b83f592
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,17 @@ namespace utils
{
auto symbol = symbol_type(system_token_symbol);
eosio::token t(N(eosio.token));
return t.get_balance(owner, symbol.name());
auto balance = t.get_balance(owner, symbol.name());
// update creditor if balance is outdated
creditor_table c(code_account, SCOPE_CREDITOR>>1);
auto creditor_itr = c.find(owner);
if(creditor_itr->balance != balance) {
c.modify(creditor_itr, ram_payer, [&](auto &i) {
i.balance = balance;
i.updated_at = now();
});
}
return balance;
}

//rotate active creditor
Expand All @@ -59,7 +69,7 @@ namespace utils
auto idx = c.get_index<N(updated_at)>();
auto itr = idx.begin();
asset free_balance = get_balance(free_creditor);
asset paid_balance = get_balance(free_creditor);
asset paid_balance = get_balance(paid_creditor);
auto free_rotated = free_balance.amount > MIN_CREDITOR_BALANCE ?TRUE:FALSE;
auto paid_rotated = paid_balance.amount > MIN_CREDITOR_BALANCE ?TRUE:FALSE;

Expand Down

0 comments on commit b83f592

Please sign in to comment.