mirror of
https://github.com/comit-network/xmr-btc-swap.git
synced 2024-10-31 15:20:15 +00:00
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:
parent
6c38d66864
commit
67fe01a2ef
@ -22,9 +22,7 @@ pub use wallet::Wallet;
|
||||
use crate::execution_params::ExecutionParams;
|
||||
use ::bitcoin::{
|
||||
hashes::{hex::ToHex, Hash},
|
||||
secp256k1,
|
||||
util::psbt::PartiallySignedTransaction,
|
||||
SigHash,
|
||||
secp256k1, SigHash,
|
||||
};
|
||||
use anyhow::{anyhow, bail, Result};
|
||||
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"))
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait BuildTxLockPsbt {
|
||||
async fn build_tx_lock_psbt(
|
||||
&self,
|
||||
output_address: Address,
|
||||
output_amount: Amount,
|
||||
) -> Result<PartiallySignedTransaction>;
|
||||
}
|
||||
|
||||
#[async_trait]
|
||||
pub trait SignTxLock {
|
||||
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_trait]
|
||||
pub trait GetNetwork {
|
||||
async fn get_network(&self) -> Network;
|
||||
}
|
||||
|
||||
pub fn recover(S: PublicKey, sig: Signature, encsig: EncryptedSignature) -> Result<SecretKey> {
|
||||
let adaptor = Adaptor::<HashTranscript<Sha256>, Deterministic<Sha256>>::default();
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -1,9 +1,8 @@
|
||||
use crate::{
|
||||
bitcoin::{
|
||||
self, current_epoch, wait_for_cancel_timelock_to_expire, BroadcastSignedTransaction,
|
||||
BuildTxLockPsbt, CancelTimelock, ExpiredTimelocks, GetBlockHeight, GetNetwork,
|
||||
GetRawTransaction, PunishTimelock, Transaction, TransactionBlockHeight, TxCancel, Txid,
|
||||
WatchForRawTransaction,
|
||||
CancelTimelock, ExpiredTimelocks, GetBlockHeight, GetRawTransaction, PunishTimelock,
|
||||
Transaction, TransactionBlockHeight, TxCancel, Txid, WatchForRawTransaction,
|
||||
},
|
||||
execution_params::ExecutionParams,
|
||||
monero,
|
||||
@ -140,10 +139,7 @@ impl State0 {
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn receive<W>(self, wallet: &W, msg: Message1) -> Result<State1>
|
||||
where
|
||||
W: BuildTxLockPsbt + GetNetwork,
|
||||
{
|
||||
pub async fn receive(self, wallet: &bitcoin::Wallet, msg: Message1) -> Result<State1> {
|
||||
let valid = CROSS_CURVE_PROOF_SYSTEM.verify(
|
||||
&msg.dleq_proof_s_a,
|
||||
(
|
||||
|
Loading…
Reference in New Issue
Block a user