diff --git a/src/lightning.rs b/src/lightning.rs index 2d0f17e..f11d64b 100644 --- a/src/lightning.rs +++ b/src/lightning.rs @@ -105,6 +105,14 @@ pub async fn pay_lightning( info!("Paying invoice {invoice}"); + state + .payments + .add_payment( + x_forwarded_for, + invoice.amount_milli_satoshis().unwrap_or(0) / 1000, + ) + .await; + let response = lightning_client .send_payment_sync(lnrpc::SendRequest { payment_request: invoice.to_string(), @@ -121,13 +129,5 @@ pub async fn pay_lightning( response.payment_preimage }; - state - .payments - .add_payment( - x_forwarded_for, - invoice.amount_milli_satoshis().unwrap_or(0) / 1000, - ) - .await; - Ok(hex::encode(payment_preimage)) } diff --git a/src/nostr_dms.rs b/src/nostr_dms.rs index 0e25a51..d0e086d 100644 --- a/src/nostr_dms.rs +++ b/src/nostr_dms.rs @@ -191,6 +191,17 @@ async fn handle_event(event: Event, state: AppState) -> anyhow::Result<()> { return Err(anyhow::anyhow!("Too many payments")); } + state + .payments + .add_payment(&event.pubkey.to_string(), amount.to_sat()) + .await; + + // track for address too + state + .payments + .add_payment(&address.to_string(), amount.to_sat()) + .await; + let resp = { let mut wallet_client = state.lightning_client.clone(); info!("Sending {amount} to {address} from nostr dm"); @@ -204,17 +215,6 @@ async fn handle_event(event: Event, state: AppState) -> anyhow::Result<()> { wallet_client.send_coins(req).await?.into_inner() }; - state - .payments - .add_payment(&event.pubkey.to_string(), amount.to_sat()) - .await; - - // track for address too - state - .payments - .add_payment(&address.to_string(), amount.to_sat()) - .await; - let txid = resp.txid; info!("Sent onchain tx: {txid}"); diff --git a/src/onchain.rs b/src/onchain.rs index e347f95..654e4ad 100644 --- a/src/onchain.rs +++ b/src/onchain.rs @@ -51,6 +51,17 @@ pub async fn pay_onchain( anyhow::bail!("max amount is 1,000,000"); } + state + .payments + .add_payment(x_forwarded_for, amount.to_sat()) + .await; + + // track for address too + state + .payments + .add_payment(&address.to_string(), amount.to_sat()) + .await; + let resp = { let mut wallet_client = state.lightning_client.clone(); info!("Sending {amount} to {address}"); @@ -64,17 +75,6 @@ pub async fn pay_onchain( wallet_client.send_coins(req).await?.into_inner() }; - state - .payments - .add_payment(x_forwarded_for, amount.to_sat()) - .await; - - // track for address too - state - .payments - .add_payment(&address.to_string(), amount.to_sat()) - .await; - OnchainResponse { txid: resp.txid, address: address.to_string(),