mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-02-18 13:44:11 -05:00
WIP: remove force
This commit is contained in:
parent
e1fdf421f8
commit
44570ff598
@ -15,7 +15,7 @@ pub async fn cancel(
|
|||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
bitcoin_wallet: Arc<Wallet>,
|
bitcoin_wallet: Arc<Wallet>,
|
||||||
db: Arc<Database>,
|
db: Arc<Database>,
|
||||||
force: bool,
|
graceful: bool,
|
||||||
) -> Result<Result<(Txid, AliceState), Error>> {
|
) -> Result<Result<(Txid, AliceState), Error>> {
|
||||||
let state = db.get_state(swap_id)?.try_into_alice()?.into();
|
let state = db.get_state(swap_id)?.try_into_alice()?.into();
|
||||||
|
|
||||||
@ -52,7 +52,7 @@ pub async fn cancel(
|
|||||||
|
|
||||||
tracing::info!(%swap_id, "Trying to manually cancel swap");
|
tracing::info!(%swap_id, "Trying to manually cancel swap");
|
||||||
|
|
||||||
if !force {
|
if graceful {
|
||||||
tracing::debug!(%swap_id, "Checking if cancel timelock is expired");
|
tracing::debug!(%swap_id, "Checking if cancel timelock is expired");
|
||||||
|
|
||||||
if let ExpiredTimelocks::None = state3.expired_timelocks(bitcoin_wallet.as_ref()).await? {
|
if let ExpiredTimelocks::None = state3.expired_timelocks(bitcoin_wallet.as_ref()).await? {
|
||||||
|
@ -273,7 +273,7 @@ async fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
Command::Cancel {
|
Command::Cancel {
|
||||||
swap_id,
|
swap_id,
|
||||||
force,
|
graceful,
|
||||||
bitcoin_electrum_rpc_url,
|
bitcoin_electrum_rpc_url,
|
||||||
bitcoin_target_block,
|
bitcoin_target_block,
|
||||||
} => {
|
} => {
|
||||||
@ -292,7 +292,7 @@ async fn main() -> Result<()> {
|
|||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
let cancel = cli::cancel(swap_id, Arc::new(bitcoin_wallet), db, force).await?;
|
let cancel = cli::cancel(swap_id, Arc::new(bitcoin_wallet), db, graceful).await?;
|
||||||
|
|
||||||
match cancel {
|
match cancel {
|
||||||
Ok((txid, _)) => {
|
Ok((txid, _)) => {
|
||||||
@ -305,7 +305,7 @@ async fn main() -> Result<()> {
|
|||||||
}
|
}
|
||||||
Command::Refund {
|
Command::Refund {
|
||||||
swap_id,
|
swap_id,
|
||||||
force,
|
graceful: force,
|
||||||
bitcoin_electrum_rpc_url,
|
bitcoin_electrum_rpc_url,
|
||||||
bitcoin_target_block,
|
bitcoin_target_block,
|
||||||
} => {
|
} => {
|
||||||
|
@ -171,7 +171,7 @@ where
|
|||||||
}
|
}
|
||||||
RawCommand::Cancel {
|
RawCommand::Cancel {
|
||||||
swap_id: SwapId { swap_id },
|
swap_id: SwapId { swap_id },
|
||||||
force,
|
graceful: force,
|
||||||
bitcoin,
|
bitcoin,
|
||||||
} => {
|
} => {
|
||||||
let (bitcoin_electrum_rpc_url, bitcoin_target_block) =
|
let (bitcoin_electrum_rpc_url, bitcoin_target_block) =
|
||||||
@ -184,7 +184,7 @@ where
|
|||||||
data_dir: data::data_dir_from(data, is_testnet)?,
|
data_dir: data::data_dir_from(data, is_testnet)?,
|
||||||
cmd: Command::Cancel {
|
cmd: Command::Cancel {
|
||||||
swap_id,
|
swap_id,
|
||||||
force,
|
graceful: force,
|
||||||
bitcoin_electrum_rpc_url,
|
bitcoin_electrum_rpc_url,
|
||||||
bitcoin_target_block,
|
bitcoin_target_block,
|
||||||
},
|
},
|
||||||
@ -192,7 +192,7 @@ where
|
|||||||
}
|
}
|
||||||
RawCommand::Refund {
|
RawCommand::Refund {
|
||||||
swap_id: SwapId { swap_id },
|
swap_id: SwapId { swap_id },
|
||||||
force,
|
graceful: force,
|
||||||
bitcoin,
|
bitcoin,
|
||||||
} => {
|
} => {
|
||||||
let (bitcoin_electrum_rpc_url, bitcoin_target_block) =
|
let (bitcoin_electrum_rpc_url, bitcoin_target_block) =
|
||||||
@ -205,7 +205,7 @@ where
|
|||||||
data_dir: data::data_dir_from(data, is_testnet)?,
|
data_dir: data::data_dir_from(data, is_testnet)?,
|
||||||
cmd: Command::Refund {
|
cmd: Command::Refund {
|
||||||
swap_id,
|
swap_id,
|
||||||
force,
|
graceful: force,
|
||||||
bitcoin_electrum_rpc_url,
|
bitcoin_electrum_rpc_url,
|
||||||
bitcoin_target_block,
|
bitcoin_target_block,
|
||||||
},
|
},
|
||||||
@ -261,13 +261,13 @@ pub enum Command {
|
|||||||
},
|
},
|
||||||
Cancel {
|
Cancel {
|
||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
force: bool,
|
graceful: bool,
|
||||||
bitcoin_electrum_rpc_url: Url,
|
bitcoin_electrum_rpc_url: Url,
|
||||||
bitcoin_target_block: usize,
|
bitcoin_target_block: usize,
|
||||||
},
|
},
|
||||||
Refund {
|
Refund {
|
||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
force: bool,
|
graceful: bool,
|
||||||
bitcoin_electrum_rpc_url: Url,
|
bitcoin_electrum_rpc_url: Url,
|
||||||
bitcoin_target_block: usize,
|
bitcoin_target_block: usize,
|
||||||
},
|
},
|
||||||
@ -376,24 +376,24 @@ enum RawCommand {
|
|||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
tor: Tor,
|
tor: Tor,
|
||||||
},
|
},
|
||||||
/// Try to cancel an ongoing swap (expert users only)
|
/// Force submission of the cancel transaction overriding the protocol state machine and blockheight checks (expert users only)
|
||||||
Cancel {
|
Cancel {
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
swap_id: SwapId,
|
swap_id: SwapId,
|
||||||
|
|
||||||
#[structopt(short, long)]
|
#[structopt(short, long, help = "Performs checks to see whether it is appropriate to refund before submitting the cancel transaction")]
|
||||||
force: bool,
|
graceful: bool,
|
||||||
|
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
bitcoin: Bitcoin,
|
bitcoin: Bitcoin,
|
||||||
},
|
},
|
||||||
/// Try to cancel a swap and refund the BTC (expert users only)
|
/// Force submission of the cancel transaction overriding the protocol state machine and blockheight checks (expert users only)
|
||||||
Refund {
|
Refund {
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
swap_id: SwapId,
|
swap_id: SwapId,
|
||||||
|
|
||||||
#[structopt(short, long)]
|
#[structopt(short, long, help = "Performs checks to see whether it is appropriate to refund before submitting the refund transaction")]
|
||||||
force: bool,
|
graceful: bool,
|
||||||
|
|
||||||
#[structopt(flatten)]
|
#[structopt(flatten)]
|
||||||
bitcoin: Bitcoin,
|
bitcoin: Bitcoin,
|
||||||
@ -1173,7 +1173,7 @@ mod tests {
|
|||||||
data_dir: data_dir_path_cli().join(TESTNET),
|
data_dir: data_dir_path_cli().join(TESTNET),
|
||||||
cmd: Command::Cancel {
|
cmd: Command::Cancel {
|
||||||
swap_id: Uuid::from_str(SWAP_ID).unwrap(),
|
swap_id: Uuid::from_str(SWAP_ID).unwrap(),
|
||||||
force: false,
|
graceful: false,
|
||||||
bitcoin_electrum_rpc_url: Url::from_str(DEFAULT_ELECTRUM_RPC_URL_TESTNET)
|
bitcoin_electrum_rpc_url: Url::from_str(DEFAULT_ELECTRUM_RPC_URL_TESTNET)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
bitcoin_target_block: DEFAULT_BITCOIN_CONFIRMATION_TARGET_TESTNET,
|
bitcoin_target_block: DEFAULT_BITCOIN_CONFIRMATION_TARGET_TESTNET,
|
||||||
@ -1189,7 +1189,7 @@ mod tests {
|
|||||||
data_dir: data_dir_path_cli().join(MAINNET),
|
data_dir: data_dir_path_cli().join(MAINNET),
|
||||||
cmd: Command::Cancel {
|
cmd: Command::Cancel {
|
||||||
swap_id: Uuid::from_str(SWAP_ID).unwrap(),
|
swap_id: Uuid::from_str(SWAP_ID).unwrap(),
|
||||||
force: false,
|
graceful: false,
|
||||||
bitcoin_electrum_rpc_url: Url::from_str(DEFAULT_ELECTRUM_RPC_URL).unwrap(),
|
bitcoin_electrum_rpc_url: Url::from_str(DEFAULT_ELECTRUM_RPC_URL).unwrap(),
|
||||||
bitcoin_target_block: DEFAULT_BITCOIN_CONFIRMATION_TARGET,
|
bitcoin_target_block: DEFAULT_BITCOIN_CONFIRMATION_TARGET,
|
||||||
},
|
},
|
||||||
@ -1204,7 +1204,7 @@ mod tests {
|
|||||||
data_dir: data_dir_path_cli().join(TESTNET),
|
data_dir: data_dir_path_cli().join(TESTNET),
|
||||||
cmd: Command::Refund {
|
cmd: Command::Refund {
|
||||||
swap_id: Uuid::from_str(SWAP_ID).unwrap(),
|
swap_id: Uuid::from_str(SWAP_ID).unwrap(),
|
||||||
force: false,
|
graceful: false,
|
||||||
bitcoin_electrum_rpc_url: Url::from_str(DEFAULT_ELECTRUM_RPC_URL_TESTNET)
|
bitcoin_electrum_rpc_url: Url::from_str(DEFAULT_ELECTRUM_RPC_URL_TESTNET)
|
||||||
.unwrap(),
|
.unwrap(),
|
||||||
bitcoin_target_block: DEFAULT_BITCOIN_CONFIRMATION_TARGET_TESTNET,
|
bitcoin_target_block: DEFAULT_BITCOIN_CONFIRMATION_TARGET_TESTNET,
|
||||||
@ -1220,7 +1220,7 @@ mod tests {
|
|||||||
data_dir: data_dir_path_cli().join(MAINNET),
|
data_dir: data_dir_path_cli().join(MAINNET),
|
||||||
cmd: Command::Refund {
|
cmd: Command::Refund {
|
||||||
swap_id: Uuid::from_str(SWAP_ID).unwrap(),
|
swap_id: Uuid::from_str(SWAP_ID).unwrap(),
|
||||||
force: false,
|
graceful: false,
|
||||||
bitcoin_electrum_rpc_url: Url::from_str(DEFAULT_ELECTRUM_RPC_URL).unwrap(),
|
bitcoin_electrum_rpc_url: Url::from_str(DEFAULT_ELECTRUM_RPC_URL).unwrap(),
|
||||||
bitcoin_target_block: DEFAULT_BITCOIN_CONFIRMATION_TARGET,
|
bitcoin_target_block: DEFAULT_BITCOIN_CONFIRMATION_TARGET,
|
||||||
},
|
},
|
||||||
|
@ -13,11 +13,11 @@ pub async fn refund(
|
|||||||
swap_id: Uuid,
|
swap_id: Uuid,
|
||||||
bitcoin_wallet: Arc<Wallet>,
|
bitcoin_wallet: Arc<Wallet>,
|
||||||
db: Database,
|
db: Database,
|
||||||
force: bool,
|
graceful: bool,
|
||||||
) -> Result<Result<BobState, SwapNotCancelledYet>> {
|
) -> Result<Result<BobState, SwapNotCancelledYet>> {
|
||||||
let state = db.get_state(swap_id)?.try_into_bob()?.into();
|
let state = db.get_state(swap_id)?.try_into_bob()?.into();
|
||||||
|
|
||||||
let state6 = if force {
|
let state6 = if !graceful {
|
||||||
match state {
|
match state {
|
||||||
BobState::BtcLocked(state3) => state3.cancel(),
|
BobState::BtcLocked(state3) => state3.cancel(),
|
||||||
BobState::XmrLockProofReceived { state, .. } => state.cancel(),
|
BobState::XmrLockProofReceived { state, .. } => state.cancel(),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user