diff --git a/integration_test/tests/generating.rs b/integration_test/tests/generating.rs index 6e6556b2..d4b13e1e 100644 --- a/integration_test/tests/generating.rs +++ b/integration_test/tests/generating.rs @@ -29,15 +29,17 @@ fn generating__generate_block__modelled() { { // No `submit` argument json = node.client.generate_block(&mining_addr.to_string(), &transactions).expect("generateblock"); + let model: Result = json.into_model(); + model.unwrap(); } #[cfg(not(feature = "v24_and_below"))] { // Check with `submit = false` so that `hex` is returned. v25 and later only. json = node.client.generate_block(&mining_addr.to_string(), &transactions, false).expect("generateblock"); + let model: Result = json.into_model(); + model.unwrap(); } - let model: Result = json.into_model(); - model.unwrap(); } #[test] diff --git a/types/src/v21/generating/error.rs b/types/src/v21/generating/error.rs deleted file mode 100644 index 1a5f82ab..00000000 --- a/types/src/v21/generating/error.rs +++ /dev/null @@ -1,35 +0,0 @@ -// SPDX-License-Identifier: CC0-1.0 - -use core::fmt; - -use bitcoin::hex; - -use crate::error::write_err; - -/// Error when converting a `GenerateBlock` type into the model type. -#[derive(Debug)] -pub enum GenerateBlockError { - /// Conversion of the `hash` field failed. - Hash(hex::HexToArrayError), -} - -impl fmt::Display for GenerateBlockError { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - use GenerateBlockError::*; - - match *self { - Hash(ref e) => write_err!(f, "conversion of the `hash` field failed"; e), - } - } -} - -#[cfg(feature = "std")] -impl std::error::Error for GenerateBlockError { - fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { - use GenerateBlockError::*; - - match *self { - Hash(ref e) => Some(e), - } - } -} diff --git a/types/src/v21/generating/into.rs b/types/src/v21/generating/into.rs index 9b766465..a0c79ac2 100644 --- a/types/src/v21/generating/into.rs +++ b/types/src/v21/generating/into.rs @@ -4,17 +4,15 @@ //! //! Types for methods found under the `== Generating ==` section of the API docs. -use bitcoin::BlockHash; +use bitcoin::{hex, BlockHash}; -use super::{GenerateBlock, GenerateBlockError}; +use super::GenerateBlock; use crate::model; impl GenerateBlock { /// Converts version specific type to a version nonspecific, more strongly typed type. - pub fn into_model(self) -> Result { - use GenerateBlockError as E; - - let hash = self.hash.parse::().map_err(E::Hash)?; + pub fn into_model(self) -> Result { + let hash = self.hash.parse::()?; Ok(model::GenerateBlock { hash, hex: None, // v25 and later only. diff --git a/types/src/v21/generating/mod.rs b/types/src/v21/generating/mod.rs index 1443d6df..babd5f3c 100644 --- a/types/src/v21/generating/mod.rs +++ b/types/src/v21/generating/mod.rs @@ -4,13 +4,10 @@ //! //! Types for methods found under the `== Generating ==` section of the API docs. -mod error; mod into; use serde::{Deserialize, Serialize}; -pub use self::error::GenerateBlockError; - /// Result of JSON-RPC method `generateblock`. /// /// > Mine a block with a set of ordered transactions immediately to a specified address or descriptor (before the RPC call returns) diff --git a/types/src/v21/mod.rs b/types/src/v21/mod.rs index f35ceadd..7844fe31 100644 --- a/types/src/v21/mod.rs +++ b/types/src/v21/mod.rs @@ -244,7 +244,7 @@ pub use self::{ Bip9SoftforkInfo, GetBlockchainInfo, GetMempoolEntry, GetMempoolInfo, Softfork, SoftforkType, }, - generating::{GenerateBlock, GenerateBlockError}, + generating::GenerateBlock, network::{GetNetworkInfo, GetPeerInfo}, util::{GetIndexInfo, GetIndexInfoName}, wallet::{ diff --git a/types/src/v22/mod.rs b/types/src/v22/mod.rs index 10efbccd..b640d43f 100644 --- a/types/src/v22/mod.rs +++ b/types/src/v22/mod.rs @@ -306,10 +306,9 @@ pub use crate::{ }, v20::{CreateMultisig, GenerateToDescriptor, GetTransaction, GetTransactionDetail}, v21::{ - Bip9SoftforkInfo, GenerateBlock, GenerateBlockError, GetBlockchainInfo, GetIndexInfo, - GetIndexInfoName, GetMempoolEntry, GetNetworkInfo, ImportDescriptors, - ImportDescriptorsResult, PsbtBumpFee, PsbtBumpFeeError, Send, SendError, Softfork, - SoftforkType, UnloadWallet, UpgradeWallet, + Bip9SoftforkInfo, GenerateBlock, GetBlockchainInfo, GetIndexInfo, GetIndexInfoName, + GetMempoolEntry, GetNetworkInfo, ImportDescriptors, ImportDescriptorsResult, PsbtBumpFee, + PsbtBumpFeeError, Send, SendError, Softfork, SoftforkType, UnloadWallet, UpgradeWallet, }, ScriptPubkey, }; diff --git a/types/src/v23/mod.rs b/types/src/v23/mod.rs index 8544c252..69d186f4 100644 --- a/types/src/v23/mod.rs +++ b/types/src/v23/mod.rs @@ -306,9 +306,9 @@ pub use crate::{ }, v20::{GenerateToDescriptor, GetTransactionDetail}, v21::{ - GenerateBlock, GenerateBlockError, GetIndexInfo, GetIndexInfoName, GetNetworkInfo, - ImportDescriptors, ImportDescriptorsResult, PsbtBumpFee, PsbtBumpFeeError, Send, SendError, - UnloadWallet, UpgradeWallet, + GenerateBlock, GetIndexInfo, GetIndexInfoName, GetNetworkInfo, ImportDescriptors, + ImportDescriptorsResult, PsbtBumpFee, PsbtBumpFeeError, Send, SendError, UnloadWallet, + UpgradeWallet, }, v22::{Banned, GetMempoolInfo, ListBanned, ScriptPubkey}, }; diff --git a/types/src/v24/mod.rs b/types/src/v24/mod.rs index 53226872..47809210 100644 --- a/types/src/v24/mod.rs +++ b/types/src/v24/mod.rs @@ -307,9 +307,9 @@ pub use crate::{ }, v20::GenerateToDescriptor, v21::{ - GenerateBlock, GenerateBlockError, GetIndexInfo, GetIndexInfoName, GetNetworkInfo, - ImportDescriptors, ImportDescriptorsResult, PsbtBumpFee, PsbtBumpFeeError, Send, SendError, - UnloadWallet, UpgradeWallet, + GenerateBlock, GetIndexInfo, GetIndexInfoName, GetNetworkInfo, ImportDescriptors, + ImportDescriptorsResult, PsbtBumpFee, PsbtBumpFeeError, Send, SendError, UnloadWallet, + UpgradeWallet, }, v22::{Banned, ListBanned, ScriptPubkey}, v23::{