mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-25 07:29:32 -05:00
Do not introduced State6
This commit is contained in:
parent
8615aaed6e
commit
9a823dca4c
@ -33,9 +33,9 @@ pub enum Bob {
|
|||||||
#[derive(Clone, strum::Display, Debug, Deserialize, Serialize, PartialEq)]
|
#[derive(Clone, strum::Display, Debug, Deserialize, Serialize, PartialEq)]
|
||||||
pub enum BobEndState {
|
pub enum BobEndState {
|
||||||
SafelyAborted,
|
SafelyAborted,
|
||||||
XmrRedeemed(Box<bob::State6>),
|
XmrRedeemed { tx_lock_id: bitcoin::Txid },
|
||||||
BtcRefunded(Box<bob::State4>),
|
BtcRefunded(Box<bob::State4>),
|
||||||
BtcPunished(Box<bob::State6>),
|
BtcPunished { tx_lock_id: bitcoin::Txid },
|
||||||
}
|
}
|
||||||
|
|
||||||
impl From<BobState> for Bob {
|
impl From<BobState> for Bob {
|
||||||
@ -50,8 +50,12 @@ impl From<BobState> for Bob {
|
|||||||
BobState::CancelTimelockExpired(state4) => Bob::CancelTimelockExpired(state4),
|
BobState::CancelTimelockExpired(state4) => Bob::CancelTimelockExpired(state4),
|
||||||
BobState::BtcCancelled(state4) => Bob::BtcCancelled(state4),
|
BobState::BtcCancelled(state4) => Bob::BtcCancelled(state4),
|
||||||
BobState::BtcRefunded(state4) => Bob::Done(BobEndState::BtcRefunded(Box::new(state4))),
|
BobState::BtcRefunded(state4) => Bob::Done(BobEndState::BtcRefunded(Box::new(state4))),
|
||||||
BobState::XmrRedeemed(state6) => Bob::Done(BobEndState::XmrRedeemed(Box::new(state6))),
|
BobState::XmrRedeemed { tx_lock_id } => {
|
||||||
BobState::BtcPunished(state6) => Bob::Done(BobEndState::BtcPunished(Box::new(state6))),
|
Bob::Done(BobEndState::XmrRedeemed { tx_lock_id })
|
||||||
|
}
|
||||||
|
BobState::BtcPunished { tx_lock_id } => {
|
||||||
|
Bob::Done(BobEndState::BtcPunished { tx_lock_id })
|
||||||
|
}
|
||||||
BobState::SafelyAborted => Bob::Done(BobEndState::SafelyAborted),
|
BobState::SafelyAborted => Bob::Done(BobEndState::SafelyAborted),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -70,9 +74,9 @@ impl From<Bob> for BobState {
|
|||||||
Bob::BtcCancelled(state4) => BobState::BtcCancelled(state4),
|
Bob::BtcCancelled(state4) => BobState::BtcCancelled(state4),
|
||||||
Bob::Done(end_state) => match end_state {
|
Bob::Done(end_state) => match end_state {
|
||||||
BobEndState::SafelyAborted => BobState::SafelyAborted,
|
BobEndState::SafelyAborted => BobState::SafelyAborted,
|
||||||
BobEndState::XmrRedeemed(state6) => BobState::XmrRedeemed(*state6),
|
BobEndState::XmrRedeemed { tx_lock_id } => BobState::XmrRedeemed { tx_lock_id },
|
||||||
BobEndState::BtcRefunded(state4) => BobState::BtcRefunded(*state4),
|
BobEndState::BtcRefunded(state4) => BobState::BtcRefunded(*state4),
|
||||||
BobEndState::BtcPunished(state6) => BobState::BtcPunished(*state6),
|
BobEndState::BtcPunished { tx_lock_id } => BobState::BtcPunished { tx_lock_id },
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -35,8 +35,12 @@ pub enum BobState {
|
|||||||
CancelTimelockExpired(State4),
|
CancelTimelockExpired(State4),
|
||||||
BtcCancelled(State4),
|
BtcCancelled(State4),
|
||||||
BtcRefunded(State4),
|
BtcRefunded(State4),
|
||||||
XmrRedeemed(State6),
|
XmrRedeemed {
|
||||||
BtcPunished(State6),
|
tx_lock_id: bitcoin::Txid,
|
||||||
|
},
|
||||||
|
BtcPunished {
|
||||||
|
tx_lock_id: bitcoin::Txid,
|
||||||
|
},
|
||||||
SafelyAborted,
|
SafelyAborted,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,8 +56,8 @@ impl fmt::Display for BobState {
|
|||||||
BobState::CancelTimelockExpired(..) => write!(f, "cancel timelock is expired"),
|
BobState::CancelTimelockExpired(..) => write!(f, "cancel timelock is expired"),
|
||||||
BobState::BtcCancelled(..) => write!(f, "btc is cancelled"),
|
BobState::BtcCancelled(..) => write!(f, "btc is cancelled"),
|
||||||
BobState::BtcRefunded(..) => write!(f, "btc is refunded"),
|
BobState::BtcRefunded(..) => write!(f, "btc is refunded"),
|
||||||
BobState::XmrRedeemed(..) => write!(f, "xmr is redeemed"),
|
BobState::XmrRedeemed { .. } => write!(f, "xmr is redeemed"),
|
||||||
BobState::BtcPunished(..) => write!(f, "btc is punished"),
|
BobState::BtcPunished { .. } => write!(f, "btc is punished"),
|
||||||
BobState::SafelyAborted => write!(f, "safely aborted"),
|
BobState::SafelyAborted => write!(f, "safely aborted"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -592,12 +596,6 @@ impl State4 {
|
|||||||
pub fn tx_lock_id(&self) -> bitcoin::Txid {
|
pub fn tx_lock_id(&self) -> bitcoin::Txid {
|
||||||
self.tx_lock.txid()
|
self.tx_lock.txid()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn state6(&self) -> State6 {
|
|
||||||
State6 {
|
|
||||||
tx_lock_id: self.tx_lock.txid(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
|
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
|
||||||
@ -650,21 +648,4 @@ impl State5 {
|
|||||||
pub fn tx_lock_id(&self) -> bitcoin::Txid {
|
pub fn tx_lock_id(&self) -> bitcoin::Txid {
|
||||||
self.tx_lock.txid()
|
self.tx_lock.txid()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn state6(&self) -> State6 {
|
|
||||||
State6 {
|
|
||||||
tx_lock_id: self.tx_lock.txid(),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug, Clone, Deserialize, Serialize, PartialEq)]
|
|
||||||
pub struct State6 {
|
|
||||||
pub tx_lock_id: Txid,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl State6 {
|
|
||||||
pub fn tx_lock_id(&self) -> bitcoin::Txid {
|
|
||||||
self.tx_lock_id
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@ -273,7 +273,9 @@ where
|
|||||||
// Bob redeems XMR using revealed s_a
|
// Bob redeems XMR using revealed s_a
|
||||||
state.claim_xmr(monero_wallet.as_ref()).await?;
|
state.claim_xmr(monero_wallet.as_ref()).await?;
|
||||||
|
|
||||||
let state = BobState::XmrRedeemed(state.state6());
|
let state = BobState::XmrRedeemed {
|
||||||
|
tx_lock_id: state.tx_lock_id(),
|
||||||
|
};
|
||||||
let db_state = state.clone().into();
|
let db_state = state.clone().into();
|
||||||
db.insert_latest_state(swap_id, Swap::Bob(db_state)).await?;
|
db.insert_latest_state(swap_id, Swap::Bob(db_state)).await?;
|
||||||
run_until(
|
run_until(
|
||||||
@ -323,7 +325,9 @@ where
|
|||||||
state.refund_btc(bitcoin_wallet.as_ref()).await?;
|
state.refund_btc(bitcoin_wallet.as_ref()).await?;
|
||||||
BobState::BtcRefunded(state)
|
BobState::BtcRefunded(state)
|
||||||
}
|
}
|
||||||
ExpiredTimelocks::Punish => BobState::BtcPunished(state.state6()),
|
ExpiredTimelocks::Punish => BobState::BtcPunished {
|
||||||
|
tx_lock_id: state.tx_lock_id(),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let db_state = state.clone().into();
|
let db_state = state.clone().into();
|
||||||
@ -341,9 +345,9 @@ where
|
|||||||
.await
|
.await
|
||||||
}
|
}
|
||||||
BobState::BtcRefunded(state4) => Ok(BobState::BtcRefunded(state4)),
|
BobState::BtcRefunded(state4) => Ok(BobState::BtcRefunded(state4)),
|
||||||
BobState::BtcPunished(state6) => Ok(BobState::BtcPunished(state6)),
|
BobState::BtcPunished { tx_lock_id } => Ok(BobState::BtcPunished { tx_lock_id }),
|
||||||
BobState::SafelyAborted => Ok(BobState::SafelyAborted),
|
BobState::SafelyAborted => Ok(BobState::SafelyAborted),
|
||||||
BobState::XmrRedeemed(state6) => Ok(BobState::XmrRedeemed(state6)),
|
BobState::XmrRedeemed { tx_lock_id } => Ok(BobState::XmrRedeemed { tx_lock_id }),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -363,8 +363,8 @@ impl BobHarness {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn assert_redeemed(&self, state: BobState) {
|
pub async fn assert_redeemed(&self, state: BobState) {
|
||||||
let lock_tx_id = if let BobState::XmrRedeemed(state6) = state {
|
let lock_tx_id = if let BobState::XmrRedeemed { tx_lock_id } = state {
|
||||||
state6.tx_lock_id()
|
tx_lock_id
|
||||||
} else {
|
} else {
|
||||||
panic!("Bob in unexpected state");
|
panic!("Bob in unexpected state");
|
||||||
};
|
};
|
||||||
@ -423,8 +423,8 @@ impl BobHarness {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub async fn assert_punished(&self, state: BobState) {
|
pub async fn assert_punished(&self, state: BobState) {
|
||||||
let lock_tx_id = if let BobState::BtcPunished(state6) = state {
|
let lock_tx_id = if let BobState::BtcPunished { tx_lock_id } = state {
|
||||||
state6.tx_lock_id()
|
tx_lock_id
|
||||||
} else {
|
} else {
|
||||||
panic!("Bob in unexpected state");
|
panic!("Bob in unexpected state");
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user