Skip to content

Commit

Permalink
upgraded ldk to 0.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
toneloc committed Oct 19, 2024
1 parent bc45660 commit 2e71671
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ user = []
lsp = []

[dependencies]
ldk-node = "0.3.0"
lightning-liquidity = "=0.1.0-alpha.4"
lightning = "=0.0.123"
ldk-node = "0.4.0"
lightning-liquidity = "=0.1.0-alpha.6"
lightning = { version = "0.0.125", features = ["std"] }
reqwest = { version = "0.11", features = ["blocking", "json"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
Expand Down
38 changes: 17 additions & 21 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,21 @@ mod price_feeds;
use std::{
io::{self, Write},
str::FromStr,
sync::Arc,
time::{Duration, SystemTime, UNIX_EPOCH},
};

use ldk_node::{
bitcoin::{secp256k1::PublicKey, Network},
config::ChannelConfig,
lightning::{
ln::{msgs::SocketAddress, ChannelId},
ln::msgs::SocketAddress,
offers::offer::Offer,
},
lightning_invoice::Bolt11Invoice,
Builder, ChannelConfig, ChannelDetails, Node,
Builder, ChannelDetails, Node,
};

use lightning::ln::types::ChannelId;
use price_feeds::{calculate_median_price, fetch_prices, set_price_feeds};
use reqwest::blocking::Client;
use types::{Bitcoin, StableChannel, USD};
Expand All @@ -49,7 +50,7 @@ fn make_node(alias: &str, port: u16, lsp_pubkey:Option<PublicKey>) -> ldk_node::
builder.set_network(Network::Signet);

// If this doesn't work, try the other one
builder.set_esplora_server("https://mutinynet.com/api/".to_string());
builder.set_chain_source_esplora("https://mutinynet.com/api/".to_string(), None);
// builder.set_esplora_server("https://mutinynet.ltbl.io/api".to_string());

// Don't need gossip right now. Also interferes with Bolt12 implementation.
Expand Down Expand Up @@ -144,7 +145,7 @@ fn check_stability(node: &Node, mut sc: StableChannel) -> StableChannel {

let amt = USD::to_msats(dollars_from_par, sc.latest_price);

let result = node.bolt12_payment().send_using_amount(&sc.counterparty_offer,Some("here ya go".to_string()),amt);
let result = node.bolt12_payment().send_using_amount(&sc.counterparty_offer,amt, None,Some("here ya go".to_string()));

// This is keysend / spontaenous payment code you can use if Bolt12 doesn't work

Expand Down Expand Up @@ -243,10 +244,9 @@ fn main() {
let lsp_net_address: SocketAddress = listening_address_str.parse().unwrap();
let sats: u64 = sats_str.parse().unwrap();

let channel_config: Option<Arc<ChannelConfig>> = None;
let announce_channel = true;
let channel_config: Option<ChannelConfig> = None;

match exchange.connect_open_channel(lsp_node_id, lsp_net_address, sats, Some(sats/2), channel_config, announce_channel) {
match exchange.open_announced_channel(lsp_node_id, lsp_net_address, sats, Some(sats/2), channel_config) {
Ok(_) => println!("Channel successfully opened to {}", node_id_str),
Err(e) => println!("Failed to open channel: {}", e),
}
Expand Down Expand Up @@ -300,7 +300,7 @@ fn main() {
let bolt11_invoice = invoice_str.parse::<Bolt11Invoice>();
match bolt11_invoice {
Ok(invoice) => {
match exchange.bolt11_payment().send(&invoice) {
match exchange.bolt11_payment().send(&invoice,None) {
Ok(payment_id) => println!("Payment sent from Exchange with payment_id: {}", payment_id),
Err(e) => println!("Error sending payment from Exchange: {}", e)
}
Expand All @@ -327,7 +327,7 @@ fn main() {
println!("Offer set.")
}
(Some("getouroffer"),[]) => {
let our_offer: Offer = user.bolt12_payment().receive_variable_amount("thanks").unwrap();
let our_offer: Offer = user.bolt12_payment().receive_variable_amount("thanks", None).unwrap();
println!("{}", our_offer);
},
// Sample start command below:
Expand Down Expand Up @@ -427,11 +427,9 @@ fn main() {
let sats: u64 = sats_str.parse().unwrap();
let push_msat = (sats / 2) * 1000;

let channel_config: Option<Arc<ChannelConfig>> = None;
let channel_config: Option<ChannelConfig> = None;

let announce_channel = true;

match user.connect_open_channel(lsp_node_id, lsp_net_address, sats, Some(push_msat), channel_config, announce_channel) {
match user.open_announced_channel(lsp_node_id, lsp_net_address, sats, Some(push_msat), channel_config) {
Ok(_) => println!("Channel successfully opened to {}", node_id_str),
Err(e) => println!("Failed to open channel: {}", e),
}
Expand Down Expand Up @@ -489,7 +487,7 @@ fn main() {
let bolt11_invoice = invoice_str.parse::<Bolt11Invoice>();
match bolt11_invoice {
Ok(invoice) => {
match user.bolt11_payment().send(&invoice) {
match user.bolt11_payment().send(&invoice, None) {
Ok(payment_id) => println!("Payment sent from User with payment_id: {}", payment_id),
Err(e) => println!("Error sending payment from User: {}", e)
}
Expand Down Expand Up @@ -528,7 +526,7 @@ fn main() {

},
(Some("getouroffer"),[]) => {
let our_offer: Offer = lsp.bolt12_payment().receive_variable_amount("thanks").unwrap();
let our_offer: Offer = lsp.bolt12_payment().receive_variable_amount("thanks", None).unwrap();
println!("{}", our_offer);
},
(Some("getaddress"), []) => {
Expand All @@ -552,11 +550,9 @@ fn main() {
let lsp_net_address: SocketAddress = listening_address_str.parse().unwrap();
let sats: u64 = sats_str.parse().unwrap();

let channel_config: Option<Arc<ChannelConfig>> = None;
let channel_config: Option<ChannelConfig> = None;

let announce_channel = true;

match lsp.connect_open_channel(user_node_id, lsp_net_address, sats, Some(sats/2), channel_config, announce_channel) {
match lsp.open_announced_channel(user_node_id, lsp_net_address, sats, Some(sats/2), channel_config) {
Ok(_) => println!("Channel successfully opened to {}", node_id_str),
Err(e) => println!("Failed to open channel: {}", e),
}
Expand Down Expand Up @@ -663,7 +659,7 @@ fn main() {
let bolt11_invoice = invoice_str.parse::<Bolt11Invoice>();
match bolt11_invoice {
Ok(invoice) => {
match lsp.bolt11_payment().send(&invoice) {
match lsp.bolt11_payment().send(&invoice, None) {
Ok(payment_id) => println!("Payment sent from LSP with payment_id: {}", payment_id),
Err(e) => println!("Error sending payment from LSP: {}", e)
}
Expand Down
2 changes: 1 addition & 1 deletion src/types.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::lightning::ln::ChannelId;
use lightning::ln::types::ChannelId;
use ldk_node::lightning::offers::offer::Offer;
use std::ops::{Div, Sub};

Expand Down

0 comments on commit 2e71671

Please sign in to comment.