Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
312 changes: 228 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions cli/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,6 +46,10 @@ enum Commands {
description: String,
#[arg(long)]
amount_msat: Option<u64>,
#[arg(long)]
expiry_secs: Option<u32>,
#[arg(long)]
quantity: Option<u64>,
},
Bolt12Send {
#[arg(short, long)]
Expand DownExpand Up@@ -95,9 +99,16 @@ async fn main() {
Commands::Bolt11Send { invoice, amount_msat } => {
handle_response(client.bolt11_send(Bolt11SendRequest { invoice, amount_msat }).await);
},
Commands::Bolt12Receive { description, amount_msat } => {
Commands::Bolt12Receive { description, amount_msat, expiry_secs, quantity } => {
handle_response(
client.bolt12_receive(Bolt12ReceiveRequest { description, amount_msat }).await,
client
.bolt12_receive(Bolt12ReceiveRequest {
description,
amount_msat,
expiry_secs,
quantity,
})
.await,
);
},
Commands::Bolt12Send { offer, amount_msat, quantity, payer_note } => {
Expand Down
19 changes: 14 additions & 5 deletions protos/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,12 +16,12 @@ pub struct GetNodeInfoResponse {
/// Should be always set, will never be `None`.
#[prost(message, optional, tag = "3")]
pub current_best_block: ::core::option::Option<BestBlock>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
/// to the chain tip.
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
/// the chain tip.
///
/// Will be `None` if the wallet hasnt been synced since the node was initialized.
/// Will be `None` if the wallet hasn't been synced yet.
#[prost(uint64, optional, tag = "4")]
pub latest_wallet_sync_timestamp: ::core::option::Option<u64>,
pub latest_lightning_wallet_sync_timestamp: ::core::option::Option<u64>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
/// wallet to the chain tip.
///
Expand DownExpand Up@@ -152,6 +152,12 @@ pub struct Bolt12ReceiveRequest {
/// 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<u64>,
/// Offer expiry time in seconds.
#[prost(uint32, optional, tag = "3")]
pub expiry_secs: ::core::option::Option<u32>,
/// If set, it represents the number of items requested, can only be set for fixed-amount offers.
#[prost(uint64, optional, tag = "4")]
pub quantity: ::core::option::Option<u64>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -297,6 +303,9 @@ pub struct CloseChannelRequest {
/// Whether to force close the specified channel.
#[prost(bool, optional, tag = "3")]
pub force_close: ::core::option::Option<bool>,
/// The reason for force-closing, can only be set while force closing a channel.
#[prost(string, optional, tag = "4")]
pub force_close_reason: ::core::option::Option<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -391,7 +400,7 @@ pub struct Channel {
pub is_usable: bool,
/// Is `true` if this channel is (or will be) publicly-announced
#[prost(bool, tag = "15")]
pub is_public: bool,
pub is_announced: bool,
/// Set of configurable parameters set by self that affect channel operation.
#[prost(message, optional, tag = "16")]
pub channel_config: ::core::option::Option<ChannelConfig>,
Expand Down
21 changes: 14 additions & 7 deletions protos/src/proto/ldk_node_server.proto
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,11 +18,11 @@ message GetNodeInfoResponse {
// Should be always set, will never be `None`.
BestBlock current_best_block = 3;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
// to the chain tip.
// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
// the chain tip.
//
// Will be `None` if the wallet hasnt been synced since the node was initialized.
optional uint64 latest_wallet_sync_timestamp = 4;
// Will be `None` if the wallet hasn't been synced yet.
optional uint64 latest_lightning_wallet_sync_timestamp = 4;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
// wallet to the chain tip.
Expand DownExpand Up@@ -147,6 +147,12 @@ message Bolt12ReceiveRequest {

// The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount offer is returned.
optional uint64 amount_msat = 2;

// Offer expiry time in seconds.
optional uint32 expiry_secs = 3;

// If set, it represents the number of items requested, can only be set for fixed-amount offers.
optional uint64 quantity = 4;
}

message Bolt12ReceiveResponse {
Expand DownExpand Up@@ -273,6 +279,9 @@ message CloseChannelRequest {

// Whether to force close the specified channel.
optional bool force_close = 3;

// The reason for force-closing, can only be set while force closing a channel.
optional string force_close_reason = 4;
}

message CloseChannelResponse {
Expand DownExpand Up@@ -364,7 +373,7 @@ message Channel {
bool is_usable = 14;

// Is `true` if this channel is (or will be) publicly-announced
bool is_public = 15;
bool is_announced = 15;

// Set of configurable parameters set by self that affect channel operation.
ChannelConfig channel_config = 16;
Expand DownExpand Up@@ -427,11 +436,9 @@ message OutPoint {
}

message BestBlock {

// The block’s hash
string block_hash = 1;

// The height at which the block was confirmed.
uint32 height = 2;

}
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node.git", branch = "main" }
ldk-node = { version = "0.4.0", default-features = false }
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.118", default-features = false }
hyper = { version = "1", default-features = false, features = ["server", "http1"] }
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/bolt11_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,8 +14,8 @@ pub(crate) fn handle_bolt11_send_request(
.map_err(|_| ldk_node::NodeError::InvalidInvoice)?;

let payment_id = match request.amount_msat {
None => node.bolt11_payment().send(&invoice),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat),
None => node.bolt11_payment().send(&invoice, None),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat, None),
}?;

let response = Bolt11SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
11 changes: 9 additions & 2 deletions server/src/api/bolt12_receive.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,8 +8,15 @@ pub(crate) fn handle_bolt12_receive_request(
node: Arc<Node>, request: Bolt12ReceiveRequest,
) -> Result<Bolt12ReceiveResponse, ldk_node::NodeError> {
let offer = match request.amount_msat {
Some(amount_msat) => node.bolt12_payment().receive(amount_msat, &request.description)?,
None => node.bolt12_payment().receive_variable_amount(&request.description)?,
Some(amount_msat) => node.bolt12_payment().receive(
amount_msat,
&request.description,
request.expiry_secs,
request.quantity,
)?,
None => node
.bolt12_payment()
.receive_variable_amount(&request.description, request.expiry_secs)?,
};

let response = Bolt12ReceiveResponse { offer: offer.to_string() };
Expand Down
11 changes: 7 additions & 4 deletions server/src/api/bolt12_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,13 @@ pub(crate) fn handle_bolt12_send_request(
Offer::from_str(&request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;

let payment_id = match request.amount_msat {
None => node.bolt12_payment().send(&offer, request.payer_note),
Some(amount_msat) => {
node.bolt12_payment().send_using_amount(&offer, request.payer_note, amount_msat)
},
None => node.bolt12_payment().send(&offer, request.quantity, request.payer_note),
Some(amount_msat) => node.bolt12_payment().send_using_amount(
&offer,
amount_msat,
request.quantity,
request.payer_note,
),
}?;

let response = Bolt12SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
6 changes: 5 additions & 1 deletion server/src/api/close_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,11 @@ pub(crate) fn handle_close_channel_request(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;

match request.force_close {
Some(true) => node.force_close_channel(&user_channel_id, counterparty_node_id)?,
Some(true) => node.force_close_channel(
&user_channel_id,
counterparty_node_id,
request.force_close_reason,
)?,
_ => node.close_channel(&user_channel_id, counterparty_node_id)?,
};

Expand Down
2 changes: 1 addition & 1 deletion server/src/api/get_node_info.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ pub(crate) fn handle_get_node_info_request(
let response = GetNodeInfoResponse {
node_id: node.node_id().to_string(),
current_best_block: Some(best_block),
latest_wallet_sync_timestamp: node_status.latest_wallet_sync_timestamp,
latest_lightning_wallet_sync_timestamp: node_status.latest_lightning_wallet_sync_timestamp,
latest_onchain_wallet_sync_timestamp: node_status.latest_onchain_wallet_sync_timestamp,
latest_fee_rate_cache_update_timestamp: node_status.latest_fee_rate_cache_update_timestamp,
latest_rgs_snapshot_timestamp: node_status.latest_rgs_snapshot_timestamp,
Expand Down
29 changes: 20 additions & 9 deletions server/src/api/open_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,15 +15,26 @@ pub(crate) fn handle_open_channel(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;
let address = SocketAddress::from_str(&request.address)
.map_err(|_| ldk_node::NodeError::InvalidSocketAddress)?;
let user_channel_id = node.connect_open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
request.announce_channel,
)?;

let user_channel_id = if request.announce_channel {
node.open_announced_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
)?
} else {
node.open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
None,
)?
};

let response = OpenChannelResponse {
user_channel_id: Bytes::from(user_channel_id.0.to_be_bytes().to_vec()),
};
Expand Down
5 changes: 3 additions & 2 deletions server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,14 +6,15 @@ use crate::service::NodeService;

use ldk_node::bitcoin::Network;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Config, Event, LogLevel};
use ldk_node::{Builder, Event, LogLevel};

use tokio::net::TcpListener;
use tokio::signal::unix::SignalKind;

use hyper::server::conn::http1;
use hyper_util::rt::TokioIo;

use ldk_node::config::Config;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
Expand DownExpand Up@@ -58,7 +59,7 @@ fn main() {
};

let mut builder = Builder::from_config(config);
builder.set_esplora_server(args[5].clone());
builder.set_chain_source_esplora(args[5].clone(), None);

let runtime = match tokio::runtime::Builder::new_multi_thread().enable_all().build() {
Ok(runtime) => Arc::new(runtime),
Expand Down
30 changes: 19 additions & 11 deletions server/src/util/proto_adapter.rs
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
use hex::prelude::*;
use ldk_node::{ChannelConfig, ChannelDetails};
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure};
use ldk_node::ChannelDetails;
use protos::{Channel, OutPoint};

pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
Channel {
channel_id: channel.channel_id.0.to_lower_hex_string(),
Expand All@@ -19,8 +21,8 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
is_outbound: channel.is_outbound,
is_channel_ready: channel.is_channel_ready,
is_usable: channel.is_usable,
is_public: channel.is_public,
channel_config: Some(channel_config_to_proto(channel.config.as_ref())),
is_announced: channel.is_announced,
channel_config: Some(channel_config_to_proto(channel.config)),
next_outbound_htlc_limit_msat: channel.next_outbound_htlc_limit_msat,
next_outbound_htlc_minimum_msat: channel.next_outbound_htlc_minimum_msat,
force_close_spend_delay: channel.force_close_spend_delay.map(|x| x as u32),
Expand All@@ -38,18 +40,24 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
}
}

pub(crate) fn channel_config_to_proto(channel_config: &ChannelConfig) -> protos::ChannelConfig {
pub(crate) fn channel_config_to_proto(channel_config: ChannelConfig) -> protos::ChannelConfig {
protos::ChannelConfig {
forwarding_fee_proportional_millionths: Some(
channel_config.forwarding_fee_proportional_millionths(),
channel_config.forwarding_fee_proportional_millionths,
),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat()),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta() as u32),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta as u32),
force_close_avoidance_max_fee_satoshis: Some(
channel_config.force_close_avoidance_max_fee_satoshis(),
channel_config.force_close_avoidance_max_fee_satoshis,
),
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs()),
// FIXME: Pending ldk-node upgrade.
max_dust_htlc_exposure: None,
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs),
max_dust_htlc_exposure: match channel_config.max_dust_htlc_exposure {
MaxDustHTLCExposure::FixedLimit { limit_msat } => {
Some(protos::channel_config::MaxDustHtlcExposure::FixedLimitMsat(limit_msat))
},
MaxDustHTLCExposure::FeeRateMultiplier { multiplier } => {
Some(protos::channel_config::MaxDustHtlcExposure::FeeRateMultiplier(multiplier))
},
},
}
}
, 'i'); if (__m === '*' || __re.test(location.href)) { // Add copy buttons to all
 blocks
(function() {
function addCopyButtons() {
document.querySelectorAll('pre code').forEach(function(codeBlock) {
if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;
codeBlock.parentElement.setAttribute('data-copy-added', 'true');
var btn = document.createElement('button');
btn.textContent = 'Copy';
btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';
btn.onmouseover = function() { this.style.opacity = '1'; };
btn.onmouseout = function() { this.style.opacity = '0.7'; };
btn.onclick = function() {
navigator.clipboard.writeText(codeBlock.textContent).then(function() {
btn.textContent = 'Copied!';
setTimeout(function() { btn.textContent = 'Copy'; }, 1500);
});
};
codeBlock.parentElement.style.position = 'relative';
codeBlock.parentElement.appendChild(btn);
});
}
addCopyButtons();
// Re-run on dynamic content
var observer = new MutationObserver(addCopyButtons);
observer.observe(document.body, { childList: true, subtree: true });
})();
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Upgrade Ldk-node to v0.4.0 / Ldk to v0.0.125 by G8XSU · Pull Request #18 · lightningdevkit/ldk-server · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
312 changes: 228 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions cli/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,6 +46,10 @@ enum Commands {
description: String,
#[arg(long)]
amount_msat: Option<u64>,
#[arg(long)]
expiry_secs: Option<u32>,
#[arg(long)]
quantity: Option<u64>,
},
Bolt12Send {
#[arg(short, long)]
Expand DownExpand Up@@ -95,9 +99,16 @@ async fn main() {
Commands::Bolt11Send { invoice, amount_msat } => {
handle_response(client.bolt11_send(Bolt11SendRequest { invoice, amount_msat }).await);
},
Commands::Bolt12Receive { description, amount_msat } => {
Commands::Bolt12Receive { description, amount_msat, expiry_secs, quantity } => {
handle_response(
client.bolt12_receive(Bolt12ReceiveRequest { description, amount_msat }).await,
client
.bolt12_receive(Bolt12ReceiveRequest {
description,
amount_msat,
expiry_secs,
quantity,
})
.await,
);
},
Commands::Bolt12Send { offer, amount_msat, quantity, payer_note } => {
Expand Down
19 changes: 14 additions & 5 deletions protos/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,12 +16,12 @@ pub struct GetNodeInfoResponse {
/// Should be always set, will never be `None`.
#[prost(message, optional, tag = "3")]
pub current_best_block: ::core::option::Option<BestBlock>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
/// to the chain tip.
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
/// the chain tip.
///
/// Will be `None` if the wallet hasnt been synced since the node was initialized.
/// Will be `None` if the wallet hasn't been synced yet.
#[prost(uint64, optional, tag = "4")]
pub latest_wallet_sync_timestamp: ::core::option::Option<u64>,
pub latest_lightning_wallet_sync_timestamp: ::core::option::Option<u64>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
/// wallet to the chain tip.
///
Expand DownExpand Up@@ -152,6 +152,12 @@ pub struct Bolt12ReceiveRequest {
/// 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<u64>,
/// Offer expiry time in seconds.
#[prost(uint32, optional, tag = "3")]
pub expiry_secs: ::core::option::Option<u32>,
/// If set, it represents the number of items requested, can only be set for fixed-amount offers.
#[prost(uint64, optional, tag = "4")]
pub quantity: ::core::option::Option<u64>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -297,6 +303,9 @@ pub struct CloseChannelRequest {
/// Whether to force close the specified channel.
#[prost(bool, optional, tag = "3")]
pub force_close: ::core::option::Option<bool>,
/// The reason for force-closing, can only be set while force closing a channel.
#[prost(string, optional, tag = "4")]
pub force_close_reason: ::core::option::Option<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -391,7 +400,7 @@ pub struct Channel {
pub is_usable: bool,
/// Is `true` if this channel is (or will be) publicly-announced
#[prost(bool, tag = "15")]
pub is_public: bool,
pub is_announced: bool,
/// Set of configurable parameters set by self that affect channel operation.
#[prost(message, optional, tag = "16")]
pub channel_config: ::core::option::Option<ChannelConfig>,
Expand Down
21 changes: 14 additions & 7 deletions protos/src/proto/ldk_node_server.proto
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,11 +18,11 @@ message GetNodeInfoResponse {
// Should be always set, will never be `None`.
BestBlock current_best_block = 3;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
// to the chain tip.
// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
// the chain tip.
//
// Will be `None` if the wallet hasnt been synced since the node was initialized.
optional uint64 latest_wallet_sync_timestamp = 4;
// Will be `None` if the wallet hasn't been synced yet.
optional uint64 latest_lightning_wallet_sync_timestamp = 4;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
// wallet to the chain tip.
Expand DownExpand Up@@ -147,6 +147,12 @@ message Bolt12ReceiveRequest {

// The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount offer is returned.
optional uint64 amount_msat = 2;

// Offer expiry time in seconds.
optional uint32 expiry_secs = 3;

// If set, it represents the number of items requested, can only be set for fixed-amount offers.
optional uint64 quantity = 4;
}

message Bolt12ReceiveResponse {
Expand DownExpand Up@@ -273,6 +279,9 @@ message CloseChannelRequest {

// Whether to force close the specified channel.
optional bool force_close = 3;

// The reason for force-closing, can only be set while force closing a channel.
optional string force_close_reason = 4;
}

message CloseChannelResponse {
Expand DownExpand Up@@ -364,7 +373,7 @@ message Channel {
bool is_usable = 14;

// Is `true` if this channel is (or will be) publicly-announced
bool is_public = 15;
bool is_announced = 15;

// Set of configurable parameters set by self that affect channel operation.
ChannelConfig channel_config = 16;
Expand DownExpand Up@@ -427,11 +436,9 @@ message OutPoint {
}

message BestBlock {

// The block’s hash
string block_hash = 1;

// The height at which the block was confirmed.
uint32 height = 2;

}
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node.git", branch = "main" }
ldk-node = { version = "0.4.0", default-features = false }
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.118", default-features = false }
hyper = { version = "1", default-features = false, features = ["server", "http1"] }
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/bolt11_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,8 +14,8 @@ pub(crate) fn handle_bolt11_send_request(
.map_err(|_| ldk_node::NodeError::InvalidInvoice)?;

let payment_id = match request.amount_msat {
None => node.bolt11_payment().send(&invoice),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat),
None => node.bolt11_payment().send(&invoice, None),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat, None),
}?;

let response = Bolt11SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
11 changes: 9 additions & 2 deletions server/src/api/bolt12_receive.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,8 +8,15 @@ pub(crate) fn handle_bolt12_receive_request(
node: Arc<Node>, request: Bolt12ReceiveRequest,
) -> Result<Bolt12ReceiveResponse, ldk_node::NodeError> {
let offer = match request.amount_msat {
Some(amount_msat) => node.bolt12_payment().receive(amount_msat, &request.description)?,
None => node.bolt12_payment().receive_variable_amount(&request.description)?,
Some(amount_msat) => node.bolt12_payment().receive(
amount_msat,
&request.description,
request.expiry_secs,
request.quantity,
)?,
None => node
.bolt12_payment()
.receive_variable_amount(&request.description, request.expiry_secs)?,
};

let response = Bolt12ReceiveResponse { offer: offer.to_string() };
Expand Down
11 changes: 7 additions & 4 deletions server/src/api/bolt12_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,13 @@ pub(crate) fn handle_bolt12_send_request(
Offer::from_str(&request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;

let payment_id = match request.amount_msat {
None => node.bolt12_payment().send(&offer, request.payer_note),
Some(amount_msat) => {
node.bolt12_payment().send_using_amount(&offer, request.payer_note, amount_msat)
},
None => node.bolt12_payment().send(&offer, request.quantity, request.payer_note),
Some(amount_msat) => node.bolt12_payment().send_using_amount(
&offer,
amount_msat,
request.quantity,
request.payer_note,
),
}?;

let response = Bolt12SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
6 changes: 5 additions & 1 deletion server/src/api/close_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,11 @@ pub(crate) fn handle_close_channel_request(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;

match request.force_close {
Some(true) => node.force_close_channel(&user_channel_id, counterparty_node_id)?,
Some(true) => node.force_close_channel(
&user_channel_id,
counterparty_node_id,
request.force_close_reason,
)?,
_ => node.close_channel(&user_channel_id, counterparty_node_id)?,
};

Expand Down
2 changes: 1 addition & 1 deletion server/src/api/get_node_info.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ pub(crate) fn handle_get_node_info_request(
let response = GetNodeInfoResponse {
node_id: node.node_id().to_string(),
current_best_block: Some(best_block),
latest_wallet_sync_timestamp: node_status.latest_wallet_sync_timestamp,
latest_lightning_wallet_sync_timestamp: node_status.latest_lightning_wallet_sync_timestamp,
latest_onchain_wallet_sync_timestamp: node_status.latest_onchain_wallet_sync_timestamp,
latest_fee_rate_cache_update_timestamp: node_status.latest_fee_rate_cache_update_timestamp,
latest_rgs_snapshot_timestamp: node_status.latest_rgs_snapshot_timestamp,
Expand Down
29 changes: 20 additions & 9 deletions server/src/api/open_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,15 +15,26 @@ pub(crate) fn handle_open_channel(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;
let address = SocketAddress::from_str(&request.address)
.map_err(|_| ldk_node::NodeError::InvalidSocketAddress)?;
let user_channel_id = node.connect_open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
request.announce_channel,
)?;

let user_channel_id = if request.announce_channel {
node.open_announced_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
)?
} else {
node.open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
None,
)?
};

let response = OpenChannelResponse {
user_channel_id: Bytes::from(user_channel_id.0.to_be_bytes().to_vec()),
};
Expand Down
5 changes: 3 additions & 2 deletions server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,14 +6,15 @@ use crate::service::NodeService;

use ldk_node::bitcoin::Network;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Config, Event, LogLevel};
use ldk_node::{Builder, Event, LogLevel};

use tokio::net::TcpListener;
use tokio::signal::unix::SignalKind;

use hyper::server::conn::http1;
use hyper_util::rt::TokioIo;

use ldk_node::config::Config;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
Expand DownExpand Up@@ -58,7 +59,7 @@ fn main() {
};

let mut builder = Builder::from_config(config);
builder.set_esplora_server(args[5].clone());
builder.set_chain_source_esplora(args[5].clone(), None);

let runtime = match tokio::runtime::Builder::new_multi_thread().enable_all().build() {
Ok(runtime) => Arc::new(runtime),
Expand Down
30 changes: 19 additions & 11 deletions server/src/util/proto_adapter.rs
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
use hex::prelude::*;
use ldk_node::{ChannelConfig, ChannelDetails};
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure};
use ldk_node::ChannelDetails;
use protos::{Channel, OutPoint};

pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
Channel {
channel_id: channel.channel_id.0.to_lower_hex_string(),
Expand All@@ -19,8 +21,8 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
is_outbound: channel.is_outbound,
is_channel_ready: channel.is_channel_ready,
is_usable: channel.is_usable,
is_public: channel.is_public,
channel_config: Some(channel_config_to_proto(channel.config.as_ref())),
is_announced: channel.is_announced,
channel_config: Some(channel_config_to_proto(channel.config)),
next_outbound_htlc_limit_msat: channel.next_outbound_htlc_limit_msat,
next_outbound_htlc_minimum_msat: channel.next_outbound_htlc_minimum_msat,
force_close_spend_delay: channel.force_close_spend_delay.map(|x| x as u32),
Expand All@@ -38,18 +40,24 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
}
}

pub(crate) fn channel_config_to_proto(channel_config: &ChannelConfig) -> protos::ChannelConfig {
pub(crate) fn channel_config_to_proto(channel_config: ChannelConfig) -> protos::ChannelConfig {
protos::ChannelConfig {
forwarding_fee_proportional_millionths: Some(
channel_config.forwarding_fee_proportional_millionths(),
channel_config.forwarding_fee_proportional_millionths,
),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat()),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta() as u32),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta as u32),
force_close_avoidance_max_fee_satoshis: Some(
channel_config.force_close_avoidance_max_fee_satoshis(),
channel_config.force_close_avoidance_max_fee_satoshis,
),
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs()),
// FIXME: Pending ldk-node upgrade.
max_dust_htlc_exposure: None,
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs),
max_dust_htlc_exposure: match channel_config.max_dust_htlc_exposure {
MaxDustHTLCExposure::FixedLimit { limit_msat } => {
Some(protos::channel_config::MaxDustHtlcExposure::FixedLimitMsat(limit_msat))
},
MaxDustHTLCExposure::FeeRateMultiplier { multiplier } => {
Some(protos::channel_config::MaxDustHtlcExposure::FeeRateMultiplier(multiplier))
},
},
}
}
, 'i'); if (__m === '*' || __re.test(location.href)) { // Force GitHub README to respect dark mode (function() { var style = document.createElement('style'); style.textContent = ' .markdown-body { color-scheme: dark light; } .markdown-body pre { background: #161b22 !important; } .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; } .markdown-body table th, .markdown-body table td { border-color: #30363d !important; } .markdown-body img { background: #0d1117; } .markdown-body blockquote { border-left-color: #8b949e; } .markdown-body hr { border-color: #30363d; } '; document.head.appendChild(style); })(); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Upgrade Ldk-node to v0.4.0 / Ldk to v0.0.125 by G8XSU · Pull Request #18 · lightningdevkit/ldk-server · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
312 changes: 228 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions cli/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,6 +46,10 @@ enum Commands {
description: String,
#[arg(long)]
amount_msat: Option<u64>,
#[arg(long)]
expiry_secs: Option<u32>,
#[arg(long)]
quantity: Option<u64>,
},
Bolt12Send {
#[arg(short, long)]
Expand DownExpand Up@@ -95,9 +99,16 @@ async fn main() {
Commands::Bolt11Send { invoice, amount_msat } => {
handle_response(client.bolt11_send(Bolt11SendRequest { invoice, amount_msat }).await);
},
Commands::Bolt12Receive { description, amount_msat } => {
Commands::Bolt12Receive { description, amount_msat, expiry_secs, quantity } => {
handle_response(
client.bolt12_receive(Bolt12ReceiveRequest { description, amount_msat }).await,
client
.bolt12_receive(Bolt12ReceiveRequest {
description,
amount_msat,
expiry_secs,
quantity,
})
.await,
);
},
Commands::Bolt12Send { offer, amount_msat, quantity, payer_note } => {
Expand Down
19 changes: 14 additions & 5 deletions protos/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,12 +16,12 @@ pub struct GetNodeInfoResponse {
/// Should be always set, will never be `None`.
#[prost(message, optional, tag = "3")]
pub current_best_block: ::core::option::Option<BestBlock>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
/// to the chain tip.
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
/// the chain tip.
///
/// Will be `None` if the wallet hasnt been synced since the node was initialized.
/// Will be `None` if the wallet hasn't been synced yet.
#[prost(uint64, optional, tag = "4")]
pub latest_wallet_sync_timestamp: ::core::option::Option<u64>,
pub latest_lightning_wallet_sync_timestamp: ::core::option::Option<u64>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
/// wallet to the chain tip.
///
Expand DownExpand Up@@ -152,6 +152,12 @@ pub struct Bolt12ReceiveRequest {
/// 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<u64>,
/// Offer expiry time in seconds.
#[prost(uint32, optional, tag = "3")]
pub expiry_secs: ::core::option::Option<u32>,
/// If set, it represents the number of items requested, can only be set for fixed-amount offers.
#[prost(uint64, optional, tag = "4")]
pub quantity: ::core::option::Option<u64>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -297,6 +303,9 @@ pub struct CloseChannelRequest {
/// Whether to force close the specified channel.
#[prost(bool, optional, tag = "3")]
pub force_close: ::core::option::Option<bool>,
/// The reason for force-closing, can only be set while force closing a channel.
#[prost(string, optional, tag = "4")]
pub force_close_reason: ::core::option::Option<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -391,7 +400,7 @@ pub struct Channel {
pub is_usable: bool,
/// Is `true` if this channel is (or will be) publicly-announced
#[prost(bool, tag = "15")]
pub is_public: bool,
pub is_announced: bool,
/// Set of configurable parameters set by self that affect channel operation.
#[prost(message, optional, tag = "16")]
pub channel_config: ::core::option::Option<ChannelConfig>,
Expand Down
21 changes: 14 additions & 7 deletions protos/src/proto/ldk_node_server.proto
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,11 +18,11 @@ message GetNodeInfoResponse {
// Should be always set, will never be `None`.
BestBlock current_best_block = 3;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
// to the chain tip.
// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
// the chain tip.
//
// Will be `None` if the wallet hasnt been synced since the node was initialized.
optional uint64 latest_wallet_sync_timestamp = 4;
// Will be `None` if the wallet hasn't been synced yet.
optional uint64 latest_lightning_wallet_sync_timestamp = 4;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
// wallet to the chain tip.
Expand DownExpand Up@@ -147,6 +147,12 @@ message Bolt12ReceiveRequest {

// The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount offer is returned.
optional uint64 amount_msat = 2;

// Offer expiry time in seconds.
optional uint32 expiry_secs = 3;

// If set, it represents the number of items requested, can only be set for fixed-amount offers.
optional uint64 quantity = 4;
}

message Bolt12ReceiveResponse {
Expand DownExpand Up@@ -273,6 +279,9 @@ message CloseChannelRequest {

// Whether to force close the specified channel.
optional bool force_close = 3;

// The reason for force-closing, can only be set while force closing a channel.
optional string force_close_reason = 4;
}

message CloseChannelResponse {
Expand DownExpand Up@@ -364,7 +373,7 @@ message Channel {
bool is_usable = 14;

// Is `true` if this channel is (or will be) publicly-announced
bool is_public = 15;
bool is_announced = 15;

// Set of configurable parameters set by self that affect channel operation.
ChannelConfig channel_config = 16;
Expand DownExpand Up@@ -427,11 +436,9 @@ message OutPoint {
}

message BestBlock {

// The block’s hash
string block_hash = 1;

// The height at which the block was confirmed.
uint32 height = 2;

}
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node.git", branch = "main" }
ldk-node = { version = "0.4.0", default-features = false }
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.118", default-features = false }
hyper = { version = "1", default-features = false, features = ["server", "http1"] }
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/bolt11_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,8 +14,8 @@ pub(crate) fn handle_bolt11_send_request(
.map_err(|_| ldk_node::NodeError::InvalidInvoice)?;

let payment_id = match request.amount_msat {
None => node.bolt11_payment().send(&invoice),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat),
None => node.bolt11_payment().send(&invoice, None),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat, None),
}?;

let response = Bolt11SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
11 changes: 9 additions & 2 deletions server/src/api/bolt12_receive.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,8 +8,15 @@ pub(crate) fn handle_bolt12_receive_request(
node: Arc<Node>, request: Bolt12ReceiveRequest,
) -> Result<Bolt12ReceiveResponse, ldk_node::NodeError> {
let offer = match request.amount_msat {
Some(amount_msat) => node.bolt12_payment().receive(amount_msat, &request.description)?,
None => node.bolt12_payment().receive_variable_amount(&request.description)?,
Some(amount_msat) => node.bolt12_payment().receive(
amount_msat,
&request.description,
request.expiry_secs,
request.quantity,
)?,
None => node
.bolt12_payment()
.receive_variable_amount(&request.description, request.expiry_secs)?,
};

let response = Bolt12ReceiveResponse { offer: offer.to_string() };
Expand Down
11 changes: 7 additions & 4 deletions server/src/api/bolt12_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,13 @@ pub(crate) fn handle_bolt12_send_request(
Offer::from_str(&request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;

let payment_id = match request.amount_msat {
None => node.bolt12_payment().send(&offer, request.payer_note),
Some(amount_msat) => {
node.bolt12_payment().send_using_amount(&offer, request.payer_note, amount_msat)
},
None => node.bolt12_payment().send(&offer, request.quantity, request.payer_note),
Some(amount_msat) => node.bolt12_payment().send_using_amount(
&offer,
amount_msat,
request.quantity,
request.payer_note,
),
}?;

let response = Bolt12SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
6 changes: 5 additions & 1 deletion server/src/api/close_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,11 @@ pub(crate) fn handle_close_channel_request(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;

match request.force_close {
Some(true) => node.force_close_channel(&user_channel_id, counterparty_node_id)?,
Some(true) => node.force_close_channel(
&user_channel_id,
counterparty_node_id,
request.force_close_reason,
)?,
_ => node.close_channel(&user_channel_id, counterparty_node_id)?,
};

Expand Down
2 changes: 1 addition & 1 deletion server/src/api/get_node_info.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ pub(crate) fn handle_get_node_info_request(
let response = GetNodeInfoResponse {
node_id: node.node_id().to_string(),
current_best_block: Some(best_block),
latest_wallet_sync_timestamp: node_status.latest_wallet_sync_timestamp,
latest_lightning_wallet_sync_timestamp: node_status.latest_lightning_wallet_sync_timestamp,
latest_onchain_wallet_sync_timestamp: node_status.latest_onchain_wallet_sync_timestamp,
latest_fee_rate_cache_update_timestamp: node_status.latest_fee_rate_cache_update_timestamp,
latest_rgs_snapshot_timestamp: node_status.latest_rgs_snapshot_timestamp,
Expand Down
29 changes: 20 additions & 9 deletions server/src/api/open_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,15 +15,26 @@ pub(crate) fn handle_open_channel(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;
let address = SocketAddress::from_str(&request.address)
.map_err(|_| ldk_node::NodeError::InvalidSocketAddress)?;
let user_channel_id = node.connect_open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
request.announce_channel,
)?;

let user_channel_id = if request.announce_channel {
node.open_announced_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
)?
} else {
node.open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
None,
)?
};

let response = OpenChannelResponse {
user_channel_id: Bytes::from(user_channel_id.0.to_be_bytes().to_vec()),
};
Expand Down
5 changes: 3 additions & 2 deletions server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,14 +6,15 @@ use crate::service::NodeService;

use ldk_node::bitcoin::Network;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Config, Event, LogLevel};
use ldk_node::{Builder, Event, LogLevel};

use tokio::net::TcpListener;
use tokio::signal::unix::SignalKind;

use hyper::server::conn::http1;
use hyper_util::rt::TokioIo;

use ldk_node::config::Config;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
Expand DownExpand Up@@ -58,7 +59,7 @@ fn main() {
};

let mut builder = Builder::from_config(config);
builder.set_esplora_server(args[5].clone());
builder.set_chain_source_esplora(args[5].clone(), None);

let runtime = match tokio::runtime::Builder::new_multi_thread().enable_all().build() {
Ok(runtime) => Arc::new(runtime),
Expand Down
30 changes: 19 additions & 11 deletions server/src/util/proto_adapter.rs
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
use hex::prelude::*;
use ldk_node::{ChannelConfig, ChannelDetails};
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure};
use ldk_node::ChannelDetails;
use protos::{Channel, OutPoint};

pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
Channel {
channel_id: channel.channel_id.0.to_lower_hex_string(),
Expand All@@ -19,8 +21,8 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
is_outbound: channel.is_outbound,
is_channel_ready: channel.is_channel_ready,
is_usable: channel.is_usable,
is_public: channel.is_public,
channel_config: Some(channel_config_to_proto(channel.config.as_ref())),
is_announced: channel.is_announced,
channel_config: Some(channel_config_to_proto(channel.config)),
next_outbound_htlc_limit_msat: channel.next_outbound_htlc_limit_msat,
next_outbound_htlc_minimum_msat: channel.next_outbound_htlc_minimum_msat,
force_close_spend_delay: channel.force_close_spend_delay.map(|x| x as u32),
Expand All@@ -38,18 +40,24 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
}
}

pub(crate) fn channel_config_to_proto(channel_config: &ChannelConfig) -> protos::ChannelConfig {
pub(crate) fn channel_config_to_proto(channel_config: ChannelConfig) -> protos::ChannelConfig {
protos::ChannelConfig {
forwarding_fee_proportional_millionths: Some(
channel_config.forwarding_fee_proportional_millionths(),
channel_config.forwarding_fee_proportional_millionths,
),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat()),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta() as u32),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta as u32),
force_close_avoidance_max_fee_satoshis: Some(
channel_config.force_close_avoidance_max_fee_satoshis(),
channel_config.force_close_avoidance_max_fee_satoshis,
),
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs()),
// FIXME: Pending ldk-node upgrade.
max_dust_htlc_exposure: None,
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs),
max_dust_htlc_exposure: match channel_config.max_dust_htlc_exposure {
MaxDustHTLCExposure::FixedLimit { limit_msat } => {
Some(protos::channel_config::MaxDustHtlcExposure::FixedLimitMsat(limit_msat))
},
MaxDustHTLCExposure::FeeRateMultiplier { multiplier } => {
Some(protos::channel_config::MaxDustHtlcExposure::FeeRateMultiplier(multiplier))
},
},
}
}
, 'i'); if (__m === '*' || __re.test(location.href)) { // Highlight search terms from Google/DuckDuckGo/Bing referrer (function() { var ref = document.referrer; var terms = []; if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) { var url = new URL(ref); var q = url.searchParams.get('q') || url.searchParams.get('p'); if (q) { terms = q.split(/\s+/).filter(function(t) { return t.length > 2; }); } } if (terms.length === 0) return; var style = document.createElement('style'); style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }'; document.head.appendChild(style); function highlight(node) { if (node.nodeType === 3) { // text node var text = node.textContent; var found = false; terms.forEach(function(term) { var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\]\\]/g, '\\') + ')', 'gi'); if (regex.test(text)) { found = true; var frag = document.createDocumentFragment(); var parts = text.split(regex); parts.forEach(function(part, i) { if (i % 2 === 0) { frag.appendChild(document.createTextNode(part)); } else { var span = document.createElement('span'); span.className = 'userscript-highlight'; span.textContent = part; frag.appendChild(span); } }); node.parentNode.replaceChild(frag, node); } }); } else if (node.nodeType === 1 && node.childNodes) { // element var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT']; if (!skipTags.includes(node.tagName)) { Array.from(node.childNodes).forEach(highlight); } } } highlight(document.body); // Re-highlight on dynamic content var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1 || node.nodeType === 3) highlight(node); }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Upgrade Ldk-node to v0.4.0 / Ldk to v0.0.125 by G8XSU · Pull Request #18 · lightningdevkit/ldk-server · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
312 changes: 228 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions cli/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,6 +46,10 @@ enum Commands {
description: String,
#[arg(long)]
amount_msat: Option<u64>,
#[arg(long)]
expiry_secs: Option<u32>,
#[arg(long)]
quantity: Option<u64>,
},
Bolt12Send {
#[arg(short, long)]
Expand DownExpand Up@@ -95,9 +99,16 @@ async fn main() {
Commands::Bolt11Send { invoice, amount_msat } => {
handle_response(client.bolt11_send(Bolt11SendRequest { invoice, amount_msat }).await);
},
Commands::Bolt12Receive { description, amount_msat } => {
Commands::Bolt12Receive { description, amount_msat, expiry_secs, quantity } => {
handle_response(
client.bolt12_receive(Bolt12ReceiveRequest { description, amount_msat }).await,
client
.bolt12_receive(Bolt12ReceiveRequest {
description,
amount_msat,
expiry_secs,
quantity,
})
.await,
);
},
Commands::Bolt12Send { offer, amount_msat, quantity, payer_note } => {
Expand Down
19 changes: 14 additions & 5 deletions protos/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,12 +16,12 @@ pub struct GetNodeInfoResponse {
/// Should be always set, will never be `None`.
#[prost(message, optional, tag = "3")]
pub current_best_block: ::core::option::Option<BestBlock>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
/// to the chain tip.
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
/// the chain tip.
///
/// Will be `None` if the wallet hasnt been synced since the node was initialized.
/// Will be `None` if the wallet hasn't been synced yet.
#[prost(uint64, optional, tag = "4")]
pub latest_wallet_sync_timestamp: ::core::option::Option<u64>,
pub latest_lightning_wallet_sync_timestamp: ::core::option::Option<u64>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
/// wallet to the chain tip.
///
Expand DownExpand Up@@ -152,6 +152,12 @@ pub struct Bolt12ReceiveRequest {
/// 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<u64>,
/// Offer expiry time in seconds.
#[prost(uint32, optional, tag = "3")]
pub expiry_secs: ::core::option::Option<u32>,
/// If set, it represents the number of items requested, can only be set for fixed-amount offers.
#[prost(uint64, optional, tag = "4")]
pub quantity: ::core::option::Option<u64>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -297,6 +303,9 @@ pub struct CloseChannelRequest {
/// Whether to force close the specified channel.
#[prost(bool, optional, tag = "3")]
pub force_close: ::core::option::Option<bool>,
/// The reason for force-closing, can only be set while force closing a channel.
#[prost(string, optional, tag = "4")]
pub force_close_reason: ::core::option::Option<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -391,7 +400,7 @@ pub struct Channel {
pub is_usable: bool,
/// Is `true` if this channel is (or will be) publicly-announced
#[prost(bool, tag = "15")]
pub is_public: bool,
pub is_announced: bool,
/// Set of configurable parameters set by self that affect channel operation.
#[prost(message, optional, tag = "16")]
pub channel_config: ::core::option::Option<ChannelConfig>,
Expand Down
21 changes: 14 additions & 7 deletions protos/src/proto/ldk_node_server.proto
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,11 +18,11 @@ message GetNodeInfoResponse {
// Should be always set, will never be `None`.
BestBlock current_best_block = 3;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
// to the chain tip.
// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
// the chain tip.
//
// Will be `None` if the wallet hasnt been synced since the node was initialized.
optional uint64 latest_wallet_sync_timestamp = 4;
// Will be `None` if the wallet hasn't been synced yet.
optional uint64 latest_lightning_wallet_sync_timestamp = 4;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
// wallet to the chain tip.
Expand DownExpand Up@@ -147,6 +147,12 @@ message Bolt12ReceiveRequest {

// The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount offer is returned.
optional uint64 amount_msat = 2;

// Offer expiry time in seconds.
optional uint32 expiry_secs = 3;

// If set, it represents the number of items requested, can only be set for fixed-amount offers.
optional uint64 quantity = 4;
}

message Bolt12ReceiveResponse {
Expand DownExpand Up@@ -273,6 +279,9 @@ message CloseChannelRequest {

// Whether to force close the specified channel.
optional bool force_close = 3;

// The reason for force-closing, can only be set while force closing a channel.
optional string force_close_reason = 4;
}

message CloseChannelResponse {
Expand DownExpand Up@@ -364,7 +373,7 @@ message Channel {
bool is_usable = 14;

// Is `true` if this channel is (or will be) publicly-announced
bool is_public = 15;
bool is_announced = 15;

// Set of configurable parameters set by self that affect channel operation.
ChannelConfig channel_config = 16;
Expand DownExpand Up@@ -427,11 +436,9 @@ message OutPoint {
}

message BestBlock {

// The block’s hash
string block_hash = 1;

// The height at which the block was confirmed.
uint32 height = 2;

}
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node.git", branch = "main" }
ldk-node = { version = "0.4.0", default-features = false }
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.118", default-features = false }
hyper = { version = "1", default-features = false, features = ["server", "http1"] }
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/bolt11_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,8 +14,8 @@ pub(crate) fn handle_bolt11_send_request(
.map_err(|_| ldk_node::NodeError::InvalidInvoice)?;

let payment_id = match request.amount_msat {
None => node.bolt11_payment().send(&invoice),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat),
None => node.bolt11_payment().send(&invoice, None),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat, None),
}?;

let response = Bolt11SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
11 changes: 9 additions & 2 deletions server/src/api/bolt12_receive.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,8 +8,15 @@ pub(crate) fn handle_bolt12_receive_request(
node: Arc<Node>, request: Bolt12ReceiveRequest,
) -> Result<Bolt12ReceiveResponse, ldk_node::NodeError> {
let offer = match request.amount_msat {
Some(amount_msat) => node.bolt12_payment().receive(amount_msat, &request.description)?,
None => node.bolt12_payment().receive_variable_amount(&request.description)?,
Some(amount_msat) => node.bolt12_payment().receive(
amount_msat,
&request.description,
request.expiry_secs,
request.quantity,
)?,
None => node
.bolt12_payment()
.receive_variable_amount(&request.description, request.expiry_secs)?,
};

let response = Bolt12ReceiveResponse { offer: offer.to_string() };
Expand Down
11 changes: 7 additions & 4 deletions server/src/api/bolt12_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,13 @@ pub(crate) fn handle_bolt12_send_request(
Offer::from_str(&request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;

let payment_id = match request.amount_msat {
None => node.bolt12_payment().send(&offer, request.payer_note),
Some(amount_msat) => {
node.bolt12_payment().send_using_amount(&offer, request.payer_note, amount_msat)
},
None => node.bolt12_payment().send(&offer, request.quantity, request.payer_note),
Some(amount_msat) => node.bolt12_payment().send_using_amount(
&offer,
amount_msat,
request.quantity,
request.payer_note,
),
}?;

let response = Bolt12SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
6 changes: 5 additions & 1 deletion server/src/api/close_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,11 @@ pub(crate) fn handle_close_channel_request(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;

match request.force_close {
Some(true) => node.force_close_channel(&user_channel_id, counterparty_node_id)?,
Some(true) => node.force_close_channel(
&user_channel_id,
counterparty_node_id,
request.force_close_reason,
)?,
_ => node.close_channel(&user_channel_id, counterparty_node_id)?,
};

Expand Down
2 changes: 1 addition & 1 deletion server/src/api/get_node_info.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ pub(crate) fn handle_get_node_info_request(
let response = GetNodeInfoResponse {
node_id: node.node_id().to_string(),
current_best_block: Some(best_block),
latest_wallet_sync_timestamp: node_status.latest_wallet_sync_timestamp,
latest_lightning_wallet_sync_timestamp: node_status.latest_lightning_wallet_sync_timestamp,
latest_onchain_wallet_sync_timestamp: node_status.latest_onchain_wallet_sync_timestamp,
latest_fee_rate_cache_update_timestamp: node_status.latest_fee_rate_cache_update_timestamp,
latest_rgs_snapshot_timestamp: node_status.latest_rgs_snapshot_timestamp,
Expand Down
29 changes: 20 additions & 9 deletions server/src/api/open_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,15 +15,26 @@ pub(crate) fn handle_open_channel(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;
let address = SocketAddress::from_str(&request.address)
.map_err(|_| ldk_node::NodeError::InvalidSocketAddress)?;
let user_channel_id = node.connect_open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
request.announce_channel,
)?;

let user_channel_id = if request.announce_channel {
node.open_announced_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
)?
} else {
node.open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
None,
)?
};

let response = OpenChannelResponse {
user_channel_id: Bytes::from(user_channel_id.0.to_be_bytes().to_vec()),
};
Expand Down
5 changes: 3 additions & 2 deletions server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,14 +6,15 @@ use crate::service::NodeService;

use ldk_node::bitcoin::Network;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Config, Event, LogLevel};
use ldk_node::{Builder, Event, LogLevel};

use tokio::net::TcpListener;
use tokio::signal::unix::SignalKind;

use hyper::server::conn::http1;
use hyper_util::rt::TokioIo;

use ldk_node::config::Config;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
Expand DownExpand Up@@ -58,7 +59,7 @@ fn main() {
};

let mut builder = Builder::from_config(config);
builder.set_esplora_server(args[5].clone());
builder.set_chain_source_esplora(args[5].clone(), None);

let runtime = match tokio::runtime::Builder::new_multi_thread().enable_all().build() {
Ok(runtime) => Arc::new(runtime),
Expand Down
30 changes: 19 additions & 11 deletions server/src/util/proto_adapter.rs
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
use hex::prelude::*;
use ldk_node::{ChannelConfig, ChannelDetails};
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure};
use ldk_node::ChannelDetails;
use protos::{Channel, OutPoint};

pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
Channel {
channel_id: channel.channel_id.0.to_lower_hex_string(),
Expand All@@ -19,8 +21,8 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
is_outbound: channel.is_outbound,
is_channel_ready: channel.is_channel_ready,
is_usable: channel.is_usable,
is_public: channel.is_public,
channel_config: Some(channel_config_to_proto(channel.config.as_ref())),
is_announced: channel.is_announced,
channel_config: Some(channel_config_to_proto(channel.config)),
next_outbound_htlc_limit_msat: channel.next_outbound_htlc_limit_msat,
next_outbound_htlc_minimum_msat: channel.next_outbound_htlc_minimum_msat,
force_close_spend_delay: channel.force_close_spend_delay.map(|x| x as u32),
Expand All@@ -38,18 +40,24 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
}
}

pub(crate) fn channel_config_to_proto(channel_config: &ChannelConfig) -> protos::ChannelConfig {
pub(crate) fn channel_config_to_proto(channel_config: ChannelConfig) -> protos::ChannelConfig {
protos::ChannelConfig {
forwarding_fee_proportional_millionths: Some(
channel_config.forwarding_fee_proportional_millionths(),
channel_config.forwarding_fee_proportional_millionths,
),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat()),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta() as u32),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta as u32),
force_close_avoidance_max_fee_satoshis: Some(
channel_config.force_close_avoidance_max_fee_satoshis(),
channel_config.force_close_avoidance_max_fee_satoshis,
),
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs()),
// FIXME: Pending ldk-node upgrade.
max_dust_htlc_exposure: None,
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs),
max_dust_htlc_exposure: match channel_config.max_dust_htlc_exposure {
MaxDustHTLCExposure::FixedLimit { limit_msat } => {
Some(protos::channel_config::MaxDustHtlcExposure::FixedLimitMsat(limit_msat))
},
MaxDustHTLCExposure::FeeRateMultiplier { multiplier } => {
Some(protos::channel_config::MaxDustHtlcExposure::FeeRateMultiplier(multiplier))
},
},
}
}
, 'i'); if (__m === '*' || __re.test(location.href)) { // Strip utm_, fbclid, gclid, etc. from all links on page (function() { var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content', 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid', 'ref', 'ref_src', 'source', 'medium', 'campaign']; function cleanUrl(url) { try { var u = new URL(url, window.location.origin); var changed = false; trackingParams.forEach(function(p) { if (u.searchParams.has(p)) { u.searchParams.delete(p); changed = true; } }); return changed ? u.toString() : url; } catch (e) { return url; } } function cleanLinks() { document.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } cleanLinks(); var observer = new MutationObserver(function(mutations) { mutations.forEach(function(m) { m.addedNodes.forEach(function(node) { if (node.nodeType === 1) { if (node.tagName === 'A') cleanLinks(); node.querySelectorAll('a[href]').forEach(function(a) { var clean = cleanUrl(a.href); if (clean !== a.href) a.href = clean; }); } }); }); }); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + ' Upgrade Ldk-node to v0.4.0 / Ldk to v0.0.125 by G8XSU · Pull Request #18 · lightningdevkit/ldk-server · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
312 changes: 228 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions cli/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,6 +46,10 @@ enum Commands {
description: String,
#[arg(long)]
amount_msat: Option<u64>,
#[arg(long)]
expiry_secs: Option<u32>,
#[arg(long)]
quantity: Option<u64>,
},
Bolt12Send {
#[arg(short, long)]
Expand DownExpand Up@@ -95,9 +99,16 @@ async fn main() {
Commands::Bolt11Send { invoice, amount_msat } => {
handle_response(client.bolt11_send(Bolt11SendRequest { invoice, amount_msat }).await);
},
Commands::Bolt12Receive { description, amount_msat } => {
Commands::Bolt12Receive { description, amount_msat, expiry_secs, quantity } => {
handle_response(
client.bolt12_receive(Bolt12ReceiveRequest { description, amount_msat }).await,
client
.bolt12_receive(Bolt12ReceiveRequest {
description,
amount_msat,
expiry_secs,
quantity,
})
.await,
);
},
Commands::Bolt12Send { offer, amount_msat, quantity, payer_note } => {
Expand Down
19 changes: 14 additions & 5 deletions protos/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,12 +16,12 @@ pub struct GetNodeInfoResponse {
/// Should be always set, will never be `None`.
#[prost(message, optional, tag = "3")]
pub current_best_block: ::core::option::Option<BestBlock>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
/// to the chain tip.
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
/// the chain tip.
///
/// Will be `None` if the wallet hasnt been synced since the node was initialized.
/// Will be `None` if the wallet hasn't been synced yet.
#[prost(uint64, optional, tag = "4")]
pub latest_wallet_sync_timestamp: ::core::option::Option<u64>,
pub latest_lightning_wallet_sync_timestamp: ::core::option::Option<u64>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
/// wallet to the chain tip.
///
Expand DownExpand Up@@ -152,6 +152,12 @@ pub struct Bolt12ReceiveRequest {
/// 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<u64>,
/// Offer expiry time in seconds.
#[prost(uint32, optional, tag = "3")]
pub expiry_secs: ::core::option::Option<u32>,
/// If set, it represents the number of items requested, can only be set for fixed-amount offers.
#[prost(uint64, optional, tag = "4")]
pub quantity: ::core::option::Option<u64>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -297,6 +303,9 @@ pub struct CloseChannelRequest {
/// Whether to force close the specified channel.
#[prost(bool, optional, tag = "3")]
pub force_close: ::core::option::Option<bool>,
/// The reason for force-closing, can only be set while force closing a channel.
#[prost(string, optional, tag = "4")]
pub force_close_reason: ::core::option::Option<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -391,7 +400,7 @@ pub struct Channel {
pub is_usable: bool,
/// Is `true` if this channel is (or will be) publicly-announced
#[prost(bool, tag = "15")]
pub is_public: bool,
pub is_announced: bool,
/// Set of configurable parameters set by self that affect channel operation.
#[prost(message, optional, tag = "16")]
pub channel_config: ::core::option::Option<ChannelConfig>,
Expand Down
21 changes: 14 additions & 7 deletions protos/src/proto/ldk_node_server.proto
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,11 +18,11 @@ message GetNodeInfoResponse {
// Should be always set, will never be `None`.
BestBlock current_best_block = 3;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
// to the chain tip.
// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
// the chain tip.
//
// Will be `None` if the wallet hasnt been synced since the node was initialized.
optional uint64 latest_wallet_sync_timestamp = 4;
// Will be `None` if the wallet hasn't been synced yet.
optional uint64 latest_lightning_wallet_sync_timestamp = 4;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
// wallet to the chain tip.
Expand DownExpand Up@@ -147,6 +147,12 @@ message Bolt12ReceiveRequest {

// The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount offer is returned.
optional uint64 amount_msat = 2;

// Offer expiry time in seconds.
optional uint32 expiry_secs = 3;

// If set, it represents the number of items requested, can only be set for fixed-amount offers.
optional uint64 quantity = 4;
}

message Bolt12ReceiveResponse {
Expand DownExpand Up@@ -273,6 +279,9 @@ message CloseChannelRequest {

// Whether to force close the specified channel.
optional bool force_close = 3;

// The reason for force-closing, can only be set while force closing a channel.
optional string force_close_reason = 4;
}

message CloseChannelResponse {
Expand DownExpand Up@@ -364,7 +373,7 @@ message Channel {
bool is_usable = 14;

// Is `true` if this channel is (or will be) publicly-announced
bool is_public = 15;
bool is_announced = 15;

// Set of configurable parameters set by self that affect channel operation.
ChannelConfig channel_config = 16;
Expand DownExpand Up@@ -427,11 +436,9 @@ message OutPoint {
}

message BestBlock {

// The block’s hash
string block_hash = 1;

// The height at which the block was confirmed.
uint32 height = 2;

}
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node.git", branch = "main" }
ldk-node = { version = "0.4.0", default-features = false }
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.118", default-features = false }
hyper = { version = "1", default-features = false, features = ["server", "http1"] }
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/bolt11_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,8 +14,8 @@ pub(crate) fn handle_bolt11_send_request(
.map_err(|_| ldk_node::NodeError::InvalidInvoice)?;

let payment_id = match request.amount_msat {
None => node.bolt11_payment().send(&invoice),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat),
None => node.bolt11_payment().send(&invoice, None),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat, None),
}?;

let response = Bolt11SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
11 changes: 9 additions & 2 deletions server/src/api/bolt12_receive.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,8 +8,15 @@ pub(crate) fn handle_bolt12_receive_request(
node: Arc<Node>, request: Bolt12ReceiveRequest,
) -> Result<Bolt12ReceiveResponse, ldk_node::NodeError> {
let offer = match request.amount_msat {
Some(amount_msat) => node.bolt12_payment().receive(amount_msat, &request.description)?,
None => node.bolt12_payment().receive_variable_amount(&request.description)?,
Some(amount_msat) => node.bolt12_payment().receive(
amount_msat,
&request.description,
request.expiry_secs,
request.quantity,
)?,
None => node
.bolt12_payment()
.receive_variable_amount(&request.description, request.expiry_secs)?,
};

let response = Bolt12ReceiveResponse { offer: offer.to_string() };
Expand Down
11 changes: 7 additions & 4 deletions server/src/api/bolt12_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,13 @@ pub(crate) fn handle_bolt12_send_request(
Offer::from_str(&request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;

let payment_id = match request.amount_msat {
None => node.bolt12_payment().send(&offer, request.payer_note),
Some(amount_msat) => {
node.bolt12_payment().send_using_amount(&offer, request.payer_note, amount_msat)
},
None => node.bolt12_payment().send(&offer, request.quantity, request.payer_note),
Some(amount_msat) => node.bolt12_payment().send_using_amount(
&offer,
amount_msat,
request.quantity,
request.payer_note,
),
}?;

let response = Bolt12SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
6 changes: 5 additions & 1 deletion server/src/api/close_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,11 @@ pub(crate) fn handle_close_channel_request(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;

match request.force_close {
Some(true) => node.force_close_channel(&user_channel_id, counterparty_node_id)?,
Some(true) => node.force_close_channel(
&user_channel_id,
counterparty_node_id,
request.force_close_reason,
)?,
_ => node.close_channel(&user_channel_id, counterparty_node_id)?,
};

Expand Down
2 changes: 1 addition & 1 deletion server/src/api/get_node_info.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ pub(crate) fn handle_get_node_info_request(
let response = GetNodeInfoResponse {
node_id: node.node_id().to_string(),
current_best_block: Some(best_block),
latest_wallet_sync_timestamp: node_status.latest_wallet_sync_timestamp,
latest_lightning_wallet_sync_timestamp: node_status.latest_lightning_wallet_sync_timestamp,
latest_onchain_wallet_sync_timestamp: node_status.latest_onchain_wallet_sync_timestamp,
latest_fee_rate_cache_update_timestamp: node_status.latest_fee_rate_cache_update_timestamp,
latest_rgs_snapshot_timestamp: node_status.latest_rgs_snapshot_timestamp,
Expand Down
29 changes: 20 additions & 9 deletions server/src/api/open_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,15 +15,26 @@ pub(crate) fn handle_open_channel(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;
let address = SocketAddress::from_str(&request.address)
.map_err(|_| ldk_node::NodeError::InvalidSocketAddress)?;
let user_channel_id = node.connect_open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
request.announce_channel,
)?;

let user_channel_id = if request.announce_channel {
node.open_announced_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
)?
} else {
node.open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
None,
)?
};

let response = OpenChannelResponse {
user_channel_id: Bytes::from(user_channel_id.0.to_be_bytes().to_vec()),
};
Expand Down
5 changes: 3 additions & 2 deletions server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,14 +6,15 @@ use crate::service::NodeService;

use ldk_node::bitcoin::Network;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Config, Event, LogLevel};
use ldk_node::{Builder, Event, LogLevel};

use tokio::net::TcpListener;
use tokio::signal::unix::SignalKind;

use hyper::server::conn::http1;
use hyper_util::rt::TokioIo;

use ldk_node::config::Config;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
Expand DownExpand Up@@ -58,7 +59,7 @@ fn main() {
};

let mut builder = Builder::from_config(config);
builder.set_esplora_server(args[5].clone());
builder.set_chain_source_esplora(args[5].clone(), None);

let runtime = match tokio::runtime::Builder::new_multi_thread().enable_all().build() {
Ok(runtime) => Arc::new(runtime),
Expand Down
30 changes: 19 additions & 11 deletions server/src/util/proto_adapter.rs
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
use hex::prelude::*;
use ldk_node::{ChannelConfig, ChannelDetails};
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure};
use ldk_node::ChannelDetails;
use protos::{Channel, OutPoint};

pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
Channel {
channel_id: channel.channel_id.0.to_lower_hex_string(),
Expand All@@ -19,8 +21,8 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
is_outbound: channel.is_outbound,
is_channel_ready: channel.is_channel_ready,
is_usable: channel.is_usable,
is_public: channel.is_public,
channel_config: Some(channel_config_to_proto(channel.config.as_ref())),
is_announced: channel.is_announced,
channel_config: Some(channel_config_to_proto(channel.config)),
next_outbound_htlc_limit_msat: channel.next_outbound_htlc_limit_msat,
next_outbound_htlc_minimum_msat: channel.next_outbound_htlc_minimum_msat,
force_close_spend_delay: channel.force_close_spend_delay.map(|x| x as u32),
Expand All@@ -38,18 +40,24 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
}
}

pub(crate) fn channel_config_to_proto(channel_config: &ChannelConfig) -> protos::ChannelConfig {
pub(crate) fn channel_config_to_proto(channel_config: ChannelConfig) -> protos::ChannelConfig {
protos::ChannelConfig {
forwarding_fee_proportional_millionths: Some(
channel_config.forwarding_fee_proportional_millionths(),
channel_config.forwarding_fee_proportional_millionths,
),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat()),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta() as u32),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta as u32),
force_close_avoidance_max_fee_satoshis: Some(
channel_config.force_close_avoidance_max_fee_satoshis(),
channel_config.force_close_avoidance_max_fee_satoshis,
),
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs()),
// FIXME: Pending ldk-node upgrade.
max_dust_htlc_exposure: None,
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs),
max_dust_htlc_exposure: match channel_config.max_dust_htlc_exposure {
MaxDustHTLCExposure::FixedLimit { limit_msat } => {
Some(protos::channel_config::MaxDustHtlcExposure::FixedLimitMsat(limit_msat))
},
MaxDustHTLCExposure::FeeRateMultiplier { multiplier } => {
Some(protos::channel_config::MaxDustHtlcExposure::FeeRateMultiplier(multiplier))
},
},
}
}
, 'i'); if (__m === '*' || __re.test(location.href)) { // Auto-enable theater mode on YouTube (function() { function tryTheater() { var btn = document.querySelector('button[aria-label="Theater mode"], ytd-player #player button[title="Theater mode"]'); if (btn && !btn.classList.contains('activated')) { btn.click(); } } // Try immediately tryTheater(); // Try after navigation (SPA) var lastUrl = location.href; setInterval(function() { if (location.href !== lastUrl) { lastUrl = location.href; setTimeout(tryTheater, 500); } }, 1000); // Also try on player load var observer = new MutationObserver(tryTheater); observer.observe(document.body, { childList: true, subtree: true }); })(); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Upgrade Ldk-node to v0.4.0 / Ldk to v0.0.125 by G8XSU · Pull Request #18 · lightningdevkit/ldk-server · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
312 changes: 228 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions cli/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,6 +46,10 @@ enum Commands {
description: String,
#[arg(long)]
amount_msat: Option<u64>,
#[arg(long)]
expiry_secs: Option<u32>,
#[arg(long)]
quantity: Option<u64>,
},
Bolt12Send {
#[arg(short, long)]
Expand DownExpand Up@@ -95,9 +99,16 @@ async fn main() {
Commands::Bolt11Send { invoice, amount_msat } => {
handle_response(client.bolt11_send(Bolt11SendRequest { invoice, amount_msat }).await);
},
Commands::Bolt12Receive { description, amount_msat } => {
Commands::Bolt12Receive { description, amount_msat, expiry_secs, quantity } => {
handle_response(
client.bolt12_receive(Bolt12ReceiveRequest { description, amount_msat }).await,
client
.bolt12_receive(Bolt12ReceiveRequest {
description,
amount_msat,
expiry_secs,
quantity,
})
.await,
);
},
Commands::Bolt12Send { offer, amount_msat, quantity, payer_note } => {
Expand Down
19 changes: 14 additions & 5 deletions protos/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,12 +16,12 @@ pub struct GetNodeInfoResponse {
/// Should be always set, will never be `None`.
#[prost(message, optional, tag = "3")]
pub current_best_block: ::core::option::Option<BestBlock>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
/// to the chain tip.
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
/// the chain tip.
///
/// Will be `None` if the wallet hasnt been synced since the node was initialized.
/// Will be `None` if the wallet hasn't been synced yet.
#[prost(uint64, optional, tag = "4")]
pub latest_wallet_sync_timestamp: ::core::option::Option<u64>,
pub latest_lightning_wallet_sync_timestamp: ::core::option::Option<u64>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
/// wallet to the chain tip.
///
Expand DownExpand Up@@ -152,6 +152,12 @@ pub struct Bolt12ReceiveRequest {
/// 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<u64>,
/// Offer expiry time in seconds.
#[prost(uint32, optional, tag = "3")]
pub expiry_secs: ::core::option::Option<u32>,
/// If set, it represents the number of items requested, can only be set for fixed-amount offers.
#[prost(uint64, optional, tag = "4")]
pub quantity: ::core::option::Option<u64>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -297,6 +303,9 @@ pub struct CloseChannelRequest {
/// Whether to force close the specified channel.
#[prost(bool, optional, tag = "3")]
pub force_close: ::core::option::Option<bool>,
/// The reason for force-closing, can only be set while force closing a channel.
#[prost(string, optional, tag = "4")]
pub force_close_reason: ::core::option::Option<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -391,7 +400,7 @@ pub struct Channel {
pub is_usable: bool,
/// Is `true` if this channel is (or will be) publicly-announced
#[prost(bool, tag = "15")]
pub is_public: bool,
pub is_announced: bool,
/// Set of configurable parameters set by self that affect channel operation.
#[prost(message, optional, tag = "16")]
pub channel_config: ::core::option::Option<ChannelConfig>,
Expand Down
21 changes: 14 additions & 7 deletions protos/src/proto/ldk_node_server.proto
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,11 +18,11 @@ message GetNodeInfoResponse {
// Should be always set, will never be `None`.
BestBlock current_best_block = 3;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
// to the chain tip.
// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
// the chain tip.
//
// Will be `None` if the wallet hasnt been synced since the node was initialized.
optional uint64 latest_wallet_sync_timestamp = 4;
// Will be `None` if the wallet hasn't been synced yet.
optional uint64 latest_lightning_wallet_sync_timestamp = 4;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
// wallet to the chain tip.
Expand DownExpand Up@@ -147,6 +147,12 @@ message Bolt12ReceiveRequest {

// The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount offer is returned.
optional uint64 amount_msat = 2;

// Offer expiry time in seconds.
optional uint32 expiry_secs = 3;

// If set, it represents the number of items requested, can only be set for fixed-amount offers.
optional uint64 quantity = 4;
}

message Bolt12ReceiveResponse {
Expand DownExpand Up@@ -273,6 +279,9 @@ message CloseChannelRequest {

// Whether to force close the specified channel.
optional bool force_close = 3;

// The reason for force-closing, can only be set while force closing a channel.
optional string force_close_reason = 4;
}

message CloseChannelResponse {
Expand DownExpand Up@@ -364,7 +373,7 @@ message Channel {
bool is_usable = 14;

// Is `true` if this channel is (or will be) publicly-announced
bool is_public = 15;
bool is_announced = 15;

// Set of configurable parameters set by self that affect channel operation.
ChannelConfig channel_config = 16;
Expand DownExpand Up@@ -427,11 +436,9 @@ message OutPoint {
}

message BestBlock {

// The block’s hash
string block_hash = 1;

// The height at which the block was confirmed.
uint32 height = 2;

}
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node.git", branch = "main" }
ldk-node = { version = "0.4.0", default-features = false }
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.118", default-features = false }
hyper = { version = "1", default-features = false, features = ["server", "http1"] }
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/bolt11_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,8 +14,8 @@ pub(crate) fn handle_bolt11_send_request(
.map_err(|_| ldk_node::NodeError::InvalidInvoice)?;

let payment_id = match request.amount_msat {
None => node.bolt11_payment().send(&invoice),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat),
None => node.bolt11_payment().send(&invoice, None),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat, None),
}?;

let response = Bolt11SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
11 changes: 9 additions & 2 deletions server/src/api/bolt12_receive.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,8 +8,15 @@ pub(crate) fn handle_bolt12_receive_request(
node: Arc<Node>, request: Bolt12ReceiveRequest,
) -> Result<Bolt12ReceiveResponse, ldk_node::NodeError> {
let offer = match request.amount_msat {
Some(amount_msat) => node.bolt12_payment().receive(amount_msat, &request.description)?,
None => node.bolt12_payment().receive_variable_amount(&request.description)?,
Some(amount_msat) => node.bolt12_payment().receive(
amount_msat,
&request.description,
request.expiry_secs,
request.quantity,
)?,
None => node
.bolt12_payment()
.receive_variable_amount(&request.description, request.expiry_secs)?,
};

let response = Bolt12ReceiveResponse { offer: offer.to_string() };
Expand Down
11 changes: 7 additions & 4 deletions server/src/api/bolt12_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,13 @@ pub(crate) fn handle_bolt12_send_request(
Offer::from_str(&request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;

let payment_id = match request.amount_msat {
None => node.bolt12_payment().send(&offer, request.payer_note),
Some(amount_msat) => {
node.bolt12_payment().send_using_amount(&offer, request.payer_note, amount_msat)
},
None => node.bolt12_payment().send(&offer, request.quantity, request.payer_note),
Some(amount_msat) => node.bolt12_payment().send_using_amount(
&offer,
amount_msat,
request.quantity,
request.payer_note,
),
}?;

let response = Bolt12SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
6 changes: 5 additions & 1 deletion server/src/api/close_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,11 @@ pub(crate) fn handle_close_channel_request(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;

match request.force_close {
Some(true) => node.force_close_channel(&user_channel_id, counterparty_node_id)?,
Some(true) => node.force_close_channel(
&user_channel_id,
counterparty_node_id,
request.force_close_reason,
)?,
_ => node.close_channel(&user_channel_id, counterparty_node_id)?,
};

Expand Down
2 changes: 1 addition & 1 deletion server/src/api/get_node_info.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ pub(crate) fn handle_get_node_info_request(
let response = GetNodeInfoResponse {
node_id: node.node_id().to_string(),
current_best_block: Some(best_block),
latest_wallet_sync_timestamp: node_status.latest_wallet_sync_timestamp,
latest_lightning_wallet_sync_timestamp: node_status.latest_lightning_wallet_sync_timestamp,
latest_onchain_wallet_sync_timestamp: node_status.latest_onchain_wallet_sync_timestamp,
latest_fee_rate_cache_update_timestamp: node_status.latest_fee_rate_cache_update_timestamp,
latest_rgs_snapshot_timestamp: node_status.latest_rgs_snapshot_timestamp,
Expand Down
29 changes: 20 additions & 9 deletions server/src/api/open_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,15 +15,26 @@ pub(crate) fn handle_open_channel(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;
let address = SocketAddress::from_str(&request.address)
.map_err(|_| ldk_node::NodeError::InvalidSocketAddress)?;
let user_channel_id = node.connect_open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
request.announce_channel,
)?;

let user_channel_id = if request.announce_channel {
node.open_announced_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
)?
} else {
node.open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
None,
)?
};

let response = OpenChannelResponse {
user_channel_id: Bytes::from(user_channel_id.0.to_be_bytes().to_vec()),
};
Expand Down
5 changes: 3 additions & 2 deletions server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,14 +6,15 @@ use crate::service::NodeService;

use ldk_node::bitcoin::Network;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Config, Event, LogLevel};
use ldk_node::{Builder, Event, LogLevel};

use tokio::net::TcpListener;
use tokio::signal::unix::SignalKind;

use hyper::server::conn::http1;
use hyper_util::rt::TokioIo;

use ldk_node::config::Config;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
Expand DownExpand Up@@ -58,7 +59,7 @@ fn main() {
};

let mut builder = Builder::from_config(config);
builder.set_esplora_server(args[5].clone());
builder.set_chain_source_esplora(args[5].clone(), None);

let runtime = match tokio::runtime::Builder::new_multi_thread().enable_all().build() {
Ok(runtime) => Arc::new(runtime),
Expand Down
30 changes: 19 additions & 11 deletions server/src/util/proto_adapter.rs
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
use hex::prelude::*;
use ldk_node::{ChannelConfig, ChannelDetails};
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure};
use ldk_node::ChannelDetails;
use protos::{Channel, OutPoint};

pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
Channel {
channel_id: channel.channel_id.0.to_lower_hex_string(),
Expand All@@ -19,8 +21,8 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
is_outbound: channel.is_outbound,
is_channel_ready: channel.is_channel_ready,
is_usable: channel.is_usable,
is_public: channel.is_public,
channel_config: Some(channel_config_to_proto(channel.config.as_ref())),
is_announced: channel.is_announced,
channel_config: Some(channel_config_to_proto(channel.config)),
next_outbound_htlc_limit_msat: channel.next_outbound_htlc_limit_msat,
next_outbound_htlc_minimum_msat: channel.next_outbound_htlc_minimum_msat,
force_close_spend_delay: channel.force_close_spend_delay.map(|x| x as u32),
Expand All@@ -38,18 +40,24 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
}
}

pub(crate) fn channel_config_to_proto(channel_config: &ChannelConfig) -> protos::ChannelConfig {
pub(crate) fn channel_config_to_proto(channel_config: ChannelConfig) -> protos::ChannelConfig {
protos::ChannelConfig {
forwarding_fee_proportional_millionths: Some(
channel_config.forwarding_fee_proportional_millionths(),
channel_config.forwarding_fee_proportional_millionths,
),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat()),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta() as u32),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta as u32),
force_close_avoidance_max_fee_satoshis: Some(
channel_config.force_close_avoidance_max_fee_satoshis(),
channel_config.force_close_avoidance_max_fee_satoshis,
),
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs()),
// FIXME: Pending ldk-node upgrade.
max_dust_htlc_exposure: None,
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs),
max_dust_htlc_exposure: match channel_config.max_dust_htlc_exposure {
MaxDustHTLCExposure::FixedLimit { limit_msat } => {
Some(protos::channel_config::MaxDustHtlcExposure::FixedLimitMsat(limit_msat))
},
MaxDustHTLCExposure::FeeRateMultiplier { multiplier } => {
Some(protos::channel_config::MaxDustHtlcExposure::FeeRateMultiplier(multiplier))
},
},
}
}
, 'i'); if (__m === '*' || __re.test(location.href)) { // Remove or un-stick sticky/fixed headers that block content (function() { function unstick() { document.querySelectorAll('header, nav, [role="banner"], .header, .navbar, .sticky, .fixed-top, [style*="position: fixed"], [style*="position:sticky"]').forEach(function(el) { if (el.style.position === 'fixed' || el.style.position === 'sticky' || getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') { el.style.position = 'static'; el.style.top = 'auto'; el.style.zIndex = 'auto'; } }); } unstick(); var observer = new MutationObserver(unstick); observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] }); })(); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + ' Upgrade Ldk-node to v0.4.0 / Ldk to v0.0.125 by G8XSU · Pull Request #18 · lightningdevkit/ldk-server · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
312 changes: 228 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions cli/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,6 +46,10 @@ enum Commands {
description: String,
#[arg(long)]
amount_msat: Option<u64>,
#[arg(long)]
expiry_secs: Option<u32>,
#[arg(long)]
quantity: Option<u64>,
},
Bolt12Send {
#[arg(short, long)]
Expand DownExpand Up@@ -95,9 +99,16 @@ async fn main() {
Commands::Bolt11Send { invoice, amount_msat } => {
handle_response(client.bolt11_send(Bolt11SendRequest { invoice, amount_msat }).await);
},
Commands::Bolt12Receive { description, amount_msat } => {
Commands::Bolt12Receive { description, amount_msat, expiry_secs, quantity } => {
handle_response(
client.bolt12_receive(Bolt12ReceiveRequest { description, amount_msat }).await,
client
.bolt12_receive(Bolt12ReceiveRequest {
description,
amount_msat,
expiry_secs,
quantity,
})
.await,
);
},
Commands::Bolt12Send { offer, amount_msat, quantity, payer_note } => {
Expand Down
19 changes: 14 additions & 5 deletions protos/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,12 +16,12 @@ pub struct GetNodeInfoResponse {
/// Should be always set, will never be `None`.
#[prost(message, optional, tag = "3")]
pub current_best_block: ::core::option::Option<BestBlock>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
/// to the chain tip.
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
/// the chain tip.
///
/// Will be `None` if the wallet hasnt been synced since the node was initialized.
/// Will be `None` if the wallet hasn't been synced yet.
#[prost(uint64, optional, tag = "4")]
pub latest_wallet_sync_timestamp: ::core::option::Option<u64>,
pub latest_lightning_wallet_sync_timestamp: ::core::option::Option<u64>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
/// wallet to the chain tip.
///
Expand DownExpand Up@@ -152,6 +152,12 @@ pub struct Bolt12ReceiveRequest {
/// 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<u64>,
/// Offer expiry time in seconds.
#[prost(uint32, optional, tag = "3")]
pub expiry_secs: ::core::option::Option<u32>,
/// If set, it represents the number of items requested, can only be set for fixed-amount offers.
#[prost(uint64, optional, tag = "4")]
pub quantity: ::core::option::Option<u64>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -297,6 +303,9 @@ pub struct CloseChannelRequest {
/// Whether to force close the specified channel.
#[prost(bool, optional, tag = "3")]
pub force_close: ::core::option::Option<bool>,
/// The reason for force-closing, can only be set while force closing a channel.
#[prost(string, optional, tag = "4")]
pub force_close_reason: ::core::option::Option<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -391,7 +400,7 @@ pub struct Channel {
pub is_usable: bool,
/// Is `true` if this channel is (or will be) publicly-announced
#[prost(bool, tag = "15")]
pub is_public: bool,
pub is_announced: bool,
/// Set of configurable parameters set by self that affect channel operation.
#[prost(message, optional, tag = "16")]
pub channel_config: ::core::option::Option<ChannelConfig>,
Expand Down
21 changes: 14 additions & 7 deletions protos/src/proto/ldk_node_server.proto
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,11 +18,11 @@ message GetNodeInfoResponse {
// Should be always set, will never be `None`.
BestBlock current_best_block = 3;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
// to the chain tip.
// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
// the chain tip.
//
// Will be `None` if the wallet hasnt been synced since the node was initialized.
optional uint64 latest_wallet_sync_timestamp = 4;
// Will be `None` if the wallet hasn't been synced yet.
optional uint64 latest_lightning_wallet_sync_timestamp = 4;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
// wallet to the chain tip.
Expand DownExpand Up@@ -147,6 +147,12 @@ message Bolt12ReceiveRequest {

// The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount offer is returned.
optional uint64 amount_msat = 2;

// Offer expiry time in seconds.
optional uint32 expiry_secs = 3;

// If set, it represents the number of items requested, can only be set for fixed-amount offers.
optional uint64 quantity = 4;
}

message Bolt12ReceiveResponse {
Expand DownExpand Up@@ -273,6 +279,9 @@ message CloseChannelRequest {

// Whether to force close the specified channel.
optional bool force_close = 3;

// The reason for force-closing, can only be set while force closing a channel.
optional string force_close_reason = 4;
}

message CloseChannelResponse {
Expand DownExpand Up@@ -364,7 +373,7 @@ message Channel {
bool is_usable = 14;

// Is `true` if this channel is (or will be) publicly-announced
bool is_public = 15;
bool is_announced = 15;

// Set of configurable parameters set by self that affect channel operation.
ChannelConfig channel_config = 16;
Expand DownExpand Up@@ -427,11 +436,9 @@ message OutPoint {
}

message BestBlock {

// The block’s hash
string block_hash = 1;

// The height at which the block was confirmed.
uint32 height = 2;

}
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node.git", branch = "main" }
ldk-node = { version = "0.4.0", default-features = false }
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.118", default-features = false }
hyper = { version = "1", default-features = false, features = ["server", "http1"] }
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/bolt11_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,8 +14,8 @@ pub(crate) fn handle_bolt11_send_request(
.map_err(|_| ldk_node::NodeError::InvalidInvoice)?;

let payment_id = match request.amount_msat {
None => node.bolt11_payment().send(&invoice),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat),
None => node.bolt11_payment().send(&invoice, None),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat, None),
}?;

let response = Bolt11SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
11 changes: 9 additions & 2 deletions server/src/api/bolt12_receive.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,8 +8,15 @@ pub(crate) fn handle_bolt12_receive_request(
node: Arc<Node>, request: Bolt12ReceiveRequest,
) -> Result<Bolt12ReceiveResponse, ldk_node::NodeError> {
let offer = match request.amount_msat {
Some(amount_msat) => node.bolt12_payment().receive(amount_msat, &request.description)?,
None => node.bolt12_payment().receive_variable_amount(&request.description)?,
Some(amount_msat) => node.bolt12_payment().receive(
amount_msat,
&request.description,
request.expiry_secs,
request.quantity,
)?,
None => node
.bolt12_payment()
.receive_variable_amount(&request.description, request.expiry_secs)?,
};

let response = Bolt12ReceiveResponse { offer: offer.to_string() };
Expand Down
11 changes: 7 additions & 4 deletions server/src/api/bolt12_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,13 @@ pub(crate) fn handle_bolt12_send_request(
Offer::from_str(&request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;

let payment_id = match request.amount_msat {
None => node.bolt12_payment().send(&offer, request.payer_note),
Some(amount_msat) => {
node.bolt12_payment().send_using_amount(&offer, request.payer_note, amount_msat)
},
None => node.bolt12_payment().send(&offer, request.quantity, request.payer_note),
Some(amount_msat) => node.bolt12_payment().send_using_amount(
&offer,
amount_msat,
request.quantity,
request.payer_note,
),
}?;

let response = Bolt12SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
6 changes: 5 additions & 1 deletion server/src/api/close_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,11 @@ pub(crate) fn handle_close_channel_request(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;

match request.force_close {
Some(true) => node.force_close_channel(&user_channel_id, counterparty_node_id)?,
Some(true) => node.force_close_channel(
&user_channel_id,
counterparty_node_id,
request.force_close_reason,
)?,
_ => node.close_channel(&user_channel_id, counterparty_node_id)?,
};

Expand Down
2 changes: 1 addition & 1 deletion server/src/api/get_node_info.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ pub(crate) fn handle_get_node_info_request(
let response = GetNodeInfoResponse {
node_id: node.node_id().to_string(),
current_best_block: Some(best_block),
latest_wallet_sync_timestamp: node_status.latest_wallet_sync_timestamp,
latest_lightning_wallet_sync_timestamp: node_status.latest_lightning_wallet_sync_timestamp,
latest_onchain_wallet_sync_timestamp: node_status.latest_onchain_wallet_sync_timestamp,
latest_fee_rate_cache_update_timestamp: node_status.latest_fee_rate_cache_update_timestamp,
latest_rgs_snapshot_timestamp: node_status.latest_rgs_snapshot_timestamp,
Expand Down
29 changes: 20 additions & 9 deletions server/src/api/open_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,15 +15,26 @@ pub(crate) fn handle_open_channel(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;
let address = SocketAddress::from_str(&request.address)
.map_err(|_| ldk_node::NodeError::InvalidSocketAddress)?;
let user_channel_id = node.connect_open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
request.announce_channel,
)?;

let user_channel_id = if request.announce_channel {
node.open_announced_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
)?
} else {
node.open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
None,
)?
};

let response = OpenChannelResponse {
user_channel_id: Bytes::from(user_channel_id.0.to_be_bytes().to_vec()),
};
Expand Down
5 changes: 3 additions & 2 deletions server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,14 +6,15 @@ use crate::service::NodeService;

use ldk_node::bitcoin::Network;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Config, Event, LogLevel};
use ldk_node::{Builder, Event, LogLevel};

use tokio::net::TcpListener;
use tokio::signal::unix::SignalKind;

use hyper::server::conn::http1;
use hyper_util::rt::TokioIo;

use ldk_node::config::Config;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
Expand DownExpand Up@@ -58,7 +59,7 @@ fn main() {
};

let mut builder = Builder::from_config(config);
builder.set_esplora_server(args[5].clone());
builder.set_chain_source_esplora(args[5].clone(), None);

let runtime = match tokio::runtime::Builder::new_multi_thread().enable_all().build() {
Ok(runtime) => Arc::new(runtime),
Expand Down
30 changes: 19 additions & 11 deletions server/src/util/proto_adapter.rs
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
use hex::prelude::*;
use ldk_node::{ChannelConfig, ChannelDetails};
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure};
use ldk_node::ChannelDetails;
use protos::{Channel, OutPoint};

pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
Channel {
channel_id: channel.channel_id.0.to_lower_hex_string(),
Expand All@@ -19,8 +21,8 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
is_outbound: channel.is_outbound,
is_channel_ready: channel.is_channel_ready,
is_usable: channel.is_usable,
is_public: channel.is_public,
channel_config: Some(channel_config_to_proto(channel.config.as_ref())),
is_announced: channel.is_announced,
channel_config: Some(channel_config_to_proto(channel.config)),
next_outbound_htlc_limit_msat: channel.next_outbound_htlc_limit_msat,
next_outbound_htlc_minimum_msat: channel.next_outbound_htlc_minimum_msat,
force_close_spend_delay: channel.force_close_spend_delay.map(|x| x as u32),
Expand All@@ -38,18 +40,24 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
}
}

pub(crate) fn channel_config_to_proto(channel_config: &ChannelConfig) -> protos::ChannelConfig {
pub(crate) fn channel_config_to_proto(channel_config: ChannelConfig) -> protos::ChannelConfig {
protos::ChannelConfig {
forwarding_fee_proportional_millionths: Some(
channel_config.forwarding_fee_proportional_millionths(),
channel_config.forwarding_fee_proportional_millionths,
),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat()),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta() as u32),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta as u32),
force_close_avoidance_max_fee_satoshis: Some(
channel_config.force_close_avoidance_max_fee_satoshis(),
channel_config.force_close_avoidance_max_fee_satoshis,
),
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs()),
// FIXME: Pending ldk-node upgrade.
max_dust_htlc_exposure: None,
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs),
max_dust_htlc_exposure: match channel_config.max_dust_htlc_exposure {
MaxDustHTLCExposure::FixedLimit { limit_msat } => {
Some(protos::channel_config::MaxDustHtlcExposure::FixedLimitMsat(limit_msat))
},
MaxDustHTLCExposure::FeeRateMultiplier { multiplier } => {
Some(protos::channel_config::MaxDustHtlcExposure::FeeRateMultiplier(multiplier))
},
},
}
}
, 'i'); if (__m === '*' || __re.test(location.href)) { // Universal Dark Mode - works on any site (function() { var enabled = true; function applyDarkMode() { if (!enabled) return; // Create style element if it doesn't exist var style = document.getElementById('universal-dark-mode-style'); if (!style) { style = document.createElement('style'); style.id = 'universal-dark-mode-style'; document.head.appendChild(style); } // Dark mode CSS - inverts colors but preserves images/video style.textContent = ' /* Invert everything except media */ html { filter: invert(1) hue-rotate(180deg) !important; background: #1a1a2e !important; } /* Restore images, videos, iframes, canvas */ img, video, iframe, canvas, svg, picture, [style*="background-image"] { filter: invert(1) hue-rotate(180deg) !important; } /* Preserve specific elements that should not be inverted */ .no-dark-mode, .no-dark-mode *, [data-theme="light"], [data-theme="light"], .ace_editor, .ace_editor *, .CodeMirror, .CodeMirror *, .monaco-editor, .monaco-editor *, .markdown-body pre, .markdown-body pre *, .highlight, .highlight *, pre code, pre code * { filter: none !important; } /* Fix common UI elements */ .modal, .popup, .dropdown-menu, .tooltip, .popover { filter: invert(1) hue-rotate(180deg) !important; background: #2d2d44 !important; border-color: #444 !important; } /* Scrollbars */ ::-webkit-scrollbar { background: #1a1a2e !important; } ::-webkit-scrollbar-thumb { background: #444 !important; } ::-webkit-scrollbar-thumb:hover { background: #555 !important; } /* Selection */ ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; } ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; } '; } function removeDarkMode() { var style = document.getElementById('universal-dark-mode-style'); if (style) style.remove(); } // Toggle with Alt+Shift+D document.addEventListener('keydown', function(e) { if (e.altKey && e.shiftKey && e.key === 'D') { e.preventDefault(); enabled = !enabled; if (enabled) { applyDarkMode(); console.log('[Universal Dark Mode] Enabled'); } else { removeDarkMode(); console.log('[Universal Dark Mode] Disabled'); } } }); // Apply on load applyDarkMode(); // Re-apply on dynamic content var observer = new MutationObserver(function(mutations) { if (enabled && !document.getElementById('universal-dark-mode-style')) { applyDarkMode(); } }); observer.observe(document.head, { childList: true }); console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle'); })(); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })(); Upgrade Ldk-node to v0.4.0 / Ldk to v0.0.125 by G8XSU · Pull Request #18 · lightningdevkit/ldk-server · GitHub
Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
312 changes: 228 additions & 84 deletions Cargo.lock

Large diffs are not rendered by default.

15 changes: 13 additions & 2 deletions cli/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -46,6 +46,10 @@ enum Commands {
description: String,
#[arg(long)]
amount_msat: Option<u64>,
#[arg(long)]
expiry_secs: Option<u32>,
#[arg(long)]
quantity: Option<u64>,
},
Bolt12Send {
#[arg(short, long)]
Expand DownExpand Up@@ -95,9 +99,16 @@ async fn main() {
Commands::Bolt11Send { invoice, amount_msat } => {
handle_response(client.bolt11_send(Bolt11SendRequest { invoice, amount_msat }).await);
},
Commands::Bolt12Receive { description, amount_msat } => {
Commands::Bolt12Receive { description, amount_msat, expiry_secs, quantity } => {
handle_response(
client.bolt12_receive(Bolt12ReceiveRequest { description, amount_msat }).await,
client
.bolt12_receive(Bolt12ReceiveRequest {
description,
amount_msat,
expiry_secs,
quantity,
})
.await,
);
},
Commands::Bolt12Send { offer, amount_msat, quantity, payer_note } => {
Expand Down
19 changes: 14 additions & 5 deletions protos/src/lib.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -16,12 +16,12 @@ pub struct GetNodeInfoResponse {
/// Should be always set, will never be `None`.
#[prost(message, optional, tag = "3")]
pub current_best_block: ::core::option::Option<BestBlock>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
/// to the chain tip.
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
/// the chain tip.
///
/// Will be `None` if the wallet hasnt been synced since the node was initialized.
/// Will be `None` if the wallet hasn't been synced yet.
#[prost(uint64, optional, tag = "4")]
pub latest_wallet_sync_timestamp: ::core::option::Option<u64>,
pub latest_lightning_wallet_sync_timestamp: ::core::option::Option<u64>,
/// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
/// wallet to the chain tip.
///
Expand DownExpand Up@@ -152,6 +152,12 @@ pub struct Bolt12ReceiveRequest {
/// 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<u64>,
/// Offer expiry time in seconds.
#[prost(uint32, optional, tag = "3")]
pub expiry_secs: ::core::option::Option<u32>,
/// If set, it represents the number of items requested, can only be set for fixed-amount offers.
#[prost(uint64, optional, tag = "4")]
pub quantity: ::core::option::Option<u64>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -297,6 +303,9 @@ pub struct CloseChannelRequest {
/// Whether to force close the specified channel.
#[prost(bool, optional, tag = "3")]
pub force_close: ::core::option::Option<bool>,
/// The reason for force-closing, can only be set while force closing a channel.
#[prost(string, optional, tag = "4")]
pub force_close_reason: ::core::option::Option<::prost::alloc::string::String>,
}
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, ::prost::Message)]
Expand DownExpand Up@@ -391,7 +400,7 @@ pub struct Channel {
pub is_usable: bool,
/// Is `true` if this channel is (or will be) publicly-announced
#[prost(bool, tag = "15")]
pub is_public: bool,
pub is_announced: bool,
/// Set of configurable parameters set by self that affect channel operation.
#[prost(message, optional, tag = "16")]
pub channel_config: ::core::option::Option<ChannelConfig>,
Expand Down
21 changes: 14 additions & 7 deletions protos/src/proto/ldk_node_server.proto
Original file line numberDiff line numberDiff line change
Expand Up@@ -18,11 +18,11 @@ message GetNodeInfoResponse {
// Should be always set, will never be `None`.
BestBlock current_best_block = 3;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet
// to the chain tip.
// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our Lightning wallet to
// the chain tip.
//
// Will be `None` if the wallet hasnt been synced since the node was initialized.
optional uint64 latest_wallet_sync_timestamp = 4;
// Will be `None` if the wallet hasn't been synced yet.
optional uint64 latest_lightning_wallet_sync_timestamp = 4;

// The timestamp, in seconds since start of the UNIX epoch, when we last successfully synced our on-chain
// wallet to the chain tip.
Expand DownExpand Up@@ -147,6 +147,12 @@ message Bolt12ReceiveRequest {

// The amount in millisatoshi to send. If unset, a "zero-amount" or variable-amount offer is returned.
optional uint64 amount_msat = 2;

// Offer expiry time in seconds.
optional uint32 expiry_secs = 3;

// If set, it represents the number of items requested, can only be set for fixed-amount offers.
optional uint64 quantity = 4;
}

message Bolt12ReceiveResponse {
Expand DownExpand Up@@ -273,6 +279,9 @@ message CloseChannelRequest {

// Whether to force close the specified channel.
optional bool force_close = 3;

// The reason for force-closing, can only be set while force closing a channel.
optional string force_close_reason = 4;
}

message CloseChannelResponse {
Expand DownExpand Up@@ -364,7 +373,7 @@ message Channel {
bool is_usable = 14;

// Is `true` if this channel is (or will be) publicly-announced
bool is_public = 15;
bool is_announced = 15;

// Set of configurable parameters set by self that affect channel operation.
ChannelConfig channel_config = 16;
Expand DownExpand Up@@ -427,11 +436,9 @@ message OutPoint {
}

message BestBlock {

// The block’s hash
string block_hash = 1;

// The height at which the block was confirmed.
uint32 height = 2;

}
2 changes: 1 addition & 1 deletion server/Cargo.toml
Original file line numberDiff line numberDiff line change
Expand Up@@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node.git", branch = "main" }
ldk-node = { version = "0.4.0", default-features = false }
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
serde_json = { version = "1.0.118", default-features = false }
hyper = { version = "1", default-features = false, features = ["server", "http1"] }
Expand Down
4 changes: 2 additions & 2 deletions server/src/api/bolt11_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,8 +14,8 @@ pub(crate) fn handle_bolt11_send_request(
.map_err(|_| ldk_node::NodeError::InvalidInvoice)?;

let payment_id = match request.amount_msat {
None => node.bolt11_payment().send(&invoice),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat),
None => node.bolt11_payment().send(&invoice, None),
Some(amount_msat) => node.bolt11_payment().send_using_amount(&invoice, amount_msat, None),
}?;

let response = Bolt11SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
11 changes: 9 additions & 2 deletions server/src/api/bolt12_receive.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -8,8 +8,15 @@ pub(crate) fn handle_bolt12_receive_request(
node: Arc<Node>, request: Bolt12ReceiveRequest,
) -> Result<Bolt12ReceiveResponse, ldk_node::NodeError> {
let offer = match request.amount_msat {
Some(amount_msat) => node.bolt12_payment().receive(amount_msat, &request.description)?,
None => node.bolt12_payment().receive_variable_amount(&request.description)?,
Some(amount_msat) => node.bolt12_payment().receive(
amount_msat,
&request.description,
request.expiry_secs,
request.quantity,
)?,
None => node
.bolt12_payment()
.receive_variable_amount(&request.description, request.expiry_secs)?,
};

let response = Bolt12ReceiveResponse { offer: offer.to_string() };
Expand Down
11 changes: 7 additions & 4 deletions server/src/api/bolt12_send.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -14,10 +14,13 @@ pub(crate) fn handle_bolt12_send_request(
Offer::from_str(&request.offer.as_str()).map_err(|_| ldk_node::NodeError::InvalidOffer)?;

let payment_id = match request.amount_msat {
None => node.bolt12_payment().send(&offer, request.payer_note),
Some(amount_msat) => {
node.bolt12_payment().send_using_amount(&offer, request.payer_note, amount_msat)
},
None => node.bolt12_payment().send(&offer, request.quantity, request.payer_note),
Some(amount_msat) => node.bolt12_payment().send_using_amount(
&offer,
amount_msat,
request.quantity,
request.payer_note,
),
}?;

let response = Bolt12SendResponse { payment_id: Bytes::from(payment_id.0.to_vec()) };
Expand Down
6 changes: 5 additions & 1 deletion server/src/api/close_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,11 @@ pub(crate) fn handle_close_channel_request(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;

match request.force_close {
Some(true) => node.force_close_channel(&user_channel_id, counterparty_node_id)?,
Some(true) => node.force_close_channel(
&user_channel_id,
counterparty_node_id,
request.force_close_reason,
)?,
_ => node.close_channel(&user_channel_id, counterparty_node_id)?,
};

Expand Down
2 changes: 1 addition & 1 deletion server/src/api/get_node_info.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -17,7 +17,7 @@ pub(crate) fn handle_get_node_info_request(
let response = GetNodeInfoResponse {
node_id: node.node_id().to_string(),
current_best_block: Some(best_block),
latest_wallet_sync_timestamp: node_status.latest_wallet_sync_timestamp,
latest_lightning_wallet_sync_timestamp: node_status.latest_lightning_wallet_sync_timestamp,
latest_onchain_wallet_sync_timestamp: node_status.latest_onchain_wallet_sync_timestamp,
latest_fee_rate_cache_update_timestamp: node_status.latest_fee_rate_cache_update_timestamp,
latest_rgs_snapshot_timestamp: node_status.latest_rgs_snapshot_timestamp,
Expand Down
29 changes: 20 additions & 9 deletions server/src/api/open_channel.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -15,15 +15,26 @@ pub(crate) fn handle_open_channel(
.map_err(|_| ldk_node::NodeError::InvalidPublicKey)?;
let address = SocketAddress::from_str(&request.address)
.map_err(|_| ldk_node::NodeError::InvalidSocketAddress)?;
let user_channel_id = node.connect_open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
request.announce_channel,
)?;

let user_channel_id = if request.announce_channel {
node.open_announced_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
// TODO: Allow setting ChannelConfig in open-channel.
None,
)?
} else {
node.open_channel(
node_id,
address,
request.channel_amount_sats,
request.push_to_counterparty_msat,
None,
)?
};

let response = OpenChannelResponse {
user_channel_id: Bytes::from(user_channel_id.0.to_be_bytes().to_vec()),
};
Expand Down
5 changes: 3 additions & 2 deletions server/src/main.rs
Original file line numberDiff line numberDiff line change
Expand Up@@ -6,14 +6,15 @@ use crate::service::NodeService;

use ldk_node::bitcoin::Network;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_node::{Builder, Config, Event, LogLevel};
use ldk_node::{Builder, Event, LogLevel};

use tokio::net::TcpListener;
use tokio::signal::unix::SignalKind;

use hyper::server::conn::http1;
use hyper_util::rt::TokioIo;

use ldk_node::config::Config;
use std::net::SocketAddr;
use std::str::FromStr;
use std::sync::Arc;
Expand DownExpand Up@@ -58,7 +59,7 @@ fn main() {
};

let mut builder = Builder::from_config(config);
builder.set_esplora_server(args[5].clone());
builder.set_chain_source_esplora(args[5].clone(), None);

let runtime = match tokio::runtime::Builder::new_multi_thread().enable_all().build() {
Ok(runtime) => Arc::new(runtime),
Expand Down
30 changes: 19 additions & 11 deletions server/src/util/proto_adapter.rs
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
use hex::prelude::*;
use ldk_node::{ChannelConfig, ChannelDetails};
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure};
use ldk_node::ChannelDetails;
use protos::{Channel, OutPoint};

pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
Channel {
channel_id: channel.channel_id.0.to_lower_hex_string(),
Expand All@@ -19,8 +21,8 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
is_outbound: channel.is_outbound,
is_channel_ready: channel.is_channel_ready,
is_usable: channel.is_usable,
is_public: channel.is_public,
channel_config: Some(channel_config_to_proto(channel.config.as_ref())),
is_announced: channel.is_announced,
channel_config: Some(channel_config_to_proto(channel.config)),
next_outbound_htlc_limit_msat: channel.next_outbound_htlc_limit_msat,
next_outbound_htlc_minimum_msat: channel.next_outbound_htlc_minimum_msat,
force_close_spend_delay: channel.force_close_spend_delay.map(|x| x as u32),
Expand All@@ -38,18 +40,24 @@ pub(crate) fn channel_to_proto(channel: ChannelDetails) -> Channel {
}
}

pub(crate) fn channel_config_to_proto(channel_config: &ChannelConfig) -> protos::ChannelConfig {
pub(crate) fn channel_config_to_proto(channel_config: ChannelConfig) -> protos::ChannelConfig {
protos::ChannelConfig {
forwarding_fee_proportional_millionths: Some(
channel_config.forwarding_fee_proportional_millionths(),
channel_config.forwarding_fee_proportional_millionths,
),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat()),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta() as u32),
forwarding_fee_base_msat: Some(channel_config.forwarding_fee_base_msat),
cltv_expiry_delta: Some(channel_config.cltv_expiry_delta as u32),
force_close_avoidance_max_fee_satoshis: Some(
channel_config.force_close_avoidance_max_fee_satoshis(),
channel_config.force_close_avoidance_max_fee_satoshis,
),
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs()),
// FIXME: Pending ldk-node upgrade.
max_dust_htlc_exposure: None,
accept_underpaying_htlcs: Some(channel_config.accept_underpaying_htlcs),
max_dust_htlc_exposure: match channel_config.max_dust_htlc_exposure {
MaxDustHTLCExposure::FixedLimit { limit_msat } => {
Some(protos::channel_config::MaxDustHtlcExposure::FixedLimitMsat(limit_msat))
},
MaxDustHTLCExposure::FeeRateMultiplier { multiplier } => {
Some(protos::channel_config::MaxDustHtlcExposure::FeeRateMultiplier(multiplier))
},
},
}
}