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
30 changes: 15 additions & 15 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions ldk-server-grpc/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,10 @@ fn generate_protos() {
"types.ClaimableAwaitingConfirmations.source",
"#[cfg_attr(feature = \"serde\", serde(serialize_with = \"crate::serde_utils::serialize_balance_source\"))]",
)
.field_attribute(
"api.GetNodeInfoResponse.network",
"#[cfg_attr(feature = \"serde\", serde(serialize_with = \"crate::serde_utils::serialize_network\"))]",
)
.field_attribute(
"api.UnifiedSendResponse.payment_result",
"#[cfg_attr(feature = \"serde\", serde(flatten))]",
Expand Down
4 changes: 4 additions & 0 deletions ldk-server-grpc/src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ pub struct GetNodeInfoResponse {
/// Will be empty if no announcement addresses are configured.
#[prost(string, repeated, tag = "12")]
pub node_uris: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
/// The Bitcoin network the node is running on (e.g., "bitcoin", "testnet", "signet", "regtest").
#[prost(enumeration = "super::types::Network", tag = "13")]
#[cfg_attr(feature = "serde", serde(serialize_with = "crate::serde_utils::serialize_network"))]
pub network: i32,
}
/// Retrieve a new on-chain funding address.
/// See more: <https://docs.rs/ldk-node/latest/ldk_node/payment/struct.OnchainPayment.html#method.new_address>
Expand Down
3 changes: 3 additions & 0 deletions ldk-server-grpc/src/proto/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ message GetNodeInfoResponse {
// These are constructed from the announcement addresses and the node's public key.
// Will be empty if no announcement addresses are configured.
repeated string node_uris = 12;

// The Bitcoin network the node is running on (e.g., "bitcoin", "testnet", "signet", "regtest").
types.Network network = 13;
}

// Retrieve a new on-chain funding address.
Expand Down
18 changes: 18 additions & 0 deletions ldk-server-grpc/src/proto/types.proto
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,24 @@ enum PaymentStatus {
FAILED = 2;
}

// The Bitcoin network the node is running on.
enum Network {
// Mainnet Bitcoin.
BITCOIN = 0;

// Bitcoin's testnet (testnet3) network.
TESTNET = 1;

// Bitcoin's testnet4 network.
TESTNET4 = 2;

// Bitcoin's signet network.
SIGNET = 3;

// Bitcoin's regtest network.
REGTEST = 4;
}

// A forwarded payment through our node.
// See more: https://docs.rs/ldk-node/latest/ldk_node/enum.Event.html#variant.PaymentForwarded
message ForwardedPayment{
Expand Down
1 change: 1 addition & 0 deletions ldk-server-grpc/src/serde_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ macro_rules! stringify_enum_serializer {
stringify_enum_serializer!(serialize_payment_direction, crate::types::PaymentDirection);
stringify_enum_serializer!(serialize_payment_status, crate::types::PaymentStatus);
stringify_enum_serializer!(serialize_balance_source, crate::types::BalanceSource);
stringify_enum_serializer!(serialize_network, crate::types::Network);

/// Serializes `Option<prost::bytes::Bytes>` as a hex string (or null).
pub fn serialize_opt_bytes_hex<S>(
Expand Down
43 changes: 43 additions & 0 deletions ldk-server-grpc/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,49 @@ impl PaymentStatus {
}
}
}
/// The Bitcoin network the node is running on.
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
#[cfg_attr(feature = "serde", serde(rename_all = "snake_case"))]
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum Network {
/// Mainnet Bitcoin.
Bitcoin = 0,
/// Bitcoin's testnet (testnet3) network.
Testnet = 1,
/// Bitcoin's testnet4 network.
Testnet4 = 2,
/// Bitcoin's signet network.
Signet = 3,
/// Bitcoin's regtest network.
Regtest = 4,
}
impl Network {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
Network::Bitcoin => "BITCOIN",
Network::Testnet => "TESTNET",
Network::Testnet4 => "TESTNET4",
Network::Signet => "SIGNET",
Network::Regtest => "REGTEST",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"BITCOIN" => Some(Self::Bitcoin),
"TESTNET" => Some(Self::Testnet),
"TESTNET4" => Some(Self::Testnet4),
"SIGNET" => Some(Self::Signet),
"REGTEST" => Some(Self::Regtest),
_ => None,
}
}
}
/// Indicates whether the balance is derived from a cooperative close, a force-close (for holder or counterparty),
/// or whether it is for an HTLC.
#[cfg_attr(feature = "serde", derive(serde::Serialize))]
Expand Down
2 changes: 1 addition & 1 deletion ldk-server/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.1.0"
edition = "2021"

[dependencies]
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node", rev = "21eea8c881790db7a90bcad4f7f45f341c72222b" }
ldk-node = { git = "https://github.com/lightningdevkit/ldk-node", rev = "16eaa6f46308965f501904506be3ceecd293f358" }
Comment thread
randomlogin marked this conversation as resolved.
serde = { version = "1.0.203", default-features = false, features = ["derive"] }
hyper = { version = "1", default-features = false, features = ["server", "http2"] }
http-body-util = { version = "0.1", default-features = false }
Expand Down
4 changes: 4 additions & 0 deletions ldk-server/src/api/get_node_info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use ldk_server_grpc::types::BestBlock;

use crate::api::error::LdkServerError;
use crate::service::Context;
use crate::util::proto_adapter::network_to_proto;

pub(crate) async fn handle_get_node_info_request(
context: Arc<Context>, _request: GetNodeInfoRequest,
Expand Down Expand Up @@ -49,6 +50,8 @@ pub(crate) async fn handle_get_node_info_request(
};
addrs.into_iter().map(|a| format!("{node_id}@{a}")).collect()
};
let network = network_to_proto(node_status.network) as i32;

let response = GetNodeInfoResponse {
node_id,
current_best_block: Some(best_block),
Expand All @@ -62,6 +65,7 @@ pub(crate) async fn handle_get_node_info_request(
announcement_addresses,
node_alias,
node_uris,
network,
};
Ok(response)
}
12 changes: 12 additions & 0 deletions ldk-server/src/util/proto_adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use bytes::Bytes;
use hex::prelude::*;
use ldk_node::bitcoin::hashes::sha256;
use ldk_node::bitcoin::secp256k1::PublicKey;
use ldk_node::bitcoin::Network;
use ldk_node::config::{ChannelConfig, MaxDustHTLCExposure};
use ldk_node::lightning::chain::channelmonitor::BalanceSource;
use ldk_node::lightning::ln::types::ChannelId;
Expand Down Expand Up @@ -510,3 +511,14 @@ pub(crate) fn graph_node_to_proto(node: NodeInfo) -> ldk_server_grpc::types::Gra
announcement_info: node.announcement_info.map(graph_node_announcement_to_proto),
}
}

pub(crate) fn network_to_proto(network: Network) -> ldk_server_grpc::types::Network {
use ldk_server_grpc::types::Network as ProtoNetwork;
match network {
Network::Bitcoin => ProtoNetwork::Bitcoin,
Network::Testnet => ProtoNetwork::Testnet,
Network::Testnet4 => ProtoNetwork::Testnet4,
Network::Signet => ProtoNetwork::Signet,
Network::Regtest => ProtoNetwork::Regtest,
}
}