diff --git a/Cargo.lock b/Cargo.lock index dcc47f6..ca05f7d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -776,6 +776,7 @@ dependencies = [ "futures", "futures-util", "fxhash", + "hex", "html2text", "hyper", "lazy_static", diff --git a/Cargo.toml b/Cargo.toml index 8ef4128..a602190 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -47,6 +47,7 @@ lru = "0.12.0" prometheus = { version = "0.13.4", features = ["process"] } lazy_static = "1.5.0" async_zmq = "0.4.0" +hex = "0.4.3" [dev-dependencies] bitcoind = { version = "0.31.0" } diff --git a/src/error.rs b/src/error.rs index ce6a3ad..1a57eb5 100644 --- a/src/error.rs +++ b/src/error.rs @@ -22,6 +22,9 @@ pub enum Error { #[error(transparent)] HexArray(#[from] bitcoin::hashes::hex::HexToArrayError), + #[error(transparent)] + Hex2(#[from] hex::FromHexError), + #[error(transparent)] ParseInt(#[from] std::num::ParseIntError), diff --git a/src/req.rs b/src/req.rs index f10371a..904f7f4 100644 --- a/src/req.rs +++ b/src/req.rs @@ -6,7 +6,6 @@ use crate::threads::index_addresses::Height; use crate::NetworkExt; use crate::{error::Error, route::ResponseType}; use bitcoin::address::NetworkUnchecked; -use bitcoin::hashes::hex::FromHex; use bitcoin::hashes::{sha256d, Hash}; use bitcoin::{consensus::deserialize, Address, BlockHash, Transaction, Txid}; use bitcoin::{OutPoint, Psbt}; @@ -90,7 +89,7 @@ pub async fn parse(req: &Request) -> Result { Err(_) => match Address::from_str(val) { Ok(address) => Resource::SearchAddress(address.assume_checked()), Err(_) => { - match Vec::::from_hex(val) + match hex::decode(val) .map(|bytes| deserialize::(&bytes)) { Ok(Ok(tx)) => Resource::SearchFullTx(tx), @@ -156,7 +155,7 @@ pub async fn parse(req: &Request) -> Result { Resource::TxToT(txid) } (&Method::GET, None, Some(&"txhex"), Some(hex), None) => { - let bytes = Vec::::from_hex(hex)?; + let bytes = hex::decode(hex)?; let tx: Transaction = deserialize(&bytes)?; Resource::FullTx(tx) } diff --git a/src/rpc/tx.rs b/src/rpc/tx.rs index 5e74427..e0df4fa 100644 --- a/src/rpc/tx.rs +++ b/src/rpc/tx.rs @@ -5,7 +5,6 @@ use crate::error::Error; use crate::state::SerTx; use crate::NODE_REST_COUNTER; use bitcoin::consensus::serialize; -use bitcoin::hashes::hex::FromHex; use bitcoin::{blockdata::constants::genesis_block, BlockHash, Network, Txid}; use hyper::body::Buf; use once_cell::sync::Lazy; @@ -37,10 +36,7 @@ pub async fn call_parse_json( network: Network, ) -> Result<(Option, SerTx), Error> { Ok(match call_json(txid).await { - Ok(tx_json) => ( - tx_json.block_hash, - SerTx(Vec::::from_hex(&tx_json.hex)?), - ), + Ok(tx_json) => (tx_json.block_hash, SerTx(hex::decode(&tx_json.hex)?)), Err(Error::GenesisTx) => { let mut block = genesis_block(network); ( diff --git a/src/state.rs b/src/state.rs index e7b9f0f..18681a3 100644 --- a/src/state.rs +++ b/src/state.rs @@ -406,14 +406,13 @@ pub fn tx_output( #[cfg(test)] mod test { - use bitcoin::hashes::hex::FromHex; use crate::state::outpoints_and_sum; #[test] fn test_prevouts() { const SOME_TX: &str = "0100000001a15d57094aa7a21a28cb20b59aab8fc7d1149a3bdbcddba9c622e4f5f6a99ece010000006c493046022100f93bb0e7d8db7bd46e40132d1f8242026e045f03a0efe71bbb8e3f475e970d790221009337cd7f1f929f00cc6ff01f03729b069a7c21b59b1736ddfee5db5946c5da8c0121033b9b137ee87d5a812d6f506efdd37f0affa7ffc310711c06c7f3e097c9447c52ffffffff0100e1f505000000001976a9140389035a9225b3839e2bbf32d826a1e222031fd888ac00000000"; - let bytes = Vec::::from_hex(SOME_TX).unwrap(); + let bytes = hex::decode(SOME_TX).unwrap(); let res = outpoints_and_sum(&bytes[..]).unwrap(); assert_eq!(res.sum, 100000000); assert_eq!(res.prevouts.len(), 1);