Skip to content

Commit 0e97a48

Browse files
committed
Add missing fields to getblockchaininfo
v21, v23 and v28 had missing return fields. Redefine the type and into functions with the missing fields in v21 and v23, add to existing definition in v28. Update other into functions.
1 parent d65d26c commit 0e97a48

File tree

17 files changed

+281
-25
lines changed

17 files changed

+281
-25
lines changed

types/src/model/blockchain.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ pub struct GetBlockchainInfo {
8484
pub target: Option<Target>, // Only from v29 onwards
8585
/// The current difficulty.
8686
pub difficulty: f64,
87+
/// The block time expressed in UNIX epoch time. v23 and later only.
88+
pub time: Option<u32>,
8789
/// Median time for the current best block.
8890
pub median_time: u32,
8991
/// Estimate of verification progress (between 0 and 1).
@@ -151,6 +153,8 @@ pub struct Bip9SoftforkInfo {
151153
pub timeout: u32,
152154
/// Height of the first block to which the status applies.
153155
pub since: u32,
156+
/// Minimum height of blocks for which the rules may be enforced. v0.21 and later only.
157+
pub min_activation_height: Option<i64>,
154158
/// Numeric statistics about BIP-9 signalling for a softfork (only for "started" status).
155159
pub statistics: Option<Bip9SoftforkStatistics>,
156160
}

types/src/v17/blockchain/into.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ impl GetBlockchainInfo {
104104
bits: None,
105105
target: None,
106106
difficulty: self.difficulty,
107+
time: None,
107108
median_time: crate::to_u32(self.median_time, "median_time")?,
108109
verification_progress: self.verification_progress,
109110
initial_block_download: self.initial_block_download,

types/src/v19/blockchain/into.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ impl GetBlockchainInfo {
3939
bits: None,
4040
target: None,
4141
difficulty: self.difficulty,
42+
time: None,
4243
median_time: crate::to_u32(self.median_time, "median_time")?,
4344
verification_progress: self.verification_progress,
4445
initial_block_download: self.initial_block_download,

types/src/v21/blockchain/into.rs

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,54 @@
11
// SPDX-License-Identifier: CC0-1.0
22

3-
use bitcoin::{Txid, Wtxid};
3+
use alloc::collections::BTreeMap;
44

5-
use super::{GetMempoolEntry, MempoolEntry, MempoolEntryError};
5+
use bitcoin::{BlockHash, Network, Txid, Work, Wtxid};
6+
7+
use super::{
8+
GetBlockchainInfo, GetBlockchainInfoError, GetMempoolEntry, MempoolEntry, MempoolEntryError,
9+
};
610
use crate::model;
711

12+
impl GetBlockchainInfo {
13+
/// Converts version specific type to a version nonspecific, more strongly typed type.
14+
pub fn into_model(self) -> Result<model::GetBlockchainInfo, GetBlockchainInfoError> {
15+
use GetBlockchainInfoError as E;
16+
17+
let chain = Network::from_core_arg(&self.chain).map_err(E::Chain)?;
18+
let best_block_hash =
19+
self.best_block_hash.parse::<BlockHash>().map_err(E::BestBlockHash)?;
20+
let chain_work = Work::from_unprefixed_hex(&self.chain_work).map_err(E::ChainWork)?;
21+
let prune_height =
22+
self.prune_height.map(|h| crate::to_u32(h, "prune_height")).transpose()?;
23+
let prune_target_size =
24+
self.prune_target_size.map(|h| crate::to_u32(h, "prune_target_size")).transpose()?;
25+
let softforks = BTreeMap::new(); // TODO: Handle softforks stuff.
26+
27+
Ok(model::GetBlockchainInfo {
28+
chain,
29+
blocks: crate::to_u32(self.blocks, "blocks")?,
30+
headers: crate::to_u32(self.headers, "headers")?,
31+
best_block_hash,
32+
bits: None,
33+
target: None,
34+
difficulty: self.difficulty,
35+
time: None,
36+
median_time: crate::to_u32(self.median_time, "median_time")?,
37+
verification_progress: self.verification_progress,
38+
initial_block_download: self.initial_block_download,
39+
chain_work,
40+
size_on_disk: self.size_on_disk,
41+
pruned: self.pruned,
42+
prune_height,
43+
automatic_pruning: self.automatic_pruning,
44+
prune_target_size,
45+
softforks,
46+
signet_challenge: None,
47+
warnings: vec![self.warnings],
48+
})
49+
}
50+
}
51+
852
impl GetMempoolEntry {
953
/// Converts version specific type to a version nonspecific, more strongly typed type.
1054
pub fn into_model(self) -> Result<model::GetMempoolEntry, MempoolEntryError> {

types/src/v21/blockchain/mod.rs

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,109 @@
66
77
mod into;
88

9+
use alloc::collections::BTreeMap;
10+
911
use serde::{Deserialize, Serialize};
1012

11-
pub use super::{MempoolEntryError, MempoolEntryFees};
13+
pub use super::{
14+
Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBlockchainInfoError, MempoolEntryError,
15+
MempoolEntryFees,
16+
};
17+
18+
/// Result of JSON-RPC method `getblockchaininfo`.
19+
///
20+
/// > getblockchaininfo
21+
/// >
22+
/// > Returns an object containing various state info regarding blockchain processing.
23+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
24+
pub struct GetBlockchainInfo {
25+
/// Current network name as defined in BIP70 (main, test, signet, regtest).
26+
pub chain: String,
27+
/// The current number of blocks processed in the server.
28+
pub blocks: i64,
29+
/// The current number of headers we have validated.
30+
pub headers: i64,
31+
/// The hash of the currently best block.
32+
#[serde(rename = "bestblockhash")]
33+
pub best_block_hash: String,
34+
/// The current difficulty.
35+
pub difficulty: f64,
36+
/// Median time for the current best block.
37+
#[serde(rename = "mediantime")]
38+
pub median_time: i64,
39+
/// Estimate of verification progress (between 0 and 1).
40+
#[serde(rename = "verificationprogress")]
41+
pub verification_progress: f64,
42+
/// Estimate of whether this node is in Initial Block Download (IBD) mode.
43+
#[serde(rename = "initialblockdownload")]
44+
pub initial_block_download: bool,
45+
/// Total amount of work in active chain, in hexadecimal.
46+
#[serde(rename = "chainwork")]
47+
pub chain_work: String,
48+
/// The estimated size of the block and undo files on disk.
49+
pub size_on_disk: u64,
50+
/// If the blocks are subject to pruning.
51+
pub pruned: bool,
52+
/// Lowest-height complete block stored (only present if pruning is enabled).
53+
#[serde(rename = "pruneheight")]
54+
pub prune_height: Option<i64>,
55+
/// Whether automatic pruning is enabled (only present if pruning is enabled).
56+
pub automatic_pruning: Option<bool>,
57+
/// The target size used by pruning (only present if automatic pruning is enabled).
58+
pub prune_target_size: Option<i64>,
59+
/// Status of softforks in progress, maps softfork name -> [`Softfork`].
60+
#[serde(default)]
61+
pub softforks: BTreeMap<String, Softfork>,
62+
/// Any network and blockchain warnings.
63+
pub warnings: String,
64+
}
65+
66+
/// Status of softfork.
67+
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
68+
pub struct Softfork {
69+
/// The [`SoftforkType`]: one of "buried", "bip9".
70+
#[serde(rename = "type")]
71+
pub type_: SoftforkType,
72+
/// The status of bip9 softforks (only for "bip9" type).
73+
pub bip9: Option<Bip9SoftforkInfo>,
74+
/// Height of the first block which the rules are or will be enforced (only for "buried" type, or "bip9" type with "active" status).
75+
pub height: Option<i64>,
76+
/// `true` if the rules are enforced for the mempool and the next block.
77+
pub active: bool,
78+
}
79+
80+
/// The softfork type: one of "buried", "bip9".
81+
#[derive(Copy, Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
82+
#[serde(rename_all = "lowercase")]
83+
pub enum SoftforkType {
84+
/// Softfork is "buried" (as defined in [BIP-90]).
85+
///
86+
/// [BIP-90] <https://github.com/bitcoin/bips/blob/master/bip-0090.mediawiki>
87+
Buried,
88+
/// Softfork is "bip9" (see [BIP-9]).
89+
///
90+
/// [BIP-9] <https://github.com/bitcoin/bips/blob/master/bip-0009.mediawiki>
91+
Bip9,
92+
}
93+
94+
/// Status of BIP-9 softforks.
95+
#[derive(Clone, PartialEq, Eq, Debug, Deserialize, Serialize)]
96+
pub struct Bip9SoftforkInfo {
97+
/// One of "defined", "started", "locked_in", "active", "failed".
98+
pub status: Bip9SoftforkStatus,
99+
/// The bit (0-28) in the block version field used to signal this softfork (only for "started" status).
100+
pub bit: Option<u8>,
101+
/// The minimum median time past of a block at which the bit gains its meaning.
102+
pub start_time: i64,
103+
/// The median time past of a block at which the deployment is considered failed if not yet locked in.
104+
pub timeout: i64,
105+
/// Height of the first block to which the status applies.
106+
pub since: i64,
107+
/// Minimum height of blocks for which the rules may be enforced. v0.21 and later only.
108+
pub min_activation_height: i64,
109+
/// Numeric statistics about BIP-9 signalling for a softfork (only for "started" status).
110+
pub statistics: Option<Bip9SoftforkStatistics>,
111+
}
12112

13113
/// Result of JSON-RPC method `getmempoolentry`.
14114
///

types/src/v21/mod.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,10 @@ mod blockchain;
236236
mod wallet;
237237

238238
#[doc(inline)]
239-
pub use self::{blockchain::GetMempoolEntry, wallet::UnloadWallet};
239+
pub use self::{
240+
blockchain::{Bip9SoftforkInfo, GetBlockchainInfo, GetMempoolEntry, Softfork, SoftforkType},
241+
wallet::UnloadWallet,
242+
};
240243
#[doc(inline)]
241244
pub use crate::{
242245
v17::{
@@ -279,13 +282,12 @@ pub use crate::{
279282
ListWalletDir, ListWalletDirWallet, NodeAddress, UtxoUpdatePsbt,
280283
},
281284
v19::{
282-
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,
283-
GetBalancesWatchOnly, GetBlockFilter, GetBlockFilterError, GetBlockchainInfo,
285+
Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,
286+
GetBalancesWatchOnly, GetBlockFilter, GetBlockFilterError,
284287
GetBlockchainInfoError, GetChainTxStats, GetDescriptorInfo, GetMempoolAncestors,
285288
GetMempoolAncestorsVerbose, GetMempoolDescendants, GetMempoolDescendantsVerbose,
286289
GetMempoolInfo, GetNetworkInfo, GetPeerInfo, GetRpcInfo, MapMempoolEntryError,
287290
MempoolEntry, MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, PeerInfo,
288-
Softfork, SoftforkType,
289291
},
290292
v20::{Banned, CreateMultisig, ListBanned, Logging},
291293
};

types/src/v22/mod.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -293,15 +293,16 @@ pub use crate::{
293293
ListWalletDir, ListWalletDirWallet, NodeAddress, UtxoUpdatePsbt,
294294
},
295295
v19::{
296-
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,
297-
GetBalancesWatchOnly, GetBlockFilter, GetBlockFilterError, GetBlockchainInfo,
296+
Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,
297+
GetBalancesWatchOnly, GetBlockFilter, GetBlockFilterError,
298298
GetBlockchainInfoError, GetChainTxStats, GetDescriptorInfo, GetMempoolAncestors,
299299
GetMempoolAncestorsVerbose, GetMempoolDescendants, GetMempoolDescendantsVerbose,
300300
GetMempoolInfo, GetNetworkInfo, GetPeerInfo, GetRpcInfo, MapMempoolEntryError,
301301
MempoolEntry, MempoolEntryError, MempoolEntryFees, MempoolEntryFeesError, PeerInfo,
302-
Softfork, SoftforkType,
303302
},
304303
v20::CreateMultisig,
305-
v21::{GetMempoolEntry, UnloadWallet},
304+
v21::{
305+
Bip9SoftforkInfo, GetBlockchainInfo, GetMempoolEntry, Softfork, SoftforkType, UnloadWallet,
306+
},
306307
ScriptPubkey,
307308
};

types/src/v23/blockchain/into.rs

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,55 @@
11
// SPDX-License-Identifier: CC0-1.0
22

3-
use bitcoin::{Txid, Wtxid};
3+
use alloc::collections::BTreeMap;
44

5-
use super::{GetMempoolEntry, MempoolEntry, MempoolEntryError};
5+
use bitcoin::{BlockHash, Network, Txid, Work, Wtxid};
6+
7+
use super::{
8+
GetBlockchainInfo, GetBlockchainInfoError, GetMempoolEntry, MempoolEntry, MempoolEntryError,
9+
};
610
use crate::model;
711

12+
impl GetBlockchainInfo {
13+
/// Converts version specific type to a version nonspecific, more strongly typed type.
14+
pub fn into_model(self) -> Result<model::GetBlockchainInfo, GetBlockchainInfoError> {
15+
use GetBlockchainInfoError as E;
16+
17+
let chain = Network::from_core_arg(&self.chain).map_err(E::Chain)?;
18+
let best_block_hash =
19+
self.best_block_hash.parse::<BlockHash>().map_err(E::BestBlockHash)?;
20+
let time = Some(crate::to_u32(self.time, "time")?);
21+
let chain_work = Work::from_unprefixed_hex(&self.chain_work).map_err(E::ChainWork)?;
22+
let prune_height =
23+
self.prune_height.map(|h| crate::to_u32(h, "prune_height")).transpose()?;
24+
let prune_target_size =
25+
self.prune_target_size.map(|h| crate::to_u32(h, "prune_target_size")).transpose()?;
26+
let softforks = BTreeMap::new(); // TODO: Handle softforks stuff.
27+
28+
Ok(model::GetBlockchainInfo {
29+
chain,
30+
blocks: crate::to_u32(self.blocks, "blocks")?,
31+
headers: crate::to_u32(self.headers, "headers")?,
32+
best_block_hash,
33+
bits: None,
34+
target: None,
35+
difficulty: self.difficulty,
36+
time,
37+
median_time: crate::to_u32(self.median_time, "median_time")?,
38+
verification_progress: self.verification_progress,
39+
initial_block_download: self.initial_block_download,
40+
chain_work,
41+
size_on_disk: self.size_on_disk,
42+
pruned: self.pruned,
43+
prune_height,
44+
automatic_pruning: self.automatic_pruning,
45+
prune_target_size,
46+
softforks,
47+
signet_challenge: None,
48+
warnings: vec![self.warnings],
49+
})
50+
}
51+
}
52+
853
impl GetMempoolEntry {
954
/// Converts version specific type to a version nonspecific, more strongly typed type.
1055
pub fn into_model(self) -> Result<model::GetMempoolEntry, MempoolEntryError> {

types/src/v23/blockchain/mod.rs

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,61 @@
66
77
mod into;
88

9+
use alloc::collections::BTreeMap;
10+
911
use serde::{Deserialize, Serialize};
1012

11-
pub use super::{MempoolEntryError, MempoolEntryFees};
13+
pub use super::{GetBlockchainInfoError, MempoolEntryError, MempoolEntryFees, Softfork};
14+
15+
/// Result of JSON-RPC method `getblockchaininfo`.
16+
///
17+
/// > getblockchaininfo
18+
/// >
19+
/// > Returns an object containing various state info regarding blockchain processing.
20+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
21+
pub struct GetBlockchainInfo {
22+
/// Current network name as defined in BIP70 (main, test, signet, regtest).
23+
pub chain: String,
24+
/// The current number of blocks processed in the server.
25+
pub blocks: i64,
26+
/// The current number of headers we have validated.
27+
pub headers: i64,
28+
/// The hash of the currently best block.
29+
#[serde(rename = "bestblockhash")]
30+
pub best_block_hash: String,
31+
/// The current difficulty.
32+
pub difficulty: f64,
33+
/// The block time expressed in UNIX epoch time. v23 and later only.
34+
pub time: i64,
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: String,
63+
}
1264

1365
/// Result of JSON-RPC method `getmempoolentry`.
1466
///

types/src/v23/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ mod util;
242242

243243
#[doc(inline)]
244244
pub use self::{
245-
blockchain::{GetMempoolEntry, SaveMempool},
245+
blockchain::{GetBlockchainInfo, GetMempoolEntry, SaveMempool},
246246
raw_transactions::{
247247
DecodePsbt, DecodePsbtError, GlobalXpub, Proprietary, PsbtInput, PsbtOutput,
248248
},
@@ -291,7 +291,7 @@ pub use crate::{
291291
},
292292
v19::{
293293
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBalances, GetBalancesMine,
294-
GetBalancesWatchOnly, GetBlockFilter, GetBlockFilterError, GetBlockchainInfo,
294+
GetBalancesWatchOnly, GetBlockFilter, GetBlockFilterError,
295295
GetBlockchainInfoError, GetChainTxStats, GetDescriptorInfo, GetMempoolAncestors,
296296
GetMempoolAncestorsVerbose, GetMempoolDescendants, GetMempoolDescendantsVerbose,
297297
GetMempoolInfo, GetNetworkInfo, GetPeerInfo, GetRpcInfo, MapMempoolEntryError,

0 commit comments

Comments
 (0)