Skip to content
Open
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: 8 additions & 4 deletions integration_test/tests/hidden.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,14 @@ fn hidden__get_orphan_txs__modelled() {
let json_v1: GetOrphanTxsVerboseOne = node2.client.get_orphan_txs_verbosity_1().expect("getorphantxs 1");
let json_v2: GetOrphanTxsVerboseTwo = node2.client.get_orphan_txs_verbosity_2().expect("getorphantxs 2");

let model_v0: mtype::GetOrphanTxs = json_v0.into_model();
let model_v1: mtype::GetOrphanTxsVerboseOne = json_v1.into_model().unwrap();
let model_v2: mtype::GetOrphanTxsVerboseTwo = json_v2.into_model().unwrap();

// use explicit errors here to check that the re-exports are good
let model_v0: Result<mtype::GetOrphanTxs, GetOrphanTxsError> = json_v0.into_model();
let model_v1: Result<mtype::GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntryError> = json_v1.into_model();
let model_v2: Result<mtype::GetOrphanTxsVerboseTwo, GetOrphanTxsVerboseTwoEntryError> = json_v2.into_model();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does the formatting job also check the integration test? At least locally that should have been split over multiple lines

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently its a naive cargo fmt --all -- --check so only workspace crates get hit. integration_test and verify are excluded.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raised #495


let model_v0 = model_v0.unwrap();
let model_v1 = model_v1.unwrap();
let model_v2 = model_v2.unwrap();

assert_eq!(model_v0.0.len(), NUM_ORPHANS as usize);
assert_eq!(model_v1.0.len(), NUM_ORPHANS as usize);
Expand Down
29 changes: 27 additions & 2 deletions types/src/v29/hidden/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ use bitcoin::hex;

use crate::error::write_err;

/// Error when converting a `GetOrphanTxs` type into the model type.
#[derive(Debug)]
pub enum GetOrphanTxsError {
/// Conversion of a `txid` from the orphanage failed.
Txid(hex::HexToArrayError),
}

impl fmt::Display for GetOrphanTxsError {
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),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for GetOrphanTxsError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Txid(ref e) => Some(e),
}
}
}

/// Error when converting a `GetOrphanTxsVerboseOneEntry` type into the model type.
#[derive(Debug)]
pub enum GetOrphanTxsVerboseOneEntryError {
Expand Down Expand Up @@ -54,8 +78,9 @@ impl fmt::Display for GetOrphanTxsVerboseTwoEntryError {
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::Consensus(ref e) => {
write_err!(f, "consensus decoding of `hex` to transaction failed"; e)
}
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions types/src/v29/hidden/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ use bitcoin::hashes::hex::FromHex;
use bitcoin::{Transaction, Txid, Wtxid};

use super::{
GetOrphanTxs, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry,
GetOrphanTxs, GetOrphanTxsError, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry,
GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwo, GetOrphanTxsVerboseTwoEntry,
GetOrphanTxsVerboseTwoEntryError,
};
use crate::model;

impl GetOrphanTxs {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> model::GetOrphanTxs { model::GetOrphanTxs(self.0) }
pub fn into_model(self) -> Result<model::GetOrphanTxs, GetOrphanTxsError> {
use GetOrphanTxsError as E;

let txids: Result<Vec<Txid>, E> =
self.0.into_iter().map(|s| s.parse::<Txid>().map_err(E::Txid)).collect();

Ok(model::GetOrphanTxs(txids?))
}
}

impl GetOrphanTxsVerboseOneEntry {
Expand Down
7 changes: 4 additions & 3 deletions types/src/v29/hidden/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
mod error;
mod into;

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

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

/// Result of JSON-RPC method `getorphantxs` verbosity 0.
///
Expand All @@ -19,7 +20,7 @@ pub use self::error::{GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwoEn
/// > Shows transactions in the tx orphanage.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct GetOrphanTxs(pub Vec<Txid>);
pub struct GetOrphanTxs(pub Vec<String>);

/// Result of JSON-RPC method `getorphantxs` verbosity 1.
///
Expand Down
2 changes: 1 addition & 1 deletion types/src/v29/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ pub use self::{
SpendActivity,
},
hidden::{
GetOrphanTxs, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry,
GetOrphanTxs, GetOrphanTxsError, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry,
GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwo, GetOrphanTxsVerboseTwoEntry,
GetOrphanTxsVerboseTwoEntryError,
},
Expand Down
29 changes: 27 additions & 2 deletions types/src/v30/hidden/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,30 @@ use bitcoin::hex;

use crate::error::write_err;

/// Error when converting a `GetOrphanTxs` type into the model type.
#[derive(Debug)]
pub enum GetOrphanTxsError {
/// Conversion of the transaction `txid` field failed.
Txid(hex::HexToArrayError),
}

impl fmt::Display for GetOrphanTxsError {
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),
}
}
}

#[cfg(feature = "std")]
impl std::error::Error for GetOrphanTxsError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match *self {
Self::Txid(ref e) => Some(e),
}
}
}

/// Error when converting a `GetOrphanTxsVerboseOneEntry` type into the model type.
#[derive(Debug)]
pub enum GetOrphanTxsVerboseOneEntryError {
Expand Down Expand Up @@ -54,8 +78,9 @@ impl fmt::Display for GetOrphanTxsVerboseTwoEntryError {
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::Consensus(ref e) => {
write_err!(f, "consensus decoding of `hex` to transaction failed"; e)
}
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions types/src/v30/hidden/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,22 @@ use bitcoin::hashes::hex::FromHex;
use bitcoin::{Transaction, Txid, Wtxid};

use super::{
GetOrphanTxs, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry,
GetOrphanTxs, GetOrphanTxsError, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry,
GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwo, GetOrphanTxsVerboseTwoEntry,
GetOrphanTxsVerboseTwoEntryError,
};
use crate::model;

impl GetOrphanTxs {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> model::GetOrphanTxs { model::GetOrphanTxs(self.0) }
pub fn into_model(self) -> Result<model::GetOrphanTxs, GetOrphanTxsError> {
use GetOrphanTxsError as E;

let txids: Result<Vec<Txid>, E> =
self.0.into_iter().map(|s| s.parse::<Txid>().map_err(E::Txid)).collect();

Ok(model::GetOrphanTxs(txids?))
}
}

impl GetOrphanTxsVerboseOneEntry {
Expand Down
7 changes: 4 additions & 3 deletions types/src/v30/hidden/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,11 @@
mod error;
mod into;

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

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

/// Result of JSON-RPC method `getorphantxs` verbosity 0.
///
Expand All @@ -19,7 +20,7 @@ pub use self::error::{GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwoEn
/// > Shows transactions in the tx orphanage.
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize)]
#[cfg_attr(feature = "serde-deny-unknown-fields", serde(deny_unknown_fields))]
pub struct GetOrphanTxs(pub Vec<Txid>);
pub struct GetOrphanTxs(pub Vec<String>);

/// Result of JSON-RPC method `getorphantxs` verbosity 1.
///
Expand Down
2 changes: 1 addition & 1 deletion types/src/v30/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ mod wallet;
pub use self::{
blockchain::GetMempoolInfo,
hidden::{
GetOrphanTxs, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry,
GetOrphanTxs, GetOrphanTxsError, GetOrphanTxsVerboseOne, GetOrphanTxsVerboseOneEntry,
GetOrphanTxsVerboseOneEntryError, GetOrphanTxsVerboseTwo, GetOrphanTxsVerboseTwoEntry,
GetOrphanTxsVerboseTwoEntryError,
},
Expand Down