Skip to content

Commit

Permalink
feat: added listoffers grpc command
Browse files Browse the repository at this point in the history
  • Loading branch information
vacwmX authored and cdecker committed Feb 7, 2024
1 parent d1052e3 commit 317cf4d
Show file tree
Hide file tree
Showing 10 changed files with 366 additions and 90 deletions.
55 changes: 55 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -1120,6 +1120,21 @@
"ListnodesResponse": {
"ListNodes.nodes[]": 1
},
"ListoffersOffers": {
"ListOffers.offers[].active": 2,
"ListOffers.offers[].bolt12": 4,
"ListOffers.offers[].label": 6,
"ListOffers.offers[].offer_id": 1,
"ListOffers.offers[].single_use": 3,
"ListOffers.offers[].used": 5
},
"ListoffersRequest": {
"ListOffers.active_only": 2,
"ListOffers.offer_id": 1
},
"ListoffersResponse": {
"ListOffers.offers[]": 1
},
"ListpaysPays": {
"ListPays.pays[].amount_msat": 8,
"ListPays.pays[].amount_sent_msat": 9,
Expand Down Expand Up @@ -4242,6 +4257,46 @@
"added": "pre-v0.10.1",
"deprecated": false
},
"ListOffers": {
"added": "pre-v0.10.1",
"deprecated": null
},
"ListOffers.active_only": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListOffers.offer_id": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListOffers.offers[]": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListOffers.offers[].active": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListOffers.offers[].bolt12": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListOffers.offers[].label": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListOffers.offers[].offer_id": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListOffers.offers[].single_use": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListOffers.offers[].used": {
"added": "pre-v0.10.1",
"deprecated": false
},
"ListPays": {
"added": "pre-v0.10.1",
"deprecated": null
Expand Down
19 changes: 19 additions & 0 deletions cln-grpc/proto/node.proto

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 44 additions & 0 deletions cln-grpc/src/convert.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions cln-grpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,38 @@ async fn list_forwards(

}

async fn list_offers(
&self,
request: tonic::Request<pb::ListoffersRequest>,
) -> Result<tonic::Response<pb::ListoffersResponse>, tonic::Status> {
let req = request.into_inner();
let req: requests::ListoffersRequest = req.into();
debug!("Client asked for list_offers");
trace!("list_offers 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::ListOffers(req))
.await
.map_err(|e| Status::new(
Code::Unknown,
format!("Error calling method ListOffers: {:?}", e)))?;
match result {
Response::ListOffers(r) => {
trace!("list_offers response: {:?}", r);
Ok(tonic::Response::new(r.into()))
},
r => Err(Status::new(
Code::Internal,
format!(
"Unexpected result {:?} to method call ListOffers",
r
)
)),
}

}

async fn list_pays(
&self,
request: tonic::Request<pb::ListpaysRequest>,
Expand Down
54 changes: 54 additions & 0 deletions cln-rpc/src/model.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion contrib/msggen/msggen/utils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def load_jsonrpc_service(schema_dir: str):
# "getlog",
"GetRoute",
"ListForwards",
# "listoffers",
"ListOffers",
"ListPays",
"ListHtlcs",
# "multifundchannel",
Expand Down
184 changes: 95 additions & 89 deletions contrib/pyln-grpc-proto/pyln/grpc/node_pb2.py

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions contrib/pyln-grpc-proto/pyln/grpc/node_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ def __init__(self, channel):
request_serializer=node__pb2.ListforwardsRequest.SerializeToString,
response_deserializer=node__pb2.ListforwardsResponse.FromString,
)
self.ListOffers = channel.unary_unary(
'/cln.Node/ListOffers',
request_serializer=node__pb2.ListoffersRequest.SerializeToString,
response_deserializer=node__pb2.ListoffersResponse.FromString,
)
self.ListPays = channel.unary_unary(
'/cln.Node/ListPays',
request_serializer=node__pb2.ListpaysRequest.SerializeToString,
Expand Down Expand Up @@ -622,6 +627,12 @@ def ListForwards(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def ListOffers(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 ListPays(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
Expand Down Expand Up @@ -955,6 +966,11 @@ def add_NodeServicer_to_server(servicer, server):
request_deserializer=node__pb2.ListforwardsRequest.FromString,
response_serializer=node__pb2.ListforwardsResponse.SerializeToString,
),
'ListOffers': grpc.unary_unary_rpc_method_handler(
servicer.ListOffers,
request_deserializer=node__pb2.ListoffersRequest.FromString,
response_serializer=node__pb2.ListoffersResponse.SerializeToString,
),
'ListPays': grpc.unary_unary_rpc_method_handler(
servicer.ListPays,
request_deserializer=node__pb2.ListpaysRequest.FromString,
Expand Down Expand Up @@ -1856,6 +1872,23 @@ def ListForwards(request,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

@staticmethod
def ListOffers(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/ListOffers',
node__pb2.ListoffersRequest.SerializeToString,
node__pb2.ListoffersResponse.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

@staticmethod
def ListPays(request,
target,
Expand Down
17 changes: 17 additions & 0 deletions contrib/pyln-testing/pyln/testing/grpc2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -1378,6 +1378,23 @@ def listforwards2py(m):
})


def listoffers_offers2py(m):
return remove_default({
"offer_id": hexlify(m.offer_id), # PrimitiveField in generate_composite
"active": m.active, # PrimitiveField in generate_composite
"single_use": m.single_use, # PrimitiveField in generate_composite
"bolt12": m.bolt12, # PrimitiveField in generate_composite
"used": m.used, # PrimitiveField in generate_composite
"label": m.label, # PrimitiveField in generate_composite
})


def listoffers2py(m):
return remove_default({
"offers": [listoffers_offers2py(i) for i in m.offers], # ArrayField[composite] in generate_composite
})


def listpays_pays2py(m):
return remove_default({
"payment_hash": hexlify(m.payment_hash), # PrimitiveField in generate_composite
Expand Down
16 changes: 16 additions & 0 deletions doc/schemas/listoffers.request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"required": [],
"additionalProperties": false,
"properties": {
"offer_id": {
"type": "hash",
"description": "Only return offers matching this ID"
},
"active_only": {
"type": "boolean",
"description": "f active_only is set and is true, only offers with active true are returned."
}
}
}

0 comments on commit 317cf4d

Please sign in to comment.