diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -10,6 +10,7 @@ set(CMAKE_CXX_VISIBILITY_PRESET hidden) option(BUILD_BITCOIN_WALLET "Activate the wallet functionality" ON) +option(BUILD_BITCOIN_CHRONIK "Activate the Chronik indexer" OFF) option(BUILD_BITCOIN_ZMQ "Activate the ZeroMQ functionalities" ON) option(BUILD_BITCOIN_CLI "Build bitcoin-cli" ON) option(BUILD_BITCOIN_TX "Build bitcoin-tx" ON) @@ -73,6 +74,7 @@ include(NativeExecutable) native_add_cmake_flags( "-DBUILD_BITCOIN_WALLET=OFF" + "-DBUILD_BITCOIN_CHRONIK=OFF" "-DBUILD_BITCOIN_QT=OFF" "-DBUILD_BITCOIN_ZMQ=OFF" "-DENABLE_QRCODE=OFF" @@ -679,6 +681,11 @@ target_sources(server PRIVATE dummywallet.cpp) endif() +# Chronik indexer is in the rust folder +if(BUILD_BITCOIN_CHRONIK) + add_subdirectory(rust) +endif() + # ZeroMQ if(BUILD_BITCOIN_ZMQ) add_subdirectory(zmq) diff --git a/src/rust/.gitignore b/src/rust/.gitignore new file mode 100644 --- /dev/null +++ b/src/rust/.gitignore @@ -0,0 +1,2 @@ +# Ignore Rust artifacts in target folder +/target diff --git a/src/rust/CMakeLists.txt b/src/rust/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/src/rust/CMakeLists.txt @@ -0,0 +1,9 @@ +find_package(Corrosion 0.2.0 REQUIRED) + +add_custom_target(check-rust-test-suite +COMMAND + Rust::Cargo + test +WORKING_DIRECTORY + ${CMAKE_CURRENT_SOURCE_DIR} +) diff --git a/src/rust/Cargo.lock b/src/rust/Cargo.lock new file mode 100644 --- /dev/null +++ b/src/rust/Cargo.lock @@ -0,0 +1,7 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "bitcoinsuite-core" +version = "0.1.0" diff --git a/src/rust/Cargo.toml b/src/rust/Cargo.toml new file mode 100644 --- /dev/null +++ b/src/rust/Cargo.toml @@ -0,0 +1,5 @@ +[workspace] + +members = [ + "bitcoinsuite-core", +] diff --git a/src/rust/bitcoinsuite-core/Cargo.toml b/src/rust/bitcoinsuite-core/Cargo.toml new file mode 100644 --- /dev/null +++ b/src/rust/bitcoinsuite-core/Cargo.toml @@ -0,0 +1,6 @@ +[package] +name = "bitcoinsuite-core" +version = "0.1.0" +edition = "2021" +rust-version = "1.61.0" +license = "MIT" diff --git a/src/rust/bitcoinsuite-core/src/hash.rs b/src/rust/bitcoinsuite-core/src/hash.rs new file mode 100644 --- /dev/null +++ b/src/rust/bitcoinsuite-core/src/hash.rs @@ -0,0 +1,20 @@ +// Copyright (c) 2022 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +//! Structs storing the results of cryptographic hash functions. + +/// Hash of the SHA-256 algorithm as defined by NIST. +/// +/// Bitcoin usually uses the double-Sha256 (see [`Sha256d`]) for hashes, +/// mostly block hashes, tx hashes and txids. +#[derive(Debug)] +pub struct Sha256([u8; 32]); + +/// SHA-256 algorithm applied twice (i.e. sha256(sha256(x))), see +/// [`Sha256`]. +/// +/// This is the most commonly used hash in Bitcoin, most prominently for +/// block hashes, tx hashes and txids. +#[derive(Debug)] +pub struct Sha256d([u8; 32]); diff --git a/src/rust/bitcoinsuite-core/src/lib.rs b/src/rust/bitcoinsuite-core/src/lib.rs new file mode 100644 --- /dev/null +++ b/src/rust/bitcoinsuite-core/src/lib.rs @@ -0,0 +1,35 @@ +// Copyright (c) 2022 The Bitcoin developers +// Distributed under the MIT software license, see the accompanying +// file COPYING or http://www.opensource.org/licenses/mit-license.php. + +#![deny(unsafe_code)] +#![warn(const_err, + dead_code, + elided_lifetimes_in_paths, + explicit_outlives_requirements, + improper_ctypes, + keyword_idents, + missing_debug_implementations, + missing_docs, + no_mangle_generic_items, + non_ascii_idents, + non_shorthand_field_patterns, + noop_method_call, + overflowing_literals, + path_statements, + patterns_in_fns_without_body, + private_in_public, + rust_2018_idioms, + single_use_lifetimes, + unconditional_recursion, + unreachable_pub, + unused_comparisons, + unused, + while_true)] + +//! Core primitives for dealing with Bitcoin-like chains. +//! +//! Note: This is a general purpose library, but has been optimized for the +//! usage in Chronik, an indexer for Bitcoin ABC. + +pub mod hash;