forked from rust-bitcoin/corepc
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmining.rs
More file actions
81 lines (75 loc) · 2.47 KB
/
mining.rs
File metadata and controls
81 lines (75 loc) · 2.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
// SPDX-License-Identifier: CC0-1.0
//! Macros for implementing JSON-RPC methods on a client.
//!
//! Specifically this is methods found under the `== Mining ==` section of the
//! API docs of Bitcoin Core `v0.17`.
//!
//! All macros require `Client` to be in scope.
//!
//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`.
/// Implements Bitcoin Core JSON-RPC API method `getblocktemplate`.
#[macro_export]
macro_rules! impl_client_v17__get_block_template {
() => {
impl Client {
pub fn get_block_template(
&self,
request: &TemplateRequest,
) -> Result<GetBlockTemplate> {
self.call("getblocktemplate", &[into_json(request)?])
}
}
};
}
/// Implements Bitcoin Core JSON-RPC API method `getmininginfo`.
#[macro_export]
macro_rules! impl_client_v17__get_mining_info {
() => {
impl Client {
pub fn get_mining_info(&self) -> Result<GetMiningInfo> {
self.call("getmininginfo", &[])
}
}
};
}
/// Implements Bitcoin Core JSON-RPC API method `getnetworkhashps`.
#[macro_export]
macro_rules! impl_client_v17__get_network_hashes_per_second {
() => {
impl Client {
pub fn get_network_hash_ps(&self) -> Result<f64> { self.call("getnetworkhashps", &[]) }
}
};
}
/// Implements Bitcoin Core JSON-RPC API method `prioritisetransaction`.
#[macro_export]
macro_rules! impl_client_v17__prioritise_transaction {
() => {
impl Client {
pub fn prioritise_transaction(
&self,
txid: &Txid,
fee_delta: bitcoin::SignedAmount,
) -> Result<bool> {
let sats = fee_delta.to_sat();
self.call("prioritisetransaction", &[into_json(txid)?, 0.into(), sats.into()])
}
}
};
}
/// Implements Bitcoin Core JSON-RPC API method `submitblock`.
#[macro_export]
macro_rules! impl_client_v17__submit_block {
() => {
impl Client {
pub fn submit_block(&self, block: &Block) -> Result<()> {
let hex: String = bitcoin::consensus::encode::serialize_hex(block);
match self.call("submitblock", &[into_json(hex)?]) {
Ok(serde_json::Value::Null) => Ok(()),
Ok(res) => Err(Error::Returned(res.to_string())),
Err(err) => Err(err.into()),
}
}
}
};
}