Skip to content

Commit b685389

Browse files
committed
Add Cli command for OnchainSend
1 parent b9d6b04 commit b685389

3 files changed

Lines changed: 29 additions & 9 deletions

File tree

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cli/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ edition = "2021"
77
client = { path = "../client" }
88
clap = { version = "4.0.5", default-features = false, features = ["derive", "std"] }
99
tokio = { version = "1.38.0", default-features = false, features = ["rt-multi-thread", "macros"] }
10+
prost = { version = "0.11.6", default-features = false}

cli/src/main.rs

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use clap::{Parser, Subcommand};
22
use client::client::LdkNodeServerClient;
3-
use client::protos::OnchainReceiveRequest;
3+
use client::error::LdkNodeServerError;
4+
use client::protos::{OnchainReceiveRequest, OnchainSendRequest};
45

56
#[derive(Parser, Debug)]
67
#[command(version, about, long_about = None)]
@@ -15,6 +16,14 @@ struct Cli {
1516
#[derive(Subcommand, Debug)]
1617
enum Commands {
1718
OnchainReceive,
19+
OnchainSend {
20+
#[arg(short, long)]
21+
address: String,
22+
#[arg(long)]
23+
amount_sats: Option<u64>,
24+
#[arg(long)]
25+
send_all: Option<bool>,
26+
},
1827
}
1928

2029
#[tokio::main]
@@ -24,14 +33,23 @@ async fn main() {
2433

2534
match cli.command {
2635
Commands::OnchainReceive => {
27-
match client.onchain_receive(OnchainReceiveRequest {}).await {
28-
Ok(response) => {
29-
println!("New Bitcoin Address: {:?}", response);
30-
},
31-
Err(e) => {
32-
eprintln!("Error in OnchainReceive: {:?}", e);
33-
},
34-
};
36+
handle_response(client.onchain_receive(OnchainReceiveRequest {}).await);
37+
},
38+
Commands::OnchainSend { address, amount_sats, send_all } => {
39+
handle_response(
40+
client.onchain_send(OnchainSendRequest { address, amount_sats, send_all }).await,
41+
);
3542
},
3643
}
3744
}
45+
46+
fn handle_response<Rs: ::prost::Message>(response: Result<Rs, LdkNodeServerError>) {
47+
match response {
48+
Ok(response) => {
49+
println!("{:?}", response);
50+
},
51+
Err(e) => {
52+
eprintln!("Error executing command: {:?}", e);
53+
},
54+
};
55+
}

0 commit comments

Comments
 (0)