From 9ad5c6bc75caee9780c052c34f37cb4cfa126593 Mon Sep 17 00:00:00 2001 From: daywalker90 <8257956+daywalker90@users.noreply.github.com> Date: Wed, 17 Apr 2024 13:12:50 +0200 Subject: [PATCH] msggen: use field numbers from .msggen.json for rust model if available --- cln-rpc/src/model.rs | 300 +++++++++++----------- contrib/msggen/msggen/__main__.py | 6 +- contrib/msggen/msggen/gen/rust.py | 73 ++++-- contrib/pyln-testing/pyln/testing/grpc.py | 3 +- 4 files changed, 204 insertions(+), 178 deletions(-) diff --git a/cln-rpc/src/model.rs b/cln-rpc/src/model.rs index 7ce5c7f1af52..c1bed7e13094 100644 --- a/cln-rpc/src/model.rs +++ b/cln-rpc/src/model.rs @@ -199,13 +199,13 @@ pub mod requests { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListpeersLevel { #[serde(rename = "io")] - IO, + IO = 0, #[serde(rename = "debug")] - DEBUG, + DEBUG = 1, #[serde(rename = "info")] - INFO, + INFO = 2, #[serde(rename = "unusual")] - UNUSUAL, + UNUSUAL = 3, } impl TryFrom for ListpeersLevel { @@ -516,15 +516,15 @@ pub mod requests { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum DatastoreMode { #[serde(rename = "must-create")] - MUST_CREATE, + MUST_CREATE = 0, #[serde(rename = "must-replace")] - MUST_REPLACE, + MUST_REPLACE = 1, #[serde(rename = "create-or-replace")] - CREATE_OR_REPLACE, + CREATE_OR_REPLACE = 2, #[serde(rename = "must-append")] - MUST_APPEND, + MUST_APPEND = 3, #[serde(rename = "create-or-append")] - CREATE_OR_APPEND, + CREATE_OR_APPEND = 4, } impl TryFrom for DatastoreMode { @@ -667,11 +667,11 @@ pub mod requests { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum DelinvoiceStatus { #[serde(rename = "paid")] - PAID, + PAID = 0, #[serde(rename = "expired")] - EXPIRED, + EXPIRED = 1, #[serde(rename = "unpaid")] - UNPAID, + UNPAID = 2, } impl TryFrom for DelinvoiceStatus { @@ -783,9 +783,9 @@ pub mod requests { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListinvoicesIndex { #[serde(rename = "created")] - CREATED, + CREATED = 0, #[serde(rename = "updated")] - UPDATED, + UPDATED = 1, } impl TryFrom for ListinvoicesIndex { @@ -896,11 +896,11 @@ pub mod requests { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListsendpaysStatus { #[serde(rename = "pending")] - PENDING, + PENDING = 0, #[serde(rename = "complete")] - COMPLETE, + COMPLETE = 1, #[serde(rename = "failed")] - FAILED, + FAILED = 2, } impl TryFrom for ListsendpaysStatus { @@ -929,9 +929,9 @@ pub mod requests { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListsendpaysIndex { #[serde(rename = "created")] - CREATED, + CREATED = 0, #[serde(rename = "updated")] - UPDATED, + UPDATED = 1, } impl TryFrom for ListsendpaysIndex { @@ -1156,11 +1156,11 @@ pub mod requests { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum NewaddrAddresstype { #[serde(rename = "bech32")] - BECH32, + BECH32 = 0, #[serde(rename = "p2tr")] - P2TR, + P2TR = 3, #[serde(rename = "all")] - ALL, + ALL = 2, } impl TryFrom for NewaddrAddresstype { @@ -1589,9 +1589,9 @@ pub mod requests { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum FeeratesStyle { #[serde(rename = "perkb")] - PERKB, + PERKB = 0, #[serde(rename = "perkw")] - PERKW, + PERKW = 1, } impl TryFrom for FeeratesStyle { @@ -1756,13 +1756,13 @@ pub mod requests { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListforwardsStatus { #[serde(rename = "offered")] - OFFERED, + OFFERED = 0, #[serde(rename = "settled")] - SETTLED, + SETTLED = 1, #[serde(rename = "local_failed")] - LOCAL_FAILED, + LOCAL_FAILED = 2, #[serde(rename = "failed")] - FAILED, + FAILED = 3, } impl TryFrom for ListforwardsStatus { @@ -1793,9 +1793,9 @@ pub mod requests { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListforwardsIndex { #[serde(rename = "created")] - CREATED, + CREATED = 0, #[serde(rename = "updated")] - UPDATED, + UPDATED = 1, } impl TryFrom for ListforwardsIndex { @@ -1880,11 +1880,11 @@ pub mod requests { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListpaysStatus { #[serde(rename = "pending")] - PENDING, + PENDING = 0, #[serde(rename = "complete")] - COMPLETE, + COMPLETE = 1, #[serde(rename = "failed")] - FAILED, + FAILED = 2, } impl TryFrom for ListpaysStatus { @@ -2207,11 +2207,11 @@ pub mod requests { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum WaitSubsystem { #[serde(rename = "invoices")] - INVOICES, + INVOICES = 0, #[serde(rename = "forwards")] - FORWARDS, + FORWARDS = 1, #[serde(rename = "sendpays")] - SENDPAYS, + SENDPAYS = 2, } impl TryFrom for WaitSubsystem { @@ -2240,11 +2240,11 @@ pub mod requests { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum WaitIndexname { #[serde(rename = "created")] - CREATED, + CREATED = 0, #[serde(rename = "updated")] - UPDATED, + UPDATED = 1, #[serde(rename = "deleted")] - DELETED, + DELETED = 2, } impl TryFrom for WaitIndexname { @@ -2436,15 +2436,15 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum GetinfoAddressType { #[serde(rename = "dns")] - DNS, + DNS = 0, #[serde(rename = "ipv4")] - IPV4, + IPV4 = 1, #[serde(rename = "ipv6")] - IPV6, + IPV6 = 2, #[serde(rename = "torv2")] - TORV2, + TORV2 = 3, #[serde(rename = "torv3")] - TORV3, + TORV3 = 4, } impl TryFrom for GetinfoAddressType { @@ -2487,17 +2487,17 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum GetinfoBindingType { #[serde(rename = "local socket")] - LOCAL_SOCKET, + LOCAL_SOCKET = 0, #[serde(rename = "websocket")] - WEBSOCKET, + WEBSOCKET = 5, #[serde(rename = "ipv4")] - IPV4, + IPV4 = 1, #[serde(rename = "ipv6")] - IPV6, + IPV6 = 2, #[serde(rename = "torv2")] - TORV2, + TORV2 = 3, #[serde(rename = "torv3")] - TORV3, + TORV3 = 4, } impl TryFrom for GetinfoBindingType { @@ -2583,19 +2583,19 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListpeersPeersLogType { #[serde(rename = "SKIPPED")] - SKIPPED, + SKIPPED = 0, #[serde(rename = "BROKEN")] - BROKEN, + BROKEN = 1, #[serde(rename = "UNUSUAL")] - UNUSUAL, + UNUSUAL = 2, #[serde(rename = "INFO")] - INFO, + INFO = 3, #[serde(rename = "DEBUG")] - DEBUG, + DEBUG = 4, #[serde(rename = "IO_IN")] - IO_IN, + IO_IN = 5, #[serde(rename = "IO_OUT")] - IO_OUT, + IO_OUT = 6, } impl TryFrom for ListpeersPeersLogType { @@ -2682,13 +2682,13 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListfundsOutputsStatus { #[serde(rename = "unconfirmed")] - UNCONFIRMED, + UNCONFIRMED = 0, #[serde(rename = "confirmed")] - CONFIRMED, + CONFIRMED = 1, #[serde(rename = "spent")] - SPENT, + SPENT = 2, #[serde(rename = "immature")] - IMMATURE, + IMMATURE = 3, } impl TryFrom for ListfundsOutputsStatus { @@ -2769,9 +2769,9 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum SendpayStatus { #[serde(rename = "pending")] - PENDING, + PENDING = 0, #[serde(rename = "complete")] - COMPLETE, + COMPLETE = 1, } impl TryFrom for SendpayStatus { @@ -2932,11 +2932,11 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum CloseType { #[serde(rename = "mutual")] - MUTUAL, + MUTUAL = 0, #[serde(rename = "unilateral")] - UNILATERAL, + UNILATERAL = 1, #[serde(rename = "unopened")] - UNOPENED, + UNOPENED = 2, } impl TryFrom for CloseType { @@ -2987,9 +2987,9 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ConnectDirection { #[serde(rename = "in")] - IN, + IN = 0, #[serde(rename = "out")] - OUT, + OUT = 1, } impl TryFrom for ConnectDirection { @@ -3016,15 +3016,15 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ConnectAddressType { #[serde(rename = "local socket")] - LOCAL_SOCKET, + LOCAL_SOCKET = 0, #[serde(rename = "ipv4")] - IPV4, + IPV4 = 1, #[serde(rename = "ipv6")] - IPV6, + IPV6 = 2, #[serde(rename = "torv2")] - TORV2, + TORV2 = 3, #[serde(rename = "torv3")] - TORV3, + TORV3 = 4, } impl TryFrom for ConnectAddressType { @@ -3090,11 +3090,11 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum CreateinvoiceStatus { #[serde(rename = "paid")] - PAID, + PAID = 0, #[serde(rename = "expired")] - EXPIRED, + EXPIRED = 1, #[serde(rename = "unpaid")] - UNPAID, + UNPAID = 2, } impl TryFrom for CreateinvoiceStatus { @@ -3260,11 +3260,11 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum DelinvoiceStatus { #[serde(rename = "paid")] - PAID, + PAID = 0, #[serde(rename = "expired")] - EXPIRED, + EXPIRED = 1, #[serde(rename = "unpaid")] - UNPAID, + UNPAID = 2, } impl TryFrom for DelinvoiceStatus { @@ -3387,11 +3387,11 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListinvoicesInvoicesStatus { #[serde(rename = "unpaid")] - UNPAID, + UNPAID = 0, #[serde(rename = "paid")] - PAID, + PAID = 1, #[serde(rename = "expired")] - EXPIRED, + EXPIRED = 2, } impl TryFrom for ListinvoicesInvoicesStatus { @@ -3479,9 +3479,9 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum SendonionStatus { #[serde(rename = "pending")] - PENDING, + PENDING = 0, #[serde(rename = "complete")] - COMPLETE, + COMPLETE = 1, } impl TryFrom for SendonionStatus { @@ -3549,11 +3549,11 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListsendpaysPaymentsStatus { #[serde(rename = "pending")] - PENDING, + PENDING = 0, #[serde(rename = "failed")] - FAILED, + FAILED = 1, #[serde(rename = "complete")] - COMPLETE, + COMPLETE = 2, } impl TryFrom for ListsendpaysPaymentsStatus { @@ -3676,11 +3676,11 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum PayStatus { #[serde(rename = "complete")] - COMPLETE, + COMPLETE = 0, #[serde(rename = "pending")] - PENDING, + PENDING = 1, #[serde(rename = "failed")] - FAILED, + FAILED = 2, } impl TryFrom for PayStatus { @@ -3736,15 +3736,15 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListnodesNodesAddressesType { #[serde(rename = "dns")] - DNS, + DNS = 0, #[serde(rename = "ipv4")] - IPV4, + IPV4 = 1, #[serde(rename = "ipv6")] - IPV6, + IPV6 = 2, #[serde(rename = "torv2")] - TORV2, + TORV2 = 3, #[serde(rename = "torv3")] - TORV3, + TORV3 = 4, } impl TryFrom for ListnodesNodesAddressesType { @@ -3818,9 +3818,9 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum WaitanyinvoiceStatus { #[serde(rename = "paid")] - PAID, + PAID = 0, #[serde(rename = "expired")] - EXPIRED, + EXPIRED = 1, } impl TryFrom for WaitanyinvoiceStatus { @@ -3896,9 +3896,9 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum WaitinvoiceStatus { #[serde(rename = "paid")] - PAID, + PAID = 0, #[serde(rename = "expired")] - EXPIRED, + EXPIRED = 1, } impl TryFrom for WaitinvoiceStatus { @@ -3974,7 +3974,7 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum WaitsendpayStatus { #[serde(rename = "complete")] - COMPLETE, + COMPLETE = 0, } impl TryFrom for WaitsendpayStatus { @@ -4079,7 +4079,7 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum KeysendStatus { #[serde(rename = "complete")] - COMPLETE, + COMPLETE = 0, } impl TryFrom for KeysendStatus { @@ -4281,33 +4281,33 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListpeerchannelsChannelsState { #[serde(rename = "OPENINGD")] - OPENINGD, + OPENINGD = 0, #[serde(rename = "CHANNELD_AWAITING_LOCKIN")] - CHANNELD_AWAITING_LOCKIN, + CHANNELD_AWAITING_LOCKIN = 1, #[serde(rename = "CHANNELD_NORMAL")] - CHANNELD_NORMAL, + CHANNELD_NORMAL = 2, #[serde(rename = "CHANNELD_SHUTTING_DOWN")] - CHANNELD_SHUTTING_DOWN, + CHANNELD_SHUTTING_DOWN = 3, #[serde(rename = "CLOSINGD_SIGEXCHANGE")] - CLOSINGD_SIGEXCHANGE, + CLOSINGD_SIGEXCHANGE = 4, #[serde(rename = "CLOSINGD_COMPLETE")] - CLOSINGD_COMPLETE, + CLOSINGD_COMPLETE = 5, #[serde(rename = "AWAITING_UNILATERAL")] - AWAITING_UNILATERAL, + AWAITING_UNILATERAL = 6, #[serde(rename = "FUNDING_SPEND_SEEN")] - FUNDING_SPEND_SEEN, + FUNDING_SPEND_SEEN = 7, #[serde(rename = "ONCHAIN")] - ONCHAIN, + ONCHAIN = 8, #[serde(rename = "DUALOPEND_OPEN_INIT")] - DUALOPEND_OPEN_INIT, + DUALOPEND_OPEN_INIT = 9, #[serde(rename = "DUALOPEND_AWAITING_LOCKIN")] - DUALOPEND_AWAITING_LOCKIN, + DUALOPEND_AWAITING_LOCKIN = 10, #[serde(rename = "CHANNELD_AWAITING_SPLICE")] - CHANNELD_AWAITING_SPLICE, + CHANNELD_AWAITING_SPLICE = 11, #[serde(rename = "DUALOPEND_OPEN_COMMITTED")] - DUALOPEND_OPEN_COMMITTED, + DUALOPEND_OPEN_COMMITTED = 12, #[serde(rename = "DUALOPEND_OPEN_COMMIT_READY")] - DUALOPEND_OPEN_COMMIT_READY, + DUALOPEND_OPEN_COMMIT_READY = 13, } impl TryFrom for ListpeerchannelsChannelsState { @@ -4442,9 +4442,9 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListpeerchannelsChannelsHtlcsDirection { #[serde(rename = "in")] - IN, + IN = 0, #[serde(rename = "out")] - OUT, + OUT = 1, } impl TryFrom for ListpeerchannelsChannelsHtlcsDirection { @@ -4630,17 +4630,17 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListclosedchannelsClosedchannelsClose_cause { #[serde(rename = "unknown")] - UNKNOWN, + UNKNOWN = 0, #[serde(rename = "local")] - LOCAL, + LOCAL = 1, #[serde(rename = "user")] - USER, + USER = 2, #[serde(rename = "remote")] - REMOTE, + REMOTE = 3, #[serde(rename = "protocol")] - PROTOCOL, + PROTOCOL = 4, #[serde(rename = "onchain")] - ONCHAIN, + ONCHAIN = 5, } impl TryFrom for ListclosedchannelsClosedchannelsClose_cause { @@ -4731,15 +4731,15 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum DecodepayFallbacksType { #[serde(rename = "P2PKH")] - P2PKH, + P2PKH = 0, #[serde(rename = "P2SH")] - P2SH, + P2SH = 1, #[serde(rename = "P2WPKH")] - P2WPKH, + P2WPKH = 2, #[serde(rename = "P2WSH")] - P2WSH, + P2WSH = 3, #[serde(rename = "P2TR")] - P2TR, + P2TR = 4, } impl TryFrom for DecodepayFallbacksType { @@ -4826,17 +4826,17 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum DecodeType { #[serde(rename = "bolt12 offer")] - BOLT12_OFFER, + BOLT12_OFFER = 0, #[serde(rename = "bolt12 invoice")] - BOLT12_INVOICE, + BOLT12_INVOICE = 1, #[serde(rename = "bolt12 invoice_request")] - BOLT12_INVOICE_REQUEST, + BOLT12_INVOICE_REQUEST = 2, #[serde(rename = "bolt11 invoice")] - BOLT11_INVOICE, + BOLT11_INVOICE = 3, #[serde(rename = "rune")] - RUNE, + RUNE = 4, #[serde(rename = "emergency recover")] - EMERGENCY_RECOVER, + EMERGENCY_RECOVER = 5, } impl TryFrom for DecodeType { @@ -5254,7 +5254,7 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum GetrouteRouteStyle { #[serde(rename = "tlv")] - TLV, + TLV = 0, } impl TryFrom for GetrouteRouteStyle { @@ -5306,13 +5306,13 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListforwardsForwardsStatus { #[serde(rename = "offered")] - OFFERED, + OFFERED = 0, #[serde(rename = "settled")] - SETTLED, + SETTLED = 1, #[serde(rename = "local_failed")] - LOCAL_FAILED, + LOCAL_FAILED = 2, #[serde(rename = "failed")] - FAILED, + FAILED = 3, } impl TryFrom for ListforwardsForwardsStatus { @@ -5343,9 +5343,9 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListforwardsForwardsStyle { #[serde(rename = "legacy")] - LEGACY, + LEGACY = 0, #[serde(rename = "tlv")] - TLV, + TLV = 1, } impl TryFrom for ListforwardsForwardsStyle { @@ -5440,11 +5440,11 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListpaysPaysStatus { #[serde(rename = "pending")] - PENDING, + PENDING = 0, #[serde(rename = "failed")] - FAILED, + FAILED = 1, #[serde(rename = "complete")] - COMPLETE, + COMPLETE = 2, } impl TryFrom for ListpaysPaysStatus { @@ -5519,9 +5519,9 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum ListhtlcsHtlcsDirection { #[serde(rename = "out")] - OUT, + OUT = 0, #[serde(rename = "in")] - IN, + IN = 1, } impl TryFrom for ListhtlcsHtlcsDirection { @@ -5805,11 +5805,11 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum WaitSubsystem { #[serde(rename = "invoices")] - INVOICES, + INVOICES = 0, #[serde(rename = "forwards")] - FORWARDS, + FORWARDS = 1, #[serde(rename = "sendpays")] - SENDPAYS, + SENDPAYS = 2, } impl TryFrom for WaitSubsystem { @@ -5860,7 +5860,7 @@ pub mod responses { #[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)] pub enum StopResult { #[serde(rename = "Shutdown complete")] - SHUTDOWN_COMPLETE, + SHUTDOWN_COMPLETE = 0, } impl TryFrom for StopResult { diff --git a/contrib/msggen/msggen/__main__.py b/contrib/msggen/msggen/__main__.py index ee1a5d1df0d9..821d4c16bf41 100644 --- a/contrib/msggen/msggen/__main__.py +++ b/contrib/msggen/msggen/__main__.py @@ -44,10 +44,10 @@ def add_handler_get_grpc2py(generator_chain: GeneratorChain): generator_chain.add_generator(Grpc2PyGenerator(dest)) -def add_handler_gen_rust_jsonrpc(generator_chain: GeneratorChain): +def add_handler_gen_rust_jsonrpc(generator_chain: GeneratorChain, meta): fname = Path("cln-rpc") / "src" / "model.rs" dest = open(fname, "w") - generator_chain.add_generator(RustGenerator(dest)) + generator_chain.add_generator(RustGenerator(dest, meta)) def load_msggen_meta(): @@ -81,7 +81,7 @@ def run(): generator_chain = GeneratorChain() add_handler_gen_grpc(generator_chain, meta) - add_handler_gen_rust_jsonrpc(generator_chain) + add_handler_gen_rust_jsonrpc(generator_chain, meta) add_handler_get_grpc2py(generator_chain) generator_chain.generate(service) diff --git a/contrib/msggen/msggen/gen/rust.py b/contrib/msggen/msggen/gen/rust.py index 668ca5a05737..767b3de6cca8 100644 --- a/contrib/msggen/msggen/gen/rust.py +++ b/contrib/msggen/msggen/gen/rust.py @@ -1,5 +1,4 @@ -from typing import TextIO -from typing import Tuple +from typing import TextIO, Tuple, Dict, Any from textwrap import dedent, indent import logging import sys @@ -65,22 +64,22 @@ def normalize_varname(field): return field -def gen_field(field): +def gen_field(field, meta): if field.omit(): return ("", "") if isinstance(field, CompositeField): - return gen_composite(field) + return gen_composite(field, meta) elif isinstance(field, EnumField): - return gen_enum(field) + return gen_enum(field, meta) elif isinstance(field, ArrayField): - return gen_array(field) + return gen_array(field, meta) elif isinstance(field, PrimitiveField): return gen_primitive(field) else: raise TypeError(f"Unmanaged type {field}") -def gen_enum(e): +def gen_enum(e, meta): defi, decl = "", "" if e.omit(): @@ -92,12 +91,31 @@ def gen_enum(e): if e.deprecated: decl += "#[deprecated]\n" decl += f"#[derive(Copy, Clone, Debug, Deserialize, Serialize, PartialEq, Eq)]\npub enum {e.typename} {{\n" + + m = meta['grpc-field-map'] + m2 = meta['grpc-enum-map'] + + message_name = e.typename.name + assert not (message_name in m and message_name in m2) + if message_name in m: + m = m[message_name] + elif message_name in m2: + m = m2[message_name] + else: + m = {} + + complete_variants = True for v in e.variants: - if v is None: - continue - norm = v.normalized() - decl += f" #[serde(rename = \"{v}\")]\n" - decl += f" {norm},\n" + if str(v) not in m: + complete_variants = False + + if m != {} and complete_variants: + for v in e.variants: + if v is None: + continue + norm = v.normalized() + decl += f" #[serde(rename = \"{v}\")]\n" + decl += f" {norm} = {m[str(v)]},\n" decl += "}\n\n" # Implement From so we can convert from the numerical @@ -108,10 +126,18 @@ def gen_enum(e): fn try_from(c: i32) -> Result<{e.typename}, anyhow::Error> {{ match c {{ """) - for i, v in enumerate(e.variants): - norm = v.normalized() - # decl += f" #[serde(rename = \"{v}\")]\n" - decl += f" {i} => Ok({e.typename}::{norm}),\n" + + if m != {} and complete_variants: + for v in e.variants: + norm = v.normalized() + # decl += f" #[serde(rename = \"{v}\")]\n" + decl += f" {m[str(v)]} => Ok({e.typename}::{norm}),\n" + else: + for i, v in enumerate(e.variants): + norm = v.normalized() + # decl += f" #[serde(rename = \"{v}\")]\n" + decl += f" {i} => Ok({e.typename}::{norm}),\n" + decl += dedent(f"""\ o => Err(anyhow::anyhow!("Unknown variant {{}} for enum {e.typename}", o)), }} @@ -178,10 +204,10 @@ def rename_if_necessary(original, name): return f"" -def gen_array(a): +def gen_array(a, meta): name = a.name.normalized().replace("[]", "") logger.debug(f"Generating array field {a.name} -> {name} ({a.path})") - _, decl = gen_field(a.itemtype) + _, decl = gen_field(a.itemtype, meta) if a.override(): decl = "" # No declaration if we have an override @@ -210,11 +236,11 @@ def gen_array(a): return (defi, decl) -def gen_composite(c) -> Tuple[str, str]: +def gen_composite(c, meta) -> Tuple[str, str]: logger.debug(f"Generating composite field {c.name} ({c.path})") fields = [] for f in c.fields: - fields.append(gen_field(f)) + fields.append(gen_field(f, meta)) r = "".join([f[1] for f in fields]) @@ -236,8 +262,9 @@ def gen_composite(c) -> Tuple[str, str]: class RustGenerator(IGenerator): - def __init__(self, dest: TextIO): + def __init__(self, dest: TextIO, meta: Dict[str, Any]): self.dest = dest + self.meta = meta def write(self, text: str, numindent: int = 0) -> None: raw = dedent(text) @@ -258,7 +285,7 @@ def generate_requests(self, service: Service): for meth in service.methods: req = meth.request - _, decl = gen_composite(req) + _, decl = gen_composite(req, self.meta) self.write(decl, numindent=1) self.generate_request_trait_impl(meth) @@ -298,7 +325,7 @@ def generate_responses(self, service: Service): for meth in service.methods: res = meth.response - _, decl = gen_composite(res) + _, decl = gen_composite(res, self.meta) self.write(decl, numindent=1) self.generate_response_trait_impl(meth) diff --git a/contrib/pyln-testing/pyln/testing/grpc.py b/contrib/pyln-testing/pyln/testing/grpc.py index ded2827f2b50..d854f25bd9be 100644 --- a/contrib/pyln-testing/pyln/testing/grpc.py +++ b/contrib/pyln-testing/pyln/testing/grpc.py @@ -119,8 +119,7 @@ def newaddr(self, addresstype=None): enum = { None: 0, "BECH32": 0, - "P2SH_SEGWIT": 1, - "P2SH-SEGWIT": 1, + "P2TR": 3, "ALL": 2 } if addresstype is not None: