msggen: add sendonionmessage method

Changelog-None
This commit is contained in:
daywalker90 2024-04-17 16:29:41 +02:00 committed by Christian Decker
parent 3c48438821
commit 5ed04c9788
9 changed files with 336 additions and 114 deletions

View file

@ -2268,6 +2268,15 @@
"SendOnion.status": 3,
"SendOnion.updated_index": 15
},
"SendonionmessageHops": {
"SendOnionMessage.hops[].node": 1,
"SendOnionMessage.hops[].tlv": 2
},
"SendonionmessageRequest": {
"SendOnionMessage.blinding": 2,
"SendOnionMessage.first_id": 1,
"SendOnionMessage.hops[]": 3
},
"SendpayRequest": {
"SendPay.amount_msat": 10,
"SendPay.bolt11": 5,
@ -7999,6 +8008,30 @@
"added": "v23.11",
"deprecated": false
},
"SendOnionMessage": {
"added": "pre-v0.10.1",
"deprecated": null
},
"SendOnionMessage.blinding": {
"added": "pre-v0.10.1",
"deprecated": false
},
"SendOnionMessage.first_id": {
"added": "pre-v0.10.1",
"deprecated": false
},
"SendOnionMessage.hops[]": {
"added": "pre-v0.10.1",
"deprecated": false
},
"SendOnionMessage.hops[].node": {
"added": "pre-v0.10.1",
"deprecated": false
},
"SendOnionMessage.hops[].tlv": {
"added": "pre-v0.10.1",
"deprecated": false
},
"SendPay": {
"added": "pre-v0.10.1",
"deprecated": null

View file

@ -81,6 +81,7 @@ service Node {
rpc ReserveInputs(ReserveinputsRequest) returns (ReserveinputsResponse) {}
rpc SendCustomMsg(SendcustommsgRequest) returns (SendcustommsgResponse) {}
rpc SendInvoice(SendinvoiceRequest) returns (SendinvoiceResponse) {}
rpc SendOnionMessage(SendonionmessageRequest) returns (SendonionmessageResponse) {}
rpc SetChannel(SetchannelRequest) returns (SetchannelResponse) {}
rpc SignInvoice(SigninvoiceRequest) returns (SigninvoiceResponse) {}
rpc SignMessage(SignmessageRequest) returns (SignmessageResponse) {}
@ -2352,6 +2353,20 @@ message SendinvoiceResponse {
optional bytes payment_preimage = 13;
}
message SendonionmessageRequest {
bytes first_id = 1;
bytes blinding = 2;
repeated SendonionmessageHops hops = 3;
}
message SendonionmessageResponse {
}
message SendonionmessageHops {
bytes node = 1;
uint32 tlv = 2;
}
message SetchannelRequest {
string id = 1;
optional Amount feebase = 2;

View file

@ -2231,6 +2231,14 @@ impl From<responses::SendinvoiceResponse> for pb::SendinvoiceResponse {
}
}
#[allow(unused_variables)]
impl From<responses::SendonionmessageResponse> for pb::SendonionmessageResponse {
fn from(c: responses::SendonionmessageResponse) -> Self {
Self {
}
}
}
#[allow(unused_variables)]
impl From<responses::SetchannelChannels> for pb::SetchannelChannels {
fn from(c: responses::SetchannelChannels) -> Self {
@ -3541,6 +3549,28 @@ impl From<requests::SendinvoiceRequest> for pb::SendinvoiceRequest {
}
}
#[allow(unused_variables)]
impl From<requests::SendonionmessageHops> for pb::SendonionmessageHops {
fn from(c: requests::SendonionmessageHops) -> Self {
Self {
node: c.node.serialize().to_vec(), // Rule #2 for type pubkey
tlv: c.tlv.into(), // Rule #2 for type u8
}
}
}
#[allow(unused_variables)]
impl From<requests::SendonionmessageRequest> for pb::SendonionmessageRequest {
fn from(c: requests::SendonionmessageRequest) -> Self {
Self {
blinding: c.blinding.serialize().to_vec(), // Rule #2 for type pubkey
first_id: c.first_id.serialize().to_vec(), // Rule #2 for type pubkey
// Field: SendOnionMessage.hops[]
hops: c.hops.into_iter().map(|i| i.into()).collect(), // Rule #3 for type SendonionmessageHops
}
}
}
#[allow(unused_variables)]
impl From<requests::SetchannelRequest> for pb::SetchannelRequest {
fn from(c: requests::SetchannelRequest) -> Self {
@ -4656,6 +4686,27 @@ impl From<pb::SendinvoiceRequest> for requests::SendinvoiceRequest {
}
}
#[allow(unused_variables)]
impl From<pb::SendonionmessageHops> for requests::SendonionmessageHops {
fn from(c: pb::SendonionmessageHops) -> Self {
Self {
node: PublicKey::from_slice(&c.node).unwrap(), // Rule #1 for type pubkey
tlv: c.tlv as u8, // Rule #1 for type u8
}
}
}
#[allow(unused_variables)]
impl From<pb::SendonionmessageRequest> for requests::SendonionmessageRequest {
fn from(c: pb::SendonionmessageRequest) -> Self {
Self {
blinding: PublicKey::from_slice(&c.blinding).unwrap(), // Rule #1 for type pubkey
first_id: PublicKey::from_slice(&c.first_id).unwrap(), // Rule #1 for type pubkey
hops: c.hops.into_iter().map(|s| s.into()).collect(), // Rule #4
}
}
}
#[allow(unused_variables)]
impl From<pb::SetchannelRequest> for requests::SetchannelRequest {
fn from(c: pb::SetchannelRequest) -> Self {

View file

@ -2362,6 +2362,38 @@ async fn send_invoice(
}
async fn send_onion_message(
&self,
request: tonic::Request<pb::SendonionmessageRequest>,
) -> Result<tonic::Response<pb::SendonionmessageResponse>, tonic::Status> {
let req = request.into_inner();
let req: requests::SendonionmessageRequest = req.into();
debug!("Client asked for send_onion_message");
trace!("send_onion_message 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::SendOnionMessage(req))
.await
.map_err(|e| Status::new(
Code::Unknown,
format!("Error calling method SendOnionMessage: {:?}", e)))?;
match result {
Response::SendOnionMessage(r) => {
trace!("send_onion_message response: {:?}", r);
Ok(tonic::Response::new(r.into()))
},
r => Err(Status::new(
Code::Internal,
format!(
"Unexpected result {:?} to method call SendOnionMessage",
r
)
)),
}
}
async fn set_channel(
&self,
request: tonic::Request<pb::SetchannelRequest>,

47
cln-rpc/src/model.rs generated
View file

@ -92,6 +92,7 @@ pub enum Request {
ReserveInputs(requests::ReserveinputsRequest),
SendCustomMsg(requests::SendcustommsgRequest),
SendInvoice(requests::SendinvoiceRequest),
SendOnionMessage(requests::SendonionmessageRequest),
SetChannel(requests::SetchannelRequest),
SignInvoice(requests::SigninvoiceRequest),
SignMessage(requests::SignmessageRequest),
@ -198,6 +199,7 @@ pub enum Response {
ReserveInputs(responses::ReserveinputsResponse),
SendCustomMsg(responses::SendcustommsgResponse),
SendInvoice(responses::SendinvoiceResponse),
SendOnionMessage(responses::SendonionmessageResponse),
SetChannel(responses::SetchannelResponse),
SignInvoice(responses::SigninvoiceResponse),
SignMessage(responses::SignmessageResponse),
@ -2787,6 +2789,36 @@ pub mod requests {
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SendonionmessageHops {
pub node: PublicKey,
pub tlv: u8,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SendonionmessageRequest {
pub blinding: PublicKey,
pub first_id: PublicKey,
pub hops: Vec<SendonionmessageHops>,
}
impl From<SendonionmessageRequest> for Request {
fn from(r: SendonionmessageRequest) -> Self {
Request::SendOnionMessage(r)
}
}
impl IntoRequest for SendonionmessageRequest {
type Response = super::responses::SendonionmessageResponse;
}
impl TypedRequest for SendonionmessageRequest {
type Response = super::responses::SendonionmessageResponse;
fn method(&self) -> &str {
"sendonionmessage"
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SetchannelRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub enforcedelay: Option<u32>,
@ -7529,6 +7561,21 @@ pub mod responses {
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SendonionmessageResponse {
}
impl TryFrom<Response> for SendonionmessageResponse {
type Error = super::TryFromResponseError;
fn try_from(response: Response) -> Result<Self, Self::Error> {
match response {
Response::SendOnionMessage(response) => Ok(response),
_ => Err(TryFromResponseError)
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SetchannelChannels {
#[serde(skip_serializing_if = "Option::is_none")]

View file

@ -134,7 +134,7 @@ def load_jsonrpc_service():
"ReserveInputs",
"SendCustomMsg",
"SendInvoice",
# "sendonionmessage",
"SendOnionMessage",
"SetChannel",
"SignInvoice",
"SignMessage",

File diff suppressed because one or more lines are too long

View file

@ -379,6 +379,11 @@ class NodeStub(object):
request_serializer=node__pb2.SendinvoiceRequest.SerializeToString,
response_deserializer=node__pb2.SendinvoiceResponse.FromString,
)
self.SendOnionMessage = channel.unary_unary(
'/cln.Node/SendOnionMessage',
request_serializer=node__pb2.SendonionmessageRequest.SerializeToString,
response_deserializer=node__pb2.SendonionmessageResponse.FromString,
)
self.SetChannel = channel.unary_unary(
'/cln.Node/SetChannel',
request_serializer=node__pb2.SetchannelRequest.SerializeToString,
@ -917,6 +922,12 @@ class NodeServicer(object):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def SendOnionMessage(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def SetChannel(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
@ -1399,6 +1410,11 @@ def add_NodeServicer_to_server(servicer, server):
request_deserializer=node__pb2.SendinvoiceRequest.FromString,
response_serializer=node__pb2.SendinvoiceResponse.SerializeToString,
),
'SendOnionMessage': grpc.unary_unary_rpc_method_handler(
servicer.SendOnionMessage,
request_deserializer=node__pb2.SendonionmessageRequest.FromString,
response_serializer=node__pb2.SendonionmessageResponse.SerializeToString,
),
'SetChannel': grpc.unary_unary_rpc_method_handler(
servicer.SetChannel,
request_deserializer=node__pb2.SetchannelRequest.FromString,
@ -2745,6 +2761,23 @@ class Node(object):
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def SendOnionMessage(request,
target,
options=(),
channel_credentials=None,
call_credentials=None,
insecure=False,
compression=None,
wait_for_ready=None,
timeout=None,
metadata=None):
return grpc.experimental.unary_unary(request, target, '/cln.Node/SendOnionMessage',
node__pb2.SendonionmessageRequest.SerializeToString,
node__pb2.SendonionmessageResponse.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def SetChannel(request,
target,

View file

@ -1790,6 +1790,11 @@ def sendinvoice2py(m):
})
def sendonionmessage2py(m):
return remove_default({
})
def setchannel_channels2py(m):
return remove_default({
"channel_id": hexlify(m.channel_id), # PrimitiveField in generate_composite