added listhtlcs model

This commit is contained in:
ff 2023-02-15 22:16:20 +01:00 committed by Rusty Russell
parent 5f653780f5
commit 6920e36135
12 changed files with 354 additions and 37 deletions

View file

@ -102,6 +102,32 @@
"spent": 2,
"unconfirmed": 0
},
"ListhtlcsHtlcsDirection": {
"in": 1,
"out": 0
},
"ListhtlcsHtlcsState": {
"RCVD_ADD_ACK_COMMIT": 3,
"RCVD_ADD_ACK_REVOCATION": 14,
"RCVD_ADD_COMMIT": 11,
"RCVD_ADD_HTLC": 10,
"RCVD_ADD_REVOCATION": 2,
"RCVD_REMOVE_ACK_COMMIT": 18,
"RCVD_REMOVE_ACK_REVOCATION": 9,
"RCVD_REMOVE_COMMIT": 6,
"RCVD_REMOVE_HTLC": 5,
"RCVD_REMOVE_REVOCATION": 17,
"SENT_ADD_ACK_COMMIT": 13,
"SENT_ADD_ACK_REVOCATION": 4,
"SENT_ADD_COMMIT": 1,
"SENT_ADD_HTLC": 0,
"SENT_ADD_REVOCATION": 12,
"SENT_REMOVE_ACK_COMMIT": 8,
"SENT_REMOVE_ACK_REVOCATION": 19,
"SENT_REMOVE_COMMIT": 16,
"SENT_REMOVE_HTLC": 15,
"SENT_REMOVE_REVOCATION": 7
},
"ListinvoicesIndex": {
"created": 0,
"updated": 1
@ -925,6 +951,21 @@
"ListFunds.channels[]": 2,
"ListFunds.outputs[]": 1
},
"ListhtlcsHtlcs": {
"ListHtlcs.htlcs[].amount_msat": 4,
"ListHtlcs.htlcs[].direction": 5,
"ListHtlcs.htlcs[].expiry": 3,
"ListHtlcs.htlcs[].id": 2,
"ListHtlcs.htlcs[].payment_hash": 6,
"ListHtlcs.htlcs[].short_channel_id": 1,
"ListHtlcs.htlcs[].state": 7
},
"ListhtlcsRequest": {
"ListHtlcs.id": 1
},
"ListhtlcsResponse": {
"ListHtlcs.htlcs[]": 1
},
"ListinvoicesInvoices": {
"ListInvoices.invoices[].amount_msat": 6,
"ListInvoices.invoices[].amount_received_msat": 12,
@ -3577,6 +3618,46 @@
"added": "pre-v0.10.1",
"deprecated": false
},
"ListHtlcs": {
"added": "v23.02",
"deprecated": null
},
"ListHtlcs.htlcs[]": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListHtlcs.htlcs[].amount_msat": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListHtlcs.htlcs[].direction": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListHtlcs.htlcs[].expiry": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListHtlcs.htlcs[].id": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListHtlcs.htlcs[].payment_hash": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListHtlcs.htlcs[].short_channel_id": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListHtlcs.htlcs[].state": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListHtlcs.id": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListInvoices": {
"added": "pre-v0.10.1",
"deprecated": null

View file

