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 },
56 Receive {
58 #[clap(long)]
59 notes: OOBNotes,
60 #[arg(long = "no-wait", action = clap::ArgAction::SetFalse)]
61 wait: bool,
62 },
63}
64
65impl EcashCommands {
66 pub async fn handle(self, client: &GatewayApi, base_url: &SafeUrl) -> anyhow::Result<()> {
67 match self {
68 Self::Backup { federation_id } => {
69 backup(client, base_url, BackupPayload { federation_id }).await?;
70 }
71 Self::Pegin { federation_id } => {
72 let response =
73 get_deposit_address(client, base_url, DepositAddressPayload { federation_id })
74 .await?;
75
76 print_response(response);
77 }
78 Self::PeginRecheck {
79 address,
80 federation_id,
81 } => {
82 let response = recheck_address(
83 client,
84 base_url,
85 DepositAddressRecheckPayload {
86 address,
87 federation_id,
88 },
89 )
90 .await?;
91 print_response(response);
92 }
93 Self::Pegout {
94 federation_id,
95 amount,
96 address,
97 } => {
98 let response = withdraw(
99 client,
100 base_url,
101 WithdrawPayload {
102 federation_id,
103 amount,
104 address,
105 quoted_fees: None,
106 },
107 )
108 .await?;
109
110 print_response(response);
111 }
112 Self::Send {
113 federation_id,
114 amount,
115 } => {
116 let response = spend_ecash(
117 client,
118 base_url,
119 SpendEcashPayload {
120 federation_id,
121 amount,
122 },
123 )
124 .await?;
125
126 print_response(response);
127 }
128 Self::Receive { notes, wait } => {
129 let response =
130 receive_ecash(client, base_url, ReceiveEcashPayload { notes, wait }).await?;
131 print_response(response);
132 }
133 }
134
135 Ok(())
136 }
137}