The choice of using a 256 bit string is temporary. This will be replaced
in favour of a 24 word seed phrase which will be used to create the
seed (BIP39).
Use the same enum across:
- setup taker,
- setup maker,
- rollover taker
Generic enum contains a reason in the Rejection case - if it's not specified, it
defaults to "unknown".
Note: Completed::Succeeded uses a marker type to allow distinguishing the
protocol in the cfd actor message handlers.
In general, we would like to let the sender of an `xtra::Message` to
be able to handle all the possible errors. The `log_error` macro
catered to the complete opposite use case, so we remove it.
In order to make error handling at the sending site more ergonomic, we
introduce a `LogFailure` trait designed for fallible `xtra::Messages`.
With this patch we've tried to change _where_ we handle errors, but
not _what_ we do with them.
With the removal of the order from the DB, we are loading a CFD by
its ID which just happens to be the order id but that is no longer
relevant at this stage.
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.