From dc4ae9deb4dfb7231974ce216fb290fa8911ff94 Mon Sep 17 00:00:00 2001 From: Carl Dong Date: Mon, 6 Feb 2023 12:14:54 -0500 Subject: [PATCH] msggen: Regenerate for addition of SignInvoice Performed using: PYTHONPATH=contrib/msggen python3 contrib/msggen/msggen/__main__.py --- .msggen.json | 6 ++++ cln-grpc/proto/node.proto | 9 ++++++ cln-grpc/src/convert.rs | 18 +++++++++++ cln-grpc/src/server.rs | 32 +++++++++++++++++++ cln-rpc/src/model.rs | 33 ++++++++++++++++++++ contrib/pyln-testing/pyln/testing/grpc2py.py | 6 ++++ 6 files changed, 104 insertions(+) diff --git a/.msggen.json b/.msggen.json index 311d64ee0..9e3c3971d 100644 --- a/.msggen.json +++ b/.msggen.json @@ -1006,6 +1006,12 @@ "SetchannelResponse": { "SetChannel.channels[]": 1 }, + "SigninvoiceRequest": { + "SignInvoice.invstring": 1 + }, + "SigninvoiceResponse": { + "SignInvoice.bolt11": 1 + }, "SignmessageRequest": { "SignMessage.message": 1 }, diff --git a/cln-grpc/proto/node.proto b/cln-grpc/proto/node.proto index 981ae2946..74f5dae3c 100644 --- a/cln-grpc/proto/node.proto +++ b/cln-grpc/proto/node.proto @@ -53,6 +53,7 @@ service Node { rpc ListPays(ListpaysRequest) returns (ListpaysResponse) {} rpc Ping(PingRequest) returns (PingResponse) {} rpc SetChannel(SetchannelRequest) returns (SetchannelResponse) {} + rpc SignInvoice(SigninvoiceRequest) returns (SigninvoiceResponse) {} rpc SignMessage(SignmessageRequest) returns (SignmessageResponse) {} rpc Stop(StopRequest) returns (StopResponse) {} } @@ -1323,6 +1324,14 @@ message SetchannelChannels { optional string warning_htlcmax_too_high = 9; } +message SigninvoiceRequest { + string invstring = 1; +} + +message SigninvoiceResponse { + string bolt11 = 1; +} + message SignmessageRequest { string message = 1; } diff --git a/cln-grpc/src/convert.rs b/cln-grpc/src/convert.rs index f727f78b0..fdb1aa10a 100644 --- a/cln-grpc/src/convert.rs +++ b/cln-grpc/src/convert.rs @@ -1101,6 +1101,15 @@ impl From for pb::SetchannelResponse { } } +#[allow(unused_variables)] +impl From for pb::SigninvoiceResponse { + fn from(c: responses::SigninvoiceResponse) -> Self { + Self { + bolt11: c.bolt11, // Rule #2 for type string + } + } +} + #[allow(unused_variables)] impl From for pb::SignmessageResponse { fn from(c: responses::SignmessageResponse) -> Self { @@ -1690,6 +1699,15 @@ impl From for requests::SetchannelRequest { } } +#[allow(unused_variables)] +impl From for requests::SigninvoiceRequest { + fn from(c: pb::SigninvoiceRequest) -> Self { + Self { + invstring: c.invstring, // Rule #1 for type string + } + } +} + #[allow(unused_variables)] impl From for requests::SignmessageRequest { fn from(c: pb::SignmessageRequest) -> Self { diff --git a/cln-grpc/src/server.rs b/cln-grpc/src/server.rs index 7759ca0a6..78938d62f 100644 --- a/cln-grpc/src/server.rs +++ b/cln-grpc/src/server.rs @@ -1466,6 +1466,38 @@ async fn set_channel( } +async fn sign_invoice( + &self, + request: tonic::Request, +) -> Result, tonic::Status> { + let req = request.into_inner(); + let req: requests::SigninvoiceRequest = req.into(); + debug!("Client asked for sign_invoice"); + trace!("sign_invoice request: {:?}", req); + let mut rpc = ClnRpc::new(&self.rpc_path) + .await + .map_err(|e| Status::new(Code::Internal, e.to_string()))?; + let result = rpc.call(Request::SignInvoice(req)) + .await + .map_err(|e| Status::new( + Code::Unknown, + format!("Error calling method SignInvoice: {:?}", e)))?; + match result { + Response::SignInvoice(r) => { + trace!("sign_invoice response: {:?}", r); + Ok(tonic::Response::new(r.into())) + }, + r => Err(Status::new( + Code::Internal, + format!( + "Unexpected result {:?} to method call SignInvoice", + r + ) + )), + } + +} + async fn sign_message( &self, request: tonic::Request, diff --git a/cln-rpc/src/model.rs b/cln-rpc/src/model.rs index bf4faeba2..a8938ba53 100644 --- a/cln-rpc/src/model.rs +++ b/cln-rpc/src/model.rs @@ -61,6 +61,7 @@ pub enum Request { ListPays(requests::ListpaysRequest), Ping(requests::PingRequest), SetChannel(requests::SetchannelRequest), + SignInvoice(requests::SigninvoiceRequest), SignMessage(requests::SignmessageRequest), Stop(requests::StopRequest), } @@ -114,6 +115,7 @@ pub enum Response { ListPays(responses::ListpaysResponse), Ping(responses::PingResponse), SetChannel(responses::SetchannelResponse), + SignInvoice(responses::SigninvoiceResponse), SignMessage(responses::SignmessageResponse), Stop(responses::StopResponse), } @@ -1241,6 +1243,21 @@ pub mod requests { type Response = super::responses::SetchannelResponse; } + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct SigninvoiceRequest { + pub invstring: String, + } + + impl From for Request { + fn from(r: SigninvoiceRequest) -> Self { + Request::SignInvoice(r) + } + } + + impl IntoRequest for SigninvoiceRequest { + type Response = super::responses::SigninvoiceResponse; + } + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SignmessageRequest { pub message: String, @@ -3517,6 +3534,22 @@ pub mod responses { } } + #[derive(Clone, Debug, Deserialize, Serialize)] + pub struct SigninvoiceResponse { + pub bolt11: String, + } + + impl TryFrom for SigninvoiceResponse { + type Error = super::TryFromResponseError; + + fn try_from(response: Response) -> Result { + match response { + Response::SignInvoice(response) => Ok(response), + _ => Err(TryFromResponseError) + } + } + } + #[derive(Clone, Debug, Deserialize, Serialize)] pub struct SignmessageResponse { pub signature: String, diff --git a/contrib/pyln-testing/pyln/testing/grpc2py.py b/contrib/pyln-testing/pyln/testing/grpc2py.py index 28b366c8b..1f18b1451 100644 --- a/contrib/pyln-testing/pyln/testing/grpc2py.py +++ b/contrib/pyln-testing/pyln/testing/grpc2py.py @@ -871,6 +871,12 @@ def setchannel2py(m): }) +def signinvoice2py(m): + return remove_default({ + "bolt11": m.bolt11, # PrimitiveField in generate_composite + }) + + def signmessage2py(m): return remove_default({ "signature": hexlify(m.signature), # PrimitiveField in generate_composite