Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.

Commit 1f46cba

Browse files
committed
f Account for getblockchaininfo returing array of warnings now
1 parent 56f1dcb commit 1f46cba

File tree

6 files changed

+108
-6
lines changed

6 files changed

+108
-6
lines changed

json/src/model/blockchain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ pub struct GetBlockchainInfo {
9797
/// Status of softforks in progress, maps softfork name -> [`Softfork`].
9898
pub softforks: BTreeMap<String, Softfork>,
9999
/// Any network and blockchain warnings.
100-
pub warnings: String,
100+
pub warnings: Vec<String>,
101101
}
102102

103103
/// Status of softfork.

json/src/v17/blockchain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ impl GetBlockchainInfo {
346346
automatic_pruning: self.automatic_pruning,
347347
prune_target_size,
348348
softforks,
349-
warnings: self.warnings,
349+
warnings: vec![self.warnings],
350350
})
351351
}
352352
}

json/src/v19/blockchain.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl GetBlockchainInfo {
171171
automatic_pruning: self.automatic_pruning,
172172
prune_target_size,
173173
softforks,
174-
warnings: self.warnings,
174+
warnings: vec![self.warnings],
175175
})
176176
}
177177
}

json/src/v19/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ mod wallet;
160160
#[doc(inline)]
161161
pub use self::{
162162
blockchain::{
163-
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBlockchainInfo, Softfork,
164-
SoftforkType,
163+
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBlockchainInfo,
164+
GetBlockchainInfoError, Softfork, SoftforkType,
165165
},
166166
wallet::{GetBalances, GetBalancesMine, GetBalancesWatchOnly},
167167
};

json/src/v28/blockchain.rs

Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! The JSON-RPC API for Bitcoin Core v28.0 - blockchain.
4+
//!
5+
//! Types for methods found under the `== Blockchain ==` section of the API docs.
6+
7+
use std::collections::BTreeMap;
8+
9+
use bitcoin::{BlockHash, Network, Work};
10+
use serde::{Deserialize, Serialize};
11+
12+
use super::{GetBlockchainInfoError, Softfork};
13+
use crate::model;
14+
15+
#[rustfmt::skip] // Keep public re-exports separate.
16+
17+
/// Result of JSON-RPC method `getblockchaininfo`.
18+
///
19+
/// Method call: `getblockchaininfo`
20+
///
21+
/// > Returns an object containing various state info regarding blockchain processing.
22+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
23+
pub struct GetBlockchainInfo {
24+
/// Current network name as defined in BIP70 (main, test, signet, regtest).
25+
pub chain: String,
26+
/// The current number of blocks processed in the server.
27+
pub blocks: i64,
28+
/// The current number of headers we have validated.
29+
pub headers: i64,
30+
/// The hash of the currently best block.
31+
#[serde(rename = "bestblockhash")]
32+
pub best_block_hash: String,
33+
/// The current difficulty.
34+
pub difficulty: f64,
35+
/// Median time for the current best block.
36+
#[serde(rename = "mediantime")]
37+
pub median_time: i64,
38+
/// Estimate of verification progress (between 0 and 1).
39+
#[serde(rename = "verificationprogress")]
40+
pub verification_progress: f64,
41+
/// Estimate of whether this node is in Initial Block Download (IBD) mode.
42+
#[serde(rename = "initialblockdownload")]
43+
pub initial_block_download: bool,
44+
/// Total amount of work in active chain, in hexadecimal.
45+
#[serde(rename = "chainwork")]
46+
pub chain_work: String,
47+
/// The estimated size of the block and undo files on disk.
48+
pub size_on_disk: u64,
49+
/// If the blocks are subject to pruning.
50+
pub pruned: bool,
51+
/// Lowest-height complete block stored (only present if pruning is enabled).
52+
#[serde(rename = "pruneheight")]
53+
pub prune_height: Option<i64>,
54+
/// Whether automatic pruning is enabled (only present if pruning is enabled).
55+
pub automatic_pruning: Option<bool>,
56+
/// The target size used by pruning (only present if automatic pruning is enabled).
57+
pub prune_target_size: Option<i64>,
58+
/// Status of softforks in progress, maps softfork name -> [`Softfork`].
59+
#[serde(default)]
60+
pub softforks: BTreeMap<String, Softfork>,
61+
/// Any network and blockchain warnings.
62+
pub warnings: Vec<String>,
63+
}
64+
65+
impl GetBlockchainInfo {
66+
/// Converts version specific type to a version in-specific, more strongly typed type.
67+
pub fn into_model(self) -> Result<model::GetBlockchainInfo, GetBlockchainInfoError> {
68+
use GetBlockchainInfoError as E;
69+
70+
let chain = Network::from_core_arg(&self.chain).map_err(E::Chain)?;
71+
let best_block_hash =
72+
self.best_block_hash.parse::<BlockHash>().map_err(E::BestBlockHash)?;
73+
let chain_work = Work::from_unprefixed_hex(&self.chain_work).map_err(E::ChainWork)?;
74+
let prune_height =
75+
self.prune_height.map(|h| crate::to_u32(h, "prune_height")).transpose()?;
76+
let prune_target_size =
77+
self.prune_target_size.map(|h| crate::to_u32(h, "prune_target_size")).transpose()?;
78+
let softforks = BTreeMap::new(); // TODO: Handle softforks stuff.
79+
80+
Ok(model::GetBlockchainInfo {
81+
chain,
82+
blocks: crate::to_u32(self.blocks, "blocks")?,
83+
headers: crate::to_u32(self.headers, "headers")?,
84+
best_block_hash,
85+
difficulty: self.difficulty,
86+
median_time: crate::to_u32(self.median_time, "median_time")?,
87+
verification_progress: self.verification_progress,
88+
initial_block_download: self.initial_block_download,
89+
chain_work,
90+
size_on_disk: self.size_on_disk,
91+
pruned: self.pruned,
92+
prune_height,
93+
automatic_pruning: self.automatic_pruning,
94+
prune_target_size,
95+
softforks,
96+
warnings: self.warnings,
97+
})
98+
}
99+
}

json/src/v28/mod.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,8 +180,11 @@
180180
//! **== Zmq ==**
181181
//! - [ ] `getzmqnotifications`
182182
183+
mod blockchain;
183184
mod network;
184185

186+
#[doc(inline)]
187+
pub use self::blockchain::GetBlockchainInfo;
185188
#[doc(inline)]
186189
pub use self::network::GetNetworkInfo;
187190
#[doc(inline)]
@@ -194,7 +197,7 @@ pub use crate::{
194197
},
195198
v19::{
196199
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,
197-
GetBalancesWatchOnly, GetBlockchainInfo, Softfork, SoftforkType,
200+
GetBalancesWatchOnly, GetBlockchainInfoError, Softfork, SoftforkType,
198201
},
199202
v22::{SendToAddress, UnloadWallet},
200203
v25::{CreateWallet, LoadWallet},

0 commit comments

Comments
 (0)