mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-12-17 20:04:25 -05:00
Take bitcoin_tx_lock_timeout as argument to action generators
This commit is contained in:
parent
1d21ae7e7a
commit
cea1af1e1a
@ -58,6 +58,9 @@ pub trait ReceiveBitcoinRedeemEncsig {
|
|||||||
///
|
///
|
||||||
/// This is called post handshake, after all the keys, addresses and most of the
|
/// This is called post handshake, after all the keys, addresses and most of the
|
||||||
/// signatures have been exchanged.
|
/// signatures have been exchanged.
|
||||||
|
///
|
||||||
|
/// The argument `bitcoin_tx_lock_timeout` is used to determine how long we will
|
||||||
|
/// wait for Bob, the counterparty, to lock up the bitcoin.
|
||||||
pub fn action_generator<N, B>(
|
pub fn action_generator<N, B>(
|
||||||
mut network: N,
|
mut network: N,
|
||||||
bitcoin_client: Arc<B>,
|
bitcoin_client: Arc<B>,
|
||||||
@ -80,6 +83,7 @@ pub fn action_generator<N, B>(
|
|||||||
tx_cancel_sig_bob,
|
tx_cancel_sig_bob,
|
||||||
..
|
..
|
||||||
}: State3,
|
}: State3,
|
||||||
|
bitcoin_tx_lock_timeout: u64,
|
||||||
) -> GenBoxed<Action, (), ()>
|
) -> GenBoxed<Action, (), ()>
|
||||||
where
|
where
|
||||||
N: ReceiveBitcoinRedeemEncsig + Send + Sync + 'static,
|
N: ReceiveBitcoinRedeemEncsig + Send + Sync + 'static,
|
||||||
@ -124,7 +128,7 @@ where
|
|||||||
Gen::new_boxed(|co| async move {
|
Gen::new_boxed(|co| async move {
|
||||||
let swap_result: Result<(), SwapFailed> = async {
|
let swap_result: Result<(), SwapFailed> = async {
|
||||||
timeout(
|
timeout(
|
||||||
Duration::from_secs(bob::SECS_TO_ACT),
|
Duration::from_secs(bitcoin_tx_lock_timeout),
|
||||||
bitcoin_client.watch_for_raw_transaction(tx_lock.txid()),
|
bitcoin_client.watch_for_raw_transaction(tx_lock.txid()),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -35,11 +35,6 @@ pub mod message;
|
|||||||
use crate::monero::{CreateWalletForOutput, WatchForTransfer};
|
use crate::monero::{CreateWalletForOutput, WatchForTransfer};
|
||||||
pub use message::{Message, Message0, Message1, Message2, Message3};
|
pub use message::{Message, Message0, Message1, Message2, Message3};
|
||||||
|
|
||||||
// TODO: Replace this with something configurable, such as an function argument.
|
|
||||||
/// Time that Bob has to publish the Bitcoin lock transaction before both
|
|
||||||
/// parties will abort, in seconds.
|
|
||||||
pub const SECS_TO_ACT: u64 = 60;
|
|
||||||
|
|
||||||
#[allow(clippy::large_enum_variant)]
|
#[allow(clippy::large_enum_variant)]
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub enum Action {
|
pub enum Action {
|
||||||
@ -63,6 +58,9 @@ pub trait ReceiveTransferProof {
|
|||||||
///
|
///
|
||||||
/// This is called post handshake, after all the keys, addresses and most of the
|
/// This is called post handshake, after all the keys, addresses and most of the
|
||||||
/// signatures have been exchanged.
|
/// signatures have been exchanged.
|
||||||
|
///
|
||||||
|
/// The argument `bitcoin_tx_lock_timeout` is used to determine how long we will
|
||||||
|
/// wait for Bob, the caller of this function, to lock up the bitcoin.
|
||||||
pub fn action_generator<N, M, B>(
|
pub fn action_generator<N, M, B>(
|
||||||
mut network: N,
|
mut network: N,
|
||||||
monero_client: Arc<M>,
|
monero_client: Arc<M>,
|
||||||
@ -84,6 +82,7 @@ pub fn action_generator<N, M, B>(
|
|||||||
tx_refund_encsig,
|
tx_refund_encsig,
|
||||||
..
|
..
|
||||||
}: State2,
|
}: State2,
|
||||||
|
bitcoin_tx_lock_timeout: u64,
|
||||||
) -> GenBoxed<Action, (), ()>
|
) -> GenBoxed<Action, (), ()>
|
||||||
where
|
where
|
||||||
N: ReceiveTransferProof + Send + Sync + 'static,
|
N: ReceiveTransferProof + Send + Sync + 'static,
|
||||||
@ -124,7 +123,7 @@ where
|
|||||||
co.yield_(Action::LockBtc(tx_lock.clone())).await;
|
co.yield_(Action::LockBtc(tx_lock.clone())).await;
|
||||||
|
|
||||||
timeout(
|
timeout(
|
||||||
Duration::from_secs(SECS_TO_ACT),
|
Duration::from_secs(bitcoin_tx_lock_timeout),
|
||||||
bitcoin_client.watch_for_raw_transaction(tx_lock.txid()),
|
bitcoin_client.watch_for_raw_transaction(tx_lock.txid()),
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
@ -25,6 +25,9 @@ use xmr_btc::{
|
|||||||
monero::{CreateWalletForOutput, Transfer, TransferProof},
|
monero::{CreateWalletForOutput, Transfer, TransferProof},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/// Time given to Bob to get the Bitcoin lock transaction included in a block.
|
||||||
|
const BITCOIN_TX_LOCK_TIMEOUT: u64 = 5;
|
||||||
|
|
||||||
type AliceNetwork = Network<EncryptedSignature>;
|
type AliceNetwork = Network<EncryptedSignature>;
|
||||||
type BobNetwork = Network<TransferProof>;
|
type BobNetwork = Network<TransferProof>;
|
||||||
|
|
||||||
@ -87,7 +90,12 @@ async fn swap_as_alice(
|
|||||||
behaviour: AliceBehaviour,
|
behaviour: AliceBehaviour,
|
||||||
state: alice::State3,
|
state: alice::State3,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
let mut action_generator = alice::action_generator(network, bitcoin_wallet.clone(), state);
|
let mut action_generator = alice::action_generator(
|
||||||
|
network,
|
||||||
|
bitcoin_wallet.clone(),
|
||||||
|
state,
|
||||||
|
BITCOIN_TX_LOCK_TIMEOUT,
|
||||||
|
);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
let state = action_generator.async_resume().await;
|
let state = action_generator.async_resume().await;
|
||||||
@ -150,6 +158,7 @@ async fn swap_as_bob(
|
|||||||
monero_wallet.clone(),
|
monero_wallet.clone(),
|
||||||
bitcoin_wallet.clone(),
|
bitcoin_wallet.clone(),
|
||||||
state,
|
state,
|
||||||
|
BITCOIN_TX_LOCK_TIMEOUT,
|
||||||
);
|
);
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
Loading…
Reference in New Issue
Block a user