@@ -6,6 +6,9 @@ use ldk_server_client::ldk_server_protos::api::{
66 GetBalancesRequest , GetNodeInfoRequest , ListChannelsRequest , ListPaymentsRequest ,
77 OnchainReceiveRequest , OnchainSendRequest , OpenChannelRequest ,
88} ;
9+ use ldk_server_client:: ldk_server_protos:: types:: {
10+ bolt11_invoice_description, Bolt11InvoiceDescription ,
11+ } ;
912
1013#[ derive( Parser , Debug ) ]
1114#[ command( version, about, long_about = None ) ]
@@ -32,7 +35,9 @@ enum Commands {
3235 } ,
3336 Bolt11Receive {
3437 #[ arg( short, long) ]
35- description : String ,
38+ description : Option < String > ,
39+ #[ arg( short, long) ]
40+ description_hash : Option < String > ,
3641 #[ arg( short, long) ]
3742 expiry_secs : u32 ,
3843 #[ arg( long) ]
@@ -87,31 +92,47 @@ async fn main() {
8792
8893 match cli. command {
8994 Commands :: GetNodeInfo => {
90- handle_response ( client. get_node_info ( GetNodeInfoRequest { } ) . await ) ;
95+ handle_response_result ( client. get_node_info ( GetNodeInfoRequest { } ) . await ) ;
9196 } ,
9297 Commands :: GetBalances => {
93- handle_response ( client. get_balances ( GetBalancesRequest { } ) . await ) ;
98+ handle_response_result ( client. get_balances ( GetBalancesRequest { } ) . await ) ;
9499 } ,
95100 Commands :: OnchainReceive => {
96- handle_response ( client. onchain_receive ( OnchainReceiveRequest { } ) . await ) ;
101+ handle_response_result ( client. onchain_receive ( OnchainReceiveRequest { } ) . await ) ;
97102 } ,
98103 Commands :: OnchainSend { address, amount_sats, send_all } => {
99- handle_response (
104+ handle_response_result (
100105 client. onchain_send ( OnchainSendRequest { address, amount_sats, send_all } ) . await ,
101106 ) ;
102107 } ,
103- Commands :: Bolt11Receive { description, expiry_secs, amount_msat } => {
104- handle_response (
105- client
106- . bolt11_receive ( Bolt11ReceiveRequest { description, expiry_secs, amount_msat } )
107- . await ,
108- ) ;
108+ Commands :: Bolt11Receive { description, description_hash, expiry_secs, amount_msat } => {
109+ let invoice_description = match ( description, description_hash) {
110+ ( Some ( desc) , None ) => Some ( Bolt11InvoiceDescription {
111+ kind : Some ( bolt11_invoice_description:: Kind :: Direct ( desc) ) ,
112+ } ) ,
113+ ( None , Some ( hash) ) => Some ( Bolt11InvoiceDescription {
114+ kind : Some ( bolt11_invoice_description:: Kind :: Hash ( hash) ) ,
115+ } ) ,
116+ ( Some ( _) , Some ( _) ) => {
117+ handle_error ( LdkServerError :: InternalError (
118+ "Only one of description or description_hash can be set." . to_string ( ) ,
119+ ) ) ;
120+ } ,
121+ ( None , None ) => None ,
122+ } ;
123+
124+ let request =
125+ Bolt11ReceiveRequest { description : invoice_description, expiry_secs, amount_msat } ;
126+
127+ handle_response_result ( client. bolt11_receive ( request) . await ) ;
109128 } ,
110129 Commands :: Bolt11Send { invoice, amount_msat } => {
111- handle_response ( client. bolt11_send ( Bolt11SendRequest { invoice, amount_msat } ) . await ) ;
130+ handle_response_result (
131+ client. bolt11_send ( Bolt11SendRequest { invoice, amount_msat } ) . await ,
132+ ) ;
112133 } ,
113134 Commands :: Bolt12Receive { description, amount_msat, expiry_secs, quantity } => {
114- handle_response (
135+ handle_response_result (
115136 client
116137 . bolt12_receive ( Bolt12ReceiveRequest {
117138 description,
@@ -123,7 +144,7 @@ async fn main() {
123144 ) ;
124145 } ,
125146 Commands :: Bolt12Send { offer, amount_msat, quantity, payer_note } => {
126- handle_response (
147+ handle_response_result (
127148 client
128149 . bolt12_send ( Bolt12SendRequest { offer, amount_msat, quantity, payer_note } )
129150 . await ,
@@ -136,7 +157,7 @@ async fn main() {
136157 push_to_counterparty_msat,
137158 announce_channel,
138159 } => {
139- handle_response (
160+ handle_response_result (
140161 client
141162 . open_channel ( OpenChannelRequest {
142163 node_pubkey,
@@ -150,22 +171,26 @@ async fn main() {
150171 ) ;
151172 } ,
152173 Commands :: ListChannels => {
153- handle_response ( client. list_channels ( ListChannelsRequest { } ) . await ) ;
174+ handle_response_result ( client. list_channels ( ListChannelsRequest { } ) . await ) ;
154175 } ,
155176 Commands :: ListPayments => {
156- handle_response ( client. list_payments ( ListPaymentsRequest { } ) . await ) ;
177+ handle_response_result ( client. list_payments ( ListPaymentsRequest { } ) . await ) ;
157178 } ,
158179 }
159180}
160181
161- fn handle_response < Rs : :: prost:: Message > ( response : Result < Rs , LdkServerError > ) {
182+ fn handle_response_result < Rs : :: prost:: Message > ( response : Result < Rs , LdkServerError > ) {
162183 match response {
163184 Ok ( response) => {
164185 println ! ( "{:?}" , response) ;
165186 } ,
166187 Err ( e) => {
167- eprintln ! ( "Error executing command: {:?}" , e) ;
168- std:: process:: exit ( 1 ) ; // Exit with status code 1 on error.
188+ handle_error ( e) ;
169189 } ,
170190 } ;
171191}
192+
193+ fn handle_error ( e : LdkServerError ) -> ! {
194+ eprintln ! ( "Error executing command: {:?}" , e) ;
195+ std:: process:: exit ( 1 ) ; // Exit with status code 1 on error.
196+ }
0 commit comments