diff --git a/Cargo-minimal.lock b/Cargo-minimal.lock index a1743a0e..72a16271 100644 --- a/Cargo-minimal.lock +++ b/Cargo-minimal.lock @@ -4,9 +4,9 @@ version = 3 [[package]] name = "aho-corasick" -version = "0.7.18" +version = "0.7.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f" +checksum = "58fb5e95d83b38284460a5fda7d6470aa0b8844d283a0b614b8535e880800d2d" dependencies = [ "memchr", ] @@ -86,26 +86,6 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f92b72b8f03128773278bf74418b9205f3d2a12c39a61f92395f47af390c32bf" -[[package]] -name = "bindgen" -version = "0.72.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f72209734318d0b619a5e0f5129918b848c416e122a3c4ce054e03cb87b726f" -dependencies = [ - "bitflags", - "cexpr", - "clang-sys", - "itertools", - "log", - "prettyplease", - "proc-macro2", - "quote 1.0.25", - "regex", - "rustc-hash", - "shlex", - "syn 2.0.16", -] - [[package]] name = "bitcoin" version = "0.31.0" @@ -161,12 +141,6 @@ dependencies = [ "log", ] -[[package]] -name = "bitflags" -version = "2.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "24a6904aef64d73cf10ab17ebace7befb918b82164785cb89907993be7f83813" - [[package]] name = "cc" version = "1.2.0" @@ -176,32 +150,12 @@ dependencies = [ "shlex", ] -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - [[package]] name = "cfg-if" version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d4c819a1287eb618df47cc647173c5c4c66ba19d888a6e50d605672aed3140de" -[[package]] -name = "clang-sys" -version = "1.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cb92721cb37482245ed88428f72253ce422b3b4ee169c70a0642521bb5db4cc" -dependencies = [ - "glob", - "libc", - "libloading", -] - [[package]] name = "colorchoice" version = "1.0.0" @@ -215,7 +169,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "df89dd0d075dea5cc5fdd6d5df6b8a61172a710b3efac1d6bdb9dd8b78f82c1a" dependencies = [ "proc-macro2", - "quote 1.0.25", + "quote 1.0.0", "syn 1.0.0", ] @@ -225,12 +179,6 @@ version = "0.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5edd69c67b2f8e0911629b7e6b8a34cb3956613cd7c6e6414966dee349c2db4f" -[[package]] -name = "either" -version = "1.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5845bf77d497f79416df39462df26d4a8b71dd6440246848ee63709476dbb9a6" - [[package]] name = "env_filter" version = "0.1.0" @@ -266,12 +214,6 @@ dependencies = [ "silentpayments", ] -[[package]] -name = "glob" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" - [[package]] name = "hex" version = "0.4.0" @@ -296,35 +238,25 @@ version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "b9b6c53306532d3c8e8087b44e6580e10db51a023cf9b433cea2ac38066b92da" -[[package]] -name = "itertools" -version = "0.10.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "37d572918e350e82412fe766d24b15e6682fb2ed2bbe018280caa810397cb319" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "0.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "91fd9dc2c587067de817fec4ad355e3818c3d893a78cab32a0a474c7a15bb8d5" +[[package]] +name = "lazy_static" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c8f31047daa365f19be14b47c29df4f7c3b581832407daabe6ae77397619237d" + [[package]] name = "libbitcoinkernel-sys" version = "0.2.0" dependencies = [ - "bindgen", "cc", ] -[[package]] -name = "libc" -version = "0.2.39" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f54263ad99207254cf58b5f701ecb432c717445ea2ee8af387334bdd1a03fdff" - [[package]] name = "libfuzzer-sys" version = "0.4.0" @@ -335,15 +267,6 @@ dependencies = [ "cc", ] -[[package]] -name = "libloading" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c979a19ffb457f0273965c333053f3d586bf759bf7b683fbebc37f9a9ebedc4" -dependencies = [ - "winapi", -] - [[package]] name = "log" version = "0.4.8" @@ -355,26 +278,9 @@ dependencies = [ [[package]] name = "memchr" -version = "2.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc" - -[[package]] -name = "minimal-lexical" -version = "0.1.2" +version = "2.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6595bb28ed34f43c3fe088e48f6cfb2e033cab45f25a5384d5fdf564fbc8c4b2" - -[[package]] -name = "nom" -version = "7.0.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7ffd9d26838a953b4af82cbeb9f1592c6798916983959be223a7124e992742c1" -dependencies = [ - "memchr", - "minimal-lexical", - "version_check", -] +checksum = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e" [[package]] name = "num-traits" @@ -382,23 +288,13 @@ version = "0.1.32" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "51eab148f171aefad295f8cece636fc488b9b392ef544da31ea4b8ef6b9e9c39" -[[package]] -name = "prettyplease" -version = "0.2.7" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "43ded2b5b204571f065ab8540367d738dfe1b3606ab9eb669dcfb5e7a3a07501" -dependencies = [ - "proc-macro2", - "syn 2.0.16", -] - [[package]] name = "proc-macro2" -version = "1.0.80" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a56dea16b0a29e94408b9aa5e2940a4eedbd128a1ba20e8f7ae60fd3d465af0e" +checksum = "19f287c234c9b2d0308d692dee5c449c1a171167a6f8150f7cf2a49d8fd96967" dependencies = [ - "unicode-ident", + "unicode-xid 0.2.0", ] [[package]] @@ -409,9 +305,9 @@ checksum = "9f0fc799e40f2a2c2be239825b30b686f1bd1d2e0e3d5e943b14c1380db49acf" [[package]] name = "quote" -version = "1.0.25" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5308e8208729c3e1504a6cfad0d5daacc4614c9a2e65d1ea312a34b5cb00fe84" +checksum = "7ab938ebe6f1c82426b5fb82eaf10c3e3028c53deaa3fbe38f5904b37cf4d767" dependencies = [ "proc-macro2", ] @@ -433,20 +329,21 @@ checksum = "34cf66eb183df1c5876e2dcf6b13d57340741e8dc255b48e40a26de954d06ae7" [[package]] name = "regex" -version = "1.5.3" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ce5f1ceb7f74abbce32601642fcf8e8508a8a8991e0621c7d750295b9095702b" +checksum = "fc98360d9e6ad383647702acc90f80b0582eac3ea577ab47d96325d3575de908" dependencies = [ "aho-corasick", "memchr", "regex-syntax", + "thread_local", ] [[package]] name = "regex-syntax" -version = "0.6.25" +version = "0.6.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b" +checksum = "11a7e20d1cce64ef2fed88b66d347f88bd9babb82845b2b858f3edbf59a4f716" [[package]] name = "rust-bitcoinkernel-fuzz" @@ -457,12 +354,6 @@ dependencies = [ "libfuzzer-sys", ] -[[package]] -name = "rustc-hash" -version = "2.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c7fb8039b3032c191086b10f11f319a6e99e1e82889c5cc6046f515c9db1d497" - [[package]] name = "secp256k1" version = "0.28.1" @@ -564,21 +455,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f8c8eab7d9f493cd89d4068085651d81ac7d39c56eb64f7158ea514b156e280" dependencies = [ "proc-macro2", - "quote 1.0.25", + "quote 1.0.0", "unicode-xid 0.2.0", ] -[[package]] -name = "syn" -version = "2.0.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a6f671d4b5ffdb8eadec19c0ae67fe2639df8684bd7bc4b83d986b8db549cf01" -dependencies = [ - "proc-macro2", - "quote 1.0.25", - "unicode-ident", -] - [[package]] name = "synom" version = "0.11.0" @@ -589,10 +469,13 @@ dependencies = [ ] [[package]] -name = "unicode-ident" -version = "1.0.0" +name = "thread_local" +version = "0.3.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d22af068fba1eb5edcb4aea19d382b2a3deb4c8f9d475c589b6ada9e0fd493ee" +checksum = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b" +dependencies = [ + "lazy_static", +] [[package]] name = "unicode-xid" @@ -612,34 +495,6 @@ version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a" -[[package]] -name = "version_check" -version = "0.9.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "45d3d553fd9413fffe7147a20171d640eda0ad4c070acd7d0c885a21bcd2e8b7" - -[[package]] -name = "winapi" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b3ad91d846a4a5342c1fb7008d26124ee6cf94a3953751618577295373b32117" -dependencies = [ - "winapi-i686-pc-windows-gnu", - "winapi-x86_64-pc-windows-gnu", -] - -[[package]] -name = "winapi-i686-pc-windows-gnu" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a16a8e2ebfc883e2b1771c6482b1fb3c6831eab289ba391619a2d93a7356220f" - -[[package]] -name = "winapi-x86_64-pc-windows-gnu" -version = "0.3.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8ca29cb03c8ceaf20f8224a18a530938305e9872b1478ea24ff44b4f503a1d1d" - [[package]] name = "windows-sys" version = "0.48.0" diff --git a/Cargo-recent.lock b/Cargo-recent.lock index 417a0e98..00bc2945 100644 --- a/Cargo-recent.lock +++ b/Cargo-recent.lock @@ -88,26 +88,6 @@ version = "0.6.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "230c5f1ca6a325a32553f8640d31ac9b49f2411e901e427570154868b46da4f7" -[[package]] -name = "bindgen" -version = "0.72.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895" -dependencies = [ - "bitflags", - "cexpr", - "clang-sys", - "itertools", - "log", - "prettyplease", - "proc-macro2", - "quote", - "regex", - "rustc-hash", - "shlex", - "syn", -] - [[package]] name = "bitcoin" version = "0.31.3" @@ -147,12 +127,6 @@ dependencies = [ "log", ] -[[package]] -name = "bitflags" -version = "2.11.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c4512299f36f043ab09a583e57bceb5a5aab7a73db1805848e8fef3c9e8c78b3" - [[package]] name = "cc" version = "1.2.61" @@ -165,32 +139,12 @@ dependencies = [ "shlex", ] -[[package]] -name = "cexpr" -version = "0.6.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766" -dependencies = [ - "nom", -] - [[package]] name = "cfg-if" version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" -[[package]] -name = "clang-sys" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0b023947811758c97c59bf9d1c188fd619ad4718dcaa767947df1cadb14f39f4" -dependencies = [ - "glob", - "libc", - "libloading", -] - [[package]] name = "colorchoice" version = "1.0.5" @@ -208,12 +162,6 @@ dependencies = [ "syn", ] -[[package]] -name = "either" -version = "1.15.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719" - [[package]] name = "env_filter" version = "1.0.1" @@ -267,12 +215,6 @@ dependencies = [ "wasip2", ] -[[package]] -name = "glob" -version = "0.3.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" - [[package]] name = "hex" version = "0.4.3" @@ -297,15 +239,6 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695" -[[package]] -name = "itertools" -version = "0.13.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186" -dependencies = [ - "either", -] - [[package]] name = "itoa" version = "1.0.18" @@ -350,7 +283,6 @@ dependencies = [ name = "libbitcoinkernel-sys" version = "0.2.0" dependencies = [ - "bindgen", "cc", ] @@ -370,16 +302,6 @@ dependencies = [ "cc", ] -[[package]] -name = "libloading" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" -dependencies = [ - "cfg-if", - "windows-link", -] - [[package]] name = "log" version = "0.4.29" @@ -392,22 +314,6 @@ version = "2.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8ca58f447f06ed17d5fc4043ce1b10dd205e060fb3ce5b979b8ed8e59ff3f79" -[[package]] -name = "minimal-lexical" -version = "0.2.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a" - -[[package]] -name = "nom" -version = "7.1.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a" -dependencies = [ - "memchr", - "minimal-lexical", -] - [[package]] name = "once_cell_polyfill" version = "1.70.2" @@ -429,16 +335,6 @@ dependencies = [ "portable-atomic", ] -[[package]] -name = "prettyplease" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" -dependencies = [ - "proc-macro2", - "syn", -] - [[package]] name = "proc-macro2" version = "1.0.106" @@ -516,12 +412,6 @@ dependencies = [ "libfuzzer-sys", ] -[[package]] -name = "rustc-hash" -version = "2.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "357703d41365b4b27c590e3ed91eabb1b663f07c4c084095e60cbed4362dff0d" - [[package]] name = "secp256k1" version = "0.28.2" diff --git a/libbitcoinkernel-sys/CHANGELOG.md b/libbitcoinkernel-sys/CHANGELOG.md index 0a12c19e..1d3d48d6 100644 --- a/libbitcoinkernel-sys/CHANGELOG.md +++ b/libbitcoinkernel-sys/CHANGELOG.md @@ -16,8 +16,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - New `btck_transaction_input_get_sequence` for retrieving a transaction input's `nSequence` - New `btck_block_tree_entry_get_ancestor` for retrieving the ancestor of a block tree entry at a given height - New `btck_block_header_to_bytes` for serializing a block header to its 80-byte consensus encoding +- Named constants for all enum-like types (`btck_BlockValidationResult_*`, `btck_ChainType_*`, `btck_LogCategory_*`, `btck_LogLevel_*`, `btck_ScriptVerificationFlags_*`, `btck_ScriptVerifyStatus_*`, `btck_SynchronizationState_*`, `btck_ValidationMode_*`, `btck_Warning_*`) exported from `libbitcoinkernel-sys` ### Changed +- Replaced bindgen-generated bindings with hand-written FFI bindings - `btck_chain_get_by_height` `block_height` parameter type changed from `int` to `int32_t` - `btck_chain_get_height` return type changed from `int` to `int32_t` - `btck_block_validation_state_destroy` now accepts a null pointer (removed `NONNULL` annotation) diff --git a/libbitcoinkernel-sys/Cargo.toml b/libbitcoinkernel-sys/Cargo.toml index bd0460ab..541e09e0 100644 --- a/libbitcoinkernel-sys/Cargo.toml +++ b/libbitcoinkernel-sys/Cargo.toml @@ -3,7 +3,7 @@ name = "libbitcoinkernel-sys" version = "0.2.0" edition = "2021" authors = ["sedited "] -description = "Raw Rust bindings to libbitcoinkernel" +description = "Raw FFI bindings to libbitcoinkernel. For safe usage, see the bitcoinkernel crate." license = "MIT" repository = "https://github.com/sedited/rust-bitcoinkernel" documentation = "https://docs.rs/bitcoinkernel" @@ -52,4 +52,3 @@ publish = true [build-dependencies] cc = "1.2" -bindgen = "0.72" diff --git a/libbitcoinkernel-sys/README.md b/libbitcoinkernel-sys/README.md index 94be1b12..94761254 100644 --- a/libbitcoinkernel-sys/README.md +++ b/libbitcoinkernel-sys/README.md @@ -1,4 +1,22 @@ -# README +# libbitcoinkernel-sys -This package is not safe for use. Use the Rust type-safe bitcoinkernel crate -instead that wraps this crate. +Raw FFI bindings to +[libbitcoinkernel](https://github.com/bitcoin/bitcoin/blob/master/src/kernel/bitcoinkernel.h), +the Bitcoin Core kernel library. + +## Warning + +This crate is not intended for direct use. Use the safe, idiomatic +[bitcoinkernel](https://crates.io/crates/bitcoinkernel) crate instead. + +## Bindings + +The bindings are hand-written and manually maintained against the upstream C +header. + +For the authoritative API documentation, refer to the upstream C header: +https://github.com/bitcoin/bitcoin/blob/master/src/kernel/bitcoinkernel.h + +## Supported targets + +Tested on x86_64 Linux, ARM64 Linux, Windows, and macOS via CI. diff --git a/libbitcoinkernel-sys/build.rs b/libbitcoinkernel-sys/build.rs index 56488652..61f505a1 100644 --- a/libbitcoinkernel-sys/build.rs +++ b/libbitcoinkernel-sys/build.rs @@ -1,7 +1,5 @@ -use bindgen::RustEdition; use std::env; use std::path::Path; -use std::path::PathBuf; use std::process::Command; fn main() { @@ -76,26 +74,6 @@ fn main() { println!("cargo:rustc-link-lib=static=bitcoinkernel"); - // Header path for bindgen - let include_path = install_dir.join("include"); - let header = include_path.join("bitcoinkernel.h"); - - #[allow(deprecated)] - let bindings = bindgen::Builder::default() - .header(header.to_str().unwrap()) - .clang_arg("-DBITCOINKERNEL_STATIC") - .rust_target(bindgen::RustTarget::Stable_1_71) - .rust_edition(RustEdition::Edition2021) - .generate() - .expect("Unable to generate bindings"); - - let out_path = PathBuf::from( - env::var("OUT_DIR").expect("OUT_DIR was not defined by the cargo environment!"), - ); - bindings - .write_to_file(out_path.join("bindings.rs")) - .expect("Couldn't write bindings!"); - let compiler = cc::Build::new().get_compiler(); let target_os = std::env::var("CARGO_CFG_TARGET_OS").unwrap(); diff --git a/libbitcoinkernel-sys/src/lib.rs b/libbitcoinkernel-sys/src/lib.rs index a38a13a8..96175be4 100644 --- a/libbitcoinkernel-sys/src/lib.rs +++ b/libbitcoinkernel-sys/src/lib.rs @@ -1,5 +1,834 @@ -#![allow(non_upper_case_globals)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] +//! Raw FFI bindings to libbitcoinkernel. +//! +//! For documentation on the underlying API, refer to the upstream C header: +//! -include!(concat!(env!("OUT_DIR"), "/bindings.rs")); +#![no_std] +#![allow(non_camel_case_types, non_upper_case_globals)] + +use core::ffi::{c_char, c_int, c_uchar, c_uint, c_void}; + +// Primitive type aliases - alphabetical order + +pub type btck_BlockCheckFlags = u32; +pub type btck_BlockValidationResult = u32; +pub type btck_ChainType = u8; +pub type btck_LogCategory = u8; +pub type btck_LogLevel = u8; +pub type btck_ScriptVerificationFlags = u32; +pub type btck_ScriptVerifyStatus = u8; +pub type btck_SynchronizationState = u8; +pub type btck_ValidationMode = u8; +pub type btck_Warning = u8; + +// btck_BlockValidationResult + +pub const btck_BlockValidationResult_UNSET: btck_BlockValidationResult = 0; +pub const btck_BlockValidationResult_CONSENSUS: btck_BlockValidationResult = 1; +pub const btck_BlockValidationResult_CACHED_INVALID: btck_BlockValidationResult = 2; +pub const btck_BlockValidationResult_INVALID_HEADER: btck_BlockValidationResult = 3; +pub const btck_BlockValidationResult_MUTATED: btck_BlockValidationResult = 4; +pub const btck_BlockValidationResult_MISSING_PREV: btck_BlockValidationResult = 5; +pub const btck_BlockValidationResult_INVALID_PREV: btck_BlockValidationResult = 6; +pub const btck_BlockValidationResult_TIME_FUTURE: btck_BlockValidationResult = 7; +pub const btck_BlockValidationResult_HEADER_LOW_WORK: btck_BlockValidationResult = 8; + +// btck_ChainType + +pub const btck_ChainType_MAINNET: btck_ChainType = 0; +pub const btck_ChainType_TESTNET: btck_ChainType = 1; +pub const btck_ChainType_TESTNET_4: btck_ChainType = 2; +pub const btck_ChainType_SIGNET: btck_ChainType = 3; +pub const btck_ChainType_REGTEST: btck_ChainType = 4; + +// btck_LogCategory + +pub const btck_LogCategory_ALL: btck_LogCategory = 0; +pub const btck_LogCategory_BENCH: btck_LogCategory = 1; +pub const btck_LogCategory_BLOCKSTORAGE: btck_LogCategory = 2; +pub const btck_LogCategory_COINDB: btck_LogCategory = 3; +pub const btck_LogCategory_LEVELDB: btck_LogCategory = 4; +pub const btck_LogCategory_MEMPOOL: btck_LogCategory = 5; +pub const btck_LogCategory_PRUNE: btck_LogCategory = 6; +pub const btck_LogCategory_RAND: btck_LogCategory = 7; +pub const btck_LogCategory_REINDEX: btck_LogCategory = 8; +pub const btck_LogCategory_VALIDATION: btck_LogCategory = 9; +pub const btck_LogCategory_KERNEL: btck_LogCategory = 10; + +// btck_LogLevel + +pub const btck_LogLevel_TRACE: btck_LogLevel = 0; +pub const btck_LogLevel_DEBUG: btck_LogLevel = 1; +pub const btck_LogLevel_INFO: btck_LogLevel = 2; + +// btck_ScriptVerificationFlags + +pub const btck_ScriptVerificationFlags_NONE: btck_ScriptVerificationFlags = 0; +pub const btck_ScriptVerificationFlags_P2SH: btck_ScriptVerificationFlags = 1 << 0; +pub const btck_ScriptVerificationFlags_DERSIG: btck_ScriptVerificationFlags = 1 << 2; +pub const btck_ScriptVerificationFlags_NULLDUMMY: btck_ScriptVerificationFlags = 1 << 4; +pub const btck_ScriptVerificationFlags_CHECKLOCKTIMEVERIFY: btck_ScriptVerificationFlags = 1 << 9; +pub const btck_ScriptVerificationFlags_CHECKSEQUENCEVERIFY: btck_ScriptVerificationFlags = 1 << 10; +pub const btck_ScriptVerificationFlags_WITNESS: btck_ScriptVerificationFlags = 1 << 11; +pub const btck_ScriptVerificationFlags_TAPROOT: btck_ScriptVerificationFlags = 1 << 17; +pub const btck_ScriptVerificationFlags_ALL: btck_ScriptVerificationFlags = + btck_ScriptVerificationFlags_P2SH + | btck_ScriptVerificationFlags_DERSIG + | btck_ScriptVerificationFlags_NULLDUMMY + | btck_ScriptVerificationFlags_CHECKLOCKTIMEVERIFY + | btck_ScriptVerificationFlags_CHECKSEQUENCEVERIFY + | btck_ScriptVerificationFlags_WITNESS + | btck_ScriptVerificationFlags_TAPROOT; + +// btck_ScriptVerifyStatus + +pub const btck_ScriptVerifyStatus_OK: btck_ScriptVerifyStatus = 0; +pub const btck_ScriptVerifyStatus_ERROR_INVALID_FLAGS_COMBINATION: btck_ScriptVerifyStatus = 1; +pub const btck_ScriptVerifyStatus_ERROR_SPENT_OUTPUTS_REQUIRED: btck_ScriptVerifyStatus = 2; + +// btck_SynchronizationState + +pub const btck_SynchronizationState_INIT_REINDEX: btck_SynchronizationState = 0; +pub const btck_SynchronizationState_INIT_DOWNLOAD: btck_SynchronizationState = 1; +pub const btck_SynchronizationState_POST_INIT: btck_SynchronizationState = 2; + +// btck_ValidationMode + +pub const btck_ValidationMode_VALID: btck_ValidationMode = 0; +pub const btck_ValidationMode_INVALID: btck_ValidationMode = 1; +pub const btck_ValidationMode_INTERNAL_ERROR: btck_ValidationMode = 2; + +// btck_Warning + +pub const btck_Warning_UNKNOWN_NEW_RULES_ACTIVATED: btck_Warning = 0; +pub const btck_Warning_LARGE_WORK_INVALID_CHAIN: btck_Warning = 1; + +// Opaque types - alphabetical order + +#[repr(C)] +pub struct btck_Block { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_BlockHash { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_BlockHeader { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_BlockSpentOutputs { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_BlockTreeEntry { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_BlockValidationState { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_Chain { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_ChainParameters { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_ChainstateManager { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_ChainstateManagerOptions { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_Coin { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_ConsensusParams { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_Context { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_ContextOptions { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_LoggingConnection { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_PrecomputedTransactionData { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_ScriptPubkey { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_Transaction { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_TransactionInput { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_TransactionOutPoint { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_TransactionOutput { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_TransactionSpentOutputs { + _unused: [u8; 0], +} +#[repr(C)] +pub struct btck_Txid { + _unused: [u8; 0], +} + +// Function-pointer type aliases - alphabetical order + +pub type btck_DestroyCallback = Option; + +pub type btck_LogCallback = Option< + unsafe extern "C" fn(user_data: *mut c_void, message: *const c_char, message_len: usize), +>; + +pub type btck_NotifyBlockTip = Option< + unsafe extern "C" fn( + user_data: *mut c_void, + state: btck_SynchronizationState, + entry: *const btck_BlockTreeEntry, + verification_progress: f64, + ), +>; + +pub type btck_NotifyFatalError = Option< + unsafe extern "C" fn(user_data: *mut c_void, message: *const c_char, message_len: usize), +>; + +pub type btck_NotifyFlushError = Option< + unsafe extern "C" fn(user_data: *mut c_void, message: *const c_char, message_len: usize), +>; + +pub type btck_NotifyHeaderTip = Option< + unsafe extern "C" fn( + user_data: *mut c_void, + state: btck_SynchronizationState, + height: i64, + timestamp: i64, + presync: c_int, + ), +>; + +pub type btck_NotifyProgress = Option< + unsafe extern "C" fn( + user_data: *mut c_void, + title: *const c_char, + title_len: usize, + progress_percent: c_int, + resume_possible: c_int, + ), +>; + +pub type btck_NotifyWarningSet = Option< + unsafe extern "C" fn( + user_data: *mut c_void, + warning: btck_Warning, + message: *const c_char, + message_len: usize, + ), +>; + +pub type btck_NotifyWarningUnset = + Option; + +pub type btck_ValidationInterfaceBlockChecked = Option< + unsafe extern "C" fn( + user_data: *mut c_void, + block: *mut btck_Block, + state: *const btck_BlockValidationState, + ), +>; + +pub type btck_ValidationInterfaceBlockConnected = Option< + unsafe extern "C" fn( + user_data: *mut c_void, + block: *mut btck_Block, + entry: *const btck_BlockTreeEntry, + ), +>; + +pub type btck_ValidationInterfaceBlockDisconnected = Option< + unsafe extern "C" fn( + user_data: *mut c_void, + block: *mut btck_Block, + entry: *const btck_BlockTreeEntry, + ), +>; + +pub type btck_ValidationInterfacePoWValidBlock = Option< + unsafe extern "C" fn( + user_data: *mut c_void, + block: *mut btck_Block, + entry: *const btck_BlockTreeEntry, + ), +>; + +pub type btck_WriteBytes = + Option c_int>; + +// These structs are passed by value across the FFI boundary - alphabetical order +// Field order must match C exactly - sizes verified by const assertions below + +#[repr(C)] +pub struct btck_LoggingOptions { + pub log_timestamps: c_int, + pub log_time_micros: c_int, + pub log_threadnames: c_int, + pub log_sourcelocations: c_int, + pub always_print_category_levels: c_int, +} + +#[repr(C)] +pub struct btck_NotificationInterfaceCallbacks { + pub user_data: *mut c_void, + pub user_data_destroy: btck_DestroyCallback, + pub block_tip: btck_NotifyBlockTip, + pub header_tip: btck_NotifyHeaderTip, + pub progress: btck_NotifyProgress, + pub warning_set: btck_NotifyWarningSet, + pub warning_unset: btck_NotifyWarningUnset, + pub flush_error: btck_NotifyFlushError, + pub fatal_error: btck_NotifyFatalError, +} + +#[repr(C)] +pub struct btck_ValidationInterfaceCallbacks { + pub user_data: *mut c_void, + pub user_data_destroy: btck_DestroyCallback, + pub block_checked: btck_ValidationInterfaceBlockChecked, + pub pow_valid_block: btck_ValidationInterfacePoWValidBlock, + pub block_connected: btck_ValidationInterfaceBlockConnected, + pub block_disconnected: btck_ValidationInterfaceBlockDisconnected, +} + +// Layout guards for structs passed by value across the FFI boundary. +// Pointer-sized fields use size_of::<*const ()>() to remain correct on both +// 32-bit and 64-bit targets. +const _: () = { + assert!(core::mem::size_of::() == 20); + assert!(core::mem::align_of::() == 4); + assert!( + core::mem::size_of::() + == 9 * core::mem::size_of::<*const ()>() + ); + assert!( + core::mem::align_of::() + == core::mem::align_of::<*const ()>() + ); + assert!( + core::mem::size_of::() + == 6 * core::mem::size_of::<*const ()>() + ); + assert!( + core::mem::align_of::() + == core::mem::align_of::<*const ()>() + ); +}; + +// extern "C" declarations - grouped by type + +extern "C" { + + // --- Transaction -------------------------------------------------------- + + pub fn btck_transaction_create( + raw_transaction: *const c_void, + raw_transaction_len: usize, + ) -> *mut btck_Transaction; + + pub fn btck_transaction_copy(transaction: *const btck_Transaction) -> *mut btck_Transaction; + + pub fn btck_transaction_to_bytes( + transaction: *const btck_Transaction, + writer: btck_WriteBytes, + user_data: *mut c_void, + ) -> c_int; + + pub fn btck_transaction_count_outputs(transaction: *const btck_Transaction) -> usize; + + pub fn btck_transaction_get_output_at( + transaction: *const btck_Transaction, + output_index: usize, + ) -> *const btck_TransactionOutput; + + pub fn btck_transaction_get_input_at( + transaction: *const btck_Transaction, + input_index: usize, + ) -> *const btck_TransactionInput; + + pub fn btck_transaction_count_inputs(transaction: *const btck_Transaction) -> usize; + + pub fn btck_transaction_get_locktime(transaction: *const btck_Transaction) -> u32; + + pub fn btck_transaction_get_txid(transaction: *const btck_Transaction) -> *const btck_Txid; + + pub fn btck_transaction_destroy(transaction: *mut btck_Transaction); + + // --- PrecomputedTransactionData ----------------------------------------- + + pub fn btck_precomputed_transaction_data_create( + tx_to: *const btck_Transaction, + spent_outputs: *mut *const btck_TransactionOutput, + spent_outputs_len: usize, + ) -> *mut btck_PrecomputedTransactionData; + + pub fn btck_precomputed_transaction_data_copy( + precomputed_txdata: *const btck_PrecomputedTransactionData, + ) -> *mut btck_PrecomputedTransactionData; + + pub fn btck_precomputed_transaction_data_destroy( + precomputed_txdata: *mut btck_PrecomputedTransactionData, + ); + + // --- ScriptPubkey ------------------------------------------------------- + + pub fn btck_script_pubkey_create( + script_pubkey: *const c_void, + script_pubkey_len: usize, + ) -> *mut btck_ScriptPubkey; + + pub fn btck_script_pubkey_copy( + script_pubkey: *const btck_ScriptPubkey, + ) -> *mut btck_ScriptPubkey; + + pub fn btck_script_pubkey_verify( + script_pubkey: *const btck_ScriptPubkey, + amount: i64, + tx_to: *const btck_Transaction, + precomputed_txdata: *const btck_PrecomputedTransactionData, + input_index: c_uint, + flags: btck_ScriptVerificationFlags, + status: *mut btck_ScriptVerifyStatus, + ) -> c_int; + + pub fn btck_script_pubkey_to_bytes( + script_pubkey: *const btck_ScriptPubkey, + writer: btck_WriteBytes, + user_data: *mut c_void, + ) -> c_int; + + pub fn btck_script_pubkey_destroy(script_pubkey: *mut btck_ScriptPubkey); + + // --- TransactionOutput -------------------------------------------------- + + pub fn btck_transaction_output_create( + script_pubkey: *const btck_ScriptPubkey, + amount: i64, + ) -> *mut btck_TransactionOutput; + + pub fn btck_transaction_output_get_script_pubkey( + transaction_output: *const btck_TransactionOutput, + ) -> *const btck_ScriptPubkey; + + pub fn btck_transaction_output_get_amount( + transaction_output: *const btck_TransactionOutput, + ) -> i64; + + pub fn btck_transaction_output_copy( + transaction_output: *const btck_TransactionOutput, + ) -> *mut btck_TransactionOutput; + + pub fn btck_transaction_output_destroy(transaction_output: *mut btck_TransactionOutput); + + // --- Logging ------------------------------------------------------------ + + pub fn btck_logging_disable(); + + pub fn btck_logging_set_options(options: btck_LoggingOptions); + + pub fn btck_logging_set_level_category(category: btck_LogCategory, level: btck_LogLevel); + + pub fn btck_logging_enable_category(category: btck_LogCategory); + + pub fn btck_logging_disable_category(category: btck_LogCategory); + + pub fn btck_logging_connection_create( + log_callback: btck_LogCallback, + user_data: *mut c_void, + user_data_destroy_callback: btck_DestroyCallback, + ) -> *mut btck_LoggingConnection; + + pub fn btck_logging_connection_destroy(logging_connection: *mut btck_LoggingConnection); + + // --- ChainParameters ---------------------------------------------------- + + pub fn btck_chain_parameters_create(chain_type: btck_ChainType) -> *mut btck_ChainParameters; + + pub fn btck_chain_parameters_copy( + chain_parameters: *const btck_ChainParameters, + ) -> *mut btck_ChainParameters; + + pub fn btck_chain_parameters_get_consensus_params( + chain_parameters: *const btck_ChainParameters, + ) -> *const btck_ConsensusParams; + + pub fn btck_chain_parameters_destroy(chain_parameters: *mut btck_ChainParameters); + + // --- ContextOptions ----------------------------------------------------- + + pub fn btck_context_options_create() -> *mut btck_ContextOptions; + + pub fn btck_context_options_set_chainparams( + context_options: *mut btck_ContextOptions, + chain_parameters: *const btck_ChainParameters, + ); + + pub fn btck_context_options_set_notifications( + context_options: *mut btck_ContextOptions, + notifications: btck_NotificationInterfaceCallbacks, + ); + + pub fn btck_context_options_set_validation_interface( + context_options: *mut btck_ContextOptions, + validation_interface_callbacks: btck_ValidationInterfaceCallbacks, + ); + + pub fn btck_context_options_destroy(context_options: *mut btck_ContextOptions); + + // --- Context ------------------------------------------------------------ + + pub fn btck_context_create(context_options: *const btck_ContextOptions) -> *mut btck_Context; + + pub fn btck_context_copy(context: *const btck_Context) -> *mut btck_Context; + + pub fn btck_context_interrupt(context: *mut btck_Context) -> c_int; + + pub fn btck_context_destroy(context: *mut btck_Context); + + // --- BlockTreeEntry ----------------------------------------------------- + + pub fn btck_block_tree_entry_get_previous( + block_tree_entry: *const btck_BlockTreeEntry, + ) -> *const btck_BlockTreeEntry; + + pub fn btck_block_tree_entry_get_ancestor( + block_tree_entry: *const btck_BlockTreeEntry, + height: i32, + ) -> *const btck_BlockTreeEntry; + + pub fn btck_block_tree_entry_get_block_header( + block_tree_entry: *const btck_BlockTreeEntry, + ) -> *mut btck_BlockHeader; + + pub fn btck_block_tree_entry_get_height(block_tree_entry: *const btck_BlockTreeEntry) -> i32; + + pub fn btck_block_tree_entry_get_block_hash( + block_tree_entry: *const btck_BlockTreeEntry, + ) -> *const btck_BlockHash; + + pub fn btck_block_tree_entry_equals( + entry1: *const btck_BlockTreeEntry, + entry2: *const btck_BlockTreeEntry, + ) -> c_int; + + // --- ChainstateManagerOptions ------------------------------------------- + + pub fn btck_chainstate_manager_options_create( + context: *const btck_Context, + data_directory: *const c_char, + data_directory_len: usize, + blocks_directory: *const c_char, + blocks_directory_len: usize, + ) -> *mut btck_ChainstateManagerOptions; + + pub fn btck_chainstate_manager_options_set_worker_threads_num( + chainstate_manager_options: *mut btck_ChainstateManagerOptions, + worker_threads: c_int, + ); + + pub fn btck_chainstate_manager_options_set_wipe_dbs( + chainstate_manager_options: *mut btck_ChainstateManagerOptions, + wipe_block_tree_db: c_int, + wipe_chainstate_db: c_int, + ) -> c_int; + + pub fn btck_chainstate_manager_options_update_block_tree_db_in_memory( + chainstate_manager_options: *mut btck_ChainstateManagerOptions, + block_tree_db_in_memory: c_int, + ); + + pub fn btck_chainstate_manager_options_update_chainstate_db_in_memory( + chainstate_manager_options: *mut btck_ChainstateManagerOptions, + chainstate_db_in_memory: c_int, + ); + + pub fn btck_chainstate_manager_options_destroy( + chainstate_manager_options: *mut btck_ChainstateManagerOptions, + ); + + // --- ChainstateManager -------------------------------------------------- + + pub fn btck_chainstate_manager_create( + chainstate_manager_options: *const btck_ChainstateManagerOptions, + ) -> *mut btck_ChainstateManager; + + pub fn btck_chainstate_manager_get_best_entry( + chainstate_manager: *const btck_ChainstateManager, + ) -> *const btck_BlockTreeEntry; + + pub fn btck_chainstate_manager_process_block_header( + chainstate_manager: *mut btck_ChainstateManager, + header: *const btck_BlockHeader, + block_validation_state: *mut btck_BlockValidationState, + ) -> c_int; + + pub fn btck_chainstate_manager_import_blocks( + chainstate_manager: *mut btck_ChainstateManager, + block_file_paths_data: *mut *const c_char, + block_file_paths_lens: *mut usize, + block_file_paths_data_len: usize, + ) -> c_int; + + pub fn btck_chainstate_manager_process_block( + chainstate_manager: *mut btck_ChainstateManager, + block: *const btck_Block, + new_block: *mut c_int, + ) -> c_int; + + pub fn btck_chainstate_manager_get_active_chain( + chainstate_manager: *const btck_ChainstateManager, + ) -> *const btck_Chain; + + pub fn btck_chainstate_manager_get_block_tree_entry_by_hash( + chainstate_manager: *const btck_ChainstateManager, + block_hash: *const btck_BlockHash, + ) -> *const btck_BlockTreeEntry; + + pub fn btck_chainstate_manager_destroy(chainstate_manager: *mut btck_ChainstateManager); + + // --- Block -------------------------------------------------------------- + + pub fn btck_block_read( + chainstate_manager: *const btck_ChainstateManager, + block_tree_entry: *const btck_BlockTreeEntry, + ) -> *mut btck_Block; + + pub fn btck_block_create(raw_block: *const c_void, raw_block_len: usize) -> *mut btck_Block; + + pub fn btck_block_copy(block: *const btck_Block) -> *mut btck_Block; + + pub fn btck_block_check( + block: *const btck_Block, + consensus_params: *const btck_ConsensusParams, + flags: btck_BlockCheckFlags, + validation_state: *mut btck_BlockValidationState, + ) -> c_int; + + pub fn btck_block_count_transactions(block: *const btck_Block) -> usize; + + pub fn btck_block_get_transaction_at( + block: *const btck_Block, + transaction_index: usize, + ) -> *const btck_Transaction; + + pub fn btck_block_get_header(block: *const btck_Block) -> *mut btck_BlockHeader; + + pub fn btck_block_get_hash(block: *const btck_Block) -> *mut btck_BlockHash; + + pub fn btck_block_to_bytes( + block: *const btck_Block, + writer: btck_WriteBytes, + user_data: *mut c_void, + ) -> c_int; + + pub fn btck_block_destroy(block: *mut btck_Block); + + // --- BlockValidationState ----------------------------------------------- + + pub fn btck_block_validation_state_create() -> *mut btck_BlockValidationState; + + pub fn btck_block_validation_state_get_validation_mode( + block_validation_state: *const btck_BlockValidationState, + ) -> btck_ValidationMode; + + pub fn btck_block_validation_state_get_block_validation_result( + block_validation_state: *const btck_BlockValidationState, + ) -> btck_BlockValidationResult; + + pub fn btck_block_validation_state_copy( + block_validation_state: *const btck_BlockValidationState, + ) -> *mut btck_BlockValidationState; + + pub fn btck_block_validation_state_destroy( + block_validation_state: *mut btck_BlockValidationState, + ); + + // --- Chain -------------------------------------------------------------- + + pub fn btck_chain_get_height(chain: *const btck_Chain) -> i32; + + pub fn btck_chain_get_by_height( + chain: *const btck_Chain, + block_height: i32, + ) -> *const btck_BlockTreeEntry; + + pub fn btck_chain_contains( + chain: *const btck_Chain, + block_tree_entry: *const btck_BlockTreeEntry, + ) -> c_int; + + // --- BlockSpentOutputs -------------------------------------------------- + + pub fn btck_block_spent_outputs_read( + chainstate_manager: *const btck_ChainstateManager, + block_tree_entry: *const btck_BlockTreeEntry, + ) -> *mut btck_BlockSpentOutputs; + + pub fn btck_block_spent_outputs_copy( + block_spent_outputs: *const btck_BlockSpentOutputs, + ) -> *mut btck_BlockSpentOutputs; + + pub fn btck_block_spent_outputs_count( + block_spent_outputs: *const btck_BlockSpentOutputs, + ) -> usize; + + pub fn btck_block_spent_outputs_get_transaction_spent_outputs_at( + block_spent_outputs: *const btck_BlockSpentOutputs, + transaction_spent_outputs_index: usize, + ) -> *const btck_TransactionSpentOutputs; + + pub fn btck_block_spent_outputs_destroy(block_spent_outputs: *mut btck_BlockSpentOutputs); + + // --- TransactionSpentOutputs -------------------------------------------- + + pub fn btck_transaction_spent_outputs_copy( + transaction_spent_outputs: *const btck_TransactionSpentOutputs, + ) -> *mut btck_TransactionSpentOutputs; + + pub fn btck_transaction_spent_outputs_count( + transaction_spent_outputs: *const btck_TransactionSpentOutputs, + ) -> usize; + + pub fn btck_transaction_spent_outputs_get_coin_at( + transaction_spent_outputs: *const btck_TransactionSpentOutputs, + coin_index: usize, + ) -> *const btck_Coin; + + pub fn btck_transaction_spent_outputs_destroy( + transaction_spent_outputs: *mut btck_TransactionSpentOutputs, + ); + + // --- TransactionInput --------------------------------------------------- + + pub fn btck_transaction_input_copy( + transaction_input: *const btck_TransactionInput, + ) -> *mut btck_TransactionInput; + + pub fn btck_transaction_input_get_out_point( + transaction_input: *const btck_TransactionInput, + ) -> *const btck_TransactionOutPoint; + + pub fn btck_transaction_input_get_sequence( + transaction_input: *const btck_TransactionInput, + ) -> u32; + + pub fn btck_transaction_input_destroy(transaction_input: *mut btck_TransactionInput); + + // --- TransactionOutPoint ------------------------------------------------ + + pub fn btck_transaction_out_point_copy( + transaction_out_point: *const btck_TransactionOutPoint, + ) -> *mut btck_TransactionOutPoint; + + pub fn btck_transaction_out_point_get_index( + transaction_out_point: *const btck_TransactionOutPoint, + ) -> u32; + + pub fn btck_transaction_out_point_get_txid( + transaction_out_point: *const btck_TransactionOutPoint, + ) -> *const btck_Txid; + + pub fn btck_transaction_out_point_destroy(transaction_out_point: *mut btck_TransactionOutPoint); + + // --- Txid --------------------------------------------------------------- + + pub fn btck_txid_copy(txid: *const btck_Txid) -> *mut btck_Txid; + + pub fn btck_txid_equals(txid1: *const btck_Txid, txid2: *const btck_Txid) -> c_int; + + pub fn btck_txid_to_bytes(txid: *const btck_Txid, output: *mut c_uchar); + + pub fn btck_txid_destroy(txid: *mut btck_Txid); + + // --- Coin --------------------------------------------------------------- + + pub fn btck_coin_copy(coin: *const btck_Coin) -> *mut btck_Coin; + + pub fn btck_coin_confirmation_height(coin: *const btck_Coin) -> u32; + + pub fn btck_coin_is_coinbase(coin: *const btck_Coin) -> c_int; + + pub fn btck_coin_get_output(coin: *const btck_Coin) -> *const btck_TransactionOutput; + + pub fn btck_coin_destroy(coin: *mut btck_Coin); + + // --- BlockHash ---------------------------------------------------------- + + pub fn btck_block_hash_create(block_hash: *const c_uchar) -> *mut btck_BlockHash; + + pub fn btck_block_hash_equals( + hash1: *const btck_BlockHash, + hash2: *const btck_BlockHash, + ) -> c_int; + + pub fn btck_block_hash_copy(block_hash: *const btck_BlockHash) -> *mut btck_BlockHash; + + pub fn btck_block_hash_to_bytes(block_hash: *const btck_BlockHash, output: *mut c_uchar); + + pub fn btck_block_hash_destroy(block_hash: *mut btck_BlockHash); + + // --- BlockHeader -------------------------------------------------------- + + pub fn btck_block_header_create( + raw_block_header: *const c_void, + raw_block_header_len: usize, + ) -> *mut btck_BlockHeader; + + pub fn btck_block_header_copy(header: *const btck_BlockHeader) -> *mut btck_BlockHeader; + + pub fn btck_block_header_get_hash(header: *const btck_BlockHeader) -> *mut btck_BlockHash; + + pub fn btck_block_header_get_prev_hash( + header: *const btck_BlockHeader, + ) -> *const btck_BlockHash; + + pub fn btck_block_header_get_timestamp(header: *const btck_BlockHeader) -> u32; + + pub fn btck_block_header_get_bits(header: *const btck_BlockHeader) -> u32; + + pub fn btck_block_header_get_version(header: *const btck_BlockHeader) -> i32; + + pub fn btck_block_header_get_nonce(header: *const btck_BlockHeader) -> u32; + + pub fn btck_block_header_to_bytes( + header: *const btck_BlockHeader, + output: *mut c_uchar, + ) -> c_int; + + pub fn btck_block_header_destroy(header: *mut btck_BlockHeader); + +} // extern "C" diff --git a/src/core/verify.rs b/src/core/verify.rs index 9843493c..2cd7f5fe 100644 --- a/src/core/verify.rs +++ b/src/core/verify.rs @@ -154,55 +154,51 @@ use std::{ }; use libbitcoinkernel_sys::{ - btck_PrecomputedTransactionData, btck_ScriptVerificationFlags, btck_ScriptVerifyStatus, + btck_PrecomputedTransactionData, btck_ScriptVerificationFlags, + btck_ScriptVerificationFlags_ALL, btck_ScriptVerificationFlags_CHECKLOCKTIMEVERIFY, + btck_ScriptVerificationFlags_CHECKSEQUENCEVERIFY, btck_ScriptVerificationFlags_DERSIG, + btck_ScriptVerificationFlags_NONE, btck_ScriptVerificationFlags_NULLDUMMY, + btck_ScriptVerificationFlags_P2SH, btck_ScriptVerificationFlags_TAPROOT, + btck_ScriptVerificationFlags_WITNESS, btck_ScriptVerifyStatus, + btck_ScriptVerifyStatus_ERROR_INVALID_FLAGS_COMBINATION, + btck_ScriptVerifyStatus_ERROR_SPENT_OUTPUTS_REQUIRED, btck_ScriptVerifyStatus_OK, btck_TransactionOutput, btck_precomputed_transaction_data_copy, btck_precomputed_transaction_data_create, btck_precomputed_transaction_data_destroy, btck_script_pubkey_verify, }; use crate::{ - c_helpers, - ffi::{ - sealed::AsPtr, BTCK_SCRIPT_VERIFICATION_FLAGS_ALL, - BTCK_SCRIPT_VERIFICATION_FLAGS_CHECKLOCKTIMEVERIFY, - BTCK_SCRIPT_VERIFICATION_FLAGS_CHECKSEQUENCEVERIFY, BTCK_SCRIPT_VERIFICATION_FLAGS_DERSIG, - BTCK_SCRIPT_VERIFICATION_FLAGS_NONE, BTCK_SCRIPT_VERIFICATION_FLAGS_NULLDUMMY, - BTCK_SCRIPT_VERIFICATION_FLAGS_P2SH, BTCK_SCRIPT_VERIFICATION_FLAGS_TAPROOT, - BTCK_SCRIPT_VERIFICATION_FLAGS_WITNESS, - BTCK_SCRIPT_VERIFY_STATUS_ERROR_INVALID_FLAGS_COMBINATION, - BTCK_SCRIPT_VERIFY_STATUS_ERROR_SPENT_OUTPUTS_REQUIRED, BTCK_SCRIPT_VERIFY_STATUS_OK, - }, - KernelError, ScriptPubkeyExt, TransactionExt, TxOutExt, + c_helpers, ffi::sealed::AsPtr, KernelError, ScriptPubkeyExt, TransactionExt, TxOutExt, }; /// No verification flags. -pub const VERIFY_NONE: btck_ScriptVerificationFlags = BTCK_SCRIPT_VERIFICATION_FLAGS_NONE; +pub const VERIFY_NONE: btck_ScriptVerificationFlags = btck_ScriptVerificationFlags_NONE; /// Validate Pay-to-Script-Hash (BIP 16). -pub const VERIFY_P2SH: btck_ScriptVerificationFlags = BTCK_SCRIPT_VERIFICATION_FLAGS_P2SH; +pub const VERIFY_P2SH: btck_ScriptVerificationFlags = btck_ScriptVerificationFlags_P2SH; /// Require strict DER encoding for ECDSA signatures (BIP 66). -pub const VERIFY_DERSIG: btck_ScriptVerificationFlags = BTCK_SCRIPT_VERIFICATION_FLAGS_DERSIG; +pub const VERIFY_DERSIG: btck_ScriptVerificationFlags = btck_ScriptVerificationFlags_DERSIG; /// Require the dummy element in OP_CHECKMULTISIG to be empty (BIP 147). -pub const VERIFY_NULLDUMMY: btck_ScriptVerificationFlags = BTCK_SCRIPT_VERIFICATION_FLAGS_NULLDUMMY; +pub const VERIFY_NULLDUMMY: btck_ScriptVerificationFlags = btck_ScriptVerificationFlags_NULLDUMMY; /// Enable OP_CHECKLOCKTIMEVERIFY (BIP 65). pub const VERIFY_CHECKLOCKTIMEVERIFY: btck_ScriptVerificationFlags = - BTCK_SCRIPT_VERIFICATION_FLAGS_CHECKLOCKTIMEVERIFY; + btck_ScriptVerificationFlags_CHECKLOCKTIMEVERIFY; /// Enable OP_CHECKSEQUENCEVERIFY (BIP 112). pub const VERIFY_CHECKSEQUENCEVERIFY: btck_ScriptVerificationFlags = - BTCK_SCRIPT_VERIFICATION_FLAGS_CHECKSEQUENCEVERIFY; + btck_ScriptVerificationFlags_CHECKSEQUENCEVERIFY; /// Validate Segregated Witness programs (BIP 141/143). -pub const VERIFY_WITNESS: btck_ScriptVerificationFlags = BTCK_SCRIPT_VERIFICATION_FLAGS_WITNESS; +pub const VERIFY_WITNESS: btck_ScriptVerificationFlags = btck_ScriptVerificationFlags_WITNESS; /// Validate Taproot spends (BIP 341/342). Requires spent outputs. -pub const VERIFY_TAPROOT: btck_ScriptVerificationFlags = BTCK_SCRIPT_VERIFICATION_FLAGS_TAPROOT; +pub const VERIFY_TAPROOT: btck_ScriptVerificationFlags = btck_ScriptVerificationFlags_TAPROOT; /// All consensus rules. -pub const VERIFY_ALL: btck_ScriptVerificationFlags = BTCK_SCRIPT_VERIFICATION_FLAGS_ALL; +pub const VERIFY_ALL: btck_ScriptVerificationFlags = btck_ScriptVerificationFlags_ALL; /// All consensus rules except Taproot. pub const VERIFY_ALL_PRE_TAPROOT: btck_ScriptVerificationFlags = VERIFY_P2SH @@ -455,7 +451,7 @@ pub fn verify( #[repr(u8)] enum ScriptVerifyStatus { /// Script verification completed successfully - Ok = BTCK_SCRIPT_VERIFY_STATUS_OK, + Ok = btck_ScriptVerifyStatus_OK, /// Invalid or inconsistent verification flags were provided. /// @@ -468,14 +464,14 @@ enum ScriptVerifyStatus { /// /// These combinations are considered invalid and result in an immediate /// verification setup failure rather than a script execution failure. - ErrorInvalidFlagsCombination = BTCK_SCRIPT_VERIFY_STATUS_ERROR_INVALID_FLAGS_COMBINATION, + ErrorInvalidFlagsCombination = btck_ScriptVerifyStatus_ERROR_INVALID_FLAGS_COMBINATION, /// Spent outputs are required but were not provided. /// /// Taproot scripts require the complete set of outputs being spent to properly /// validate witness data. This occurs when the TAPROOT flag is set but no spent /// outputs were provided. - ErrorSpentOutputsRequired = BTCK_SCRIPT_VERIFY_STATUS_ERROR_SPENT_OUTPUTS_REQUIRED, + ErrorSpentOutputsRequired = btck_ScriptVerifyStatus_ERROR_SPENT_OUTPUTS_REQUIRED, } impl From for btck_ScriptVerifyStatus { @@ -484,14 +480,15 @@ impl From for btck_ScriptVerifyStatus { } } +#[allow(non_upper_case_globals)] impl From for ScriptVerifyStatus { fn from(value: btck_ScriptVerifyStatus) -> Self { match value { - BTCK_SCRIPT_VERIFY_STATUS_OK => ScriptVerifyStatus::Ok, - BTCK_SCRIPT_VERIFY_STATUS_ERROR_INVALID_FLAGS_COMBINATION => { + btck_ScriptVerifyStatus_OK => ScriptVerifyStatus::Ok, + btck_ScriptVerifyStatus_ERROR_INVALID_FLAGS_COMBINATION => { ScriptVerifyStatus::ErrorInvalidFlagsCombination } - BTCK_SCRIPT_VERIFY_STATUS_ERROR_SPENT_OUTPUTS_REQUIRED => { + btck_ScriptVerifyStatus_ERROR_SPENT_OUTPUTS_REQUIRED => { ScriptVerifyStatus::ErrorSpentOutputsRequired } _ => panic!("Unknown script verify status: {}", value), @@ -554,21 +551,21 @@ mod tests { #[test] fn test_verify_constants() { - assert_eq!(VERIFY_NONE, BTCK_SCRIPT_VERIFICATION_FLAGS_NONE); - assert_eq!(VERIFY_P2SH, BTCK_SCRIPT_VERIFICATION_FLAGS_P2SH); - assert_eq!(VERIFY_DERSIG, BTCK_SCRIPT_VERIFICATION_FLAGS_DERSIG); - assert_eq!(VERIFY_NULLDUMMY, BTCK_SCRIPT_VERIFICATION_FLAGS_NULLDUMMY); + assert_eq!(VERIFY_NONE, btck_ScriptVerificationFlags_NONE); + assert_eq!(VERIFY_P2SH, btck_ScriptVerificationFlags_P2SH); + assert_eq!(VERIFY_DERSIG, btck_ScriptVerificationFlags_DERSIG); + assert_eq!(VERIFY_NULLDUMMY, btck_ScriptVerificationFlags_NULLDUMMY); assert_eq!( VERIFY_CHECKLOCKTIMEVERIFY, - BTCK_SCRIPT_VERIFICATION_FLAGS_CHECKLOCKTIMEVERIFY + btck_ScriptVerificationFlags_CHECKLOCKTIMEVERIFY ); assert_eq!( VERIFY_CHECKSEQUENCEVERIFY, - BTCK_SCRIPT_VERIFICATION_FLAGS_CHECKSEQUENCEVERIFY + btck_ScriptVerificationFlags_CHECKSEQUENCEVERIFY ); - assert_eq!(VERIFY_WITNESS, BTCK_SCRIPT_VERIFICATION_FLAGS_WITNESS); - assert_eq!(VERIFY_TAPROOT, BTCK_SCRIPT_VERIFICATION_FLAGS_TAPROOT); - assert_eq!(VERIFY_ALL, BTCK_SCRIPT_VERIFICATION_FLAGS_ALL); + assert_eq!(VERIFY_WITNESS, btck_ScriptVerificationFlags_WITNESS); + assert_eq!(VERIFY_TAPROOT, btck_ScriptVerificationFlags_TAPROOT); + assert_eq!(VERIFY_ALL, btck_ScriptVerificationFlags_ALL); } #[test] @@ -607,18 +604,18 @@ mod tests { #[test] fn test_script_verify_status_from_kernel() { - let ok: ScriptVerifyStatus = BTCK_SCRIPT_VERIFY_STATUS_OK.into(); + let ok: ScriptVerifyStatus = btck_ScriptVerifyStatus_OK.into(); assert_eq!(ok, ScriptVerifyStatus::Ok); let invalid_flags: ScriptVerifyStatus = - BTCK_SCRIPT_VERIFY_STATUS_ERROR_INVALID_FLAGS_COMBINATION.into(); + btck_ScriptVerifyStatus_ERROR_INVALID_FLAGS_COMBINATION.into(); assert_eq!( invalid_flags, ScriptVerifyStatus::ErrorInvalidFlagsCombination ); let spent_required: ScriptVerifyStatus = - BTCK_SCRIPT_VERIFY_STATUS_ERROR_SPENT_OUTPUTS_REQUIRED.into(); + btck_ScriptVerifyStatus_ERROR_SPENT_OUTPUTS_REQUIRED.into(); assert_eq!( spent_required, ScriptVerifyStatus::ErrorSpentOutputsRequired @@ -628,20 +625,20 @@ mod tests { #[test] fn test_script_verify_status_to_kernel() { let ok: btck_ScriptVerifyStatus = ScriptVerifyStatus::Ok.into(); - assert_eq!(ok, BTCK_SCRIPT_VERIFY_STATUS_OK); + assert_eq!(ok, btck_ScriptVerifyStatus_OK); let invalid_flags: btck_ScriptVerifyStatus = ScriptVerifyStatus::ErrorInvalidFlagsCombination.into(); assert_eq!( invalid_flags, - BTCK_SCRIPT_VERIFY_STATUS_ERROR_INVALID_FLAGS_COMBINATION + btck_ScriptVerifyStatus_ERROR_INVALID_FLAGS_COMBINATION ); let spent_required: btck_ScriptVerifyStatus = ScriptVerifyStatus::ErrorSpentOutputsRequired.into(); assert_eq!( spent_required, - BTCK_SCRIPT_VERIFY_STATUS_ERROR_SPENT_OUTPUTS_REQUIRED + btck_ScriptVerifyStatus_ERROR_SPENT_OUTPUTS_REQUIRED ); } diff --git a/src/ffi/constants.rs b/src/ffi/constants.rs deleted file mode 100644 index 74e2e5b4..00000000 --- a/src/ffi/constants.rs +++ /dev/null @@ -1,80 +0,0 @@ -use crate::{ - btck_BlockValidationResult, btck_ChainType, btck_LogCategory, btck_LogLevel, - btck_ScriptVerificationFlags, btck_ScriptVerifyStatus, btck_SynchronizationState, - btck_ValidationMode, btck_Warning, -}; - -// Synchronization States -pub const BTCK_SYNCHRONIZATION_STATE_INIT_REINDEX: btck_SynchronizationState = 0; -pub const BTCK_SYNCHRONIZATION_STATE_INIT_DOWNLOAD: btck_SynchronizationState = 1; -pub const BTCK_SYNCHRONIZATION_STATE_POST_INIT: btck_SynchronizationState = 2; - -// Warning Types -pub const BTCK_WARNING_UNKNOWN_NEW_RULES_ACTIVATED: btck_Warning = 0; -pub const BTCK_WARNING_LARGE_WORK_INVALID_CHAIN: btck_Warning = 1; - -// Validation Modes -pub const BTCK_VALIDATION_MODE_VALID: btck_ValidationMode = 0; -pub const BTCK_VALIDATION_MODE_INVALID: btck_ValidationMode = 1; -pub const BTCK_VALIDATION_MODE_INTERNAL_ERROR: btck_ValidationMode = 2; - -// Block Validation Results -pub const BTCK_BLOCK_VALIDATION_RESULT_UNSET: btck_BlockValidationResult = 0; -pub const BTCK_BLOCK_VALIDATION_RESULT_CONSENSUS: btck_BlockValidationResult = 1; -pub const BTCK_BLOCK_VALIDATION_RESULT_CACHED_INVALID: btck_BlockValidationResult = 2; -pub const BTCK_BLOCK_VALIDATION_RESULT_INVALID_HEADER: btck_BlockValidationResult = 3; -pub const BTCK_BLOCK_VALIDATION_RESULT_MUTATED: btck_BlockValidationResult = 4; -pub const BTCK_BLOCK_VALIDATION_RESULT_MISSING_PREV: btck_BlockValidationResult = 5; -pub const BTCK_BLOCK_VALIDATION_RESULT_INVALID_PREV: btck_BlockValidationResult = 6; -pub const BTCK_BLOCK_VALIDATION_RESULT_TIME_FUTURE: btck_BlockValidationResult = 7; -pub const BTCK_BLOCK_VALIDATION_RESULT_HEADER_LOW_WORK: btck_BlockValidationResult = 8; - -// Log Categories -pub const BTCK_LOG_CATEGORY_ALL: btck_LogCategory = 0; -pub const BTCK_LOG_CATEGORY_BENCH: btck_LogCategory = 1; -pub const BTCK_LOG_CATEGORY_BLOCKSTORAGE: btck_LogCategory = 2; -pub const BTCK_LOG_CATEGORY_COINDB: btck_LogCategory = 3; -pub const BTCK_LOG_CATEGORY_LEVELDB: btck_LogCategory = 4; -pub const BTCK_LOG_CATEGORY_MEMPOOL: btck_LogCategory = 5; -pub const BTCK_LOG_CATEGORY_PRUNE: btck_LogCategory = 6; -pub const BTCK_LOG_CATEGORY_RAND: btck_LogCategory = 7; -pub const BTCK_LOG_CATEGORY_REINDEX: btck_LogCategory = 8; -pub const BTCK_LOG_CATEGORY_VALIDATION: btck_LogCategory = 9; -pub const BTCK_LOG_CATEGORY_KERNEL: btck_LogCategory = 10; - -// Log Levels -pub const BTCK_LOG_LEVEL_TRACE: btck_LogLevel = 0; -pub const BTCK_LOG_LEVEL_DEBUG: btck_LogLevel = 1; -pub const BTCK_LOG_LEVEL_INFO: btck_LogLevel = 2; - -// Script Verify Status -pub const BTCK_SCRIPT_VERIFY_STATUS_OK: btck_ScriptVerifyStatus = 0; -pub const BTCK_SCRIPT_VERIFY_STATUS_ERROR_INVALID_FLAGS_COMBINATION: btck_ScriptVerifyStatus = 1; -pub const BTCK_SCRIPT_VERIFY_STATUS_ERROR_SPENT_OUTPUTS_REQUIRED: btck_ScriptVerifyStatus = 2; - -// Script Verification Flags -pub const BTCK_SCRIPT_VERIFICATION_FLAGS_NONE: btck_ScriptVerificationFlags = 0; -pub const BTCK_SCRIPT_VERIFICATION_FLAGS_P2SH: btck_ScriptVerificationFlags = 1 << 0; -pub const BTCK_SCRIPT_VERIFICATION_FLAGS_DERSIG: btck_ScriptVerificationFlags = 1 << 2; -pub const BTCK_SCRIPT_VERIFICATION_FLAGS_NULLDUMMY: btck_ScriptVerificationFlags = 1 << 4; -pub const BTCK_SCRIPT_VERIFICATION_FLAGS_CHECKLOCKTIMEVERIFY: btck_ScriptVerificationFlags = 1 << 9; -pub const BTCK_SCRIPT_VERIFICATION_FLAGS_CHECKSEQUENCEVERIFY: btck_ScriptVerificationFlags = - 1 << 10; -pub const BTCK_SCRIPT_VERIFICATION_FLAGS_WITNESS: btck_ScriptVerificationFlags = 1 << 11; -pub const BTCK_SCRIPT_VERIFICATION_FLAGS_TAPROOT: btck_ScriptVerificationFlags = 1 << 17; - -pub const BTCK_SCRIPT_VERIFICATION_FLAGS_ALL: btck_ScriptVerificationFlags = - BTCK_SCRIPT_VERIFICATION_FLAGS_P2SH - | BTCK_SCRIPT_VERIFICATION_FLAGS_DERSIG - | BTCK_SCRIPT_VERIFICATION_FLAGS_NULLDUMMY - | BTCK_SCRIPT_VERIFICATION_FLAGS_CHECKLOCKTIMEVERIFY - | BTCK_SCRIPT_VERIFICATION_FLAGS_CHECKSEQUENCEVERIFY - | BTCK_SCRIPT_VERIFICATION_FLAGS_WITNESS - | BTCK_SCRIPT_VERIFICATION_FLAGS_TAPROOT; - -// Chain types -pub const BTCK_CHAIN_TYPE_MAINNET: btck_ChainType = 0; -pub const BTCK_CHAIN_TYPE_TESTNET: btck_ChainType = 1; -pub const BTCK_CHAIN_TYPE_TESTNET_4: btck_ChainType = 2; -pub const BTCK_CHAIN_TYPE_SIGNET: btck_ChainType = 3; -pub const BTCK_CHAIN_TYPE_REGTEST: btck_ChainType = 4; diff --git a/src/ffi/mod.rs b/src/ffi/mod.rs index f2749c5b..7de18fff 100644 --- a/src/ffi/mod.rs +++ b/src/ffi/mod.rs @@ -1,5 +1,4 @@ pub mod c_helpers; -pub mod constants; #[cfg(test)] pub mod test_utils; @@ -21,4 +20,3 @@ pub(crate) mod sealed { } pub use c_helpers::{enabled, present, success, to_c_bool, to_c_result, to_string}; -pub(crate) use constants::*; diff --git a/src/lib.rs b/src/lib.rs index 935aaaa7..b4ab45ef 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -179,27 +179,11 @@ //! //! - Silent Payment Scanning -#![allow(non_upper_case_globals)] -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] - use std::ffi::NulError; use std::{fmt, panic}; use crate::core::{ScriptPubkeyExt, TransactionExt, TxOutExt}; -use ffi::{ - c_helpers, BTCK_BLOCK_VALIDATION_RESULT_CACHED_INVALID, BTCK_BLOCK_VALIDATION_RESULT_CONSENSUS, - BTCK_BLOCK_VALIDATION_RESULT_HEADER_LOW_WORK, BTCK_BLOCK_VALIDATION_RESULT_INVALID_HEADER, - BTCK_BLOCK_VALIDATION_RESULT_INVALID_PREV, BTCK_BLOCK_VALIDATION_RESULT_MISSING_PREV, - BTCK_BLOCK_VALIDATION_RESULT_MUTATED, BTCK_BLOCK_VALIDATION_RESULT_TIME_FUTURE, - BTCK_BLOCK_VALIDATION_RESULT_UNSET, BTCK_CHAIN_TYPE_MAINNET, BTCK_CHAIN_TYPE_REGTEST, - BTCK_CHAIN_TYPE_SIGNET, BTCK_CHAIN_TYPE_TESTNET, BTCK_CHAIN_TYPE_TESTNET_4, - BTCK_SYNCHRONIZATION_STATE_INIT_DOWNLOAD, BTCK_SYNCHRONIZATION_STATE_INIT_REINDEX, - BTCK_SYNCHRONIZATION_STATE_POST_INIT, BTCK_VALIDATION_MODE_INTERNAL_ERROR, - BTCK_VALIDATION_MODE_INVALID, BTCK_VALIDATION_MODE_VALID, - BTCK_WARNING_LARGE_WORK_INVALID_CHAIN, BTCK_WARNING_UNKNOWN_NEW_RULES_ACTIVATED, -}; -use libbitcoinkernel_sys::*; +use ffi::c_helpers; pub mod core; pub mod ffi; diff --git a/src/log/logging.rs b/src/log/logging.rs index 771c65b2..852fdcb8 100644 --- a/src/log/logging.rs +++ b/src/log/logging.rs @@ -1,22 +1,17 @@ use std::ffi::{c_char, c_void}; use libbitcoinkernel_sys::{ - btck_LogCategory, btck_LogLevel, btck_LoggingConnection, btck_LoggingOptions, + btck_LogCategory, btck_LogCategory_ALL, btck_LogCategory_BENCH, btck_LogCategory_BLOCKSTORAGE, + btck_LogCategory_COINDB, btck_LogCategory_KERNEL, btck_LogCategory_LEVELDB, + btck_LogCategory_MEMPOOL, btck_LogCategory_PRUNE, btck_LogCategory_RAND, + btck_LogCategory_REINDEX, btck_LogCategory_VALIDATION, btck_LogLevel, btck_LogLevel_DEBUG, + btck_LogLevel_INFO, btck_LogLevel_TRACE, btck_LoggingConnection, btck_LoggingOptions, btck_logging_connection_create, btck_logging_connection_destroy, btck_logging_disable, btck_logging_disable_category, btck_logging_enable_category, btck_logging_set_level_category, btck_logging_set_options, }; -use crate::{ - ffi::{ - c_helpers, BTCK_LOG_CATEGORY_ALL, BTCK_LOG_CATEGORY_BENCH, BTCK_LOG_CATEGORY_BLOCKSTORAGE, - BTCK_LOG_CATEGORY_COINDB, BTCK_LOG_CATEGORY_KERNEL, BTCK_LOG_CATEGORY_LEVELDB, - BTCK_LOG_CATEGORY_MEMPOOL, BTCK_LOG_CATEGORY_PRUNE, BTCK_LOG_CATEGORY_RAND, - BTCK_LOG_CATEGORY_REINDEX, BTCK_LOG_CATEGORY_VALIDATION, BTCK_LOG_LEVEL_DEBUG, - BTCK_LOG_LEVEL_INFO, BTCK_LOG_LEVEL_TRACE, - }, - KernelError, -}; +use crate::{ffi::c_helpers, KernelError}; /// A function for handling log messages produced by the kernel library. pub trait Log { @@ -189,27 +184,27 @@ impl Logger { #[repr(u8)] pub enum LogCategory { /// All logging categories enabled - All = BTCK_LOG_CATEGORY_ALL, + All = btck_LogCategory_ALL, /// Benchmark and performance logging - Bench = BTCK_LOG_CATEGORY_BENCH, + Bench = btck_LogCategory_BENCH, /// Block storage operations - BlockStorage = BTCK_LOG_CATEGORY_BLOCKSTORAGE, + BlockStorage = btck_LogCategory_BLOCKSTORAGE, /// Coin database operations - CoinDb = BTCK_LOG_CATEGORY_COINDB, + CoinDb = btck_LogCategory_COINDB, /// LevelDB operations - LevelDb = BTCK_LOG_CATEGORY_LEVELDB, + LevelDb = btck_LogCategory_LEVELDB, /// Memory pool operations - Mempool = BTCK_LOG_CATEGORY_MEMPOOL, + Mempool = btck_LogCategory_MEMPOOL, /// Block pruning operations - Prune = BTCK_LOG_CATEGORY_PRUNE, + Prune = btck_LogCategory_PRUNE, /// Random number generation - Rand = BTCK_LOG_CATEGORY_RAND, + Rand = btck_LogCategory_RAND, /// Block reindexing operations - Reindex = BTCK_LOG_CATEGORY_REINDEX, + Reindex = btck_LogCategory_REINDEX, /// Block and transaction validation - Validation = BTCK_LOG_CATEGORY_VALIDATION, + Validation = btck_LogCategory_VALIDATION, /// Kernel-specific operations - Kernel = BTCK_LOG_CATEGORY_KERNEL, + Kernel = btck_LogCategory_KERNEL, } impl From for btck_LogCategory { @@ -218,20 +213,21 @@ impl From for btck_LogCategory { } } +#[allow(non_upper_case_globals)] impl From for LogCategory { fn from(value: btck_LogCategory) -> Self { match value { - BTCK_LOG_CATEGORY_ALL => LogCategory::All, - BTCK_LOG_CATEGORY_BENCH => LogCategory::Bench, - BTCK_LOG_CATEGORY_BLOCKSTORAGE => LogCategory::BlockStorage, - BTCK_LOG_CATEGORY_COINDB => LogCategory::CoinDb, - BTCK_LOG_CATEGORY_LEVELDB => LogCategory::LevelDb, - BTCK_LOG_CATEGORY_MEMPOOL => LogCategory::Mempool, - BTCK_LOG_CATEGORY_PRUNE => LogCategory::Prune, - BTCK_LOG_CATEGORY_RAND => LogCategory::Rand, - BTCK_LOG_CATEGORY_REINDEX => LogCategory::Reindex, - BTCK_LOG_CATEGORY_VALIDATION => LogCategory::Validation, - BTCK_LOG_CATEGORY_KERNEL => LogCategory::Kernel, + btck_LogCategory_ALL => LogCategory::All, + btck_LogCategory_BENCH => LogCategory::Bench, + btck_LogCategory_BLOCKSTORAGE => LogCategory::BlockStorage, + btck_LogCategory_COINDB => LogCategory::CoinDb, + btck_LogCategory_LEVELDB => LogCategory::LevelDb, + btck_LogCategory_MEMPOOL => LogCategory::Mempool, + btck_LogCategory_PRUNE => LogCategory::Prune, + btck_LogCategory_RAND => LogCategory::Rand, + btck_LogCategory_REINDEX => LogCategory::Reindex, + btck_LogCategory_VALIDATION => LogCategory::Validation, + btck_LogCategory_KERNEL => LogCategory::Kernel, _ => panic!("Unknown log category: {}", value), } } @@ -245,11 +241,11 @@ impl From for LogCategory { #[repr(u8)] pub enum LogLevel { /// Detailed trace information for debugging - Trace = BTCK_LOG_LEVEL_TRACE, + Trace = btck_LogLevel_TRACE, /// Debug information for development - Debug = BTCK_LOG_LEVEL_DEBUG, + Debug = btck_LogLevel_DEBUG, /// General informational messages - Info = BTCK_LOG_LEVEL_INFO, + Info = btck_LogLevel_INFO, } impl From for btck_LogLevel { @@ -258,12 +254,13 @@ impl From for btck_LogLevel { } } +#[allow(non_upper_case_globals)] impl From for LogLevel { fn from(value: btck_LogLevel) -> Self { match value { - BTCK_LOG_LEVEL_TRACE => LogLevel::Trace, - BTCK_LOG_LEVEL_DEBUG => LogLevel::Debug, - BTCK_LOG_LEVEL_INFO => LogLevel::Info, + btck_LogLevel_TRACE => LogLevel::Trace, + btck_LogLevel_DEBUG => LogLevel::Debug, + btck_LogLevel_INFO => LogLevel::Info, _ => panic!("Unknown log level: {}", value), } } diff --git a/src/notifications/types.rs b/src/notifications/types.rs index e23220d7..1af0361b 100644 --- a/src/notifications/types.rs +++ b/src/notifications/types.rs @@ -1,24 +1,22 @@ use std::marker::PhantomData; use libbitcoinkernel_sys::{ - btck_BlockValidationResult, btck_BlockValidationState, btck_SynchronizationState, - btck_ValidationMode, btck_Warning, btck_block_validation_state_copy, + btck_BlockValidationResult, btck_BlockValidationResult_CACHED_INVALID, + btck_BlockValidationResult_CONSENSUS, btck_BlockValidationResult_HEADER_LOW_WORK, + btck_BlockValidationResult_INVALID_HEADER, btck_BlockValidationResult_INVALID_PREV, + btck_BlockValidationResult_MISSING_PREV, btck_BlockValidationResult_MUTATED, + btck_BlockValidationResult_TIME_FUTURE, btck_BlockValidationResult_UNSET, + btck_BlockValidationState, btck_SynchronizationState, btck_SynchronizationState_INIT_DOWNLOAD, + btck_SynchronizationState_INIT_REINDEX, btck_SynchronizationState_POST_INIT, + btck_ValidationMode, btck_ValidationMode_INTERNAL_ERROR, btck_ValidationMode_INVALID, + btck_ValidationMode_VALID, btck_Warning, btck_Warning_LARGE_WORK_INVALID_CHAIN, + btck_Warning_UNKNOWN_NEW_RULES_ACTIVATED, btck_block_validation_state_copy, btck_block_validation_state_create, btck_block_validation_state_destroy, btck_block_validation_state_get_block_validation_result, btck_block_validation_state_get_validation_mode, }; -use crate::{ - ffi::sealed::{AsPtr, FromMutPtr, FromPtr}, - BTCK_BLOCK_VALIDATION_RESULT_CACHED_INVALID, BTCK_BLOCK_VALIDATION_RESULT_CONSENSUS, - BTCK_BLOCK_VALIDATION_RESULT_HEADER_LOW_WORK, BTCK_BLOCK_VALIDATION_RESULT_INVALID_HEADER, - BTCK_BLOCK_VALIDATION_RESULT_INVALID_PREV, BTCK_BLOCK_VALIDATION_RESULT_MISSING_PREV, - BTCK_BLOCK_VALIDATION_RESULT_MUTATED, BTCK_BLOCK_VALIDATION_RESULT_TIME_FUTURE, - BTCK_BLOCK_VALIDATION_RESULT_UNSET, BTCK_SYNCHRONIZATION_STATE_INIT_DOWNLOAD, - BTCK_SYNCHRONIZATION_STATE_INIT_REINDEX, BTCK_SYNCHRONIZATION_STATE_POST_INIT, - BTCK_VALIDATION_MODE_INTERNAL_ERROR, BTCK_VALIDATION_MODE_INVALID, BTCK_VALIDATION_MODE_VALID, - BTCK_WARNING_LARGE_WORK_INVALID_CHAIN, BTCK_WARNING_UNKNOWN_NEW_RULES_ACTIVATED, -}; +use crate::ffi::sealed::{AsPtr, FromMutPtr, FromPtr}; /// Current synchronization state of the blockchain. /// @@ -28,11 +26,11 @@ use crate::{ #[repr(u8)] pub enum SynchronizationState { /// Currently reindexing the blockchain from disk - InitReindex = BTCK_SYNCHRONIZATION_STATE_INIT_REINDEX, + InitReindex = btck_SynchronizationState_INIT_REINDEX, /// Initial block download - syncing from network peers - InitDownload = BTCK_SYNCHRONIZATION_STATE_INIT_DOWNLOAD, + InitDownload = btck_SynchronizationState_INIT_DOWNLOAD, /// Synchronization complete - processing new blocks - PostInit = BTCK_SYNCHRONIZATION_STATE_POST_INIT, + PostInit = btck_SynchronizationState_POST_INIT, } impl From for btck_SynchronizationState { @@ -41,12 +39,13 @@ impl From for btck_SynchronizationState { } } +#[allow(non_upper_case_globals)] impl From for SynchronizationState { fn from(value: btck_SynchronizationState) -> Self { match value { - BTCK_SYNCHRONIZATION_STATE_INIT_REINDEX => SynchronizationState::InitReindex, - BTCK_SYNCHRONIZATION_STATE_INIT_DOWNLOAD => SynchronizationState::InitDownload, - BTCK_SYNCHRONIZATION_STATE_POST_INIT => SynchronizationState::PostInit, + btck_SynchronizationState_INIT_REINDEX => SynchronizationState::InitReindex, + btck_SynchronizationState_INIT_DOWNLOAD => SynchronizationState::InitDownload, + btck_SynchronizationState_POST_INIT => SynchronizationState::PostInit, _ => panic!("Unknown synchronization state: {}", value), } } @@ -63,13 +62,13 @@ pub enum Warning { /// /// This typically means the software is out of date and doesn't /// recognize new consensus rules that have activated on the network. - UnknownNewRulesActivated = BTCK_WARNING_UNKNOWN_NEW_RULES_ACTIVATED, + UnknownNewRulesActivated = btck_Warning_UNKNOWN_NEW_RULES_ACTIVATED, /// A chain with significant work contains invalid blocks /// /// This warning indicates that a substantial amount of computational /// work has been expended on a chain that contains invalid blocks. - LargeWorkInvalidChain = BTCK_WARNING_LARGE_WORK_INVALID_CHAIN, + LargeWorkInvalidChain = btck_Warning_LARGE_WORK_INVALID_CHAIN, } impl From for btck_Warning { @@ -78,11 +77,12 @@ impl From for btck_Warning { } } +#[allow(non_upper_case_globals)] impl From for Warning { fn from(value: btck_Warning) -> Self { match value { - BTCK_WARNING_UNKNOWN_NEW_RULES_ACTIVATED => Warning::UnknownNewRulesActivated, - BTCK_WARNING_LARGE_WORK_INVALID_CHAIN => Warning::LargeWorkInvalidChain, + btck_Warning_UNKNOWN_NEW_RULES_ACTIVATED => Warning::UnknownNewRulesActivated, + btck_Warning_LARGE_WORK_INVALID_CHAIN => Warning::LargeWorkInvalidChain, _ => panic!("Unknown warning: {}", value), } } @@ -109,11 +109,11 @@ impl std::fmt::Display for Warning { #[repr(u8)] pub enum ValidationMode { /// The data structure is valid according to consensus rules - Valid = BTCK_VALIDATION_MODE_VALID, + Valid = btck_ValidationMode_VALID, /// The data structure is invalid according to consensus rules - Invalid = BTCK_VALIDATION_MODE_INVALID, + Invalid = btck_ValidationMode_INVALID, /// An internal error occurred during validation - InternalError = BTCK_VALIDATION_MODE_INTERNAL_ERROR, + InternalError = btck_ValidationMode_INTERNAL_ERROR, } impl From for btck_ValidationMode { @@ -122,12 +122,13 @@ impl From for btck_ValidationMode { } } +#[allow(non_upper_case_globals)] impl From for ValidationMode { fn from(value: btck_ValidationMode) -> Self { match value { - BTCK_VALIDATION_MODE_VALID => ValidationMode::Valid, - BTCK_VALIDATION_MODE_INVALID => ValidationMode::Invalid, - BTCK_VALIDATION_MODE_INTERNAL_ERROR => ValidationMode::InternalError, + btck_ValidationMode_VALID => ValidationMode::Valid, + btck_ValidationMode_INVALID => ValidationMode::Invalid, + btck_ValidationMode_INTERNAL_ERROR => ValidationMode::InternalError, _ => panic!("Unknown validation mode: {}", value), } } @@ -141,23 +142,23 @@ impl From for ValidationMode { #[repr(u32)] pub enum BlockValidationResult { /// Initial value - block has not yet been validated - Unset = BTCK_BLOCK_VALIDATION_RESULT_UNSET, + Unset = btck_BlockValidationResult_UNSET, /// Block is valid according to consensus rules - Consensus = BTCK_BLOCK_VALIDATION_RESULT_CONSENSUS, + Consensus = btck_BlockValidationResult_CONSENSUS, /// Block was cached as invalid (reason not stored) - CachedInvalid = BTCK_BLOCK_VALIDATION_RESULT_CACHED_INVALID, + CachedInvalid = btck_BlockValidationResult_CACHED_INVALID, /// Block header is invalid (proof of work or timestamp) - InvalidHeader = BTCK_BLOCK_VALIDATION_RESULT_INVALID_HEADER, + InvalidHeader = btck_BlockValidationResult_INVALID_HEADER, /// Block data doesn't match the proof of work commitment - Mutated = BTCK_BLOCK_VALIDATION_RESULT_MUTATED, + Mutated = btck_BlockValidationResult_MUTATED, /// Previous block is not available - MissingPrev = BTCK_BLOCK_VALIDATION_RESULT_MISSING_PREV, + MissingPrev = btck_BlockValidationResult_MISSING_PREV, /// Previous block is invalid - InvalidPrev = BTCK_BLOCK_VALIDATION_RESULT_INVALID_PREV, + InvalidPrev = btck_BlockValidationResult_INVALID_PREV, /// Block timestamp is too far in the future - TimeFuture = BTCK_BLOCK_VALIDATION_RESULT_TIME_FUTURE, + TimeFuture = btck_BlockValidationResult_TIME_FUTURE, /// Block header indicates insufficient work - HeaderLowWork = BTCK_BLOCK_VALIDATION_RESULT_HEADER_LOW_WORK, + HeaderLowWork = btck_BlockValidationResult_HEADER_LOW_WORK, } impl From for btck_BlockValidationResult { @@ -166,18 +167,19 @@ impl From for btck_BlockValidationResult { } } +#[allow(non_upper_case_globals)] impl From for BlockValidationResult { fn from(value: btck_BlockValidationResult) -> Self { match value { - BTCK_BLOCK_VALIDATION_RESULT_UNSET => BlockValidationResult::Unset, - BTCK_BLOCK_VALIDATION_RESULT_CONSENSUS => BlockValidationResult::Consensus, - BTCK_BLOCK_VALIDATION_RESULT_CACHED_INVALID => BlockValidationResult::CachedInvalid, - BTCK_BLOCK_VALIDATION_RESULT_INVALID_HEADER => BlockValidationResult::InvalidHeader, - BTCK_BLOCK_VALIDATION_RESULT_MUTATED => BlockValidationResult::Mutated, - BTCK_BLOCK_VALIDATION_RESULT_MISSING_PREV => BlockValidationResult::MissingPrev, - BTCK_BLOCK_VALIDATION_RESULT_INVALID_PREV => BlockValidationResult::InvalidPrev, - BTCK_BLOCK_VALIDATION_RESULT_TIME_FUTURE => BlockValidationResult::TimeFuture, - BTCK_BLOCK_VALIDATION_RESULT_HEADER_LOW_WORK => BlockValidationResult::HeaderLowWork, + btck_BlockValidationResult_UNSET => BlockValidationResult::Unset, + btck_BlockValidationResult_CONSENSUS => BlockValidationResult::Consensus, + btck_BlockValidationResult_CACHED_INVALID => BlockValidationResult::CachedInvalid, + btck_BlockValidationResult_INVALID_HEADER => BlockValidationResult::InvalidHeader, + btck_BlockValidationResult_MUTATED => BlockValidationResult::Mutated, + btck_BlockValidationResult_MISSING_PREV => BlockValidationResult::MissingPrev, + btck_BlockValidationResult_INVALID_PREV => BlockValidationResult::InvalidPrev, + btck_BlockValidationResult_TIME_FUTURE => BlockValidationResult::TimeFuture, + btck_BlockValidationResult_HEADER_LOW_WORK => BlockValidationResult::HeaderLowWork, _ => panic!("Unknown block validation result: {}", value), } } @@ -314,15 +316,15 @@ mod tests { fn test_synchronization_state_values() { assert_eq!( SynchronizationState::InitReindex as u8, - BTCK_SYNCHRONIZATION_STATE_INIT_REINDEX + btck_SynchronizationState_INIT_REINDEX ); assert_eq!( SynchronizationState::InitDownload as u8, - BTCK_SYNCHRONIZATION_STATE_INIT_DOWNLOAD + btck_SynchronizationState_INIT_DOWNLOAD ); assert_eq!( SynchronizationState::PostInit as u8, - BTCK_SYNCHRONIZATION_STATE_POST_INIT + btck_SynchronizationState_POST_INIT ); } @@ -367,11 +369,11 @@ mod tests { fn test_warning_values() { assert_eq!( Warning::UnknownNewRulesActivated as u8, - BTCK_WARNING_UNKNOWN_NEW_RULES_ACTIVATED + btck_Warning_UNKNOWN_NEW_RULES_ACTIVATED ); assert_eq!( Warning::LargeWorkInvalidChain as u8, - BTCK_WARNING_LARGE_WORK_INVALID_CHAIN + btck_Warning_LARGE_WORK_INVALID_CHAIN ); } @@ -415,11 +417,11 @@ mod tests { #[test] fn test_validation_mode_values() { - assert_eq!(ValidationMode::Valid as u8, BTCK_VALIDATION_MODE_VALID); - assert_eq!(ValidationMode::Invalid as u8, BTCK_VALIDATION_MODE_INVALID); + assert_eq!(ValidationMode::Valid as u8, btck_ValidationMode_VALID); + assert_eq!(ValidationMode::Invalid as u8, btck_ValidationMode_INVALID); assert_eq!( ValidationMode::InternalError as u8, - BTCK_VALIDATION_MODE_INTERNAL_ERROR + btck_ValidationMode_INTERNAL_ERROR ); } @@ -490,39 +492,39 @@ mod tests { fn test_block_validation_result_values() { assert_eq!( BlockValidationResult::Unset as u32, - BTCK_BLOCK_VALIDATION_RESULT_UNSET + btck_BlockValidationResult_UNSET ); assert_eq!( BlockValidationResult::Consensus as u32, - BTCK_BLOCK_VALIDATION_RESULT_CONSENSUS + btck_BlockValidationResult_CONSENSUS ); assert_eq!( BlockValidationResult::CachedInvalid as u32, - BTCK_BLOCK_VALIDATION_RESULT_CACHED_INVALID + btck_BlockValidationResult_CACHED_INVALID ); assert_eq!( BlockValidationResult::InvalidHeader as u32, - BTCK_BLOCK_VALIDATION_RESULT_INVALID_HEADER + btck_BlockValidationResult_INVALID_HEADER ); assert_eq!( BlockValidationResult::Mutated as u32, - BTCK_BLOCK_VALIDATION_RESULT_MUTATED + btck_BlockValidationResult_MUTATED ); assert_eq!( BlockValidationResult::MissingPrev as u32, - BTCK_BLOCK_VALIDATION_RESULT_MISSING_PREV + btck_BlockValidationResult_MISSING_PREV ); assert_eq!( BlockValidationResult::InvalidPrev as u32, - BTCK_BLOCK_VALIDATION_RESULT_INVALID_PREV + btck_BlockValidationResult_INVALID_PREV ); assert_eq!( BlockValidationResult::TimeFuture as u32, - BTCK_BLOCK_VALIDATION_RESULT_TIME_FUTURE + btck_BlockValidationResult_TIME_FUTURE ); assert_eq!( BlockValidationResult::HeaderLowWork as u32, - BTCK_BLOCK_VALIDATION_RESULT_HEADER_LOW_WORK + btck_BlockValidationResult_HEADER_LOW_WORK ); } diff --git a/src/state/context.rs b/src/state/context.rs index ea2062fe..0df2d0e3 100644 --- a/src/state/context.rs +++ b/src/state/context.rs @@ -56,8 +56,9 @@ use std::ffi::c_void; use libbitcoinkernel_sys::{ - btck_ChainParameters, btck_ChainType, btck_Context, btck_ContextOptions, - btck_NotificationInterfaceCallbacks, btck_ValidationInterfaceCallbacks, + btck_ChainParameters, btck_ChainType, btck_ChainType_MAINNET, btck_ChainType_REGTEST, + btck_ChainType_SIGNET, btck_ChainType_TESTNET, btck_ChainType_TESTNET_4, btck_Context, + btck_ContextOptions, btck_NotificationInterfaceCallbacks, btck_ValidationInterfaceCallbacks, btck_chain_parameters_create, btck_chain_parameters_destroy, btck_context_create, btck_context_destroy, btck_context_interrupt, btck_context_options_create, btck_context_options_destroy, btck_context_options_set_chainparams, @@ -83,8 +84,7 @@ use crate::{ BlockDisconnectedCallback, NewPoWValidBlockCallback, ValidationCallbackRegistry, }, }, - KernelError, BTCK_CHAIN_TYPE_MAINNET, BTCK_CHAIN_TYPE_REGTEST, BTCK_CHAIN_TYPE_SIGNET, - BTCK_CHAIN_TYPE_TESTNET, BTCK_CHAIN_TYPE_TESTNET_4, + KernelError, }; /// Chain parameters for configuring a [`Context`]. @@ -1003,15 +1003,15 @@ impl Drop for ContextBuilder { #[repr(u8)] pub enum ChainType { /// Bitcoin mainnet - production network with economic value - Mainnet = BTCK_CHAIN_TYPE_MAINNET, + Mainnet = btck_ChainType_MAINNET, /// Bitcoin testnet3 - test network for development and testing - Testnet = BTCK_CHAIN_TYPE_TESTNET, + Testnet = btck_ChainType_TESTNET, /// Bitcoin testnet4 - newer test network with tweaked block production - Testnet4 = BTCK_CHAIN_TYPE_TESTNET_4, + Testnet4 = btck_ChainType_TESTNET_4, /// Bitcoin signet - test network with controlled, regular block production - Signet = BTCK_CHAIN_TYPE_SIGNET, + Signet = btck_ChainType_SIGNET, /// Regression test network for local development - Regtest = BTCK_CHAIN_TYPE_REGTEST, + Regtest = btck_ChainType_REGTEST, } impl From for btck_ChainType { @@ -1020,14 +1020,15 @@ impl From for btck_ChainType { } } +#[allow(non_upper_case_globals)] impl From for ChainType { fn from(value: btck_ChainType) -> Self { match value { - BTCK_CHAIN_TYPE_MAINNET => ChainType::Mainnet, - BTCK_CHAIN_TYPE_TESTNET => ChainType::Testnet, - BTCK_CHAIN_TYPE_TESTNET_4 => ChainType::Testnet4, - BTCK_CHAIN_TYPE_SIGNET => ChainType::Signet, - BTCK_CHAIN_TYPE_REGTEST => ChainType::Regtest, + btck_ChainType_MAINNET => ChainType::Mainnet, + btck_ChainType_TESTNET => ChainType::Testnet, + btck_ChainType_TESTNET_4 => ChainType::Testnet4, + btck_ChainType_SIGNET => ChainType::Signet, + btck_ChainType_REGTEST => ChainType::Regtest, _ => panic!("Unknown chain type: {}", value), } }