Skip to content
Draft
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
12 changes: 12 additions & 0 deletions client/src/client_sync/v17/hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,18 @@
//!
//! See or use the `define_jsonrpc_bitreq_client!` macro to define a `Client`.
/// Implements Bitcoin Core JSON-RPC API method `estimaterawfee`.
#[macro_export]
macro_rules! impl_client_v17__estimate_raw_fee {
() => {
impl Client {
pub fn estimate_raw_fee(&self, conf_target: u32) -> Result<EstimateRawFee> {
self.call("estimaterawfee", &[conf_target.into()])
}
}
};
}

/// Implements Bitcoin Core JSON-RPC API method `waitforblock`.
#[macro_export]
macro_rules! impl_client_v17__wait_for_block {
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ crate::impl_client_v17__generate!();
crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v18/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ crate::impl_client_v17__generate!();
crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v19/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ crate::impl_client_v17__generate_to_address!();
crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v20/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ crate::impl_client_v20__generate_to_descriptor!();
crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/v21/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v21__add_peer_address!();
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
26 changes: 26 additions & 0 deletions client/src/client_sync/v22/hidden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: CC0-1.0

//! Macros for implementing JSON-RPC methods on a client.
//!
//! Specifically this is `== Hidden ==` methods that are not listed in the
//! API docs of Bitcoin Core `v22`.
//!
//! 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 `addconnection`.
#[macro_export]
macro_rules! impl_client_v22__add_connection {
() => {
impl Client {
pub fn add_connection(
&self,
address: &str,
connection_type: &str,
) -> Result<AddConnection> {
self.call("addconnection", &[into_json(address)?, into_json(connection_type)?])
}
}
};
}
3 changes: 3 additions & 0 deletions client/src/client_sync/v22/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//!
//! We ignore option arguments unless they effect the shape of the returned JSON data.

mod hidden;
mod signer;
mod wallet;

Expand Down Expand Up @@ -69,7 +70,9 @@ crate::impl_client_v20__generate_to_descriptor!();
crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v22__add_connection!();
crate::impl_client_v21__add_peer_address!();
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
2 changes: 2 additions & 0 deletions client/src/client_sync/v23/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ crate::impl_client_v20__generate_to_descriptor!();
crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v22__add_connection!();
crate::impl_client_v21__add_peer_address!();
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
2 changes: 2 additions & 0 deletions client/src/client_sync/v24/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ crate::impl_client_v20__generate_to_descriptor!();
crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v22__add_connection!();
crate::impl_client_v21__add_peer_address!();
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
2 changes: 2 additions & 0 deletions client/src/client_sync/v25/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ crate::impl_client_v20__generate_to_descriptor!();
crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v22__add_connection!();
crate::impl_client_v21__add_peer_address!();
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
2 changes: 2 additions & 0 deletions client/src/client_sync/v26/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ crate::impl_client_v20__generate_to_descriptor!();
crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v22__add_connection!();
crate::impl_client_v21__add_peer_address!();
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
30 changes: 30 additions & 0 deletions client/src/client_sync/v27/hidden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: CC0-1.0

//! Macros for implementing JSON-RPC methods on a client.
//!
//! Specifically this is `== Hidden ==` methods that are not listed in the
//! API docs of Bitcoin Core `v29`.
//!
//! 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 `addconnection`.
#[macro_export]
macro_rules! impl_client_v27__add_connection {
() => {
impl Client {
pub fn add_connection(
&self,
address: &str,
connection_type: &str,
v2transport: bool,
) -> Result<AddConnection> {
self.call(
"addconnection",
&[into_json(address)?, into_json(connection_type)?, into_json(v2transport)?],
)
}
}
};
}
4 changes: 4 additions & 0 deletions client/src/client_sync/v27/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
//!
//! We ignore option arguments unless they effect the shape of the returned JSON data.

pub mod hidden;

use std::collections::BTreeMap;
use std::path::Path;

Expand Down Expand Up @@ -74,7 +76,9 @@ crate::impl_client_v20__generate_to_descriptor!();
crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v27__add_connection!();
crate::impl_client_v21__add_peer_address!();
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
2 changes: 2 additions & 0 deletions client/src/client_sync/v28/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ crate::impl_client_v20__generate_to_descriptor!();
crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v27__add_connection!();
crate::impl_client_v21__add_peer_address!();
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
2 changes: 2 additions & 0 deletions client/src/client_sync/v29/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ crate::impl_client_v20__generate_to_descriptor!();
crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v27__add_connection!();
crate::impl_client_v21__add_peer_address!();
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand Down
2 changes: 2 additions & 0 deletions client/src/client_sync/v30/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ crate::impl_client_v23__save_mempool!();
crate::impl_client_v25__scan_blocks!();
crate::impl_client_v17__verify_chain!();
crate::impl_client_v17__verify_tx_out_proof!();
crate::impl_client_v17__estimate_raw_fee!();
crate::impl_client_v17__wait_for_block!();
crate::impl_client_v17__wait_for_block_height!();
crate::impl_client_v17__wait_for_new_block!();
Expand All @@ -77,6 +78,7 @@ crate::impl_client_v20__generate_to_descriptor!();
crate::impl_client_v17__invalidate_block!();

// == Hidden ==
crate::impl_client_v27__add_connection!();
crate::impl_client_v21__add_peer_address!();

// == Mining ==
Expand Down
64 changes: 64 additions & 0 deletions integration_test/tests/hidden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// SPDX-License-Identifier: CC0-1.0

//! Tests for methods that are `== Hidden ==` and not in the API docs of Bitcoin Core.

#![allow(non_snake_case)] // Test names intentionally use double underscore.

use integration_test::{Node, NodeExt as _, Wallet};
use node::mtype;
use node::vtype::*; // All the version specific types.
#[cfg(not(feature = "v21_and_below"))]
use node::P2P;

#[test]
#[cfg(not(feature = "v21_and_below"))]
fn hidden__add_connection__modelled() {
let (listener, dialer, _node3) = integration_test::three_node_network();

let p2p = listener.p2p_connect(false).expect("p2p address");
let address = match p2p {
P2P::Connect(socket, _) => socket.to_string(),
_ => unreachable!("p2p_connect should return P2P::Connect"),
};

let json: AddConnection = {
#[cfg(feature = "v26_and_below")]
{
dialer.client.add_connection(&address, "outbound-full-relay").expect("addconnection")
}
#[cfg(not(feature = "v26_and_below"))]
{
dialer
.client
.add_connection(&address, "outbound-full-relay", false)
.expect("addconnection")
}
};

let model: mtype::AddConnection = json.into_model();

assert_eq!(model.address, address);
assert_eq!(model.connection_type, "outbound-full-relay");
assert!(dialer.peers_connected() >= 1);
}

#[test]
fn hidden__estimate_raw_fee__modelled() {
let node = Node::with_wallet(Wallet::Default, &[]);
node.fund_wallet();

// Give the fee estimator some confirmation history.
for _ in 0..10 {
node.create_mined_transaction();
}

let json: EstimateRawFee = node.client.estimate_raw_fee(2).expect("estimaterawfee");
let json_range: &RawFeeRange = json.long.fail.as_ref().unwrap();

assert!(json_range.total_confirmed > 0.0);

let model: Result<mtype::EstimateRawFee, EstimateRawFeeError> = json.into_model();
let estimate = model.unwrap();

assert!(estimate.long.scale > 0);
}
63 changes: 63 additions & 0 deletions types/src/model/hidden.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// SPDX-License-Identifier: CC0-1.0

//! Types for methods that are `== Hidden ==` and not in the API docs of Bitcoin Core.
//!
//! These structs model the types returned by the JSON-RPC API but have concrete types
//! and are not specific to a specific version of Bitcoin Core.

use bitcoin::FeeRate;
use serde::{Deserialize, Serialize};

/// Models the result of JSON-RPC method `addconnection`.
#[derive(Clone, Debug, PartialEq, Eq, Deserialize, Serialize)]
pub struct AddConnection {
/// The address of the newly added connection.
pub address: String,
/// Type of connection.
pub connection_type: String,
}

/// Models the result of JSON-RPC method `estimaterawfee`.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct EstimateRawFee {
/// Estimate for short time horizon.
pub short: Option<RawFeeDetail>,
/// Estimate for medium time horizon.
pub medium: Option<RawFeeDetail>,
/// Estimate for long time horizon.
pub long: RawFeeDetail,
}

