Skip to content

Commit 1acb6b7

Browse files
committed
Implement submit header and test
Add a test and client macro for `submitheader` for v18 and up. There are no changes up to v29.
1 parent cc2992e commit 1acb6b7

File tree

26 files changed

+67
-13
lines changed

26 files changed

+67
-13
lines changed

client/src/client_sync/v18/mining.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// SPDX-License-Identifier: CC0-1.0
2+
3+
//! Macros for implementing JSON-RPC methods on a client.
4+
//!
5+
//! Specifically this is methods found under the `== Mining ==` section of the
6+
//! API docs of Bitcoin Core `v0.18`.
7+
//!
8+
//! All macros require `Client` to be in scope.
9+
//!
10+
//! See or use the `define_jsonrpc_minreq_client!` macro to define a `Client`.
11+
12+
/// Implements Bitcoin Core JSON-RPC API method `submitheader`.
13+
#[macro_export]
14+
macro_rules! impl_client_v18__submit_header {
15+
() => {
16+
impl Client {
17+
pub fn submit_header(&self, header: &bitcoin::block::Header) -> Result<()> {
18+
let hexdata = bitcoin::consensus::encode::serialize_hex(header);
19+
match self.call("submitheader", &[hexdata.into()]) {
20+
Ok(serde_json::Value::Null) => Ok(()),
21+
Ok(res) => Err(Error::Returned(res.to_string())),
22+
Err(err) => Err(err.into()),
23+
}
24+
}
25+
}
26+
};
27+
}

client/src/client_sync/v18/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
//! We ignore option arguments unless they effect the shape of the returned JSON data.
66
77
pub mod control;
8+
pub mod mining;
89
pub mod network;
910
pub mod raw_transactions;
1011
pub mod util;
@@ -74,6 +75,7 @@ crate::impl_client_v17__get_mining_info!();
7475
crate::impl_client_v17__get_network_hashes_per_second!();
7576
crate::impl_client_v17__prioritise_transaction!();
7677
crate::impl_client_v17__submit_block!();
78+
crate::impl_client_v18__submit_header!();
7779

7880
// == Network ==
7981
crate::impl_client_v17__add_node!();

client/src/client_sync/v19/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ crate::impl_client_v17__get_mining_info!();
7171
crate::impl_client_v17__get_network_hashes_per_second!();
7272
crate::impl_client_v17__prioritise_transaction!();
7373
crate::impl_client_v17__submit_block!();
74+
crate::impl_client_v18__submit_header!();
7475

7576
// == Network ==
7677
crate::impl_client_v17__add_node!();

client/src/client_sync/v20/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ crate::impl_client_v17__get_mining_info!();
6868
crate::impl_client_v17__get_network_hashes_per_second!();
6969
crate::impl_client_v17__prioritise_transaction!();
7070
crate::impl_client_v17__submit_block!();
71+
crate::impl_client_v18__submit_header!();
7172

7273
// == Network ==
7374
crate::impl_client_v17__add_node!();

client/src/client_sync/v21/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ crate::impl_client_v17__get_mining_info!();
7070
crate::impl_client_v17__get_network_hashes_per_second!();
7171
crate::impl_client_v17__prioritise_transaction!();
7272
crate::impl_client_v17__submit_block!();
73+
crate::impl_client_v18__submit_header!();
7374

7475
// == Network ==
7576
crate::impl_client_v17__add_node!();

client/src/client_sync/v22/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ crate::impl_client_v17__get_mining_info!();
7070
crate::impl_client_v17__get_network_hashes_per_second!();
7171
crate::impl_client_v17__prioritise_transaction!();
7272
crate::impl_client_v17__submit_block!();
73+
crate::impl_client_v18__submit_header!();
7374

7475
// == Network ==
7576
crate::impl_client_v17__add_node!();

client/src/client_sync/v23/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ crate::impl_client_v17__get_mining_info!();
7272
crate::impl_client_v17__get_network_hashes_per_second!();
7373
crate::impl_client_v17__prioritise_transaction!();
7474
crate::impl_client_v17__submit_block!();
75+
crate::impl_client_v18__submit_header!();
7576

7677
// == Network ==
7778
crate::impl_client_v17__add_node!();

client/src/client_sync/v24/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ crate::impl_client_v17__get_mining_info!();
6969
crate::impl_client_v17__get_network_hashes_per_second!();
7070
crate::impl_client_v17__prioritise_transaction!();
7171
crate::impl_client_v17__submit_block!();
72+
crate::impl_client_v18__submit_header!();
7273

7374
// == Network ==
7475
crate::impl_client_v17__add_node!();

client/src/client_sync/v25/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ crate::impl_client_v17__get_mining_info!();
6969
crate::impl_client_v17__get_network_hashes_per_second!();
7070
crate::impl_client_v17__prioritise_transaction!();
7171
crate::impl_client_v17__submit_block!();
72+
crate::impl_client_v18__submit_header!();
7273

7374
// == Network ==
7475
crate::impl_client_v17__add_node!();

client/src/client_sync/v26/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ crate::impl_client_v17__get_network_hashes_per_second!();
7474
crate::impl_client_v26__get_prioritised_transactions!();
7575
crate::impl_client_v17__prioritise_transaction!();
7676
crate::impl_client_v17__submit_block!();
77+
crate::impl_client_v18__submit_header!();
7778

7879
// == Network ==
7980
crate::impl_client_v17__add_node!();

0 commit comments

Comments
 (0)