Setchannel request is provided

This commit is contained in:
Justin Litchfield 2022-09-15 10:48:05 -05:00 committed by Christian Decker
parent 6324980484
commit 51e2433087
10 changed files with 291 additions and 11 deletions

View file

@ -973,6 +973,27 @@
"SendPsbt.tx": 1,
"SendPsbt.txid": 2
},
"SetchannelChannels": {
"SetChannel.channels[].channel_id": 2,
"SetChannel.channels[].fee_base_msat": 4,
"SetChannel.channels[].fee_proportional_millionths": 5,
"SetChannel.channels[].maximum_htlc_out_msat": 8,
"SetChannel.channels[].minimum_htlc_out_msat": 6,
"SetChannel.channels[].peer_id": 1,
"SetChannel.channels[].short_channel_id": 3,
"SetChannel.channels[].warning_htlcmax_too_high": 9,
"SetChannel.channels[].warning_htlcmin_too_low": 7
},
"SetchannelRequest": {
"SetChannel.feebase": 2,
"SetChannel.feeppm": 3,
"SetChannel.htlcmax": 5,
"SetChannel.htlcmin": 4,
"SetChannel.id": 1
},
"SetchannelResponse": {
"SetChannel.channels[]": 1
},
"SignmessageRequest": {
"SignMessage.message": 1
},

View file

@ -52,6 +52,7 @@ service Node {
rpc ListForwards(ListforwardsRequest) returns (ListforwardsResponse) {}
rpc ListPays(ListpaysRequest) returns (ListpaysResponse) {}
rpc Ping(PingRequest) returns (PingResponse) {}
rpc SetChannel(SetchannelRequest) returns (SetchannelResponse) {}
rpc SignMessage(SignmessageRequest) returns (SignmessageResponse) {}
rpc Stop(StopRequest) returns (StopResponse) {}
}
@ -1287,6 +1288,30 @@ message PingResponse {
uint32 totlen = 1;
}
message SetchannelRequest {
string id = 1;
optional Amount feebase = 2;
optional uint32 feeppm = 3;
optional Amount htlcmin = 4;
optional Amount htlcmax = 5;
}
message SetchannelResponse {
repeated SetchannelChannels channels = 1;
}
message SetchannelChannels {
bytes peer_id = 1;
bytes channel_id = 2;
optional string short_channel_id = 3;
Amount fee_base_msat = 4;
uint32 fee_proportional_millionths = 5;
Amount minimum_htlc_out_msat = 6;
optional string warning_htlcmin_too_low = 7;
Amount maximum_htlc_out_msat = 8;
optional string warning_htlcmax_too_high = 9;
}
message SignmessageRequest {
string message = 1;
}

View file

@ -961,8 +961,39 @@ impl From<responses::PingResponse> for pb::PingResponse {
}
#[allow(unused_variables)]
<<<<<<< HEAD
impl From<responses::SignmessageResponse> for pb::SignmessageResponse {
fn from(c: responses::SignmessageResponse) -> Self {
=======
impl From<&responses::SetchannelChannels> for pb::SetchannelChannels {
fn from(c: &responses::SetchannelChannels) -> Self {
Self {
peer_id: c.peer_id.to_vec(), // Rule #2 for type pubkey
channel_id: hex::decode(&c.channel_id).unwrap(), // Rule #2 for type hex
short_channel_id: c.short_channel_id.as_ref().map(|v| v.to_string()), // Rule #2 for type short_channel_id?
fee_base_msat: Some(c.fee_base_msat.into()), // Rule #2 for type msat
fee_proportional_millionths: c.fee_proportional_millionths.clone(), // Rule #2 for type u32
minimum_htlc_out_msat: Some(c.minimum_htlc_out_msat.into()), // Rule #2 for type msat
warning_htlcmin_too_low: c.warning_htlcmin_too_low.clone(), // Rule #2 for type string?
maximum_htlc_out_msat: Some(c.maximum_htlc_out_msat.into()), // Rule #2 for type msat
warning_htlcmax_too_high: c.warning_htlcmax_too_high.clone(), // Rule #2 for type string?
}
}
}
#[allow(unused_variables)]
impl From<&responses::SetchannelResponse> for pb::SetchannelResponse {
fn from(c: &responses::SetchannelResponse) -> Self {
Self {
channels: c.channels.iter().map(|i| i.into()).collect(), // Rule #3 for type SetchannelChannels
}
}
}
#[allow(unused_variables)]
impl From<&responses::SignmessageResponse> for pb::SignmessageResponse {
fn from(c: &responses::SignmessageResponse) -> Self {
>>>>>>> bd301acdc... Setchannel request is provided
Self {
signature: hex::decode(&c.signature).unwrap(), // Rule #2 for type hex
recid: hex::decode(&c.recid).unwrap(), // Rule #2 for type hex
@ -1523,8 +1554,26 @@ impl From<pb::PingRequest> for requests::PingRequest {
}
#[allow(unused_variables)]
<<<<<<< HEAD
impl From<pb::SignmessageRequest> for requests::SignmessageRequest {
fn from(c: pb::SignmessageRequest) -> Self {
=======
impl From<&pb::SetchannelRequest> for requests::SetchannelRequest {
fn from(c: &pb::SetchannelRequest) -> Self {
Self {
id: c.id.clone(), // Rule #1 for type string
feebase: c.feebase.as_ref().map(|a| a.into()), // Rule #1 for type msat?
feeppm: c.feeppm.clone(), // Rule #1 for type u32?
htlcmin: c.htlcmin.as_ref().map(|a| a.into()), // Rule #1 for type msat?
htlcmax: c.htlcmax.as_ref().map(|a| a.into()), // Rule #1 for type msat?
}
}
}
#[allow(unused_variables)]
impl From<&pb::SignmessageRequest> for requests::SignmessageRequest {
fn from(c: &pb::SignmessageRequest) -> Self {
>>>>>>> bd301acdc... Setchannel request is provided
Self {
message: c.message, // Rule #1 for type string
}

View file

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

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

@ -60,6 +60,7 @@ pub enum Request {
ListForwards(requests::ListforwardsRequest),
ListPays(requests::ListpaysRequest),
Ping(requests::PingRequest),
SetChannel(requests::SetchannelRequest),
SignMessage(requests::SignmessageRequest),
Stop(requests::StopRequest),
}
@ -112,6 +113,7 @@ pub enum Response {
ListForwards(responses::ListforwardsResponse),
ListPays(responses::ListpaysResponse),
Ping(responses::PingResponse),
SetChannel(responses::SetchannelResponse),
SignMessage(responses::SignmessageResponse),
Stop(responses::StopResponse),
}
@ -1274,6 +1276,20 @@ pub mod requests {
type Response = super::responses::PingResponse;
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SetchannelRequest {
#[serde(alias = "id")]
pub id: String,
#[serde(alias = "feebase", skip_serializing_if = "Option::is_none")]
pub feebase: Option<Amount>,
#[serde(alias = "feeppm", skip_serializing_if = "Option::is_none")]
pub feeppm: Option<u32>,
#[serde(alias = "htlcmin", skip_serializing_if = "Option::is_none")]
pub htlcmin: Option<Amount>,
#[serde(alias = "htlcmax", skip_serializing_if = "Option::is_none")]
pub htlcmax: Option<Amount>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SignmessageRequest {
#[serde(alias = "message")]
@ -3717,6 +3733,34 @@ pub mod responses {
}
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SetchannelChannels {
#[serde(alias = "peer_id")]
pub peer_id: Pubkey,
#[serde(alias = "channel_id")]
pub channel_id: String,
#[serde(alias = "short_channel_id", skip_serializing_if = "Option::is_none")]
pub short_channel_id: Option<ShortChannelId>,
#[serde(alias = "fee_base_msat")]
pub fee_base_msat: Amount,
#[serde(alias = "fee_proportional_millionths")]
pub fee_proportional_millionths: u32,
#[serde(alias = "minimum_htlc_out_msat")]
pub minimum_htlc_out_msat: Amount,
#[serde(alias = "warning_htlcmin_too_low", skip_serializing_if = "Option::is_none")]
pub warning_htlcmin_too_low: Option<String>,
#[serde(alias = "maximum_htlc_out_msat")]
pub maximum_htlc_out_msat: Amount,
#[serde(alias = "warning_htlcmax_too_high", skip_serializing_if = "Option::is_none")]
pub warning_htlcmax_too_high: Option<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SetchannelResponse {
#[serde(alias = "channels")]
pub channels: Vec<SetchannelChannels>,
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct SignmessageResponse {
#[serde(alias = "signature")]

View file

@ -107,6 +107,7 @@ def load_jsonrpc_service(schema_dir: str = None):
# "sendinvoice",
# "sendonionmessage",
# "setchannelfee",
"SetChannel",
"SignMessage",
# "unreserveinputs",
# "waitblockheight",

View file

@ -849,6 +849,26 @@ def ping2py(m):
})
def setchannel_channels2py(m):
return remove_default({
"peer_id": hexlify(m.peer_id), # PrimitiveField in generate_composite
"channel_id": hexlify(m.channel_id), # PrimitiveField in generate_composite
"short_channel_id": m.short_channel_id, # PrimitiveField in generate_composite
"fee_base_msat": amount2msat(m.fee_base_msat), # PrimitiveField in generate_composite
"fee_proportional_millionths": m.fee_proportional_millionths, # PrimitiveField in generate_composite
"minimum_htlc_out_msat": amount2msat(m.minimum_htlc_out_msat), # PrimitiveField in generate_composite
"warning_htlcmin_too_low": m.warning_htlcmin_too_low, # PrimitiveField in generate_composite
"maximum_htlc_out_msat": amount2msat(m.maximum_htlc_out_msat), # PrimitiveField in generate_composite
"warning_htlcmax_too_high": m.warning_htlcmax_too_high, # PrimitiveField in generate_composite
})
def setchannel2py(m):
return remove_default({
"channels": [setchannel_channels2py(i) for i in m.channels], # ArrayField[composite] in generate_composite
})
def signmessage2py(m):
return remove_default({
"signature": hexlify(m.signature), # PrimitiveField in generate_composite

File diff suppressed because one or more lines are too long

View file

@ -234,6 +234,11 @@ class NodeStub(object):
request_serializer=node__pb2.PingRequest.SerializeToString,
response_deserializer=node__pb2.PingResponse.FromString,
)
self.SetChannel = channel.unary_unary(
'/cln.Node/SetChannel',
request_serializer=node__pb2.SetchannelRequest.SerializeToString,
response_deserializer=node__pb2.SetchannelResponse.FromString,
)
self.SignMessage = channel.unary_unary(
'/cln.Node/SignMessage',
request_serializer=node__pb2.SignmessageRequest.SerializeToString,
@ -513,6 +518,12 @@ class NodeServicer(object):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def SetChannel(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 SignMessage(self, request, context):
"""Missing associated documentation comment in .proto file."""
context.set_code(grpc.StatusCode.UNIMPLEMENTED)
@ -748,6 +759,11 @@ def add_NodeServicer_to_server(servicer, server):
request_deserializer=node__pb2.PingRequest.FromString,
response_serializer=node__pb2.PingResponse.SerializeToString,
),
'SetChannel': grpc.unary_unary_rpc_method_handler(
servicer.SetChannel,
request_deserializer=node__pb2.SetchannelRequest.FromString,
response_serializer=node__pb2.SetchannelResponse.SerializeToString,
),
'SignMessage': grpc.unary_unary_rpc_method_handler(
servicer.SignMessage,
request_deserializer=node__pb2.SignmessageRequest.FromString,
@ -1516,6 +1532,23 @@ class Node(object):
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def SetChannel(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/SetChannel',
node__pb2.SetchannelRequest.SerializeToString,
node__pb2.SetchannelResponse.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def SignMessage(request,
target,

View file

@ -0,0 +1,25 @@
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": false,
"required": [
"id"
],
"properties": {
"id": {
"type": "string"
},
"feebase": {
"type": "msat"
},
"feeppm": {
"type": "u32"
},
"htlcmin": {
"type": "msat"
},
"htlcmax": {
"type": "msat"
}
}
}