Skip to content

Commit

Permalink
Update for Tapyrus-Cores and esplora-tapyrus
Browse files Browse the repository at this point in the history
  • Loading branch information
Yamaguchi committed Jun 22, 2024
1 parent 0892b01 commit adbfd68
Show file tree
Hide file tree
Showing 9 changed files with 160 additions and 219 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build_electrs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
matrix:
os: [ubuntu-18.04, macos-11]
env:
ELECTRS_TAG: "v0.9.11"
ELECTRS_TAG: "v0.5.1"

steps:
- name: Check out Electrs
Expand Down
57 changes: 9 additions & 48 deletions .github/workflows/cont_integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,72 +9,33 @@ name: CI
jobs:

build:
strategy:
matrix:
os: ["macos-12", "ubuntu-22.04", "windows-2022"]
runs-on: ${{ matrix.os }}
runs-on: ubuntu-20.04
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: dtolnay/rust-toolchain@stable
- run: cargo build


test-electrs:
name: Test Electrs
runs-on: ubuntu-20.04
env:
CARGO_TERM_COLOR: always
RUST_LOG: debug
strategy:
matrix:
features:
- bitcoind_22_1,electrs_0_8_10
- bitcoind_22_1,electrs_0_9_1
- bitcoind_22_1,electrs_0_9_11
fail-fast: false

steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@stable
- run: cargo test --features ${{ matrix.features }}


test-electrs-esplora:
name: Test Electrs Esplora
runs-on: ubuntu-20.04
env:
CARGO_TERM_COLOR: always
NETWORK_ID: 1905960821
PRIVATE_KEY: cUJN5RVzYWFoeY8rUztd47jzXCu1p57Ay8V7pqCzsBD3PEXN7Dd4
GENESIS_BLOCK: 0100000000000000000000000000000000000000000000000000000000000000000000002b5331139c6bc8646bb4e5737c51378133f70b9712b75548cb3c05f9188670e7440d295e7300c5640730c4634402a3e66fb5d921f76b48d8972a484cc0361e66ef74f45e012103af80b90d25145da28c583359beb47b21796b2fe1a23c1511e443e7a64dfdb27d40e05f064662d6b9acf65ae416379d82e11a9b78cdeb3a316d1057cd2780e3727f70a61f901d10acbe349cd11e04aa6b4351e782c44670aefbe138e99a5ce75ace01010000000100000000000000000000000000000000000000000000000000000000000000000000000000ffffffff0100f2052a010000001976a91445d405b9ed450fec89044f9b7a99a4ef6fe2cd3f88ac00000000
strategy:
matrix:
features: ["bitcoind_22_1,legacy,esplora_a33e97e1"]

features:
- tapyrusd/0_5_2,legacy,electrs_0_5_1
- tapyrusd/0_5_2,legacy,electrs_0_5_0
- tapyrusd/0_5_1,legacy,electrs_0_5_1
- tapyrusd/0_5_1,legacy,electrs_0_5_0
steps:
- uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- uses: dtolnay/rust-toolchain@stable
- run: cargo test --features ${{ matrix.features }}

test-electrs-no-download:
name: Test Electrs no auto-download features
runs-on: ubuntu-20.04
env:
CARGO_TERM_COLOR: always
ELECTRS_EXEC: "/home/runner/.cargo-install/electrs/bin/electrs"
steps:
- uses: dtolnay/rust-toolchain@stable
- name: Install electrs
# Automatically cache installed binaries to avoid compiling them each run
uses: baptiste0928/cargo-install@v2
with:
crate: electrs
- run: "echo $ELECTRS_EXEC"
- name: Checkout Crate
uses: actions/checkout@v3
- uses: Swatinem/rust-cache@v2
- run: cargo test --features 'bitcoind/25_0'

cosmetics:
runs-on: ubuntu-20.04
steps:
Expand Down
33 changes: 10 additions & 23 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "electrsd"
version = "0.28.0"
version = "0.1.0"
authors = ["Riccardo Casatta <[email protected]>"]
description = "Utility to run a regtest electrs process, useful in integration testing environment"
repository = "https://github.com/RCasatta/electrsd"
Expand All @@ -10,8 +10,8 @@ edition = "2018"
categories = ["cryptography::cryptocurrencies", "development-tools::testing"]

