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

@ -22,9 +22,7 @@ pub use wallet::Wallet;
use crate::execution_params::ExecutionParams; use crate::execution_params::ExecutionParams;
use ::bitcoin::{ use ::bitcoin::{
hashes::{hex::ToHex, Hash}, hashes::{hex::ToHex, Hash},
secp256k1, secp256k1, SigHash,
util::psbt::PartiallySignedTransaction,
SigHash,
}; };
use anyhow::{anyhow, bail, Result}; use anyhow::{anyhow, bail, Result};
use async_trait::async_trait; use async_trait::async_trait;
@ -203,15 +201,6 @@ pub fn build_shared_output_descriptor(A: Point, B: Point) -> Descriptor<bitcoin:
Descriptor::Wsh(Wsh::new(miniscript).expect("a valid descriptor")) Descriptor::Wsh(Wsh::new(miniscript).expect("a valid descriptor"))
} }
#[async_trait]
pub trait BuildTxLockPsbt {
async fn build_tx_lock_psbt(
&self,
output_address: Address,
output_amount: Amount,
) -> Result<PartiallySignedTransaction>;
}
#[async_trait] #[async_trait]
pub trait SignTxLock { pub trait SignTxLock {
async fn sign_tx_lock(&self, tx_lock: TxLock) -> Result<Transaction>; async fn sign_tx_lock(&self, tx_lock: TxLock) -> Result<Transaction>;
@ -251,11 +240,6 @@ pub trait GetRawTransaction {
async fn get_raw_transaction(&self, txid: Txid) -> Result<Transaction>; async fn get_raw_transaction(&self, txid: Txid) -> Result<Transaction>;
} }
#[async_trait]
pub trait GetNetwork {
async fn get_network(&self) -> Network;
}
pub fn recover(S: PublicKey, sig: Signature, encsig: EncryptedSignature) -> Result<SecretKey> { pub fn recover(S: PublicKey, sig: Signature, encsig: EncryptedSignature) -> Result<SecretKey> {
let adaptor = Adaptor::<HashTranscript<Sha256>, Deterministic<Sha256>>::default(); let adaptor = Adaptor::<HashTranscript<Sha256>, Deterministic<Sha256>>::default();

View File

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

View File

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

View File

@ -1,9 +1,8 @@
use crate::{ use crate::{
bitcoin::{ bitcoin::{
self, current_epoch, wait_for_cancel_timelock_to_expire, BroadcastSignedTransaction, self, current_epoch, wait_for_cancel_timelock_to_expire, BroadcastSignedTransaction,
BuildTxLockPsbt, CancelTimelock, ExpiredTimelocks, GetBlockHeight, GetNetwork, CancelTimelock, ExpiredTimelocks, GetBlockHeight, GetRawTransaction, PunishTimelock,
GetRawTransaction, PunishTimelock, Transaction, TransactionBlockHeight, TxCancel, Txid, Transaction, TransactionBlockHeight, TxCancel, Txid, WatchForRawTransaction,
WatchForRawTransaction,
}, },
execution_params::ExecutionParams, execution_params::ExecutionParams,
monero, monero,
@ -140,10 +139,7 @@ impl State0 {
} }
} }
pub async fn receive<W>(self, wallet: &W, msg: Message1) -> Result<State1> pub async fn receive(self, wallet: &bitcoin::Wallet, msg: Message1) -> Result<State1> {
where
W: BuildTxLockPsbt + GetNetwork,
{
let valid = CROSS_CURVE_PROOF_SYSTEM.verify( let valid = CROSS_CURVE_PROOF_SYSTEM.verify(
&msg.dleq_proof_s_a, &msg.dleq_proof_s_a,
( (