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

Commit d4301fc

Browse files
authored
Move code for getblock (#26)
Seems that we added the `getblock` stuff in the order we implemented it instead of in some sane order. Move the code for `getblock` so it is in the same order in code as it is listed in the `rpc-api.txt` file. Code move only, no other changes.
2 parents bb5a9ff + 463bd33 commit d4301fc

File tree

15 files changed

+255
-255
lines changed

15 files changed

+255
-255
lines changed

client/src/client_sync/v17/blockchain.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,6 @@
99
//!
1010
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
1111
12-
/// Implements bitcoind JSON-RPC API method `getblockchaininfo`
13-
#[macro_export]
14-
macro_rules! impl_client_v17__getblockchaininfo {
15-
() => {
16-
impl Client {
17-
pub fn get_blockchain_info(&self) -> Result<GetBlockchainInfo> {
18-
self.call("getblockchaininfo", &[])
19-
}
20-
}
21-
};
22-
}
23-
2412
/// Implements bitcoind JSON-RPC API method `getbestblockhash`
2513
#[macro_export]
2614
macro_rules! impl_client_v17__getbestblockhash {
@@ -70,6 +58,18 @@ macro_rules! impl_client_v17__getblock {
7058
};
7159
}
7260

61+
/// Implements bitcoind JSON-RPC API method `getblockchaininfo`
62+
#[macro_export]
63+
macro_rules! impl_client_v17__getblockchaininfo {
64+
() => {
65+
impl Client {
66+
pub fn get_blockchain_info(&self) -> Result<GetBlockchainInfo> {
67+
self.call("getblockchaininfo", &[])
68+
}
69+
}
70+
};
71+
}
72+
7373
/// Implements bitcoind JSON-RPC API method `gettxout`
7474
#[macro_export]
7575
macro_rules! impl_client_v17__gettxout {

integration_test/src/v17/blockchain.rs

+13-13
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,6 @@
55
//! Specifically this is methods found under the `== Blockchain ==` section of the
66
//! API docs of `bitcoind v0.17.1`.
77
8-
/// Requires `Client` to be in scope and to implement `get_blockchain_info`.
9-
#[macro_export]
10-
macro_rules! impl_test_v17__getblockchaininfo {
11-
() => {
12-
#[test]
13-
fn get_blockchain_info() {
14-
let bitcoind = $crate::bitcoind_no_wallet();
15-
let json = bitcoind.client.get_blockchain_info().expect("getblockchaininfo");
16-
assert!(json.into_model().is_ok());
17-
}
18-
};
19-
}
20-
218
/// Requires `Client` to be in scope and to implement `get_best_block_hash`.
229
#[macro_export]
2310
macro_rules! impl_test_v17__getbestblockhash {
@@ -81,6 +68,19 @@ macro_rules! impl_test_v17__getblock_verbosity_2 {
8168
};
8269
}
8370

71+
/// Requires `Client` to be in scope and to implement `get_blockchain_info`.
72+
#[macro_export]
73+
macro_rules! impl_test_v17__getblockchaininfo {
74+
() => {
75+
#[test]
76+
fn get_blockchain_info() {
77+
let bitcoind = $crate::bitcoind_no_wallet();
78+
let json = bitcoind.client.get_blockchain_info().expect("getblockchaininfo");
79+
assert!(json.into_model().is_ok());
80+
}
81+
};
82+
}
83+
8484
/// Requires `Client` to be in scope and to implement `get_tx_out`.
8585
#[macro_export]
8686
macro_rules! impl_test_v17__gettxout {

integration_test/tests/v17_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use integration_test::*;
88
mod blockchain {
99
use super::*;
1010

11-
impl_test_v17__getblockchaininfo!();
1211
impl_test_v17__getbestblockhash!();
1312
impl_test_v17__getblock_verbosity_0!();
1413
impl_test_v17__getblock_verbosity_1!();
14+
impl_test_v17__getblockchaininfo!();
1515
}
1616

1717
// == Control ==

integration_test/tests/v18_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use integration_test::*;
88
mod blockchain {
99
use super::*;
1010

11-
impl_test_v17__getblockchaininfo!();
1211
impl_test_v17__getbestblockhash!();
1312
impl_test_v17__getblock_verbosity_0!();
1413
impl_test_v17__getblock_verbosity_1!();
14+
impl_test_v17__getblockchaininfo!();
1515
}
1616

1717
// == Control ==

integration_test/tests/v19_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use integration_test::*;
88
mod blockchain {
99
use super::*;
1010

11-
impl_test_v17__getblockchaininfo!();
1211
impl_test_v17__getbestblockhash!();
1312
impl_test_v17__getblock_verbosity_0!();
1413
impl_test_v17__getblock_verbosity_1!();
14+
impl_test_v17__getblockchaininfo!();
1515
}
1616

1717
// == Control ==

integration_test/tests/v20_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use integration_test::*;
88
mod blockchain {
99
use super::*;
1010

11-
impl_test_v17__getblockchaininfo!();
1211
impl_test_v17__getbestblockhash!();
1312
impl_test_v17__getblock_verbosity_0!();
1413
impl_test_v17__getblock_verbosity_1!();
14+
impl_test_v17__getblockchaininfo!();
1515
}
1616

1717
// == Control ==

integration_test/tests/v21_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use integration_test::*;
88
mod blockchain {
99
use super::*;
1010

11-
impl_test_v17__getblockchaininfo!();
1211
impl_test_v17__getbestblockhash!();
1312
impl_test_v17__getblock_verbosity_0!();
1413
impl_test_v17__getblock_verbosity_1!();
14+
impl_test_v17__getblockchaininfo!();
1515
}
1616

1717
// == Control ==

integration_test/tests/v22_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use integration_test::*;
88
mod blockchain {
99
use super::*;
1010

11-
impl_test_v17__getblockchaininfo!();
1211
impl_test_v17__getbestblockhash!();
1312
impl_test_v17__getblock_verbosity_0!();
1413
impl_test_v17__getblock_verbosity_1!();
14+
impl_test_v17__getblockchaininfo!();
1515
}
1616

1717
// == Control ==

integration_test/tests/v23_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use integration_test::*;
88
mod blockchain {
99
use super::*;
1010

11-
impl_test_v17__getblockchaininfo!();
1211
impl_test_v17__getbestblockhash!();
1312
impl_test_v17__getblock_verbosity_0!();
1413
impl_test_v17__getblock_verbosity_1!();
14+
impl_test_v17__getblockchaininfo!();
1515
}
1616

1717
// == Control ==

integration_test/tests/v24_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use integration_test::*;
88
mod blockchain {
99
use super::*;
1010

11-
impl_test_v17__getblockchaininfo!();
1211
impl_test_v17__getbestblockhash!();
1312
impl_test_v17__getblock_verbosity_0!();
1413
impl_test_v17__getblock_verbosity_1!();
14+
impl_test_v17__getblockchaininfo!();
1515
}
1616

1717
// == Control ==

integration_test/tests/v25_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use integration_test::*;
88
mod blockchain {
99
use super::*;
1010

11-
impl_test_v17__getblockchaininfo!();
1211
impl_test_v17__getbestblockhash!();
1312
impl_test_v17__getblock_verbosity_0!();
1413
impl_test_v17__getblock_verbosity_1!();
14+
impl_test_v17__getblockchaininfo!();
1515
}
1616

1717
// == Control ==

integration_test/tests/v26_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use integration_test::*;
88
mod blockchain {
99
use super::*;
1010

11-
impl_test_v17__getblockchaininfo!();
1211
impl_test_v17__getbestblockhash!();
1312
impl_test_v17__getblock_verbosity_0!();
1413
impl_test_v17__getblock_verbosity_1!();
14+
impl_test_v17__getblockchaininfo!();
1515
}
1616

1717
// == Control ==

integration_test/tests/v27_api.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use integration_test::*;
88
mod blockchain {
99
use super::*;
1010

11-
impl_test_v17__getblockchaininfo!();
1211
impl_test_v17__getbestblockhash!();
1312
impl_test_v17__getblock_verbosity_0!();
1413
impl_test_v17__getblock_verbosity_1!();
14+
impl_test_v17__getblockchaininfo!();
1515
}
1616

1717
// == Control ==

json/src/model/blockchain.rs

+47-47
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,53 @@ use serde::{Deserialize, Serialize};
1717
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
1818
pub struct GetBestBlockHash(pub BlockHash);
1919

20+
/// Models the result of JSON-RPC method `getblock` with verbosity set to 0.
21+
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
22+
pub struct GetBlockVerbosityZero(pub Block);
23+
24+
/// Models the result of JSON-RPC method `getblock` with verbosity set to 1.
25+
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
26+
pub struct GetBlockVerbosityOne {
27+
/// The block hash (same as provided) in RPC call.
28+
pub hash: BlockHash,
29+
/// The number of confirmations, or -1 if the block is not on the main chain.
30+
pub confirmations: i32,
31+
/// The block size.
32+
pub size: usize,
33+
/// The block size excluding witness data.
34+
pub stripped_size: Option<usize>, // Weight?
35+
/// The block weight as defined in BIP-141.
36+
pub weight: Weight,
37+
/// The block height or index.
38+
pub height: usize,
39+
/// The block version.
40+
pub version: block::Version,
41+
/// The block version formatted in hexadecimal.
42+
pub version_hex: String,
43+
/// The merkle root.
44+
pub merkle_root: String,
45+
/// The transaction ids.
46+
pub tx: Vec<Txid>,
47+
/// The block time expressed in UNIX epoch time.
48+
pub time: usize,
49+
/// The median block time expressed in UNIX epoch time.
50+
pub median_time: Option<usize>,
51+
/// The nonce.
52+
pub nonce: u32,
53+
/// The bits.
54+
pub bits: CompactTarget,
55+
/// The difficulty.
56+
pub difficulty: f64,
57+
/// Expected number of hashes required to produce the chain up to this block (in hex).
58+
pub chain_work: Work,
59+
/// The number of transactions in the block.
60+
pub n_tx: u32,
61+
/// The hash of the previous block (if available).
62+
pub previous_block_hash: Option<BlockHash>,
63+
/// The hash of the next block (if available).
64+
pub next_block_hash: Option<BlockHash>,
65+
}
66+
2067
/// Models the result of JSON-RPC method `getblockchaininfo`.
2168
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
2269
pub struct GetBlockchainInfo {
@@ -129,53 +176,6 @@ pub struct Bip9SoftforkStatistics {
129176
pub possible: Option<bool>,
130177
}
131178

132-
/// Models the result of JSON-RPC method `getblock` with verbosity set to 0.
133-
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
134-
pub struct GetBlockVerbosityZero(pub Block);
135-
136-
/// Models the result of JSON-RPC method `getblock` with verbosity set to 1.
137-
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
138-
pub struct GetBlockVerbosityOne {
139-
/// The block hash (same as provided) in RPC call.
140-
pub hash: BlockHash,
141-
/// The number of confirmations, or -1 if the block is not on the main chain.
142-
pub confirmations: i32,
143-
/// The block size.
144-
pub size: usize,
145-
/// The block size excluding witness data.
146-
pub stripped_size: Option<usize>, // Weight?
147-
/// The block weight as defined in BIP-141.
148-
pub weight: Weight,
149-
/// The block height or index.
150-
pub height: usize,
151-
/// The block version.
152-
pub version: block::Version,
153-
/// The block version formatted in hexadecimal.
154-
pub version_hex: String,
155-
/// The merkle root.
156-
pub merkle_root: String,
157-
/// The transaction ids.
158-
pub tx: Vec<Txid>,
159-
/// The block time expressed in UNIX epoch time.
160-
pub time: usize,
161-
/// The median block time expressed in UNIX epoch time.
162-
pub median_time: Option<usize>,
163-
/// The nonce.
164-
pub nonce: u32,
165-
/// The bits.
166-
pub bits: CompactTarget,
167-
/// The difficulty.
168-
pub difficulty: f64,
169-
/// Expected number of hashes required to produce the chain up to this block (in hex).
170-
pub chain_work: Work,
171-
/// The number of transactions in the block.
172-
pub n_tx: u32,
173-
/// The hash of the previous block (if available).
174-
pub previous_block_hash: Option<BlockHash>,
175-
/// The hash of the next block (if available).
176-
pub next_block_hash: Option<BlockHash>,
177-
}
178-
179179
/// Models the result of JSON-RPC method `gettxout`.
180180
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
181181
pub struct GetTxOut {

0 commit comments

Comments
 (0)