Skip to content

Commit 9e6f836

Browse files
committed
Add getdeploymentinfo struct, model and test
Getdeploymentinfo returns a chain of json objects. Add structs for all of them and a model with an into function. Add a client macro and test.
1 parent 869f0c4 commit 9e6f836

File tree

21 files changed

+288
-15
lines changed

21 files changed

+288
-15
lines changed

client/src/client_sync/v23/blockchain.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,18 @@ macro_rules! impl_client_v23__get_block_from_peer {
2525
};
2626
}
2727

28+
/// Implements Bitcoin Core JSON-RPC API method `getdeploymentinfo`.
29+
#[macro_export]
30+
macro_rules! impl_client_v23__get_deployment_info {
31+
() => {
32+
impl Client {
33+
pub fn get_deployment_info(&self, blockhash: &BlockHash) -> Result<GetDeploymentInfo> {
34+
self.call("getdeploymentinfo", &[into_json(blockhash)?])
35+
}
36+
}
37+
};
38+
}
39+
2840
/// Implements Bitcoin Core JSON-RPC API method `savemempool`
2941
#[macro_export]
3042
macro_rules! impl_client_v23__save_mempool {

client/src/client_sync/v23/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ crate::impl_client_v17__get_block_header!();
4141
crate::impl_client_v17__get_block_stats!();
4242
crate::impl_client_v17__get_chain_tips!();
4343
crate::impl_client_v17__get_chain_tx_stats!();
44+
crate::impl_client_v23__get_deployment_info!();
4445
crate::impl_client_v17__get_difficulty!();
4546
crate::impl_client_v17__get_mempool_ancestors!();
4647
crate::impl_client_v17__get_mempool_descendants!();

client/src/client_sync/v24/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ crate::impl_client_v17__get_block_header!();
3838
crate::impl_client_v17__get_block_stats!();
3939
crate::impl_client_v17__get_chain_tips!();
4040
crate::impl_client_v17__get_chain_tx_stats!();
41+
crate::impl_client_v23__get_deployment_info!();
4142
crate::impl_client_v17__get_difficulty!();
4243
crate::impl_client_v17__get_mempool_ancestors!();
4344
crate::impl_client_v17__get_mempool_descendants!();

client/src/client_sync/v25/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ crate::impl_client_v17__get_block_header!();
4040
crate::impl_client_v17__get_block_stats!();
4141
crate::impl_client_v17__get_chain_tips!();
4242
crate::impl_client_v17__get_chain_tx_stats!();
43+
crate::impl_client_v23__get_deployment_info!();
4344
crate::impl_client_v17__get_difficulty!();
4445
crate::impl_client_v17__get_mempool_ancestors!();
4546
crate::impl_client_v17__get_mempool_descendants!();

client/src/client_sync/v26/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ crate::impl_client_v17__get_block_header!();
4242
crate::impl_client_v17__get_block_stats!();
4343
crate::impl_client_v17__get_chain_tips!();
4444
crate::impl_client_v17__get_chain_tx_stats!();
45+
crate::impl_client_v23__get_deployment_info!();
4546
crate::impl_client_v17__get_difficulty!();
4647
crate::impl_client_v17__get_mempool_ancestors!();
4748
crate::impl_client_v17__get_mempool_descendants!();

client/src/client_sync/v27/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ crate::impl_client_v17__get_block_header!();
3838
crate::impl_client_v17__get_block_stats!();
3939
crate::impl_client_v17__get_chain_tips!();
4040
crate::impl_client_v17__get_chain_tx_stats!();
41+
crate::impl_client_v23__get_deployment_info!();
4142
crate::impl_client_v17__get_difficulty!();
4243
crate::impl_client_v17__get_mempool_ancestors!();
4344
crate::impl_client_v17__get_mempool_descendants!();

client/src/client_sync/v28/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ crate::impl_client_v17__get_block_header!();
4040
crate::impl_client_v17__get_block_stats!();
4141
crate::impl_client_v17__get_chain_tips!();
4242
crate::impl_client_v17__get_chain_tx_stats!();
43+
crate::impl_client_v23__get_deployment_info!();
4344
crate::impl_client_v17__get_difficulty!();
4445
crate::impl_client_v17__get_mempool_ancestors!();
4546
crate::impl_client_v17__get_mempool_descendants!();

client/src/client_sync/v29/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ crate::impl_client_v17__get_block_header!();
3939
crate::impl_client_v17__get_block_stats!();
4040
crate::impl_client_v17__get_chain_tips!();
4141
crate::impl_client_v17__get_chain_tx_stats!();
42+
crate::impl_client_v23__get_deployment_info!();
4243
crate::impl_client_v29__get_descriptor_activity!();
4344
crate::impl_client_v17__get_difficulty!();
4445
crate::impl_client_v17__get_mempool_ancestors!();

integration_test/tests/blockchain.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,17 @@ fn blockchain__get_chain_tx_stats__modelled() {
178178
model.unwrap();
179179
}
180180

181+
#[test]
182+
#[cfg(not(feature = "v22_and_below"))]
183+
fn blockchain__get_deployment_info__modelled() {
184+
let node = Node::with_wallet(Wallet::None, &[]);
185+
let block_hash = node.client.best_block_hash().expect("best_block_hash failed");
186+
187+
let json: GetDeploymentInfo = node.client.get_deployment_info(&block_hash).expect("getdeploymentinfo");
188+
let model: Result<mtype::GetDeploymentInfo, GetDeploymentInfoError> = json.into_model();
189+
model.unwrap();
190+
}
191+
181192
#[test]
182193
#[cfg(not(feature = "v28_and_below"))]
183194
fn blockchain__get_descriptor_activity__modelled() {

types/src/model/blockchain.rs

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,72 @@ pub struct GetChainTxStats {
384384
pub tx_rate: Option<u32>,
385385
}
386386

387+
/// Models the result of JSON-RPC method `getdeploymentinfo`.
388+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
389+
#[serde(deny_unknown_fields)]
390+
pub struct GetDeploymentInfo {
391+
/// Requested block hash (or tip).
392+
pub hash: BlockHash,
393+
/// Requested block height (or tip).
394+
pub height: u32,
395+
/// Deployments info, keyed by deployment name.
396+
pub deployments: std::collections::BTreeMap<String, DeploymentInfo>,
397+
}
398+
399+
/// Deployment info. Returned as part of `getdeploymentinfo`.
400+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
401+
#[serde(deny_unknown_fields)]
402+
pub struct DeploymentInfo {
403+
/// One of "buried", "bip9".
404+
pub deployment_type: String,
405+
/// Height of the first block which the rules are or will be enforced (only for "buried" type, or "bip9" type with "active" status).
406+
pub height: Option<u32>,
407+
/// True if the rules are enforced for the mempool and the next block.
408+
pub active: bool,
409+
/// Status of bip9 softforks (only for "bip9" type).
410+
pub bip9: Option<Bip9Info>,
411+
}
412+
413+
/// Status of bip9 softforks. Returned as part of `getdeploymentinfo`.
414+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
415+
#[serde(deny_unknown_fields)]
416+
pub struct Bip9Info {
417+
/// The bit (0-28) in the block version field used to signal this softfork (only for "started" and "locked_in" status).
418+
pub bit: Option<u8>,
419+
/// The minimum median time past of a block at which the bit gains its meaning.
420+
pub start_time: i64,
421+
/// The median time past of a block at which the deployment is considered failed if not yet locked in.
422+
pub timeout: i64,
423+
/// Minimum height of blocks for which the rules may be enforced.
424+
pub min_activation_height: u32,
425+
/// Status of deployment at specified block (one of "defined", "started", "locked_in", "active", "failed").
426+
pub status: String,
427+
/// Height of the first block to which the status applies.
428+
pub since: u32,
429+
/// Status of deployment at the next block.
430+
pub status_next: String,
431+
/// Numeric statistics about signalling for a softfork (only for "started" and "locked_in" status).
432+
pub statistics: Option<Bip9Statistics>,
433+
/// Indicates blocks that signalled with a # and blocks that did not with a -.
434+
pub signalling: Option<String>,
435+
}
436+
437+
/// Numeric statistics about signalling for a softfork. Returned as part of `getdeploymentinfo`.
438+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
439+
#[serde(deny_unknown_fields)]
440+
pub struct Bip9Statistics {
441+
/// The length in blocks of the signalling period.
442+
pub period: u32,
443+
/// The number of blocks with the version bit set required to activate the feature (only for "started" status).
444+
pub threshold: Option<u32>,
445+
/// The number of blocks elapsed since the beginning of the current period.
446+
pub elapsed: u32,
447+
/// The number of blocks with the version bit set in the current period.
448+
pub count: u32,
449+
/// Returns false if there are not enough blocks left in this period to pass activation threshold (only for "started" status).
450+
pub possible: Option<bool>,
451+
}
452+
387453
/// Models the result of JSON-RPC method `getdifficulty`.
388454
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
389455
#[serde(deny_unknown_fields)]

0 commit comments

Comments
 (0)