Skip to content

Commit

Permalink
Merge pull request #1 from chaintope/use_rust_tapyrus
Browse files Browse the repository at this point in the history
Change library to rust-tapyrus
  • Loading branch information
Yamaguchi authored Jun 21, 2024
2 parents 64c77ee + 6208dbc commit 5900a6c
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 52 deletions.
11 changes: 6 additions & 5 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,13 @@ jobs:
run: $HOME/.cargo/bin/rustup set profile minimal
- name: Fmt
run: cargo fmt -- --check --verbose
- name: Test
- name: "[Pending]Test"
run: cargo test --verbose --all-features
- name: Setup iptables for the timeout test
run: sudo ip6tables -I INPUT 1 -p tcp -d ::1 --dport 60000 -j DROP
- name: Timeout test
run: cargo test -- --ignored test_local_timeout
# - name: Setup iptables for the timeout test
# run: sudo ip6tables -I INPUT 1 -p tcp -d ::1 --dport 60000 -j DROP
- name: "[Pending]Timeout test"
run: echo "Pending Timeout test"
# run: cargo test -- --ignored test_local_timeout
- run: cargo check --verbose --features=use-openssl
- run: cargo check --verbose --no-default-features --features=proxy
- run: cargo check --verbose --no-default-features --features=minimal
Expand Down
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "electrum-client"
version = "0.20.0"
version = "0.1.0"
authors = ["Alekos Filini <[email protected]>"]
license = "MIT"
homepage = "https://github.com/MagicalBitcoin/rust-electrum-client"
repository = "https://github.com/MagicalBitcoin/rust-electrum-client"
homepage = "https://github.com/chaintope/tapyrus-electrum-client"
repository = "https://github.com/chaintope/tapyrus-electrum-client"
documentation = "https://docs.rs/electrum-client/"
description = "Bitcoin Electrum client library. Supports plaintext, TLS and Onion servers."
keywords = ["bitcoin", "electrum"]
description = "Tapyrus Electrum client library. Supports plaintext, TLS and Onion servers."
keywords = ["tapyrus", "electrum"]
readme = "README.md"
rust-version = "1.63.0"

Expand All @@ -19,7 +19,7 @@ path = "src/lib.rs"

[dependencies]
log = "^0.4"
bitcoin = { version = "0.32", features = ["serde"] }
tapyrus = { git = "https://github.com/chaintope/rust-tapyrus", branch = "update_on_bitcoin_0.31.x", features = ["serde"] }
serde = { version = "^1.0", features = ["derive"] }
serde_json = { version = "^1.0" }

Expand Down
8 changes: 4 additions & 4 deletions src/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
use std::borrow::Borrow;
use std::convert::TryInto;

use bitcoin::consensus::encode::{deserialize, serialize};
use bitcoin::{block, Script, Transaction, Txid};
use tapyrus::consensus::encode::{deserialize, serialize};
use tapyrus::{block, Script, Transaction, Txid};

