diff --git a/src/api.rs b/src/api.rs index 940a1f1..040be2e 100644 --- a/src/api.rs +++ b/src/api.rs @@ -4,7 +4,7 @@ pub use tapyrus::consensus::{deserialize, serialize}; pub use tapyrus::hex::FromHex; -use tapyrus::Weight; +use tapyrus::{MalFixTxid, Weight}; pub use tapyrus::{ transaction, Amount, BlockHash, OutPoint, ScriptBuf, Transaction, TxIn, TxOut, Txid, Witness, }; @@ -19,7 +19,7 @@ pub struct PrevOut { #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] pub struct Vin { - pub txid: Txid, + pub txid: MalFixTxid, pub vout: u32, // None if coinbase pub prevout: Option, @@ -47,14 +47,14 @@ pub struct TxStatus { #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] pub struct MerkleProof { pub block_height: u32, - pub merkle: Vec, + pub merkle: Vec, pub pos: usize, } #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] pub struct OutputStatus { pub spent: bool, - pub txid: Option, + pub txid: Option, pub vin: Option, pub status: Option, } @@ -68,7 +68,7 @@ pub struct BlockStatus { #[derive(Deserialize, Clone, Debug, PartialEq, Eq)] pub struct Tx { - pub txid: Txid, + pub txid: MalFixTxid, pub version: i32, pub locktime: u32, pub vin: Vec, diff --git a/src/async.rs b/src/async.rs index cd45acf..7be917d 100644 --- a/src/async.rs +++ b/src/async.rs @@ -17,9 +17,7 @@ use std::str::FromStr; use tapyrus::consensus::{deserialize, serialize}; use tapyrus::hashes::{sha256, Hash}; use tapyrus::hex::{DisplayHex, FromHex}; -use tapyrus::{ - block::Header as BlockHeader, Block, BlockHash, MerkleBlock, Script, Transaction, Txid, -}; +use tapyrus::{block::Header as BlockHeader, Block, BlockHash, MerkleBlock, Script, Transaction, MalFixTxid}; #[allow(unused_imports)] use log::{debug, error, info, trace}; @@ -69,8 +67,8 @@ impl AsyncClient { AsyncClient { url, client } } - /// Get a [`Transaction`] option given its [`Txid`] - pub async fn get_tx(&self, txid: &Txid) -> Result, Error> { + /// Get a [`Transaction`] option given its [`MalFixTxid`] + pub async fn get_tx(&self, txid: &MalFixTxid) -> Result, Error> { let resp = self .client .get(&format!("{}/tx/{}/raw", self.url, txid)) @@ -91,8 +89,8 @@ impl AsyncClient { } } - /// Get a [`Transaction`] given its [`Txid`]. - pub async fn get_tx_no_opt(&self, txid: &Txid) -> Result { + /// Get a [`Transaction`] given its [`MalFixTxid`]. + pub async fn get_tx_no_opt(&self, txid: &MalFixTxid) -> Result { match self.get_tx(txid).await { Ok(Some(tx)) => Ok(tx), Ok(None) => Err(Error::TransactionNotFound(*txid)), @@ -100,12 +98,12 @@ impl AsyncClient { } } - /// Get a [`Txid`] of a transaction given its index in a block with a given hash. + /// Get a [`MalFixTxid`] of a transaction given its index in a block with a given hash. pub async fn get_txid_at_block_index( &self, block_hash: &BlockHash, index: usize, - ) -> Result, Error> { + ) -> Result, Error> { let resp = self .client .get(&format!("{}/block/{}/txid/{}", self.url, block_hash, index)) @@ -122,12 +120,12 @@ impl AsyncClient { message: resp.text().await?, }) } else { - Ok(Some(Txid::from_str(&resp.text().await?)?)) + Ok(Some(MalFixTxid::from_str(&resp.text().await?)?)) } } - /// Get the status of a [`Transaction`] given its [`Txid`]. - pub async fn get_tx_status(&self, txid: &Txid) -> Result { + /// Get the status of a [`Transaction`] given its [`MalFixTxid`]. + pub async fn get_tx_status(&self, txid: &MalFixTxid) -> Result { let resp = self .client .get(&format!("{}/tx/{}/status", self.url, txid)) @@ -143,8 +141,8 @@ impl AsyncClient { } } - /// Get transaction info given it's [`Txid`]. - pub async fn get_tx_info(&self, txid: &Txid) -> Result, Error> { + /// Get transaction info given it's [`MalFixTxid`]. + pub async fn get_tx_info(&self, txid: &MalFixTxid) -> Result, Error> { let resp = self .client .get(&format!("{}/tx/{}", self.url, txid)) @@ -222,8 +220,8 @@ impl AsyncClient { } } - /// Get a merkle inclusion proof for a [`Transaction`] with the given [`Txid`]. - pub async fn get_merkle_proof(&self, tx_hash: &Txid) -> Result, Error> { + /// Get a merkle inclusion proof for a [`Transaction`] with the given [`MalFixTxid`]. + pub async fn get_merkle_proof(&self, tx_hash: &MalFixTxid) -> Result, Error> { let resp = self .client .get(&format!("{}/tx/{}/merkle-proof", self.url, tx_hash)) @@ -244,8 +242,8 @@ impl AsyncClient { } } - /// Get a [`MerkleBlock`] inclusion proof for a [`Transaction`] with the given [`Txid`]. - pub async fn get_merkle_block(&self, tx_hash: &Txid) -> Result, Error> { + /// Get a [`MerkleBlock`] inclusion proof for a [`Transaction`] with the given [`MalFixTxid`]. + pub async fn get_merkle_block(&self, tx_hash: &MalFixTxid) -> Result, Error> { let resp = self .client .get(&format!("{}/tx/{}/merkleblock-proof", self.url, tx_hash)) @@ -267,10 +265,10 @@ impl AsyncClient { } } - /// Get the spending status of an output given a [`Txid`] and the output index. + /// Get the spending status of an output given a [`MalFixTxid`] and the output index. pub async fn get_output_status( &self, - txid: &Txid, + txid: &MalFixTxid, index: u64, ) -> Result, Error> { let resp = self @@ -376,7 +374,7 @@ impl AsyncClient { pub async fn scripthash_txs( &self, script: &Script, - last_seen: Option, + last_seen: Option, ) -> Result, Error> { let script_hash = sha256::Hash::hash(script.as_bytes()); let url = match last_seen { diff --git a/src/blocking.rs b/src/blocking.rs index 6147258..f3d5f6f 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -23,9 +23,7 @@ use minreq::{Proxy, Request}; use tapyrus::consensus::{deserialize, serialize, Decodable}; use tapyrus::hashes::{sha256, Hash}; use tapyrus::hex::{DisplayHex, FromHex}; -use tapyrus::{ - block::Header as BlockHeader, Block, BlockHash, MerkleBlock, Script, Transaction, Txid, -}; +use tapyrus::{block::Header as BlockHeader, Block, BlockHash, MerkleBlock, Script, Transaction, MalFixTxid}; use crate::{BlockStatus, BlockSummary, Builder, Error, MerkleProof, OutputStatus, Tx, TxStatus}; @@ -91,7 +89,7 @@ impl BlockingClient { } } - fn get_opt_response_txid(&self, path: &str) -> Result, Error> { + fn get_opt_response_txid(&self, path: &str) -> Result, Error> { match self.get_request(path)?.send() { Ok(resp) if is_status_not_found(resp.status_code) => Ok(None), Ok(resp) if !is_status_ok(resp.status_code) => { @@ -100,7 +98,7 @@ impl BlockingClient { Err(Error::HttpResponse { status, message }) } Ok(resp) => Ok(Some( - Txid::from_str(resp.as_str().map_err(Error::Minreq)?).map_err(Error::HexToArray)?, + MalFixTxid::from_str(resp.as_str().map_err(Error::Minreq)?).map_err(Error::HexToArray)?, )), Err(e) => Err(Error::Minreq(e)), } @@ -185,13 +183,13 @@ impl BlockingClient { } } - /// Get a [`Transaction`] option given its [`Txid`] - pub fn get_tx(&self, txid: &Txid) -> Result, Error> { + /// Get a [`Transaction`] option given its [`MalFixTxid`] + pub fn get_tx(&self, txid: &MalFixTxid) -> Result, Error> { self.get_opt_response(&format!("/tx/{}/raw", txid)) } - /// Get a [`Transaction`] given its [`Txid`]. - pub fn get_tx_no_opt(&self, txid: &Txid) -> Result { + /// Get a [`Transaction`] given its [`MalFixTxid`]. + pub fn get_tx_no_opt(&self, txid: &MalFixTxid) -> Result { match self.get_tx(txid) { Ok(Some(tx)) => Ok(tx), Ok(None) => Err(Error::TransactionNotFound(*txid)), @@ -199,22 +197,22 @@ impl BlockingClient { } } - /// Get a [`Txid`] of a transaction given its index in a block with a given hash. + /// Get a [`MalFixTxid`] of a transaction given its index in a block with a given hash. pub fn get_txid_at_block_index( &self, block_hash: &BlockHash, index: usize, - ) -> Result, Error> { + ) -> Result, Error> { self.get_opt_response_txid(&format!("/block/{}/txid/{}", block_hash, index)) } - /// Get the status of a [`Transaction`] given its [`Txid`]. - pub fn get_tx_status(&self, txid: &Txid) -> Result { + /// Get the status of a [`Transaction`] given its [`MalFixTxid`]. + pub fn get_tx_status(&self, txid: &MalFixTxid) -> Result { self.get_response_json(&format!("/tx/{}/status", txid)) } - /// Get transaction info given it's [`Txid`]. - pub fn get_tx_info(&self, txid: &Txid) -> Result, Error> { + /// Get transaction info given it's [`MalFixTxid`]. + pub fn get_tx_info(&self, txid: &MalFixTxid) -> Result, Error> { self.get_opt_response_json(&format!("/tx/{}", txid)) } @@ -233,20 +231,20 @@ impl BlockingClient { self.get_opt_response(&format!("/block/{}/raw", block_hash)) } - /// Get a merkle inclusion proof for a [`Transaction`] with the given [`Txid`]. - pub fn get_merkle_proof(&self, txid: &Txid) -> Result, Error> { + /// Get a merkle inclusion proof for a [`Transaction`] with the given [`MalFixTxid`]. + pub fn get_merkle_proof(&self, txid: &MalFixTxid) -> Result, Error> { self.get_opt_response_json(&format!("/tx/{}/merkle-proof", txid)) } - /// Get a [`MerkleBlock`] inclusion proof for a [`Transaction`] with the given [`Txid`]. - pub fn get_merkle_block(&self, txid: &Txid) -> Result, Error> { + /// Get a [`MerkleBlock`] inclusion proof for a [`Transaction`] with the given [`MalFixTxid`]. + pub fn get_merkle_block(&self, txid: &MalFixTxid) -> Result, Error> { self.get_opt_response_hex(&format!("/tx/{}/merkleblock-proof", txid)) } - /// Get the spending status of an output given a [`Txid`] and the output index. + /// Get the spending status of an output given a [`MalFixTxid`] and the output index. pub fn get_output_status( &self, - txid: &Txid, + txid: &MalFixTxid, index: u64, ) -> Result, Error> { self.get_opt_response_json(&format!("/tx/{}/outspend/{}", txid, index)) @@ -311,7 +309,7 @@ impl BlockingClient { pub fn scripthash_txs( &self, script: &Script, - last_seen: Option, + last_seen: Option, ) -> Result, Error> { let script_hash = sha256::Hash::hash(script.as_bytes()); let path = match last_seen { diff --git a/src/lib.rs b/src/lib.rs index 04e9c0d..5255e06 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -71,7 +71,7 @@ use std::collections::HashMap; use std::fmt; use std::num::TryFromIntError; -use tapyrus::consensus; +use tapyrus::{consensus, MalFixTxid}; pub mod api; @@ -185,7 +185,7 @@ pub enum Error { /// Invalid hex data returned (attempting to create a vector) HexToBytes(tapyrus::hex::HexToBytesError), /// Transaction not found - TransactionNotFound(Txid), + TransactionNotFound(MalFixTxid), /// Header height not found HeaderHeightNotFound(u32), /// Header hash not found @@ -235,8 +235,7 @@ mod test { #[cfg(all(feature = "blocking", feature = "async"))] use { electrsd::{ - electrum_client::ElectrumApi, tapyrusd::tapyruscore_rpc::json::AddressType, - tapyrusd::tapyruscore_rpc::RpcApi, + electrum_client::ElectrumApi, tapyrusd::tapyruscore_rpc::RpcApi, }, std::time::Duration, tapyrus::hashes::Hash, @@ -493,7 +492,7 @@ mod test { assert!(tx_status.confirmed); // Bogus txid returns a TxStatus with false, None, None, None - let txid = Txid::hash(b"ayyyy lmao"); + let txid = MalFixTxid::hash(b"ayyyy lmao"); let tx_status = blocking_client.get_tx_status(&txid).unwrap(); let tx_status_async = async_client.get_tx_status(&txid).await.unwrap(); assert_eq!(tx_status, tx_status_async); @@ -554,7 +553,7 @@ mod test { assert_eq!(tx_info.status.block_hash, tx_res.info.blockhash); assert_eq!(tx_info.status.block_time, tx_res.info.blocktime); - let txid = Txid::hash(b"not exist"); + let txid = MalFixTxid::hash(b"not exist"); assert_eq!(blocking_client.get_tx_info(&txid).unwrap(), None); assert_eq!(async_client.get_tx_info(&txid).await.unwrap(), None); } @@ -744,7 +743,7 @@ mod test { let merkle_block_async = async_client.get_merkle_block(&txid).await.unwrap().unwrap(); assert_eq!(merkle_block, merkle_block_async); - let mut matches = vec![txid]; + let mut matches = vec![Txid::from_byte_array(txid.to_byte_array())]; let mut indexes = vec![]; let root = merkle_block .txn @@ -887,13 +886,13 @@ mod test { .transaction() .unwrap(); let script = &expected_tx.output[0].script_pubkey; - let scripthash_txs_txids: Vec = blocking_client + let scripthash_txs_txids: Vec = blocking_client .scripthash_txs(script, None) .unwrap() .iter() .map(|tx| tx.txid) .collect(); - let scripthash_txs_txids_async: Vec = async_client + let scripthash_txs_txids_async: Vec = async_client .scripthash_txs(script, None) .await .unwrap()