From 8c832aa44a752bb752cfcb2bda6b70adfd744b1a Mon Sep 17 00:00:00 2001 From: ok300 <106775972+ok300@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:27:18 +0100 Subject: [PATCH] Add support for getting and accepting quotes --- src/swaps/boltz.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/src/swaps/boltz.rs b/src/swaps/boltz.rs index 3c4302d..5eec37b 100644 --- a/src/swaps/boltz.rs +++ b/src/swaps/boltz.rs @@ -17,10 +17,10 @@ //! output_amount - base_fees - claim_fee //! ); -use bitcoin::key; use bitcoin::{ hashes::sha256, hex::DisplayHex, taproot::TapLeaf, PublicKey, ScriptBuf, Transaction, }; +use bitcoin::{key, Amount}; use lightning_invoice::Bolt11Invoice; use serde::{Deserialize, Serialize}; use serde_json::Value; @@ -564,6 +564,28 @@ impl BoltzApiClientV2 { let end_point = format!("chain/{}/transaction", chain); Ok(serde_json::from_str(&self.post(&end_point, data)?)?) } + + /// Looks up the quote for a Zero-Amount Receive Chain Swap. + /// + /// If the user locked up a valid amount, it will return the server lockup amount. In all other + /// cases, it will return an error. + pub fn get_quote(&self, swap_id: &str) -> Result { + let end_point = format!("swap/chain/{swap_id}/quote"); + Ok(serde_json::from_str(&self.get(&end_point)?)?) + } + + /// Accepts a specific quote for a Zero-Amount Receive Chain Swap. + pub fn accept_quote(&self, swap_id: &str, amount_sat: u64) -> Result<(), Error> { + let data = json!( + { + "amount": amount_sat + } + ); + + let end_point = format!("swap/chain/{swap_id}/quote"); + self.post(&end_point, data)?; + Ok(()) + } } #[derive(Debug, Clone, Serialize, Deserialize)] @@ -1284,6 +1306,13 @@ pub struct GetFeeEstimationResponse { pub lbtc: f64, } +#[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(rename_all = "camelCase")] +pub struct GetQuoteResponse { + /// Server lockup amount, in sat + pub amount: u64, +} + #[cfg(test)] mod tests { use super::*;