diff --git a/server/src/api/get_node_info.rs b/server/src/api/get_node_info.rs new file mode 100644 index 0000000..dc5e8ef --- /dev/null +++ b/server/src/api/get_node_info.rs @@ -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, _request: GetNodeInfoRequest, +) -> Result { + 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) +} diff --git a/server/src/api/mod.rs b/server/src/api/mod.rs index 22a2185..6355e9d 100644 --- a/server/src/api/mod.rs +++ b/server/src/api/mod.rs @@ -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; diff --git a/server/src/service.rs b/server/src/service.rs index df18538..15eaa79 100644 --- a/server/src/service.rs +++ b/server/src/service.rs @@ -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}; @@ -41,6 +42,7 @@ impl Service> 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)) },