Skip to content

Commit 82162e2

Browse files
authored
Merge pull request #20 from G8XSU/error-model-2
Simpler Error Model for ldk-server
2 parents 9ce78ae + 3c3c133 commit 82162e2

26 files changed

+1302
-1143
lines changed

cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use clap::{Parser, Subcommand};
22
use client::client::LdkNodeServerClient;
33
use client::error::LdkNodeServerError;
4-
use client::protos::{
4+
use client::protos::api::{
55
Bolt11ReceiveRequest, Bolt11SendRequest, Bolt12ReceiveRequest, Bolt12SendRequest,
66
OnchainReceiveRequest, OnchainSendRequest, OpenChannelRequest,
77
};

client/src/client.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use prost::Message;
22

33
use crate::error::LdkNodeServerError;
4-
use protos::{
4+
use protos::api::{
55
Bolt11ReceiveRequest, Bolt11ReceiveResponse, Bolt11SendRequest, Bolt11SendResponse,
66
Bolt12ReceiveRequest, Bolt12ReceiveResponse, Bolt12SendRequest, Bolt12SendResponse,
77
CloseChannelRequest, CloseChannelResponse, ListChannelsRequest, ListChannelsResponse,

protos/build.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,16 @@ fn main() {
1414
fn generate_protos() {
1515
prost_build::Config::new()
1616
.bytes(&["."])
17-
.compile_protos(&["src/proto/ldk_node_server.proto"], &["src/"])
17+
.compile_protos(
18+
&["src/proto/api.proto", "src/proto/types.proto", "src/proto/error.proto"],
19+
&["src/proto/"],
20+
)
1821
.expect("protobuf compilation failed");
1922
println!("OUT_DIR: {}", &env::var("OUT_DIR").unwrap());
20-
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("ldk_node_server.rs");
21-
fs::copy(from_path, "src/lib.rs").unwrap();
23+
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("api.rs");
24+
fs::copy(from_path, "src/api.rs").unwrap();
25+
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("types.rs");
26+
fs::copy(from_path, "src/types.rs").unwrap();
27+
let from_path = Path::new(&env::var("OUT_DIR").unwrap()).join("error.rs");
28+
fs::copy(from_path, "src/error.rs").unwrap();
2229
}

protos/src/api.rs

Lines changed: 313 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,313 @@
1+
/// Retrieve the latest node info like `node_id`, `current_best_block` etc.
2+
/// See more:
3+
/// - <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.node_id>
4+
/// - <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.status>
5+
#[allow(clippy::derive_partial_eq_without_eq)]
6+
#[derive(Clone, PartialEq, ::prost::Message)]
7+
pub struct GetNodeInfoRequest {}
8+
#[allow(clippy::derive_partial_eq_without_eq)]
9+
#[derive(Clone, PartialEq, ::prost::Message)]
10+
pub struct GetNodeInfoResponse {
11+
/// The hex-encoded `node-id` or public key for our own lightning node.
12+
#[prost(string, tag = "1")]
13+
pub node_id: ::prost::alloc::string::String,
14+
/// The best block to which our Lightning wallet is currently synced.
15+
///
16+
/// Should be always set, will never be `None`.
17+
#[prost(message, optional, tag = "3")]
18+
pub current_best_block: ::core::option::Option<super::types::BestBlock>,
19+
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
20+
/// the chain tip.
21+
///
22+
/// Will be `None` if the wallet hasn't been synced yet.
23+
#[prost(uint64, optional, tag = "4")]
24+
pub latest_lightning_wallet_sync_timestamp: ::core::option::Option<u64>,
25+
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
26+
/// wallet to the chain tip.
27+
///
28+
/// Will be `None` if the wallet hasn’t been synced since the node was initialized.
29+
#[prost(uint64, optional, tag = "5")]
30+
pub latest_onchain_wallet_sync_timestamp: ::core::option::Option<u64>,
31+
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully update our fee rate cache.
32+
///
33+
/// Will be `None` if the cache hasn’t been updated since the node was initialized.
34+
#[prost(uint64, optional, tag = "6")]
35+
pub latest_fee_rate_cache_update_timestamp: ::core::option::Option<u64>,
36+
/// The timestamp, in seconds since start of the UNIX epoch, when the last rapid gossip sync (RGS) snapshot we
37+
/// successfully applied was generated.
38+
///
39+
/// Will be `None` if RGS isn’t configured or the snapshot hasn’t been updated since the node was initialized.
40+
#[prost(uint64, optional, tag = "7")]
41+
pub latest_rgs_snapshot_timestamp: ::core::option::Option<u64>,
42+
/// The timestamp, in seconds since start of the UNIX epoch, when we last broadcasted a node announcement.
43+
///
44+
/// Will be `None` if we have no public channels or we haven’t broadcasted since the node was initialized.
45+
#[prost(uint64, optional, tag = "8")]
46+
pub latest_node_announcement_broadcast_timestamp: ::core::option::Option<u64>,
47+
}
48+
/// Retrieve a new on-chain funding address.
49+
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/payment/struct.OnchainPayment.html#method.new_address>
50+
#[allow(clippy::derive_partial_eq_without_eq)]
51+
#[derive(Clone, PartialEq, ::prost::Message)]
52+
pub struct OnchainReceiveRequest {}
53+
#[allow(clippy::derive_partial_eq_without_eq)]
54+
#[derive(Clone, PartialEq, ::prost::Message)]
55+
pub struct OnchainReceiveResponse {
56+
/// A Bitcoin on-chain address.
57+
#[prost(string, tag = "1")]
58+
pub address: ::prost::alloc::string::String,
59+
}
60+
/// Send an on-chain payment to the given address.
61+
#[allow(clippy::derive_partial_eq_without_eq)]
62+
#[derive(Clone, PartialEq, ::prost::Message)]
63+
pub struct OnchainSendRequest {
64+
/// The address to send coins to.
65+
#[prost(string, tag = "1")]
66+
pub address: ::prost::alloc::string::String,
67+
/// The amount in satoshis to send.
68+
/// While sending the specified amount, we will respect any on-chain reserve we need to keep,
69+
/// i.e., won't allow to cut into `total_anchor_channels_reserve_sats`.
70+
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/payment/struct.OnchainPayment.html#method.send_to_address>
71+
#[prost(uint64, optional, tag = "2")]
72+
pub amount_sats: ::core::option::Option<u64>,
73+
/// If set, the amount_sats field should be unset.
74+
/// It indicates that node will send full balance to the specified address.
75+
///
76+
/// Please note that when send_all is used this operation will **not** retain any on-chain reserves,
77+
/// which might be potentially dangerous if you have open Anchor channels for which you can't trust
78+
/// the counterparty to spend the Anchor output after channel closure.
79+
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/payment/struct.OnchainPayment.html#method.send_all_to_address>
80+
#[prost(bool, optional, tag = "3")]
81+
pub send_all: ::core::option::Option<bool>,
82+
}
83+
#[allow(clippy::derive_partial_eq_without_eq)]
84+
#[derive(Clone, PartialEq, ::prost::Message)]
85+
pub struct OnchainSendResponse {
86+
/// The transaction ID of the broadcasted transaction.
87+
#[prost(string, tag = "1")]
88+
pub txid: ::prost::alloc::string::String,
89+
}
90+
/// Return a BOLT11 payable invoice that can be used to request and receive a payment
91+
/// for the given amount, if specified.
92+
/// The inbound payment will be automatically claimed upon arrival.
93+
/// See more:
94+
/// - <https://docs.rs/ldk-node/latest/ldk_node/payment/struct.Bolt11Payment.html#method.receive>
95+
/// - <https://docs.rs/ldk-node/latest/ldk_node/payment/struct.Bolt11Payment.html#method.receive_variable_amount>
96+
#[allow(clippy::derive_partial_eq_without_eq)]
97+
#[derive(Clone, PartialEq, ::prost::Message)]
98+
pub struct Bolt11ReceiveRequest {
99+
/// The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount invoice is returned.
100+
#[prost(uint64, optional, tag = "1")]
101+
pub amount_msat: ::core::option::Option<u64>,
102+
/// An optional description to attach along with the invoice.
103+
/// Will be set in the description field of the encoded payment request.
104+
#[prost(string, tag = "2")]
105+
pub description: ::prost::alloc::string::String,
106+
/// Invoice expiry time in seconds.
107+
#[prost(uint32, tag = "3")]
108+
pub expiry_secs: u32,
109+
}
110+
#[allow(clippy::derive_partial_eq_without_eq)]
111+
#[derive(Clone, PartialEq, ::prost::Message)]
112+
pub struct Bolt11ReceiveResponse {
113+
/// An invoice for a payment within the Lightning Network.
114+
/// With the details of the invoice, the sender has all the data necessary to send a payment
115+
/// to the recipient.
116+
#[prost(string, tag = "1")]
117+
pub invoice: ::prost::alloc::string::String,
118+
}
119+
/// Send a payment for a BOLT11 invoice.
120+
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/payment/struct.Bolt11Payment.html#method.send>
121+
#[allow(clippy::derive_partial_eq_without_eq)]
122+
#[derive(Clone, PartialEq, ::prost::Message)]
123+
pub struct Bolt11SendRequest {
124+
/// An invoice for a payment within the Lightning Network.
125+
#[prost(string, tag = "1")]
126+
pub invoice: ::prost::alloc::string::String,
127+
/// Set this field when paying a so-called "zero-amount" invoice, i.e., an invoice that leaves the
128+
/// amount paid to be determined by the user.
129+
/// This operation will fail if the amount specified is less than the value required by the given invoice.
130+
#[prost(uint64, optional, tag = "2")]
131+
pub amount_msat: ::core::option::Option<u64>,
132+
}
133+
#[allow(clippy::derive_partial_eq_without_eq)]
134+
#[derive(Clone, PartialEq, ::prost::Message)]
135+
pub struct Bolt11SendResponse {
136+
/// An identifier used to uniquely identify a payment.
137+
#[prost(bytes = "bytes", tag = "1")]
138+
pub payment_id: ::prost::bytes::Bytes,
139+
}
140+
/// Returns a BOLT12 offer for the given amount, if specified.
141+
///
142+
/// See more:
143+
/// - <https://docs.rs/ldk-node/latest/ldk_node/payment/struct.Bolt12Payment.html#method.receive>
144+
/// - <https://docs.rs/ldk-node/latest/ldk_node/payment/struct.Bolt12Payment.html#method.receive_variable_amount>
145+
#[allow(clippy::derive_partial_eq_without_eq)]
146+
#[derive(Clone, PartialEq, ::prost::Message)]
147+
pub struct Bolt12ReceiveRequest {
148+
/// An optional description to attach along with the offer.
149+
/// Will be set in the description field of the encoded offer.
150+
#[prost(string, tag = "1")]
151+
pub description: ::prost::alloc::string::String,
152+
/// The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount offer is returned.
153+
#[prost(uint64, optional, tag = "2")]
154+
pub amount_msat: ::core::option::Option<u64>,
155+
/// Offer expiry time in seconds.
156+
#[prost(uint32, optional, tag = "3")]
157+
pub expiry_secs: ::core::option::Option<u32>,
158+
/// If set, it represents the number of items requested, can only be set for fixed-amount offers.
159+
#[prost(uint64, optional, tag = "4")]
160+
pub quantity: ::core::option::Option<u64>,
161+
}
162+
#[allow(clippy::derive_partial_eq_without_eq)]
163+
#[derive(Clone, PartialEq, ::prost::Message)]
164+
pub struct Bolt12ReceiveResponse {
165+
/// An offer for a payment within the Lightning Network.
166+
/// With the details of the offer, the sender has all the data necessary to send a payment
167+
/// to the recipient.
168+
#[prost(string, tag = "1")]
169+
pub offer: ::prost::alloc::string::String,
170+
}
171+
/// Send a payment for a BOLT12 offer.
172+
/// See more:
173+
/// - <https://docs.rs/ldk-node/latest/ldk_node/payment/struct.Bolt12Payment.html#method.send>
174+
/// - <https://docs.rs/ldk-node/latest/ldk_node/payment/struct.Bolt12Payment.html#method.send_using_amount>
175+
#[allow(clippy::derive_partial_eq_without_eq)]
176+
#[derive(Clone, PartialEq, ::prost::Message)]
177+
pub struct Bolt12SendRequest {
178+
/// An offer for a payment within the Lightning Network.
179+
#[prost(string, tag = "1")]
180+
pub offer: ::prost::alloc::string::String,
181+
/// Set this field when paying a so-called "zero-amount" offer, i.e., an offer that leaves the
182+
/// amount paid to be determined by the user.
183+
/// This operation will fail if the amount specified is less than the value required by the given offer.
184+
#[prost(uint64, optional, tag = "2")]
185+
pub amount_msat: ::core::option::Option<u64>,
186+
/// If set, it represents the number of items requested.
187+
#[prost(uint64, optional, tag = "3")]
188+
pub quantity: ::core::option::Option<u64>,
189+
/// If set, it will be seen by the recipient and reflected back in the invoice.
190+
#[prost(string, optional, tag = "4")]
191+
pub payer_note: ::core::option::Option<::prost::alloc::string::String>,
192+
}
193+
#[allow(clippy::derive_partial_eq_without_eq)]
194+
#[derive(Clone, PartialEq, ::prost::Message)]
195+
pub struct Bolt12SendResponse {
196+
/// An identifier used to uniquely identify a payment.
197+
#[prost(bytes = "bytes", tag = "1")]
198+
pub payment_id: ::prost::bytes::Bytes,
199+
}
200+
/// Creates a new outbound channel to the given remote node.
201+
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.connect_open_channel>
202+
#[allow(clippy::derive_partial_eq_without_eq)]
203+
#[derive(Clone, PartialEq, ::prost::Message)]
204+
pub struct OpenChannelRequest {
205+
/// The hex-encoded public key of the node to open a channel with.
206+
#[prost(string, tag = "1")]
207+
pub node_pubkey: ::prost::alloc::string::String,
208+
/// An address which can be used to connect to a remote peer.
209+
/// It can be of type IPv4:port, IPv6:port, OnionV3:port or hostname:port
210+
#[prost(string, tag = "2")]
211+
pub address: ::prost::alloc::string::String,
212+
/// The amount of satoshis the caller is willing to commit to the channel.
213+
#[prost(uint64, tag = "3")]
214+
pub channel_amount_sats: u64,
215+
/// The amount of satoshis to push to the remote side as part of the initial commitment state.
216+
#[prost(uint64, optional, tag = "4")]
217+
pub push_to_counterparty_msat: ::core::option::Option<u64>,
218+
/// The channel configuration to be used for opening this channel. If unset, default ChannelConfig is used.
219+
#[prost(message, optional, tag = "5")]
220+
pub channel_config: ::core::option::Option<super::types::ChannelConfig>,
221+
/// Whether the channel should be public.
222+
#[prost(bool, tag = "6")]
223+
pub announce_channel: bool,
224+
}
225+
#[allow(clippy::derive_partial_eq_without_eq)]
226+
#[derive(Clone, PartialEq, ::prost::Message)]
227+
pub struct OpenChannelResponse {
228+
/// The channel id of the created channel that user can use to refer to channel.
229+
#[prost(bytes = "bytes", tag = "1")]
230+
pub user_channel_id: ::prost::bytes::Bytes,
231+
}
232+
/// Update the config for a previously opened channel.
233+
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.update_channel_config>
234+
#[allow(clippy::derive_partial_eq_without_eq)]
235+
#[derive(Clone, PartialEq, ::prost::Message)]
236+
pub struct UpdateChannelConfigRequest {
237+
/// The hex-encoded local `user_channel_id` of this channel.
238+
#[prost(string, tag = "1")]
239+
pub user_channel_id: ::prost::alloc::string::String,
240+
/// The hex-encoded public key of the counterparty node to update channel config with.
241+
#[prost(string, tag = "2")]
242+
pub counterparty_node_id: ::prost::alloc::string::String,
243+
/// The updated channel configuration settings for a channel.
244+
#[prost(message, optional, tag = "3")]
245+
pub channel_config: ::core::option::Option<super::types::ChannelConfig>,
246+
}
247+
#[allow(clippy::derive_partial_eq_without_eq)]
248+
#[derive(Clone, PartialEq, ::prost::Message)]
249+
pub struct UpdateChannelConfigResponse {}
250+
/// Closes the channel specified by given request.
251+
/// See more:
252+
/// - <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.close_channel>
253+
/// - <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.force_close_channel>
254+
#[allow(clippy::derive_partial_eq_without_eq)]
255+
#[derive(Clone, PartialEq, ::prost::Message)]
256+
pub struct CloseChannelRequest {
257+
/// The channel id of the created channel that user can use to refer to channel.
258+
#[prost(bytes = "bytes", tag = "1")]
259+
pub user_channel_id: ::prost::bytes::Bytes,
260+
/// The hex-encoded public key of the node to close a channel with.
261+
#[prost(string, tag = "2")]
262+
pub counterparty_node_id: ::prost::alloc::string::String,
263+
/// Whether to force close the specified channel.
264+
#[prost(bool, optional, tag = "3")]
265+
pub force_close: ::core::option::Option<bool>,
266+
/// The reason for force-closing, can only be set while force closing a channel.
267+
#[prost(string, optional, tag = "4")]
268+
pub force_close_reason: ::core::option::Option<::prost::alloc::string::String>,
269+
}
270+
#[allow(clippy::derive_partial_eq_without_eq)]
271+
#[derive(Clone, PartialEq, ::prost::Message)]
272+
pub struct CloseChannelResponse {}
273+
/// Returns a list of known channels.
274+
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.list_channels>
275+
#[allow(clippy::derive_partial_eq_without_eq)]
276+
#[derive(Clone, PartialEq, ::prost::Message)]
277+
pub struct ListChannelsRequest {}
278+
#[allow(clippy::derive_partial_eq_without_eq)]
279+
#[derive(Clone, PartialEq, ::prost::Message)]
280+
pub struct ListChannelsResponse {
281+
/// List of channels.
282+
#[prost(message, repeated, tag = "1")]
283+
pub channels: ::prost::alloc::vec::Vec<super::types::Channel>,
284+
}
285+
/// Returns payment details for a given payment_id.
286+
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.payment>
287+
#[allow(clippy::derive_partial_eq_without_eq)]
288+
#[derive(Clone, PartialEq, ::prost::Message)]
289+
pub struct GetPaymentDetailsRequest {
290+
/// An identifier used to uniquely identify a payment in hex-encoded form.
291+
#[prost(string, tag = "1")]
292+
pub payment_id: ::prost::alloc::string::String,
293+
}
294+
#[allow(clippy::derive_partial_eq_without_eq)]
295+
#[derive(Clone, PartialEq, ::prost::Message)]
296+
pub struct GetPaymentDetailsResponse {
297+
/// Represents a payment.
298+
/// Will be `None` if payment doesn't exist.
299+
#[prost(message, optional, tag = "1")]
300+
pub payment: ::core::option::Option<super::types::Payment>,
301+
}
302+
/// Retrieves list of all payments.
303+
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/struct.Node.html#method.list_payments>
304+
#[allow(clippy::derive_partial_eq_without_eq)]
305+
#[derive(Clone, PartialEq, ::prost::Message)]
306+
pub struct ListPaymentsRequest {}
307+
#[allow(clippy::derive_partial_eq_without_eq)]
308+
#[derive(Clone, PartialEq, ::prost::Message)]
309+
pub struct ListPaymentsResponse {
310+
/// List of payments.
311+
#[prost(message, repeated, tag = "1")]
312+
pub payments: ::prost::alloc::vec::Vec<super::types::Payment>,
313+
}

0 commit comments

Comments
 (0)