mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-31 15:20:15 +00:00
Use action to name trait
This commit is contained in:
parent
4e91ac467b
commit
81cbc24c46
@ -19,8 +19,8 @@ use xmr_btc::{
|
|||||||
alice,
|
alice,
|
||||||
alice::State3,
|
alice::State3,
|
||||||
bitcoin::{
|
bitcoin::{
|
||||||
poll_until_block_height_is_gte, BlockHeight, BroadcastSignedTransaction,
|
poll_until_block_height_is_gte, BroadcastSignedTransaction, EncryptedSignature,
|
||||||
EncryptedSignature, GetRawTransaction, TransactionBlockHeight, TxCancel, TxLock, TxRefund,
|
GetBlockHeight, GetRawTransaction, TransactionBlockHeight, TxCancel, TxLock, TxRefund,
|
||||||
WaitForTransactionFinality, WatchForRawTransaction,
|
WaitForTransactionFinality, WatchForRawTransaction,
|
||||||
},
|
},
|
||||||
config::Config,
|
config::Config,
|
||||||
@ -212,7 +212,7 @@ pub async fn publish_cancel_transaction<W>(
|
|||||||
bitcoin_wallet: Arc<W>,
|
bitcoin_wallet: Arc<W>,
|
||||||
) -> Result<bitcoin::TxCancel>
|
) -> Result<bitcoin::TxCancel>
|
||||||
where
|
where
|
||||||
W: GetRawTransaction + TransactionBlockHeight + BlockHeight + BroadcastSignedTransaction,
|
W: GetRawTransaction + TransactionBlockHeight + GetBlockHeight + BroadcastSignedTransaction,
|
||||||
{
|
{
|
||||||
// First wait for cancel timelock to expire
|
// First wait for cancel timelock to expire
|
||||||
let tx_lock_height = bitcoin_wallet
|
let tx_lock_height = bitcoin_wallet
|
||||||
@ -259,7 +259,7 @@ pub async fn wait_for_bitcoin_refund<W>(
|
|||||||
bitcoin_wallet: Arc<W>,
|
bitcoin_wallet: Arc<W>,
|
||||||
) -> Result<(bitcoin::TxRefund, Option<bitcoin::Transaction>)>
|
) -> Result<(bitcoin::TxRefund, Option<bitcoin::Transaction>)>
|
||||||
where
|
where
|
||||||
W: BlockHeight + WatchForRawTransaction,
|
W: GetBlockHeight + WatchForRawTransaction,
|
||||||
{
|
{
|
||||||
let punish_timelock_expired =
|
let punish_timelock_expired =
|
||||||
poll_until_block_height_is_gte(bitcoin_wallet.as_ref(), cancel_tx_height + punish_timelock);
|
poll_until_block_height_is_gte(bitcoin_wallet.as_ref(), cancel_tx_height + punish_timelock);
|
||||||
|
@ -8,7 +8,7 @@ use std::time::Duration;
|
|||||||
use tokio::time::interval;
|
use tokio::time::interval;
|
||||||
use xmr_btc::{
|
use xmr_btc::{
|
||||||
bitcoin::{
|
bitcoin::{
|
||||||
BlockHeight, BroadcastSignedTransaction, BuildTxLockPsbt, SignTxLock,
|
BroadcastSignedTransaction, BuildTxLockPsbt, GetBlockHeight, SignTxLock,
|
||||||
TransactionBlockHeight, WatchForRawTransaction,
|
TransactionBlockHeight, WatchForRawTransaction,
|
||||||
},
|
},
|
||||||
config::Config,
|
config::Config,
|
||||||
@ -132,8 +132,8 @@ impl GetRawTransaction for Wallet {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl BlockHeight for Wallet {
|
impl GetBlockHeight for Wallet {
|
||||||
async fn block_height(&self) -> u32 {
|
async fn get_block_height(&self) -> u32 {
|
||||||
(|| async { Ok(self.inner.client.getblockcount().await?) })
|
(|| async { Ok(self.inner.client.getblockcount().await?) })
|
||||||
.retry(ConstantBackoff::new(Duration::from_secs(1)))
|
.retry(ConstantBackoff::new(Duration::from_secs(1)))
|
||||||
.await
|
.await
|
||||||
|
@ -29,7 +29,7 @@ use tokio::{sync::Mutex, time::timeout};
|
|||||||
use tracing::{error, info};
|
use tracing::{error, info};
|
||||||
pub mod message;
|
pub mod message;
|
||||||
use crate::bitcoin::{
|
use crate::bitcoin::{
|
||||||
current_epoch, wait_for_cancel_timelock_to_expire, BlockHeight, TransactionBlockHeight,
|
current_epoch, wait_for_cancel_timelock_to_expire, GetBlockHeight, TransactionBlockHeight,
|
||||||
};
|
};
|
||||||
pub use message::{Message, Message0, Message1, Message2};
|
pub use message::{Message, Message0, Message1, Message2};
|
||||||
|
|
||||||
@ -90,7 +90,7 @@ pub fn action_generator<N, B>(
|
|||||||
) -> GenBoxed<Action, (), ()>
|
) -> GenBoxed<Action, (), ()>
|
||||||
where
|
where
|
||||||
N: ReceiveBitcoinRedeemEncsig + Send + 'static,
|
N: ReceiveBitcoinRedeemEncsig + Send + 'static,
|
||||||
B: bitcoin::BlockHeight
|
B: bitcoin::GetBlockHeight
|
||||||
+ bitcoin::TransactionBlockHeight
|
+ bitcoin::TransactionBlockHeight
|
||||||
+ bitcoin::WatchForRawTransaction
|
+ bitcoin::WatchForRawTransaction
|
||||||
+ Send
|
+ Send
|
||||||
@ -684,7 +684,7 @@ impl State3 {
|
|||||||
|
|
||||||
pub async fn wait_for_cancel_timelock_to_expire<W>(&self, bitcoin_wallet: &W) -> Result<()>
|
pub async fn wait_for_cancel_timelock_to_expire<W>(&self, bitcoin_wallet: &W) -> Result<()>
|
||||||
where
|
where
|
||||||
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
|
W: WatchForRawTransaction + TransactionBlockHeight + GetBlockHeight,
|
||||||
{
|
{
|
||||||
wait_for_cancel_timelock_to_expire(
|
wait_for_cancel_timelock_to_expire(
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
@ -696,7 +696,7 @@ impl State3 {
|
|||||||
|
|
||||||
pub async fn expired_timelocks<W>(&self, bitcoin_wallet: &W) -> Result<ExpiredTimelocks>
|
pub async fn expired_timelocks<W>(&self, bitcoin_wallet: &W) -> Result<ExpiredTimelocks>
|
||||||
where
|
where
|
||||||
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
|
W: WatchForRawTransaction + TransactionBlockHeight + GetBlockHeight,
|
||||||
{
|
{
|
||||||
current_epoch(
|
current_epoch(
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
|
@ -201,8 +201,8 @@ pub trait WaitForTransactionFinality {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait BlockHeight {
|
pub trait GetBlockHeight {
|
||||||
async fn block_height(&self) -> u32;
|
async fn get_block_height(&self) -> u32;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
@ -238,9 +238,9 @@ pub fn recover(S: PublicKey, sig: Signature, encsig: EncryptedSignature) -> Resu
|
|||||||
|
|
||||||
pub async fn poll_until_block_height_is_gte<B>(client: &B, target: u32)
|
pub async fn poll_until_block_height_is_gte<B>(client: &B, target: u32)
|
||||||
where
|
where
|
||||||
B: BlockHeight,
|
B: GetBlockHeight,
|
||||||
{
|
{
|
||||||
while client.block_height().await < target {
|
while client.get_block_height().await < target {
|
||||||
tokio::time::delay_for(std::time::Duration::from_secs(1)).await;
|
tokio::time::delay_for(std::time::Duration::from_secs(1)).await;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -252,9 +252,9 @@ pub async fn current_epoch<W>(
|
|||||||
lock_tx_id: ::bitcoin::Txid,
|
lock_tx_id: ::bitcoin::Txid,
|
||||||
) -> anyhow::Result<ExpiredTimelocks>
|
) -> anyhow::Result<ExpiredTimelocks>
|
||||||
where
|
where
|
||||||
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
|
W: WatchForRawTransaction + TransactionBlockHeight + GetBlockHeight,
|
||||||
{
|
{
|
||||||
let current_block_height = bitcoin_wallet.block_height().await;
|
let current_block_height = bitcoin_wallet.get_block_height().await;
|
||||||
let lock_tx_height = bitcoin_wallet.transaction_block_height(lock_tx_id).await;
|
let lock_tx_height = bitcoin_wallet.transaction_block_height(lock_tx_id).await;
|
||||||
let cancel_timelock_height = lock_tx_height + cancel_timelock;
|
let cancel_timelock_height = lock_tx_height + cancel_timelock;
|
||||||
let punish_timelock_height = cancel_timelock_height + punish_timelock;
|
let punish_timelock_height = cancel_timelock_height + punish_timelock;
|
||||||
@ -275,7 +275,7 @@ pub async fn wait_for_cancel_timelock_to_expire<W>(
|
|||||||
lock_tx_id: ::bitcoin::Txid,
|
lock_tx_id: ::bitcoin::Txid,
|
||||||
) -> Result<()>
|
) -> Result<()>
|
||||||
where
|
where
|
||||||
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
|
W: WatchForRawTransaction + TransactionBlockHeight + GetBlockHeight,
|
||||||
{
|
{
|
||||||
let tx_lock_height = bitcoin_wallet.transaction_block_height(lock_tx_id).await;
|
let tx_lock_height = bitcoin_wallet.transaction_block_height(lock_tx_id).await;
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ use tracing::error;
|
|||||||
pub mod message;
|
pub mod message;
|
||||||
use crate::{
|
use crate::{
|
||||||
bitcoin::{
|
bitcoin::{
|
||||||
current_epoch, wait_for_cancel_timelock_to_expire, BlockHeight, GetRawTransaction, Network,
|
current_epoch, wait_for_cancel_timelock_to_expire, GetBlockHeight, GetRawTransaction,
|
||||||
TransactionBlockHeight,
|
Network, TransactionBlockHeight,
|
||||||
},
|
},
|
||||||
monero::{CreateWalletForOutput, WatchForTransfer},
|
monero::{CreateWalletForOutput, WatchForTransfer},
|
||||||
};
|
};
|
||||||
@ -95,7 +95,7 @@ pub fn action_generator<N, M, B>(
|
|||||||
where
|
where
|
||||||
N: ReceiveTransferProof + Send + 'static,
|
N: ReceiveTransferProof + Send + 'static,
|
||||||
M: monero::WatchForTransfer + Send + Sync + 'static,
|
M: monero::WatchForTransfer + Send + Sync + 'static,
|
||||||
B: bitcoin::BlockHeight
|
B: bitcoin::GetBlockHeight
|
||||||
+ bitcoin::TransactionBlockHeight
|
+ bitcoin::TransactionBlockHeight
|
||||||
+ bitcoin::WatchForRawTransaction
|
+ bitcoin::WatchForRawTransaction
|
||||||
+ Send
|
+ Send
|
||||||
@ -626,7 +626,7 @@ impl State3 {
|
|||||||
|
|
||||||
pub async fn wait_for_cancel_timelock_to_expire<W>(&self, bitcoin_wallet: &W) -> Result<()>
|
pub async fn wait_for_cancel_timelock_to_expire<W>(&self, bitcoin_wallet: &W) -> Result<()>
|
||||||
where
|
where
|
||||||
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
|
W: WatchForRawTransaction + TransactionBlockHeight + GetBlockHeight,
|
||||||
{
|
{
|
||||||
wait_for_cancel_timelock_to_expire(
|
wait_for_cancel_timelock_to_expire(
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
@ -663,7 +663,7 @@ impl State3 {
|
|||||||
|
|
||||||
pub async fn current_epoch<W>(&self, bitcoin_wallet: &W) -> Result<ExpiredTimelocks>
|
pub async fn current_epoch<W>(&self, bitcoin_wallet: &W) -> Result<ExpiredTimelocks>
|
||||||
where
|
where
|
||||||
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
|
W: WatchForRawTransaction + TransactionBlockHeight + GetBlockHeight,
|
||||||
{
|
{
|
||||||
current_epoch(
|
current_epoch(
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
@ -795,7 +795,7 @@ impl State4 {
|
|||||||
|
|
||||||
pub async fn wait_for_cancel_timelock_to_expire<W>(&self, bitcoin_wallet: &W) -> Result<()>
|
pub async fn wait_for_cancel_timelock_to_expire<W>(&self, bitcoin_wallet: &W) -> Result<()>
|
||||||
where
|
where
|
||||||
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
|
W: WatchForRawTransaction + TransactionBlockHeight + GetBlockHeight,
|
||||||
{
|
{
|
||||||
wait_for_cancel_timelock_to_expire(
|
wait_for_cancel_timelock_to_expire(
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
@ -807,7 +807,7 @@ impl State4 {
|
|||||||
|
|
||||||
pub async fn expired_timelock<W>(&self, bitcoin_wallet: &W) -> Result<ExpiredTimelocks>
|
pub async fn expired_timelock<W>(&self, bitcoin_wallet: &W) -> Result<ExpiredTimelocks>
|
||||||
where
|
where
|
||||||
W: WatchForRawTransaction + TransactionBlockHeight + BlockHeight,
|
W: WatchForRawTransaction + TransactionBlockHeight + GetBlockHeight,
|
||||||
{
|
{
|
||||||
current_epoch(
|
current_epoch(
|
||||||
bitcoin_wallet,
|
bitcoin_wallet,
|
||||||
|
Loading…
Reference in New Issue
Block a user