mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-08-11 12:30:01 +00:00
add taker wait on fiat confirmation
This commit is contained in:
@ -85,3 +85,11 @@ pub struct PsbtSubmissionRequest {
|
|||||||
pub offer_id_hex: String,
|
pub offer_id_hex: String,
|
||||||
pub robohash_hex: String,
|
pub robohash_hex: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// request polled to check if the maker has submitted his escrow transaction
|
||||||
|
// and the escrow transaction is confirmed once this returns 200 the chat can open
|
||||||
|
#[derive(Debug, Serialize)]
|
||||||
|
pub struct IsOfferReadyRequest {
|
||||||
|
pub robohash_hex: String,
|
||||||
|
pub offer_id_hex: String,
|
||||||
|
}
|
||||||
|
@ -17,6 +17,7 @@ use bdk::{
|
|||||||
wallet::AddressInfo,
|
wallet::AddressInfo,
|
||||||
};
|
};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::{thread::sleep, time::Duration};
|
||||||
|
|
||||||
impl BondRequirementResponse {
|
impl BondRequirementResponse {
|
||||||
fn _format_request(trader_setup: &TraderSettings) -> OrderRequest {
|
fn _format_request(trader_setup: &TraderSettings) -> OrderRequest {
|
||||||
@ -107,7 +108,7 @@ impl OfferTakenResponse {
|
|||||||
let request = OfferTakenRequest {
|
let request = OfferTakenRequest {
|
||||||
// maybe can be made a bit more efficient (less clone)
|
// maybe can be made a bit more efficient (less clone)
|
||||||
robohash_hex: trader_setup.robosats_robohash_hex.clone(),
|
robohash_hex: trader_setup.robosats_robohash_hex.clone(),
|
||||||
order_id_hex: offer.order_id_hex.clone(),
|
order_id_hex: offer.offer_id_hex.clone(),
|
||||||
};
|
};
|
||||||
let client = reqwest::blocking::Client::new();
|
let client = reqwest::blocking::Client::new();
|
||||||
let res = client
|
let res = client
|
||||||
|
@ -112,3 +112,32 @@ impl PsbtSubmissionRequest {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl IsOfferReadyRequest {
|
||||||
|
pub fn poll(taker_config: &TraderSettings, offer: &ActiveOffer) -> Result<()> {
|
||||||
|
let request = IsOfferReadyRequest {
|
||||||
|
robohash_hex: taker_config.robosats_robohash_hex.clone(),
|
||||||
|
offer_id_hex: offer.offer_id_hex.clone(),
|
||||||
|
};
|
||||||
|
let client = reqwest::blocking::Client::new();
|
||||||
|
loop {
|
||||||
|
let res = client
|
||||||
|
.post(format!(
|
||||||
|
"{}{}",
|
||||||
|
taker_config.coordinator_endpoint, "/poll-offer-status-taker"
|
||||||
|
))
|
||||||
|
.json(&request)
|
||||||
|
.send()?;
|
||||||
|
if res.status() == 200 {
|
||||||
|
return Ok(());
|
||||||
|
} else if res.status() != 201 {
|
||||||
|
return Err(anyhow!(
|
||||||
|
"Submitting taker psbt failed. Status: {}",
|
||||||
|
res.status()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
// Sleep for 10 sec and poll again
|
||||||
|
sleep(Duration::from_secs(10));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -24,11 +24,11 @@ impl ActiveOffer {
|
|||||||
maker_config,
|
maker_config,
|
||||||
)?;
|
)?;
|
||||||
Ok(ActiveOffer {
|
Ok(ActiveOffer {
|
||||||
order_id_hex: submission_result.order_id_hex,
|
offer_id_hex: submission_result.order_id_hex,
|
||||||
bond_locked_until_timestamp: submission_result.bond_locked_until_timestamp,
|
|
||||||
used_musig_config: musig_data,
|
used_musig_config: musig_data,
|
||||||
used_bond: bond,
|
used_bond: bond,
|
||||||
expected_payout_address: payout_address,
|
expected_payout_address: payout_address,
|
||||||
|
escrow_psbt: None,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,8 +43,12 @@ pub fn run_taker(taker_config: &TraderSettings) -> Result<()> {
|
|||||||
available_offers = PublicOffers::fetch(taker_config)?;
|
available_offers = PublicOffers::fetch(taker_config)?;
|
||||||
}
|
}
|
||||||
let selected_offer: &PublicOffer = available_offers.ask_user_to_select()?;
|
let selected_offer: &PublicOffer = available_offers.ask_user_to_select()?;
|
||||||
|
|
||||||
|
// take selected offer and wait for maker to sign his input to the ecrow transaction
|
||||||
let accepted_offer =
|
let accepted_offer =
|
||||||
ActiveOffer::take(&wallet, taker_config, selected_offer)?.wait_on_maker()?;
|
ActiveOffer::take(&wallet, taker_config, selected_offer)?.wait_on_maker(taker_config)?;
|
||||||
|
|
||||||
|
accepted_offer.wait_on_fiat_confirmation()?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
use bdk::electrum_client::Request;
|
use bdk::electrum_client::Request;
|
||||||
|
|
||||||
use crate::communication::api::{OfferPsbtRequest, PsbtSubmissionRequest};
|
use crate::communication::api::{IsOfferReadyRequest, OfferPsbtRequest, PsbtSubmissionRequest};
|
||||||
|
|
||||||
use super::utils::*;
|
use super::utils::*;
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -42,16 +42,29 @@ impl ActiveOffer {
|
|||||||
)?;
|
)?;
|
||||||
|
|
||||||
Ok(ActiveOffer {
|
Ok(ActiveOffer {
|
||||||
order_id_hex: offer.offer_id_hex.clone(),
|
offer_id_hex: offer.offer_id_hex.clone(),
|
||||||
used_musig_config: musig_data,
|
used_musig_config: musig_data,
|
||||||
used_bond: bond,
|
used_bond: bond,
|
||||||
expected_payout_address: payout_address,
|
expected_payout_address: payout_address,
|
||||||
escrow_psbt: escrow_contract_psbt,
|
escrow_psbt: Some(escrow_contract_psbt),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wait_on_maker(self) -> Result<Self> {
|
pub fn wait_on_maker(self, taker_config: &TraderSettings) -> Result<Self> {
|
||||||
// tbd
|
IsOfferReadyRequest::poll(taker_config, &self)?;
|
||||||
|
Ok(self)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn wait_on_fiat_confirmation(&self) -> Result<&Self> {
|
||||||
|
// let user confirm in CLI that the fiat payment has been sent/receivec
|
||||||
|
loop {
|
||||||
|
println!("Please confirm that the fiat payment has been sent/received. (y/N)");
|
||||||
|
let mut input = String::new();
|
||||||
|
std::io::stdin().read_line(&mut input)?;
|
||||||
|
if input.trim().to_lowercase() == "y" {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(self)
|
Ok(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,9 @@ use super::*;
|
|||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct ActiveOffer {
|
pub struct ActiveOffer {
|
||||||
pub order_id_hex: String,
|
pub offer_id_hex: String,
|
||||||
pub used_musig_config: MuSigData,
|
pub used_musig_config: MuSigData,
|
||||||
pub used_bond: PartiallySignedTransaction,
|
pub used_bond: PartiallySignedTransaction,
|
||||||
pub expected_payout_address: AddressInfo,
|
pub expected_payout_address: AddressInfo,
|
||||||
pub escrow_psbt: PartiallySignedTransaction,
|
pub escrow_psbt: Option<PartiallySignedTransaction>,
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user