diff --git a/taptrade-cli-demo/trader/src/trading/maker_utils.rs b/taptrade-cli-demo/trader/src/trading/maker_utils.rs index 132b93f..cbb6e11 100644 --- a/taptrade-cli-demo/trader/src/trading/maker_utils.rs +++ b/taptrade-cli-demo/trader/src/trading/maker_utils.rs @@ -29,16 +29,11 @@ impl ActiveOffer { // polling until offer is taken, in production a more efficient way would make sense // returns the PSBT of the escrow trade transaction we have to validate, sign and return - pub fn wait_until_taken( - &self, - trader_config: &TraderSettings, - ) -> Result { + pub fn wait_until_taken(&self, trader_config: &TraderSettings) -> Result { loop { thread::sleep(Duration::from_secs(10)); if let Some(offer_taken_response) = OfferTakenResponse::check(self, trader_config)? { - let psbt_bytes = hex::decode(offer_taken_response.trade_psbt_hex_to_sign)?; - let psbt = PartiallySignedTransaction::deserialize(&psbt_bytes)?; - return Ok(psbt); + return Ok(offer_taken_response); } } } diff --git a/taptrade-cli-demo/trader/src/trading/mod.rs b/taptrade-cli-demo/trader/src/trading/mod.rs index 3345e4f..203717f 100644 --- a/taptrade-cli-demo/trader/src/trading/mod.rs +++ b/taptrade-cli-demo/trader/src/trading/mod.rs @@ -30,10 +30,10 @@ pub fn run_maker(maker_config: &TraderSettings) -> Result<()> { let offer = ActiveOffer::create(&wallet, maker_config)?; info!("Maker offer created: {:#?}", &offer); - let mut escrow_contract_psbt = offer.wait_until_taken(maker_config)?; - wallet - .validate_maker_psbt(&escrow_contract_psbt)? - .sign_escrow_psbt(&mut escrow_contract_psbt)?; + let escrow_psbt_requirements = offer.wait_until_taken(maker_config)?; + let escrow_psbt = wallet.get_escrow_psbt(escrow_psbt_requirements, maker_config); + // .validate_maker_psbt(&escrow_contract_psbt)? + // .sign_escrow_psbt(&mut escrow_contract_psbt)?; // submit signed escrow psbt back to coordinator PsbtSubmissionRequest::submit_escrow_psbt( diff --git a/taptrade-cli-demo/trader/src/wallet/mod.rs b/taptrade-cli-demo/trader/src/wallet/mod.rs index 22c6983..87d7e0c 100644 --- a/taptrade-cli-demo/trader/src/wallet/mod.rs +++ b/taptrade-cli-demo/trader/src/wallet/mod.rs @@ -3,7 +3,10 @@ pub mod musig2; pub mod wallet_utils; use super::*; -use crate::{cli::TraderSettings, communication::api::BondRequirementResponse}; +use crate::{ + cli::TraderSettings, + communication::api::{BondRequirementResponse, OfferTakenResponse}, +}; use anyhow::{anyhow, Result}; use bdk::{ bitcoin::{ @@ -85,6 +88,18 @@ impl TradingWallet { Ok((bond, musig_data, payout_address)) } + pub async fn get_escrow_psbt( + &self, + escrow_psbt_requirements: OfferTakenResponse, + trader_config: &TraderSettings, + ) -> Result { + let fee_address = escrow_psbt_requirements.escrow_tx_fee_address; + let output_descriptor = escrow_psbt_requirements.escrow_output_descriptor; + + self.wallet.sync(&self.backend, SyncOptions::default())?; + Ok(()) + } + // validate that the taker psbt references the correct inputs and amounts // taker input should be the same as in the previous bond transaction. // input amount should be the bond amount when buying, @@ -94,19 +109,19 @@ impl TradingWallet { Ok(self) } - pub fn sign_escrow_psbt(&self, escrow_psbt: &mut PartiallySignedTransaction) -> Result<&Self> { - let finalized = self.wallet.sign(escrow_psbt, SignOptions::default())?; - if !finalized { - return Err(anyhow!("Signing of taker escrow psbt failed!")); - } - Ok(self) - } + // pub fn sign_escrow_psbt(&self, escrow_psbt: &mut PartiallySignedTransaction) -> Result<&Self> { + // let finalized = self.wallet.sign(escrow_psbt, SignOptions::default())?; + // if !finalized { + // return Err(anyhow!("Signing of taker escrow psbt failed!")); + // } + // Ok(self) + // } // validate amounts, escrow output - pub fn validate_maker_psbt(&self, psbt: &PartiallySignedTransaction) -> Result<&Self> { - error!("IMPLEMENT MAKER PSBT VALIDATION!"); - // tbd once the trade psbt is implemented on coordinator side + // pub fn validate_maker_psbt(&self, psbt: &PartiallySignedTransaction) -> Result<&Self> { + // error!("IMPLEMENT MAKER PSBT VALIDATION!"); + // // tbd once the trade psbt is implemented on coordinator side - Ok(self) - } + // Ok(self) + // } }