Skip to content
This repository was archived by the owner on Nov 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 107 additions & 4 deletions client/src/client_sync/v17/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ macro_rules! impl_client_v17__getblock {
self.call("getblock", &[into_json(hash)?, 0.into()])
}

pub fn get_block_verbosity_one(
&self,
hash: BlockHash,
) -> Result<GetBlockVerbosityOne> {
pub fn get_block_verbosity_one(&self, hash: BlockHash) -> Result<GetBlockVerbosityOne> {
self.call("getblock", &[into_json(hash)?, 1.into()])
}
}
Expand All @@ -67,6 +64,112 @@ macro_rules! impl_client_v17__getblockchaininfo {
};
}

/// Implements bitcoind JSON-RPC API method `getblockcount`
#[macro_export]
macro_rules! impl_client_v17__getblockcount {
() => {
impl Client {
pub fn get_block_count(&self) -> Result<GetBlockCount> {
self.call("getblockcount", &[])
}
}
};
}

/// Implements bitcoind JSON-RPC API method `getblockhash`
#[macro_export]
macro_rules! impl_client_v17__getblockhash {
() => {
impl Client {
pub fn get_block_hash(&self, height: u64) -> Result<GetBlockHash> {
self.call("getblockhash", &[into_json(height)?])
}
}
};
}

/// Implements bitcoind JSON-RPC API method `getblockheader`
#[macro_export]
macro_rules! impl_client_v17__getblockheader {
() => {
impl Client {
pub fn get_block_header(&self, hash: &BlockHash) -> Result<GetBlockHeader> {
self.call("getblockheader", &[into_json(hash)?, into_json(false)?])
}

// This is the same as calling getblockheader with verbose==true.
pub fn get_block_header_verbose(
&self,
hash: &BlockHash,
) -> Result<GetBlockHeaderVerbose> {
self.call("getblockheader", &[into_json(hash)?])
}
}
};
}

/// Implements bitcoind JSON-RPC API method `getblockstats`
#[macro_export]
macro_rules! impl_client_v17__getblockstats {
() => {
impl Client {
pub fn get_block_stats_by_height(&self, height: u32) -> Result<GetBlockStats> {
self.call("getblockstats", &[into_json(height)?])
}

pub fn get_block_stats_by_block_hash(&self, hash: &BlockHash) -> Result<GetBlockStats> {
self.call("getblockstats", &[into_json(hash)?])
}
}
};
}

/// Implements bitcoind JSON-RPC API method `getchaintips`
#[macro_export]
macro_rules! impl_client_v17__getchaintips {
() => {
impl Client {
pub fn get_chain_tips(&self) -> Result<GetChainTips> { self.call("getchaintips", &[]) }
}
};
}

/// Implements bitcoind JSON-RPC API method `getchaintxstats`
#[macro_export]
macro_rules! impl_client_v17__getchaintxstats {
() => {
impl Client {
pub fn get_chain_tx_stats(&self) -> Result<GetChainTxStats> {
self.call("getchaintxstats", &[])
}
}
};
}

/// Implements bitcoind JSON-RPC API method `getdifficulty`
#[macro_export]
macro_rules! impl_client_v17__getdifficulty {
() => {
impl Client {
pub fn get_difficulty(&self) -> Result<GetDifficulty> {
self.call("getdifficulty", &[])
}
}
};
}

/// Implements bitcoind JSON-RPC API method `getmempoolancestors`
#[macro_export]
macro_rules! impl_client_v17__getmempoolancestors {
() => {
impl Client {
pub fn get_mempool_ancestors(&self, txid: Txid) -> Result<GetMempoolAncestors> {
self.call("getmempoolancestors", &[into_json(txid)?])
}
}
};
}

/// Implements bitcoind JSON-RPC API method `gettxout`
#[macro_export]
macro_rules! impl_client_v17__gettxout {
Expand Down
8 changes: 8 additions & 0 deletions client/src/client_sync/v17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@ crate::impl_client_v17__getblockchaininfo!();
crate::impl_client_v17__getbestblockhash!();
crate::impl_client_v17__getblock!();
crate::impl_client_v17__gettxout!();
crate::impl_client_v17__getblockcount!();
crate::impl_client_v17__getblockhash!();
crate::impl_client_v17__getblockheader!();
crate::impl_client_v17__getblockstats!();
crate::impl_client_v17__getchaintips!();
crate::impl_client_v17__getchaintxstats!();
crate::impl_client_v17__getdifficulty!();
crate::impl_client_v17__getmempoolancestors!();

// == Control ==
crate::impl_client_v17__stop!();
Expand Down
125 changes: 124 additions & 1 deletion integration_test/src/v17/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,134 @@ macro_rules! impl_test_v17__getblockchaininfo {
};
}

