diff --git a/moksha-mint/src/btconchain/lnd.rs b/moksha-mint/src/btconchain/lnd.rs index 609caf9d..d21efb72 100644 --- a/moksha-mint/src/btconchain/lnd.rs +++ b/moksha-mint/src/btconchain/lnd.rs @@ -28,14 +28,14 @@ impl LndBtcOnchain { pub async fn client_lock( &self, - ) -> anyhow::Result> { + ) -> Result, MokshaMintError> { let guard = self.0.lock().await; Ok(MutexGuard::map(guard, |client| client.lightning())) } pub async fn wallet_lock( &self, - ) -> anyhow::Result> { + ) -> Result, MokshaMintError> { let guard = self.0.lock().await; Ok(MutexGuard::map(guard, |client| client.wallet())) } @@ -50,12 +50,7 @@ impl BtcOnchain for LndBtcOnchain { ..Default::default() }; - let response = self - .wallet_lock() - .await - .expect("failed to lock wallet") - .list_unspent(request) - .await?; + let response = self.wallet_lock().await?.list_unspent(request).await?; Ok(response .get_ref() @@ -76,12 +71,7 @@ impl BtcOnchain for LndBtcOnchain { ..Default::default() }; - let response = self - .wallet_lock() - .await - .expect("failed to lock wallet") - .list_unspent(request) - .await?; + let response = self.wallet_lock().await?.list_unspent(request).await?; Ok(response.get_ref().utxos.iter().any(|utxo| { utxo.address == address @@ -91,7 +81,7 @@ impl BtcOnchain for LndBtcOnchain { } async fn new_address(&self) -> Result { - let mut client = self.client_lock().await.expect("failed to lock client"); + let mut client = self.client_lock().await?; let response = client .new_address(NewAddressRequest { r#type: AddressType::WitnessPubkeyHash as i32, @@ -111,8 +101,7 @@ impl BtcOnchain for LndBtcOnchain { ) -> Result { let response = self .client_lock() - .await - .expect("failed to lock client") + .await? .send_coins(SendCoinsRequest { addr: address.to_owned(), amount: amount as i64, @@ -134,8 +123,7 @@ impl BtcOnchain for LndBtcOnchain { ) -> Result { let response = self .client_lock() - .await - .expect("failed to lock client") + .await? .estimate_fee(EstimateFeeRequest { addr_to_amount: std::iter::once(&(address.to_owned(), amount as i64)) .cloned() diff --git a/moksha-mint/src/lightning/lnd.rs b/moksha-mint/src/lightning/lnd.rs index ba1ae9b9..f042a321 100644 --- a/moksha-mint/src/lightning/lnd.rs +++ b/moksha-mint/src/lightning/lnd.rs @@ -68,7 +68,7 @@ impl LndLightning { pub async fn client_lock( &self, - ) -> anyhow::Result> { + ) -> Result, MokshaMintError> { let guard = self.0.lock().await; Ok(MutexGuard::map(guard, |client| client.lightning())) } @@ -87,11 +87,9 @@ impl Lightning for LndLightning { let invoice = self .client_lock() - .await - .expect("failed to lock client") + .await? .lookup_invoice(fedimint_tonic_lnd::tonic::Request::new(invoice_request)) - .await - .expect("failed to lookup invoice") + .await? .into_inner(); Ok(invoice.state == fedimint_tonic_lnd::lnrpc::invoice::InvoiceState::Settled as i32) @@ -105,11 +103,9 @@ impl Lightning for LndLightning { let invoice = self .client_lock() - .await - .expect("failed to lock client") + .await? .add_invoice(fedimint_tonic_lnd::tonic::Request::new(invoice_request)) - .await - .expect("failed to create invoice") + .await? .into_inner(); Ok(CreateInvoiceResult { @@ -128,11 +124,9 @@ impl Lightning for LndLightning { }; let payment_response = self .client_lock() - .await - .expect("failed to lock client") //FIXME map error + .await? .send_payment_sync(fedimint_tonic_lnd::tonic::Request::new(pay_req)) - .await - .expect("failed to pay invoice") + .await? .into_inner(); let total_fees = payment_response