Remove BuildTxLockPsbt and GetNetwork traits

These traits were only used once within the `TxLock` constructor.
Looking at the rest of the codebase, we don't really seem to follow
any abstractions here where the protocol shouldn't know about the
exact types that is being passed in.

As such, these types are just noise and might as well be removed in
favor of simplicity.
This commit is contained in:
Thomas Eizinger 2021-02-26 10:14:43 +11:00
parent 6c38d66864
commit 67fe01a2ef
No known key found for this signature in database
GPG key ID: 651AC83A6C6C8B96
4 changed files with 14 additions and 44 deletions

View file

@ -1,6 +1,5 @@
use crate::bitcoin::{
build_shared_output_descriptor, Address, Amount, BuildTxLockPsbt, GetNetwork, PublicKey,
Transaction, TX_FEE,
build_shared_output_descriptor, Address, Amount, PublicKey, Transaction, Wallet, TX_FEE,
};
use ::bitcoin::{util::psbt::PartiallySignedTransaction, OutPoint, TxIn, TxOut, Txid};
use anyhow::Result;
@ -14,10 +13,7 @@ pub struct TxLock {
}
impl TxLock {
pub async fn new<W>(wallet: &W, amount: Amount, A: PublicKey, B: PublicKey) -> Result<Self>
where
W: BuildTxLockPsbt + GetNetwork,
{
pub async fn new(wallet: &Wallet, amount: Amount, A: PublicKey, B: PublicKey) -> Result<Self> {
let lock_output_descriptor = build_shared_output_descriptor(A.0, B.0);
let address = lock_output_descriptor
.address(wallet.get_network().await)

View file

@ -1,8 +1,8 @@
use crate::{
bitcoin::{
timelocks::BlockHeight, Address, Amount, BroadcastSignedTransaction, BuildTxLockPsbt,
GetBlockHeight, GetNetwork, GetRawTransaction, SignTxLock, Transaction,
TransactionBlockHeight, TxLock, WaitForTransactionFinality, WatchForRawTransaction,
timelocks::BlockHeight, Address, Amount, BroadcastSignedTransaction, GetBlockHeight,
GetRawTransaction, SignTxLock, Transaction, TransactionBlockHeight, TxLock,
WaitForTransactionFinality, WatchForRawTransaction,
},
execution_params::ExecutionParams,
};
@ -110,11 +110,8 @@ impl Wallet {
self.inner.lock().await.sync(noop_progress(), None)?;
Ok(())
}
}
#[async_trait]
impl BuildTxLockPsbt for Wallet {
async fn build_tx_lock_psbt(
pub async fn build_tx_lock_psbt(
&self,
output_address: Address,
output_amount: Amount,
@ -129,6 +126,10 @@ impl BuildTxLockPsbt for Wallet {
tracing::debug!("tx lock built");
Ok(psbt)
}
pub async fn get_network(&self) -> bitcoin::Network {
self.inner.lock().await.network()
}
}
#[async_trait]
@ -283,13 +284,6 @@ impl WaitForTransactionFinality for Wallet {
}
}
#[async_trait]
impl GetNetwork for Wallet {
async fn get_network(&self) -> bitcoin::Network {
self.inner.lock().await.network()
}
}
fn tx_status_url(txid: Txid, base_url: &Url) -> Result<Url> {
let url = base_url.join(&format!("tx/{}/status", txid))?;
Ok(url)