Skip to main content

cdk_mint_rpc/mint_rpc_cli/subcommands/
update_mint_method.rs

1use anyhow::Result;
2use clap::Args;
3use tonic::Request;
4
5use crate::payment_method::{Bolt11MintMethodOptions, UpdateMintMethodRequest};
6use crate::InterceptedPaymentMethodServiceClient;
7
8/// Command to update the settings of a mint (NUT-04) payment method
9///
10/// NUT-04 defines how tokens are minted in exchange for external payments. This command
11/// allows configuring the available token units, payment methods, amounts, and other settings
12/// for the minting process.
13#[derive(Args, Debug)]
14pub struct UpdateMintMethodCommand {
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 minting (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 minted in a single transaction
24    #[arg(long)]
25    min_amount: Option<u64>,
26    /// The maximum amount that can be minted 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 should include description fields in Lightning invoices
33    #[arg(long)]
34    description: Option<bool>,
35}
36
37/// Executes the update_mint_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-04 payment methods.
41///
42/// # Arguments
43/// * `client` - The RPC client used to communicate with the mint
44/// * `sub_command_args` - The NUT-04 configuration parameters to update
45pub async fn update_mint_method(
46    client: &mut InterceptedPaymentMethodServiceClient,
47    sub_command_args: &UpdateMintMethodCommand,
48) -> Result<()> {
49    // Create options if description is set
50    let options = sub_command_args
51        .description
52        .map(|description| Bolt11MintMethodOptions { description });
53
54    let response = client
55        .update_mint_method(Request::new(UpdateMintMethodRequest {
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!("Mint 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 description: {}", options.description);
87    }
88
89    Ok(())
90}