Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use parse::<Txid>() in place of encode::deserialize_hex() #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
34 changes: 9 additions & 25 deletions types/src/v17/blockchain/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl GetBlockVerbosityOne {
let tx = self
.tx
.iter()
.map(|t| encode::deserialize_hex::<Txid>(t).map_err(E::Tx))
.map(|t| t.parse::<Txid>().map_err(E::Hash))
.collect::<Result<Vec<_>, _>>()?;
let median_time = self.median_time.map(|t| crate::to_u32(t, "median_time")).transpose()?;
let bits = CompactTarget::from_unprefixed_hex(&self.bits).map_err(E::Bits)?;
Expand Down Expand Up @@ -328,12 +328,8 @@ impl GetDifficulty {

impl GetMempoolAncestors {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::GetMempoolAncestors, encode::FromHexError> {
let v = self
.0
.iter()
.map(|t| encode::deserialize_hex::<Txid>(t))
.collect::<Result<Vec<_>, _>>()?;
pub fn into_model(self) -> Result<model::GetMempoolAncestors, hex::HexToArrayError> {
let v = self.0.iter().map(|t| t.parse::<Txid>()).collect::<Result<Vec<_>, _>>()?;
Ok(model::GetMempoolAncestors(v))
}
}
Expand All @@ -355,12 +351,8 @@ impl GetMempoolAncestorsVerbose {

impl GetMempoolDescendants {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::GetMempoolDescendants, encode::FromHexError> {
let v = self
.0
.iter()
.map(|t| encode::deserialize_hex::<Txid>(t))
.collect::<Result<Vec<_>, _>>()?;
pub fn into_model(self) -> Result<model::GetMempoolDescendants, hex::HexToArrayError> {
let v = self.0.iter().map(|t| t.parse::<Txid>()).collect::<Result<Vec<_>, _>>()?;
Ok(model::GetMempoolDescendants(v))
}
}
Expand Down Expand Up @@ -460,12 +452,8 @@ impl GetMempoolInfo {

impl GetRawMempool {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::GetRawMempool, encode::FromHexError> {
let v = self
.0
.iter()
.map(|t| encode::deserialize_hex::<Txid>(t))
.collect::<Result<Vec<_>, _>>()?;
pub fn into_model(self) -> Result<model::GetRawMempool, hex::HexToArrayError> {
let v = self.0.iter().map(|t| t.parse::<Txid>()).collect::<Result<Vec<_>, _>>()?;
Ok(model::GetRawMempool(v))
}
}
Expand Down Expand Up @@ -551,12 +539,8 @@ impl GetTxOutSetInfo {

impl VerifyTxOutProof {
/// Converts version specific type to a version nonspecific, more strongly typed type.
pub fn into_model(self) -> Result<model::VerifyTxOutProof, encode::FromHexError> {
let proofs = self
.0
.iter()
.map(|t| encode::deserialize_hex::<Txid>(t))
.collect::<Result<Vec<_>, _>>()?;
pub fn into_model(self) -> Result<model::VerifyTxOutProof, hex::HexToArrayError> {
let proofs = self.0.iter().map(|t| t.parse::<Txid>()).collect::<Result<Vec<_>, _>>()?;
Ok(model::VerifyTxOutProof(proofs))
}
}
Loading