Skip to content

Commit

Permalink
chore: PostMeltBtcOnchainResponse.txid is optional
Browse files Browse the repository at this point in the history
  • Loading branch information
ngutech21 committed Jul 30, 2024
1 parent 68c4761 commit 23bbc3d
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 5 deletions.
4 changes: 3 additions & 1 deletion integrationtests/tests/tests_lnd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down
8 changes: 6 additions & 2 deletions moksha-cli/src/bin/moksha-cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -296,15 +296,19 @@ 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 ...");

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;
Expand Down
2 changes: 1 addition & 1 deletion moksha-core/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,
}

impl From<BtcOnchainMeltQuote> for PostMeltQuoteBtcOnchainResponse {
Expand Down
2 changes: 1 addition & 1 deletion moksha-mint/src/routes/btconchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 23bbc3d

Please sign in to comment.