diff --git a/src/utils.cpp b/src/utils.cpp index 3fbb89d..45c7292 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -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 @@ -59,7 +69,7 @@ namespace utils auto idx = c.get_index(); 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;