Skip to content

Commit

Permalink
msggen: Add fundchannel request
Browse files Browse the repository at this point in the history
  • Loading branch information
cdecker authored and rustyrussell committed Jul 21, 2022
1 parent b8bcc7d commit 77f5eb5
Show file tree
Hide file tree
Showing 10 changed files with 295 additions and 42 deletions.
20 changes: 20 additions & 0 deletions .msggen.json
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,26 @@
"Feerates.perkw": 3,
"Feerates.warning_missing_feerates": 1
},
"FundchannelRequest": {
"FundChannel.amount": 1,
"FundChannel.announce": 3,
"FundChannel.close_to": 6,
"FundChannel.compact_lease": 8,
"FundChannel.feerate": 2,
"FundChannel.id": 9,
"FundChannel.minconf": 10,
"FundChannel.minconf[]": 4,
"FundChannel.push_msat": 5,
"FundChannel.request_amt": 7,
"FundChannel.utxos[]": 11
},
"FundchannelResponse": {
"FundChannel.channel_id": 4,
"FundChannel.close_to": 5,
"FundChannel.outnum": 3,
"FundChannel.tx": 1,
"FundChannel.txid": 2
},
"FundpsbtRequest": {
"FundPsbt.excess_as_change": 8,
"FundPsbt.feerate": 2,
Expand Down
22 changes: 22 additions & 0 deletions cln-grpc/proto/node.proto
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ service Node {
rpc TxSend(TxsendRequest) returns (TxsendResponse) {}
rpc Disconnect(DisconnectRequest) returns (DisconnectResponse) {}
rpc Feerates(FeeratesRequest) returns (FeeratesResponse) {}
rpc FundChannel(FundchannelRequest) returns (FundchannelResponse) {}
rpc GetRoute(GetrouteRequest) returns (GetrouteResponse) {}
rpc ListForwards(ListforwardsRequest) returns (ListforwardsResponse) {}
rpc ListPays(ListpaysRequest) returns (ListpaysResponse) {}
Expand Down Expand Up @@ -1138,6 +1139,27 @@ message FeeratesOnchain_fee_estimates {
uint64 htlc_success_satoshis = 5;
}

message FundchannelRequest {
bytes id = 9;
AmountOrAll amount = 1;
optional Feerate feerate = 2;
optional bool announce = 3;
optional double minconf = 10;
optional Amount push_msat = 5;
optional string close_to = 6;
optional Amount request_amt = 7;
optional string compact_lease = 8;
repeated Outpoint utxos = 11;
}

message FundchannelResponse {
bytes tx = 1;
bytes txid = 2;
uint32 outnum = 3;
bytes channel_id = 4;
optional bytes close_to = 5;
}

message GetrouteRequest {
bytes id = 1;
Amount amount_msat = 9;
Expand Down
31 changes: 31 additions & 0 deletions cln-grpc/src/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -853,6 +853,19 @@ impl From<&responses::FeeratesResponse> for pb::FeeratesResponse {
}
}

#[allow(unused_variables)]
impl From<&responses::FundchannelResponse> for pb::FundchannelResponse {
fn from(c: &responses::FundchannelResponse) -> Self {
Self {
tx: hex::decode(&c.tx).unwrap(), // Rule #2 for type hex
txid: hex::decode(&c.txid).unwrap(), // Rule #2 for type txid
outnum: c.outnum.clone(), // Rule #2 for type u32
channel_id: hex::decode(&c.channel_id).unwrap(), // Rule #2 for type hex
close_to: c.close_to.as_ref().map(|v| hex::decode(&v).unwrap()), // Rule #2 for type hex?
}
}
}

#[allow(unused_variables)]
impl From<&responses::GetrouteRoute> for pb::GetrouteRoute {
fn from(c: &responses::GetrouteRoute) -> Self {
Expand Down Expand Up @@ -1424,6 +1437,24 @@ impl From<&pb::FeeratesRequest> for requests::FeeratesRequest {
}
}

#[allow(unused_variables)]
impl From<&pb::FundchannelRequest> for requests::FundchannelRequest {
fn from(c: &pb::FundchannelRequest) -> Self {
Self {
id: cln_rpc::primitives::Pubkey::from_slice(&c.id).unwrap(), // Rule #1 for type pubkey
amount: c.amount.as_ref().unwrap().into(), // Rule #1 for type msat_or_all
feerate: c.feerate.as_ref().map(|a| a.into()), // Rule #1 for type feerate?
announce: c.announce.clone(), // Rule #1 for type boolean?
minconf: c.minconf.clone(), // Rule #1 for type number?
push_msat: c.push_msat.as_ref().map(|a| a.into()), // Rule #1 for type msat?
close_to: c.close_to.clone(), // Rule #1 for type string?
request_amt: c.request_amt.as_ref().map(|a| a.into()), // Rule #1 for type msat?
compact_lease: c.compact_lease.clone(), // Rule #1 for type string?
utxos: Some(c.utxos.iter().map(|s| s.into()).collect()), // Rule #4
}
}
}

#[allow(unused_variables)]
impl From<&pb::GetrouteRequest> for requests::GetrouteRequest {
fn from(c: &pb::GetrouteRequest) -> Self {
Expand Down
32 changes: 32 additions & 0 deletions cln-grpc/src/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,38 @@ async fn feerates(

}

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

}

async fn get_route(
&self,
request: tonic::Request<pb::GetrouteRequest>,
Expand Down
40 changes: 40 additions & 0 deletions cln-rpc/src/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub enum Request {
TxSend(requests::TxsendRequest),
Disconnect(requests::DisconnectRequest),
Feerates(requests::FeeratesRequest),
FundChannel(requests::FundchannelRequest),
GetRoute(requests::GetrouteRequest),
ListForwards(requests::ListforwardsRequest),
ListPays(requests::ListpaysRequest),
Expand Down Expand Up @@ -105,6 +106,7 @@ pub enum Response {
TxSend(responses::TxsendResponse),
Disconnect(responses::DisconnectResponse),
Feerates(responses::FeeratesResponse),
FundChannel(responses::FundchannelResponse),
GetRoute(responses::GetrouteResponse),
ListForwards(responses::ListforwardsResponse),
ListPays(responses::ListpaysResponse),
Expand Down Expand Up @@ -698,6 +700,30 @@ pub mod requests {
pub style: FeeratesStyle,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct FundchannelRequest {
#[serde(alias = "id")]
pub id: Pubkey,
#[serde(alias = "amount")]
pub amount: AmountOrAll,
#[serde(alias = "feerate", skip_serializing_if = "Option::is_none")]
pub feerate: Option<Feerate>,
#[serde(alias = "announce", skip_serializing_if = "Option::is_none")]
pub announce: Option<bool>,
#[serde(alias = "minconf", skip_serializing_if = "Option::is_none")]
pub minconf: Option<f64>,
#[serde(alias = "push_msat", skip_serializing_if = "Option::is_none")]
pub push_msat: Option<Amount>,
#[serde(alias = "close_to", skip_serializing_if = "Option::is_none")]
pub close_to: Option<String>,
#[serde(alias = "request_amt", skip_serializing_if = "Option::is_none")]
pub request_amt: Option<Amount>,
#[serde(alias = "compact_lease", skip_serializing_if = "Option::is_none")]
pub compact_lease: Option<String>,
#[serde(alias = "utxos", skip_serializing_if = "Option::is_none")]
pub utxos: Option<Vec<Outpoint>>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct GetrouteRequest {
#[serde(alias = "id")]
Expand Down Expand Up @@ -2522,6 +2548,20 @@ pub mod responses {
pub warning_missing_feerates: Option<String>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct FundchannelResponse {
#[serde(alias = "tx")]
pub tx: String,
#[serde(alias = "txid")]
pub txid: String,
#[serde(alias = "outnum")]
pub outnum: u32,
#[serde(alias = "channel_id")]
pub channel_id: String,
#[serde(alias = "close_to", skip_serializing_if = "Option::is_none")]
pub close_to: Option<String>,
}

/// The features understood by the destination node
#[derive(Copy, Clone, Debug, Deserialize, Serialize)]
pub enum GetrouteRouteStyle {
Expand Down
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 = None):
# "fetchinvoice",
# "fundchannel_cancel",
# "fundchannel_complete",
# "fundchannel",
"FundChannel",
# "fundchannel_start",
# "funderupdate",
# "getlog",
Expand Down
10 changes: 10 additions & 0 deletions contrib/pyln-testing/pyln/testing/grpc2py.py
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,16 @@ def feerates2py(m):
})


def fundchannel2py(m):
return remove_default({
"tx": hexlify(m.tx), # PrimitiveField in generate_composite
"txid": hexlify(m.txid), # PrimitiveField in generate_composite
"outnum": m.outnum, # PrimitiveField in generate_composite
"channel_id": hexlify(m.channel_id), # PrimitiveField in generate_composite
"close_to": hexlify(m.close_to), # PrimitiveField in generate_composite
})


def getroute_route2py(m):
return remove_default({
"id": hexlify(m.id), # PrimitiveField in generate_composite
Expand Down
102 changes: 61 additions & 41 deletions contrib/pyln-testing/pyln/testing/node_pb2.py

Large diffs are not rendered by default.

33 changes: 33 additions & 0 deletions contrib/pyln-testing/pyln/testing/node_pb2_grpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,11 @@ def __init__(self, channel):
request_serializer=node__pb2.FeeratesRequest.SerializeToString,
response_deserializer=node__pb2.FeeratesResponse.FromString,
)
self.FundChannel = channel.unary_unary(
'/cln.Node/FundChannel',
request_serializer=node__pb2.FundchannelRequest.SerializeToString,
response_deserializer=node__pb2.FundchannelResponse.FromString,
)
self.GetRoute = channel.unary_unary(
'/cln.Node/GetRoute',
request_serializer=node__pb2.GetrouteRequest.SerializeToString,
Expand Down Expand Up @@ -473,6 +478,12 @@ def Feerates(self, request, context):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')

def FundChannel(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 GetRoute(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
Expand Down Expand Up @@ -701,6 +712,11 @@ def add_NodeServicer_to_server(servicer, server):
request_deserializer=node__pb2.FeeratesRequest.FromString,
response_serializer=node__pb2.FeeratesResponse.SerializeToString,
),
'FundChannel': grpc.unary_unary_rpc_method_handler(
servicer.FundChannel,
request_deserializer=node__pb2.FundchannelRequest.FromString,
response_serializer=node__pb2.FundchannelResponse.SerializeToString,
),
'GetRoute': grpc.unary_unary_rpc_method_handler(
servicer.GetRoute,
request_deserializer=node__pb2.GetrouteRequest.FromString,
Expand Down Expand Up @@ -1399,6 +1415,23 @@ def Feerates(request,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)

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

@staticmethod
def GetRoute(request,
target,
Expand Down
45 changes: 45 additions & 0 deletions doc/schemas/fundchannel.request.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [
"id",
"amount"
],
"properties": {
"id": {
"type": "pubkey",
"description": "id is the peer id obtained from connect."
},
"amount": {
"type": "msat_or_all"
},
"feerate": {
"type": "feerate"
},
"announce": {
"type": "boolean"
},
"minconf": {
"type": "number"
},
"push_msat": {
"type": "msat"
},
"close_to": {
"type": "string"
},
"request_amt": {
"type": "msat"
},
"compact_lease": {
"type": "string"
},
"utxos": {
"type": "array",
"items": {
"type": "outpoint"
}
}
}
}

0 comments on commit 77f5eb5

Please sign in to comment.