Skip to content

Commit 95df5e8

Browse files
committed
bitcoin node sync heights
1 parent 87fbe96 commit 95df5e8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

client/src/format.rs

+2
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,8 @@ pub fn print_server_info(info: ServerInfo, format: Format) {
155155
println!("CHAIN: {}", info.chain);
156156
println!(" Height {}", info.tip.height);
157157
println!(" Hash {}", info.tip.hash);
158+
println!(" Blocks Height {}", info.blocks_height);
159+
println!(" Headers Height {}", info.headers_height);
158160
}
159161
Format::Json => {
160162
println!("{}", serde_json::to_string_pretty(&info).unwrap());

client/src/rpc.rs

+21-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ pub(crate) type Responder<T> = oneshot::Sender<T>;
6868
pub struct ServerInfo {
6969
pub chain: ExtendedNetwork,
7070
pub tip: ChainAnchor,
71+
pub blocks_height: u32,
72+
pub headers_height: u32,
7173
}
7274

7375
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -401,6 +403,7 @@ pub struct RegisterParams {
401403
pub struct RpcServerImpl {
402404
wallet_manager: WalletManager,
403405
store: AsyncChainState,
406+
rpc: BitcoinRpc,
404407
client: reqwest::Client,
405408
}
406409

@@ -647,9 +650,11 @@ impl WalletManager {
647650

648651
impl RpcServerImpl {
649652
pub fn new(store: AsyncChainState, wallet_manager: WalletManager) -> Self {
653+
let rpc = wallet_manager.rpc.clone();
650654
RpcServerImpl {
651655
wallet_manager,
652656
store,
657+
rpc,
653658
client: reqwest::Client::new(),
654659
}
655660
}
@@ -729,7 +734,22 @@ impl RpcServer for RpcServerImpl {
729734
.get_tip()
730735
.await
731736
.map_err(|error| ErrorObjectOwned::owned(-1, error.to_string(), None::<String>))?;
732-
Ok(ServerInfo { chain, tip })
737+
#[derive(Deserialize)]
738+
struct Info {
739+
blocks: u32,
740+
headers: u32,
741+
}
742+
let info: Info = self
743+
.rpc
744+
.send_json(&self.client, &self.rpc.get_blockchain_info())
745+
.await
746+
.map_err(|error| ErrorObjectOwned::owned(-1, error.to_string(), None::<String>))?;
747+
Ok(ServerInfo {
748+
chain,
749+
tip,
750+
blocks_height: info.blocks,
751+
headers_height: info.headers,
752+
})
733753
}
734754

735755
async fn get_space(

0 commit comments

Comments
 (0)