gateway_cli/
onchain_commands.rs1use bitcoin::address::NetworkUnchecked;
2use clap::Subcommand;
3use fedimint_core::BitcoinAmountOrAll;
4use fedimint_gateway_common::SendOnchainRequest;
5
6use crate::{GatewayRpcClient, print_response};
7
8#[derive(Subcommand)]
9pub enum OnchainCommands {
10 Address,
13 Send {
16 #[clap(long)]
18 address: bitcoin::Address<NetworkUnchecked>,
19
20 #[clap(long)]
25 amount: BitcoinAmountOrAll,
26
27 #[clap(long)]
29 fee_rate_sats_per_vbyte: u64,
30 },
31}
32
33impl OnchainCommands {
34 pub async fn handle(
35 self,
36 create_client: impl Fn() -> GatewayRpcClient + Send + Sync,
37 ) -> anyhow::Result<()> {
38 match self {
39 Self::Address => {
40 let response = create_client()
41 .get_ln_onchain_address()
42 .await?
43 .assume_checked();
44 println!("{response}");
45 }
46 Self::Send {
47 address,
48 amount,
49 fee_rate_sats_per_vbyte,
50 } => {
51 let response = create_client()
52 .send_onchain(SendOnchainRequest {
53 address,
54 amount,
55 fee_rate_sats_per_vbyte,
56 })
57 .await?;
58 print_response(response);
59 }
60 }
61
62 Ok(())
63 }
64}