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

Add support for Bitcoin Core v28 #22

Merged
merged 1 commit into from
Nov 2, 2024
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ jobs:
matrix:
feature:
[
"28_0",
"27_1",
"27_0",
"26_2",
Expand Down
1 change: 1 addition & 0 deletions client/src/client_sync/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ pub mod v24;
pub mod v25;
pub mod v26;
pub mod v27;
pub mod v28;

use std::fs::File;
use std::io::{BufRead, BufReader};
Expand Down
44 changes: 44 additions & 0 deletions client/src/client_sync/v28.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// SPDX-License-Identifier: CC0-1.0

//! A JSON-RPC client for testing against Bitcoin Core `v28`.
//!
//! We ignore option arguments unless they effect the shape of the returned JSON data.

use bitcoin::address::{Address, NetworkChecked};
use bitcoin::{Amount, Block, BlockHash, Txid};

use crate::client_sync::{handle_defaults, into_json};
use crate::json::v28::*;

crate::define_jsonrpc_minreq_client!("v28");

// == Blockchain ==
crate::impl_client_v17__getblockchaininfo!();
crate::impl_client_v17__getbestblockhash!();
crate::impl_client_v17__getblock!();
crate::impl_client_v17__gettxout!();

// == Control ==
crate::impl_client_v17__stop!();

// == Generating ==
crate::impl_client_v17__generatetoaddress!();

// == Network ==
crate::impl_client_v17__getnetworkinfo!();
crate::impl_client_check_expected_server_version!({ [280000] });

// == Rawtransactions ==
crate::impl_client_v17__sendrawtransaction!();

// == Wallet ==
crate::impl_client_v17__createwallet!();
crate::impl_client_v22__unloadwallet!();
crate::impl_client_v22__loadwallet!();
crate::impl_client_v17__getbalance!();
crate::impl_client_v19__getbalances!();
crate::impl_client_v17__getnewaddress!();
crate::impl_client_v17__sendtoaddress!();
crate::impl_client_v17__gettransaction!();

pub use crate::client_sync::v23::AddressType;
7 changes: 7 additions & 0 deletions contrib/run_bitcoind.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ COMMAND
- stop Kill all bitcoind nodes using 'pkill bitcoind'.

KNOWN_VERSION
- v28 Bitcoin Core v28.0
- v27 Bitcoin Core v27.1
- v26 Bitcoin Core v26.2
- v25 Bitcoin Core v25.2
Expand All @@ -49,6 +50,7 @@ main() {

case $cmd in
all)
start "v28" # 28.0
start "v27" # 27.1
start "v26" # 26.2
start "v25" # 25.2
Expand Down Expand Up @@ -84,6 +86,11 @@ start() {
local version="$1"

case $version in
v28)
local version_number="28.0"
local version_id="280"
;;

v27)
local version_number="27.1"
local version_id="271"
Expand Down
2 changes: 2 additions & 0 deletions integration_test/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ edition = "2021"
[features]
# Enable the same feature in `bitcoind` and the version feature here.
# All minor releases (but only the latest patch release).
"28_0" = ["v28", "bitcoind/28_0"]
"27_1" = ["v27", "bitcoind/27_1"]
"27_0" = ["v27", "bitcoind/27_0"]
"26_2" = ["v26", "bitcoind/26_2"]
Expand All @@ -37,6 +38,7 @@ edition = "2021"
"0_17_1" = ["v17", "bitcoind/0_17_1"]

# Each minor version is tested with the same client.
"v28" = []
"v27" = []
"v26" = []
"v25" = []
Expand Down
57 changes: 57 additions & 0 deletions integration_test/tests/v28_api.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//! Test the JSON-RPC API against `bitcoind v28.0`.

#![cfg(feature = "v28")]

use integration_test::*;

// == Blockchain ==
mod blockchain {
use super::*;

impl_test_v17__getblockchaininfo!();
impl_test_v17__getbestblockhash!();
impl_test_v17__getblock_verbosity_0!();
impl_test_v17__getblock_verbosity_1!();
}

