Making all fields private revealed some weirdness in how we compute
the position of the CFD. For an order, it made sense that we store
the `origin` of it. For a CFD however, it makes more sense to store
the position and role of the actor explicitly and derive other
information from there.
Electrum sometimes returns error code -27
bad-txns-inputs-missingorspent. This can occur because the transaction
has been published. Electrum should return error code -25 transaction
already on chain. In the case of error code -27 we now check if the
transaction is on chain and return ok if it is.
Loading the CFD by oracle event id, based on the "initial oracle event id" that we store in the CFD is wrong.
We should actually no store this even id at all, as it only becomes relevant once the setup is completed and we have a DLC.
If we load based on the event id that was stored in the CFD we might still load based on an outdated id once we roll over!
Thus, the event id of the cfd was removed. We always use the one stored in the DLC.
Since it is very hard to load a CFD based on the event id in the DLC (because that only exists in some states) this was removed.
Instead, upon attestation, we load all CFDs and then decide if we care about the attestation.
This should be optimized to loading all **open** CFDs at some point.
The rollover actor is spawned the the maker receives a rollover proposal message from the taker. After the rollover is complete, it sends itself
a completion message triggering a "cleanup" handler. Cleanup involves sending messages to maker_cfd actor and the maker_inc_connections to
trigger removal of stored references to the rollover actor.
Add a macro to simplify assertions on Cfd state in both maker and taker, which
significantly reduces boilerplate in tests.
Macro was used for brevity (we can hide `.await.unwrap()`), when a function was
used it would take 4 lines after formatting.
Putting each import statement on a dedicated line makes it a lot less
likely to create merge conflicts when items are removed / added because
Git resolves conflicts on a line-by-line basis.
We need this on the maker side to be able to get stats on what takers do.
For the taker it will also become relevant in the future so it is not wrong to add it.
If we don't receive a message from BitMex within 5 seconds, we ping
them to let them know that we are still using this connection. This
avoids the constant dis/reconnects that we have been seeing.
To make boot-up of the system easier, we want allow for a state where
we do not yet have a quote available.
Allow the quote in the projection to be optional and fallback to `None`
for profit calculation.
In case we fail to calculate the profit or this data is otherwise not
available, we still want to display as much as possible and only
blank out the data we cannot compute.
BDK's database only acts as a cache and can always be fully restored
by deleting it. With an Electrum backend, syncing is very quick meaning
the local cache basically does not serve any purpose. We've been having
troubles with BDK's database being broken due to internal inconsistency
problems. Switching to an in-memory database should fix these because
a restart of the application essentially wipes the database.
Resolves#465.
Implying `Sync` as part of withdraw allows us to remove the `Sync`
from the startup of the application which avoids an error case in
case we cannot find a particular transaction.