Skip to content

Commit

Permalink
Merge pull request #1 from chaintope/change_tapyrus_to_bitcoin
Browse files Browse the repository at this point in the history
Change bitcoin library to tapyrus
  • Loading branch information
rantan authored Jul 1, 2024
2 parents 6002aea + 496b922 commit 64690e5
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 111 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/code_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ jobs:
RUSTFLAGS: "-Cinstrument-coverage"
RUSTDOCFLAGS: "-Cinstrument-coverage"
LLVM_PROFILE_FILE: "report-%p-%m.profraw"

NETWORK_ID: 1905960821
PRIVATE_KEY: cUJN5RVzYWFoeY8rUztd47jzXCu1p57Ay8V7pqCzsBD3PEXN7Dd4
GENESIS_BLOCK: 0100000000000000000000000000000000000000000000000000000000000000000000002b5331139c6bc8646bb4e5737c51378133f70b9712b75548cb3c05f9188670e7440d295e7300c5640730c4634402a3e66fb5d921f76b48d8972a484cc0361e66ef74f45e012103af80b90d25145da28c583359beb47b21796b2fe1a23c1511e443e7a64dfdb27d40e05f064662d6b9acf65ae416379d82e11a9b78cdeb3a316d1057cd2780e3727f70a61f901d10acbe349cd11e04aa6b4351e782c44670aefbe138e99a5ce75ace01010000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0100f2052a010000001976a91445d405b9ed450fec89044f9b7a99a4ef6fe2cd3f88ac00000000
steps:
- name: Checkout
uses: actions/checkout@v2
Expand Down
4 changes: 4 additions & 0 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ jobs:
build-test:

runs-on: ubuntu-latest
env:
NETWORK_ID: 1905960821
PRIVATE_KEY: cUJN5RVzYWFoeY8rUztd47jzXCu1p57Ay8V7pqCzsBD3PEXN7Dd4
GENESIS_BLOCK: 0100000000000000000000000000000000000000000000000000000000000000000000002b5331139c6bc8646bb4e5737c51378133f70b9712b75548cb3c05f9188670e7440d295e7300c5640730c4634402a3e66fb5d921f76b48d8972a484cc0361e66ef74f45e012103af80b90d25145da28c583359beb47b21796b2fe1a23c1511e443e7a64dfdb27d40e05f064662d6b9acf65ae416379d82e11a9b78cdeb3a316d1057cd2780e3727f70a61f901d10acbe349cd11e04aa6b4351e782c44670aefbe138e99a5ce75ace01010000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0100f2052a010000001976a91445d405b9ed450fec89044f9b7a99a4ef6fe2cd3f88ac00000000
strategy:
matrix:
rust:
Expand Down
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ 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"

Expand All @@ -18,7 +18,7 @@ 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
28 changes: 14 additions & 14 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 @@ -83,7 +83,7 @@ pub struct Tx {

#[derive(Deserialize, Clone, Debug, PartialEq, Eq)]
pub struct BlockTime {
pub timestamp: u64,
pub time: u64,
pub height: u32,
}

Expand All @@ -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 @@ -133,9 +133,9 @@ impl Tx {
TxStatus {
confirmed: true,
block_height: Some(height),
block_time: Some(timestamp),
block_time: Some(time),
..
} => Some(BlockTime { timestamp, height }),
} => Some(BlockTime { time, height }),
_ => None,
}
}
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 64690e5

Please sign in to comment.