/// Requires `Client` to be in scope and to implement `getblockcount`.
#[macro_export]
macro_rules! impl_test_v17__getblockcount {
() => {
#[test]
fn get_block_count() {
let bitcoind = $crate::bitcoind_no_wallet();
let json = bitcoind.client.get_block_count().expect("getblockcount");
let _ = json.into_model();
}
};
}

/// Requires `Client` to be in scope and to implement `getblockhash`.
#[macro_export]
macro_rules! impl_test_v17__getblockhash {
() => {
#[test]
fn get_block_hash() {
let bitcoind = $crate::bitcoind_no_wallet();
let json = bitcoind.client.get_block_hash(0).expect("getblockhash");
assert!(json.into_model().is_ok());
}
};
}

/// Requires `Client` to be in scope and to implement `getblockheader`.
#[macro_export]
macro_rules! impl_test_v17__getblockheader {
() => {
#[test]
fn get_block_header() { // verbose = false
let bitcoind = $crate::bitcoind_no_wallet();
let block_hash = best_block_hash();
let json = bitcoind.client.get_block_header(&block_hash).expect("getblockheader");
assert!(json.into_model().is_ok());
}

#[test]
fn get_block_header_verbose() { // verbose = true
let bitcoind = $crate::bitcoind_no_wallet();
let block_hash = best_block_hash();
let json = bitcoind.client.get_block_header_verbose(&block_hash).expect("getblockheader");
assert!(json.into_model().is_ok());
}
};
}

/// Requires `Client` to be in scope and to implement `getblockstats`.
#[macro_export]
macro_rules! impl_test_v17__getblockstats {
() => {
#[test]
fn get_block_stats_by_height() {
let bitcoind = $crate::bitcoind_no_wallet();
let json = bitcoind.client.get_block_stats_by_height(0).expect("getblockstats");
assert!(json.into_model().is_ok());
}

#[test]
fn get_block_stats_by_hash() { // verbose = true
let bitcoind = $crate::bitcoind_no_wallet();
let block_hash = best_block_hash();
let json = bitcoind.client.get_block_stats_by_block_hash(&block_hash).expect("getblockstats");
assert!(json.into_model().is_ok());
}
};
}

/// Requires `Client` to be in scope and to implement `getchaintips`.
#[macro_export]
macro_rules! impl_test_v17__getchaintips {
() => {
#[test]
fn get_chain_tips() {
let bitcoind = $crate::bitcoind_no_wallet();
let json = bitcoind.client.get_chain_tips().expect("getchaintips");
assert!(json.into_model().is_ok());
}
}
}

/// Requires `Client` to be in scope and to implement `getchaintxstats`.
#[macro_export]
macro_rules! impl_test_v17__getchaintxstats {
() => {
#[test]
fn get_chain_tx_stats() {
let bitcoind = $crate::bitcoind_no_wallet();
let json = bitcoind.client.get_chain_tx_stats().expect("getchaintxstats");
assert!(json.into_model().is_ok());
}
}
}

/// Requires `Client` to be in scope and to implement `getdifficulty`.
#[macro_export]
macro_rules! impl_test_v17__getdifficulty {
() => {
#[test]
fn get_difficulty() {
let bitcoind = $crate::bitcoind_no_wallet();
let json = bitcoind.client.get_difficulty().expect("getdifficulty");
let _ = json.into_model();
}
}
}

/// Requires `Client` to be in scope and to implement `getmempoolancestors`.
#[macro_export]
macro_rules! impl_test_v17__getmempoolancestors {
() => {
#[test]
fn get_mempool_ancestors() {
// FIXME: We need a valid txid to test this.
todo!()
}
}
}

/// Requires `Client` to be in scope and to implement `get_tx_out`.
#[macro_export]
macro_rules! impl_test_v17__gettxout {
() => {
#[test]
fn get_tx_out() { todo!() }
fn get_tx_out() {
// FIXME: We need a valid txid to test this.
todo!()
}
};
}
7 changes: 7 additions & 0 deletions integration_test/tests/v17_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ mod blockchain {
impl_test_v17__getblock_verbosity_0!();
impl_test_v17__getblock_verbosity_1!();
impl_test_v17__getblockchaininfo!();
impl_test_v17__getblockcount!();
impl_test_v17__getblockhash!();
impl_test_v17__getblockheader!();
impl_test_v17__getblockstats!();
impl_test_v17__getchaintips!();
impl_test_v17__getchaintxstats!();
impl_test_v17__getdifficulty!();
}

// == Control ==
Expand Down
Loading
Loading