/// Estimate for a time horizon. Part of `estimaterawfee`.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct RawFeeDetail {
/// Estimate fee rate in BTC/kB.
pub fee_rate: Option<FeeRate>,
/// Exponential decay (per block) for historical moving average of confirmation data.
pub decay: f64,
/// The resolution of confirmation targets at this time horizon.
pub scale: u32,
/// Information about the lowest range of feerates to succeed in meeting the threshold.
pub pass: Option<RawFeeRange>,
/// Information about the highest range of feerates to fail to meet the threshold.
pub fail: Option<RawFeeRange>,
/// Errors encountered during processing.
pub errors: Option<Vec<String>>,
}

/// Information about a feerate range. Part of `estimaterawfee`.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct RawFeeRange {
/// Start of feerate range.
pub start_range: Option<FeeRate>,
/// End of feerate range.
pub end_range: Option<FeeRate>,
/// Number of txs over history horizon in the feerate range that were confirmed within target.
pub within_target: f64,
/// Number of txs over history horizon in the feerate range that were confirmed at any point.
pub total_confirmed: f64,
/// Current number of txs in mempool in the feerate range unconfirmed for at least target blocks.
pub in_mempool: f64,
/// Number of txs over history horizon in the feerate range that left mempool unconfirmed after target.
pub left_mempool: f64,
}
2 changes: 2 additions & 0 deletions types/src/model/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
mod blockchain;
mod control;
mod generating;
mod hidden;
mod mining;
mod network;
mod raw_transactions;
Expand Down Expand Up @@ -38,6 +39,7 @@ pub use self::{
WaitForBlockHeight, WaitForNewBlock,
},
generating::{Generate, GenerateBlock, GenerateToAddress, GenerateToDescriptor},
hidden::{AddConnection, EstimateRawFee, RawFeeDetail, RawFeeRange},
mining::{
BlockTemplateTransaction, GetBlockTemplate, GetMiningInfo, GetPrioritisedTransactions,
NextBlockInfo, PrioritisedTransaction,
Expand Down
Loading