mirror of
https://github.com/RoboSats/taptrade-core.git
synced 2025-07-23 19:23:18 +00:00
add psbt submission for maker
This commit is contained in:
@ -127,3 +127,32 @@ impl OfferTakenResponse {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl PsbtSubmissionRequest {
|
||||||
|
pub fn submit_escrow_psbt(
|
||||||
|
psbt: &PartiallySignedTransaction,
|
||||||
|
offer_id_hex: String,
|
||||||
|
taker_config: &TraderSettings,
|
||||||
|
) -> Result<()> {
|
||||||
|
let request = PsbtSubmissionRequest {
|
||||||
|
signed_psbt_hex: psbt.serialize_hex(),
|
||||||
|
offer_id_hex,
|
||||||
|
robohash_hex: taker_config.robosats_robohash_hex.clone(),
|
||||||
|
};
|
||||||
|
let client = reqwest::blocking::Client::new();
|
||||||
|
let res = client
|
||||||
|
.post(format!(
|
||||||
|
"{}{}",
|
||||||
|
taker_config.coordinator_endpoint, "/submit-escrow-psbt"
|
||||||
|
))
|
||||||
|
.json(&request)
|
||||||
|
.send()?;
|
||||||
|
if res.status() != 200 {
|
||||||
|
return Err(anyhow!(
|
||||||
|
"Submitting escrow psbt failed. Status: {}",
|
||||||
|
res.status()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -84,35 +84,6 @@ impl OfferPsbtRequest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl PsbtSubmissionRequest {
|
|
||||||
pub fn submit_taker_psbt(
|
|
||||||
psbt: &PartiallySignedTransaction,
|
|
||||||
offer_id_hex: String,
|
|
||||||
taker_config: &TraderSettings,
|
|
||||||
) -> Result<()> {
|
|
||||||
let request = PsbtSubmissionRequest {
|
|
||||||
signed_psbt_hex: psbt.serialize_hex(),
|
|
||||||
offer_id_hex,
|
|
||||||
robohash_hex: taker_config.robosats_robohash_hex.clone(),
|
|
||||||
};
|
|
||||||
let client = reqwest::blocking::Client::new();
|
|
||||||
let res = client
|
|
||||||
.post(format!(
|
|
||||||
"{}{}",
|
|
||||||
taker_config.coordinator_endpoint, "/submit-taker-psbt"
|
|
||||||
))
|
|
||||||
.json(&request)
|
|
||||||
.send()?;
|
|
||||||
if res.status() != 200 {
|
|
||||||
return Err(anyhow!(
|
|
||||||
"Submitting taker psbt failed. Status: {}",
|
|
||||||
res.status()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl IsOfferReadyRequest {
|
impl IsOfferReadyRequest {
|
||||||
pub fn poll(taker_config: &TraderSettings, offer: &ActiveOffer) -> Result<()> {
|
pub fn poll(taker_config: &TraderSettings, offer: &ActiveOffer) -> Result<()> {
|
||||||
let request = IsOfferReadyRequest {
|
let request = IsOfferReadyRequest {
|
||||||
|
@ -34,6 +34,14 @@ pub fn run_maker(maker_config: &TraderSettings) -> Result<()> {
|
|||||||
.validate_maker_psbt(&escrow_contract_psbt)?
|
.validate_maker_psbt(&escrow_contract_psbt)?
|
||||||
.sign_escrow_psbt(&mut escrow_contract_psbt)?;
|
.sign_escrow_psbt(&mut escrow_contract_psbt)?;
|
||||||
|
|
||||||
|
// submit signed escrow psbt back to coordinator
|
||||||
|
PsbtSubmissionRequest::submit_escrow_psbt(
|
||||||
|
&escrow_contract_psbt,
|
||||||
|
offer.offer_id_hex.clone(),
|
||||||
|
taker_config,
|
||||||
|
)?;
|
||||||
|
// wait for confirmation
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ impl ActiveOffer {
|
|||||||
.sign_escrow_psbt(&mut escrow_contract_psbt)?;
|
.sign_escrow_psbt(&mut escrow_contract_psbt)?;
|
||||||
|
|
||||||
// submit signed escrow psbt back to coordinator
|
// submit signed escrow psbt back to coordinator
|
||||||
PsbtSubmissionRequest::submit_taker_psbt(
|
PsbtSubmissionRequest::submit_escrow_psbt(
|
||||||
&escrow_contract_psbt,
|
&escrow_contract_psbt,
|
||||||
offer.offer_id_hex.clone(),
|
offer.offer_id_hex.clone(),
|
||||||
taker_config,
|
taker_config,
|
||||||
|
Reference in New Issue
Block a user