From 7dd78761d64d96aa3f5718045b3ac80d621bcd5f Mon Sep 17 00:00:00 2001 From: Razvan Pricop <22615594+RazorBest@users.noreply.github.com> Date: Fri, 10 Apr 2026 16:07:39 +0200 Subject: [PATCH 1/3] Add to_u64 function in corepc-types --- types/src/lib.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/types/src/lib.rs b/types/src/lib.rs index 845e098f..52b3f645 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -63,6 +63,11 @@ pub fn to_u32(value: i64, field: &str) -> Result { u32::try_from(value).map_err(|_| NumericError::Overflow { value, field: field.to_owned() }) } +/// Converts an `i64` numeric type to a `u64`. +pub fn to_u64(value: i64, field: &str) -> Result { + u64::try_from(value).map_err(|_| NumericError::Negative { value, field: field.to_owned() }) +} + /// Error converting an `i64` to a `u32`. /// /// If we expect a numeric value to sanely fit inside a `u32` we use that type in the `model` From 2616578f6df9d277700f9e0d0e5437da02280334 Mon Sep 17 00:00:00 2001 From: Razvan Pricop <22615594+RazorBest@users.noreply.github.com> Date: Fri, 10 Apr 2026 16:09:51 +0200 Subject: [PATCH 2/3] Change the type of model::GetBlockchainInfo::prune_target_size from u32 to u64 --- integration_test/tests/blockchain.rs | 2 +- types/src/model/blockchain.rs | 2 +- types/src/v17/blockchain/into.rs | 2 +- types/src/v19/blockchain/into.rs | 2 +- types/src/v21/blockchain/into.rs | 2 +- types/src/v23/blockchain/into.rs | 2 +- types/src/v28/blockchain/into.rs | 2 +- types/src/v29/blockchain/into.rs | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/integration_test/tests/blockchain.rs b/integration_test/tests/blockchain.rs index 63450e99..92f57ad9 100644 --- a/integration_test/tests/blockchain.rs +++ b/integration_test/tests/blockchain.rs @@ -206,7 +206,7 @@ fn blockchain__get_block__modelled() { #[test] fn blockchain__get_blockchain_info__modelled() { - let node = Node::with_wallet(Wallet::None, &[]); + let node = Node::with_wallet(Wallet::None, &["-prune=10000"]); let json: GetBlockchainInfo = node.client.get_blockchain_info().expect("rpc"); let model: Result = json.into_model(); diff --git a/types/src/model/blockchain.rs b/types/src/model/blockchain.rs index 8dc70eaf..ef78a689 100644 --- a/types/src/model/blockchain.rs +++ b/types/src/model/blockchain.rs @@ -241,7 +241,7 @@ pub struct GetBlockchainInfo { /// Whether automatic pruning is enabled (only present if pruning is enabled). pub automatic_pruning: Option, /// The target size used by pruning (only present if automatic pruning is enabled). - pub prune_target_size: Option, + pub prune_target_size: Option, /// Status of softforks in progress, maps softfork name -> [`Softfork`] (empty from v29 onwards). pub softforks: BTreeMap, /// The block challenge (aka. block script) diff --git a/types/src/v17/blockchain/into.rs b/types/src/v17/blockchain/into.rs index 8b867562..f8fd64b5 100644 --- a/types/src/v17/blockchain/into.rs +++ b/types/src/v17/blockchain/into.rs @@ -98,7 +98,7 @@ impl GetBlockchainInfo { 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()?; + self.prune_target_size.map(|h| crate::to_u64(h, "prune_target_size")).transpose()?; let softforks = BTreeMap::new(); // TODO: Handle softforks stuff. Ok(model::GetBlockchainInfo { diff --git a/types/src/v19/blockchain/into.rs b/types/src/v19/blockchain/into.rs index fd60814d..3b6ec0f4 100644 --- a/types/src/v19/blockchain/into.rs +++ b/types/src/v19/blockchain/into.rs @@ -29,7 +29,7 @@ impl GetBlockchainInfo { 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()?; + self.prune_target_size.map(|h| crate::to_u64(h, "prune_target_size")).transpose()?; let softforks = BTreeMap::new(); // TODO: Handle softforks stuff. Ok(model::GetBlockchainInfo { diff --git a/types/src/v21/blockchain/into.rs b/types/src/v21/blockchain/into.rs index 4c53d0b2..d76169cd 100644 --- a/types/src/v21/blockchain/into.rs +++ b/types/src/v21/blockchain/into.rs @@ -24,7 +24,7 @@ impl GetBlockchainInfo { 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()?; + self.prune_target_size.map(|h| crate::to_u64(h, "prune_target_size")).transpose()?; let softforks = BTreeMap::new(); // TODO: Handle softforks stuff. Ok(model::GetBlockchainInfo { diff --git a/types/src/v23/blockchain/into.rs b/types/src/v23/blockchain/into.rs index 7a6814d3..edd5770a 100644 --- a/types/src/v23/blockchain/into.rs +++ b/types/src/v23/blockchain/into.rs @@ -25,7 +25,7 @@ impl GetBlockchainInfo { 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()?; + self.prune_target_size.map(|h| crate::to_u64(h, "prune_target_size")).transpose()?; let softforks = BTreeMap::new(); // TODO: Handle softforks stuff. Ok(model::GetBlockchainInfo { diff --git a/types/src/v28/blockchain/into.rs b/types/src/v28/blockchain/into.rs index cb0b3ad9..46210f49 100644 --- a/types/src/v28/blockchain/into.rs +++ b/types/src/v28/blockchain/into.rs @@ -23,7 +23,7 @@ impl GetBlockchainInfo { 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()?; + self.prune_target_size.map(|h| crate::to_u64(h, "prune_target_size")).transpose()?; let softforks = BTreeMap::new(); // TODO: Handle softforks stuff. Ok(model::GetBlockchainInfo { diff --git a/types/src/v29/blockchain/into.rs b/types/src/v29/blockchain/into.rs index dd4ea010..71e25fc1 100644 --- a/types/src/v29/blockchain/into.rs +++ b/types/src/v29/blockchain/into.rs @@ -267,7 +267,7 @@ impl GetBlockchainInfo { 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()?; + self.prune_target_size.map(|h| crate::to_u64(h, "prune_target_size")).transpose()?; let signet_challenge = self.signet_challenge.as_ref().map(|s| ScriptBuf::from_hex(s)).transpose()?; From b10dc06c2a203f19f13440292e970ffd5679ebb4 Mon Sep 17 00:00:00 2001 From: Razvan Pricop <22615594+RazorBest@users.noreply.github.com> Date: Fri, 10 Apr 2026 16:10:52 +0200 Subject: [PATCH 3/3] Document the presence of u64 for NumericError --- types/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/types/src/lib.rs b/types/src/lib.rs index 52b3f645..dc5b96ec 100644 --- a/types/src/lib.rs +++ b/types/src/lib.rs @@ -68,11 +68,11 @@ pub fn to_u64(value: i64, field: &str) -> Result { u64::try_from(value).map_err(|_| NumericError::Negative { value, field: field.to_owned() }) } -/// Error converting an `i64` to a `u32`. +/// Error converting an `i64` to a `u32` or `u64`. /// -/// If we expect a numeric value to sanely fit inside a `u32` we use that type in the `model` -/// module, this requires converting the `i64` returned by the JSONRPC API into a `u32`, if our -/// expectations are not met this error will be encountered. +/// The JSONRPC API returns `i64` values. If these values match our expectations, then +/// we convert them to either `u32` or `u64`, depending on the JSONRPC field. If our +/// expectations are not met, this error is returned. #[derive(Debug)] pub enum NumericError { /// Expected an unsigned numeric value however the value was negative.