// == Control ==
mod control {
use super::*;

impl_test_v17__stop!();
}

// == Generating ==
mod generating {
use super::*;

impl_test_v17__generatetoaddress!();
}

// == Network ==
mod network {
use super::*;

impl_test_v17__getnetworkinfo!();
}

// == Rawtransactions ==
mod raw_transactions {
use super::*;

impl_test_v17__sendrawtransaction!();
}

// == Wallet ==
mod wallet {
use super::*;

impl_test_v17__createwallet!();
impl_test_v17__loadwallet!();

impl_test_v17__getnewaddress!();
impl_test_v17__getbalance!();
impl_test_v19__getbalances!();
impl_test_v17__sendtoaddress!();
impl_test_v17__gettransaction!();
}
2 changes: 1 addition & 1 deletion json/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub mod v24;
pub mod v25;
pub mod v26;
pub mod v27;
pub mod v28;

// JSON types that model _all_ `bitcoind` versions.
pub mod model;
Expand Down Expand Up @@ -82,4 +83,3 @@ fn btc_per_kb(btc_per_kb: f64) -> Result<Option<FeeRate>, ParseAmountError> {

Ok(rate)
}

2 changes: 1 addition & 1 deletion json/src/model/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ pub struct GetBlockchainInfo {
/// Status of softforks in progress, maps softfork name -> [`Softfork`].
pub softforks: BTreeMap<String, Softfork>,
/// Any network and blockchain warnings.
pub warnings: String,
pub warnings: Vec<String>,
}

/// Status of softfork.
Expand Down
2 changes: 1 addition & 1 deletion json/src/model/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ pub struct GetNetworkInfo {
/// List of local addresses.
pub local_addresses: Vec<GetNetworkInfoAddress>,
/// Any network and blockchain warnings.
pub warnings: String,
pub warnings: Vec<String>,
}

/// Part of the result of the JSON-RPC method `getnetworkinfo` (information per network).
Expand Down
2 changes: 1 addition & 1 deletion json/src/v17/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl GetBlockchainInfo {
automatic_pruning: self.automatic_pruning,
prune_target_size,
softforks,
warnings: self.warnings,
warnings: vec![self.warnings],
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions json/src/v17/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,8 @@ pub use self::{
generating::{Generate, GenerateToAddress},
network::{
AddedNode, AddedNodeAddress, Banned, GetAddedNodeInfo, GetNetTotals, GetNetworkInfo,
GetNetworkInfoAddress, GetNetworkInfoNetwork, GetPeerInfo, ListBanned, PeerInfo,
UploadTarget,
GetNetworkInfoAddress, GetNetworkInfoError, GetNetworkInfoNetwork, GetPeerInfo, ListBanned,
PeerInfo, UploadTarget,
},
raw_transactions::SendRawTransaction,
wallet::{
Expand Down
2 changes: 1 addition & 1 deletion json/src/v17/network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl GetNetworkInfo {
relay_fee,
incremental_fee,
local_addresses: self.local_addresses.into_iter().map(|a| a.into_model()).collect(),
warnings: self.warnings,
warnings: vec![self.warnings],
})
}
}
Expand Down
2 changes: 1 addition & 1 deletion json/src/v19/blockchain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ impl GetBlockchainInfo {
automatic_pruning: self.automatic_pruning,
prune_target_size,
softforks,
warnings: self.warnings,
warnings: vec![self.warnings],
})
}
}
Expand Down
4 changes: 2 additions & 2 deletions json/src/v19/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ mod wallet;
#[doc(inline)]
pub use self::{
blockchain::{
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBlockchainInfo, Softfork,
SoftforkType,
Bip9SoftforkInfo, Bip9SoftforkStatistics, Bip9SoftforkStatus, GetBlockchainInfo,
GetBlockchainInfoError, Softfork, SoftforkType,
},
wallet::{GetBalances, GetBalancesMine, GetBalancesWatchOnly},
};
Expand Down
99 changes: 99 additions & 0 deletions json/src/v28/blockchain.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
// SPDX-License-Identifier: CC0-1.0

