From 21a8342289a8a8836b7043b7ae565cb8f4eebc39 Mon Sep 17 00:00:00 2001 From: Riccardo Casatta Date: Thu, 12 Jan 2023 11:14:47 +0100 Subject: [PATCH] Implement GRPC -> JSON conversions also for response types --- cln-grpc/src/convert.rs | 1108 +++++++++++++++++++++++++++++ cln-rpc/src/primitives.rs | 35 + contrib/msggen/msggen/gen/grpc.py | 16 + 3 files changed, 1159 insertions(+) diff --git a/cln-grpc/src/convert.rs b/cln-grpc/src/convert.rs index 0d34dafb3..b2cb07204 100644 --- a/cln-grpc/src/convert.rs +++ b/cln-grpc/src/convert.rs @@ -2318,3 +2318,1111 @@ impl From for requests::StopRequest { } } +#[allow(unused_variables)] +impl From for responses::GetinfoOur_features { + fn from(c: pb::GetinfoOurFeatures) -> Self { + Self { + init: hex::encode(&c.init), // Rule #1 for type hex + node: hex::encode(&c.node), // Rule #1 for type hex + channel: hex::encode(&c.channel), // Rule #1 for type hex + invoice: hex::encode(&c.invoice), // Rule #1 for type hex + } + } +} + +#[allow(unused_variables)] +impl From for responses::GetinfoAddress { + fn from(c: pb::GetinfoAddress) -> Self { + Self { + item_type: c.item_type.try_into().unwrap(), + port: c.port as u16, // Rule #1 for type u16 + address: c.address, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::GetinfoBinding { + fn from(c: pb::GetinfoBinding) -> Self { + Self { + item_type: c.item_type.try_into().unwrap(), + address: c.address, // Rule #1 for type string? + port: c.port.map(|v| v as u16), // Rule #1 for type u16? + socket: c.socket, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::GetinfoResponse { + fn from(c: pb::GetinfoResponse) -> Self { + Self { + id: PublicKey::from_slice(&c.id).unwrap(), // Rule #1 for type pubkey + alias: c.alias, // Rule #1 for type string + color: hex::encode(&c.color), // Rule #1 for type hex + num_peers: c.num_peers, // Rule #1 for type u32 + num_pending_channels: c.num_pending_channels, // Rule #1 for type u32 + num_active_channels: c.num_active_channels, // Rule #1 for type u32 + num_inactive_channels: c.num_inactive_channels, // Rule #1 for type u32 + version: c.version, // Rule #1 for type string + lightning_dir: c.lightning_dir, // Rule #1 for type string + our_features: c.our_features.map(|v| v.into()), + blockheight: c.blockheight, // Rule #1 for type u32 + network: c.network, // Rule #1 for type string + msatoshi_fees_collected: c.msatoshi_fees_collected, // Rule #1 for type u64? + fees_collected_msat: c.fees_collected_msat.unwrap().into(), // Rule #1 for type msat + address: c.address.into_iter().map(|s| s.into()).collect(), // Rule #4 + binding: Some(c.binding.into_iter().map(|s| s.into()).collect()), // Rule #4 + warning_bitcoind_sync: c.warning_bitcoind_sync, // Rule #1 for type string? + warning_lightningd_sync: c.warning_lightningd_sync, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListpeersPeersLog { + fn from(c: pb::ListpeersPeersLog) -> Self { + Self { + item_type: c.item_type.try_into().unwrap(), + num_skipped: c.num_skipped, // Rule #1 for type u32? + time: c.time, // Rule #1 for type string? + source: c.source, // Rule #1 for type string? + log: c.log, // Rule #1 for type string? + node_id: c.node_id.map(|v| PublicKey::from_slice(&v).unwrap()), // Rule #1 for type pubkey? + data: c.data.map(|v| hex::encode(v)), // Rule #1 for type hex? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListpeersPeersChannelsFeerate { + fn from(c: pb::ListpeersPeersChannelsFeerate) -> Self { + Self { + perkw: c.perkw, // Rule #1 for type u32 + perkb: c.perkb, // Rule #1 for type u32 + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListpeersPeersChannelsInflight { + fn from(c: pb::ListpeersPeersChannelsInflight) -> Self { + Self { + funding_txid: hex::encode(&c.funding_txid), // Rule #1 for type txid + funding_outnum: c.funding_outnum, // Rule #1 for type u32 + feerate: c.feerate, // Rule #1 for type string + total_funding_msat: c.total_funding_msat.unwrap().into(), // Rule #1 for type msat + our_funding_msat: c.our_funding_msat.unwrap().into(), // Rule #1 for type msat + scratch_txid: hex::encode(&c.scratch_txid), // Rule #1 for type txid + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListpeersPeersChannelsFunding { + fn from(c: pb::ListpeersPeersChannelsFunding) -> Self { + Self { + local_msat: c.local_msat.map(|a| a.into()), // Rule #1 for type msat? + remote_msat: c.remote_msat.map(|a| a.into()), // Rule #1 for type msat? + pushed_msat: c.pushed_msat.map(|a| a.into()), // Rule #1 for type msat? + local_funds_msat: c.local_funds_msat.unwrap().into(), // Rule #1 for type msat + remote_funds_msat: c.remote_funds_msat.unwrap().into(), // Rule #1 for type msat + fee_paid_msat: c.fee_paid_msat.map(|a| a.into()), // Rule #1 for type msat? + fee_rcvd_msat: c.fee_rcvd_msat.map(|a| a.into()), // Rule #1 for type msat? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListpeersPeersChannelsAlias { + fn from(c: pb::ListpeersPeersChannelsAlias) -> Self { + Self { + local: c.local.map(|v| cln_rpc::primitives::ShortChannelId::from_str(&v).unwrap()), // Rule #1 for type short_channel_id? + remote: c.remote.map(|v| cln_rpc::primitives::ShortChannelId::from_str(&v).unwrap()), // Rule #1 for type short_channel_id? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListpeersPeersChannelsHtlcs { + fn from(c: pb::ListpeersPeersChannelsHtlcs) -> Self { + Self { + direction: c.direction.try_into().unwrap(), + id: c.id, // Rule #1 for type u64 + amount_msat: c.amount_msat.unwrap().into(), // Rule #1 for type msat + expiry: c.expiry, // Rule #1 for type u32 + payment_hash: Sha256::from_slice(&c.payment_hash).unwrap(), // Rule #1 for type hash + local_trimmed: c.local_trimmed, // Rule #1 for type boolean? + status: c.status, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListpeersPeersChannels { + fn from(c: pb::ListpeersPeersChannels) -> Self { + Self { + state: c.state.try_into().unwrap(), + scratch_txid: c.scratch_txid.map(|v| hex::encode(v)), // Rule #1 for type txid? + feerate: c.feerate.map(|v| v.into()), + owner: c.owner, // Rule #1 for type string? + short_channel_id: c.short_channel_id.map(|v| cln_rpc::primitives::ShortChannelId::from_str(&v).unwrap()), // Rule #1 for type short_channel_id? + channel_id: c.channel_id.map(|v| Sha256::from_slice(&v).unwrap()), // Rule #1 for type hash? + funding_txid: c.funding_txid.map(|v| hex::encode(v)), // Rule #1 for type txid? + funding_outnum: c.funding_outnum, // Rule #1 for type u32? + initial_feerate: c.initial_feerate, // Rule #1 for type string? + last_feerate: c.last_feerate, // Rule #1 for type string? + next_feerate: c.next_feerate, // Rule #1 for type string? + next_fee_step: c.next_fee_step, // Rule #1 for type u32? + inflight: Some(c.inflight.into_iter().map(|s| s.into()).collect()), // Rule #4 + close_to: c.close_to.map(|v| hex::encode(v)), // Rule #1 for type hex? + private: c.private, // Rule #1 for type boolean? + opener: c.opener.try_into().unwrap(), + closer: c.closer.map(|v| v.try_into().unwrap()), + features: c.features.into_iter().map(|s| s.into()).collect(), // Rule #4 + funding: c.funding.map(|v| v.into()), + to_us_msat: c.to_us_msat.map(|a| a.into()), // Rule #1 for type msat? + min_to_us_msat: c.min_to_us_msat.map(|a| a.into()), // Rule #1 for type msat? + max_to_us_msat: c.max_to_us_msat.map(|a| a.into()), // Rule #1 for type msat? + total_msat: c.total_msat.map(|a| a.into()), // Rule #1 for type msat? + fee_base_msat: c.fee_base_msat.map(|a| a.into()), // Rule #1 for type msat? + fee_proportional_millionths: c.fee_proportional_millionths, // Rule #1 for type u32? + dust_limit_msat: c.dust_limit_msat.map(|a| a.into()), // Rule #1 for type msat? + max_total_htlc_in_msat: c.max_total_htlc_in_msat.map(|a| a.into()), // Rule #1 for type msat? + their_reserve_msat: c.their_reserve_msat.map(|a| a.into()), // Rule #1 for type msat? + our_reserve_msat: c.our_reserve_msat.map(|a| a.into()), // Rule #1 for type msat? + spendable_msat: c.spendable_msat.map(|a| a.into()), // Rule #1 for type msat? + receivable_msat: c.receivable_msat.map(|a| a.into()), // Rule #1 for type msat? + minimum_htlc_in_msat: c.minimum_htlc_in_msat.map(|a| a.into()), // Rule #1 for type msat? + minimum_htlc_out_msat: c.minimum_htlc_out_msat.map(|a| a.into()), // Rule #1 for type msat? + maximum_htlc_out_msat: c.maximum_htlc_out_msat.map(|a| a.into()), // Rule #1 for type msat? + their_to_self_delay: c.their_to_self_delay, // Rule #1 for type u32? + our_to_self_delay: c.our_to_self_delay, // Rule #1 for type u32? + max_accepted_htlcs: c.max_accepted_htlcs, // Rule #1 for type u32? + alias: c.alias.map(|v| v.into()), +state_changes: None, status: Some(c.status.into_iter().map(|s| s.into()).collect()), // Rule #4 + in_payments_offered: c.in_payments_offered, // Rule #1 for type u64? + in_offered_msat: c.in_offered_msat.map(|a| a.into()), // Rule #1 for type msat? + in_payments_fulfilled: c.in_payments_fulfilled, // Rule #1 for type u64? + in_fulfilled_msat: c.in_fulfilled_msat.map(|a| a.into()), // Rule #1 for type msat? + out_payments_offered: c.out_payments_offered, // Rule #1 for type u64? + out_offered_msat: c.out_offered_msat.map(|a| a.into()), // Rule #1 for type msat? + out_payments_fulfilled: c.out_payments_fulfilled, // Rule #1 for type u64? + out_fulfilled_msat: c.out_fulfilled_msat.map(|a| a.into()), // Rule #1 for type msat? + htlcs: Some(c.htlcs.into_iter().map(|s| s.into()).collect()), // Rule #4 + close_to_addr: c.close_to_addr, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListpeersPeers { + fn from(c: pb::ListpeersPeers) -> Self { + Self { + id: PublicKey::from_slice(&c.id).unwrap(), // Rule #1 for type pubkey + connected: c.connected, // Rule #1 for type boolean + log: Some(c.log.into_iter().map(|s| s.into()).collect()), // Rule #4 + channels: Some(c.channels.into_iter().map(|s| s.into()).collect()), // Rule #4 + netaddr: Some(c.netaddr.into_iter().map(|s| s.into()).collect()), // Rule #4 + remote_addr: c.remote_addr, // Rule #1 for type string? + features: c.features.map(|v| hex::encode(v)), // Rule #1 for type hex? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListpeersResponse { + fn from(c: pb::ListpeersResponse) -> Self { + Self { + peers: c.peers.into_iter().map(|s| s.into()).collect(), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListfundsOutputs { + fn from(c: pb::ListfundsOutputs) -> Self { + Self { + txid: hex::encode(&c.txid), // Rule #1 for type txid + output: c.output, // Rule #1 for type u32 + amount_msat: c.amount_msat.unwrap().into(), // Rule #1 for type msat + scriptpubkey: hex::encode(&c.scriptpubkey), // Rule #1 for type hex + address: c.address, // Rule #1 for type string? + redeemscript: c.redeemscript.map(|v| hex::encode(v)), // Rule #1 for type hex? + status: c.status.try_into().unwrap(), + reserved: c.reserved, // Rule #1 for type boolean + blockheight: c.blockheight, // Rule #1 for type u32? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListfundsChannels { + fn from(c: pb::ListfundsChannels) -> Self { + Self { + peer_id: PublicKey::from_slice(&c.peer_id).unwrap(), // Rule #1 for type pubkey + our_amount_msat: c.our_amount_msat.unwrap().into(), // Rule #1 for type msat + amount_msat: c.amount_msat.unwrap().into(), // Rule #1 for type msat + funding_txid: hex::encode(&c.funding_txid), // Rule #1 for type txid + funding_output: c.funding_output, // Rule #1 for type u32 + connected: c.connected, // Rule #1 for type boolean + state: c.state.try_into().unwrap(), + short_channel_id: c.short_channel_id.map(|v| cln_rpc::primitives::ShortChannelId::from_str(&v).unwrap()), // Rule #1 for type short_channel_id? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListfundsResponse { + fn from(c: pb::ListfundsResponse) -> Self { + Self { + outputs: c.outputs.into_iter().map(|s| s.into()).collect(), // Rule #4 + channels: c.channels.into_iter().map(|s| s.into()).collect(), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::SendpayResponse { + fn from(c: pb::SendpayResponse) -> Self { + Self { + id: c.id, // Rule #1 for type u64 + groupid: c.groupid, // Rule #1 for type u64? + payment_hash: Sha256::from_slice(&c.payment_hash).unwrap(), // Rule #1 for type hash + status: c.status.try_into().unwrap(), + amount_msat: c.amount_msat.map(|a| a.into()), // Rule #1 for type msat? + destination: c.destination.map(|v| PublicKey::from_slice(&v).unwrap()), // Rule #1 for type pubkey? + created_at: c.created_at, // Rule #1 for type u64 + completed_at: c.completed_at, // Rule #1 for type u64? + amount_sent_msat: c.amount_sent_msat.unwrap().into(), // Rule #1 for type msat + label: c.label, // Rule #1 for type string? + partid: c.partid, // Rule #1 for type u64? + bolt11: c.bolt11, // Rule #1 for type string? + bolt12: c.bolt12, // Rule #1 for type string? + payment_preimage: c.payment_preimage.map(|v| v.try_into().unwrap()), // Rule #1 for type secret? + message: c.message, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListchannelsChannels { + fn from(c: pb::ListchannelsChannels) -> Self { + Self { + source: PublicKey::from_slice(&c.source).unwrap(), // Rule #1 for type pubkey + destination: PublicKey::from_slice(&c.destination).unwrap(), // Rule #1 for type pubkey + short_channel_id: cln_rpc::primitives::ShortChannelId::from_str(&c.short_channel_id).unwrap(), // Rule #1 for type short_channel_id + direction: c.direction, // Rule #1 for type u32 + public: c.public, // Rule #1 for type boolean + amount_msat: c.amount_msat.unwrap().into(), // Rule #1 for type msat + message_flags: c.message_flags as u8, // Rule #1 for type u8 + channel_flags: c.channel_flags as u8, // Rule #1 for type u8 + active: c.active, // Rule #1 for type boolean + last_update: c.last_update, // Rule #1 for type u32 + base_fee_millisatoshi: c.base_fee_millisatoshi, // Rule #1 for type u32 + fee_per_millionth: c.fee_per_millionth, // Rule #1 for type u32 + delay: c.delay, // Rule #1 for type u32 + htlc_minimum_msat: c.htlc_minimum_msat.unwrap().into(), // Rule #1 for type msat + htlc_maximum_msat: c.htlc_maximum_msat.map(|a| a.into()), // Rule #1 for type msat? + features: hex::encode(&c.features), // Rule #1 for type hex + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListchannelsResponse { + fn from(c: pb::ListchannelsResponse) -> Self { + Self { + channels: c.channels.into_iter().map(|s| s.into()).collect(), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::AddgossipResponse { + fn from(c: pb::AddgossipResponse) -> Self { + Self { + } + } +} + +#[allow(unused_variables)] +impl From for responses::AutocleaninvoiceResponse { + fn from(c: pb::AutocleaninvoiceResponse) -> Self { + Self { + enabled: c.enabled, // Rule #1 for type boolean + expired_by: c.expired_by, // Rule #1 for type u64? + cycle_seconds: c.cycle_seconds, // Rule #1 for type u64? + } + } +} + +#[allow(unused_variables)] +impl From for responses::CheckmessageResponse { + fn from(c: pb::CheckmessageResponse) -> Self { + Self { + verified: c.verified, // Rule #1 for type boolean + pubkey: PublicKey::from_slice(&c.pubkey).unwrap(), // Rule #1 for type pubkey + } + } +} + +#[allow(unused_variables)] +impl From for responses::CloseResponse { + fn from(c: pb::CloseResponse) -> Self { + Self { + item_type: c.item_type.try_into().unwrap(), + tx: c.tx.map(|v| hex::encode(v)), // Rule #1 for type hex? + txid: c.txid.map(|v| hex::encode(v)), // Rule #1 for type txid? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ConnectAddress { + fn from(c: pb::ConnectAddress) -> Self { + Self { + item_type: c.item_type.try_into().unwrap(), + socket: c.socket, // Rule #1 for type string? + address: c.address, // Rule #1 for type string? + port: c.port.map(|v| v as u16), // Rule #1 for type u16? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ConnectResponse { + fn from(c: pb::ConnectResponse) -> Self { + Self { + id: PublicKey::from_slice(&c.id).unwrap(), // Rule #1 for type pubkey + features: hex::encode(&c.features), // Rule #1 for type hex + direction: c.direction.try_into().unwrap(), + address: c.address.unwrap().into(), + } + } +} + +#[allow(unused_variables)] +impl From for responses::CreateinvoiceResponse { + fn from(c: pb::CreateinvoiceResponse) -> Self { + Self { + label: c.label, // Rule #1 for type string + bolt11: c.bolt11, // Rule #1 for type string? + bolt12: c.bolt12, // Rule #1 for type string? + payment_hash: Sha256::from_slice(&c.payment_hash).unwrap(), // Rule #1 for type hash + amount_msat: c.amount_msat.map(|a| a.into()), // Rule #1 for type msat? + status: c.status.try_into().unwrap(), + description: c.description, // Rule #1 for type string + expires_at: c.expires_at, // Rule #1 for type u64 + pay_index: c.pay_index, // Rule #1 for type u64? + amount_received_msat: c.amount_received_msat.map(|a| a.into()), // Rule #1 for type msat? + paid_at: c.paid_at, // Rule #1 for type u64? + payment_preimage: c.payment_preimage.map(|v| v.try_into().unwrap()), // Rule #1 for type secret? + local_offer_id: c.local_offer_id.map(|v| hex::encode(v)), // Rule #1 for type hex? + invreq_payer_note: c.invreq_payer_note, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::DatastoreResponse { + fn from(c: pb::DatastoreResponse) -> Self { + Self { + key: c.key.into_iter().map(|s| s.into()).collect(), // Rule #4 + generation: c.generation, // Rule #1 for type u64? + hex: c.hex.map(|v| hex::encode(v)), // Rule #1 for type hex? + string: c.string, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::CreateonionResponse { + fn from(c: pb::CreateonionResponse) -> Self { + Self { + onion: hex::encode(&c.onion), // Rule #1 for type hex + shared_secrets: c.shared_secrets.into_iter().map(|s| s.try_into().unwrap()).collect(), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::DeldatastoreResponse { + fn from(c: pb::DeldatastoreResponse) -> Self { + Self { + key: c.key.into_iter().map(|s| s.into()).collect(), // Rule #4 + generation: c.generation, // Rule #1 for type u64? + hex: c.hex.map(|v| hex::encode(v)), // Rule #1 for type hex? + string: c.string, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::DelexpiredinvoiceResponse { + fn from(c: pb::DelexpiredinvoiceResponse) -> Self { + Self { + } + } +} + +#[allow(unused_variables)] +impl From for responses::DelinvoiceResponse { + fn from(c: pb::DelinvoiceResponse) -> Self { + Self { + label: c.label, // Rule #1 for type string + bolt11: c.bolt11, // Rule #1 for type string? + bolt12: c.bolt12, // Rule #1 for type string? + amount_msat: c.amount_msat.map(|a| a.into()), // Rule #1 for type msat? + description: c.description, // Rule #1 for type string? + payment_hash: Sha256::from_slice(&c.payment_hash).unwrap(), // Rule #1 for type hash + status: c.status.try_into().unwrap(), + expires_at: c.expires_at, // Rule #1 for type u64 + local_offer_id: c.local_offer_id.map(|v| hex::encode(v)), // Rule #1 for type hex? + invreq_payer_note: c.invreq_payer_note, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::InvoiceResponse { + fn from(c: pb::InvoiceResponse) -> Self { + Self { + bolt11: c.bolt11, // Rule #1 for type string + payment_hash: Sha256::from_slice(&c.payment_hash).unwrap(), // Rule #1 for type hash + payment_secret: c.payment_secret.try_into().unwrap(), // Rule #1 for type secret + expires_at: c.expires_at, // Rule #1 for type u64 + warning_capacity: c.warning_capacity, // Rule #1 for type string? + warning_offline: c.warning_offline, // Rule #1 for type string? + warning_deadends: c.warning_deadends, // Rule #1 for type string? + warning_private_unused: c.warning_private_unused, // Rule #1 for type string? + warning_mpp: c.warning_mpp, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListdatastoreDatastore { + fn from(c: pb::ListdatastoreDatastore) -> Self { + Self { + key: c.key.into_iter().map(|s| s.into()).collect(), // Rule #4 + generation: c.generation, // Rule #1 for type u64? + hex: c.hex.map(|v| hex::encode(v)), // Rule #1 for type hex? + string: c.string, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListdatastoreResponse { + fn from(c: pb::ListdatastoreResponse) -> Self { + Self { + datastore: c.datastore.into_iter().map(|s| s.into()).collect(), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListinvoicesInvoices { + fn from(c: pb::ListinvoicesInvoices) -> Self { + Self { + label: c.label, // Rule #1 for type string + description: c.description, // Rule #1 for type string? + payment_hash: Sha256::from_slice(&c.payment_hash).unwrap(), // Rule #1 for type hash + status: c.status.try_into().unwrap(), + expires_at: c.expires_at, // Rule #1 for type u64 + amount_msat: c.amount_msat.map(|a| a.into()), // Rule #1 for type msat? + bolt11: c.bolt11, // Rule #1 for type string? + bolt12: c.bolt12, // Rule #1 for type string? + local_offer_id: c.local_offer_id.map(|v| Sha256::from_slice(&v).unwrap()), // Rule #1 for type hash? + invreq_payer_note: c.invreq_payer_note, // Rule #1 for type string? + pay_index: c.pay_index, // Rule #1 for type u64? + amount_received_msat: c.amount_received_msat.map(|a| a.into()), // Rule #1 for type msat? + paid_at: c.paid_at, // Rule #1 for type u64? + payment_preimage: c.payment_preimage.map(|v| v.try_into().unwrap()), // Rule #1 for type secret? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListinvoicesResponse { + fn from(c: pb::ListinvoicesResponse) -> Self { + Self { + invoices: c.invoices.into_iter().map(|s| s.into()).collect(), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::SendonionResponse { + fn from(c: pb::SendonionResponse) -> Self { + Self { + id: c.id, // Rule #1 for type u64 + payment_hash: Sha256::from_slice(&c.payment_hash).unwrap(), // Rule #1 for type hash + status: c.status.try_into().unwrap(), + amount_msat: c.amount_msat.map(|a| a.into()), // Rule #1 for type msat? + destination: c.destination.map(|v| PublicKey::from_slice(&v).unwrap()), // Rule #1 for type pubkey? + created_at: c.created_at, // Rule #1 for type u64 + amount_sent_msat: c.amount_sent_msat.unwrap().into(), // Rule #1 for type msat + label: c.label, // Rule #1 for type string? + bolt11: c.bolt11, // Rule #1 for type string? + bolt12: c.bolt12, // Rule #1 for type string? + partid: c.partid, // Rule #1 for type u64? + payment_preimage: c.payment_preimage.map(|v| v.try_into().unwrap()), // Rule #1 for type secret? + message: c.message, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListsendpaysPayments { + fn from(c: pb::ListsendpaysPayments) -> Self { + Self { + id: c.id, // Rule #1 for type u64 + groupid: c.groupid, // Rule #1 for type u64 + partid: c.partid, // Rule #1 for type u64? + payment_hash: Sha256::from_slice(&c.payment_hash).unwrap(), // Rule #1 for type hash + status: c.status.try_into().unwrap(), + amount_msat: c.amount_msat.map(|a| a.into()), // Rule #1 for type msat? + destination: c.destination.map(|v| PublicKey::from_slice(&v).unwrap()), // Rule #1 for type pubkey? + created_at: c.created_at, // Rule #1 for type u64 + amount_sent_msat: c.amount_sent_msat.unwrap().into(), // Rule #1 for type msat + label: c.label, // Rule #1 for type string? + bolt11: c.bolt11, // Rule #1 for type string? + description: c.description, // Rule #1 for type string? + bolt12: c.bolt12, // Rule #1 for type string? + payment_preimage: c.payment_preimage.map(|v| v.try_into().unwrap()), // Rule #1 for type secret? + erroronion: c.erroronion.map(|v| hex::encode(v)), // Rule #1 for type hex? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListsendpaysResponse { + fn from(c: pb::ListsendpaysResponse) -> Self { + Self { + payments: c.payments.into_iter().map(|s| s.into()).collect(), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListtransactionsTransactionsInputs { + fn from(c: pb::ListtransactionsTransactionsInputs) -> Self { + Self { + txid: hex::encode(&c.txid), // Rule #1 for type txid + index: c.index, // Rule #1 for type u32 + sequence: c.sequence, // Rule #1 for type u32 + item_type: c.item_type.map(|v| v.try_into().unwrap()), + channel: c.channel.map(|v| cln_rpc::primitives::ShortChannelId::from_str(&v).unwrap()), // Rule #1 for type short_channel_id? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListtransactionsTransactionsOutputs { + fn from(c: pb::ListtransactionsTransactionsOutputs) -> Self { + Self { + index: c.index, // Rule #1 for type u32 + amount_msat: c.amount_msat.unwrap().into(), // Rule #1 for type msat + script_pub_key: hex::encode(&c.script_pub_key), // Rule #1 for type hex + item_type: c.item_type.map(|v| v.try_into().unwrap()), + channel: c.channel.map(|v| cln_rpc::primitives::ShortChannelId::from_str(&v).unwrap()), // Rule #1 for type short_channel_id? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListtransactionsTransactions { + fn from(c: pb::ListtransactionsTransactions) -> Self { + Self { + hash: hex::encode(&c.hash), // Rule #1 for type txid + rawtx: hex::encode(&c.rawtx), // Rule #1 for type hex + blockheight: c.blockheight, // Rule #1 for type u32 + txindex: c.txindex, // Rule #1 for type u32 + locktime: c.locktime, // Rule #1 for type u32 + version: c.version, // Rule #1 for type u32 + inputs: c.inputs.into_iter().map(|s| s.into()).collect(), // Rule #4 + outputs: c.outputs.into_iter().map(|s| s.into()).collect(), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListtransactionsResponse { + fn from(c: pb::ListtransactionsResponse) -> Self { + Self { + transactions: c.transactions.into_iter().map(|s| s.into()).collect(), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::PayResponse { + fn from(c: pb::PayResponse) -> Self { + Self { + payment_preimage: c.payment_preimage.try_into().unwrap(), // Rule #1 for type secret + destination: c.destination.map(|v| PublicKey::from_slice(&v).unwrap()), // Rule #1 for type pubkey? + payment_hash: Sha256::from_slice(&c.payment_hash).unwrap(), // Rule #1 for type hash + created_at: c.created_at, // Rule #1 for type number + parts: c.parts, // Rule #1 for type u32 + amount_msat: c.amount_msat.unwrap().into(), // Rule #1 for type msat + amount_sent_msat: c.amount_sent_msat.unwrap().into(), // Rule #1 for type msat + warning_partial_completion: c.warning_partial_completion, // Rule #1 for type string? + status: c.status.try_into().unwrap(), + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListnodesNodesAddresses { + fn from(c: pb::ListnodesNodesAddresses) -> Self { + Self { + item_type: c.item_type.try_into().unwrap(), + port: c.port as u16, // Rule #1 for type u16 + address: c.address, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListnodesNodes { + fn from(c: pb::ListnodesNodes) -> Self { + Self { + nodeid: PublicKey::from_slice(&c.nodeid).unwrap(), // Rule #1 for type pubkey + last_timestamp: c.last_timestamp, // Rule #1 for type u32? + alias: c.alias, // Rule #1 for type string? + color: c.color.map(|v| hex::encode(v)), // Rule #1 for type hex? + features: c.features.map(|v| hex::encode(v)), // Rule #1 for type hex? + addresses: Some(c.addresses.into_iter().map(|s| s.into()).collect()), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListnodesResponse { + fn from(c: pb::ListnodesResponse) -> Self { + Self { + nodes: c.nodes.into_iter().map(|s| s.into()).collect(), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::WaitanyinvoiceResponse { + fn from(c: pb::WaitanyinvoiceResponse) -> Self { + Self { + label: c.label, // Rule #1 for type string + description: c.description, // Rule #1 for type string + payment_hash: Sha256::from_slice(&c.payment_hash).unwrap(), // Rule #1 for type hash + status: c.status.try_into().unwrap(), + expires_at: c.expires_at, // Rule #1 for type u64 + amount_msat: c.amount_msat.map(|a| a.into()), // Rule #1 for type msat? + bolt11: c.bolt11, // Rule #1 for type string? + bolt12: c.bolt12, // Rule #1 for type string? + pay_index: c.pay_index, // Rule #1 for type u64? + amount_received_msat: c.amount_received_msat.map(|a| a.into()), // Rule #1 for type msat? + paid_at: c.paid_at, // Rule #1 for type u64? + payment_preimage: c.payment_preimage.map(|v| v.try_into().unwrap()), // Rule #1 for type secret? + } + } +} + +#[allow(unused_variables)] +impl From for responses::WaitinvoiceResponse { + fn from(c: pb::WaitinvoiceResponse) -> Self { + Self { + label: c.label, // Rule #1 for type string + description: c.description, // Rule #1 for type string + payment_hash: Sha256::from_slice(&c.payment_hash).unwrap(), // Rule #1 for type hash + status: c.status.try_into().unwrap(), + expires_at: c.expires_at, // Rule #1 for type u64 + amount_msat: c.amount_msat.map(|a| a.into()), // Rule #1 for type msat? + bolt11: c.bolt11, // Rule #1 for type string? + bolt12: c.bolt12, // Rule #1 for type string? + pay_index: c.pay_index, // Rule #1 for type u64? + amount_received_msat: c.amount_received_msat.map(|a| a.into()), // Rule #1 for type msat? + paid_at: c.paid_at, // Rule #1 for type u64? + payment_preimage: c.payment_preimage.map(|v| v.try_into().unwrap()), // Rule #1 for type secret? + } + } +} + +#[allow(unused_variables)] +impl From for responses::WaitsendpayResponse { + fn from(c: pb::WaitsendpayResponse) -> Self { + Self { + id: c.id, // Rule #1 for type u64 + groupid: c.groupid, // Rule #1 for type u64? + payment_hash: Sha256::from_slice(&c.payment_hash).unwrap(), // Rule #1 for type hash + status: c.status.try_into().unwrap(), + amount_msat: c.amount_msat.map(|a| a.into()), // Rule #1 for type msat? + destination: c.destination.map(|v| PublicKey::from_slice(&v).unwrap()), // Rule #1 for type pubkey? + created_at: c.created_at, // Rule #1 for type u64 + completed_at: c.completed_at, // Rule #1 for type number? + amount_sent_msat: c.amount_sent_msat.unwrap().into(), // Rule #1 for type msat + label: c.label, // Rule #1 for type string? + partid: c.partid, // Rule #1 for type u64? + bolt11: c.bolt11, // Rule #1 for type string? + bolt12: c.bolt12, // Rule #1 for type string? + payment_preimage: c.payment_preimage.map(|v| v.try_into().unwrap()), // Rule #1 for type secret? + } + } +} + +#[allow(unused_variables)] +impl From for responses::NewaddrResponse { + fn from(c: pb::NewaddrResponse) -> Self { + Self { + bech32: c.bech32, // Rule #1 for type string? + p2sh_segwit: c.p2sh_segwit, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::WithdrawResponse { + fn from(c: pb::WithdrawResponse) -> Self { + Self { + tx: hex::encode(&c.tx), // Rule #1 for type hex + txid: hex::encode(&c.txid), // Rule #1 for type txid + psbt: c.psbt, // Rule #1 for type string + } + } +} + +#[allow(unused_variables)] +impl From for responses::KeysendResponse { + fn from(c: pb::KeysendResponse) -> Self { + Self { + payment_preimage: c.payment_preimage.try_into().unwrap(), // Rule #1 for type secret + destination: c.destination.map(|v| PublicKey::from_slice(&v).unwrap()), // Rule #1 for type pubkey? + payment_hash: Sha256::from_slice(&c.payment_hash).unwrap(), // Rule #1 for type hash + created_at: c.created_at, // Rule #1 for type number + parts: c.parts, // Rule #1 for type u32 + amount_msat: c.amount_msat.unwrap().into(), // Rule #1 for type msat + amount_sent_msat: c.amount_sent_msat.unwrap().into(), // Rule #1 for type msat + warning_partial_completion: c.warning_partial_completion, // Rule #1 for type string? + status: c.status.try_into().unwrap(), + } + } +} + +#[allow(unused_variables)] +impl From for responses::FundpsbtReservations { + fn from(c: pb::FundpsbtReservations) -> Self { + Self { + txid: hex::encode(&c.txid), // Rule #1 for type txid + vout: c.vout, // Rule #1 for type u32 + was_reserved: c.was_reserved, // Rule #1 for type boolean + reserved: c.reserved, // Rule #1 for type boolean + reserved_to_block: c.reserved_to_block, // Rule #1 for type u32 + } + } +} + +#[allow(unused_variables)] +impl From for responses::FundpsbtResponse { + fn from(c: pb::FundpsbtResponse) -> Self { + Self { + psbt: c.psbt, // Rule #1 for type string + feerate_per_kw: c.feerate_per_kw, // Rule #1 for type u32 + estimated_final_weight: c.estimated_final_weight, // Rule #1 for type u32 + excess_msat: c.excess_msat.unwrap().into(), // Rule #1 for type msat + change_outnum: c.change_outnum, // Rule #1 for type u32? + reservations: Some(c.reservations.into_iter().map(|s| s.into()).collect()), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::SendpsbtResponse { + fn from(c: pb::SendpsbtResponse) -> Self { + Self { + tx: hex::encode(&c.tx), // Rule #1 for type hex + txid: hex::encode(&c.txid), // Rule #1 for type txid + } + } +} + +#[allow(unused_variables)] +impl From for responses::SignpsbtResponse { + fn from(c: pb::SignpsbtResponse) -> Self { + Self { + signed_psbt: c.signed_psbt, // Rule #1 for type string + } + } +} + +#[allow(unused_variables)] +impl From for responses::UtxopsbtReservations { + fn from(c: pb::UtxopsbtReservations) -> Self { + Self { + txid: hex::encode(&c.txid), // Rule #1 for type txid + vout: c.vout, // Rule #1 for type u32 + was_reserved: c.was_reserved, // Rule #1 for type boolean + reserved: c.reserved, // Rule #1 for type boolean + reserved_to_block: c.reserved_to_block, // Rule #1 for type u32 + } + } +} + +#[allow(unused_variables)] +impl From for responses::UtxopsbtResponse { + fn from(c: pb::UtxopsbtResponse) -> Self { + Self { + psbt: c.psbt, // Rule #1 for type string + feerate_per_kw: c.feerate_per_kw, // Rule #1 for type u32 + estimated_final_weight: c.estimated_final_weight, // Rule #1 for type u32 + excess_msat: c.excess_msat.unwrap().into(), // Rule #1 for type msat + change_outnum: c.change_outnum, // Rule #1 for type u32? + reservations: Some(c.reservations.into_iter().map(|s| s.into()).collect()), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::TxdiscardResponse { + fn from(c: pb::TxdiscardResponse) -> Self { + Self { + unsigned_tx: hex::encode(&c.unsigned_tx), // Rule #1 for type hex + txid: hex::encode(&c.txid), // Rule #1 for type txid + } + } +} + +#[allow(unused_variables)] +impl From for responses::TxprepareResponse { + fn from(c: pb::TxprepareResponse) -> Self { + Self { + psbt: c.psbt, // Rule #1 for type string + unsigned_tx: hex::encode(&c.unsigned_tx), // Rule #1 for type hex + txid: hex::encode(&c.txid), // Rule #1 for type txid + } + } +} + +#[allow(unused_variables)] +impl From for responses::TxsendResponse { + fn from(c: pb::TxsendResponse) -> Self { + Self { + psbt: c.psbt, // Rule #1 for type string + tx: hex::encode(&c.tx), // Rule #1 for type hex + txid: hex::encode(&c.txid), // Rule #1 for type txid + } + } +} + +#[allow(unused_variables)] +impl From for responses::DisconnectResponse { + fn from(c: pb::DisconnectResponse) -> Self { + Self { + } + } +} + +#[allow(unused_variables)] +impl From for responses::FeeratesPerkb { + fn from(c: pb::FeeratesPerkb) -> Self { + Self { + min_acceptable: c.min_acceptable, // Rule #1 for type u32 + max_acceptable: c.max_acceptable, // Rule #1 for type u32 + opening: c.opening, // Rule #1 for type u32? + mutual_close: c.mutual_close, // Rule #1 for type u32? + unilateral_close: c.unilateral_close, // Rule #1 for type u32? + delayed_to_us: c.delayed_to_us, // Rule #1 for type u32? + htlc_resolution: c.htlc_resolution, // Rule #1 for type u32? + penalty: c.penalty, // Rule #1 for type u32? + } + } +} + +#[allow(unused_variables)] +impl From for responses::FeeratesPerkw { + fn from(c: pb::FeeratesPerkw) -> Self { + Self { + min_acceptable: c.min_acceptable, // Rule #1 for type u32 + max_acceptable: c.max_acceptable, // Rule #1 for type u32 + opening: c.opening, // Rule #1 for type u32? + mutual_close: c.mutual_close, // Rule #1 for type u32? + unilateral_close: c.unilateral_close, // Rule #1 for type u32? + delayed_to_us: c.delayed_to_us, // Rule #1 for type u32? + htlc_resolution: c.htlc_resolution, // Rule #1 for type u32? + penalty: c.penalty, // Rule #1 for type u32? + } + } +} + +#[allow(unused_variables)] +impl From for responses::FeeratesOnchain_fee_estimates { + fn from(c: pb::FeeratesOnchainFeeEstimates) -> Self { + Self { + opening_channel_satoshis: c.opening_channel_satoshis, // Rule #1 for type u64 + mutual_close_satoshis: c.mutual_close_satoshis, // Rule #1 for type u64 + unilateral_close_satoshis: c.unilateral_close_satoshis, // Rule #1 for type u64 + htlc_timeout_satoshis: c.htlc_timeout_satoshis, // Rule #1 for type u64 + htlc_success_satoshis: c.htlc_success_satoshis, // Rule #1 for type u64 + } + } +} + +#[allow(unused_variables)] +impl From for responses::FeeratesResponse { + fn from(c: pb::FeeratesResponse) -> Self { + Self { + warning_missing_feerates: c.warning_missing_feerates, // Rule #1 for type string? + perkb: c.perkb.map(|v| v.into()), + perkw: c.perkw.map(|v| v.into()), + onchain_fee_estimates: c.onchain_fee_estimates.map(|v| v.into()), + } + } +} + +#[allow(unused_variables)] +impl From for responses::FundchannelResponse { + fn from(c: pb::FundchannelResponse) -> Self { + Self { + tx: hex::encode(&c.tx), // Rule #1 for type hex + txid: hex::encode(&c.txid), // Rule #1 for type txid + outnum: c.outnum, // Rule #1 for type u32 + channel_id: hex::encode(&c.channel_id), // Rule #1 for type hex + close_to: c.close_to.map(|v| hex::encode(v)), // Rule #1 for type hex? + mindepth: c.mindepth, // Rule #1 for type u32? + } + } +} + +#[allow(unused_variables)] +impl From for responses::GetrouteRoute { + fn from(c: pb::GetrouteRoute) -> Self { + Self { + id: PublicKey::from_slice(&c.id).unwrap(), // Rule #1 for type pubkey + channel: cln_rpc::primitives::ShortChannelId::from_str(&c.channel).unwrap(), // Rule #1 for type short_channel_id + direction: c.direction, // Rule #1 for type u32 + msatoshi: c.msatoshi, // Rule #1 for type u64? + amount_msat: c.amount_msat.unwrap().into(), // Rule #1 for type msat + delay: c.delay, // Rule #1 for type u32 + style: c.style.try_into().unwrap(), + } + } +} + +#[allow(unused_variables)] +impl From for responses::GetrouteResponse { + fn from(c: pb::GetrouteResponse) -> Self { + Self { + route: c.route.into_iter().map(|s| s.into()).collect(), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListforwardsForwards { + fn from(c: pb::ListforwardsForwards) -> Self { + Self { + in_channel: cln_rpc::primitives::ShortChannelId::from_str(&c.in_channel).unwrap(), // Rule #1 for type short_channel_id + in_htlc_id: c.in_htlc_id, // Rule #1 for type u64? + in_msat: c.in_msat.unwrap().into(), // Rule #1 for type msat + status: c.status.try_into().unwrap(), + received_time: c.received_time, // Rule #1 for type number + out_channel: c.out_channel.map(|v| cln_rpc::primitives::ShortChannelId::from_str(&v).unwrap()), // Rule #1 for type short_channel_id? + out_htlc_id: c.out_htlc_id, // Rule #1 for type u64? + style: c.style.map(|v| v.try_into().unwrap()), + fee_msat: c.fee_msat.map(|a| a.into()), // Rule #1 for type msat? + out_msat: c.out_msat.map(|a| a.into()), // Rule #1 for type msat? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListforwardsResponse { + fn from(c: pb::ListforwardsResponse) -> Self { + Self { + forwards: c.forwards.into_iter().map(|s| s.into()).collect(), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListpaysPays { + fn from(c: pb::ListpaysPays) -> Self { + Self { + payment_hash: Sha256::from_slice(&c.payment_hash).unwrap(), // Rule #1 for type hash + status: c.status.try_into().unwrap(), + destination: c.destination.map(|v| PublicKey::from_slice(&v).unwrap()), // Rule #1 for type pubkey? + created_at: c.created_at, // Rule #1 for type u64 + completed_at: c.completed_at, // Rule #1 for type u64? + label: c.label, // Rule #1 for type string? + bolt11: c.bolt11, // Rule #1 for type string? + description: c.description, // Rule #1 for type string? + bolt12: c.bolt12, // Rule #1 for type string? + preimage: c.preimage.map(|v| v.try_into().unwrap()), // Rule #1 for type secret? + number_of_parts: c.number_of_parts, // Rule #1 for type u64? + erroronion: c.erroronion.map(|v| hex::encode(v)), // Rule #1 for type hex? + } + } +} + +#[allow(unused_variables)] +impl From for responses::ListpaysResponse { + fn from(c: pb::ListpaysResponse) -> Self { + Self { + pays: c.pays.into_iter().map(|s| s.into()).collect(), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::PingResponse { + fn from(c: pb::PingResponse) -> Self { + Self { + totlen: c.totlen as u16, // Rule #1 for type u16 + } + } +} + +#[allow(unused_variables)] +impl From for responses::SetchannelChannels { + fn from(c: pb::SetchannelChannels) -> Self { + Self { + peer_id: PublicKey::from_slice(&c.peer_id).unwrap(), // Rule #1 for type pubkey + channel_id: hex::encode(&c.channel_id), // Rule #1 for type hex + short_channel_id: c.short_channel_id.map(|v| cln_rpc::primitives::ShortChannelId::from_str(&v).unwrap()), // Rule #1 for type short_channel_id? + fee_base_msat: c.fee_base_msat.unwrap().into(), // Rule #1 for type msat + fee_proportional_millionths: c.fee_proportional_millionths, // Rule #1 for type u32 + minimum_htlc_out_msat: c.minimum_htlc_out_msat.unwrap().into(), // Rule #1 for type msat + warning_htlcmin_too_low: c.warning_htlcmin_too_low, // Rule #1 for type string? + maximum_htlc_out_msat: c.maximum_htlc_out_msat.unwrap().into(), // Rule #1 for type msat + warning_htlcmax_too_high: c.warning_htlcmax_too_high, // Rule #1 for type string? + } + } +} + +#[allow(unused_variables)] +impl From for responses::SetchannelResponse { + fn from(c: pb::SetchannelResponse) -> Self { + Self { + channels: c.channels.into_iter().map(|s| s.into()).collect(), // Rule #4 + } + } +} + +#[allow(unused_variables)] +impl From for responses::SignmessageResponse { + fn from(c: pb::SignmessageResponse) -> Self { + Self { + signature: hex::encode(&c.signature), // Rule #1 for type hex + recid: hex::encode(&c.recid), // Rule #1 for type hex + zbase: c.zbase, // Rule #1 for type string + } + } +} + +#[allow(unused_variables)] +impl From for responses::StopResponse { + fn from(c: pb::StopResponse) -> Self { + Self { + } + } +} + diff --git a/cln-rpc/src/primitives.rs b/cln-rpc/src/primitives.rs index 4dbc97079..9caf76d60 100644 --- a/cln-rpc/src/primitives.rs +++ b/cln-rpc/src/primitives.rs @@ -254,6 +254,41 @@ pub enum ChannelSide { REMOTE, } +impl TryFrom for ChannelSide { + type Error = crate::Error; + + fn try_from(value: i32) -> std::result::Result { + match value { + 0 => Ok(ChannelSide::LOCAL), + 1 => Ok(ChannelSide::REMOTE), + _ => Err(anyhow!( + "Invalid ChannelSide mapping, only 0 or 1 are allowed" + )), + } + } +} + +impl TryFrom for ChannelState { + type Error = crate::Error; + + fn try_from(value: i32) -> std::result::Result { + match value { + 0 => Ok(ChannelState::OPENINGD), + 1 => Ok(ChannelState::CHANNELD_AWAITING_LOCKIN), + 2 => Ok(ChannelState::CHANNELD_NORMAL), + 3 => Ok(ChannelState::CHANNELD_SHUTTING_DOWN), + 4 => Ok(ChannelState::CLOSINGD_SIGEXCHANGE), + 5 => Ok(ChannelState::CLOSINGD_COMPLETE), + 6 => Ok(ChannelState::AWAITING_UNILATERAL), + 7 => Ok(ChannelState::FUNDING_SPEND_SEEN), + 8 => Ok(ChannelState::ONCHAIN), + 9 => Ok(ChannelState::DUALOPEND_OPEN_INIT), + 10 => Ok(ChannelState::DUALOPEND_AWAITING_LOCKIN), + _ => Err(anyhow!("Invalid channel state {}", value)), + } + } +} + impl<'de> Deserialize<'de> for Amount { fn deserialize(deserializer: D) -> Result where diff --git a/contrib/msggen/msggen/gen/grpc.py b/contrib/msggen/msggen/gen/grpc.py index e0a85dd1d..7bf6ee291 100644 --- a/contrib/msggen/msggen/gen/grpc.py +++ b/contrib/msggen/msggen/gen/grpc.py @@ -405,6 +405,7 @@ class GrpcUnconverterGenerator(GrpcConverterGenerator): """ def generate(self, service: Service): self.generate_requests(service) + self.generate_responses(service) def generate_composite(self, prefix, field: CompositeField) -> None: # First pass: generate any sub-fields before we generate the @@ -436,12 +437,22 @@ class GrpcUnconverterGenerator(GrpcConverterGenerator): 'u32': f's', 'secret': f's.try_into().unwrap()' }.get(typ, f's.into()') + + # TODO fix properly + if typ in ["ListtransactionsTransactionsType"]: + continue + if name == 'state_changes': + self.write(f" state_changes: None,") + continue + if f.required: self.write(f"{name}: c.{name}.into_iter().map(|s| {mapping}).collect(), // Rule #4\n", numindent=3) else: self.write(f"{name}: Some(c.{name}.into_iter().map(|s| {mapping}).collect()), // Rule #4\n", numindent=3) elif isinstance(f, EnumField): + if f.path == 'ListPeers.peers[].channels[].htlcs[].state': + continue if f.required: self.write(f"{name}: c.{name}.try_into().unwrap(),\n", numindent=3) else: @@ -453,7 +464,12 @@ class GrpcUnconverterGenerator(GrpcConverterGenerator): # types, or have some conversion such as # hex-decoding. Also includes the `Some()` that grpc # requires for non-native types. + + if name == "scriptPubKey": + name = "script_pub_key" + rhs = { + 'u8': f'c.{name} as u8', 'u16': f'c.{name} as u16', 'u16?': f'c.{name}.map(|v| v as u16)', 'hex': f'hex::encode(&c.{name})',