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

Commit 7506b74

Browse files
committed
v17: Add support for blockchain methods
Add support to the `v17` client and integration tests for the following methods (all from the `blockchain` section): - `getblockcount` - `getblockhash` - `getblockheader`
1 parent d4301fc commit 7506b74

File tree

8 files changed

+895
-14
lines changed

8 files changed

+895
-14
lines changed

client/src/client_sync/v17/blockchain.rs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,100 @@ macro_rules! impl_client_v17__getblockchaininfo {
7070
};
7171
}
7272

73+
/// Implements bitcoind JSON-RPC API method `getblockcount`
74+
#[macro_export]
75+
macro_rules! impl_client_v17__getblockcount {
76+
() => {
77+
impl Client {
78+
pub fn get_block_count(&self) -> Result<GetBlockCount> {
79+
self.call("getblockcount", &[])
80+
}
81+
}
82+
};
83+
}
84+
85+
/// Implements bitcoind JSON-RPC API method `getblockhash`
86+
#[macro_export]
87+
macro_rules! impl_client_v17__getblockhash {
88+
() => {
89+
impl Client {
90+
pub fn get_block_hash(&self, height: u64) -> Result<GetBlockHash> {
91+
self.call("getblockhash", &[into_json(height)?])
92+
}
93+
}
94+
};
95+
}
96+
97+
/// Implements bitcoind JSON-RPC API method `getblockheader`
98+
#[macro_export]
99+
macro_rules! impl_client_v17__getblockheader {
100+
() => {
101+
impl Client {
102+
pub fn get_block_header(&self, hash: &BlockHash) -> Result<GetBlockHeader> {
103+
self.call("getblockheader", &[into_json(hash)?, into_json(false)?])
104+
}
105+
106+
// This is the same as calling getblockheader with verbose==true.
107+
pub fn get_block_header_verbose(
108+
&self,
109+
hash: &BlockHash,
110+
) -> Result<GetBlockHeaderVerbose> {
111+
self.call("getblockheader", &[into_json(hash)?])
112+
}
113+
}
114+
};
115+
}
116+
117+
/// Implements bitcoind JSON-RPC API method `getblockstats`
118+
#[macro_export]
119+
macro_rules! impl_client_v17__getblockstats {
120+
() => {
121+
impl Client {
122+
pub fn get_block_stats_by_height(&self, height: u32) -> Result<GetBlockStats> {
123+
self.call("getblockstats", &[into_json(height)?])
124+
}
125+
126+
pub fn get_block_stats_by_block_hash(&self, hash: &BlockHash) -> Result<GetBlockStats> {
127+
self.call("getblockstats", &[into_json(hash)?])
128+
}
129+
}
130+
};
131+
}
132+
133+
/// Implements bitcoind JSON-RPC API method `getchaintips`
134+
#[macro_export]
135+
macro_rules! impl_client_v17__getchaintips {
136+
() => {
137+
impl Client {
138+
pub fn get_chain_tips(&self) -> Result<GetChainTips> { self.call("getchaintips", &[]) }
139+
}
140+
};
141+
}
142+
143+
/// Implements bitcoind JSON-RPC API method `getchaintxstats`
144+
#[macro_export]
145+
macro_rules! impl_client_v17__getchaintxstats {
146+
() => {
147+
impl Client {
148+
pub fn get_chain_tx_stats(&self) -> Result<GetChainTxStats> {
149+
self.call("getchaintxstats", &[])
150+
}
151+
}
152+
};
153+
}
154+
155+
/// Implements bitcoind JSON-RPC API method `getdifficulty`
156+
#[macro_export]
157+
macro_rules! impl_client_v17__getdifficulty {
158+
() => {
159+
impl Client {
160+
pub fn get_difficulty(&self) -> Result<GetDifficulty> {
161+
self.call("getdifficulty", &[])
162+
}
163+
}
164+
};
165+
}
166+
73167
/// Implements bitcoind JSON-RPC API method `gettxout`
74168
#[macro_export]
75169
macro_rules! impl_client_v17__gettxout {

client/src/client_sync/v17/mod.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ crate::impl_client_v17__getblockchaininfo!();
2525
crate::impl_client_v17__getbestblockhash!();
2626
crate::impl_client_v17__getblock!();
2727
crate::impl_client_v17__gettxout!();
28+
crate::impl_client_v17__getblockcount!();
29+
crate::impl_client_v17__getblockhash!();
30+
crate::impl_client_v17__getblockheader!();
31+
crate::impl_client_v17__getblockstats!();
32+
crate::impl_client_v17__getchaintips!();
33+
crate::impl_client_v17__getchaintxstats!();
34+
crate::impl_client_v17__getdifficulty!();
2835

2936
// == Control ==
3037
crate::impl_client_v17__stop!();

integration_test/src/v17/blockchain.rs

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,114 @@ macro_rules! impl_test_v17__getblockchaininfo {
8181
};
8282
}
8383

