From 23bbc3dfb8fecdeb6833f115a25cff1c90c36401 Mon Sep 17 00:00:00 2001 From: ngutech21 Date: Tue, 30 Jul 2024 16:09:10 +0200 Subject: [PATCH] chore: PostMeltBtcOnchainResponse.txid is optional --- integrationtests/tests/tests_lnd.rs | 4 +++- moksha-cli/src/bin/moksha-cli.rs | 8 ++++++-- moksha-core/src/primitives.rs | 2 +- moksha-mint/src/routes/btconchain.rs | 2 +- 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/integrationtests/tests/tests_lnd.rs b/integrationtests/tests/tests_lnd.rs index 25165e79..79526f9c 100644 --- a/integrationtests/tests/tests_lnd.rs +++ b/integrationtests/tests/tests_lnd.rs @@ -114,7 +114,9 @@ async fn test_btc_onchain_mint_melt() -> anyhow::Result<()> { assert!(!result.paid); btc_client.mine_blocks(1).await?; - let is_tx_paid = wallet.is_onchain_tx_paid(&mint_url, result.txid).await?; + let txid = result.txid.expect("No txid returned from mint"); + + let is_tx_paid = wallet.is_onchain_tx_paid(&mint_url, txid).await?; assert!(is_tx_paid); Ok(()) diff --git a/moksha-cli/src/bin/moksha-cli.rs b/moksha-cli/src/bin/moksha-cli.rs index 19d496c1..c814f1f2 100644 --- a/moksha-cli/src/bin/moksha-cli.rs +++ b/moksha-cli/src/bin/moksha-cli.rs @@ -296,7 +296,9 @@ async fn main() -> anyhow::Result<()> { let PostMeltBtcOnchainResponse { paid, txid } = wallet.pay_onchain(wallet_keyset, quote).await?; - term.write_line(&format!("Created transaction: {}\n", &txid))?; + if let Some(txid) = txid.clone() { + term.write_line(&format!("Created transaction: {}\n", &txid))?; + } let progress_bar = cli::progress_bar()?; progress_bar.set_message("Waiting for payment confirmation ..."); @@ -304,7 +306,9 @@ async fn main() -> anyhow::Result<()> { loop { tokio::time::sleep(std::time::Duration::from_millis(2_000)).await; - if paid || wallet.is_onchain_tx_paid(&mint_url, txid.clone()).await? { + let txid = txid.clone(); + + if paid || txid.as_ref().is_some() && wallet.is_onchain_tx_paid(&mint_url, txid.expect("invalid txid")).await? { progress_bar.finish_with_message("\nTokens melted successfully\n"); cli::show_total_balance(&wallet).await?; break; diff --git a/moksha-core/src/primitives.rs b/moksha-core/src/primitives.rs index 0fbbf860..1f9e9d4f 100644 --- a/moksha-core/src/primitives.rs +++ b/moksha-core/src/primitives.rs @@ -339,7 +339,7 @@ pub struct PostMeltBtcOnchainRequest { #[derive(Deserialize, Serialize, Debug, Clone, ToSchema)] pub struct PostMeltBtcOnchainResponse { pub paid: bool, - pub txid: String, + pub txid: Option, } impl From for PostMeltQuoteBtcOnchainResponse { diff --git a/moksha-mint/src/routes/btconchain.rs b/moksha-mint/src/routes/btconchain.rs index dbed169a..c92b17f1 100644 --- a/moksha-mint/src/routes/btconchain.rs +++ b/moksha-mint/src/routes/btconchain.rs @@ -286,7 +286,7 @@ pub async fn post_melt_btconchain( .await?; tx.commit().await?; - Ok(Json(PostMeltBtcOnchainResponse { paid, txid })) + Ok(Json(PostMeltBtcOnchainResponse { paid, txid:Some(txid) })) } #[utoipa::path(