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
33 changes: 33 additions & 0 deletions .github/workflows/cron-weekly-rustfmt.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Nightly rustfmt

permissions:
contents: write
pull-requests: write

on:
schedule:
- cron: "0 0 * * 0" # runs weekly on Sunday at 00:00
workflow_dispatch: # allows manual triggering
jobs:
format:
name: Nightly rustfmt
runs-on: ubuntu-24.04
steps:
- uses: actions/checkout@v5
- uses: dtolnay/rust-toolchain@nightly
with:
components: rustfmt
- name: Run Nightly rustfmt
# Run the formatter and manually remove trailing whitespace.
run: cargo +nightly fmt && git ls-files -- '*.rs' -z | xargs sed -E -i'' -e 's/[[:space:]]+$//'
- name: Get the current date
run: echo "date=$(date +'%Y-%m-%d')" >> $GITHUB_ENV
- name: Create Pull Request
uses: peter-evans/create-pull-request@v7
with:
author: Fmt Bot <[email protected]>
title: Automated nightly rustfmt (${{ env.date }})
body: |
Automated nightly `rustfmt` changes by [create-pull-request](https://github.com/peter-evans/create-pull-request) GitHub action
commit-message: ${{ env.date }} automated rustfmt nightly
labels: rustfmt
13 changes: 7 additions & 6 deletions ldk-server-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use prost::Message;
use std::time::{SystemTime, UNIX_EPOCH};

use crate::error::LdkServerError;
use crate::error::LdkServerErrorCode::{
AuthError, InternalError, InternalServerError, InvalidRequestError, LightningError,
};
use bitcoin_hashes::hmac::{Hmac, HmacEngine};
use bitcoin_hashes::{sha256, Hash, HashEngine};
use ldk_server_protos::api::{
Expand All @@ -32,9 +28,14 @@ use ldk_server_protos::endpoints::{
OPEN_CHANNEL_PATH, SPLICE_IN_PATH, SPLICE_OUT_PATH, UPDATE_CHANNEL_CONFIG_PATH,
};
use ldk_server_protos::error::{ErrorCode, ErrorResponse};
use prost::Message;
use reqwest::header::CONTENT_TYPE;
use reqwest::{Certificate, Client};
use std::time::{SystemTime, UNIX_EPOCH};

use crate::error::LdkServerError;
use crate::error::LdkServerErrorCode::{
AuthError, InternalError, InternalServerError, InvalidRequestError, LightningError,
};

const APPLICATION_OCTET_STREAM: &str = "application/octet-stream";

Expand Down
3 changes: 2 additions & 1 deletion ldk-server/src/api/bolt11_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use ldk_server_protos::api::{Bolt11ReceiveRequest, Bolt11ReceiveResponse};

use crate::api::error::LdkServerError;
use crate::service::Context;
use crate::util::proto_adapter::proto_to_bolt11_description;
use ldk_server_protos::api::{Bolt11ReceiveRequest, Bolt11ReceiveResponse};

pub(crate) fn handle_bolt11_receive_request(
context: Context, request: Bolt11ReceiveRequest,
Expand Down
10 changes: 6 additions & 4 deletions ldk-server/src/api/bolt11_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InvalidRequestError;
use crate::service::Context;
use std::str::FromStr;

use ldk_node::lightning::routing::router::RouteParametersConfig;
use ldk_node::lightning_invoice::Bolt11Invoice;
use ldk_server_protos::api::{Bolt11SendRequest, Bolt11SendResponse};
use std::str::FromStr;

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InvalidRequestError;
use crate::service::Context;

pub(crate) fn handle_bolt11_send_request(
context: Context, request: Bolt11SendRequest,
Expand Down
3 changes: 2 additions & 1 deletion ldk-server/src/api/bolt12_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use ldk_server_protos::api::{Bolt12ReceiveRequest, Bolt12ReceiveResponse};

use crate::api::error::LdkServerError;
use crate::service::Context;
use ldk_server_protos::api::{Bolt12ReceiveRequest, Bolt12ReceiveResponse};

pub(crate) fn handle_bolt12_receive_request(
context: Context, request: Bolt12ReceiveRequest,
Expand Down
10 changes: 6 additions & 4 deletions ldk-server/src/api/bolt12_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InvalidRequestError;
use crate::service::Context;
use std::str::FromStr;

use ldk_node::lightning::offers::offer::Offer;
use ldk_node::lightning::routing::router::RouteParametersConfig;
use ldk_server_protos::api::{Bolt12SendRequest, Bolt12SendResponse};
use std::str::FromStr;

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InvalidRequestError;
use crate::service::Context;

pub(crate) fn handle_bolt12_send_request(
context: Context, request: Bolt12SendRequest,
Expand Down
10 changes: 6 additions & 4 deletions ldk-server/src/api/close_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InvalidRequestError;
use crate::service::Context;
use std::str::FromStr;

use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::UserChannelId;
use ldk_server_protos::api::{
CloseChannelRequest, CloseChannelResponse, ForceCloseChannelRequest, ForceCloseChannelResponse,
};
use std::str::FromStr;

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InvalidRequestError;
use crate::service::Context;

pub(crate) fn handle_close_channel_request(
context: Context, request: CloseChannelRequest,
Expand Down
3 changes: 2 additions & 1 deletion ldk-server/src/api/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use ldk_node::NodeError;
use std::fmt;

use ldk_node::NodeError;

#[derive(Clone, Debug, PartialEq, Eq)]
pub(crate) struct LdkServerError {
// The error message containing a generic description of the error condition in English.
Expand Down
3 changes: 2 additions & 1 deletion ldk-server/src/api/get_balances.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use ldk_server_protos::api::{GetBalancesRequest, GetBalancesResponse};

use crate::api::error::LdkServerError;
use crate::service::Context;
use crate::util::proto_adapter::{lightning_balance_to_proto, pending_sweep_balance_to_proto};
use ldk_server_protos::api::{GetBalancesRequest, GetBalancesResponse};

pub(crate) fn handle_get_balances_request(
context: Context, _request: GetBalancesRequest,
Expand Down
5 changes: 3 additions & 2 deletions ldk-server/src/api/get_node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use crate::api::error::LdkServerError;
use crate::service::Context;
use ldk_server_protos::api::{GetNodeInfoRequest, GetNodeInfoResponse};
use ldk_server_protos::types::BestBlock;

use crate::api::error::LdkServerError;
use crate::service::Context;

pub(crate) fn handle_get_node_info_request(
context: Context, _request: GetNodeInfoRequest,
) -> Result<GetNodeInfoResponse, LdkServerError> {
Expand Down
7 changes: 4 additions & 3 deletions ldk-server/src/api/get_payment_details.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,14 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use hex::FromHex;
use ldk_node::lightning::ln::channelmanager::PaymentId;
use ldk_server_protos::api::{GetPaymentDetailsRequest, GetPaymentDetailsResponse};

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InvalidRequestError;
use crate::service::Context;
use crate::util::proto_adapter::payment_to_proto;
use hex::FromHex;
use ldk_node::lightning::ln::channelmanager::PaymentId;
use ldk_server_protos::api::{GetPaymentDetailsRequest, GetPaymentDetailsResponse};

pub(crate) fn handle_get_payment_details_request(
context: Context, request: GetPaymentDetailsRequest,
Expand Down
3 changes: 2 additions & 1 deletion ldk-server/src/api/list_channels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use ldk_server_protos::api::{ListChannelsRequest, ListChannelsResponse};

use crate::api::error::LdkServerError;
use crate::service::Context;
use crate::util::proto_adapter::channel_to_proto;
use ldk_server_protos::api::{ListChannelsRequest, ListChannelsResponse};

pub(crate) fn handle_list_channels_request(
context: Context, _request: ListChannelsRequest,
Expand Down
9 changes: 5 additions & 4 deletions ldk-server/src/api/list_forwarded_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use bytes::Bytes;
use ldk_server_protos::api::{ListForwardedPaymentsRequest, ListForwardedPaymentsResponse};
use ldk_server_protos::types::{ForwardedPayment, PageToken};
use prost::Message;

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InternalServerError;
use crate::io::persist::{
FORWARDED_PAYMENTS_PERSISTENCE_PRIMARY_NAMESPACE,
FORWARDED_PAYMENTS_PERSISTENCE_SECONDARY_NAMESPACE,
};
use crate::service::Context;
use bytes::Bytes;
use ldk_server_protos::api::{ListForwardedPaymentsRequest, ListForwardedPaymentsResponse};
use ldk_server_protos::types::{ForwardedPayment, PageToken};
use prost::Message;

pub(crate) fn handle_list_forwarded_payments_request(
context: Context, request: ListForwardedPaymentsRequest,
Expand Down
9 changes: 5 additions & 4 deletions ldk-server/src/api/list_payments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use bytes::Bytes;
use ldk_server_protos::api::{ListPaymentsRequest, ListPaymentsResponse};
use ldk_server_protos::types::{PageToken, Payment};
use prost::Message;

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InternalServerError;
use crate::io::persist::{
PAYMENTS_PERSISTENCE_PRIMARY_NAMESPACE, PAYMENTS_PERSISTENCE_SECONDARY_NAMESPACE,
};
use crate::service::Context;
use bytes::Bytes;
use ldk_server_protos::api::{ListPaymentsRequest, ListPaymentsResponse};
use ldk_server_protos::types::{PageToken, Payment};
use prost::Message;

pub(crate) fn handle_list_payments_request(
context: Context, request: ListPaymentsRequest,
Expand Down
5 changes: 3 additions & 2 deletions ldk-server/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InvalidRequestError;
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure};
use ldk_server_protos::types::channel_config::MaxDustHtlcExposure;

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InvalidRequestError;

pub(crate) mod bolt11_receive;
pub(crate) mod bolt11_send;
pub(crate) mod bolt12_receive;
Expand Down
3 changes: 2 additions & 1 deletion ldk-server/src/api/onchain_receive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use ldk_server_protos::api::{OnchainReceiveRequest, OnchainReceiveResponse};

use crate::api::error::LdkServerError;
use crate::service::Context;
use ldk_server_protos::api::{OnchainReceiveRequest, OnchainReceiveResponse};

pub(crate) fn handle_onchain_receive_request(
context: Context, _request: OnchainReceiveRequest,
Expand Down
8 changes: 5 additions & 3 deletions ldk-server/src/api/onchain_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use std::str::FromStr;

use ldk_node::bitcoin::{Address, FeeRate};
use ldk_server_protos::api::{OnchainSendRequest, OnchainSendResponse};

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InvalidRequestError;
use crate::service::Context;
use ldk_node::bitcoin::{Address, FeeRate};
use ldk_server_protos::api::{OnchainSendRequest, OnchainSendResponse};
use std::str::FromStr;

pub(crate) fn handle_onchain_send_request(
context: Context, request: OnchainSendRequest,
Expand Down
10 changes: 6 additions & 4 deletions ldk-server/src/api/open_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use crate::api::build_channel_config_from_proto;
use crate::api::error::LdkServerError;
use crate::service::Context;
use std::str::FromStr;

use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::config::ChannelConfig;
use ldk_node::lightning::ln::msgs::SocketAddress;
use ldk_server_protos::api::{OpenChannelRequest, OpenChannelResponse};
use std::str::FromStr;

use crate::api::build_channel_config_from_proto;
use crate::api::error::LdkServerError;
use crate::service::Context;

pub(crate) fn handle_open_channel(
context: Context, request: OpenChannelRequest,
Expand Down
10 changes: 6 additions & 4 deletions ldk-server/src/api/splice_channel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,18 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InvalidRequestError;
use crate::service::Context;
use std::str::FromStr;

use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::bitcoin::Address;
use ldk_node::UserChannelId;
use ldk_server_protos::api::{
SpliceInRequest, SpliceInResponse, SpliceOutRequest, SpliceOutResponse,
};
use std::str::FromStr;

use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::InvalidRequestError;
use crate::service::Context;

pub(crate) fn handle_splice_in_request(
context: Context, request: SpliceInRequest,
Expand Down
12 changes: 7 additions & 5 deletions ldk-server/src/api/update_channel_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,16 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use std::str::FromStr;

use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::UserChannelId;
use ldk_server_protos::api::{UpdateChannelConfigRequest, UpdateChannelConfigResponse};

use crate::api::build_channel_config_from_proto;
use crate::api::error::LdkServerError;
use crate::api::error::LdkServerErrorCode::{InvalidRequestError, LightningError};
use crate::service::Context;
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::UserChannelId;
use ldk_server_protos::api::{UpdateChannelConfigRequest, UpdateChannelConfigResponse};
use std::str::FromStr;

pub(crate) fn handle_update_channel_config_request(
context: Context, request: UpdateChannelConfigRequest,
Expand All @@ -24,7 +26,7 @@ pub(crate) fn handle_update_channel_config_request(
.parse::<u128>()
.map_err(|_| LdkServerError::new(InvalidRequestError, "Invalid UserChannelId."))?;

//FIXME: Use ldk/ldk-node's partial config update api.
// FIXME: Use ldk/ldk-node's partial config update api.
let current_config = context
.node
.list_channels()
Expand Down
3 changes: 2 additions & 1 deletion ldk-server/src/io/events/event_publisher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
// You may not use this file except in accordance with one or both of these
// licenses.

use crate::api::error::LdkServerError;
use async_trait::async_trait;
use ldk_server_protos::events::EventEnvelope;

use crate::api::error::LdkServerError;

/// A trait for publishing events or notifications from the LDK Server.
///
/// Implementors of this trait define how events are sent to various messaging
Expand Down
Loading