Skip to content

Commit 77f5eb5

Browse files
cdeckerrustyrussell
authored andcommitted
msggen: Add fundchannel request
1 parent b8bcc7d commit 77f5eb5

File tree

10 files changed

+295
-42
lines changed

10 files changed

+295
-42
lines changed

.msggen.json

+20
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,26 @@
381381
"Feerates.perkw": 3,
382382
"Feerates.warning_missing_feerates": 1
383383
},
384+
"FundchannelRequest": {
385+
"FundChannel.amount": 1,
386+
"FundChannel.announce": 3,
387+
"FundChannel.close_to": 6,
388+
"FundChannel.compact_lease": 8,
389+
"FundChannel.feerate": 2,
390+
"FundChannel.id": 9,
391+
"FundChannel.minconf": 10,
392+
"FundChannel.minconf[]": 4,
393+
"FundChannel.push_msat": 5,
394+
"FundChannel.request_amt": 7,
395+
"FundChannel.utxos[]": 11
396+
},
397+
"FundchannelResponse": {
398+
"FundChannel.channel_id": 4,
399+
"FundChannel.close_to": 5,
400+
"FundChannel.outnum": 3,
401+
"FundChannel.tx": 1,
402+
"FundChannel.txid": 2
403+
},
384404
"FundpsbtRequest": {
385405
"FundPsbt.excess_as_change": 8,
386406
"FundPsbt.feerate": 2,

cln-grpc/proto/node.proto

+22
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ service Node {
4747
rpc TxSend(TxsendRequest) returns (TxsendResponse) {}
4848
rpc Disconnect(DisconnectRequest) returns (DisconnectResponse) {}
4949
rpc Feerates(FeeratesRequest) returns (FeeratesResponse) {}
50+
rpc FundChannel(FundchannelRequest) returns (FundchannelResponse) {}
5051
rpc GetRoute(GetrouteRequest) returns (GetrouteResponse) {}
5152
rpc ListForwards(ListforwardsRequest) returns (ListforwardsResponse) {}
5253
rpc ListPays(ListpaysRequest) returns (ListpaysResponse) {}
@@ -1138,6 +1139,27 @@ message FeeratesOnchain_fee_estimates {
11381139
uint64 htlc_success_satoshis = 5;
11391140
}
11401141

1142+
message FundchannelRequest {
1143+
bytes id = 9;
1144+
AmountOrAll amount = 1;
1145+
optional Feerate feerate = 2;
1146+
optional bool announce = 3;
1147+
optional double minconf = 10;
1148+
optional Amount push_msat = 5;
1149+
optional string close_to = 6;
1150+
optional Amount request_amt = 7;
1151+
optional string compact_lease = 8;
1152+
repeated Outpoint utxos = 11;
1153+
}
1154+
1155+
message FundchannelResponse {
1156+
bytes tx = 1;
1157+
bytes txid = 2;
1158+
uint32 outnum = 3;
1159+
bytes channel_id = 4;
1160+
optional bytes close_to = 5;
1161+
}
1162+
11411163
message GetrouteRequest {
11421164
bytes id = 1;
11431165
Amount amount_msat = 9;

cln-grpc/src/convert.rs

+31
Original file line numberDiff line numberDiff line change
@@ -853,6 +853,19 @@ impl From<&responses::FeeratesResponse> for pb::FeeratesResponse {
853853
}
854854
}
855855

856+
#[allow(unused_variables)]
857+
impl From<&responses::FundchannelResponse> for pb::FundchannelResponse {
858+
fn from(c: &responses::FundchannelResponse) -> Self {
859+
Self {
860+
tx: hex::decode(&c.tx).unwrap(), // Rule #2 for type hex
861+
txid: hex::decode(&c.txid).unwrap(), // Rule #2 for type txid
862+
outnum: c.outnum.clone(), // Rule #2 for type u32
863+
channel_id: hex::decode(&c.channel_id).unwrap(), // Rule #2 for type hex
864+
close_to: c.close_to.as_ref().map(|v| hex::decode(&v).unwrap()), // Rule #2 for type hex?
865+
}
866+
}
867+
}
868+
856869
#[allow(unused_variables)]
857870
impl From<&responses::GetrouteRoute> for pb::GetrouteRoute {
858871
fn from(c: &responses::GetrouteRoute) -> Self {
@@ -1424,6 +1437,24 @@ impl From<&pb::FeeratesRequest> for requests::FeeratesRequest {
14241437
}
14251438
}
14261439

1440+
#[allow(unused_variables)]
1441+
impl From<&pb::FundchannelRequest> for requests::FundchannelRequest {
1442+
fn from(c: &pb::FundchannelRequest) -> Self {
1443+
Self {
1444+
id: cln_rpc::primitives::Pubkey::from_slice(&c.id).unwrap(), // Rule #1 for type pubkey
1445+
amount: c.amount.as_ref().unwrap().into(), // Rule #1 for type msat_or_all
1446+
feerate: c.feerate.as_ref().map(|a| a.into()), // Rule #1 for type feerate?
1447+
announce: c.announce.clone(), // Rule #1 for type boolean?
1448+
minconf: c.minconf.clone(), // Rule #1 for type number?
1449+
push_msat: c.push_msat.as_ref().map(|a| a.into()), // Rule #1 for type msat?
1450+
close_to: c.close_to.clone(), // Rule #1 for type string?
1451+
request_amt: c.request_amt.as_ref().map(|a| a.into()), // Rule #1 for type msat?
1452+
compact_lease: c.compact_lease.clone(), // Rule #1 for type string?
1453+
utxos: Some(c.utxos.iter().map(|s| s.into()).collect()), // Rule #4
1454+
}
1455+
}
1456+
}
1457+
14271458
#[allow(unused_variables)]
14281459
impl From<&pb::GetrouteRequest> for requests::GetrouteRequest {
14291460
fn from(c: &pb::GetrouteRequest) -> Self {

cln-grpc/src/server.rs

+32
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,38 @@ async fn feerates(
12741274

12751275
}
12761276

1277+
async fn fund_channel(
1278+
&self,
1279+
request: tonic::Request<pb::FundchannelRequest>,
1280+
) -> Result<tonic::Response<pb::FundchannelResponse>, tonic::Status> {
1281+
let req = request.into_inner();
1282+
let req: requests::FundchannelRequest = (&req).into();
1283+
debug!("Client asked for fund_channel");
1284+
trace!("fund_channel request: {:?}", req);
1285+
let mut rpc = ClnRpc::new(&self.rpc_path)
1286+
.await
1287+
.map_err(|e| Status::new(Code::Internal, e.to_string()))?;
1288+
let result = rpc.call(Request::FundChannel(req))
1289+
.await
1290+
.map_err(|e| Status::new(
1291+
Code::Unknown,
1292+
format!("Error calling method FundChannel: {:?}", e)))?;
1293+
match result {
1294+
Response::FundChannel(r) => {
1295+
trace!("fund_channel response: {:?}", r);
1296+
Ok(tonic::Response::new((&r).into()))
1297+
},
1298+
r => Err(Status::new(
1299+
Code::Internal,
1300+
format!(
1301+
"Unexpected result {:?} to method call FundChannel",
1302+
r
1303+
)
1304+
)),
1305+
}
1306+
1307+
}
1308+
12771309
async fn get_route(
12781310
&self,
12791311
request: tonic::Request<pb::GetrouteRequest>,

cln-rpc/src/model.rs

+40
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ pub enum Request {
5555
TxSend(requests::TxsendRequest),
5656
Disconnect(requests::DisconnectRequest),
5757
Feerates(requests::FeeratesRequest),
58+
FundChannel(requests::FundchannelRequest),
5859
GetRoute(requests::GetrouteRequest),
5960
ListForwards(requests::ListforwardsRequest),
6061
ListPays(requests::ListpaysRequest),
@@ -105,6 +106,7 @@ pub enum Response {
105106
TxSend(responses::TxsendResponse),
106107
Disconnect(responses::DisconnectResponse),
107108
Feerates(responses::FeeratesResponse),
109+
FundChannel(responses::FundchannelResponse),
108110
GetRoute(responses::GetrouteResponse),
109111
ListForwards(responses::ListforwardsResponse),
110112
ListPays(responses::ListpaysResponse),
@@ -698,6 +700,30 @@ pub mod requests {
698700
pub style: FeeratesStyle,
699701
}
700702

703+
#[derive(Clone, Debug, Deserialize, Serialize)]
704+
pub struct FundchannelRequest {
705+
#[serde(alias = "id")]
706+
pub id: Pubkey,
707+
#[serde(alias = "amount")]
708+
pub amount: AmountOrAll,
709+
#[serde(alias = "feerate", skip_serializing_if = "Option::is_none")]
710+
pub feerate: Option<Feerate>,
711+
#[serde(alias = "announce", skip_serializing_if = "Option::is_none")]
712+
pub announce: Option<bool>,
713+
#[serde(alias = "minconf", skip_serializing_if = "Option::is_none")]
714+
pub minconf: Option<f64>,
715+
#[serde(alias = "push_msat", skip_serializing_if = "Option::is_none")]
716+
pub push_msat: Option<Amount>,
717+
#[serde(alias = "close_to", skip_serializing_if = "Option::is_none")]
718+
pub close_to: Option<String>,
719+
#[serde(alias = "request_amt", skip_serializing_if = "Option::is_none")]
720+
pub request_amt: Option<Amount>,
721+
#[serde(alias = "compact_lease", skip_serializing_if = "Option::is_none")]
722+
pub compact_lease: Option<String>,
723+
#[serde(alias = "utxos", skip_serializing_if = "Option::is_none")]
724+
pub utxos: Option<Vec<Outpoint>>,
725+
}
726+
701727
#[derive(Clone, Debug, Deserialize, Serialize)]
702728
pub struct GetrouteRequest {
703729
#[serde(alias = "id")]
@@ -2522,6 +2548,20 @@ pub mod responses {
25222548
pub warning_missing_feerates: Option<String>,
25232549
}
25242550

2551+
#[derive(Clone, Debug, Deserialize, Serialize)]
2552+
pub struct FundchannelResponse {
2553+
#[serde(alias = "tx")]
2554+
pub tx: String,
2555+
#[serde(alias = "txid")]
2556+
pub txid: String,
2557+
#[serde(alias = "outnum")]
2558+
pub outnum: u32,
2559+
#[serde(alias = "channel_id")]
2560+
pub channel_id: String,
2561+
#[serde(alias = "close_to", skip_serializing_if = "Option::is_none")]
2562+
pub close_to: Option<String>,
2563+
}
2564+
25252565
/// The features understood by the destination node
25262566
#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
25272567
pub enum GetrouteRouteStyle {

contrib/msggen/msggen/utils/utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ def load_jsonrpc_service(schema_dir: str = None):
8282
# "fetchinvoice",
8383
# "fundchannel_cancel",
8484
# "fundchannel_complete",
85-
# "fundchannel",
85+
"FundChannel",
8686
# "fundchannel_start",
8787
# "funderupdate",
8888
# "getlog",

contrib/pyln-testing/pyln/testing/grpc2py.py

+10
Original file line numberDiff line numberDiff line change
@@ -769,6 +769,16 @@ def feerates2py(m):
769769
})
770770

771771

772+
def fundchannel2py(m):
773+
return remove_default({
774+
"tx": hexlify(m.tx), # PrimitiveField in generate_composite
775+
"txid": hexlify(m.txid), # PrimitiveField in generate_composite
776+
"outnum": m.outnum, # PrimitiveField in generate_composite
777+
"channel_id": hexlify(m.channel_id), # PrimitiveField in generate_composite
778+
"close_to": hexlify(m.close_to), # PrimitiveField in generate_composite
779+
})
780+
781+
772782
def getroute_route2py(m):
773783
return remove_default({
774784
"id": hexlify(m.id), # PrimitiveField in generate_composite

contrib/pyln-testing/pyln/testing/node_pb2.py

+61-41
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

contrib/pyln-testing/pyln/testing/node_pb2_grpc.py

+33
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ def __init__(self, channel):
209209
request_serializer=node__pb2.FeeratesRequest.SerializeToString,
210210
response_deserializer=node__pb2.FeeratesResponse.FromString,
211211
)
212+
self.FundChannel = channel.unary_unary(
213+
'/cln.Node/FundChannel',
214+
request_serializer=node__pb2.FundchannelRequest.SerializeToString,
215+
response_deserializer=node__pb2.FundchannelResponse.FromString,
216+
)
212217
self.GetRoute = channel.unary_unary(
213218
'/cln.Node/GetRoute',
214219
request_serializer=node__pb2.GetrouteRequest.SerializeToString,
@@ -473,6 +478,12 @@ def Feerates(self, request, context):
473478
context.set_details('Method not implemented!')
474479
raise NotImplementedError('Method not implemented!')
475480

481+
def FundChannel(self, request, context):
482+
"""Missing associated documentation comment in .proto file."""
483+
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
484+
context.set_details('Method not implemented!')
485+
raise NotImplementedError('Method not implemented!')
486+
476487
def GetRoute(self, request, context):
477488
"""Missing associated documentation comment in .proto file."""
478489
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
@@ -701,6 +712,11 @@ def add_NodeServicer_to_server(servicer, server):
701712
request_deserializer=node__pb2.FeeratesRequest.FromString,
702713
response_serializer=node__pb2.FeeratesResponse.SerializeToString,
703714
),
715+
'FundChannel': grpc.unary_unary_rpc_method_handler(
716+
servicer.FundChannel,
717+
request_deserializer=node__pb2.FundchannelRequest.FromString,
718+
response_serializer=node__pb2.FundchannelResponse.SerializeToString,
719+
),
704720
'GetRoute': grpc.unary_unary_rpc_method_handler(
705721
servicer.GetRoute,
706722
request_deserializer=node__pb2.GetrouteRequest.FromString,
@@ -1399,6 +1415,23 @@ def Feerates(request,
13991415
options, channel_credentials,
14001416
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
14011417

1418+
@staticmethod
1419+
def FundChannel(request,
1420+
target,
1421+
options=(),
1422+
channel_credentials=None,
1423+
call_credentials=None,
1424+
insecure=False,
1425+
compression=None,
1426+
wait_for_ready=None,
1427+
timeout=None,
1428+
metadata=None):
1429+
return grpc.experimental.unary_unary(request, target, '/cln.Node/FundChannel',
1430+
node__pb2.FundchannelRequest.SerializeToString,
1431+
node__pb2.FundchannelResponse.FromString,
1432+
options, channel_credentials,
1433+
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
1434+
14021435
@staticmethod
14031436
def GetRoute(request,
14041437
target,

doc/schemas/fundchannel.request.json

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
{
2+
"$schema": "http://json-schema.org/draft-07/schema#",
3+
"type": "object",
4+
"additionalProperties": false,
5+
"required": [
6+
"id",
7+
"amount"
8+
],
9+
"properties": {
10+
"id": {
11+
"type": "pubkey",
12+
"description": "id is the peer id obtained from connect."
13+
},
14+
"amount": {
15+
"type": "msat_or_all"
16+
},
17+
"feerate": {
18+
"type": "feerate"
19+
},
20+
"announce": {
21+
"type": "boolean"
22+
},
23+
"minconf": {
24+
"type": "number"
25+
},
26+
"push_msat": {
27+
"type": "msat"
28+
},
29+
"close_to": {
30+
"type": "string"
31+
},
32+
"request_amt": {
33+
"type": "msat"
34+
},
35+
"compact_lease": {
36+
"type": "string"
37+
},
38+
"utxos": {
39+
"type": "array",
40+
"items": {
41+
"type": "outpoint"
42+
}
43+
}
44+
}
45+
}

0 commit comments

Comments
 (0)