Skip to content

Commit bbd3d56

Browse files
committed
Merge #314: Address all TODO in v26
cb12454 Run the formatter (Jamil Lambert, PhD) 37b0821 Add getaddrmaninfo struct and test (Jamil Lambert, PhD) 9ee00e0 Redefine getprioritisedtransactions (Jamil Lambert, PhD) e163f93 Implement importmempool method and test (Jamil Lambert, PhD) 90df558 Add getchainstates method, model and test (Jamil Lambert, PhD) 0d7f6ce Add loadtxoutset method and model (Jamil Lambert, PhD) 6f5145d Add dumptxoutset method, model and test (Jamil Lambert, PhD) c891dc9 Move v26 blockchain to subdirectory (Jamil Lambert, PhD) Pull request description: Go through all the TODO in the v26 types table. Add all the missing RPCs. - Move the blockchain module to a subdirectory with separate `into.rs` and `error.rs` files in preparation for adding the new RPCs. Code move only. - Add `dumptxoutset` method, model and test. An extra required (help says optional) argument was added in v29, update the client macro and test. - Add `loadtxoutset` method and model. It was not possible to test this, opened Issue #313. - Add `getchainstates` method, model and test. Extra return fields added in v29, redefine the struct and into_model fn. - Implement `importmempool` method and test. Returns an empty json object, add the client macro and test. - Redefine getprioritisedtransactions. Add the extra return field in v27. Also change the model so that the `fee_delta` is an `Amount`. - Add getaddrmaninfo struct and test. Was marked as having a model, but nothing to model. Update the types table. - Run the formatter. ACKs for top commit: tcharding: ACK cb12454 Tree-SHA512: 2d8b98329cb629552c7747c503a9ec494a4011867782c96ab01bd1e6dd2c53b55da0d37b978ebf7a07e184e8c0dd455c02119545be83270ae1cbc56b514f6eb7
2 parents 35ef25c + cb12454 commit bbd3d56

File tree

31 files changed

+942
-176
lines changed

31 files changed

+942
-176
lines changed

client/src/client_sync/v26/blockchain.rs

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,30 @@
99
//!
1010
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
1111
12+
/// Implements Bitcoin Core JSON-RPC API method `dumptxoutset`.
13+
#[macro_export]
14+
macro_rules! impl_client_v26__dump_tx_out_set {
15+
() => {
16+
impl Client {
17+
pub fn dump_tx_out_set(&self, path: &str) -> Result<DumpTxOutSet> {
18+
self.call("dumptxoutset", &[path.into()])
19+
}
20+
}
21+
};
22+
}
23+
24+
/// Implements Bitcoin Core JSON-RPC API method `getchainstates`.
25+
#[macro_export]
26+
macro_rules! impl_client_v26__get_chain_states {
27+
() => {
28+
impl Client {
29+
pub fn get_chain_states(&self) -> Result<GetChainStates> {
30+
self.call("getchainstates", &[])
31+
}
32+
}
33+
};
34+
}
35+
1236
/// Implements Bitcoin Core JSON-RPC API method `gettxoutsetinfo`.
1337
#[macro_export]
1438
macro_rules! impl_client_v26__get_tx_out_set_info {
@@ -20,3 +44,31 @@ macro_rules! impl_client_v26__get_tx_out_set_info {
2044
}
2145
};
2246
}
47+
48+
/// Implements Bitcoin Core JSON-RPC API method `importmempool`.
49+
#[macro_export]
50+
macro_rules! impl_client_v26__import_mempool {
51+
() => {
52+
impl Client {
53+
pub fn import_mempool(&self, filepath: &str) -> Result<()> {
54+
match self.call("importmempool", &[filepath.into()]) {
55+
Ok(serde_json::Value::Object(ref map)) if map.is_empty() => Ok(()),
56+
Ok(res) => Err(Error::Returned(res.to_string())),
57+
Err(err) => Err(err.into()),
58+
}
59+
}
60+
}
61+
};
62+
}
63+
64+
/// Implements Bitcoin Core JSON-RPC API method `loadtxoutset`.
65+
#[macro_export]
66+
macro_rules! impl_client_v26__load_tx_out_set {
67+
() => {
68+
impl Client {
69+
pub fn load_tx_out_set(&self, path: &str) -> Result<LoadTxOutSet> {
70+
self.call("loadtxoutset", &[path.into()])
71+
}
72+
}
73+
};
74+
}

client/src/client_sync/v26/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
77
pub mod blockchain;
88
pub mod mining;
9+
pub mod network;
910
pub mod raw_transactions;
1011

1112
use std::collections::BTreeMap;
@@ -31,6 +32,7 @@ crate::define_jsonrpc_minreq_client!("v26");
3132
crate::impl_client_check_expected_server_version!({ [260000, 260100, 260200] });
3233

3334
// == Blockchain ==
35+
crate::impl_client_v26__dump_tx_out_set!();
3436
crate::impl_client_v17__get_best_block_hash!();
3537
crate::impl_client_v17__get_block!();
3638
crate::impl_client_v17__get_blockchain_info!();
@@ -40,6 +42,7 @@ crate::impl_client_v23__get_block_from_peer!();
4042
crate::impl_client_v17__get_block_hash!();
4143
crate::impl_client_v17__get_block_header!();
4244
crate::impl_client_v17__get_block_stats!();
45+
crate::impl_client_v26__get_chain_states!();
4346
crate::impl_client_v17__get_chain_tips!();
4447
crate::impl_client_v17__get_chain_tx_stats!();
4548
crate::impl_client_v23__get_deployment_info!();
@@ -53,6 +56,8 @@ crate::impl_client_v17__get_tx_out!();
5356
crate::impl_client_v17__get_tx_out_proof!();
5457
crate::impl_client_v26__get_tx_out_set_info!();
5558
crate::impl_client_v24__get_tx_spending_prevout!();
59+
crate::impl_client_v26__import_mempool!();
60+
crate::impl_client_v26__load_tx_out_set!();
5661
crate::impl_client_v17__precious_block!();
5762
crate::impl_client_v17__prune_blockchain!();
5863
crate::impl_client_v23__save_mempool!();
@@ -88,6 +93,7 @@ crate::impl_client_v17__add_node!();
8893
crate::impl_client_v17__clear_banned!();
8994
crate::impl_client_v17__disconnect_node!();
9095
crate::impl_client_v17__get_added_node_info!();
96+
crate::impl_client_v26__get_addr_man_info!();
9197
crate::impl_client_v17__get_connection_count!();
9298
crate::impl_client_v17__get_net_totals!();
9399
crate::impl_client_v17__get_network_info!();
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! Macros for implementing JSON-RPC methods on a client.
4+
//!
5+
//! Requires `Client` to be in scope.
6+
//!
7+
//! Specifically this is methods found under the `== Network ==` section of the
8+
//! API docs of Bitcoin Core `v26`.
9+
//!
10+
//! See, or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
11+
12+
/// Implements Bitcoin Core JSON-RPC API method `getaddrmaninfo`.
13+
#[macro_export]
14+
macro_rules! impl_client_v26__get_addr_man_info {
15+
() => {
16+
impl Client {
17+
pub fn get_addr_man_info(&self) -> Result<GetAddrManInfo> {
18+
self.call("getaddrmaninfo", &[])
19+
}
20+
}
21+
};
22+
}

client/src/client_sync/v27/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ crate::define_jsonrpc_minreq_client!("v27");
2727
crate::impl_client_check_expected_server_version!({ [270000, 270100, 270200] });
2828

2929
// == Blockchain ==
30+
crate::impl_client_v26__dump_tx_out_set!();
3031
crate::impl_client_v17__get_best_block_hash!();
3132
crate::impl_client_v17__get_block!();
3233
crate::impl_client_v17__get_blockchain_info!();
@@ -36,6 +37,7 @@ crate::impl_client_v23__get_block_from_peer!();
3637
crate::impl_client_v17__get_block_hash!();
3738
crate::impl_client_v17__get_block_header!();
3839
crate::impl_client_v17__get_block_stats!();
40+
crate::impl_client_v26__get_chain_states!();
3941
crate::impl_client_v17__get_chain_tips!();
4042
crate::impl_client_v17__get_chain_tx_stats!();
4143
crate::impl_client_v23__get_deployment_info!();
@@ -49,6 +51,7 @@ crate::impl_client_v17__get_tx_out!();
4951
crate::impl_client_v17__get_tx_out_proof!();
5052
crate::impl_client_v26__get_tx_out_set_info!();
5153
crate::impl_client_v24__get_tx_spending_prevout!();
54+
crate::impl_client_v26__import_mempool!();
5255
crate::impl_client_v17__precious_block!();
5356
crate::impl_client_v17__prune_blockchain!();
5457
crate::impl_client_v23__save_mempool!();
@@ -84,6 +87,7 @@ crate::impl_client_v17__add_node!();
8487
crate::impl_client_v17__clear_banned!();
8588
crate::impl_client_v17__disconnect_node!();
8689
crate::impl_client_v17__get_added_node_info!();
90+
crate::impl_client_v26__get_addr_man_info!();
8791
crate::impl_client_v17__get_connection_count!();
8892
crate::impl_client_v17__get_net_totals!();
8993
crate::impl_client_v17__get_network_info!();

client/src/client_sync/v28/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ crate::define_jsonrpc_minreq_client!("v28");
2929
crate::impl_client_check_expected_server_version!({ [280000, 280100, 280200] });
3030

3131
// == Blockchain ==
32+
crate::impl_client_v26__dump_tx_out_set!();
3233
crate::impl_client_v17__get_best_block_hash!();
3334
crate::impl_client_v17__get_block!();
3435
crate::impl_client_v17__get_blockchain_info!();
@@ -38,6 +39,7 @@ crate::impl_client_v23__get_block_from_peer!();
3839
crate::impl_client_v17__get_block_hash!();
3940
crate::impl_client_v17__get_block_header!();
4041
crate::impl_client_v17__get_block_stats!();
42+
crate::impl_client_v26__get_chain_states!();
4143
crate::impl_client_v17__get_chain_tips!();
4244
crate::impl_client_v17__get_chain_tx_stats!();
4345
crate::impl_client_v23__get_deployment_info!();
@@ -51,6 +53,7 @@ crate::impl_client_v17__get_tx_out!();
5153
crate::impl_client_v17__get_tx_out_proof!();
5254
crate::impl_client_v26__get_tx_out_set_info!();
5355
crate::impl_client_v24__get_tx_spending_prevout!();
56+
crate::impl_client_v26__import_mempool!();
5457
crate::impl_client_v17__precious_block!();
5558
crate::impl_client_v17__prune_blockchain!();
5659
crate::impl_client_v23__save_mempool!();
@@ -86,6 +89,7 @@ crate::impl_client_v17__add_node!();
8689
crate::impl_client_v17__clear_banned!();
8790
crate::impl_client_v17__disconnect_node!();
8891
crate::impl_client_v17__get_added_node_info!();
92+
crate::impl_client_v26__get_addr_man_info!();
8993
crate::impl_client_v17__get_connection_count!();
9094
crate::impl_client_v17__get_net_totals!();
9195
crate::impl_client_v17__get_network_info!();

client/src/client_sync/v29/blockchain.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@
99
//!
1010
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
1111
12+
/// Implements Bitcoin Core JSON-RPC API method `dumptxoutset`.
13+
#[macro_export]
14+
macro_rules! impl_client_v29__dump_tx_out_set {
15+
() => {
16+
impl Client {
17+
pub fn dump_tx_out_set(&self, path: &str, snapshot_type: &str) -> Result<DumpTxOutSet> {
18+
self.call("dumptxoutset", &[path.into(), snapshot_type.into()])
19+
}
20+
}
21+
};
22+
}
23+
1224
/// Implements Bitcoin Core JSON-RPC API method `getdescriptoractivity`.
1325
#[macro_export]
1426
macro_rules! impl_client_v29__get_descriptor_activity {

client/src/client_sync/v29/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ crate::define_jsonrpc_minreq_client!("v29");
2828
crate::impl_client_check_expected_server_version!({ [290000] });
2929

3030
// == Blockchain ==
31+
crate::impl_client_v29__dump_tx_out_set!();
3132
crate::impl_client_v17__get_best_block_hash!();
3233
crate::impl_client_v17__get_block!();
3334
crate::impl_client_v17__get_blockchain_info!();
@@ -37,6 +38,7 @@ crate::impl_client_v23__get_block_from_peer!();
3738
crate::impl_client_v17__get_block_hash!();
3839
crate::impl_client_v17__get_block_header!();
3940
crate::impl_client_v17__get_block_stats!();
41+
crate::impl_client_v26__get_chain_states!();
4042
crate::impl_client_v17__get_chain_tips!();
4143
crate::impl_client_v17__get_chain_tx_stats!();
4244
crate::impl_client_v23__get_deployment_info!();
@@ -51,6 +53,7 @@ crate::impl_client_v17__get_tx_out!();
5153
crate::impl_client_v17__get_tx_out_proof!();
5254
crate::impl_client_v26__get_tx_out_set_info!();
5355
crate::impl_client_v24__get_tx_spending_prevout!();
56+
crate::impl_client_v26__import_mempool!();
5457
crate::impl_client_v17__precious_block!();
5558
crate::impl_client_v17__prune_blockchain!();
5659
crate::impl_client_v23__save_mempool!();
@@ -86,6 +89,7 @@ crate::impl_client_v17__add_node!();
8689
crate::impl_client_v17__clear_banned!();
8790
crate::impl_client_v17__disconnect_node!();
8891
crate::impl_client_v17__get_added_node_info!();
92+
crate::impl_client_v26__get_addr_man_info!();
8993
crate::impl_client_v17__get_connection_count!();
9094
crate::impl_client_v17__get_net_totals!();
9195
crate::impl_client_v17__get_network_info!();

integration_test/tests/blockchain.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,30 @@ use node::client::client_sync;
99
use node::vtype::*; // All the version specific types.
1010
use node::mtype;
1111

12+
#[test]
13+
#[cfg(not(feature = "v25_and_below"))]
14+
fn blockchain__dump_tx_out_set__modelled() {
15+
let node = Node::with_wallet(Wallet::Default, &[]);
16+
node.fund_wallet();
17+
let (_address, _tx) = node.create_mined_transaction();
18+
19+
let temp_path = integration_test::random_tmp_file();
20+
let path = temp_path.to_str().expect("temp path should be valid UTF-8");
21+
let json: DumpTxOutSet;
22+
#[cfg(feature = "v28_and_below")]
23+
{
24+
json = node.client.dump_tx_out_set(path).expect("dumptxoutset");
25+
}
26+
#[cfg(not(feature = "v28_and_below"))]
27+
{
28+
json = node.client.dump_tx_out_set(path, "latest").expect("dumptxoutset");
29+
}
30+
let model: Result<mtype::DumpTxOutSet, DumpTxOutSetError> = json.into_model();
31+
let dump = model.unwrap();
32+
33+
assert!(dump.coins_written.to_sat() > 0);
34+
}
35+
1236
#[test]
1337
fn blockchain__get_best_block_hash__modelled() {
1438
let node = Node::with_wallet(Wallet::None, &[]);
@@ -160,6 +184,20 @@ fn getblockstats_txindex() {
160184
json.into_model().unwrap();
161185
}
162186

187+
#[test]
188+
#[cfg(not(feature = "v25_and_below"))]
189+
fn blockchain__get_chain_states__modelled() {
190+
let node = Node::with_wallet(Wallet::Default, &[]);
191+
node.fund_wallet();
192+
let (_address, _tx) = node.create_mined_transaction();
193+
194+
let json: GetChainStates = node.client.get_chain_states().expect("getchainstates");
195+
let model: Result<mtype::GetChainStates, _> = json.into_model();
196+
let chain_states = model.unwrap();
197+
198+
assert!(chain_states.chain_states[0].blocks > 0);
199+
}
200+
163201
#[test]
164202
fn blockchain__get_chain_tips__modelled() {
165203
let node = Node::with_wallet(Wallet::None, &[]);
@@ -331,6 +369,18 @@ fn blockchain__get_tx_spending_prevout__modelled() {
331369
assert_eq!(spending_prevout.0[0].outpoint.vout, 0);
332370
}
333371

372+
#[test]
373+
#[cfg(not(feature = "v25_and_below"))]
374+
fn blockchain__import_mempool() {
375+
let node = Node::with_wallet(Wallet::Default, &[]);
376+
node.fund_wallet();
377+
let (_address, _tx) = node.create_mined_transaction();
378+
379+
let mempool_path = node.client.save_mempool().expect("savemempool");
380+
381+
let _: () = node.client.import_mempool(&mempool_path.filename).expect("importmempool");
382+
}
383+
334384
#[test]
335385
fn blockchain__precious_block() {
336386
let node = Node::with_wallet(Wallet::Default, &[]);

integration_test/tests/network.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,19 @@ fn network__get_added_node_info() {
4949
let _: GetAddedNodeInfo = node.client.get_added_node_info().expect("getaddednodeinfo");
5050
}
5151

52+
#[test]
53+
#[cfg(not(feature = "v25_and_below"))]
54+
fn network__get_addr_man_info() {
55+
let node = Node::with_wallet(Wallet::None, &[]);
56+
let json: GetAddrManInfo = node.client.get_addr_man_info().expect("getaddrmaninfo");
57+
assert!(!json.0.is_empty());
58+
59+
for (network_name, network_info) in &json.0 {
60+
assert!(!network_name.is_empty());
61+
assert_eq!(network_info.total, network_info.new + network_info.tried);
62+
};
63+
}
64+
5265
#[test]
5366
fn network__get_connection_count() {
5467
let node = Node::with_wallet(Wallet::None, &[]);

0 commit comments

Comments
 (0)