mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-08-08 14:32:24 -04:00
Move loading the state into the function
In the production code it is a weird indirection that we load the state and then pass in the state and the database. In the tests we have one additional load by doing it inside the command, but loading from the db is not expensive.
This commit is contained in:
parent
095d67f946
commit
0c616c7437
6 changed files with 24 additions and 62 deletions
|
@ -242,9 +242,7 @@ async fn main() -> Result<()> {
|
|||
)
|
||||
.await?;
|
||||
|
||||
let resume_state = db.get_state(swap_id)?.try_into_bob()?.into();
|
||||
let cancel =
|
||||
bob::cancel(swap_id, resume_state, Arc::new(bitcoin_wallet), db, force).await?;
|
||||
let cancel = bob::cancel(swap_id, Arc::new(bitcoin_wallet), db, force).await?;
|
||||
|
||||
match cancel {
|
||||
Ok((txid, _)) => {
|
||||
|
@ -279,9 +277,7 @@ async fn main() -> Result<()> {
|
|||
)
|
||||
.await?;
|
||||
|
||||
let resume_state = db.get_state(swap_id)?.try_into_bob()?.into();
|
||||
|
||||
bob::refund(swap_id, resume_state, Arc::new(bitcoin_wallet), db, force).await??;
|
||||
bob::refund(swap_id, Arc::new(bitcoin_wallet), db, force).await??;
|
||||
}
|
||||
};
|
||||
Ok(())
|
||||
|
|
|
@ -13,11 +13,12 @@ pub enum Error {
|
|||
|
||||
pub async fn cancel(
|
||||
swap_id: Uuid,
|
||||
state: BobState,
|
||||
bitcoin_wallet: Arc<Wallet>,
|
||||
db: Database,
|
||||
force: bool,
|
||||
) -> Result<Result<(Txid, BobState), Error>> {
|
||||
let state = db.get_state(swap_id)?.try_into_bob()?.into();
|
||||
|
||||
let state6 = match state {
|
||||
BobState::BtcLocked(state3) => state3.cancel(),
|
||||
BobState::XmrLockProofReceived { state, .. } => state.cancel(),
|
||||
|
|
|
@ -11,11 +11,12 @@ pub struct SwapNotCancelledYet(Uuid);
|
|||
|
||||
pub async fn refund(
|
||||
swap_id: Uuid,
|
||||
state: BobState,
|
||||
bitcoin_wallet: Arc<Wallet>,
|
||||
db: Database,
|
||||
force: bool,
|
||||
) -> Result<Result<BobState, SwapNotCancelledYet>> {
|
||||
let state = db.get_state(swap_id)?.try_into_bob()?.into();
|
||||
|
||||
let state6 = if force {
|
||||
match state {
|
||||
BobState::BtcLocked(state3) => state3.cancel(),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue