Split RefundBitcoin into CancelBitcoin and RefundBitcoin

This commit is contained in:
Lucas Soriano del Pino 2020-10-16 14:06:25 +11:00
parent d813957c5a
commit 969ca63081
2 changed files with 10 additions and 16 deletions

View File

@ -69,10 +69,8 @@ pub enum Action {
spend_key: monero::PrivateKey, spend_key: monero::PrivateKey,
view_key: monero::PrivateViewKey, view_key: monero::PrivateViewKey,
}, },
RefundBitcoin { CancelBitcoin(bitcoin::Transaction),
tx_cancel: bitcoin::Transaction, RefundBitcoin(bitcoin::Transaction),
tx_refund: bitcoin::Transaction,
},
} }
// TODO: This could be moved to the monero module // TODO: This could be moved to the monero module
@ -250,8 +248,6 @@ where
if let Err(SwapFailed::AfterBtcLock(_)) = swap_result { if let Err(SwapFailed::AfterBtcLock(_)) = swap_result {
let tx_cancel = let tx_cancel =
bitcoin::TxCancel::new(&tx_lock, refund_timelock, A.clone(), b.public()); bitcoin::TxCancel::new(&tx_lock, refund_timelock, A.clone(), b.public());
let tx_refund = bitcoin::TxRefund::new(&tx_cancel, &refund_address);
let signed_tx_cancel = { let signed_tx_cancel = {
let sig_a = tx_cancel_sig_a.clone(); let sig_a = tx_cancel_sig_a.clone();
let sig_b = b.sign(tx_cancel.digest()); let sig_b = b.sign(tx_cancel.digest());
@ -262,7 +258,11 @@ where
.expect("sig_{a,b} to be valid signatures for tx_cancel") .expect("sig_{a,b} to be valid signatures for tx_cancel")
}; };
co.yield_(Action::CancelBitcoin(signed_tx_cancel)).await;
let signed_tx_refund = { let signed_tx_refund = {
let tx_refund = bitcoin::TxRefund::new(&tx_cancel, &refund_address);
let adaptor = Adaptor::<Sha256, Deterministic<Sha256>>::default(); let adaptor = Adaptor::<Sha256, Deterministic<Sha256>>::default();
let sig_a = let sig_a =
@ -274,11 +274,7 @@ where
.expect("sig_{a,b} to be valid signatures for tx_refund") .expect("sig_{a,b} to be valid signatures for tx_refund")
}; };
co.yield_(Action::RefundBitcoin { co.yield_(Action::RefundBitcoin(signed_tx_refund)).await;
tx_cancel: signed_tx_cancel,
tx_refund: signed_tx_refund,
})
.await;
} }
}) })
} }

View File

@ -48,14 +48,12 @@ async fn swap_as_bob(
.create_and_load_wallet_for_output(spend_key, view_key) .create_and_load_wallet_for_output(spend_key, view_key)
.await?; .await?;
} }
GeneratorState::Yielded(Action::RefundBitcoin { GeneratorState::Yielded(Action::CancelBitcoin(tx_cancel)) => {
tx_cancel,
tx_refund,
}) => {
let _ = bitcoin_wallet let _ = bitcoin_wallet
.broadcast_signed_transaction(tx_cancel) .broadcast_signed_transaction(tx_cancel)
.await?; .await?;
}
GeneratorState::Yielded(Action::RefundBitcoin(tx_refund)) => {
let _ = bitcoin_wallet let _ = bitcoin_wallet
.broadcast_signed_transaction(tx_refund) .broadcast_signed_transaction(tx_refund)
.await?; .await?;