gateway_cli/
ecash_commands.rs1use bitcoin::Address;
2use bitcoin::address::NetworkUnchecked;
3use clap::Subcommand;
4use fedimint_core::config::FederationId;
5use fedimint_core::util::SafeUrl;
6use fedimint_core::{Amount, BitcoinAmountOrAll};
7use fedimint_gateway_client::{
8 backup, get_deposit_address, receive_ecash, recheck_address, spend_ecash, withdraw,
9};
10use fedimint_gateway_common::{
11 BackupPayload, DepositAddressPayload, DepositAddressRecheckPayload, ReceiveEcashPayload,
12 SpendEcashPayload, WithdrawPayload,
13};
14use fedimint_ln_common::client::GatewayApi;
15use fedimint_mint_client::OOBNotes;
16
17use crate::print_response;
18
19#[derive(Subcommand)]
20pub enum EcashCommands {
21 Backup {
23 #[clap(long)]
24 federation_id: FederationId,
25 },
26 Pegin {
29 #[clap(long)]
30 federation_id: FederationId,
31 },
32 PeginRecheck {
34 #[clap(long)]
35 address: bitcoin::Address<NetworkUnchecked>,
36 #[clap(long)]
37 federation_id: FederationId,
38 },
39 Pegout {
41 #[clap(long)]
42 federation_id: FederationId,
43 #[clap(long)]
45 amount: BitcoinAmountOrAll,
46 #[clap(long)]
48 address: Address<NetworkUnchecked>,
49 },
50 Send {
52 #[clap(long)]
53 federation_id: FederationId,
54 amount: Amount,
55 #[clap(long)]
56 allow_overpay: bool,
57 #[clap(long, default_value_t = 60 * 60 * 24 * 7)]
58 timeout: u64,
59 #[clap(long)]
60 include_invite: bool,
61 },
62 Receive {
64 #[clap(long)]
65 notes: OOBNotes,
66 #[arg(long = "no-wait", action = clap::ArgAction::SetFalse)]
67 wait: bool,
68 },
69}
70
71impl EcashCommands {
72 pub async fn handle(self, client: &GatewayApi, base_url: &SafeUrl) -> anyhow::Result<()> {
73 match self {
74 Self::Backup { federation_id } => {
75 backup(client, base_url, BackupPayload { federation_id }).await?;
76 }
77 Self::Pegin { federation_id } => {
78 let response =
79 get_deposit_address(client, base_url, DepositAddressPayload { federation_id })
80 .await?;
81
82 print_response(response);
83 }
84 Self::PeginRecheck {
85 address,
86 federation_id,
87 } => {
88 let response = recheck_address(
89 client,
90 base_url,
91 DepositAddressRecheckPayload {
92 address,
93 federation_id,
94 },
95 )
96 .await?;
97 print_response(response);
98 }
99 Self::Pegout {
100 federation_id,
101 amount,
102 address,
103 } => {
104 let response = withdraw(
105 client,
106 base_url,
107 WithdrawPayload {
108 federation_id,
109 amount,
110 address,
111 quoted_fees: None,
112 },
113 )
114 .await?;
115
116 print_response(response);
117 }
118 Self::Send {
119 federation_id,
120 amount,
121 allow_overpay,
122 timeout,
123 include_invite,
124 } => {
125 let response = spend_ecash(
126 client,
127 base_url,
128 SpendEcashPayload {
129 federation_id,
130 amount,
131 allow_overpay,
132 timeout,
133 include_invite,
134 },
135 )
136 .await?;
137
138 print_response(response);
139 }
140 Self::Receive { notes, wait } => {
141 let response =
142 receive_ecash(client, base_url, ReceiveEcashPayload { notes, wait }).await?;
143 print_response(response);
144 }
145 }
146
147 Ok(())
148 }
149}