Skip to content

Commit 6a38a71

Browse files
committed
feat(client): Add v29 module
1 parent 0778704 commit 6a38a71

4 files changed

Lines changed: 32 additions & 5 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ jsonrpc = { version = "0.18.0", features = ["simple_http", "simple_tcp", "minreq
1818
[features]
1919
default = ["30_0"]
2020
30_0 = []
21+
29_0 = []
2122
28_0 = []

src/client.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@ use std::{
66

77
use crate::error::Error;
88
use crate::jsonrpc::minreq_http::Builder;
9+
#[cfg(not(feature = "29_0"))]
10+
use corepc_types::v30::GetBlockFilter;
911
use corepc_types::{
1012
bitcoin::{
1113
block::Header, consensus::encode::deserialize_hex, Block, BlockHash, Transaction, Txid,
1214
},
13-
model::{GetBlockCount, GetBlockFilter, GetRawMempool},
15+
model::{GetBlockCount, GetRawMempool},
1416
};
1517
use jsonrpc::{
1618
serde,
@@ -21,6 +23,9 @@ use jsonrpc::{
2123
#[cfg(feature = "28_0")]
2224
pub mod v28;
2325

26+
#[cfg(feature = "29_0")]
27+
pub mod v29;
28+
2429
/// Client authentication methods for the Bitcoin Core JSON-RPC server
2530
#[derive(Clone, Debug, Hash, Eq, PartialEq, Ord, PartialOrd)]
2631
pub enum Auth {
@@ -187,7 +192,7 @@ impl Client {
187192
Ok(block_hash.parse()?)
188193
}
189194

190-
/// Retrieves the compact block filter for a given block
195+
/// Retrieve the `basic` BIP 157 content filter for a particular block
191196
///
192197
/// # Arguments
193198
///
@@ -196,6 +201,7 @@ impl Client {
196201
/// # Returns
197202
///
198203
/// The `GetBlockFilter` structure containing the filter data
204+
#[cfg(not(feature = "29_0"))]
199205
pub fn get_block_filter(&self, block_hash: &BlockHash) -> Result<GetBlockFilter, Error> {
200206
let block_filter: GetBlockFilter = self.call("getblockfilter", &[json!(block_hash)])?;
201207
Ok(block_filter)

src/client/v29.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use corepc_types::{bitcoin::BlockHash, v29::GetBlockFilter};
2+
3+
use jsonrpc::serde_json::json;
4+
5+
use crate::{Client, Error};
6+
7+
impl Client {
8+
/// Retrieve the `basic` BIP 157 content filter for a particular block
9+
///
10+
/// # Arguments
11+
///
12+
/// * `block_hash`: The hash of the block whose filter is requested
13+
///
14+
/// # Returns
15+
///
16+
/// The `GetBlockFilter` structure containing the filter data
17+
pub fn get_block_filter(&self, block_hash: &BlockHash) -> Result<GetBlockFilter, Error> {
18+
let block_filter: GetBlockFilter = self.call("getblockfilter", &[json!(block_hash)])?;
19+
Ok(block_filter)
20+
}
21+
}

tests/test_rpc_client.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -169,11 +169,10 @@ fn test_get_block_hash_invalid_height() {
169169
fn test_get_best_block_hash() {
170170
let client = test_client();
171171

172-
let best_hash = client
172+
let best_block_hash = client
173173
.get_best_block_hash()
174174
.expect("failed to get best block hash");
175-
176-
assert_eq!(best_hash.to_string().len(), 64);
175+
assert_eq!(best_block_hash.to_string().len(), 64);
177176
}
178177

179178
#[test]

0 commit comments

Comments
 (0)