Skip to content
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
7 changes: 3 additions & 4 deletions types/src/v17/blockchain/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,15 +113,14 @@ pub enum GetBlockHeaderError {
/// Conversion of hex data to bytes failed.
Hex(hex::HexToBytesError),
/// Consensus decoding of bytes to header failed.
Consensus(encode::Error),
Header(encode::Error),
}

impl fmt::Display for GetBlockHeaderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Hex(ref e) => write_err!(f, "conversion of hex data to bytes failed"; e),
Self::Consensus(ref e) =>
write_err!(f, "consensus decoding of bytes to header failed"; e),
Self::Header(ref e) => write_err!(f, "consensus decoding of bytes to header failed"; e),
}
}
}
Expand All @@ -131,7 +130,7 @@ impl std::error::Error for GetBlockHeaderError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Hex(ref e) => Some(e),
Self::Consensus(ref e) => Some(e),
Self::Header(ref e) => Some(e),
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion types/src/v17/blockchain/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ impl GetBlockHeader {
use GetBlockHeaderError as E;

let v = Vec::from_hex(&self.0).map_err(E::Hex)?;
let header = encode::deserialize::<block::Header>(&v).map_err(E::Consensus)?;
let header = encode::deserialize::<block::Header>(&v).map_err(E::Header)?;

Ok(model::GetBlockHeader(header))
}
Expand Down
5 changes: 3 additions & 2 deletions types/src/v17/mining/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ pub enum BlockTemplateTransactionError {
Data(consensus::encode::FromHexError),
/// Conversion of the `txid` field failed.
Txid(hex::HexToArrayError),
/// Conversion of the `hash` field failed.
/// Conversion of the `hash` field to `wtxid` failed.
Hash(hex::HexToArrayError),
/// Conversion of the `fee` field failed.
Fee(ParseAmountError),
Expand All @@ -77,7 +77,8 @@ impl fmt::Display for BlockTemplateTransactionError {
Self::Numeric(ref e) => write_err!(f, "numeric"; e),
Self::Data(ref e) => write_err!(f, "conversion of the `data` field failed"; e),
Self::Txid(ref e) => write_err!(f, "conversion of the `txid` field failed"; e),
Self::Hash(ref e) => write_err!(f, "conversion of the `hash` field failed"; e),
Self::Hash(ref e) =>
write_err!(f, "conversion of the `hash` field to `wtxid` failed"; e),
Self::Fee(ref e) => write_err!(f, "conversion of the `fee` field failed"; e),
}
}
Expand Down
5 changes: 3 additions & 2 deletions types/src/v17/raw_transactions/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::psbt::{
/// Error when converting a `DecodePsbt` type into the model type.
#[derive(Debug)]
pub enum DecodePsbtError {
/// Conversion of the `tx` field failed.
/// Conversion of the `tx` field to `unsigned_tx` failed.
Tx(RawTransactionError),
/// Conversion of one the map items in the `unknown` field failed.
Unknown(hex::HexToBytesError),
Expand All @@ -31,7 +31,8 @@ pub enum DecodePsbtError {
impl fmt::Display for DecodePsbtError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Tx(ref e) => write_err!(f, "conversion of raw transaction data field failed"; e),
Self::Tx(ref e) =>
write_err!(f, "conversion of the `tx` field to `unsigned_tx` failed"; e),
Self::Unknown(ref e) =>
write_err!(f, "conversion of one the map items in the `unknown` field failed"; e),
Self::Inputs(ref e) => write_err!(f, "conversion of one of the PSBT inputs failed"; e),
Expand Down
5 changes: 3 additions & 2 deletions types/src/v23/raw_transactions/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::error::write_err;
/// Error when converting a `DecodePsbt` type into the model type.
#[derive(Debug)]
pub enum DecodePsbtError {
/// Conversion of the `tx` field failed.
/// Conversion of the `tx` field to `unsigned_tx` failed.
Tx(RawTransactionError),
/// Conversion of the `global_xpubs` field failed.
GlobalXpubs(GlobalXpubError),
Expand All @@ -30,7 +30,8 @@ pub enum DecodePsbtError {
impl fmt::Display for DecodePsbtError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Tx(ref e) => write_err!(f, "conversion of raw transaction data field failed"; e),
Self::Tx(ref e) =>
write_err!(f, "conversion of the `tx` field to `unsigned_tx` failed"; e),
Self::GlobalXpubs(ref e) =>
write_err!(f, "conversion of one the map items in the `global_xbubs` field failed"; e),
Self::Proprietary(ref e) =>
Expand Down
5 changes: 3 additions & 2 deletions types/src/v24/raw_transactions/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::error::write_err;
/// Error when converting a `DecodePsbt` type into the model type.
#[derive(Debug)]
pub enum DecodePsbtError {
/// Conversion of the `tx` field failed.
/// Conversion of the `tx` field to `unsigned_tx` failed.
Tx(RawTransactionError),
/// Conversion of the `global_xpubs` field failed.
GlobalXpubs(GlobalXpubError),
Expand All @@ -31,7 +31,8 @@ pub enum DecodePsbtError {
impl fmt::Display for DecodePsbtError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Tx(ref e) => write_err!(f, "conversion of raw transaction data field failed"; e),
Self::Tx(ref e) =>
write_err!(f, "conversion of the `tx` field to `unsigned_tx` failed"; e),
Self::GlobalXpubs(ref e) =>
write_err!(f, "conversion of one the map items in the `global_xbubs` field failed"; e),
Self::Proprietary(ref e) =>
Expand Down
32 changes: 23 additions & 9 deletions types/src/v29/blockchain/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,15 +289,14 @@ pub enum GetBlockHeaderError {
/// Conversion of hex data to bytes failed.
Hex(hex::HexToBytesError),
/// Consensus decoding of bytes to header failed.
Consensus(encode::Error),
Header(encode::Error),
}

impl fmt::Display for GetBlockHeaderError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Hex(ref e) => write_err!(f, "conversion of hex data to bytes failed"; e),
Self::Consensus(ref e) =>
write_err!(f, "consensus decoding of bytes to header failed"; e),
Self::Header(ref e) => write_err!(f, "consensus decoding of bytes to header failed"; e),
}
}
}
Expand All @@ -307,7 +306,7 @@ impl std::error::Error for GetBlockHeaderError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Hex(ref e) => Some(e),
Self::Consensus(ref e) => Some(e),
Self::Header(ref e) => Some(e),
}
}
}
Expand Down Expand Up @@ -427,8 +426,14 @@ impl From<NumericError> for GetChainStatesError {
pub enum GetDescriptorActivityError {
/// Conversion of numeric type (e.g., height) to expected type failed.
Numeric(NumericError),
/// Conversion of a hash string (BlockHash, Txid) failed.
Hash(hex::HexToArrayError),
/// Conversion of the `spend_txid` field failed.
SpendTxid(hex::HexToArrayError),
/// Conversion of the `prevout_txid` field failed.
PrevoutTxid(hex::HexToArrayError),
/// Conversion of the `txid` field failed.
Txid(hex::HexToArrayError),
/// Conversion of the `block_hash` field failed.
BlockHash(hex::HexToArrayError),
/// Conversion of the `amount` field (f64 BTC) failed.
Amount(amount::ParseAmountError),
/// Conversion of script hex to ScriptBuf failed.
Expand All @@ -449,7 +454,13 @@ impl fmt::Display for GetDescriptorActivityError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Numeric(ref e) => write_err!(f, "numeric conversion failed"; e),
Self::Hash(ref e) => write_err!(f, "conversion of a hash string failed"; e),
Self::SpendTxid(ref e) =>
write_err!(f, "conversion of the `spend_txid` field failed"; e),
Self::PrevoutTxid(ref e) =>
write_err!(f, "conversion of the `prevout_txid` field failed"; e),
Self::Txid(ref e) => write_err!(f, "conversion of the `txid` field failed"; e),
Self::BlockHash(ref e) =>
write_err!(f, "conversion of the `block_hash` field failed"; e),
Self::Amount(ref e) => write_err!(f, "conversion of the `amount` field failed"; e),
Self::Script(ref e) => write_err!(f, "conversion of the script `hex` field failed"; e),
Self::Address(ref e) => write_err!(f, "conversion of the `address` field failed"; e),
Expand All @@ -470,7 +481,10 @@ impl std::error::Error for GetDescriptorActivityError {

match *self {
Numeric(ref e) => Some(e),
Hash(ref e) => Some(e),
SpendTxid(ref e) => Some(e),
PrevoutTxid(ref e) => Some(e),
Txid(ref e) => Some(e),
BlockHash(ref e) => Some(e),
Amount(ref e) => Some(e),
Script(ref e) => Some(e),
Address(ref e) => Some(e),
Expand All @@ -487,7 +501,7 @@ impl From<NumericError> for GetDescriptorActivityError {
}

impl From<hex::HexToArrayError> for GetDescriptorActivityError {
fn from(e: hex::HexToArrayError) -> Self { Self::Hash(e) }
fn from(e: hex::HexToArrayError) -> Self { Self::BlockHash(e) }
}

impl From<amount::ParseAmountError> for GetDescriptorActivityError {
Expand Down
13 changes: 7 additions & 6 deletions types/src/v29/blockchain/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ impl GetBlockHeader {
use GetBlockHeaderError as E;

let v = Vec::from_hex(&self.0).map_err(E::Hex)?;
let header = encode::deserialize::<block::Header>(&v).map_err(E::Consensus)?;
let header = encode::deserialize::<block::Header>(&v).map_err(E::Header)?;

Ok(model::GetBlockHeader(header))
}
Expand Down Expand Up @@ -404,11 +404,12 @@ impl GetDescriptorActivity {
.block_hash
.map(|s| BlockHash::from_str(&s))
.transpose()
.map_err(E::Hash)?;
.map_err(E::BlockHash)?;
let height =
spend.height.map(|h| crate::to_u32(h, "height")).transpose()?;
let spend_txid = Txid::from_str(&spend.spend_txid).map_err(E::Hash)?;
let prevout_txid = Txid::from_str(&spend.prevout_txid).map_err(E::Hash)?;
let spend_txid = Txid::from_str(&spend.spend_txid).map_err(E::SpendTxid)?;
let prevout_txid =
Txid::from_str(&spend.prevout_txid).map_err(E::PrevoutTxid)?;
let prevout_spk = spend.prevout_spk.into_model().map_err(E::PrevoutSpk)?;

Ok(model::ActivityEntry::Spend(model::SpendActivity {
Expand All @@ -428,10 +429,10 @@ impl GetDescriptorActivity {
.block_hash
.map(|s| BlockHash::from_str(&s))
.transpose()
.map_err(E::Hash)?;
.map_err(E::BlockHash)?;
let height =
receive.height.map(|h| crate::to_u32(h, "height")).transpose()?; // Uses From<NumericError>
let txid = Txid::from_str(&receive.txid).map_err(E::Hash)?;
let txid = Txid::from_str(&receive.txid).map_err(E::Txid)?;
let output_spk = receive.output_spk.into_model().map_err(E::OutputSpk)?;

Ok(model::ActivityEntry::Receive(model::ReceiveActivity {
Expand Down
14 changes: 7 additions & 7 deletions types/src/v29/hidden/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,20 +66,20 @@ pub enum GetOrphanTxsVerboseTwoEntryError {
Txid(hex::HexToArrayError),
/// Conversion of the transaction `wtxid` field failed.
Wtxid(hex::HexToArrayError),
/// Conversion of hex data to bytes failed.
/// Conversion of the `hex` field to bytes failed.
Hex(hex::HexToBytesError),
/// Consensus decoding of `hex` to transaction failed.
Consensus(encode::Error),
/// Consensus decoding of the `hex` bytes to `transaction` failed.
Transaction(encode::Error),
}

impl fmt::Display for GetOrphanTxsVerboseTwoEntryError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
match *self {
Self::Txid(ref e) => write_err!(f, "conversion of the `txid` field failed"; e),
Self::Wtxid(ref e) => write_err!(f, "conversion of the `wtxid` field failed"; e),
Self::Hex(ref e) => write_err!(f, "conversion of hex data to bytes failed"; e),
Self::Consensus(ref e) =>
write_err!(f, "consensus decoding of `hex` to transaction failed"; e),
Self::Hex(ref e) => write_err!(f, "conversion of the `hex` field to bytes failed"; e),
Self::Transaction(ref e) =>
write_err!(f, "consensus decoding of the `hex` bytes to `transaction` failed"; e),
}
}
}
Expand All @@ -91,7 +91,7 @@ impl std::error::Error for GetOrphanTxsVerboseTwoEntryError {
Self::Txid(ref e) => Some(e),
Self::Wtxid(ref e) => Some(e),
Self::Hex(ref e) => Some(e),
Self::Consensus(ref e) => Some(e),
Self::Transaction(ref e) => Some(e),
}
}
}
2 changes: 1 addition & 1 deletion types/src/v29/hidden/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl GetOrphanTxsVerboseTwoEntry {
let txid = self.txid.parse::<Txid>().map_err(E::Txid)?;
let wtxid = self.wtxid.parse::<Wtxid>().map_err(E::Wtxid)?;
let v = Vec::from_hex(&self.hex).map_err(E::Hex)?;
let transaction = encode::deserialize::<Transaction>(&v).map_err(E::Consensus)?;
let transaction = encode::deserialize::<Transaction>(&v).map_err(E::Transaction)?;

Ok(model::GetOrphanTxsVerboseTwoEntry {
txid,
Expand Down
73 changes: 0 additions & 73 deletions types/src/v30/hidden/error.rs

This file was deleted.

2 changes: 1 addition & 1 deletion types/src/v30/hidden/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ impl GetOrphanTxsVerboseTwoEntry {
let txid = self.txid.parse::<Txid>().map_err(E::Txid)?;
let wtxid = self.wtxid.parse::<Wtxid>().map_err(E::Wtxid)?;
let v = Vec::from_hex(&self.hex).map_err(E::Hex)?;
let transaction = encode::deserialize::<Transaction>(&v).map_err(E::Consensus)?;
let transaction = encode::deserialize::<Transaction>(&v).map_err(E::Transaction)?;

Ok(model::GetOrphanTxsVerboseTwoEntry {
txid,
Expand Down
6 changes: 3 additions & 3 deletions types/src/v30/hidden/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@
//!
//! Types for methods that are excluded from the API docs by default.

mod error;
mod into;

use serde::{Deserialize, Serialize};

pub use self::error::{GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwoEntryError};
pub use super::GetOrphanTxsError;
pub use super::{
GetOrphanTxsError, GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwoEntryError,
};

/// Result of JSON-RPC method `getorphantxs` verbosity 0.
///
Expand Down
6 changes: 3 additions & 3 deletions types/src/v30/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,8 @@ mod wallet;
pub use self::{
blockchain::GetMempoolInfo,
hidden::{
GetOrphanTxs, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry,
GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwo, GetOrphanTxsVerboseTwoEntry,
GetOrphanTxsVerboseTwoEntryError,
GetOrphanTxs, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry, GetOrphanTxsVerboseTwo,
GetOrphanTxsVerboseTwoEntry,
},
mining::{GetMiningInfo, GetMiningInfoError},
raw_transactions::{
Expand Down Expand Up @@ -365,6 +364,7 @@ pub use crate::{
GetBlockVerboseTwoError, GetBlockVerboseTwoTransaction, GetBlockchainInfo,
GetBlockchainInfoError, GetChainStates, GetChainStatesError, GetDescriptorActivity,
GetDescriptorActivityError, GetDescriptorInfo, GetOrphanTxsError,
GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwoEntryError,
GetRawTransactionVerboseWithPrevout, MempoolAcceptance, MempoolAcceptanceFees,
NextBlockInfo, NextBlockInfoError, RawTransactionInputWithPrevout, ReceiveActivity,
SpendActivity, TestMempoolAccept,
Expand Down
Loading