diff --git a/Cargo.lock b/Cargo.lock index 6bd52c4..847f68a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -814,6 +814,7 @@ dependencies = [ "hyper-util", "ldk-node", "prost", + "protos", "serde", "serde_json", "tokio", @@ -1143,6 +1144,14 @@ dependencies = [ "prost", ] +[[package]] +name = "protos" +version = "0.1.0" +dependencies = [ + "prost", + "prost-build", +] + [[package]] name = "quote" version = "1.0.36" diff --git a/Cargo.toml b/Cargo.toml index 9f05927..61b420c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [workspace] resolver = "2" -members = [ "cli", "client", "server"] +members = [ "cli", "client", "protos", "server"] [profile.release] panic = "abort" diff --git a/protos/Cargo.toml b/protos/Cargo.toml new file mode 100644 index 0000000..7a69b66 --- /dev/null +++ b/protos/Cargo.toml @@ -0,0 +1,12 @@ +[package] +name = "protos" +version = "0.1.0" +edition = "2021" + +build = "build.rs" + +[dependencies] +prost = { version = "0.11.6", default-features = false, features = ["std", "prost-derive"] } + +[target.'cfg(genproto)'.build-dependencies] +prost-build = { version = "0.11.6" , default-features = false} diff --git a/protos/build.rs b/protos/build.rs new file mode 100644 index 0000000..b65f50d --- /dev/null +++ b/protos/build.rs @@ -0,0 +1,20 @@ +#[cfg(genproto)] +extern crate prost_build; + +#[cfg(genproto)] +use std::{env, fs, path::Path}; + +/// To generate updated proto objects, run `RUSTFLAGS="--cfg genproto" cargo build` +fn main() { + #[cfg(genproto)] + generate_protos(); +} + +#[cfg(genproto)] +fn generate_protos() { + prost_build::compile_protos(&["src/proto/ldk_node_server.proto"], &["src/"]) + .expect("protobuf compilation failed"); + println!("sss {}", &env::var("OUT_DIR").unwrap()); + let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("ldk_node_server.rs"); + fs::copy(from_path, "src/lib.rs").unwrap(); +} diff --git a/protos/src/lib.rs b/protos/src/lib.rs new file mode 100644 index 0000000..689db8c --- /dev/null +++ b/protos/src/lib.rs @@ -0,0 +1,416 @@ +/// Retrieve a new on-chain funding address. +/// See more: +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct OnchainReceiveRequest {} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct OnchainReceiveResponse { + /// A Bitcoin on-chain address. + #[prost(string, tag = "1")] + pub address: ::prost::alloc::string::String, +} +/// Send an on-chain payment to the given address. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct OnchainSendRequest { + /// The address to send coins to. + #[prost(string, tag = "1")] + pub address: ::prost::alloc::string::String, + /// The amount in satoshis to send. + /// While sending the specified amount, we will respect any on-chain reserve we need to keep, + /// i.e., won't allow to cut into `total_anchor_channels_reserve_sats`. + /// See more: + #[prost(uint64, optional, tag = "2")] + pub amount_sats: ::core::option::Option, + /// If set, the amount_sats field should be unset. + /// It indicates that node will send full balance to the specified address. + /// + /// Please note that when send_all is used this operation will **not** retain any on-chain reserves, + /// which might be potentially dangerous if you have open Anchor channels for which you can't trust + /// the counterparty to spend the Anchor output after channel closure. + /// See more: + #[prost(bool, optional, tag = "3")] + pub send_all: ::core::option::Option, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct OnchainSendResponse { + /// The transaction ID of the broadcasted transaction. + #[prost(string, tag = "1")] + pub txid: ::prost::alloc::string::String, +} +/// Return a BOLT11 payable invoice that can be used to request and receive a payment +/// for the given amount, if specified. +/// The inbound payment will be automatically claimed upon arrival. +/// See more: +/// - +/// - +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Bolt11ReceiveRequest { + /// The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount invoice is returned. + #[prost(uint64, optional, tag = "1")] + pub amount_msat: ::core::option::Option, + /// An optional description to attach along with the invoice. + /// Will be set in the description field of the encoded payment request. + #[prost(string, tag = "2")] + pub description: ::prost::alloc::string::String, + /// Invoice expiry time in seconds. + #[prost(uint32, tag = "3")] + pub expiry_secs: u32, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Bolt11ReceiveResponse { + /// An invoice for a payment within the Lightning Network. + /// With the details of the invoice, the sender has all the data necessary to send a payment + /// to the recipient. + #[prost(string, tag = "1")] + pub invoice: ::prost::alloc::string::String, +} +/// Send a payment for a BOLT11 invoice. +/// See more: +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Bolt11SendRequest { + /// An invoice for a payment within the Lightning Network. + #[prost(string, tag = "1")] + pub invoice: ::prost::alloc::string::String, + /// Set this field when paying a so-called "zero-amount" invoice, i.e., an invoice that leaves the + /// amount paid to be determined by the user. + /// This operation will fail if the amount specified is less than the value required by the given invoice. + #[prost(uint64, optional, tag = "2")] + pub amount_msat: ::core::option::Option, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Bolt11SendResponse { + /// An identifier used to uniquely identify a payment. + #[prost(message, optional, tag = "1")] + pub payment_id: ::core::option::Option, +} +/// An identifier used to uniquely identify a payment. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct PaymentId { + #[prost(bytes = "vec", tag = "1")] + pub data: ::prost::alloc::vec::Vec, +} +/// Returns a BOLT12 offer for the given amount, if specified. +/// +/// See more: +/// - +/// - +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Bolt12ReceiveRequest { + /// An optional description to attach along with the offer. + /// Will be set in the description field of the encoded offer. + #[prost(string, tag = "1")] + pub description: ::prost::alloc::string::String, + /// The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount offer is returned. + #[prost(uint64, optional, tag = "2")] + pub amount_msat: ::core::option::Option, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Bolt12ReceiveResponse { + /// An offer for a payment within the Lightning Network. + /// With the details of the offer, the sender has all the data necessary to send a payment + /// to the recipient. + #[prost(string, tag = "1")] + pub offer: ::prost::alloc::string::String, +} +/// Send a payment for a BOLT12 offer. +/// See more: +/// - +/// - +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Bolt12SendRequest { + /// An offer for a payment within the Lightning Network. + #[prost(string, tag = "1")] + pub offer: ::prost::alloc::string::String, + /// Set this field when paying a so-called "zero-amount" offer, i.e., an offer that leaves the + /// amount paid to be determined by the user. + /// This operation will fail if the amount specified is less than the value required by the given offer. + #[prost(uint64, optional, tag = "2")] + pub amount_msat: ::core::option::Option, + /// If set, it represents the number of items requested. + #[prost(uint64, optional, tag = "3")] + pub quantity: ::core::option::Option, + /// If set, it will be seen by the recipient and reflected back in the invoice. + #[prost(string, optional, tag = "4")] + pub payer_note: ::core::option::Option<::prost::alloc::string::String>, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Bolt12SendResponse { + /// An identifier used to uniquely identify a payment. + #[prost(message, optional, tag = "1")] + pub payment_id: ::core::option::Option, +} +/// Creates a new outbound channel to the given remote node. +/// See more: +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct OpenChannelRequest { + /// The hex-encoded public key of the node to open a channel with. + #[prost(string, tag = "1")] + pub node_pubkey: ::prost::alloc::string::String, + /// An address which can be used to connect to a remote peer. + /// It can be of type IPv4:port, IPv6:port, OnionV3:port or hostname:port + #[prost(string, tag = "2")] + pub address: ::prost::alloc::string::String, + /// The amount of satoshis the caller is willing to commit to the channel. + #[prost(uint64, tag = "3")] + pub channel_amount_sats: u64, + /// The amount of satoshis to push to the remote side as part of the initial commitment state. + #[prost(uint64, optional, tag = "4")] + pub push_to_counterparty_msat: ::core::option::Option, + /// The channel configuration to be used for opening this channel. If unset, default ChannelConfig is used. + #[prost(message, optional, tag = "5")] + pub channel_config: ::core::option::Option, + /// Whether the channel should be public. + #[prost(bool, tag = "6")] + pub announce_channel: bool, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct OpenChannelResponse { + /// The channel id of the created channel that user can use to refer to channel. + #[prost(bytes = "vec", tag = "1")] + pub user_channel_id: ::prost::alloc::vec::Vec, +} +/// ChannelConfig represents the configuration settings for a channel in a Lightning Network node. +/// See more: +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ChannelConfig { + /// Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound + /// over the channel. + /// See more: + #[prost(uint32, tag = "1")] + pub forwarding_fee_proportional_millionths: u32, + /// Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, + /// in excess of forwarding_fee_proportional_millionths. + /// See more: + #[prost(uint32, tag = "2")] + pub forwarding_fee_base_msat: u32, + /// The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded + /// over the channel this config applies to. + /// See more: + #[prost(uint32, tag = "3")] + pub cltv_expiry_delta: u32, + /// The maximum additional fee we’re willing to pay to avoid waiting for the counterparty’s + /// to_self_delay to reclaim funds. + /// See more: + #[prost(uint64, tag = "4")] + pub force_close_avoidance_max_fee_satoshis: u64, + /// If set, allows this channel’s counterparty to skim an additional fee off this node’s + /// inbound HTLCs. Useful for liquidity providers to offload on-chain channel costs to end users. + /// See more: + #[prost(bool, tag = "5")] + pub accept_underpaying_htlcs: bool, + /// Limit our total exposure to potential loss to on-chain fees on close, including + /// in-flight HTLCs which are burned to fees as they are too small to claim on-chain + /// and fees on commitment transaction(s) broadcasted by our counterparty in excess of + /// our own fee estimate. + /// See more: + #[prost(oneof = "channel_config::MaxDustHtlcExposure", tags = "6, 7")] + pub max_dust_htlc_exposure: ::core::option::Option, +} +/// Nested message and enum types in `ChannelConfig`. +pub mod channel_config { + /// Limit our total exposure to potential loss to on-chain fees on close, including + /// in-flight HTLCs which are burned to fees as they are too small to claim on-chain + /// and fees on commitment transaction(s) broadcasted by our counterparty in excess of + /// our own fee estimate. + /// See more: + #[allow(clippy::derive_partial_eq_without_eq)] + #[derive(Clone, PartialEq, ::prost::Oneof)] + pub enum MaxDustHtlcExposure { + /// This sets a fixed limit on the total dust exposure in millisatoshis. + /// See more: + #[prost(uint64, tag = "6")] + FixedLimitMsat(u64), + /// This sets a multiplier on the ConfirmationTarget::OnChainSweep feerate (in sats/KW) to determine the maximum allowed dust exposure. + /// See more: + #[prost(uint64, tag = "7")] + FeeRateMultiplier(u64), + } +} +/// Closes the channel specified by given request. +/// See more: +/// - +/// - +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct CloseChannelRequest { + /// The channel id of the created channel that user can use to refer to channel. + #[prost(bytes = "vec", tag = "1")] + pub user_channel_id: ::prost::alloc::vec::Vec, + /// The hex-encoded public key of the node to close a channel with. + #[prost(string, tag = "2")] + pub counterparty_node_id: ::prost::alloc::string::String, + /// Whether to force close the specified channel. + #[prost(bool, tag = "3")] + pub force_close: bool, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct CloseChannelResponse {} +/// Returns a list of known channels. +/// See more: +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ListChannelsRequest {} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct ListChannelsResponse { + /// List of channels. + #[prost(message, repeated, tag = "1")] + pub channels: ::prost::alloc::vec::Vec, +} +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Channel { + /// The channel ID (prior to funding transaction generation, this is a random 32-byte + /// identifier, afterwards this is the transaction ID of the funding transaction XOR the + /// funding transaction output). + /// + /// Note that this means this value is *not* persistent - it can change once during the + /// lifetime of the channel. + #[prost(string, tag = "1")] + pub channel_id: ::prost::alloc::string::String, + /// The node ID of our the channel's remote counterparty. + #[prost(string, tag = "2")] + pub counterparty_node_id: ::prost::alloc::string::String, + /// The channel's funding transaction output, if we've negotiated the funding transaction with + /// our counterparty already. + #[prost(message, optional, tag = "3")] + pub funding_txo: ::core::option::Option, + /// The local `user_channel_id` of this channel. + #[prost(bytes = "vec", tag = "4")] + pub user_channel_id: ::prost::alloc::vec::Vec, + /// The value, in satoshis, that must always be held as a reserve in the channel for us. This + /// value ensures that if we broadcast a revoked state, our counterparty can punish us by + /// claiming at least this value on chain. + /// + /// This value is not included in \[`outbound_capacity_msat`\] as it can never be spent. + /// + /// This value will be `None` for outbound channels until the counterparty accepts the channel. + #[prost(uint64, optional, tag = "5")] + pub unspendable_punishment_reserve: ::core::option::Option, + /// The value, in satoshis, of this channel as it appears in the funding output. + #[prost(uint64, tag = "6")] + pub channel_value_sats: u64, + /// The currently negotiated fee rate denominated in satoshi per 1000 weight units, + /// which is applied to commitment and HTLC transactions. + #[prost(uint32, tag = "7")] + pub feerate_sat_per_1000_weight: u32, + /// The available outbound capacity for sending HTLCs to the remote peer. + /// + /// The amount does not include any pending HTLCs which are not yet resolved (and, thus, whose + /// balance is not available for inclusion in new outbound HTLCs). This further does not include + /// any pending outgoing HTLCs which are awaiting some other resolution to be sent. + #[prost(uint64, tag = "8")] + pub outbound_capacity_msat: u64, + /// The available outbound capacity for sending HTLCs to the remote peer. + /// + /// The amount does not include any pending HTLCs which are not yet resolved + /// (and, thus, whose balance is not available for inclusion in new inbound HTLCs). This further + /// does not include any pending outgoing HTLCs which are awaiting some other resolution to be + /// sent. + #[prost(uint64, tag = "9")] + pub inbound_capacity_msat: u64, + /// The number of required confirmations on the funding transactions before the funding is + /// considered "locked". The amount is selected by the channel fundee. + /// + /// The value will be `None` for outbound channels until the counterparty accepts the channel. + #[prost(uint32, optional, tag = "10")] + pub confirmations_required: ::core::option::Option, + /// The current number of confirmations on the funding transaction. + #[prost(uint32, optional, tag = "11")] + pub confirmations: ::core::option::Option, + /// Is `true` if the channel was initiated (and therefore funded) by us. + #[prost(bool, tag = "12")] + pub is_outbound: bool, + /// Is `true` if both parties have exchanged `channel_ready` messages, and the channel is + /// not currently being shut down. Both parties exchange `channel_ready` messages upon + /// independently verifying that the required confirmations count provided by + /// `confirmations_required` has been reached. + #[prost(bool, tag = "13")] + pub is_channel_ready: bool, + /// Is `true` if the channel (a) `channel_ready` messages have been exchanged, (b) the + /// peer is connected, and (c) the channel is not currently negotiating shutdown. + /// + /// This is a strict superset of `is_channel_ready`. + #[prost(bool, tag = "14")] + pub is_usable: bool, + /// Is `true` if this channel is (or will be) publicly-announced + #[prost(bool, tag = "15")] + pub is_public: bool, + /// Set of configurable parameters set by self that affect channel operation. + #[prost(message, optional, tag = "16")] + pub channel_config: ::core::option::Option, + /// The available outbound capacity for sending a single HTLC to the remote peer. This is + /// similar to `outbound_capacity_msat` but it may be further restricted by + /// the current state and per-HTLC limit(s). This is intended for use when routing, allowing us + /// to use a limit as close as possible to the HTLC limit we can currently send. + #[prost(uint64, tag = "17")] + pub next_outbound_htlc_limit_msat: u64, + /// The minimum value for sending a single HTLC to the remote peer. This is the equivalent of + /// `next_outbound_htlc_limit_msat` but represents a lower-bound, rather than + /// an upper-bound. This is intended for use when routing, allowing us to ensure we pick a + /// route which is valid. + #[prost(uint64, tag = "18")] + pub next_outbound_htlc_minimum_msat: u64, + /// The number of blocks (after our commitment transaction confirms) that we will need to wait + /// until we can claim our funds after we force-close the channel. During this time our + /// counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty + /// force-closes the channel and broadcasts a commitment transaction we do not have to wait any + /// time to claim our non-HTLC-encumbered funds. + /// + /// This value will be `None` for outbound channels until the counterparty accepts the channel. + #[prost(uint32, optional, tag = "19")] + pub force_close_spend_delay: ::core::option::Option, + /// The smallest value HTLC (in msat) the remote peer will accept, for this channel. + /// + /// This field is only `None` before we have received either the `OpenChannel` or + /// `AcceptChannel` message from the remote peer. + #[prost(uint64, optional, tag = "20")] + pub counterparty_outbound_htlc_minimum_msat: ::core::option::Option, + /// The largest value HTLC (in msat) the remote peer currently will accept, for this channel. + #[prost(uint64, optional, tag = "21")] + pub counterparty_outbound_htlc_maximum_msat: ::core::option::Option, + /// The value, in satoshis, that must always be held in the channel for our counterparty. This + /// value ensures that if our counterparty broadcasts a revoked state, we can punish them by + /// claiming at least this value on chain. + /// + /// This value is not included in `inbound_capacity_msat` as it can never be spent. + #[prost(uint64, optional, tag = "22")] + pub counterparty_unspendable_punishment_reserve: ::core::option::Option, + /// Base routing fee in millisatoshis. + #[prost(uint32, optional, tag = "23")] + pub counterparty_forwarding_info_fee_base_msat: ::core::option::Option, + /// Proportional fee, in millionths of a satoshi the channel will charge per transferred satoshi. + #[prost(uint32, optional, tag = "24")] + pub counterparty_forwarding_info_fee_proportional_millionths: ::core::option::Option, + /// The minimum difference in CLTV expiry between an ingoing HTLC and its outgoing counterpart, + /// such that the outgoing HTLC is forwardable to this counterparty. + #[prost(uint32, optional, tag = "25")] + pub counterparty_forwarding_info_cltv_expiry_delta: ::core::option::Option, +} +/// Represent a transaction outpoint. +#[allow(clippy::derive_partial_eq_without_eq)] +#[derive(Clone, PartialEq, ::prost::Message)] +pub struct Outpoint { + /// The referenced transaction's txid. + #[prost(string, tag = "1")] + pub txid: ::prost::alloc::string::String, + /// The index of the referenced output in its transaction's vout. + #[prost(uint32, tag = "2")] + pub vout: u32, +} diff --git a/protos/src/proto/ldk_node_server.proto b/protos/src/proto/ldk_node_server.proto new file mode 100644 index 0000000..07409d8 --- /dev/null +++ b/protos/src/proto/ldk_node_server.proto @@ -0,0 +1,387 @@ +syntax = "proto3"; +package ldk_node_server; + +// Retrieve a new on-chain funding address. +// See more: https://docs.rs/ldk-node/latest/ldk_node/payment/struct.OnchainPayment.html#method.new_address +message OnchainReceiveRequest { +} + +message OnchainReceiveResponse { + + // A Bitcoin on-chain address. + string address = 1; +} + +// Send an on-chain payment to the given address. +message OnchainSendRequest { + + // The address to send coins to. + string address = 1; + + // The amount in satoshis to send. + // While sending the specified amount, we will respect any on-chain reserve we need to keep, + // i.e., won't allow to cut into `total_anchor_channels_reserve_sats`. + // See more: https://docs.rs/ldk-node/latest/ldk_node/payment/struct.OnchainPayment.html#method.send_to_address + optional uint64 amount_sats = 2; + + // If set, the amount_sats field should be unset. + // It indicates that node will send full balance to the specified address. + // + // Please note that when send_all is used this operation will **not** retain any on-chain reserves, + // which might be potentially dangerous if you have open Anchor channels for which you can't trust + // the counterparty to spend the Anchor output after channel closure. + // See more: https://docs.rs/ldk-node/latest/ldk_node/payment/struct.OnchainPayment.html#method.send_all_to_address + optional bool send_all = 3; +} + +message OnchainSendResponse { + + // The transaction ID of the broadcasted transaction. + string txid = 1; +} + +// Return a BOLT11 payable invoice that can be used to request and receive a payment +// for the given amount, if specified. +// The inbound payment will be automatically claimed upon arrival. +// See more: +// - https://docs.rs/ldk-node/latest/ldk_node/payment/struct.Bolt11Payment.html#method.receive +// - https://docs.rs/ldk-node/latest/ldk_node/payment/struct.Bolt11Payment.html#method.receive_variable_amount +message Bolt11ReceiveRequest { + + // The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount invoice is returned. + optional uint64 amount_msat = 1; + + // An optional description to attach along with the invoice. + // Will be set in the description field of the encoded payment request. + string description = 2; + + // Invoice expiry time in seconds. + uint32 expiry_secs = 3; +} + + +message Bolt11ReceiveResponse { + + // An invoice for a payment within the Lightning Network. + // With the details of the invoice, the sender has all the data necessary to send a payment + // to the recipient. + string invoice = 1; +} + +// Send a payment for a BOLT11 invoice. +// See more: https://docs.rs/ldk-node/latest/ldk_node/payment/struct.Bolt11Payment.html#method.send +message Bolt11SendRequest { + + // An invoice for a payment within the Lightning Network. + string invoice = 1; + + // Set this field when paying a so-called "zero-amount" invoice, i.e., an invoice that leaves the + // amount paid to be determined by the user. + // This operation will fail if the amount specified is less than the value required by the given invoice. + optional uint64 amount_msat = 2; + +} + +message Bolt11SendResponse { + + // An identifier used to uniquely identify a payment. + PaymentId payment_id = 1; +} + +// An identifier used to uniquely identify a payment. +message PaymentId { + + bytes data = 1; +} + +// Returns a BOLT12 offer for the given amount, if specified. +// +// See more: +// - https://docs.rs/ldk-node/latest/ldk_node/payment/struct.Bolt12Payment.html#method.receive +// - https://docs.rs/ldk-node/latest/ldk_node/payment/struct.Bolt12Payment.html#method.receive_variable_amount +message Bolt12ReceiveRequest { + + // An optional description to attach along with the offer. + // Will be set in the description field of the encoded offer. + string description = 1; + + // The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount offer is returned. + optional uint64 amount_msat = 2; +} + +message Bolt12ReceiveResponse { + + // An offer for a payment within the Lightning Network. + // With the details of the offer, the sender has all the data necessary to send a payment + // to the recipient. + string offer = 1; +} + +// Send a payment for a BOLT12 offer. +// See more: +// - https://docs.rs/ldk-node/latest/ldk_node/payment/struct.Bolt12Payment.html#method.send +// - https://docs.rs/ldk-node/latest/ldk_node/payment/struct.Bolt12Payment.html#method.send_using_amount +message Bolt12SendRequest { + + // An offer for a payment within the Lightning Network. + string offer = 1; + + // Set this field when paying a so-called "zero-amount" offer, i.e., an offer that leaves the + // amount paid to be determined by the user. + // This operation will fail if the amount specified is less than the value required by the given offer. + optional uint64 amount_msat = 2; + + // If set, it represents the number of items requested. + optional uint64 quantity = 3; + + // If set, it will be seen by the recipient and reflected back in the invoice. + optional string payer_note = 4; +} + +message Bolt12SendResponse { + + // An identifier used to uniquely identify a payment. + PaymentId payment_id = 1; +} + +// Creates a new outbound channel to the given remote node. +// See more: https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.connect_open_channel +message OpenChannelRequest { + + // The hex-encoded public key of the node to open a channel with. + string node_pubkey = 1; + + // An address which can be used to connect to a remote peer. + // It can be of type IPv4:port, IPv6:port, OnionV3:port or hostname:port + string address = 2; + + // The amount of satoshis the caller is willing to commit to the channel. + uint64 channel_amount_sats = 3; + + // The amount of satoshis to push to the remote side as part of the initial commitment state. + optional uint64 push_to_counterparty_msat = 4; + + // The channel configuration to be used for opening this channel. If unset, default ChannelConfig is used. + optional ChannelConfig channel_config = 5; + + // Whether the channel should be public. + bool announce_channel = 6; +} + +message OpenChannelResponse { + + // The channel id of the created channel that user can use to refer to channel. + bytes user_channel_id = 1; +} + +// ChannelConfig represents the configuration settings for a channel in a Lightning Network node. +// See more: https://docs.rs/lightning/latest/lightning/util/config/struct.ChannelConfig.html +message ChannelConfig { + // Amount (in millionths of a satoshi) charged per satoshi for payments forwarded outbound + // over the channel. + // See more: https://docs.rs/lightning/latest/lightning/util/config/struct.ChannelConfig.html#structfield.forwarding_fee_proportional_millionths + uint32 forwarding_fee_proportional_millionths = 1; + + // Amount (in milli-satoshi) charged for payments forwarded outbound over the channel, + // in excess of forwarding_fee_proportional_millionths. + // See more: https://docs.rs/lightning/latest/lightning/util/config/struct.ChannelConfig.html#structfield.forwarding_fee_base_msat + uint32 forwarding_fee_base_msat = 2; + + // The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded + // over the channel this config applies to. + // See more: https://docs.rs/lightning/latest/lightning/util/config/struct.ChannelConfig.html#structfield.cltv_expiry_delta + uint32 cltv_expiry_delta = 3; + + // The maximum additional fee we’re willing to pay to avoid waiting for the counterparty’s + // to_self_delay to reclaim funds. + // See more: https://docs.rs/lightning/latest/lightning/util/config/struct.ChannelConfig.html#structfield.force_close_avoidance_max_fee_satoshis + uint64 force_close_avoidance_max_fee_satoshis = 4; + + // If set, allows this channel’s counterparty to skim an additional fee off this node’s + // inbound HTLCs. Useful for liquidity providers to offload on-chain channel costs to end users. + // See more: https://docs.rs/lightning/latest/lightning/util/config/struct.ChannelConfig.html#structfield.accept_underpaying_htlcs + bool accept_underpaying_htlcs = 5; + + // Limit our total exposure to potential loss to on-chain fees on close, including + // in-flight HTLCs which are burned to fees as they are too small to claim on-chain + // and fees on commitment transaction(s) broadcasted by our counterparty in excess of + // our own fee estimate. + // See more: https://docs.rs/lightning/latest/lightning/util/config/struct.ChannelConfig.html#structfield.max_dust_htlc_exposure + oneof max_dust_htlc_exposure { + + // This sets a fixed limit on the total dust exposure in millisatoshis. + // See more: https://docs.rs/lightning/latest/lightning/util/config/enum.MaxDustHTLCExposure.html#variant.FixedLimitMsat + uint64 fixed_limit_msat = 6; + + // This sets a multiplier on the ConfirmationTarget::OnChainSweep feerate (in sats/KW) to determine the maximum allowed dust exposure. + // See more: https://docs.rs/lightning/latest/lightning/util/config/enum.MaxDustHTLCExposure.html#variant.FeeRateMultiplier + uint64 fee_rate_multiplier = 7; + } +} + +// Closes the channel specified by given request. +// See more: +// - https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.close_channel +// - https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.force_close_channel +message CloseChannelRequest { + + // The channel id of the created channel that user can use to refer to channel. + bytes user_channel_id = 1; + + // The hex-encoded public key of the node to close a channel with. + string counterparty_node_id = 2; + + // Whether to force close the specified channel. + optional bool force_close = 3; +} + +message CloseChannelResponse { + +} + +// Returns a list of known channels. +// See more: https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.list_channels +message ListChannelsRequest {} + +message ListChannelsResponse { + + // List of channels. + repeated Channel channels = 1; +} + +message Channel { + // The channel ID (prior to funding transaction generation, this is a random 32-byte + // identifier, afterwards this is the transaction ID of the funding transaction XOR the + // funding transaction output). + // + // Note that this means this value is *not* persistent - it can change once during the + // lifetime of the channel. + string channel_id = 1; + + // The node ID of our the channel's remote counterparty. + string counterparty_node_id = 2; + + // The channel's funding transaction output, if we've negotiated the funding transaction with + // our counterparty already. + optional OutPoint funding_txo = 3; + + // The local `user_channel_id` of this channel. + bytes user_channel_id = 4; + + // The value, in satoshis, that must always be held as a reserve in the channel for us. This + // value ensures that if we broadcast a revoked state, our counterparty can punish us by + // claiming at least this value on chain. + // + // This value is not included in [`outbound_capacity_msat`] as it can never be spent. + // + // This value will be `None` for outbound channels until the counterparty accepts the channel. + optional uint64 unspendable_punishment_reserve = 5; + + // The value, in satoshis, of this channel as it appears in the funding output. + uint64 channel_value_sats = 6; + + // The currently negotiated fee rate denominated in satoshi per 1000 weight units, + // which is applied to commitment and HTLC transactions. + uint32 feerate_sat_per_1000_weight = 7; + + // The available outbound capacity for sending HTLCs to the remote peer. + // + // The amount does not include any pending HTLCs which are not yet resolved (and, thus, whose + // balance is not available for inclusion in new outbound HTLCs). This further does not include + // any pending outgoing HTLCs which are awaiting some other resolution to be sent. + uint64 outbound_capacity_msat = 8; + + // The available outbound capacity for sending HTLCs to the remote peer. + // + // The amount does not include any pending HTLCs which are not yet resolved + // (and, thus, whose balance is not available for inclusion in new inbound HTLCs). This further + // does not include any pending outgoing HTLCs which are awaiting some other resolution to be + // sent. + uint64 inbound_capacity_msat = 9; + + // The number of required confirmations on the funding transactions before the funding is + // considered "locked". The amount is selected by the channel fundee. + // + // The value will be `None` for outbound channels until the counterparty accepts the channel. + optional uint32 confirmations_required = 10; + + // The current number of confirmations on the funding transaction. + optional uint32 confirmations = 11; + + // Is `true` if the channel was initiated (and therefore funded) by us. + bool is_outbound = 12; + + // Is `true` if both parties have exchanged `channel_ready` messages, and the channel is + // not currently being shut down. Both parties exchange `channel_ready` messages upon + // independently verifying that the required confirmations count provided by + // `confirmations_required` has been reached. + bool is_channel_ready = 13; + + // Is `true` if the channel (a) `channel_ready` messages have been exchanged, (b) the + // peer is connected, and (c) the channel is not currently negotiating shutdown. + // + // This is a strict superset of `is_channel_ready`. + bool is_usable = 14; + + // Is `true` if this channel is (or will be) publicly-announced + bool is_public = 15; + + // Set of configurable parameters set by self that affect channel operation. + ChannelConfig channel_config = 16; + + // The available outbound capacity for sending a single HTLC to the remote peer. This is + // similar to `outbound_capacity_msat` but it may be further restricted by + // the current state and per-HTLC limit(s). This is intended for use when routing, allowing us + // to use a limit as close as possible to the HTLC limit we can currently send. + uint64 next_outbound_htlc_limit_msat = 17; + + // The minimum value for sending a single HTLC to the remote peer. This is the equivalent of + // `next_outbound_htlc_limit_msat` but represents a lower-bound, rather than + // an upper-bound. This is intended for use when routing, allowing us to ensure we pick a + // route which is valid. + uint64 next_outbound_htlc_minimum_msat = 18; + + // The number of blocks (after our commitment transaction confirms) that we will need to wait + // until we can claim our funds after we force-close the channel. During this time our + // counterparty is allowed to punish us if we broadcasted a stale state. If our counterparty + // force-closes the channel and broadcasts a commitment transaction we do not have to wait any + // time to claim our non-HTLC-encumbered funds. + // + // This value will be `None` for outbound channels until the counterparty accepts the channel. + optional uint32 force_close_spend_delay = 19; + + // The smallest value HTLC (in msat) the remote peer will accept, for this channel. + // + // This field is only `None` before we have received either the `OpenChannel` or + // `AcceptChannel` message from the remote peer. + optional uint64 counterparty_outbound_htlc_minimum_msat = 20; + + // The largest value HTLC (in msat) the remote peer currently will accept, for this channel. + optional uint64 counterparty_outbound_htlc_maximum_msat = 21; + + // The value, in satoshis, that must always be held in the channel for our counterparty. This + // value ensures that if our counterparty broadcasts a revoked state, we can punish them by + // claiming at least this value on chain. + // + // This value is not included in `inbound_capacity_msat` as it can never be spent. + optional uint64 counterparty_unspendable_punishment_reserve = 22; + + // Base routing fee in millisatoshis. + optional uint32 counterparty_forwarding_info_fee_base_msat = 23; + + // Proportional fee, in millionths of a satoshi the channel will charge per transferred satoshi. + optional uint32 counterparty_forwarding_info_fee_proportional_millionths = 24; + + // The minimum difference in CLTV expiry between an ingoing HTLC and its outgoing counterpart, + // such that the outgoing HTLC is forwardable to this counterparty. + optional uint32 counterparty_forwarding_info_cltv_expiry_delta = 25; +} + +// Represent a transaction outpoint. +message OutPoint { + // The referenced transaction's txid. + string txid = 1; + + // The index of the referenced output in its transaction's vout. + uint32 vout = 2; +} \ No newline at end of file diff --git a/server/Cargo.toml b/server/Cargo.toml index 2a9d7e9..82fd980 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -12,3 +12,4 @@ http-body-util = { version = "0.1", default-features = false } hyper-util = { version = "0.1", default-features = false, features = ["server-graceful"] } tokio = { version = "1.38.0", default-features = false, features = ["time", "signal", "rt-multi-thread"] } prost = { version = "0.11.6", default-features = false, features = ["std"] } +protos = { path = "../protos" }