@ -55,6 +55,7 @@ service Node {
rpc GetRoute(GetrouteRequest) returns (GetrouteResponse) {}
rpc ListForwards(ListforwardsRequest) returns (ListforwardsResponse) {}
rpc ListPays(ListpaysRequest) returns (ListpaysResponse) {}
rpc ListHtlcs(ListhtlcsRequest) returns (ListhtlcsResponse) {}
rpc Ping(PingRequest) returns (PingResponse) {}
rpc SendCustomMsg(SendcustommsgRequest) returns (SendcustommsgResponse) {}
rpc SetChannel(SetchannelRequest) returns (SetchannelResponse) {}
@ -1631,6 +1632,29 @@ message ListpaysPays {
optional bytes erroronion = 10;
}
message ListhtlcsRequest {
optional string id = 1;
}
message ListhtlcsResponse {
repeated ListhtlcsHtlcs htlcs = 1;
}
message ListhtlcsHtlcs {
// ListHtlcs.htlcs[].direction
enum ListhtlcsHtlcsDirection {
OUT = 0;
IN = 1;
}
string short_channel_id = 1;
uint64 id = 2;
uint32 expiry = 3;
Amount amount_msat = 4;
ListhtlcsHtlcsDirection direction = 5;
bytes payment_hash = 6;
HtlcState state = 7;
}
message PingRequest {
bytes id = 1;
optional uint32 len = 2;

View file

@ -1504,6 +1504,31 @@ impl From<responses::ListpaysResponse> for pb::ListpaysResponse {
}
}
#[allow(unused_variables)]
impl From<responses::ListhtlcsHtlcs> for pb::ListhtlcsHtlcs {
fn from(c: responses::ListhtlcsHtlcs) -> Self {
Self {
short_channel_id: c.short_channel_id.to_string(), // Rule #2 for type short_channel_id
id: c.id, // Rule #2 for type u64
expiry: c.expiry, // Rule #2 for type u32
amount_msat: Some(c.amount_msat.into()), // Rule #2 for type msat
direction: c.direction as i32,
payment_hash: c.payment_hash.to_vec(), // Rule #2 for type hash
state: c.state as i32,
}
}
}
#[allow(unused_variables)]
impl From<responses::ListhtlcsResponse> for pb::ListhtlcsResponse {
fn from(c: responses::ListhtlcsResponse) -> Self {
Self {
// Field: ListHtlcs.htlcs[]
htlcs: c.htlcs.into_iter().map(|i| i.into()).collect(), // Rule #3 for type ListhtlcsHtlcs
}
}
}
#[allow(unused_variables)]
impl From<responses::PingResponse> for pb::PingResponse {
fn from(c: responses::PingResponse) -> Self {
@ -2197,6 +2222,15 @@ impl From<requests::ListpaysRequest> for pb::ListpaysRequest {
}
}
#[allow(unused_variables)]
impl From<requests::ListhtlcsRequest> for pb::ListhtlcsRequest {
fn from(c: requests::ListhtlcsRequest) -> Self {
Self {
id: c.id, // Rule #2 for type string?
}
}
}
#[allow(unused_variables)]
impl From<requests::PingRequest> for pb::PingRequest {
fn from(c: requests::PingRequest) -> Self {
@ -2867,6 +2901,15 @@ impl From<pb::ListpaysRequest> for requests::ListpaysRequest {
}
}
#[allow(unused_variables)]
impl From<pb::ListhtlcsRequest> for requests::ListhtlcsRequest {
fn from(c: pb::ListhtlcsRequest) -> Self {
Self {
id: c.id, // Rule #1 for type string?
}
}
}
#[allow(unused_variables)]
impl From<pb::PingRequest> for requests::PingRequest {
fn from(c: pb::PingRequest) -> Self {

View file

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

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

@ -61,6 +61,7 @@ pub enum Request {
GetRoute(requests::GetrouteRequest),
ListForwards(requests::ListforwardsRequest),
ListPays(requests::ListpaysRequest),
ListHtlcs(requests::ListhtlcsRequest),
Ping(requests::PingRequest),
SendCustomMsg(requests::SendcustommsgRequest),
SetChannel(requests::SetchannelRequest),
@ -122,6 +123,7 @@ pub enum Response {
GetRoute(responses::GetrouteResponse),
ListForwards(responses::ListforwardsResponse),
ListPays(responses::ListpaysResponse),
ListHtlcs(responses::ListhtlcsResponse),
Ping(responses::PingResponse),
SendCustomMsg(responses::SendcustommsgResponse),
SetChannel(responses::SetchannelResponse),
@ -1395,6 +1397,22 @@ pub mod requests {
type Response = super::responses::ListpaysResponse;
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ListhtlcsRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<String>,
}
impl From<ListhtlcsRequest> for Request {
fn from(r: ListhtlcsRequest) -> Self {
Request::ListHtlcs(r)
}
}
impl IntoRequest for ListhtlcsRequest {
type Response = super::responses::ListhtlcsResponse;
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PingRequest {
pub id: PublicKey,
@ -4667,6 +4685,64 @@ pub mod responses {
}
}
/// out if we offered this to the peer, in if they offered it
#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]
pub enum ListhtlcsHtlcsDirection {
#[serde(rename = "out")]
OUT,
#[serde(rename = "in")]
IN,
}
impl TryFrom<i32> for ListhtlcsHtlcsDirection {
type Error = anyhow::Error;
fn try_from(c: i32) -> Result<ListhtlcsHtlcsDirection, anyhow::Error> {
match c {
0 => Ok(ListhtlcsHtlcsDirection::OUT),
1 => Ok(ListhtlcsHtlcsDirection::IN),
o => Err(anyhow::anyhow!("Unknown variant {} for enum ListhtlcsHtlcsDirection", o)),
}
}
}
impl ToString for ListhtlcsHtlcsDirection {
fn to_string(&self) -> String {
match self {
ListhtlcsHtlcsDirection::OUT => "OUT",
ListhtlcsHtlcsDirection::IN => "IN",
}.to_string()
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ListhtlcsHtlcs {
pub short_channel_id: ShortChannelId,
pub id: u64,
pub expiry: u32,
pub amount_msat: Amount,
// Path `ListHtlcs.htlcs[].direction`
pub direction: ListhtlcsHtlcsDirection,
pub payment_hash: Sha256,
// Path `ListHtlcs.htlcs[].state`
pub state: HtlcState,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ListhtlcsResponse {
pub htlcs: Vec<ListhtlcsHtlcs>,
}
impl TryFrom<Response> for ListhtlcsResponse {
type Error = super::TryFromResponseError;
fn try_from(response: Response) -> Result<Self, Self::Error> {
match response {
Response::ListHtlcs(response) => Ok(response),
_ => Err(TryFromResponseError)
}
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct PingResponse {
pub totlen: u16,

BIN
contrib/msggen/dist/msggen-0.1.0.tar.gz vendored Normal file

Binary file not shown.

View file

View file

@ -177,6 +177,7 @@ class OverridePatch(Patch):
'ListPeers.peers[].channels[].state_changes[].old_state': "ChannelState",
'ListPeers.peers[].channels[].htlcs[].state': "HtlcState",
'ListPeerChannels.channels[].htlcs[].state': "HtlcState",
'ListHtlcs.htlcs[].state': "HtlcState",
}
def visit(self, f: model.Field) -> None:

View file

@ -83,6 +83,7 @@ def load_jsonrpc_service(schema_dir: str):
"ListForwards",
# "listoffers",
"ListPays",
"ListHtlcs",
# "multifundchannel",
# "multiwithdraw",
# "offer",

File diff suppressed because one or more lines are too long

View file

@ -249,6 +249,11 @@ class NodeStub(object):
request_serializer=node__pb2.ListpaysRequest.SerializeToString,
response_deserializer=node__pb2.ListpaysResponse.FromString,
)
self.ListHtlcs = channel.unary_unary(
'/cln.Node/ListHtlcs',
request_serializer=node__pb2.ListhtlcsRequest.SerializeToString,
response_deserializer=node__pb2.ListhtlcsResponse.FromString,
)
self.Ping = channel.unary_unary(
'/cln.Node/Ping',
request_serializer=node__pb2.PingRequest.SerializeToString,
@ -576,6 +581,12 @@ class NodeServicer(object):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def ListHtlcs(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 Ping(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
@ -862,6 +873,11 @@ def add_NodeServicer_to_server(servicer, server):
request_deserializer=node__pb2.ListpaysRequest.FromString,
response_serializer=node__pb2.ListpaysResponse.SerializeToString,
),
'ListHtlcs': grpc.unary_unary_rpc_method_handler(
servicer.ListHtlcs,
request_deserializer=node__pb2.ListhtlcsRequest.FromString,
response_serializer=node__pb2.ListhtlcsResponse.SerializeToString,
),
'Ping': grpc.unary_unary_rpc_method_handler(
servicer.Ping,
request_deserializer=node__pb2.PingRequest.FromString,
@ -1711,6 +1727,23 @@ class Node(object):
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def ListHtlcs(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/ListHtlcs',
node__pb2.ListhtlcsRequest.SerializeToString,
node__pb2.ListhtlcsResponse.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def Ping(request,
target,

View file

@ -1289,6 +1289,24 @@ def listpays2py(m):
})
def listhtlcs_htlcs2py(m):
return remove_default({
"short_channel_id": m.short_channel_id, # PrimitiveField in generate_composite
"id": m.id, # PrimitiveField in generate_composite
"expiry": m.expiry, # PrimitiveField in generate_composite
"amount_msat": amount2msat(m.amount_msat), # PrimitiveField in generate_composite
"direction": str(m.direction), # EnumField in generate_composite
"payment_hash": hexlify(m.payment_hash), # PrimitiveField in generate_composite
"state": str(m.state), # EnumField in generate_composite
})
def listhtlcs2py(m):
return remove_default({
"htlcs": [listhtlcs_htlcs2py(i) for i in m.htlcs], # ArrayField[composite] in generate_composite
})
def ping2py(m):
return remove_default({
"totlen": m.totlen, # PrimitiveField in generate_composite