Skip to content

Commit 42ed35f

Browse files
committed
Update getserverinfo structure
1 parent 76708c2 commit 42ed35f

File tree

4 files changed

+26
-14
lines changed

4 files changed

+26
-14
lines changed

client/src/format.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ pub fn print_list_unspent(utxos: Vec<WalletOutput>, format: Format) {
152152
pub fn print_server_info(info: ServerInfo, format: Format) {
153153
match format {
154154
Format::Text => {
155-
println!("CHAIN: {}", info.chain);
155+
println!("CHAIN: {}", info.network);
156156
println!(" Height {}", info.tip.height);
157157
println!(" Hash {}", info.tip.hash);
158158
}

client/src/rpc.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,16 @@ pub(crate) type Responder<T> = oneshot::Sender<T>;
6666

6767
#[derive(Debug, Clone, Serialize, Deserialize)]
6868
pub struct ServerInfo {
69-
pub chain: String,
69+
pub network: String,
7070
pub tip: ChainAnchor,
71-
pub progress: Option<f32>,
71+
pub chain: ChainInfo,
72+
pub progress: f32,
73+
}
74+
75+
#[derive(Debug, Clone, Serialize, Deserialize)]
76+
pub struct ChainInfo {
77+
blocks: u32,
78+
headers: u32,
7279
}
7380

7481
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -1083,7 +1090,7 @@ impl AsyncChainState {
10831090
rpc,
10841091
chain_state,
10851092
)
1086-
.await?;
1093+
.await?;
10871094

10881095
Ok(block
10891096
.block_meta
@@ -1205,7 +1212,7 @@ impl AsyncChainState {
12051212
rpc,
12061213
chain_state,
12071214
)
1208-
.await;
1215+
.await;
12091216
let _ = resp.send(res);
12101217
}
12111218
ChainStateCommand::GetTxMeta { txid, resp } => {
@@ -1267,7 +1274,7 @@ impl AsyncChainState {
12671274
File::open(anchors_path)
12681275
.or_else(|e| Err(anyhow!("Could not open anchors file: {}", e)))?,
12691276
)
1270-
.or_else(|e| Err(anyhow!("Could not read anchors file: {}", e)))?;
1277+
.or_else(|e| Err(anyhow!("Could not read anchors file: {}", e)))?;
12711278
return Ok(anchors);
12721279
}
12731280

@@ -1569,6 +1576,7 @@ async fn get_server_info(client: &reqwest::Client, rpc: &BitcoinRpc, tip: ChainA
15691576
struct Info {
15701577
pub chain: String,
15711578
pub headers: u32,
1579+
pub blocks: u32,
15721580
}
15731581

15741582
let info: Info = rpc
@@ -1577,12 +1585,16 @@ async fn get_server_info(client: &reqwest::Client, rpc: &BitcoinRpc, tip: ChainA
15771585
.map_err(|e| anyhow!("Could not retrieve blockchain info ({})", e))?;
15781586

15791587
Ok(ServerInfo {
1580-
chain: info.chain,
1588+
network: info.chain,
15811589
tip,
1590+
chain: ChainInfo {
1591+
blocks: info.blocks,
1592+
headers: info.headers,
1593+
},
15821594
progress: if info.headers >= tip.height {
1583-
Some(tip.height as f32 / info.headers as f32)
1595+
tip.height as f32 / info.headers as f32
15841596
} else {
1585-
None
1586-
}
1597+
0.0
1598+
},
15871599
})
15881600
}

client/src/wallets.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -363,9 +363,9 @@ impl RpcWallet {
363363
.get_best_chain(Some(wallet_info.tip), wallet.config.network);
364364
if let Ok(Some(best_chain)) = best_chain {
365365
wallet_info.progress = if best_chain.height >= wallet_info.tip {
366-
Some(wallet_info.tip as f32 / best_chain.height as f32)
366+
wallet_info.tip as f32 / best_chain.height as f32
367367
} else {
368-
None
368+
0.0
369369
}
370370
}
371371

wallet/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub struct WalletInfo {
104104
pub start_block: u32,
105105
pub tip: u32,
106106
pub descriptors: Vec<DescriptorInfo>,
107-
pub progress: Option<f32>,
107+
pub progress: f32,
108108
}
109109

110110
#[derive(Debug, Clone, Serialize, Deserialize)]
@@ -590,7 +590,7 @@ impl SpacesWallet {
590590
start_block: self.config.start_block,
591591
tip: self.internal.local_chain().tip().height(),
592592
descriptors,
593-
progress: None,
593+
progress: 0.0,
594594
}
595595
}
596596

0 commit comments

Comments
 (0)