1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
//! # lnd_rest
//!
//! Rust wrapper to interact with the REST API of a Lightning Network Daemon node.
//!
//! ## Usage
//!
//! Add package to your `Cargo.toml` manifest:
//!
//! ```sh
//! cargo add lnd_rest
//! ```
//!
//! ### Add a new invoice
//!
//! ```rust
//! use lnd_rest::node::Node;
//! use lnd_rest::types::AddInvoiceRequest;
//!
//! #[tokio::main]
//! async fn main() {
//! let host = "your_lnd_host".to_string();
//! let macaroon_path = "path/to/macaroon".to_string();
//! let cert_path = "path/to/cert".to_string();
//!
//! let node = Node::init(host, macaroon_path, cert_path).await.unwrap();
//!
//! let add_invoice_request = AddInvoiceRequest {
//! value_msat: 1000, // Set the invoice value in millisatoshis
//! expiry: 3600, // Set the expiry time in seconds
//! // Set other fields as needed
//! ..Default::default()
//! };
//!
//! let add_invoice_response = node.add_invoice(&add_invoice_request).await;
//!
//! match add_invoice_response {
//! Ok(response) => {
//! println!("Payment hash: {}", response.r_hash);
//! // Access other fields as needed
//! }
//! Err(err) => {
//! eprintln!("Error adding invoice: {}", err);
//! }
//! }
//! }
//! ```
//!
//! ### Lookup an invoice
//!
//! ```rust
//! use lnd_rest::node::Node;
//!
//! #[tokio::main]
//! async fn main() {
//! let host = "your_lnd_host".to_string();
//! let macaroon_path = "path/to/macaroon".to_string();
//! let cert_path = "path/to/cert".to_string();
//!
//! let node = Node::init(host, macaroon_path, cert_path).await.unwrap();
//!
//! let payment_hash = "your_payment_hash".to_string();
//!
//! let lookup_invoice_response = node.lookup_invoice(&payment_hash).await;
//!
//! match lookup_invoice_response {
//! Ok(response) => {
//! println!("Invoice state: {:?}", response.state);
//! // Access other fields as needed
//! }
//! Err(err) => {
//! eprintln!("Error looking up invoice: {}", err);
//! }
//! }
//! }
//! ```
//!
//! ### Pay an invoice
//!
//! ```rust
//! use lnd_rest::node::Node;
//! use lnd_rest::types::SendPaymentSyncRequest;
//!
//! #[tokio::main]
//! async fn main() {
//! let host = "your_lnd_host".to_string();
//! let macaroon_path = "path/to/macaroon".to_string();
//! let cert_path = "path/to/cert".to_string();
//!
//! let node = Node::init(host, macaroon_path, cert_path).await.unwrap();
//!
//! let send_payment_request = SendPaymentSyncRequest {
//! payment_request: "your_payment_request".to_string(),
//! // Set other fields as needed
//! ..Default::default()
//! };
//!
//! let send_payment_response = node.pay_invoice(&send_payment_request).await;
//!
//! match send_payment_response {
//! Ok(response) => {
//! println!("Payment preimage: {}", response.payment_preimage);
//! // Access other fields as needed
//! }
//! Err(err) => {
//! eprintln!("Error paying invoice: {}", err);
//! }
//! }
//! }
//! ```
//!
//! ### List payments
//!
//! ```rust
//! use lnd_rest::node::Node;
//! use lnd_rest::types::ListPaymentsRequest;
//!
//! #[tokio::main]
//! async fn main() {
//! let host = "your_lnd_host".to_string();
//! let macaroon_path = "path/to/macaroon".to_string();
//! let cert_path = "path/to/cert".to_string();
//!
//! let node = Node::init(host, macaroon_path, cert_path).await.unwrap();
//!
//! let list_payments_request = ListPaymentsRequest {
//! include_incomplete: true, // Include incomplete payments
//! // Set other fields as needed
//! ..Default::default()
//! };
//!
//! let list_payments_response = node.list_payments(&list_payments_request).await;
//!
//! match list_payments_response {
//! Ok(response) => {
//! for payment in response.payments {
//! println!("Payment hash: {}", payment.payment_hash);
//! // Access other fields as needed
//! }
//! }
//! Err(err) => {
//! eprintln!("Error listing payments: {}", err);
//! }
//! }
//! }
//! ```