accounting row fix
This commit is contained in:
@@ -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}')
|
||||
return value
|
||||
|
||||
async def adjust_balance(account: DbAccount, token=NATIVE_TOKEN, subcategory=AccountingSubcategory.InitialBalance, note=None):
|
||||
|
||||
Reference in New Issue
Block a user