From 238f6a989da56b57e7b33cff55463e51610759be Mon Sep 17 00:00:00 2001 From: Franck Royer Date: Thu, 3 Dec 2020 09:48:18 +1100 Subject: [PATCH] Extract spend key as soon as possible --- swap/src/alice/swap.rs | 47 ++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/swap/src/alice/swap.rs b/swap/src/alice/swap.rs index cc5e421a..380b542c 100644 --- a/swap/src/alice/swap.rs +++ b/swap/src/alice/swap.rs @@ -67,8 +67,7 @@ pub enum AliceState { tx_cancel: TxCancel, }, BtcRefunded { - tx_refund: TxRefund, - published_refund_tx: ::bitcoin::Transaction, + spend_key: monero::PrivateKey, state3: State3, }, BtcPunishable { @@ -244,8 +243,9 @@ pub async fn run_until( tracing::info!("Cannot resume swap from BTC locked state, aborting"); // Alice did not lock Xmr yet - swap( + run_until( AliceState::SafelyAborted, + is_target_state, event_loop_handle, bitcoin_wallet, monero_wallet, @@ -401,12 +401,16 @@ pub async fn run_until( .await } Some(published_refund_tx) => { + let spend_key = extract_monero_private_key( + published_refund_tx, + tx_refund, + state3.s_a, + state3.a.clone(), + state3.S_b_bitcoin, + )?; + run_until( - AliceState::BtcRefunded { - tx_refund, - published_refund_tx, - state3, - }, + AliceState::BtcRefunded { spend_key, state3 }, is_target_state, event_loop_handle, bitcoin_wallet.clone(), @@ -417,18 +421,7 @@ pub async fn run_until( } } } - AliceState::BtcRefunded { - tx_refund, - published_refund_tx, - state3, - } => { - let spend_key = extract_monero_private_key( - published_refund_tx, - tx_refund, - state3.s_a, - state3.a.clone(), - state3.S_b_bitcoin, - )?; + AliceState::BtcRefunded { spend_key, state3 } => { let view_key = state3.v; monero_wallet @@ -472,12 +465,16 @@ pub async fn run_until( .await } Either::Right((published_refund_tx, _)) => { + let spend_key = extract_monero_private_key( + published_refund_tx, + tx_refund, + state3.s_a, + state3.a.clone(), + state3.S_b_bitcoin, + )?; + run_until( - AliceState::BtcRefunded { - tx_refund, - published_refund_tx, - state3, - }, + AliceState::BtcRefunded { spend_key, state3 }, is_target_state, event_loop_handle, bitcoin_wallet.clone(),