mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2025-05-20 15:40:48 -04:00
Remove traits in favor of using the wallet struct directly
Abstracting over the individual bits of functionality of the wallet does have its place, especially if one wants to keep a separation of an abstract protocol library that other people can use with their own wallets. However, at the moment, the traits only cause unnecessary friction. We can always add such abstraction layers again once we need them.
This commit is contained in:
parent
8c0df23647
commit
45cff81ea5
6 changed files with 96 additions and 203 deletions
|
@ -1,10 +1,8 @@
|
|||
use crate::{
|
||||
bitcoin,
|
||||
bitcoin::{
|
||||
poll_until_block_height_is_gte, BlockHeight, BroadcastSignedTransaction, CancelTimelock,
|
||||
EncryptedSignature, GetBlockHeight, GetRawTransaction, PunishTimelock,
|
||||
TransactionBlockHeight, TxCancel, TxLock, TxRefund, WaitForTransactionFinality,
|
||||
WatchForRawTransaction,
|
||||
poll_until_block_height_is_gte, BlockHeight, CancelTimelock, EncryptedSignature,
|
||||
PunishTimelock, TxCancel, TxLock, TxRefund,
|
||||
},
|
||||
execution_params::ExecutionParams,
|
||||
monero,
|
||||
|
@ -31,14 +29,11 @@ use tracing::info;
|
|||
|
||||
// TODO(Franck): Use helper functions from xmr-btc instead of re-writing them
|
||||
// here
|
||||
pub async fn wait_for_locked_bitcoin<W>(
|
||||
pub async fn wait_for_locked_bitcoin(
|
||||
lock_bitcoin_txid: bitcoin::Txid,
|
||||
bitcoin_wallet: Arc<W>,
|
||||
bitcoin_wallet: &bitcoin::Wallet,
|
||||
execution_params: ExecutionParams,
|
||||
) -> Result<()>
|
||||
where
|
||||
W: WatchForRawTransaction + WaitForTransactionFinality,
|
||||
{
|
||||
) -> Result<()> {
|
||||
// We assume we will see Bob's transaction in the mempool first.
|
||||
timeout(
|
||||
execution_params.bob_time_to_act,
|
||||
|
@ -130,13 +125,10 @@ pub fn build_bitcoin_redeem_transaction(
|
|||
Ok(tx)
|
||||
}
|
||||
|
||||
pub async fn publish_bitcoin_redeem_transaction<W>(
|
||||
pub async fn publish_bitcoin_redeem_transaction(
|
||||
redeem_tx: bitcoin::Transaction,
|
||||
bitcoin_wallet: Arc<W>,
|
||||
) -> Result<::bitcoin::Txid>
|
||||
where
|
||||
W: BroadcastSignedTransaction + WaitForTransactionFinality,
|
||||
{
|
||||
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||
) -> Result<::bitcoin::Txid> {
|
||||
info!("Attempting to publish bitcoin redeem txn");
|
||||
let txid = bitcoin_wallet
|
||||
.broadcast_signed_transaction(redeem_tx)
|
||||
|
@ -145,17 +137,14 @@ where
|
|||
Ok(txid)
|
||||
}
|
||||
|
||||
pub async fn publish_cancel_transaction<W>(
|
||||
pub async fn publish_cancel_transaction(
|
||||
tx_lock: TxLock,
|
||||
a: bitcoin::SecretKey,
|
||||
B: bitcoin::PublicKey,
|
||||
cancel_timelock: CancelTimelock,
|
||||
tx_cancel_sig_bob: bitcoin::Signature,
|
||||
bitcoin_wallet: Arc<W>,
|
||||
) -> Result<bitcoin::TxCancel>
|
||||
where
|
||||
W: GetRawTransaction + TransactionBlockHeight + GetBlockHeight + BroadcastSignedTransaction,
|
||||
{
|
||||
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||
) -> Result<bitcoin::TxCancel> {
|
||||
// First wait for cancel timelock to expire
|
||||
let tx_lock_height = bitcoin_wallet
|
||||
.transaction_block_height(tx_lock.txid())
|
||||
|
@ -194,18 +183,15 @@ where
|
|||
Ok(tx_cancel)
|
||||
}
|
||||
|
||||
pub async fn wait_for_bitcoin_refund<W>(
|
||||
pub async fn wait_for_bitcoin_refund(
|
||||
tx_cancel: &TxCancel,
|
||||
cancel_tx_height: BlockHeight,
|
||||
punish_timelock: PunishTimelock,
|
||||
refund_address: &bitcoin::Address,
|
||||
bitcoin_wallet: Arc<W>,
|
||||
) -> Result<(bitcoin::TxRefund, Option<bitcoin::Transaction>)>
|
||||
where
|
||||
W: GetBlockHeight + WatchForRawTransaction,
|
||||
{
|
||||
bitcoin_wallet: &bitcoin::Wallet,
|
||||
) -> Result<(bitcoin::TxRefund, Option<bitcoin::Transaction>)> {
|
||||
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, cancel_tx_height + punish_timelock);
|
||||
|
||||
let tx_refund = bitcoin::TxRefund::new(tx_cancel, refund_address);
|
||||
|
||||
|
@ -267,14 +253,11 @@ pub fn build_bitcoin_punish_transaction(
|
|||
Ok(signed_tx_punish)
|
||||
}
|
||||
|
||||
pub async fn publish_bitcoin_punish_transaction<W>(
|
||||
pub async fn publish_bitcoin_punish_transaction(
|
||||
punish_tx: bitcoin::Transaction,
|
||||
bitcoin_wallet: Arc<W>,
|
||||
bitcoin_wallet: Arc<bitcoin::Wallet>,
|
||||
execution_params: ExecutionParams,
|
||||
) -> Result<bitcoin::Txid>
|
||||
where
|
||||
W: BroadcastSignedTransaction + WaitForTransactionFinality,
|
||||
{
|
||||
) -> Result<bitcoin::Txid> {
|
||||
let txid = bitcoin_wallet
|
||||
.broadcast_signed_transaction(punish_tx)
|
||||
.await?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue