grpc: Allow conversion code to use deprecated fields

The warning was rather superfluous, we should rather annotate the
downstream structs so the developer gets a warning, not us library
maintainers.
This commit is contained in:
Christian Decker
2023-01-13 15:00:15 +01:00
committed by Alex Myers
parent 640edf3955
commit e5d5737927
4 changed files with 326 additions and 266 deletions

View File

@@ -63,6 +63,7 @@ impl From<responses::GetinfoResponse> for pb::GetinfoResponse {
our_features: c.our_features.map(|v| v.into()),
blockheight: c.blockheight, // Rule #2 for type u32
network: c.network, // Rule #2 for type string
#[allow(deprecated)]
msatoshi_fees_collected: c.msatoshi_fees_collected, // Rule #2 for type u64?
fees_collected_msat: Some(c.fees_collected_msat.into()), // Rule #2 for type msat
address: c.address.into_iter().map(|i| i.into()).collect(), // Rule #3 for type GetinfoAddress
@@ -116,7 +117,9 @@ impl From<responses::ListpeersPeersChannelsInflight> for pb::ListpeersPeersChann
impl From<responses::ListpeersPeersChannelsFunding> for pb::ListpeersPeersChannelsFunding {
fn from(c: responses::ListpeersPeersChannelsFunding) -> Self {
Self {
#[allow(deprecated)]
local_msat: c.local_msat.map(|f| f.into()), // Rule #2 for type msat?
#[allow(deprecated)]
remote_msat: c.remote_msat.map(|f| f.into()), // Rule #2 for type msat?
pushed_msat: c.pushed_msat.map(|f| f.into()), // Rule #2 for type msat?
local_funds_msat: Some(c.local_funds_msat.into()), // Rule #2 for type msat
@@ -769,6 +772,7 @@ impl From<responses::NewaddrResponse> for pb::NewaddrResponse {
fn from(c: responses::NewaddrResponse) -> Self {
Self {
bech32: c.bech32, // Rule #2 for type string?
#[allow(deprecated)]
p2sh_segwit: c.p2sh_segwit, // Rule #2 for type string?
}
}
@@ -993,6 +997,7 @@ impl From<responses::GetrouteRoute> for pb::GetrouteRoute {
id: c.id.serialize().to_vec(), // Rule #2 for type pubkey
channel: c.channel.to_string(), // Rule #2 for type short_channel_id
direction: c.direction, // Rule #2 for type u32
#[allow(deprecated)]
msatoshi: c.msatoshi, // Rule #2 for type u64?
amount_msat: Some(c.amount_msat.into()), // Rule #2 for type msat
delay: c.delay, // Rule #2 for type u32

View File

@@ -327,6 +327,8 @@ class GrpcConverterGenerator(IGenerator):
f'c.{name}' # default to just assignment
)
if f.deprecated:
self.write(f"#[allow(deprecated)]\n", numindent=3)
self.write(f"{name}: {rhs}, // Rule #2 for type {typ}\n", numindent=3)
elif isinstance(f, CompositeField):

File diff suppressed because one or more lines are too long

View File

@@ -239,6 +239,11 @@ class NodeStub(object):
request_serializer=node__pb2.SetchannelRequest.SerializeToString,
response_deserializer=node__pb2.SetchannelResponse.FromString,
)
self.SignInvoice = channel.unary_unary(
'/cln.Node/SignInvoice',
request_serializer=node__pb2.SigninvoiceRequest.SerializeToString,
response_deserializer=node__pb2.SigninvoiceResponse.FromString,
)
self.SignMessage = channel.unary_unary(
'/cln.Node/SignMessage',
request_serializer=node__pb2.SignmessageRequest.SerializeToString,
@@ -524,6 +529,12 @@ class NodeServicer(object):
context.set_details('Method not implemented!')
raise NotImplementedError('Method not implemented!')
def SignInvoice(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)
@@ -764,6 +775,11 @@ def add_NodeServicer_to_server(servicer, server):
request_deserializer=node__pb2.SetchannelRequest.FromString,
response_serializer=node__pb2.SetchannelResponse.SerializeToString,
),
'SignInvoice': grpc.unary_unary_rpc_method_handler(
servicer.SignInvoice,
request_deserializer=node__pb2.SigninvoiceRequest.FromString,
response_serializer=node__pb2.SigninvoiceResponse.SerializeToString,
),
'SignMessage': grpc.unary_unary_rpc_method_handler(
servicer.SignMessage,
request_deserializer=node__pb2.SignmessageRequest.FromString,
@@ -1549,6 +1565,23 @@ class Node(object):
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def SignInvoice(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/SignInvoice',
node__pb2.SigninvoiceRequest.SerializeToString,
node__pb2.SigninvoiceResponse.FromString,
options, channel_credentials,
insecure, call_credentials, compression, wait_for_ready, timeout, metadata)
@staticmethod
def SignMessage(request,
target,