Skip to content

Commit

Permalink
Merge #15: Use parse::<Txid>() in place of encode::deserialize_hex()
Browse files Browse the repository at this point in the history
6a465b4 Use parse::<Txid> instead of encode::deserialize_hex (fedemagnani)

Pull request description:

  Closes #11

ACKs for top commit:
  tcharding:
    ACK 6a465b4
  apoelstra:
    ACK 6a465b4; successfully ran local tests; interesting about the changed error type

Tree-SHA512: 12cc31b167cdfeb03674f879102ef8a5eb587ce757807482cf9caa650f7367d67e243710ad8cb097a5f9e5db02e4e354410fa5574ef13f5d9e3c00c6948557a6
  • Loading branch information
apoelstra committed Dec 4, 2024
2 parents ecc2aa5 + 6a465b4 commit 4553eec
Showing 1 changed file with 9 additions and 25 deletions.
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))
}
}

0 comments on commit 4553eec

Please sign in to comment.