fix some feedback

This commit is contained in:
Roei Erez
2024-06-22 10:46:14 +03:00
parent 7e022ff930
commit fff8f5bdaa
6 changed files with 48 additions and 29 deletions

View File

@@ -39,7 +39,7 @@ url = "2.5.0"
futures-util = { version = "0.3.28", default-features = false, features = ["sink", "std"] }
async-trait = "0.1.80"
hex = "0.4"
reqwest = { version = "=0.11.20", features = ["json", "blocking"] }
reqwest = { version = "=0.11.20", features = ["json"] }
electrum-client = { version = "0.19.0" }
[dev-dependencies]

View File

@@ -36,8 +36,6 @@ struct EsploraTx {
status: Status,
}
// TODO some of this fields may be Option in unconfirmed
#[derive(Deserialize)]
struct Status {
block_height: Option<i32>,
@@ -64,7 +62,7 @@ impl LiquidChainService for HybridLiquidChainService {
async fn broadcast(&self, tx: &Transaction, swap_id: Option<&str>) -> Result<Txid> {
let tx_bytes = tx.serialize();
info!("tx: {}", tx_bytes.to_hex());
info!("Broadcasting Liquid tx: {}", tx_bytes.to_hex());
let client = reqwest::Client::new();
let response = client
.post(format!("{LIQUID_ESPLORA_URL}/tx"))

View File

@@ -18,7 +18,7 @@ use crate::receive_swap::{
};
use crate::utils;
pub const LOWBALL_FEE_RATE: f32 = 0.01;
pub const LOWBALL_FEE_RATE_SAT_PER_VBYTE: f32 = 0.01;
/// Configuration for the Liquid SDK
#[derive(Clone, Debug, Serialize)]

View File

@@ -98,7 +98,10 @@ impl ReceiveSwapStateHandler {
}
// looking for lockup script history to verify lockup was broadcasted
if let Err(e) = self.verify_lockup_tx(&receive_swap, &transaction).await {
if let Err(e) = self
.verify_lockup_tx(&receive_swap, &transaction, false)
.await
{
return Err(anyhow!(
"swapper mempool reported lockup could not be verified. txid: {}, err: {}",
transaction.id,
@@ -164,7 +167,10 @@ impl ReceiveSwapStateHandler {
return Err(anyhow!("Unexpected payload from Boltz status stream"));
};
// looking for lockup script history to verify lockup was broadcasted
if let Err(e) = self.verify_lockup_tx(&receive_swap, &transaction).await {
if let Err(e) = self
.verify_lockup_tx(&receive_swap, &transaction, true)
.await
{
return Err(anyhow!(
"swapper reported lockup could not be verified. txid: {}, err: {}",
transaction.id,
@@ -306,6 +312,7 @@ impl ReceiveSwapStateHandler {
&self,
receive_swap: &ReceiveSwap,
swap_update_tx: &SwapUpdateTxDetails,
verify_confirmation: bool,
) -> Result<()> {
// looking for lockup script history to verify lockup was broadcasted
let script_history = self.lockup_script_history(receive_swap).await?;
@@ -313,28 +320,38 @@ impl ReceiveSwapStateHandler {
.iter()
.find(|h| h.txid.to_hex().eq(&swap_update_tx.id));
if lockup_tx_history.is_none() {
return Err(anyhow!(
"swapper lockup wasn't found, reported txid={} waiting for confirmation",
swap_update_tx.id,
));
}
match lockup_tx_history {
Some(history) => {
info!("swapper lockup found, verifying transaction content...");
info!("swapper lockup found, verifying transaction content...");
let lockup_tx = utils::deserialize_tx_hex(&swap_update_tx.hex)?;
if !lockup_tx
.txid()
.to_hex()
.eq(&lockup_tx_history.unwrap().txid.to_hex())
{
return Err(anyhow!(
"swapper reported txid and transaction hex do not match: {} vs {}",
swap_update_tx.id,
lockup_tx.txid().to_hex()
));
}
let lockup_tx = utils::deserialize_tx_hex(&swap_update_tx.hex)?;
if !lockup_tx
.txid()
.to_hex()
.eq(&lockup_tx_history.unwrap().txid.to_hex())
{
return Err(anyhow!(
"swapper reported txid and transaction hex do not match: {} vs {}",
swap_update_tx.id,
lockup_tx.txid().to_hex()
));
if verify_confirmation && history.height <= 0 {
return Err(anyhow!(
"swapper reported lockup was not confirmed, txid={} waiting for confirmation",
swap_update_tx.id,
));
}
Ok(())
}
None => {
return Err(anyhow!(
"swapper reported lockup wasn't found, txid={} waiting for confirmation",
swap_update_tx.id,
));
}
}
Ok(())
}
async fn lockup_script_history(&self, receive_swap: &ReceiveSwap) -> Result<Vec<History>> {

View File

@@ -565,7 +565,11 @@ impl LiquidSdk {
async fn estimate_onchain_tx_fee(&self, amount_sat: u64, address: &str) -> Result<u64> {
Ok(self
.onchain_wallet
.build_tx(Some(LOWBALL_FEE_RATE * 1000.0), address, amount_sat)
.build_tx(
Some(LOWBALL_FEE_RATE_SAT_PER_VBYTE * 1000.0),
address,
amount_sat,
)
.await?
.all_fees()
.values()

View File

@@ -13,7 +13,7 @@ use tokio::sync::{broadcast, Mutex};
use crate::chain::liquid::LiquidChainService;
use crate::model::PaymentState::{Complete, Created, Failed, Pending, TimedOut};
use crate::model::{Config, SendSwap, LOWBALL_FEE_RATE};
use crate::model::{Config, SendSwap, LOWBALL_FEE_RATE_SAT_PER_VBYTE};
use crate::swapper::Swapper;
use crate::wallet::OnchainWallet;
use crate::{ensure_sdk, get_invoice_amount};
@@ -196,7 +196,7 @@ impl SendSwapStateHandler {
let lockup_tx = self
.onchain_wallet
.build_tx(
Some(LOWBALL_FEE_RATE * 1000.0),
Some(LOWBALL_FEE_RATE_SAT_PER_VBYTE * 1000.0),
&create_response.address,
create_response.expected_amount,
)