11use clap:: { Parser , Subcommand } ;
22use 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 ) ]
1617enum 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