Skip to content

Commit 7185343

Browse files
committed
gl-plugin: Use call_typed for regular invoice creation
Replace call_raw with call_typed when creating a regular invoice in the LSP invoice handler. This provides better type safety by using the generated cln_rpc::model::requests::InvoiceRequest and cln_rpc::model::responses::InvoiceResponse types. Benefits: - Compile-time type checking for request/response fields - No manual hex decoding needed for payment_hash/payment_secret - Access to created_index field from the response - Cleaner code without custom request/response structs
1 parent 2fafe20 commit 7185343

1 file changed

Lines changed: 8 additions & 12 deletions

File tree

libs/gl-plugin/src/node/mod.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use tokio_stream::wrappers::ReceiverStream;
2525
use tonic::{transport::ServerTlsConfig, Code, Request, Response, Status};
2626
mod wrapper;
2727
use gl_client::bitcoin;
28+
use std::borrow::Borrow;
2829
use std::str::FromStr;
2930
pub use wrapper::WrappedNodeServer;
3031

@@ -218,7 +219,7 @@ impl Node for PluginNodeServer {
218219
);
219220

220221
// Create a regular invoice without JIT channel negotiation
221-
let invreq = crate::requests::Invoice {
222+
let invreq = cln_rpc::model::requests::InvoiceRequest {
222223
amount_msat: cln_rpc::primitives::AmountOrAny::Amount(
223224
cln_rpc::primitives::Amount::from_msat(req.amount_msat),
224225
),
@@ -230,24 +231,19 @@ impl Node for PluginNodeServer {
230231
cltv: Some(144),
231232
deschashonly: None,
232233
exposeprivatechannels: None,
233-
dev_routes: None,
234234
};
235235

236-
let res: crate::responses::Invoice = rpc
237-
.call_raw("invoice", &invreq)
236+
let res = rpc
237+
.call_typed(&invreq)
238238
.await
239239
.map_err(|e| Status::new(Code::Internal, e.to_string()))?;
240240

241241
return Ok(Response::new(pb::LspInvoiceResponse {
242242
bolt11: res.bolt11,
243-
created_index: 0, // Not available in our Invoice response
244-
expires_at: res.expiry_time,
245-
payment_hash: hex::decode(&res.payment_hash)
246-
.map_err(|e| Status::new(Code::Internal, format!("Invalid payment_hash: {}", e)))?,
247-
payment_secret: res
248-
.payment_secret
249-
.map(|s| hex::decode(&s).unwrap_or_default())
250-
.unwrap_or_default(),
243+
created_index: res.created_index.unwrap_or(0) as u32,
244+
expires_at: res.expires_at as u32,
245+
payment_hash: <cln_rpc::primitives::Sha256 as Borrow<[u8]>>::borrow(&res.payment_hash).to_vec(),
246+
payment_secret: res.payment_secret.to_vec(),
251247
}));
252248
}
253249

0 commit comments

Comments
 (0)