Skip to content

Commit

Permalink
Add impl for GetNodeInfo Api.
Browse files Browse the repository at this point in the history
  • Loading branch information
G8XSU committed Oct 14, 2024
1 parent 664c09c commit a978cc6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
29 changes: 29 additions & 0 deletions server/src/api/get_node_info.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
use crate::util::hex_util;
use ldk_node::Node;
use protos::{BitcoinBlock, GetNodeInfoRequest, GetNodeInfoResponse};
use std::sync::Arc;

pub(crate) const GET_NODE_INFO: &str = "GetNodeInfo";

pub(crate) fn handle_get_node_info_request(
node: Arc<Node>, _request: GetNodeInfoRequest,
) -> Result<GetNodeInfoResponse, ldk_node::NodeError> {
let node_status = node.status();

let best_block = BitcoinBlock {
block_hash: node_status.current_best_block.block_hash.to_string(),
height: node_status.current_best_block.height,
};

let response = GetNodeInfoResponse {
node_id: hex_util::to_string(&node.node_id().serialize()),
current_best_block: Some(best_block),
latest_wallet_sync_timestamp: node_status.latest_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,
latest_node_announcement_broadcast_timestamp: node_status
.latest_node_announcement_broadcast_timestamp,
};
Ok(response)
}
1 change: 1 addition & 0 deletions server/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pub(crate) mod bolt11_send;
pub(crate) mod bolt12_receive;
pub(crate) mod bolt12_send;
pub(crate) mod close_channel;
pub(crate) mod get_node_info;
pub(crate) mod list_channels;
pub(crate) mod onchain_receive;
pub(crate) mod onchain_send;
Expand Down
2 changes: 2 additions & 0 deletions server/src/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use crate::api::bolt11_send::{handle_bolt11_send_request, BOLT11_SEND_PATH};
use crate::api::bolt12_receive::{handle_bolt12_receive_request, BOLT12_RECEIVE_PATH};
use crate::api::bolt12_send::{handle_bolt12_send_request, BOLT12_SEND_PATH};
use crate::api::close_channel::{handle_close_channel_request, CLOSE_CHANNEL_PATH};
use crate::api::get_node_info::{handle_get_node_info_request, GET_NODE_INFO};
use crate::api::list_channels::{handle_list_channels_request, LIST_CHANNELS_PATH};
use crate::api::onchain_receive::{handle_onchain_receive_request, ONCHAIN_RECEIVE_PATH};
use crate::api::onchain_send::{handle_onchain_send_request, ONCHAIN_SEND_PATH};
Expand All @@ -41,6 +42,7 @@ impl Service<Request<Incoming>> for NodeService {
let node = Arc::clone(&self.node);
// Exclude '/' from path pattern matching.
match &req.uri().path()[1..] {
GET_NODE_INFO => Box::pin(handle_request(node, req, handle_get_node_info_request)),
ONCHAIN_RECEIVE_PATH => {
Box::pin(handle_request(node, req, handle_onchain_receive_request))
},
Expand Down

0 comments on commit a978cc6

Please sign in to comment.