mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-11-17 15:26:14 +00:00
Inline wait_for_locked_bitcoin() that is only called once
Reduce indirection.
This commit is contained in:
parent
6a3e4802f1
commit
21429f24b2
@ -2,7 +2,6 @@ use crate::bitcoin::{
|
|||||||
poll_until_block_height_is_gte, BlockHeight, CancelTimelock, EncryptedSignature,
|
poll_until_block_height_is_gte, BlockHeight, CancelTimelock, EncryptedSignature,
|
||||||
PunishTimelock, TxCancel, TxLock, TxRefund,
|
PunishTimelock, TxCancel, TxLock, TxRefund,
|
||||||
};
|
};
|
||||||
use crate::execution_params::ExecutionParams;
|
|
||||||
use crate::protocol::alice;
|
use crate::protocol::alice;
|
||||||
use crate::protocol::alice::event_loop::EventLoopHandle;
|
use crate::protocol::alice::event_loop::EventLoopHandle;
|
||||||
use crate::protocol::alice::TransferProof;
|
use crate::protocol::alice::TransferProof;
|
||||||
@ -14,30 +13,6 @@ use futures::future::{select, Either};
|
|||||||
use futures::pin_mut;
|
use futures::pin_mut;
|
||||||
use libp2p::PeerId;
|
use libp2p::PeerId;
|
||||||
use sha2::Sha256;
|
use sha2::Sha256;
|
||||||
use tokio::time::timeout;
|
|
||||||
|
|
||||||
// TODO(Franck): Use helper functions from xmr-btc instead of re-writing them
|
|
||||||
// here
|
|
||||||
pub async fn wait_for_locked_bitcoin(
|
|
||||||
lock_bitcoin_txid: bitcoin::Txid,
|
|
||||||
bitcoin_wallet: &bitcoin::Wallet,
|
|
||||||
execution_params: ExecutionParams,
|
|
||||||
) -> Result<()> {
|
|
||||||
// We assume we will see Bob's transaction in the mempool first.
|
|
||||||
timeout(
|
|
||||||
execution_params.bob_time_to_act,
|
|
||||||
bitcoin_wallet.watch_for_raw_transaction(lock_bitcoin_txid),
|
|
||||||
)
|
|
||||||
.await
|
|
||||||
.context("Failed to find lock Bitcoin tx")??;
|
|
||||||
|
|
||||||
// // We saw the transaction in the mempool, waiting for it to be confirmed.
|
|
||||||
bitcoin_wallet
|
|
||||||
.wait_for_transaction_finality(lock_bitcoin_txid, execution_params)
|
|
||||||
.await?;
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub async fn lock_xmr(
|
pub async fn lock_xmr(
|
||||||
bob_peer_id: PeerId,
|
bob_peer_id: PeerId,
|
||||||
|
@ -9,16 +9,17 @@ use crate::protocol::alice::event_loop::EventLoopHandle;
|
|||||||
use crate::protocol::alice::steps::{
|
use crate::protocol::alice::steps::{
|
||||||
build_bitcoin_punish_transaction, build_bitcoin_redeem_transaction, extract_monero_private_key,
|
build_bitcoin_punish_transaction, build_bitcoin_redeem_transaction, extract_monero_private_key,
|
||||||
lock_xmr, publish_cancel_transaction, wait_for_bitcoin_encrypted_signature,
|
lock_xmr, publish_cancel_transaction, wait_for_bitcoin_encrypted_signature,
|
||||||
wait_for_bitcoin_refund, wait_for_locked_bitcoin,
|
wait_for_bitcoin_refund,
|
||||||
};
|
};
|
||||||
use crate::protocol::alice::AliceState;
|
use crate::protocol::alice::AliceState;
|
||||||
use crate::{bitcoin, database, monero};
|
use crate::{bitcoin, database, monero};
|
||||||
use anyhow::{bail, Result};
|
use anyhow::{bail, Context, Result};
|
||||||
use async_recursion::async_recursion;
|
use async_recursion::async_recursion;
|
||||||
use futures::future::{select, Either};
|
use futures::future::{select, Either};
|
||||||
use futures::pin_mut;
|
use futures::pin_mut;
|
||||||
use rand::{CryptoRng, RngCore};
|
use rand::{CryptoRng, RngCore};
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use tokio::time::timeout;
|
||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
use uuid::Uuid;
|
use uuid::Uuid;
|
||||||
|
|
||||||
@ -80,12 +81,16 @@ async fn run_until_internal(
|
|||||||
state3,
|
state3,
|
||||||
bob_peer_id,
|
bob_peer_id,
|
||||||
} => {
|
} => {
|
||||||
let _ = wait_for_locked_bitcoin(
|
timeout(
|
||||||
state3.tx_lock.txid(),
|
execution_params.bob_time_to_act,
|
||||||
&bitcoin_wallet,
|
bitcoin_wallet.watch_for_raw_transaction(state3.tx_lock.txid()),
|
||||||
execution_params,
|
|
||||||
)
|
)
|
||||||
.await?;
|
.await
|
||||||
|
.context("Failed to find lock Bitcoin tx")??;
|
||||||
|
|
||||||
|
bitcoin_wallet
|
||||||
|
.wait_for_transaction_finality(state3.tx_lock.txid(), execution_params)
|
||||||
|
.await?;
|
||||||
|
|
||||||
let state = AliceState::BtcLocked {
|
let state = AliceState::BtcLocked {
|
||||||
bob_peer_id,
|
bob_peer_id,
|
||||||
|
Loading…
Reference in New Issue
Block a user