[dependencies]
bitcoind = { version = "0.36.0" }
electrum-client = { version = "0.20.0", default-features = false }
tapyrusd = { git = "https://github.com/chaintope/tapyrusd", branch="use_rust_tapyrus" }
electrum-client = { git = "https://github.com/chaintope/rust-electrum-client", default-features = false }
log = { version = "0.4" }
which = { version = "4.2.5" }

Expand All @@ -23,10 +23,8 @@ env_logger = { version = "0.10" }

[build-dependencies]
bitcoin_hashes = { version = "0.14", optional = true }
zip = { version = "0.6", default-features = false, optional = true, features = [
"bzip2",
"deflate",
] }
flate2 = { version = "1.0", optional = true }
tar = { version = "0.4", optional = true }
minreq = { version = "2.9.0", default-features = false, optional = true, features = [
"https",
] }
Expand All @@ -35,19 +33,8 @@ minreq = { version = "2.9.0", default-features = false, optional = true, feature
legacy = []

# download is not supposed to be used directly only through selecting one of the version feature
download = ["bitcoin_hashes", "zip", "minreq"]

esplora_a33e97e1 = ["download"]
electrs_0_8_10 = ["download"]
electrs_0_9_1 = ["download"]
electrs_0_9_11 = ["download"]

bitcoind_25_0 = ["download", "bitcoind/25_0"]
bitcoind_24_0_1 = ["download", "bitcoind/24_0_1"]
bitcoind_23_1 = ["download", "bitcoind/23_1"]
bitcoind_22_1 = ["download", "bitcoind/22_1"]
bitcoind_0_21_2 = ["download", "bitcoind/0_21_2"]
bitcoind_0_20_2 = ["download", "bitcoind/0_20_2"]
bitcoind_0_19_1 = ["download", "bitcoind/0_19_1"]
bitcoind_0_18_1 = ["download", "bitcoind/0_18_1"]
bitcoind_0_17_1 = ["download", "bitcoind/0_17_1"]
download = ["bitcoin_hashes", "flate2", "tar", "minreq"]

electrs_0_5_0 = ["download"]
electrs_0_5_1 = ["download"]

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ assert_eq!(header.height, 0);
In your project Cargo.toml, activate the following features

```yml
electrsd = { version= "0.23", features = ["bitcoind_23_1", "electrs_0_9_1"] }
electrsd = { version= "0.23", features = ["tapyrusd_0_5_2", "electrs_0_5_1"] }
```

Then use it:
Expand Down
46 changes: 23 additions & 23 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,16 @@ fn main() {
#[cfg(feature = "download")]
mod download {
use bitcoin_hashes::{sha256, Hash};
use flate2::read::GzDecoder;
use std::fs::File;
use std::io::{BufRead, BufReader, Cursor};
use std::os::unix::fs::PermissionsExt;
use std::path::Path;
use std::str::FromStr;

use tar::Archive;
include!("src/versions.rs");

const GITHUB_URL: &str =
"https://github.com/RCasatta/electrsd/releases/download/electrs_releases";
const GITHUB_URL: &str = "https://github.com/chaintope/esplora-tapyrus/releases/download";

fn get_expected_sha256(filename: &str) -> Result<sha256::Hash, ()> {
let file = File::open("sha256").map_err(|_| ())?;
Expand All @@ -40,44 +40,44 @@ mod download {
return;
}
let download_filename_without_extension = electrs_name();
let download_filename = format!("{}.zip", download_filename_without_extension);
let download_filename = format!("{}.tar.gz", download_filename_without_extension);
dbg!(&download_filename);
let expected_hash = get_expected_sha256(&download_filename).unwrap();
// let expected_hash = get_expected_sha256(&download_filename).unwrap();
let out_dir = std::env::var_os("OUT_DIR").unwrap();
let electrs_exe_home = Path::new(&out_dir).join("electrs");
let destination_filename = electrs_exe_home
.join(&download_filename_without_extension)
.join("electrs");

dbg!(&destination_filename);

if !destination_filename.exists() {
println!(
"filename:{} version:{} hash:{}",
download_filename, VERSION, expected_hash
);
println!("filename:{} version:{}", download_filename, VERSION);

let download_endpoint =
std::env::var("ELECTRSD_DOWNLOAD_ENDPOINT").unwrap_or(GITHUB_URL.to_string());
let url = format!("{}/{}", download_endpoint, download_filename);
let url = format!("{}/{}/{}", download_endpoint, VERSION, download_filename);

let downloaded_bytes = minreq::get(url).send().unwrap().into_bytes();

let downloaded_hash = sha256::Hash::hash(&downloaded_bytes);
assert_eq!(expected_hash, downloaded_hash);
let cursor = Cursor::new(downloaded_bytes);
// let downloaded_hash = sha256::Hash::hash(&downloaded_bytes);
// assert_eq!(expected_hash, downloaded_hash);

let mut archive = Archive::new(GzDecoder::new(&downloaded_bytes[..]));

let mut archive = zip::ZipArchive::new(cursor).unwrap();
let mut file = archive.by_index(0).unwrap();
std::fs::create_dir_all(destination_filename.parent().unwrap()).unwrap();
let mut outfile = std::fs::File::create(&destination_filename).unwrap();
for mut entry in archive.entries().unwrap().flatten() {
if let Ok(file) = entry.path() {
if file.ends_with("electrs") {
entry.unpack(&destination_filename).unwrap();

std::io::copy(&mut file, &mut outfile).unwrap();
std::fs::set_permissions(
&destination_filename,
std::fs::Permissions::from_mode(0o755),
)
.unwrap();
std::fs::set_permissions(
&destination_filename,
std::fs::Permissions::from_mode(0o755),
)
.unwrap();
}
}
}
}
}
}
24 changes: 12 additions & 12 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ pub enum Error {
/// Wrapper of io Error
Io(std::io::Error),

/// Wrapper of bitcoind Error
Bitcoind(bitcoind::Error),
/// Wrapper of tapyrusd Error
Tapyrusd(tapyrusd::Error),

/// Wrapper of electrum_client Error
ElectrumClient(electrum_client::Error),

/// Wrapper of bitcoincore_rpc Error
BitcoinCoreRpc(bitcoind::bitcoincore_rpc::Error),
TapyrusCoreRpc(tapyrusd::tapyruscore_rpc::Error),

/// Wrapper of nix Error
#[cfg(not(target_os = "windows"))]
Expand All @@ -23,7 +23,7 @@ pub enum Error {
/// Returned when both tmpdir and staticdir is specified in `Conf` options
BothDirsSpecified,

/// Returned when calling methods requiring the bitcoind executable but none is found
/// Returned when calling methods requiring the tapyrusd executable but none is found
/// (no feature, no `ELECTRS_EXEC`, no `electrs` in `PATH` )
NoElectrsExecutableFound,

Expand All @@ -35,9 +35,9 @@ impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Io(e) => Some(e),
Error::Bitcoind(e) => Some(e),
Error::Tapyrusd(e) => Some(e),
Error::ElectrumClient(e) => Some(e),
Error::BitcoinCoreRpc(e) => Some(e),
Error::TapyrusCoreRpc(e) => Some(e),

#[cfg(not(target_os = "windows"))]
Error::Nix(e) => Some(e),
Expand All @@ -59,9 +59,9 @@ impl From<std::io::Error> for Error {
}
}

impl From<bitcoind::Error> for Error {
fn from(e: bitcoind::Error) -> Self {
Error::Bitcoind(e)
impl From<tapyrusd::Error> for Error {
fn from(e: tapyrusd::Error) -> Self {
Error::Tapyrusd(e)
}
}

Expand All @@ -71,9 +71,9 @@ impl From<electrum_client::Error> for Error {
}
}

impl From<bitcoind::bitcoincore_rpc::Error> for Error {
fn from(e: bitcoind::bitcoincore_rpc::Error) -> Self {
Error::BitcoinCoreRpc(e)
impl From<tapyrusd::tapyruscore_rpc::Error> for Error {
fn from(e: tapyrusd::tapyruscore_rpc::Error) -> Self {
Error::TapyrusCoreRpc(e)
}
}

Expand Down
Loading

0 comments on commit adbfd68

Please sign in to comment.