msggen: add renepay method

Changelog-None
This commit is contained in:
daywalker90 2024-04-24 16:07:14 +02:00 committed by Christian Decker
parent 5c0f25f916
commit 9538ecccad
9 changed files with 452 additions and 99 deletions

View file

@ -403,6 +403,11 @@
"startdir": 3,
"stop": 1
},
"RenepayStatus": {
"complete": 0,
"failed": 2,
"pending": 1
},
"SendonionStatus": {
"complete": 1,
"pending": 0
@ -2132,6 +2137,26 @@
"PreApproveKeysend.destination": 1,
"PreApproveKeysend.payment_hash": 2
},
"RenepayRequest": {
"RenePay.amount_msat": 2,
"RenePay.description": 6,
"RenePay.dev_use_shadow": 8,
"RenePay.invstring": 1,
"RenePay.label": 7,
"RenePay.maxdelay": 4,
"RenePay.maxfee": 3,
"RenePay.retry_for": 5
},
"RenepayResponse": {
"RenePay.amount_msat": 5,
"RenePay.amount_sent_msat": 6,
"RenePay.created_at": 3,
"RenePay.destination": 8,
"RenePay.parts": 4,
"RenePay.payment_hash": 2,
"RenePay.payment_preimage": 1,
"RenePay.status": 7
},
"SendcustommsgRequest": {
"SendCustomMsg.msg": 2,
"SendCustomMsg.node_id": 1
@ -7523,6 +7548,70 @@
"added": "v23.02",
"deprecated": false
},
"RenePay": {
"added": "pre-v0.10.1",
"deprecated": null
},
"RenePay.amount_msat": {
"added": "pre-v0.10.1",
"deprecated": false
},
"RenePay.amount_sent_msat": {
"added": "pre-v0.10.1",
"deprecated": false
},
"RenePay.created_at": {
"added": "pre-v0.10.1",
"deprecated": false
},
"RenePay.description": {
"added": "pre-v0.10.1",
"deprecated": false
},
"RenePay.destination": {
"added": "pre-v0.10.1",
"deprecated": false
},
"RenePay.dev_use_shadow": {
"added": "pre-v0.10.1",
"deprecated": false
},
"RenePay.invstring": {
"added": "pre-v0.10.1",
"deprecated": false
},
"RenePay.label": {
"added": "pre-v0.10.1",
"deprecated": false
},
"RenePay.maxdelay": {
"added": "pre-v0.10.1",
"deprecated": false
},
"RenePay.maxfee": {
"added": "pre-v0.10.1",
"deprecated": false
},
"RenePay.parts": {
"added": "pre-v0.10.1",
"deprecated": false
},
"RenePay.payment_hash": {
"added": "pre-v0.10.1",
"deprecated": false
},
"RenePay.payment_preimage": {
"added": "pre-v0.10.1",
"deprecated": false
},
"RenePay.retry_for": {
"added": "pre-v0.10.1",
"deprecated": false
},
"RenePay.status": {
"added": "pre-v0.10.1",
"deprecated": false
},
"SendCustomMsg": {
"added": "v0.10.1",
"deprecated": null

View file

@ -76,6 +76,7 @@ service Node {
rpc OpenChannel_Update(Openchannel_updateRequest) returns (Openchannel_updateResponse) {}
rpc Ping(PingRequest) returns (PingResponse) {}
rpc Plugin(PluginRequest) returns (PluginResponse) {}
rpc RenePay(RenepayRequest) returns (RenepayResponse) {}
rpc SendCustomMsg(SendcustommsgRequest) returns (SendcustommsgResponse) {}
rpc SetChannel(SetchannelRequest) returns (SetchannelResponse) {}
rpc SignInvoice(SigninvoiceRequest) returns (SigninvoiceResponse) {}
@ -2231,6 +2232,34 @@ message PluginPlugins {
bool dynamic = 3;
}
message RenepayRequest {
string invstring = 1;
optional Amount amount_msat = 2;
optional Amount maxfee = 3;
optional uint32 maxdelay = 4;
optional uint32 retry_for = 5;
optional string description = 6;
optional string label = 7;
optional bool dev_use_shadow = 8;
}
message RenepayResponse {
// RenePay.status
enum RenepayStatus {
COMPLETE = 0;
PENDING = 1;
FAILED = 2;
}
bytes payment_preimage = 1;
bytes payment_hash = 2;
double created_at = 3;
uint32 parts = 4;
Amount amount_msat = 5;
Amount amount_sent_msat = 6;
RenepayStatus status = 7;
optional bytes destination = 8;
}
message SendcustommsgRequest {
bytes node_id = 1;
bytes msg = 2;

View file

@ -2132,6 +2132,22 @@ impl From<responses::PluginResponse> for pb::PluginResponse {
}
}
#[allow(unused_variables)]
impl From<responses::RenepayResponse> for pb::RenepayResponse {
fn from(c: responses::RenepayResponse) -> Self {
Self {
amount_msat: Some(c.amount_msat.into()), // Rule #2 for type msat
amount_sent_msat: Some(c.amount_sent_msat.into()), // Rule #2 for type msat
created_at: c.created_at, // Rule #2 for type number
destination: c.destination.map(|v| v.serialize().to_vec()), // Rule #2 for type pubkey?
parts: c.parts, // Rule #2 for type u32
payment_hash: <Sha256 as AsRef<[u8]>>::as_ref(&c.payment_hash).to_vec(), // Rule #2 for type hash
payment_preimage: c.payment_preimage.to_vec(), // Rule #2 for type secret
status: c.status as i32,
}
}
}
#[allow(unused_variables)]
impl From<responses::SendcustommsgResponse> for pb::SendcustommsgResponse {
fn from(c: responses::SendcustommsgResponse) -> Self {
@ -3340,6 +3356,22 @@ impl From<requests::PluginRequest> for pb::PluginRequest {
}
}
#[allow(unused_variables)]
impl From<requests::RenepayRequest> for pb::RenepayRequest {
fn from(c: requests::RenepayRequest) -> Self {
Self {
amount_msat: c.amount_msat.map(|f| f.into()), // Rule #2 for type msat?
description: c.description, // Rule #2 for type string?
dev_use_shadow: c.dev_use_shadow, // Rule #2 for type boolean?
invstring: c.invstring, // Rule #2 for type string
label: c.label, // Rule #2 for type string?
maxdelay: c.maxdelay, // Rule #2 for type u32?
maxfee: c.maxfee.map(|f| f.into()), // Rule #2 for type msat?
retry_for: c.retry_for, // Rule #2 for type u32?
}
}
}
#[allow(unused_variables)]
impl From<requests::SendcustommsgRequest> for pb::SendcustommsgRequest {
fn from(c: requests::SendcustommsgRequest) -> Self {
@ -4362,6 +4394,22 @@ impl From<pb::PluginRequest> for requests::PluginRequest {
}
}
#[allow(unused_variables)]
impl From<pb::RenepayRequest> for requests::RenepayRequest {
fn from(c: pb::RenepayRequest) -> Self {
Self {
amount_msat: c.amount_msat.map(|a| a.into()), // Rule #1 for type msat?
description: c.description, // Rule #1 for type string?
dev_use_shadow: c.dev_use_shadow, // Rule #1 for type boolean?
invstring: c.invstring, // Rule #1 for type string
label: c.label, // Rule #1 for type string?
maxdelay: c.maxdelay, // Rule #1 for type u32?
maxfee: c.maxfee.map(|a| a.into()), // Rule #1 for type msat?
retry_for: c.retry_for, // Rule #1 for type u32?
}
}
}
#[allow(unused_variables)]
impl From<pb::SendcustommsgRequest> for requests::SendcustommsgRequest {
fn from(c: pb::SendcustommsgRequest) -> Self {

View file

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

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

@ -87,6 +87,7 @@ pub enum Request {
OpenChannel_Update(requests::Openchannel_updateRequest),
Ping(requests::PingRequest),
Plugin(requests::PluginRequest),
RenePay(requests::RenepayRequest),
SendCustomMsg(requests::SendcustommsgRequest),
SetChannel(requests::SetchannelRequest),
SignInvoice(requests::SigninvoiceRequest),
@ -185,6 +186,7 @@ pub enum Response {
OpenChannel_Update(responses::Openchannel_updateResponse),
Ping(responses::PingResponse),
Plugin(responses::PluginResponse),
RenePay(responses::RenepayResponse),
SendCustomMsg(responses::SendcustommsgResponse),
SetChannel(responses::SetchannelResponse),
SignInvoice(responses::SigninvoiceResponse),
@ -2634,6 +2636,42 @@ pub mod requests {
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct RenepayRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub amount_msat: Option<Amount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub dev_use_shadow: Option<bool>,
#[serde(skip_serializing_if = "Option::is_none")]
pub label: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub maxdelay: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
pub maxfee: Option<Amount>,
#[serde(skip_serializing_if = "Option::is_none")]
pub retry_for: Option<u32>,
pub invstring: String,
}
impl From<RenepayRequest> for Request {
fn from(r: RenepayRequest) -> Self {
Request::RenePay(r)
}
}
impl IntoRequest for RenepayRequest {
type Response = super::responses::RenepayResponse;
}
impl TypedRequest for RenepayRequest {
type Response = super::responses::RenepayResponse;
fn method(&self) -> &str {
"renepay"
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SendcustommsgRequest {
pub msg: String,
pub node_id: PublicKey,
@ -7060,6 +7098,64 @@ pub mod responses {
}
}
/// ['Status of payment.']
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub enum RenepayStatus {
#[serde(rename = "complete")]
COMPLETE = 0,
#[serde(rename = "pending")]
PENDING = 1,
#[serde(rename = "failed")]
FAILED = 2,
}
impl TryFrom<i32> for RenepayStatus {
type Error = anyhow::Error;
fn try_from(c: i32) -> Result<RenepayStatus, anyhow::Error> {
match c {
0 => Ok(RenepayStatus::COMPLETE),
1 => Ok(RenepayStatus::PENDING),
2 => Ok(RenepayStatus::FAILED),
o => Err(anyhow::anyhow!("Unknown variant {} for enum RenepayStatus", o)),
}
}
}
impl ToString for RenepayStatus {
fn to_string(&self) -> String {
match self {
RenepayStatus::COMPLETE => "COMPLETE",
RenepayStatus::PENDING => "PENDING",
RenepayStatus::FAILED => "FAILED",
}.to_string()
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct RenepayResponse {
#[serde(skip_serializing_if = "Option::is_none")]
pub destination: Option<PublicKey>,
// Path `RenePay.status`
pub status: RenepayStatus,
pub amount_msat: Amount,
pub amount_sent_msat: Amount,
pub created_at: f64,
pub parts: u32,
pub payment_hash: Sha256,
pub payment_preimage: Secret,
}
impl TryFrom<Response> for RenepayResponse {
type Error = super::TryFromResponseError;
fn try_from(response: Response) -> Result<Self, Self::Error> {
match response {
Response::RenePay(response) => Ok(response),
_ => Err(TryFromResponseError)
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SendcustommsgResponse {
pub status: String,

View file

@ -129,6 +129,7 @@ def load_jsonrpc_service():
# "parsefeerate",
"Ping",
"Plugin",
"RenePay",
# "reserveinputs",
"SendCustomMsg",
# "sendinvoice",

File diff suppressed because one or more lines are too long

View file

@ -354,6 +354,11 @@ class NodeStub(object):
request_serializer=node__pb2.PluginRequest.SerializeToString,
response_deserializer=node__pb2.PluginResponse.FromString,
)
self.RenePay = channel.unary_unary(
'/cln.Node/RenePay',
request_serializer=node__pb2.RenepayRequest.SerializeToString,
response_deserializer=node__pb2.RenepayResponse.FromString,
)
self.SendCustomMsg = channel.unary_unary(
'/cln.Node/SendCustomMsg',
request_serializer=node__pb2.SendcustommsgRequest.SerializeToString,
@ -847,6 +852,12 @@ class NodeServicer(object):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def RenePay(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 SendCustomMsg(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
@ -1286,6 +1297,11 @@ def add_NodeServicer_to_server(servicer, server):
request_deserializer=node__pb2.PluginRequest.FromString,
response_serializer=node__pb2.PluginResponse.SerializeToString,
),
'RenePay': grpc.unary_unary_rpc_method_handler(
servicer.RenePay,
request_deserializer=node__pb2.RenepayRequest.FromString,
response_serializer=node__pb2.RenepayResponse.SerializeToString,
),
'SendCustomMsg': grpc.unary_unary_rpc_method_handler(
servicer.SendCustomMsg,
request_deserializer=node__pb2.SendcustommsgRequest.FromString,
@ -2532,6 +2548,23 @@ class Node(object):
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def RenePay(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/RenePay',
node__pb2.RenepayRequest.SerializeToString,
node__pb2.RenepayResponse.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def SendCustomMsg(request,
target,

View file

@ -1715,6 +1715,19 @@ def plugin2py(m):
})
def renepay2py(m):
return remove_default({
"status": str(m.status), # EnumField in generate_composite
"amount_msat": amount2msat(m.amount_msat), # PrimitiveField in generate_composite
"amount_sent_msat": amount2msat(m.amount_sent_msat), # PrimitiveField in generate_composite
"created_at": m.created_at, # PrimitiveField in generate_composite
"destination": hexlify(m.destination), # PrimitiveField in generate_composite
"parts": m.parts, # PrimitiveField in generate_composite
"payment_hash": hexlify(m.payment_hash), # PrimitiveField in generate_composite
"payment_preimage": hexlify(m.payment_preimage), # PrimitiveField in generate_composite
})
def sendcustommsg2py(m):
return remove_default({
"status": m.status, # PrimitiveField in generate_composite