diff --git a/src/dexorder/accounting.py b/src/dexorder/accounting.py index d1f1e31..84db4f3 100644 --- a/src/dexorder/accounting.py +++ b/src/dexorder/accounting.py @@ -210,6 +210,9 @@ async def add_accounting_row(account: str, block_hash: Optional[str], tx_id: Opt """ if amount == 0: return dec(0) + # Adjust database account if it exists + if not is_tracked_address(account): + return dec(0) if adjust_decimals: amount = await adj_dec(token, amount) # noinspection PyTypeChecker @@ -222,16 +225,12 @@ async def add_accounting_row(account: str, block_hash: Optional[str], tx_id: Opt token=token, amount=amount, value=value, note=note, chain_id=chain_id, tx_id=tx_id, )) - # Adjust database account if it exists - if is_tracked_address(account): - account_db = db.session.get(DbAccount, (current_chain.get(), account)) - new_amount = account_db.balances.get(token, dec(0)) + amount - if new_amount < 0: - log.error(f'negative balance for account {account} when applying accounting row {time} {category} {subcategory} {token} {amount} ${value}') - account_db.balances[token] = new_amount - db.session.add(account_db) # deep changes would not be detected by the ORM - else: - log.warning(f'No db account found for {account}') + account_db = db.session.get(DbAccount, (current_chain.get(), account)) + new_amount = account_db.balances.get(token, dec(0)) + amount + if new_amount < 0: + log.error(f'negative balance for account {account} when applying accounting row {time} {category} {subcategory} {token} {amount} ${value}') + account_db.balances[token] = new_amount + db.session.add(account_db) # deep changes would not be detected by the ORM return value async def adjust_balance(account: DbAccount, token=NATIVE_TOKEN, subcategory=AccountingSubcategory.InitialBalance, note=None):