Skip to content

Commit

Permalink
Use payment params amount for onchain
Browse files Browse the repository at this point in the history
  • Loading branch information
benthecarman committed Mar 21, 2024
1 parent 6fa7633 commit 783c14c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions src/onchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{AppState, MAX_SEND_AMOUNT};

#[derive(Clone, Deserialize)]
pub struct OnchainRequest {
sats: u64,
sats: Option<u64>,
address: String,
}

Expand All @@ -23,10 +23,6 @@ pub async fn pay_onchain(
state: AppState,
payload: OnchainRequest,
) -> anyhow::Result<OnchainResponse> {
if payload.sats > MAX_SEND_AMOUNT {
anyhow::bail!("max amount is 10,000,000");
}

let res = {
let network = state.network;

Expand All @@ -49,7 +45,14 @@ pub async fn pay_onchain(

let bitcoin_client = state.bitcoin_client.clone();

let amount = Amount::from_sat(payload.sats);
let amount = params
.amount()
.or(payload.sats.map(Amount::from_sat))
.ok_or(anyhow::anyhow!("invalid amount"))?;

if amount.to_sat() > MAX_SEND_AMOUNT {
anyhow::bail!("max amount is 10,000,000");
}

let txid = task::block_in_place(|| {
bitcoin_client.send_to_address(&address, amount, None, None, None, None, None, None)
Expand Down

0 comments on commit 783c14c

Please sign in to comment.