diff --git a/Cargo.lock b/Cargo.lock index 64f9d55..29689b4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -179,7 +179,6 @@ dependencies = [ "chrono 0.4.19 (registry+https://github.com/rust-lang/crates.io-index)", "dirs 3.0.1 (registry+https://github.com/rust-lang/crates.io-index)", "dotenv 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)", - "hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)", "lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)", "log 0.4.11 (registry+https://github.com/rust-lang/crates.io-index)", "miniscript 3.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -550,11 +549,6 @@ name = "hex" version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -[[package]] -name = "hex" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" - [[package]] name = "http" version = "0.2.1" @@ -2030,7 +2024,6 @@ dependencies = [ "checksum heck 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "20564e78d53d2bb135c343b3f47714a56af2061f1c928fdb541dc7b9fdd94205" "checksum hermit-abi 0.1.17 (registry+https://github.com/rust-lang/crates.io-index)" = "5aca5565f760fb5b220e499d72710ed156fdb74e631659e99377d9ebfbd13ae8" "checksum hex 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "805026a5d0141ffc30abb3be3173848ad46a1b1664fe632428479619a3644d77" -"checksum hex 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "644f9158b2f133fd50f5fb3242878846d9eb792e445c893805ff0e3824006e35" "checksum http 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "28d569972648b2c512421b5f2a405ad6ac9666547189d0c5477a3f200f3e02f9" "checksum http-body 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)" = "13d5ff830006f7646652e057693569bfe0d51760c0085a071769d142a205111b" "checksum httparse 1.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "cd179ae861f0c2e53da70d892f5f3029f9594be0c41dc5269cd371691b1dc2f9" diff --git a/Cargo.toml b/Cargo.toml index 99b17e9..484ca58 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -35,7 +35,6 @@ bitcoin_hashes = { version = "0.9.0", features = [ "serde" ] } bitcoincore-rpc = "0.12.0" miniscript = { version = "3.0.0", features = [ "serde" ] } chrono = { version = "0.4.19", default-features = false } -hex = "0.4.2" serde = { version = "1.0.117", features = [ "derive" ] } serde_json = "1.0.59" lazy_static = "1.4.0" diff --git a/src/electrum/server.rs b/src/electrum/server.rs index b2168eb..8dcb350 100644 --- a/src/electrum/server.rs +++ b/src/electrum/server.rs @@ -7,6 +7,7 @@ use std::sync::{Arc, Mutex}; use std::thread; use bitcoin::Txid; +use bitcoin_hashes::hex::ToHex; use serde_json::{from_str, from_value, Value}; use crate::electrum::{electrum_height, QueryExt}; @@ -255,7 +256,7 @@ impl Connection { json!(self.query.get_tx_json(&txid)?) } else { let raw = self.query.get_tx_raw(&txid)?; - json!(hex::encode(&raw)) + json!(raw.to_hex()) }) } diff --git a/src/http.rs b/src/http.rs index e424ada..ff2631f 100644 --- a/src/http.rs +++ b/src/http.rs @@ -9,7 +9,7 @@ use warp::sse::ServerSentEvent; use warp::{self, reply, Filter, Reply}; use bitcoin::{Address, BlockHash, OutPoint, Txid}; -use bitcoin_hashes::hex::FromHex; +use bitcoin_hashes::hex::{FromHex, ToHex}; use crate::error::{fmt_error_chain, BwtError, Error, OptionExt}; use crate::types::{BlockId, ScriptHash}; @@ -225,7 +225,7 @@ fn setup( .and(query.clone()) .map(|txid: Txid, query: Arc| { let tx_raw = query.get_tx_raw(&txid)?; - Ok(hex::encode(tx_raw)) + Ok(tx_raw.to_hex()) }) .map(handle_error); @@ -236,7 +236,7 @@ fn setup( .and(query.clone()) .map(|txid: Txid, query: Arc| { let proof = query.get_tx_proof(&txid)?; - Ok(hex::encode(proof)) + Ok(proof.to_hex()) }) .map(handle_error); diff --git a/src/query.rs b/src/query.rs index 1769709..19d245f 100644 --- a/src/query.rs +++ b/src/query.rs @@ -7,6 +7,7 @@ use serde::Serialize; use serde_json::Value; use bitcoin::{BlockHash, BlockHeader, Network, OutPoint, Transaction, Txid}; +use bitcoin_hashes::hex::FromHex; use bitcoincore_rpc::{json as rpcjson, Client as RpcClient, RpcApi}; use crate::error::{BwtError, Context, OptionExt, Result}; @@ -184,7 +185,7 @@ impl Query { // and is incompatible with pruning, but works for non-wallet transactions too. else { let tx_hex = self.rpc.get_raw_transaction_hex(txid, None)?; - Ok(hex::decode(tx_hex)?) + Ok(Vec::from_hex(&tx_hex)?) } } @@ -204,8 +205,8 @@ impl Query { pub fn broadcast(&self, tx_hex: &str) -> Result { if let Some(broadcast_cmd) = &self.config.broadcast_cmd { - // need to deserialize to ensure validity (preventing code injection) and to determine the txid - let tx: Transaction = bitcoin::consensus::deserialize(&hex::decode(tx_hex)?)?; + // re-serialize the tx to ensure validity (preventing potential code injection) and to determine the txid + let tx: Transaction = bitcoin::consensus::deserialize(&Vec::from_hex(tx_hex)?)?; let cmd = broadcast_cmd.replacen("{tx_hex}", tx_hex, 1); debug!("broadcasting tx with cmd {}", broadcast_cmd); let status = Command::new("sh").arg("-c").arg(cmd).status()?;