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:
|
if amount == 0:
|
||||||
return dec(0)
|
return dec(0)
|
||||||
|
# Adjust database account if it exists
|
||||||
|
if not is_tracked_address(account):
|
||||||
|
return dec(0)
|
||||||
if adjust_decimals:
|
if adjust_decimals:
|
||||||
amount = await adj_dec(token, amount)
|
amount = await adj_dec(token, amount)
|
||||||
# noinspection PyTypeChecker
|
# 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,
|
token=token, amount=amount, value=value, note=note,
|
||||||
chain_id=chain_id, tx_id=tx_id,
|
chain_id=chain_id, tx_id=tx_id,
|
||||||
))
|
))
|
||||||
# Adjust database account if it exists
|
account_db = db.session.get(DbAccount, (current_chain.get(), account))
|
||||||
if is_tracked_address(account):
|
new_amount = account_db.balances.get(token, dec(0)) + amount
|
||||||
account_db = db.session.get(DbAccount, (current_chain.get(), account))
|
if new_amount < 0:
|
||||||
new_amount = account_db.balances.get(token, dec(0)) + amount
|
log.error(f'negative balance for account {account} when applying accounting row {time} {category} {subcategory} {token} {amount} ${value}')
|
||||||
if new_amount < 0:
|
account_db.balances[token] = new_amount
|
||||||
log.error(f'negative balance for account {account} when applying accounting row {time} {category} {subcategory} {token} {amount} ${value}')
|
db.session.add(account_db) # deep changes would not be detected by the ORM
|
||||||
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
|
return value
|
||||||
|
|
||||||
async def adjust_balance(account: DbAccount, token=NATIVE_TOKEN, subcategory=AccountingSubcategory.InitialBalance, note=None):
|
async def adjust_balance(account: DbAccount, token=NATIVE_TOKEN, subcategory=AccountingSubcategory.InitialBalance, note=None):
|
||||||
|
|||||||
Reference in New Issue
Block a user