Skip to main content

cdk_mint_rpc/mint_rpc_cli/subcommands/
update_melt_method.rs

1use anyhow::Result;
2use clap::Args;
3use tonic::Request;
4
5use crate::payment_method::{Bolt11MeltMethodOptions, UpdateMeltMethodRequest};
6use crate::InterceptedPaymentMethodServiceClient;
7
8/// Command to update the settings of a melt (NUT-05) payment method
9///
10/// NUT-05 defines how tokens are melted (redeemed) for external payments. This command
11/// allows configuring the available token units, payment methods, amounts, and other settings
12/// for the melting process.
13#[derive(Args, Debug)]
14pub struct UpdateMeltMethodCommand {
15    /// The token unit type (e.g., "sat")
16    #[arg(short, long)]
17    #[arg(default_value = "sat")]
18    unit: String,
19    /// The payment method for melting (e.g., "bolt11" for Lightning payments)
20    #[arg(short, long)]
21    #[arg(default_value = "bolt11")]
22    method: String,
23    /// The minimum amount that can be melted in a single transaction
24    #[arg(long)]
25    min_amount: Option<u64>,
26    /// The maximum amount that can be melted in a single transaction
27    #[arg(long)]
28    max_amount: Option<u64>,
29    /// Human-readable name for this payment method
30    #[arg(long)]
31    method_name: Option<String>,
32    /// Whether the mint supports paying amountless Lightning invoices
33    #[arg(long)]
34    amountless: Option<bool>,
35}
36
37/// Executes the update_melt_method command against the mint server
38///
39/// This function sends an RPC request to update the settings of one of the mint's
40/// NUT-05 payment methods.
41///
42/// # Arguments
43/// * `client` - The RPC client used to communicate with the mint
44/// * `sub_command_args` - The NUT-05 configuration parameters to update
45pub async fn update_melt_method(
46    client: &mut InterceptedPaymentMethodServiceClient,
47    sub_command_args: &UpdateMeltMethodCommand,
48) -> Result<()> {
49    // Create options if amountless is set
50    let options = sub_command_args
51        .amountless
52        .map(|amountless| Bolt11MeltMethodOptions { amountless });
53
54    let response = client
55        .update_melt_method(Request::new(UpdateMeltMethodRequest {
56            method: sub_command_args.method.clone(),
57            unit: sub_command_args.unit.clone(),
58            min_amount: sub_command_args.min_amount,
59            max_amount: sub_command_args.max_amount,
60            options,
61            method_name: sub_command_args.method_name.clone(),
62        }))
63        .await?
64        .into_inner();
65
66    println!("Melt method settings:");
67    println!("  Unit: {}", response.unit);
68    println!("  Method: {}", response.method);
69    println!(
70        "  Min amount: {}",
71        response
72            .min_amount
73            .map_or("none".to_string(), |a| a.to_string())
74    );
75    println!(
76        "  Max amount: {}",
77        response
78            .max_amount
79            .map_or("none".to_string(), |a| a.to_string())
80    );
81    println!(
82        "  Method name: {}",
83        response.method_name.unwrap_or_else(|| "none".to_string())
84    );
85    if let Some(options) = response.options {
86        println!("  Bolt11 amountless: {}", options.amountless);
87    }
88
89    Ok(())
90}