Skip to content

Commit

Permalink
grpc: Add WaitBlockHeight method to grpc interface
Browse files Browse the repository at this point in the history
  • Loading branch information
cdecker authored and rustyrussell committed Oct 23, 2023
1 parent 76c5e6a commit dfea5fb
Show file tree
Hide file tree
Showing 12 changed files with 255 additions and 21 deletions.
19 changes: 19 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -1579,6 +1579,13 @@
"WaitAnyInvoice.status": 4,
"WaitAnyInvoice.updated_index": 14
},
"WaitblockheightRequest": {
"WaitBlockHeight.blockheight": 1,
"WaitBlockHeight.timeout": 2
},
"WaitblockheightResponse": {
"WaitBlockHeight.blockheight": 1
},
"WaitinvoiceRequest": {
"WaitInvoice.label": 1
},
Expand Down Expand Up @@ -5518,6 +5525,18 @@
"added": "v23.08",
"deprecated": false
},
"WaitBlockHeight": {
"added": "pre-v0.10.1",
"deprecated": null
},
"WaitBlockHeight.blockheight": {
"added": "pre-v0.10.1",
"deprecated": false
},
"WaitBlockHeight.timeout": {
"added": "pre-v0.10.1",
"deprecated": false
},
"WaitInvoice": {
"added": "pre-v0.10.1",
"deprecated": null
Expand Down
10 changes: 10 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.

29 changes: 29 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 @@ -1722,6 +1722,38 @@ async fn sign_message(

}

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

}

async fn stop(
&self,
request: tonic::Request<pb::StopRequest>,
Expand Down
48 changes: 47 additions & 1 deletion cln-grpc/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::pb::*;
use serde_json::json;

#[test]
Expand Down Expand Up @@ -246,14 +247,57 @@ fn test_getinfo() {
"network": "regtest",
"fees_collected_msat": "0msat", "lightning-dir": "/tmp/ltests-20irp76f/test_pay_variants_1/lightning-1/regtest",
"our_features": {"init": "8808226aa2", "node": "80008808226aa2", "channel": "", "invoice": "024200"}});
let _u: cln_rpc::model::responses::GetinfoResponse = serde_json::from_value(j.clone()).unwrap();
let u: cln_rpc::model::responses::GetinfoResponse = serde_json::from_value(j.clone()).unwrap();
let _g: GetinfoResponse = u.into();
//let u2: cln_rpc::model::GetinfoResponse = g.into();
//let j2 = serde_json::to_value(u2).unwrap();
//assert_eq!(j, j2);
}

#[test]
fn test_keysend() {
let g =
KeysendRequest {
destination: hex::decode(
"035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
)
.unwrap(),
amount_msat: Some(Amount { msat: 10000 }),

label: Some("hello".to_string()),
exemptfee: None,
maxdelay: None,
retry_for: None,
maxfeepercent: None,
routehints: Some(RoutehintList {
hints: vec![Routehint {
hops: vec![RouteHop {
id: hex::decode(
"035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
)
.unwrap(),
short_channel_id: "12345x678x90".to_string(),
feebase: Some(Amount { msat: 123 }),
feeprop: 1234,
expirydelta: 9,
},RouteHop {
id: hex::decode(
"035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
)
.unwrap(),
short_channel_id: "12345x678x90".to_string(),
feebase: Some(Amount { msat: 123 }),
feeprop: 1234,
expirydelta: 9,
}],
}],
}),
extratlvs: None,
};

let u: cln_rpc::model::requests::KeysendRequest = g.into();
let _ser = serde_json::to_string(&u);

let j = r#"{
"destination": "035d2b1192dfba134e10e540875d366ebc8bc353d5aa766b80c090b39c3a5d885d",
"payment_hash": "e74b03a98453dcb5a7ed5406b97ec3566dde4be85ef71685110f4c0ebc600592",
Expand All @@ -267,6 +311,8 @@ fn test_keysend() {
"status": "complete"
}"#;
let u: cln_rpc::model::responses::KeysendResponse = serde_json::from_str(j).unwrap();
let g: KeysendResponse = u.clone().into();
println!("{:?}", g);

let v: serde_json::Value = serde_json::to_value(u.clone()).unwrap();
let g: cln_rpc::model::responses::KeysendResponse = u.into();
Expand Down
35 changes: 35 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 @@ -103,7 +103,7 @@ def load_jsonrpc_service(schema_dir: str):
"SignInvoice",
"SignMessage",
# "unreserveinputs",
# "waitblockheight",
"WaitBlockHeight",
# "ListConfigs",
# "check", # No point in mapping this one
"Stop",
Expand Down
43 changes: 24 additions & 19 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 @@ -279,6 +279,11 @@ def __init__(self, channel):
request_serializer=node__pb2.SignmessageRequest.SerializeToString,
response_deserializer=node__pb2.SignmessageResponse.FromString,
)
self.WaitBlockHeight = channel.unary_unary(
'/cln.Node/WaitBlockHeight',
request_serializer=node__pb2.WaitblockheightRequest.SerializeToString,
response_deserializer=node__pb2.WaitblockheightResponse.FromString,
)
self.Stop = channel.unary_unary(
'/cln.Node/Stop',
request_serializer=node__pb2.StopRequest.SerializeToString,
Expand Down Expand Up @@ -622,6 +627,12 @@ def SignMessage(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def WaitBlockHeight(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 Stop(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
Expand Down Expand Up @@ -914,6 +925,11 @@ def add_NodeServicer_to_server(servicer, server):
request_deserializer=node__pb2.SignmessageRequest.FromString,
response_serializer=node__pb2.SignmessageResponse.SerializeToString,
),
'WaitBlockHeight': grpc.unary_unary_rpc_method_handler(
servicer.WaitBlockHeight,
request_deserializer=node__pb2.WaitblockheightRequest.FromString,
response_serializer=node__pb2.WaitblockheightResponse.SerializeToString,
),
'Stop': grpc.unary_unary_rpc_method_handler(
servicer.Stop,
request_deserializer=node__pb2.StopRequest.FromString,
Expand Down Expand Up @@ -1845,6 +1861,23 @@ def SignMessage(request,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

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

@staticmethod
def Stop(request,
target,
Expand Down
1 change: 1 addition & 0 deletions contrib/pyln-grpc-proto/pyln/grpc/primitives_pb2.py

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

6 changes: 6 additions & 0 deletions contrib/pyln-testing/pyln/testing/grpc2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -1358,6 +1358,12 @@ def signmessage2py(m):
})


def waitblockheight2py(m):
return remove_default({
"blockheight": m.blockheight, # PrimitiveField in generate_composite
})


def stop2py(m):
return remove_default({
})
Expand Down
18 changes: 18 additions & 0 deletions doc/schemas/waitblockheight.request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [
"blockheight"
],
"properties": {
"blockheight": {
"type": "u32",
"description": "The current block height (>= blockheight parameter)"
},
"timeout": {
"type": "u32",
"description": "If timeout seconds is reached without the specified blockheight being reached, this command will fail with a code of 2000."
}
}
}

0 comments on commit dfea5fb

Please sign in to comment.