The best strategy to achieve this would be to keep a local collection unspents for utxos (the crawler component should keep this in sync watching the chain continuously) and to create a sort of spendings collection that resembles the concept in databases of the "write-ahead log".
When a new swap it's taken and accepted by the daemon, both the unspents and the spendings collection need to be atomically updated, respectively "logically deleting" the unspent "to be consumed" by the swap in the former and inserting a "sort of" new utxo in the latter. (I say sort of because we wouldn't have yet a txid field like in the unspesnts one, but we are interested only in the value and asset field)
The balances endpoint would need to calculate the real available balance aggregating the two collection, NOT only looking in the unspents colelction, but both.
The best strategy to achieve this would be to keep a local collection
unspents
for utxos (the crawler component should keep this in sync watching the chain continuously) and to create a sort ofspendings
collection that resembles the concept in databases of the "write-ahead log".When a new swap it's taken and accepted by the daemon, both the
unspents
and thespendings
collection need to be atomically updated, respectively "logically deleting" the unspent "to be consumed" by the swap in the former and inserting a "sort of" new utxo in the latter. (I say sort of because we wouldn't have yet a txid field like in the unspesnts one, but we are interested only in the value and asset field)The balances endpoint would need to calculate the real available balance aggregating the two collection, NOT only looking in the
unspents
colelction, but both.