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

Move code for getblock #26

Merged
merged 1 commit into from
Sep 2, 2024
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
24 changes: 12 additions & 12 deletions client/src/client_sync/v17/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,6 @@
//!
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.

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

/// Implements bitcoind JSON-RPC API method `getbestblockhash`
#[macro_export]
macro_rules! impl_client_v17__getbestblockhash {
Expand Down Expand Up @@ -70,6 +58,18 @@ macro_rules! impl_client_v17__getblock {
};
}

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

/// Implements bitcoind JSON-RPC API method `gettxout`
#[macro_export]
macro_rules! impl_client_v17__gettxout {
Expand Down
26 changes: 13 additions & 13 deletions integration_test/src/v17/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@
//! Specifically this is methods found under the `== Blockchain ==` section of the
//! API docs of `bitcoind v0.17.1`.

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

/// Requires `Client` to be in scope and to implement `get_best_block_hash`.
#[macro_export]
macro_rules! impl_test_v17__getbestblockhash {
Expand Down Expand Up @@ -81,6 +68,19 @@ macro_rules! impl_test_v17__getblock_verbosity_2 {
};
}

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

/// Requires `Client` to be in scope and to implement `get_tx_out`.
#[macro_export]
macro_rules! impl_test_v17__gettxout {
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v17_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use integration_test::*;
mod blockchain {
use super::*;

impl_test_v17__getblockchaininfo!();
impl_test_v17__getbestblockhash!();
impl_test_v17__getblock_verbosity_0!();
impl_test_v17__getblock_verbosity_1!();
impl_test_v17__getblockchaininfo!();
}

// == Control ==
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v18_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use integration_test::*;
mod blockchain {
use super::*;

impl_test_v17__getblockchaininfo!();
impl_test_v17__getbestblockhash!();
impl_test_v17__getblock_verbosity_0!();
impl_test_v17__getblock_verbosity_1!();
impl_test_v17__getblockchaininfo!();
}

// == Control ==
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v19_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use integration_test::*;
mod blockchain {
use super::*;

impl_test_v17__getblockchaininfo!();
impl_test_v17__getbestblockhash!();
impl_test_v17__getblock_verbosity_0!();
impl_test_v17__getblock_verbosity_1!();
impl_test_v17__getblockchaininfo!();
}

// == Control ==
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v20_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use integration_test::*;
mod blockchain {
use super::*;

impl_test_v17__getblockchaininfo!();
impl_test_v17__getbestblockhash!();
impl_test_v17__getblock_verbosity_0!();
impl_test_v17__getblock_verbosity_1!();
impl_test_v17__getblockchaininfo!();
}

// == Control ==
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v21_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use integration_test::*;
mod blockchain {
use super::*;

impl_test_v17__getblockchaininfo!();
impl_test_v17__getbestblockhash!();
impl_test_v17__getblock_verbosity_0!();
impl_test_v17__getblock_verbosity_1!();
impl_test_v17__getblockchaininfo!();
}

// == Control ==
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v22_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use integration_test::*;
mod blockchain {
use super::*;

impl_test_v17__getblockchaininfo!();
impl_test_v17__getbestblockhash!();
impl_test_v17__getblock_verbosity_0!();
impl_test_v17__getblock_verbosity_1!();
impl_test_v17__getblockchaininfo!();
}

// == Control ==
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v23_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use integration_test::*;
mod blockchain {
use super::*;

impl_test_v17__getblockchaininfo!();
impl_test_v17__getbestblockhash!();
impl_test_v17__getblock_verbosity_0!();
impl_test_v17__getblock_verbosity_1!();
impl_test_v17__getblockchaininfo!();
}

// == Control ==
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v24_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use integration_test::*;
mod blockchain {
use super::*;

impl_test_v17__getblockchaininfo!();
impl_test_v17__getbestblockhash!();
impl_test_v17__getblock_verbosity_0!();
impl_test_v17__getblock_verbosity_1!();
impl_test_v17__getblockchaininfo!();
}

// == Control ==
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v25_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use integration_test::*;
mod blockchain {
use super::*;

impl_test_v17__getblockchaininfo!();
impl_test_v17__getbestblockhash!();
impl_test_v17__getblock_verbosity_0!();
impl_test_v17__getblock_verbosity_1!();
impl_test_v17__getblockchaininfo!();
}

// == Control ==
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v26_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use integration_test::*;
mod blockchain {
use super::*;

impl_test_v17__getblockchaininfo!();
impl_test_v17__getbestblockhash!();
impl_test_v17__getblock_verbosity_0!();
impl_test_v17__getblock_verbosity_1!();
impl_test_v17__getblockchaininfo!();
}

// == Control ==
Expand Down
2 changes: 1 addition & 1 deletion integration_test/tests/v27_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use integration_test::*;
mod blockchain {
use super::*;

impl_test_v17__getblockchaininfo!();
impl_test_v17__getbestblockhash!();
impl_test_v17__getblock_verbosity_0!();
impl_test_v17__getblock_verbosity_1!();
impl_test_v17__getblockchaininfo!();
}

// == Control ==
Expand Down
94 changes: 47 additions & 47 deletions json/src/model/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,53 @@ use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct GetBestBlockHash(pub BlockHash);

/// Models the result of JSON-RPC method `getblock` with verbosity set to 0.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct GetBlockVerbosityZero(pub Block);

/// Models the result of JSON-RPC method `getblock` with verbosity set to 1.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct GetBlockVerbosityOne {
/// The block hash (same as provided) in RPC call.
pub hash: BlockHash,
/// The number of confirmations, or -1 if the block is not on the main chain.
pub confirmations: i32,
/// The block size.
pub size: usize,
/// The block size excluding witness data.
pub stripped_size: Option<usize>, // Weight?
/// The block weight as defined in BIP-141.
pub weight: Weight,
/// The block height or index.
pub height: usize,
/// The block version.
pub version: block::Version,
/// The block version formatted in hexadecimal.
pub version_hex: String,
/// The merkle root.
pub merkle_root: String,
/// The transaction ids.
pub tx: Vec<Txid>,
/// The block time expressed in UNIX epoch time.
pub time: usize,
/// The median block time expressed in UNIX epoch time.
pub median_time: Option<usize>,
/// The nonce.
pub nonce: u32,
/// The bits.
pub bits: CompactTarget,
/// The difficulty.
pub difficulty: f64,
/// Expected number of hashes required to produce the chain up to this block (in hex).
pub chain_work: Work,
/// The number of transactions in the block.
pub n_tx: u32,
/// The hash of the previous block (if available).
pub previous_block_hash: Option<BlockHash>,
/// The hash of the next block (if available).
pub next_block_hash: Option<BlockHash>,
}

/// Models the result of JSON-RPC method `getblockchaininfo`.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct GetBlockchainInfo {
Expand Down Expand Up @@ -129,53 +176,6 @@ pub struct Bip9SoftforkStatistics {
pub possible: Option<bool>,
}

/// Models the result of JSON-RPC method `getblock` with verbosity set to 0.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct GetBlockVerbosityZero(pub Block);

/// Models the result of JSON-RPC method `getblock` with verbosity set to 1.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct GetBlockVerbosityOne {
/// The block hash (same as provided) in RPC call.
pub hash: BlockHash,
/// The number of confirmations, or -1 if the block is not on the main chain.
pub confirmations: i32,
/// The block size.
pub size: usize,
/// The block size excluding witness data.
pub stripped_size: Option<usize>, // Weight?
/// The block weight as defined in BIP-141.
pub weight: Weight,
/// The block height or index.
pub height: usize,
/// The block version.
pub version: block::Version,
/// The block version formatted in hexadecimal.
pub version_hex: String,
/// The merkle root.
pub merkle_root: String,
/// The transaction ids.
pub tx: Vec<Txid>,
/// The block time expressed in UNIX epoch time.
pub time: usize,
/// The median block time expressed in UNIX epoch time.
pub median_time: Option<usize>,
/// The nonce.
pub nonce: u32,
/// The bits.
pub bits: CompactTarget,
/// The difficulty.
pub difficulty: f64,
/// Expected number of hashes required to produce the chain up to this block (in hex).
pub chain_work: Work,
/// The number of transactions in the block.
pub n_tx: u32,
/// The hash of the previous block (if available).
pub previous_block_hash: Option<BlockHash>,
/// The hash of the next block (if available).
pub next_block_hash: Option<BlockHash>,
}

/// Models the result of JSON-RPC method `gettxout`.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct GetTxOut {
Expand Down
Loading
Loading