mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-05-02 14:56:10 -04:00
Move Swap state out of storage
This commit is contained in:
parent
ac2cfd7f65
commit
33a111d879
6 changed files with 114 additions and 110 deletions
|
@ -32,7 +32,8 @@ use crate::{
|
|||
transport::SwapTransport,
|
||||
TokioExecutor,
|
||||
},
|
||||
storage::{self, Database},
|
||||
state,
|
||||
storage::Database,
|
||||
SwapAmounts, PUNISH_TIMELOCK, REFUND_TIMELOCK,
|
||||
};
|
||||
use xmr_btc::{
|
||||
|
@ -177,7 +178,7 @@ pub async fn swap(
|
|||
};
|
||||
|
||||
let swap_id = Uuid::new_v4();
|
||||
db.insert_latest_state(swap_id, storage::Alice::Handshaken(state3.clone()).into())
|
||||
db.insert_latest_state(swap_id, state::Alice::Handshaken(state3.clone()).into())
|
||||
.await?;
|
||||
|
||||
info!("Handshake complete, we now have State3 for Alice.");
|
||||
|
@ -205,14 +206,14 @@ pub async fn swap(
|
|||
public_spend_key,
|
||||
public_view_key,
|
||||
}) => {
|
||||
db.insert_latest_state(swap_id, storage::Alice::BtcLocked(state3.clone()).into())
|
||||
db.insert_latest_state(swap_id, state::Alice::BtcLocked(state3.clone()).into())
|
||||
.await?;
|
||||
|
||||
let (transfer_proof, _) = monero_wallet
|
||||
.transfer(public_spend_key, public_view_key, amount)
|
||||
.await?;
|
||||
|
||||
db.insert_latest_state(swap_id, storage::Alice::XmrLocked(state3.clone()).into())
|
||||
db.insert_latest_state(swap_id, state::Alice::XmrLocked(state3.clone()).into())
|
||||
.await?;
|
||||
|
||||
let mut guard = network.as_ref().lock().await;
|
||||
|
@ -223,7 +224,7 @@ pub async fn swap(
|
|||
GeneratorState::Yielded(Action::RedeemBtc(tx)) => {
|
||||
db.insert_latest_state(
|
||||
swap_id,
|
||||
storage::Alice::BtcRedeemable {
|
||||
state::Alice::BtcRedeemable {
|
||||
state: state3.clone(),
|
||||
redeem_tx: tx.clone(),
|
||||
}
|
||||
|
@ -237,11 +238,8 @@ pub async fn swap(
|
|||
let _ = bitcoin_wallet.broadcast_signed_transaction(tx).await?;
|
||||
}
|
||||
GeneratorState::Yielded(Action::PunishBtc(tx)) => {
|
||||
db.insert_latest_state(
|
||||
swap_id,
|
||||
storage::Alice::BtcPunishable(state3.clone()).into(),
|
||||
)
|
||||
.await?;
|
||||
db.insert_latest_state(swap_id, state::Alice::BtcPunishable(state3.clone()).into())
|
||||
.await?;
|
||||
|
||||
let _ = bitcoin_wallet.broadcast_signed_transaction(tx).await?;
|
||||
}
|
||||
|
@ -251,7 +249,7 @@ pub async fn swap(
|
|||
}) => {
|
||||
db.insert_latest_state(
|
||||
swap_id,
|
||||
storage::Alice::BtcRefunded {
|
||||
state::Alice::BtcRefunded {
|
||||
state: state3.clone(),
|
||||
spend_key,
|
||||
view_key,
|
||||
|
@ -265,7 +263,7 @@ pub async fn swap(
|
|||
.await?;
|
||||
}
|
||||
GeneratorState::Complete(()) => {
|
||||
db.insert_latest_state(swap_id, storage::Alice::SwapComplete.into())
|
||||
db.insert_latest_state(swap_id, state::Alice::SwapComplete.into())
|
||||
.await?;
|
||||
|
||||
return Ok(());
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue