Skip to content

Commit

Permalink
Change bitcoin library to tapyrus
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamaguchi committed Jun 25, 2024
1 parent 6002aea commit 6527a32
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 107 deletions.
14 changes: 7 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,21 @@ version = "0.9.0"
edition = "2018"
authors = ["Alekos Filini <[email protected]>"]
license = "MIT"
homepage = "https://github.com/bitcoindevkit/rust-esplora-client"
repository = "https://github.com/bitcoindevkit/rust-esplora-client"
homepage = "https://github.com/chaintope/rust-esplora-client"
repository = "https://github.com/chaintope/rust-esplora-client"
documentation = "https://docs.rs/esplora-client/"
description = "Bitcoin Esplora API client library. Supports plaintext, TLS and Onion servers. Blocking or async"
keywords = ["bitcoin", "esplora"]
description = "Tapyrus Esplora API client library. Supports plaintext, TLS and Onion servers. Blocking or async"
keywords = ["tapyrus", "esplora"]
readme = "README.md"
rust-version = "1.63.0"

[lib]
name = "esplora_client"
name = "tapyrus_esplora_client"
path = "src/lib.rs"

[dependencies]
serde = { version = "1.0", features = ["derive"] }
bitcoin = { version = "0.32", features = ["serde", "std"], default-features = false }
tapyrus = { git = "https://github.com/chaintope/rust-tapyrus", branch = "update_on_bitcoin_0.31.x", default-features = false, features = ["serde", "std"] }
hex = { package = "hex-conservative", version = "0.2" }
log = "^0.4"
minreq = { version = "2.11.0", features = ["json-using-serde"], optional = true }
Expand All @@ -27,7 +27,7 @@ reqwest = { version = "0.11", optional = true, default-features = false, feature
[dev-dependencies]
serde_json = "1.0"
tokio = { version = "1.20.1", features = ["full"] }
electrsd = { version = "0.28.0", features = ["legacy", "esplora_a33e97e1", "bitcoind_25_0"] }
electrsd = { git = "https://github.com/chaintope/electrsd", features = ["legacy", "electrs_0_5_1", "tapyrusd_0_5_2"] }
lazy_static = "1.4.0"

[features]
Expand Down
22 changes: 11 additions & 11 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
//!
//! see: <https://github.com/Blockstream/esplora/blob/master/API.md>
pub use bitcoin::consensus::{deserialize, serialize};
pub use bitcoin::hex::FromHex;
use bitcoin::Weight;
pub use bitcoin::{
pub use tapyrus::consensus::{deserialize, serialize};
pub use tapyrus::hex::FromHex;
use tapyrus::Weight;
pub use tapyrus::{
transaction, Amount, BlockHash, OutPoint, ScriptBuf, Transaction, TxIn, TxOut, Txid, Witness,
};

Expand Down Expand Up @@ -93,15 +93,15 @@ pub struct BlockSummary {
#[serde(flatten)]
pub time: BlockTime,
/// Hash of the previous block, will be `None` for the genesis block.
pub previousblockhash: Option<bitcoin::BlockHash>,
pub merkle_root: bitcoin::hash_types::TxMerkleNode,
pub previousblockhash: Option<tapyrus::BlockHash>,
pub merkle_root: tapyrus::hash_types::TxMerkleNode,
}

impl Tx {
pub fn to_tx(&self) -> Transaction {
Transaction {
version: transaction::Version::non_standard(self.version),
lock_time: bitcoin::absolute::LockTime::from_consensus(self.locktime),
lock_time: tapyrus::absolute::LockTime::from_consensus(self.locktime),
input: self
.vin
.iter()
Expand All @@ -112,7 +112,7 @@ impl Tx {
vout: vin.vout,
},
script_sig: vin.scriptsig,
sequence: bitcoin::Sequence(vin.sequence),
sequence: tapyrus::Sequence(vin.sequence),
witness: Witness::from_slice(&vin.witness),
})
.collect(),
Expand All @@ -121,7 +121,7 @@ impl Tx {
.iter()
.cloned()
.map(|vout| TxOut {
value: Amount::from_sat(vout.value),
value: Amount::from_tap(vout.value),
script_pubkey: vout.scriptpubkey,
})
.collect(),
Expand All @@ -147,7 +147,7 @@ impl Tx {
.map(|vin| {
vin.prevout.map(|po| TxOut {
script_pubkey: po.scriptpubkey,
value: Amount::from_sat(po.value),
value: Amount::from_tap(po.value),
})
})
.collect()
Expand All @@ -158,7 +158,7 @@ impl Tx {
}

pub fn fee(&self) -> Amount {
Amount::from_sat(self.fee)
Amount::from_tap(self.fee)
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/async.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@
use std::collections::HashMap;
use std::str::FromStr;

use bitcoin::consensus::{deserialize, serialize};
use bitcoin::hashes::{sha256, Hash};
use bitcoin::hex::{DisplayHex, FromHex};
use bitcoin::{
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,
};

Expand Down
12 changes: 6 additions & 6 deletions src/blocking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ use log::{debug, error, info, trace};

use minreq::{Proxy, Request};

use bitcoin::consensus::{deserialize, serialize, Decodable};
use bitcoin::hashes::{sha256, Hash};
use bitcoin::hex::{DisplayHex, FromHex};
use bitcoin::{
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,
};

Expand Down Expand Up @@ -118,7 +118,7 @@ impl BlockingClient {
let hex_str = resp.as_str().map_err(Error::Minreq)?;
let hex_vec = Vec::from_hex(hex_str).unwrap();
deserialize::<T>(&hex_vec)
.map_err(Error::BitcoinEncoding)
.map_err(Error::TapyrusEncoding)
.map(|r| Some(r))
}
Err(e) => Err(Error::Minreq(e)),
Expand All @@ -135,7 +135,7 @@ impl BlockingClient {
Ok(resp) => {
let hex_str = resp.as_str().map_err(Error::Minreq)?;
let hex_vec = Vec::from_hex(hex_str).unwrap();
deserialize::<T>(&hex_vec).map_err(Error::BitcoinEncoding)
deserialize::<T>(&hex_vec).map_err(Error::TapyrusEncoding)
}
Err(e) => Err(Error::Minreq(e)),
}
Expand Down
Loading

0 comments on commit 6527a32

Please sign in to comment.