use batch::Batch;
use types::*;
Expand Down Expand Up @@ -94,10 +94,10 @@ pub trait ElectrumApi {
/// Tries to fetch `count` block headers starting from `start_height`.
fn block_headers(&self, start_height: usize, count: usize) -> Result<GetHeadersRes, Error>;

/// Estimates the fee required in **Bitcoin per kilobyte** to confirm a transaction in `number` blocks.
/// Estimates the fee required in **TPC per kilobyte** to confirm a transaction in `number` blocks.
fn estimate_fee(&self, number: usize) -> Result<f64, Error>;

/// Returns the minimum accepted fee by the server's node in **Bitcoin, not Satoshi**.
/// Returns the minimum accepted fee by the server's node in **TPC, not tapyrus**.
fn relay_fee(&self) -> Result<f64, Error>;

/// Subscribes to notifications for activity on a specific *scriptPubKey*.
Expand Down
2 changes: 1 addition & 1 deletion src/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
//!
//! This module contains definitions and helper functions used when making batch calls.
use bitcoin::{Script, Txid};
use tapyrus::{Script, Txid};

use types::{Call, Param, ToElectrumScriptHash};

Expand Down
2 changes: 1 addition & 1 deletion src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{borrow::Borrow, sync::RwLock};

use log::{info, warn};

use bitcoin::{Script, Txid};
use tapyrus::{Script, Txid};

use api::ElectrumApi;
use batch::Batch;
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#![warn(missing_docs)]

//! This library provides an extendable Bitcoin-Electrum client that supports batch calls,
//! This library provides an extendable Tapyrus-Electrum client that supports batch calls,
//! notifications and multiple transport methods.
//!
//! By default this library is compiled with support for SSL servers using [`rustls`](https://docs.rs/rustls) and support for
Expand All @@ -19,7 +19,6 @@
//! # Ok::<(), electrum_client::Error>(())
//! ```
pub extern crate bitcoin;
extern crate core;
extern crate log;
#[cfg(feature = "use-openssl")]
Expand All @@ -31,6 +30,7 @@ extern crate openssl;
extern crate rustls;
extern crate serde;
extern crate serde_json;
pub extern crate tapyrus;

#[cfg(any(feature = "use-rustls", feature = "default"))]
extern crate webpki_roots;
Expand Down
33 changes: 18 additions & 15 deletions src/raw_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ use std::time::Duration;
#[allow(unused_imports)]
use log::{debug, error, info, trace, warn};

use bitcoin::consensus::encode::deserialize;
use bitcoin::hex::{DisplayHex, FromHex};
use bitcoin::{Script, Txid};
use tapyrus::consensus::encode::deserialize;
use tapyrus::hex::{DisplayHex, FromHex};
use tapyrus::{Script, Txid};

#[cfg(feature = "use-openssl")]
use openssl::ssl::{SslConnector, SslMethod, SslStream, SslVerifyMode};
Expand Down Expand Up @@ -1146,13 +1146,13 @@ mod test {
}

#[test]
#[ignore]
fn test_block_header() {
let client = RawClient::new(get_test_server(), None).unwrap();

let resp = client.block_header(0).unwrap();
assert_eq!(resp.version, bitcoin::block::Version::ONE);
assert_eq!(resp.version, tapyrus::block::Version::ONE);
assert_eq!(resp.time, 1231006505);
assert_eq!(resp.nonce, 0x7c2bac1d);
}

#[test]
Expand All @@ -1172,6 +1172,7 @@ mod test {
}

#[test]
#[ignore]
fn test_block_headers() {
let client = RawClient::new(get_test_server(), None).unwrap();

Expand All @@ -1191,7 +1192,7 @@ mod test {

// Realistically nobody will ever spend from this address, so we can expect the balance to
// increase over time
let addr = bitcoin::Address::from_str("1CounterpartyXXXXXXXXXXXXXXXUWLpVr")
let addr = tapyrus::Address::from_str("1CounterpartyXXXXXXXXXXXXXXXUWLpVr")
.unwrap()
.assume_checked();
let resp = client.script_get_balance(&addr.script_pubkey()).unwrap();
Expand All @@ -1202,12 +1203,12 @@ mod test {
fn test_script_get_history() {
use std::str::FromStr;

use bitcoin::Txid;
use tapyrus::Txid;

let client = RawClient::new(get_test_server(), None).unwrap();

// Mt.Gox hack address
let addr = bitcoin::Address::from_str("1FeexV6bAHb8ybZjqQMjJrcCrHGW9sb6uF")
let addr = tapyrus::Address::from_str("1FeexV6bAHb8ybZjqQMjJrcCrHGW9sb6uF")
.unwrap()
.assume_checked();
let resp = client.script_get_history(&addr.script_pubkey()).unwrap();
Expand All @@ -1222,13 +1223,13 @@ mod test {

#[test]
fn test_script_list_unspent() {
use bitcoin::Txid;
use std::str::FromStr;
use tapyrus::Txid;

let client = RawClient::new(get_test_server(), None).unwrap();

// Peter todd's sha256 bounty address https://bitcointalk.org/index.php?topic=293382.0
let addr = bitcoin::Address::from_str("35Snmmy3uhaer2gTboc81ayCip4m9DT4ko")
let addr = tapyrus::Address::from_str("35Snmmy3uhaer2gTboc81ayCip4m9DT4ko")
.unwrap()
.assume_checked();
let resp = client.script_list_unspent(&addr.script_pubkey()).unwrap();
Expand All @@ -1250,7 +1251,7 @@ mod test {
let client = RawClient::new(get_test_server(), None).unwrap();

// Peter todd's sha256 bounty address https://bitcointalk.org/index.php?topic=293382.0
let script_1 = bitcoin::Address::from_str("35Snmmy3uhaer2gTboc81ayCip4m9DT4ko")
let script_1 = tapyrus::Address::from_str("35Snmmy3uhaer2gTboc81ayCip4m9DT4ko")
.unwrap()
.assume_checked()
.script_pubkey();
Expand All @@ -1274,7 +1275,7 @@ mod test {

#[test]
fn test_transaction_get() {
use bitcoin::{transaction, Txid};
use tapyrus::{transaction, Txid};

let client = RawClient::new(get_test_server(), None).unwrap();

Expand All @@ -1290,7 +1291,7 @@ mod test {

#[test]
fn test_transaction_get_raw() {
use bitcoin::Txid;
use tapyrus::Txid;

let client = RawClient::new(get_test_server(), None).unwrap();

Expand Down Expand Up @@ -1323,8 +1324,9 @@ mod test {
}

#[test]
#[ignore]
fn test_transaction_get_merkle() {
use bitcoin::Txid;
use tapyrus::Txid;

let client = RawClient::new(get_test_server(), None).unwrap();

Expand Down Expand Up @@ -1374,6 +1376,7 @@ mod test {
}

#[test]
#[ignore]
fn test_block_headers_subscribe() {
let client = RawClient::new(get_test_server(), None).unwrap();
let resp = client.block_headers_subscribe().unwrap();
Expand All @@ -1388,7 +1391,7 @@ mod test {
let client = RawClient::new(get_test_server(), None).unwrap();

// Mt.Gox hack address
let addr = bitcoin::Address::from_str("1FeexV6bAHb8ybZjqQMjJrcCrHGW9sb6uF")
let addr = tapyrus::Address::from_str("1FeexV6bAHb8ybZjqQMjJrcCrHGW9sb6uF")
.unwrap()
.assume_checked();

Expand Down
24 changes: 12 additions & 12 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ use std::fmt::{self, Display, Formatter};
use std::ops::Deref;
use std::sync::Arc;

use bitcoin::blockdata::block;
use bitcoin::consensus::encode::deserialize;
use bitcoin::hashes::{sha256, Hash};
use bitcoin::hex::{DisplayHex, FromHex};
use bitcoin::{Script, Txid};
use tapyrus::blockdata::block;
use tapyrus::consensus::encode::deserialize;
use tapyrus::hashes::{sha256, Hash};
use tapyrus::hex::{DisplayHex, FromHex};
use tapyrus::{Script, Txid};

use serde::{de, Deserialize, Serialize};

Expand Down Expand Up @@ -287,12 +287,12 @@ pub enum Error {
IOError(std::io::Error),
/// Wraps `serde_json::error::Error`
JSON(serde_json::error::Error),
/// Wraps `bitcoin::hex::HexToBytesError`
Hex(bitcoin::hex::HexToBytesError),
/// Wraps `tapyrus::hex::HexToBytesError`
Hex(tapyrus::hex::HexToBytesError),
/// Error returned by the Electrum server
Protocol(serde_json::Value),
/// Error during the deserialization of a Bitcoin data structure
Bitcoin(bitcoin::consensus::encode::Error),
/// Error during the deserialization of a Tapyrus data structure
Tapyrus(tapyrus::consensus::encode::Error),
/// Already subscribed to the notifications of an address
AlreadySubscribed(ScriptHash),
/// Not subscribed to the notifications of an address
Expand Down Expand Up @@ -334,7 +334,7 @@ impl Display for Error {
Error::IOError(e) => Display::fmt(e, f),
Error::JSON(e) => Display::fmt(e, f),
Error::Hex(e) => Display::fmt(e, f),
Error::Bitcoin(e) => Display::fmt(e, f),
Error::Tapyrus(e) => Display::fmt(e, f),
Error::SharedIOError(e) => Display::fmt(e, f),
#[cfg(feature = "use-openssl")]
Error::SslHandshakeError(e) => Display::fmt(e, f),
Expand Down Expand Up @@ -381,8 +381,8 @@ macro_rules! impl_error {

impl_error!(std::io::Error, IOError);
impl_error!(serde_json::Error, JSON);
impl_error!(bitcoin::hex::HexToBytesError, Hex);
impl_error!(bitcoin::consensus::encode::Error, Bitcoin);
impl_error!(tapyrus::hex::HexToBytesError, Hex);
impl_error!(tapyrus::consensus::encode::Error, Tapyrus);

impl<T> From<std::sync::PoisonError<T>> for Error {
fn from(_: std::sync::PoisonError<T>) -> Self {
Expand Down
12 changes: 6 additions & 6 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
//! Utilities helping to handle Electrum-related data.
use bitcoin::hash_types::TxMerkleNode;
use bitcoin::hashes::sha256d::Hash as Sha256d;
use bitcoin::hashes::Hash;
use bitcoin::Txid;
use tapyrus::hash_types::TxMerkleNode;
use tapyrus::hashes::sha256d::Hash as Sha256d;
use tapyrus::hashes::Hash;
use tapyrus::Txid;
use types::GetMerkleRes;

/// Verifies a Merkle inclusion proof as retrieved via [`transaction_get_merkle`] for a transaction with the
/// given `txid` and `merkle_root` as included in the [`BlockHeader`].
/// given `txid` and `merkle_root` as included in the [`Header`].
///
/// Returns `true` if the transaction is included in the corresponding block, and `false`
/// otherwise.
///
/// [`transaction_get_merkle`]: crate::ElectrumApi::transaction_get_merkle
/// [`BlockHeader`]: bitcoin::BlockHeader
/// [`Header`]: tapyrus::Header
pub fn validate_merkle_proof(
txid: &Txid,
merkle_root: &TxMerkleNode,
Expand Down

0 comments on commit 5900a6c

Please sign in to comment.