//! The JSON-RPC API for Bitcoin Core v28.0 - blockchain.
//!
//! Types for methods found under the `== Blockchain ==` section of the API docs.

use std::collections::BTreeMap;

use bitcoin::{BlockHash, Network, Work};
use serde::{Deserialize, Serialize};

use super::{GetBlockchainInfoError, Softfork};
use crate::model;

#[rustfmt::skip] // Keep public re-exports separate.

/// Result of JSON-RPC method `getblockchaininfo`.
///
/// Method call: `getblockchaininfo`
///
/// > Returns an object containing various state info regarding blockchain processing.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
pub struct GetBlockchainInfo {
/// Current network name as defined in BIP70 (main, test, signet, regtest).
pub chain: String,
/// The current number of blocks processed in the server.
pub blocks: i64,
/// The current number of headers we have validated.
pub headers: i64,
/// The hash of the currently best block.
#[serde(rename = "bestblockhash")]
pub best_block_hash: String,
/// The current difficulty.
pub difficulty: f64,
/// Median time for the current best block.
#[serde(rename = "mediantime")]
pub median_time: i64,
/// Estimate of verification progress (between 0 and 1).
#[serde(rename = "verificationprogress")]
pub verification_progress: f64,
/// Estimate of whether this node is in Initial Block Download (IBD) mode.
#[serde(rename = "initialblockdownload")]
pub initial_block_download: bool,
/// Total amount of work in active chain, in hexadecimal.
#[serde(rename = "chainwork")]
pub chain_work: String,
/// The estimated size of the block and undo files on disk.
pub size_on_disk: u64,
/// If the blocks are subject to pruning.
pub pruned: bool,
/// Lowest-height complete block stored (only present if pruning is enabled).
#[serde(rename = "pruneheight")]
pub prune_height: Option<i64>,
/// Whether automatic pruning is enabled (only present if pruning is enabled).
pub automatic_pruning: Option<bool>,
/// The target size used by pruning (only present if automatic pruning is enabled).
pub prune_target_size: Option<i64>,
/// Status of softforks in progress, maps softfork name -> [`Softfork`].
#[serde(default)]
pub softforks: BTreeMap<String, Softfork>,
/// Any network and blockchain warnings.
pub warnings: Vec<String>,
}

impl GetBlockchainInfo {
/// Converts version specific type to a version in-specific, more strongly typed type.
pub fn into_model(self) -> Result<model::GetBlockchainInfo, GetBlockchainInfoError> {
use GetBlockchainInfoError as E;

let chain = Network::from_core_arg(&self.chain).map_err(E::Chain)?;
let best_block_hash =
self.best_block_hash.parse::<BlockHash>().map_err(E::BestBlockHash)?;
let chain_work = Work::from_unprefixed_hex(&self.chain_work).map_err(E::ChainWork)?;
let prune_height =
self.prune_height.map(|h| crate::to_u32(h, "prune_height")).transpose()?;
let prune_target_size =
self.prune_target_size.map(|h| crate::to_u32(h, "prune_target_size")).transpose()?;
let softforks = BTreeMap::new(); // TODO: Handle softforks stuff.

Ok(model::GetBlockchainInfo {
chain,
blocks: crate::to_u32(self.blocks, "blocks")?,
headers: crate::to_u32(self.headers, "headers")?,
best_block_hash,
difficulty: self.difficulty,
median_time: crate::to_u32(self.median_time, "median_time")?,
verification_progress: self.verification_progress,
initial_block_download: self.initial_block_download,
chain_work,
size_on_disk: self.size_on_disk,
pruned: self.pruned,
prune_height,
automatic_pruning: self.automatic_pruning,
prune_target_size,
softforks,
warnings: self.warnings,
})
}
}
Loading
Loading