diff --git a/integrationtests/src/lnd_client.rs b/integrationtests/src/lnd_client.rs index ed076ab3..78ebdb94 100644 --- a/integrationtests/src/lnd_client.rs +++ b/integrationtests/src/lnd_client.rs @@ -111,6 +111,21 @@ impl LndClient { Ok(amount_in_sat as u64) } + pub async fn is_transaction_paid(&self, txid: &str) -> anyhow::Result { + let request = ListUnspentRequest { + min_confs: 0, + max_confs: i32::MAX, + ..Default::default() + }; + + let response = self.wallet_lock().await?.list_unspent(request).await?; + + Ok(response.get_ref().utxos.iter().any(|utxo| { + utxo.outpoint.clone().expect("No outpoint found").txid_str == txid + && utxo.confirmations > 0 + })) + } + pub async fn connect_to_peer(&self, peer_pubkey: &str, host_port: &str) -> anyhow::Result<()> { self.wait_for_node_sync().await?; let mut client = self.client_lock().await?; diff --git a/integrationtests/tests/tests_lnd.rs b/integrationtests/tests/tests_lnd.rs index 79526f9c..cf072abe 100644 --- a/integrationtests/tests/tests_lnd.rs +++ b/integrationtests/tests/tests_lnd.rs @@ -116,7 +116,9 @@ async fn test_btc_onchain_mint_melt() -> anyhow::Result<()> { let txid = result.txid.expect("No txid returned from mint"); - let is_tx_paid = wallet.is_onchain_tx_paid(&mint_url, txid).await?; + let lnd_client = LndClient::new_mint_lnd().await?; + + let is_tx_paid = lnd_client.is_transaction_paid(&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 c814f1f2..b81ba887 100644 --- a/moksha-cli/src/bin/moksha-cli.rs +++ b/moksha-cli/src/bin/moksha-cli.rs @@ -306,9 +306,11 @@ async fn main() -> anyhow::Result<()> { loop { tokio::time::sleep(std::time::Duration::from_millis(2_000)).await; - let txid = txid.clone(); - - if paid || txid.as_ref().is_some() && wallet.is_onchain_tx_paid(&mint_url, txid.expect("invalid txid")).await? { + if paid + || wallet + .is_onchain_paid(&mint_url, quote.quote.clone()) + .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 1f9e9d4f..f4cb0ee1 100644 --- a/moksha-core/src/primitives.rs +++ b/moksha-core/src/primitives.rs @@ -355,11 +355,6 @@ impl From for PostMeltQuoteBtcOnchainResponse { } } -#[derive(Deserialize, Serialize, Debug, Clone, ToSchema)] -pub struct GetMeltBtcOnchainResponse { - pub paid: bool, -} - #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ToSchema)] pub struct Nuts { /// Minting tokens diff --git a/moksha-mint/src/routes/btconchain.rs b/moksha-mint/src/routes/btconchain.rs index c92b17f1..68fb599d 100644 --- a/moksha-mint/src/routes/btconchain.rs +++ b/moksha-mint/src/routes/btconchain.rs @@ -3,10 +3,10 @@ use axum::{ Json, }; use moksha_core::primitives::{ - BtcOnchainMeltQuote, BtcOnchainMintQuote, CurrencyUnit, GetMeltBtcOnchainResponse, - PaymentMethod, PostMeltBtcOnchainRequest, PostMeltBtcOnchainResponse, - PostMeltQuoteBtcOnchainRequest, PostMeltQuoteBtcOnchainResponse, PostMintBtcOnchainRequest, - PostMintBtcOnchainResponse, PostMintQuoteBtcOnchainRequest, PostMintQuoteBtcOnchainResponse, + BtcOnchainMeltQuote, BtcOnchainMintQuote, CurrencyUnit, PaymentMethod, + PostMeltBtcOnchainRequest, PostMeltBtcOnchainResponse, PostMeltQuoteBtcOnchainRequest, + PostMeltQuoteBtcOnchainResponse, PostMintBtcOnchainRequest, PostMintBtcOnchainResponse, + PostMintQuoteBtcOnchainRequest, PostMintQuoteBtcOnchainResponse, }; use tracing::{info, instrument}; use uuid::Uuid; @@ -286,33 +286,10 @@ pub async fn post_melt_btconchain( .await?; tx.commit().await?; - Ok(Json(PostMeltBtcOnchainResponse { paid, txid:Some(txid) })) -} - -#[utoipa::path( - get, - path = "/v1/melt/btconchain/{tx_id}", - responses( - (status = 200, description = "is transaction paid", body = [GetMeltOnchainResponse]) - ), - params( - ("tx_id" = String, Path, description = "Bitcoin onchain transaction-id"), - ) - )] -#[instrument(name = "get_melt_btconchain", skip(mint), err)] -pub async fn get_melt_btconchain( - Path(tx_id): Path, - State(mint): State, -) -> Result, MokshaMintError> { - info!("is transaction paid: {}", tx_id); - let paid = mint - .onchain - .as_ref() - .expect("onchain not set") - .is_transaction_paid(&tx_id) - .await?; - - Ok(Json(GetMeltBtcOnchainResponse { paid })) + Ok(Json(PostMeltBtcOnchainResponse { + paid, + txid: Some(txid), + })) } async fn is_onchain_paid( diff --git a/moksha-mint/src/server.rs b/moksha-mint/src/server.rs index 3cfadcde..aed51483 100644 --- a/moksha-mint/src/server.rs +++ b/moksha-mint/src/server.rs @@ -1,7 +1,6 @@ use crate::routes::btconchain::{ - get_melt_btconchain, get_melt_quote_btconchain, get_mint_quote_btconchain, - post_melt_btconchain, post_melt_quote_btconchain, post_mint_btconchain, - post_mint_quote_btconchain, + get_melt_quote_btconchain, get_mint_quote_btconchain, post_melt_btconchain, + post_melt_quote_btconchain, post_mint_btconchain, post_mint_quote_btconchain, }; use crate::routes::default::{ get_info, get_keys, get_keys_by_id, get_keysets, get_melt_quote_bolt11, get_mint_quote_bolt11, @@ -25,15 +24,14 @@ use crate::mint::Mint; use moksha_core::blind::BlindedMessage; use moksha_core::blind::BlindedSignature; use moksha_core::primitives::{ - ContactInfoResponse, CurrencyUnit, GetMeltBtcOnchainResponse, KeyResponse, KeysResponse, - MintInfoResponse, Nut10, Nut11, Nut12, Nut13, Nut14, Nut15, Nut16, Nut17, Nut18, Nut19, Nut4, - Nut5, Nut7, Nut8, Nut9, Nuts, PaymentMethod, PaymentMethodConfig, - PaymentMethodConfigBtcOnchainMelt, PaymentMethodConfigBtcOnchainMint, PostMeltBolt11Request, - PostMeltBolt11Response, PostMeltQuoteBolt11Request, PostMeltQuoteBolt11Response, - PostMeltQuoteBtcOnchainRequest, PostMeltQuoteBtcOnchainResponse, PostMintBolt11Request, - PostMintBolt11Response, PostMintQuoteBolt11Request, PostMintQuoteBolt11Response, - PostMintQuoteBtcOnchainRequest, PostMintQuoteBtcOnchainResponse, PostSwapRequest, - PostSwapResponse, + ContactInfoResponse, CurrencyUnit, KeyResponse, KeysResponse, MintInfoResponse, Nut10, Nut11, + Nut12, Nut13, Nut14, Nut15, Nut16, Nut17, Nut18, Nut19, Nut4, Nut5, Nut7, Nut8, Nut9, Nuts, + PaymentMethod, PaymentMethodConfig, PaymentMethodConfigBtcOnchainMelt, + PaymentMethodConfigBtcOnchainMint, PostMeltBolt11Request, PostMeltBolt11Response, + PostMeltQuoteBolt11Request, PostMeltQuoteBolt11Response, PostMeltQuoteBtcOnchainRequest, + PostMeltQuoteBtcOnchainResponse, PostMintBolt11Request, PostMintBolt11Response, + PostMintQuoteBolt11Request, PostMintQuoteBolt11Response, PostMintQuoteBtcOnchainRequest, + PostMintQuoteBtcOnchainResponse, PostSwapRequest, PostSwapResponse, }; use tower_http::services::ServeDir; @@ -112,7 +110,6 @@ pub async fn run_server(mint: Mint) -> anyhow::Result<()> { crate::routes::btconchain::post_melt_quote_btconchain, crate::routes::btconchain::get_melt_quote_btconchain, crate::routes::btconchain::post_melt_btconchain, - crate::routes::btconchain::get_melt_btconchain ), components(schemas( MintInfoResponse, @@ -157,7 +154,6 @@ pub async fn run_server(mint: Mint) -> anyhow::Result<()> { PostMintQuoteBtcOnchainResponse, PostMeltQuoteBtcOnchainRequest, PostMeltQuoteBtcOnchainResponse, - GetMeltBtcOnchainResponse, ContactInfoResponse, PaymentMethodConfig, PaymentMethodConfigBtcOnchainMint, @@ -201,7 +197,6 @@ fn app(mint: Mint) -> Router { get(get_melt_quote_btconchain), ) .route("/v1/melt/btconchain", post(post_melt_btconchain)) - .route("/v1/melt/btconchain/:txid", get(get_melt_btconchain)) } else { Router::new() }; diff --git a/moksha-wallet/src/client/crossplatform.rs b/moksha-wallet/src/client/crossplatform.rs index 934a0e48..1244078d 100644 --- a/moksha-wallet/src/client/crossplatform.rs +++ b/moksha-wallet/src/client/crossplatform.rs @@ -4,12 +4,12 @@ use moksha_core::{ blind::BlindedMessage, keyset::Keysets, primitives::{ - CurrencyUnit, GetMeltBtcOnchainResponse, KeysResponse, MintInfoResponse, - PostMeltBolt11Request, PostMeltBolt11Response, PostMeltBtcOnchainRequest, - PostMeltBtcOnchainResponse, PostMeltQuoteBolt11Request, PostMeltQuoteBolt11Response, - PostMeltQuoteBtcOnchainRequest, PostMeltQuoteBtcOnchainResponse, PostMintBolt11Request, - PostMintBolt11Response, PostMintBtcOnchainRequest, PostMintBtcOnchainResponse, - PostMintQuoteBolt11Request, PostMintQuoteBolt11Response, PostMintQuoteBtcOnchainRequest, + CurrencyUnit, KeysResponse, MintInfoResponse, PostMeltBolt11Request, + PostMeltBolt11Response, PostMeltBtcOnchainRequest, PostMeltBtcOnchainResponse, + PostMeltQuoteBolt11Request, PostMeltQuoteBolt11Response, PostMeltQuoteBtcOnchainRequest, + PostMeltQuoteBtcOnchainResponse, PostMintBolt11Request, PostMintBolt11Response, + PostMintBtcOnchainRequest, PostMintBtcOnchainResponse, PostMintQuoteBolt11Request, + PostMintQuoteBolt11Response, PostMintQuoteBtcOnchainRequest, PostMintQuoteBtcOnchainResponse, PostSwapRequest, PostSwapResponse, }, proof::Proofs, @@ -203,13 +203,4 @@ impl CashuClient for CrossPlatformHttpClient { self.do_get(&mint_url.join(&format!("/v1/melt/quote/btconchain/{quote}"))?) .await } - - async fn get_melt_onchain( - &self, - mint_url: &Url, - txid: String, - ) -> Result { - self.do_get(&mint_url.join(&format!("/v1/melt/btconchain/{txid}"))?) - .await - } } diff --git a/moksha-wallet/src/client/mod.rs b/moksha-wallet/src/client/mod.rs index 33d44b70..c0f3e0b1 100644 --- a/moksha-wallet/src/client/mod.rs +++ b/moksha-wallet/src/client/mod.rs @@ -3,10 +3,10 @@ use moksha_core::{ blind::BlindedMessage, keyset::Keysets, primitives::{ - CurrencyUnit, GetMeltBtcOnchainResponse, KeysResponse, MintInfoResponse, - PostMeltBolt11Response, PostMeltBtcOnchainResponse, PostMeltQuoteBolt11Response, - PostMeltQuoteBtcOnchainResponse, PostMintBolt11Response, PostMintBtcOnchainResponse, - PostMintQuoteBolt11Response, PostMintQuoteBtcOnchainResponse, PostSwapResponse, + CurrencyUnit, KeysResponse, MintInfoResponse, PostMeltBolt11Response, + PostMeltBtcOnchainResponse, PostMeltQuoteBolt11Response, PostMeltQuoteBtcOnchainResponse, + PostMintBolt11Response, PostMintBtcOnchainResponse, PostMintQuoteBolt11Response, + PostMintQuoteBtcOnchainResponse, PostSwapResponse, }, proof::Proofs, }; @@ -125,10 +125,4 @@ pub trait CashuClient { mint_url: &Url, quote: String, ) -> Result; - - async fn get_melt_onchain( - &self, - mint_url: &Url, - txid: String, - ) -> Result; } diff --git a/moksha-wallet/src/wallet.rs b/moksha-wallet/src/wallet.rs index e918d0ea..5adcc882 100644 --- a/moksha-wallet/src/wallet.rs +++ b/moksha-wallet/src/wallet.rs @@ -180,14 +180,6 @@ where .paid) } - pub async fn is_onchain_tx_paid( - &self, - mint_url: &Url, - txid: String, - ) -> Result { - Ok(self.client.get_melt_onchain(mint_url, txid).await?.paid) - } - pub async fn get_wallet_keysets(&self) -> Result, MokshaWalletError> { let mut tx = self.localstore.begin_tx().await?; let keysets = self.localstore.get_keysets(&mut tx).await?;