84+
/// Requires `Client` to be in scope and to implement `getblockcount`.
85+
#[macro_export]
86+
macro_rules! impl_test_v17__getblockcount {
87+
() => {
88+
#[test]
89+
fn get_block_count() {
90+
let bitcoind = $crate::bitcoind_no_wallet();
91+
let json = bitcoind.client.get_block_count().expect("getblockcount");
92+
let _ = json.into_model();
93+
}
94+
};
95+
}
96+
97+
/// Requires `Client` to be in scope and to implement `getblockhash`.
98+
#[macro_export]
99+
macro_rules! impl_test_v17__getblockhash {
100+
() => {
101+
#[test]
102+
fn get_block_hash() {
103+
let bitcoind = $crate::bitcoind_no_wallet();
104+
let json = bitcoind.client.get_block_hash(0).expect("getblockhash");
105+
assert!(json.into_model().is_ok());
106+
}
107+
};
108+
}
109+
110+
/// Requires `Client` to be in scope and to implement `getblockheader`.
111+
#[macro_export]
112+
macro_rules! impl_test_v17__getblockheader {
113+
() => {
114+
#[test]
115+
fn get_block_header() { // verbose = false
116+
let bitcoind = $crate::bitcoind_no_wallet();
117+
let block_hash = best_block_hash();
118+
let json = bitcoind.client.get_block_header(&block_hash).expect("getblockheader");
119+
assert!(json.into_model().is_ok());
120+
}
121+
122+
#[test]
123+
fn get_block_header_verbose() { // verbose = true
124+
let bitcoind = $crate::bitcoind_no_wallet();
125+
let block_hash = best_block_hash();
126+
let json = bitcoind.client.get_block_header_verbose(&block_hash).expect("getblockheader");
127+
assert!(json.into_model().is_ok());
128+
}
129+
};
130+
}
131+
132+
/// Requires `Client` to be in scope and to implement `getblockstats`.
133+
#[macro_export]
134+
macro_rules! impl_test_v17__getblockstats {
135+
() => {
136+
#[test]
137+
fn get_block_stats_by_height() {
138+
let bitcoind = $crate::bitcoind_no_wallet();
139+
let json = bitcoind.client.get_block_stats_by_height(0).expect("getblockstats");
140+
assert!(json.into_model().is_ok());
141+
}
142+
143+
#[test]
144+
fn get_block_stats_by_hash() { // verbose = true
145+
let bitcoind = $crate::bitcoind_no_wallet();
146+
let block_hash = best_block_hash();
147+
let json = bitcoind.client.get_block_stats_by_block_hash(&block_hash).expect("getblockstats");
148+
assert!(json.into_model().is_ok());
149+
}
150+
};
151+
}
152+
153+
/// Requires `Client` to be in scope and to implement `getchaintips`.
154+
#[macro_export]
155+
macro_rules! impl_test_v17__getchaintips {
156+
() => {
157+
#[test]
158+
fn get_chain_tips() {
159+
let bitcoind = $crate::bitcoind_no_wallet();
160+
let json = bitcoind.client.get_chain_tips().expect("getchaintips");
161+
assert!(json.into_model().is_ok());
162+
}
163+
}
164+
}
165+
166+
/// Requires `Client` to be in scope and to implement `getchaintxstats`.
167+
#[macro_export]
168+
macro_rules! impl_test_v17__getchaintxstats {
169+
() => {
170+
#[test]
171+
fn get_chain_tx_stats() {
172+
let bitcoind = $crate::bitcoind_no_wallet();
173+
let json = bitcoind.client.get_chain_tx_stats().expect("getchaintxstats");
174+
assert!(json.into_model().is_ok());
175+
}
176+
}
177+
}
178+
179+
/// Requires `Client` to be in scope and to implement `getdifficulty`.
180+
#[macro_export]
181+
macro_rules! impl_test_v17__getdifficulty {
182+
() => {
183+
#[test]
184+
fn get_difficulty() {
185+
let bitcoind = $crate::bitcoind_no_wallet();
186+
let json = bitcoind.client.get_difficulty().expect("getdifficulty");
187+
let _ = json.into_model();
188+
}
189+
}
190+
}
191+
84192
/// Requires `Client` to be in scope and to implement `get_tx_out`.
85193
#[macro_export]
86194
macro_rules! impl_test_v17__gettxout {

integration_test/tests/v17_api.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ mod blockchain {
1212
impl_test_v17__getblock_verbosity_0!();
1313
impl_test_v17__getblock_verbosity_1!();
1414
impl_test_v17__getblockchaininfo!();
15+
impl_test_v17__getblockcount!();
16+
impl_test_v17__getblockhash!();
17+
impl_test_v17__getblockheader!();
18+
impl_test_v17__getblockstats!();
19+
impl_test_v17__getchaintips!();
20+
impl_test_v17__getchaintxstats!();
21+
impl_test_v17__getdifficulty!();
1522
}
1623

1724
// == Control ==

0 commit comments

Comments
 (0)