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

Commit e74992a

Browse files
authored
v17: Add support for blockchain methods (#29)
Add support to the `v17` client and integration tests for blockchain section methods. //! **== Blockchain ==** //! - [x] `getbestblockhash` //! - [x] `getblock "blockhash" ( verbosity ) ` //! - [x] `getblockchaininfo` //! - [x] `getblockcount` //! - [x] `getblockhash height` //! - [x] `getblockheader "hash" ( verbose )` //! - [x] `getblockstats hash_or_height ( stats )` //! - [x] `getchaintips` //! - [x] `getchaintxstats ( nblocks blockhash )` //! - [x] `getdifficulty` //! - [x] `getmempoolancestors txid (verbose)` //! - [x] `getmempooldescendants txid (verbose)` //! - [x] `getmempoolentry txid` //! - [x] `getmempoolinfo` //! - [x] `getrawmempool ( verbose )` //! - [x] `gettxout "txid" n ( include_mempool )` //! - [x] `gettxoutproof ["txid",...] ( blockhash )` //! - [x] `gettxoutsetinfo` //! - [x] `preciousblock "blockhash"` //! - [-] `pruneblockchain` //! - [-] `savemempool` //! - [-] `scantxoutset <action> ( <scanobjects> )` //! - [x] `verifychain ( checklevel nblocks )` //! - [-] `verifytxoutproof "proof"` //! //! Key: //! - `[ ]` means not yet done. //! - `[x]` marks means implemented _and_ tested. //! - `[-]` means it was considered and intentionally not done.
2 parents 97ec8e8 + 4d906e9 commit e74992a

File tree

8 files changed

+965
-15
lines changed

8 files changed

+965
-15
lines changed

client/src/client_sync/v17/blockchain.rs

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,112 @@ macro_rules! impl_client_v17__getblockchaininfo {
6464
};
6565
}
6666

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

client/src/client_sync/v17/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,14 @@ 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!();
35+
crate::impl_client_v17__getmempoolancestors!();
2836

2937
// == Control ==
3038
crate::impl_client_v17__getmemoryinfo!();

integration_test/src/v17/blockchain.rs

Lines changed: 124 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,134 @@ 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+
192+
/// Requires `Client` to be in scope and to implement `getmempoolancestors`.
193+
#[macro_export]
194+
macro_rules! impl_test_v17__getmempoolancestors {
195+
() => {
196+
#[test]
197+
fn get_mempool_ancestors() {
198+
// FIXME: We need a valid txid to test this.
199+
todo!()
200+
}
201+
}
202+
}
203+
84204
/// Requires `Client` to be in scope and to implement `get_tx_out`.
85205
#[macro_export]
86206
macro_rules! impl_test_v17__gettxout {
87207
() => {
88208
#[test]
89-
fn get_tx_out() { todo!() }
209+
fn get_tx_out() {
210+
// FIXME: We need a valid txid to test this.
211+
todo!()
212+
}
90213
};
91214
}

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)