From 0b2ca1f6609c306a43ec0fdd513cd17be239224a Mon Sep 17 00:00:00 2001 From: Sudarshan-21 Date: Sun, 5 May 2024 12:40:34 +0530 Subject: [PATCH 1/7] Placeholder snippets added, dependency import --- Cargo.lock | 2 +- crates/floresta-cli/Cargo.toml | 2 +- crates/floresta-cli/src/error.rs | 27 +++++++++++++++++++++++++++ crates/floresta-cli/src/main.rs | 9 +++++---- crates/floresta-cli/src/rpc_types.rs | 13 +++++++++++++ 5 files changed, 47 insertions(+), 6 deletions(-) create mode 100644 crates/floresta-cli/src/error.rs diff --git a/Cargo.lock b/Cargo.lock index c90ccfd2..6acba9be 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -925,7 +925,6 @@ dependencies = [ name = "floresta-cli" version = "0.1.0" dependencies = [ - "anyhow", "bitcoin 0.31.0", "clap", "rand 0.8.5", @@ -933,6 +932,7 @@ dependencies = [ "serde", "serde_json", "tempfile", + "thiserror", ] [[package]] diff --git a/crates/floresta-cli/Cargo.toml b/crates/floresta-cli/Cargo.toml index 6a4c552f..603f9a85 100644 --- a/crates/floresta-cli/Cargo.toml +++ b/crates/floresta-cli/Cargo.toml @@ -19,7 +19,7 @@ clap = { version = "4.0.29", features = ["derive"] } bitcoin = { version = "0.31", features = ["serde", "std"] } serde = { version = "1.0", features = ["derive"] } serde_json = "1.0" -anyhow = "1.0" +thiserror = "1.0" reqwest = { version = "0.11.23", optional = true, features = ["blocking"] } [features] diff --git a/crates/floresta-cli/src/error.rs b/crates/floresta-cli/src/error.rs new file mode 100644 index 00000000..16377ff6 --- /dev/null +++ b/crates/floresta-cli/src/error.rs @@ -0,0 +1,27 @@ +use thiserror::Error; +use floresta_cli::rpc_types::Error as RpcError; + +#[derive(Error, Debug)] +pub enum AppError { + #[error("Invalid network specified")] + InvalidNetwork, + #[error("RPC client error: {0}")] + CustomRpcError(#[from] reqwest::Error), + #[error("Serialization error: {0}")] + SerializationError(#[from] serde_json::Error), + #[error("Floresta RPC error: {0}")] + FlorestaRpcError(#[from] floresta_cli::rpc_types::Error), + #[error("Internal API error: {0}")] + ApiError(String), +} + +impl From for AppError { + fn from(error: serde_json::Error) -> Self { + AppError::SerializationError(error) + } +} +impl From for AppError { + fn from(error: RpcError) -> Self { + AppError::FlorestaRpcError(error) + } +} \ No newline at end of file diff --git a/crates/floresta-cli/src/main.rs b/crates/floresta-cli/src/main.rs index 76abfe95..a1a83475 100644 --- a/crates/floresta-cli/src/main.rs +++ b/crates/floresta-cli/src/main.rs @@ -1,19 +1,20 @@ use std::fmt::Debug; -use anyhow::Ok; use bitcoin::BlockHash; use bitcoin::Network; use bitcoin::Txid; use clap::Parser; use clap::Subcommand; +use crate::error::AppError; use floresta_cli::reqwest_client::ReqwestClient; use floresta_cli::rpc::FlorestaRPC; +mod error; mod reqwest_client; mod rpc; mod rpc_types; -fn main() -> anyhow::Result<()> { +fn main() -> Result<(), AppError> { let cli = Cli::parse(); let client = ReqwestClient::new(get_host(&cli)); @@ -21,7 +22,7 @@ fn main() -> anyhow::Result<()> { println!("{}", res); - anyhow::Ok(()) + Ok(()) } fn get_host(cmd: &Cli) -> String { @@ -38,7 +39,7 @@ fn get_host(cmd: &Cli) -> String { } } -fn do_request(cmd: &Cli, client: ReqwestClient) -> anyhow::Result { +fn do_request(cmd: &Cli, client: ReqwestClient) -> Result { Ok(match cmd.methods.clone() { Methods::GetBlockchainInfo => serde_json::to_string_pretty(&client.get_blockchain_info()?)?, Methods::GetBlockHash { height } => { diff --git a/crates/floresta-cli/src/rpc_types.rs b/crates/floresta-cli/src/rpc_types.rs index d29866ed..72b36567 100644 --- a/crates/floresta-cli/src/rpc_types.rs +++ b/crates/floresta-cli/src/rpc_types.rs @@ -1,3 +1,4 @@ +use crate::error::AppError; use std::fmt::Display; use serde::Deserialize; @@ -274,6 +275,18 @@ impl From for Error { } } +impl From for AppError { + fn from(error: Error) -> Self { + match error { + Error::Serde(e) => AppError::SerializationError(e), + #[cfg(feature = "with-reqwest")] + Error::Reqwest(e) => AppError::CustomRpcError(e), + Error::Api(e) => AppError::ApiError(format!("{}", e)), + Error::EmtpyResponse => AppError::ApiError("Empty response from server".to_string()), + } + } +} + impl Display for Error { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { From 6e8d9f7002630aa578bc32d8ad12ef6281e3ccb3 Mon Sep 17 00:00:00 2001 From: jaoleal Date: Tue, 14 May 2024 14:38:33 -0300 Subject: [PATCH 2/7] Delegating errors to thiserror crate using #[from] Signed-off-by: jaoleal --- florestad/src/error.rs | 104 +++++++++++++---------------------------- 1 file changed, 33 insertions(+), 71 deletions(-) diff --git a/florestad/src/error.rs b/florestad/src/error.rs index ec896dd0..3127209b 100644 --- a/florestad/src/error.rs +++ b/florestad/src/error.rs @@ -1,79 +1,41 @@ +use crate::slip132; use bitcoin::consensus::encode; #[cfg(feature = "cli-blockchain")] use btcd_rpc::error::UtreexodError; use floresta_chain::BlockValidationErrors; use floresta_chain::BlockchainError; - -use crate::slip132; -#[derive(Debug)] +use thiserror::Error; +#[derive(Error, Debug)] pub enum Error { #[cfg(feature = "cli-blockchain")] - UtreexodError(UtreexodError), - Encode(encode::Error), - Db(kv::Error), - ParseNum(std::num::ParseIntError), - Rustreexo(String), - Io(std::io::Error), - BlockValidation(BlockValidationErrors), - ScriptValidation(bitcoin::blockdata::script::Error), - Blockchain(BlockchainError), - SerdeJson(serde_json::Error), - TomlParsing(toml::de::Error), - WalletInput(slip132::Error), - AddressParsing(bitcoin::address::ParseError), - Address(bitcoin::address::Error), - Miniscript(miniscript::Error), -} - -impl std::fmt::Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Error::Encode(err) => write!(f, "Encode error: {err}"), - #[cfg(feature = "cli-blockchain")] - Error::UtreexodError(_) => write!(f, "UtreexodError"), - Error::Db(err) => write!(f, "Database error {err}"), - Error::ParseNum(err) => write!(f, "int parse error: {err}"), - Error::Rustreexo(err) => write!(f, "Rustreexo error: {err}"), - Error::Io(err) => write!(f, "Io error {err}"), - Error::ScriptValidation(err) => write!(f, "Error during script evaluation: {err}"), - Error::Blockchain(err) => write!(f, "Error with our blockchain backend: {:?}", err), - Error::SerdeJson(err) => write!(f, "Error serializing object {err}"), - Error::WalletInput(err) => write!(f, "Error while parsing user input {:?}", err), - Error::TomlParsing(err) => write!(f, "Error deserializing toml file {err}"), - Error::AddressParsing(err) => write!(f, "Invalid address {err}"), - Error::Miniscript(err) => write!(f, "Miniscript error: {err}"), - Error::BlockValidation(err) => write!(f, "Error while validating block: {err:?}"), - Error::Address(err) => write!(f, "Error while validating address: {err}"), - } - } + #[error(transparent)] + UtreexodError(#[from] UtreexodError), + #[error(transparent)] + Encode(#[from] encode::Error), + #[error(transparent)] + Db(#[from] kv::Error), + #[error(transparent)] + ParseNum(#[from] std::num::ParseIntError), + #[error(transparent)] + Rustreexo(#[from] String), + #[error(transparent)] + Io(#[from] std::io::Error), + #[error(transparent)] + BlockValidation(#[from] BlockValidationErrors), + #[error(transparent)] + ScriptValidation(#[from] bitcoin::blockdata::script::Error), + #[error(transparent)] + Blockchain(#[from] BlockchainError), + #[error(transparent)] + SerdeJson(#[from] serde_json::Error), + #[error(transparent)] + TomlParsing(#[from] toml::de::Error), + #[error(transparent)] + WalletInput(#[from] slip132::Error), + #[error(transparent)] + AddressParsing(#[from] bitcoin::address::ParseError), + #[error(transparent)] + Address(#[from] bitcoin::address::Error), + #[error(transparent)] + Miniscript(#[from] miniscript::Error), } -/// Implements `From` where `T` is a possible error outcome in this crate, this macro only -/// takes [T] and builds [Error] with the right variant. -macro_rules! impl_from_error { - ($field:ident, $error:ty) => { - impl From<$error> for Error { - fn from(err: $error) -> Self { - Error::$field(err) - } - } - }; -} -// impl_from_error!(Parsing, bitcoin::hashes::hex::Error); -#[cfg(feature = "cli-blockchain")] -impl_from_error!(UtreexodError, UtreexodError); -impl_from_error!(Encode, encode::Error); -impl_from_error!(Db, kv::Error); -impl_from_error!(ParseNum, std::num::ParseIntError); -impl_from_error!(Rustreexo, String); -impl_from_error!(Io, std::io::Error); -impl_from_error!(ScriptValidation, bitcoin::blockdata::script::Error); -impl_from_error!(Blockchain, BlockchainError); -impl_from_error!(SerdeJson, serde_json::Error); -impl_from_error!(WalletInput, slip132::Error); -impl_from_error!(TomlParsing, toml::de::Error); -impl_from_error!(BlockValidation, BlockValidationErrors); -impl_from_error!(AddressParsing, bitcoin::address::ParseError); -impl_from_error!(Miniscript, miniscript::Error); -impl_from_error!(Address, bitcoin::address::Error); - -impl std::error::Error for Error {} From efe7d96a4425e3d8b3ece6d3b809b361eb35c774 Mon Sep 17 00:00:00 2001 From: jaoleal Date: Wed, 15 May 2024 09:58:04 -0300 Subject: [PATCH 3/7] saving progress --- .pre-commit-config.yaml | 1 + Cargo.lock | 377 ++++++++++++++------------- crates/floresta-cli/src/error.rs | 4 +- crates/floresta-cli/src/main.rs | 2 +- crates/floresta-cli/src/rpc_types.rs | 53 +--- flake.lock | 210 +++++++++++++++ flake.nix | 94 +++++++ florestad/Cargo.toml | 3 +- florestad/src/config_file.rs | 2 +- florestad/src/error.rs | 17 +- florestad/src/florestad.rs | 9 +- florestad/src/slip132.rs | 6 +- florestad/src/wallet_input.rs | 10 +- 13 files changed, 527 insertions(+), 261 deletions(-) create mode 120000 .pre-commit-config.yaml create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 120000 index 00000000..98ef3aaa --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1 @@ +/nix/store/f9740731bvbp8xgm3ws47p1c8khqlrhr-pre-commit-config.json \ No newline at end of file diff --git a/Cargo.lock b/Cargo.lock index 6acba9be..b8cef73d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -40,9 +40,9 @@ dependencies = [ [[package]] name = "allocator-api2" -version = "0.2.16" +version = "0.2.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5" +checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" [[package]] name = "android-tzdata" @@ -61,58 +61,53 @@ dependencies = [ [[package]] name = "anstream" -version = "0.6.13" +version = "0.6.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d96bd03f33fe50a863e394ee9718a706f988b9079b20c3784fb726e7678b62fb" +checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b" dependencies = [ "anstyle", "anstyle-parse", "anstyle-query", "anstyle-wincon", "colorchoice", + "is_terminal_polyfill", "utf8parse", ] [[package]] name = "anstyle" -version = "1.0.6" +version = "1.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8901269c6307e8d93993578286ac0edf7f195079ffff5ebdeea6a59ffb7e36bc" +checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b" [[package]] name = "anstyle-parse" -version = "0.2.3" +version = "0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c75ac65da39e5fe5ab759307499ddad880d724eed2f6ce5b5e8a26f4f387928c" +checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4" dependencies = [ "utf8parse", ] [[package]] name = "anstyle-query" -version = "1.0.2" +version = "1.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e28923312444cdd728e4738b3f9c9cac739500909bb3d3c94b43551b16517648" +checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5" dependencies = [ "windows-sys 0.52.0", ] [[package]] name = "anstyle-wincon" -version = "3.0.2" +version = "3.0.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1cd54b81ec8d6180e24654d0b371ad22fc3dd083b6ff8ba325b72e00c87660a7" +checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19" dependencies = [ "anstyle", "windows-sys 0.52.0", ] -[[package]] -name = "anyhow" -version = "1.0.81" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0952808a6c2afd1aa8947271f3a60f1a6763c7b912d210184c5149b5cf147247" - [[package]] name = "async-attributes" version = "1.1.2" @@ -136,27 +131,26 @@ dependencies = [ [[package]] name = "async-channel" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f28243a43d821d11341ab73c80bed182dc015c514b951616cf79bd4af39af0c3" +checksum = "9f2776ead772134d55b62dd45e59a79e21612d85d0af729b8b7d3967d601a62a" dependencies = [ "concurrent-queue", "event-listener 5.3.0", - "event-listener-strategy 0.5.1", + "event-listener-strategy 0.5.2", "futures-core", "pin-project-lite", ] [[package]] name = "async-executor" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f98c37cf288e302c16ef6c8472aad1e034c6c84ce5ea7b8101c98eb4a802fee" +checksum = "b10202063978b3351199d68f8b22c4e47e4b1b822f8d43fd862d5ea8c006b29a" dependencies = [ - "async-lock 3.3.0", "async-task", "concurrent-queue", - "fastrand 2.0.2", + "fastrand 2.1.0", "futures-lite 2.3.0", "slab", ] @@ -167,7 +161,7 @@ version = "2.4.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "05b1b633a2115cd122d73b955eadd9916c18c8f510ec9cd1686404c60ad1c29c" dependencies = [ - "async-channel 2.2.0", + "async-channel 2.3.0", "async-executor", "async-io 2.3.2", "async-lock 3.3.0", @@ -208,8 +202,8 @@ dependencies = [ "futures-io", "futures-lite 2.3.0", "parking", - "polling 3.6.0", - "rustix 0.38.32", + "polling 3.7.0", + "rustix 0.38.34", "slab", "tracing", "windows-sys 0.52.0", @@ -264,9 +258,9 @@ dependencies = [ [[package]] name = "async-task" -version = "4.7.0" +version = "4.7.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fbb36e985947064623dbd357f727af08ffd077f93d696782f3c56365fa2e2799" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" [[package]] name = "atomic-waker" @@ -276,9 +270,9 @@ checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" [[package]] name = "autocfg" -version = "1.2.0" +version = "1.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f1fdabc7756949593fe60f30ec81974b613357de856987752631dea1e3394c80" +checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" [[package]] name = "backtrace" @@ -411,18 +405,16 @@ dependencies = [ [[package]] name = "blocking" -version = "1.5.1" +version = "1.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6a37913e8dc4ddcc604f0c6d3bf2887c995153af3611de9e23c352b44c1b9118" +checksum = "495f7104e962b7356f0aeb34247aca1fe7d2e783b346582db7f2904cb5717e88" dependencies = [ - "async-channel 2.2.0", + "async-channel 2.3.0", "async-lock 3.3.0", "async-task", - "fastrand 2.0.2", "futures-io", "futures-lite 2.3.0", "piper", - "tracing", ] [[package]] @@ -455,19 +447,20 @@ checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9" [[package]] name = "cc" -version = "1.0.92" +version = "1.0.97" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2678b2e3449475e95b0aa6f9b506a28e61b3dc8996592b983695e8ebb58a8b41" +checksum = "099a5357d84c4c61eb35fc8eafa9a79a902c2f76911e5747ced4e032edd8d9b4" dependencies = [ "jobserver", "libc", + "once_cell", ] [[package]] name = "cfg-expr" -version = "0.15.7" +version = "0.15.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "fa50868b64a9a6fda9d593ce778849ea8715cd2a3d2cc17ffdb4a2f2f2f1961d" +checksum = "d067ad48b8650848b989a59a86c6c36a995d02d2bf778d45c3c5d57bc2718f02" dependencies = [ "smallvec", "target-lexicon", @@ -493,16 +486,16 @@ checksum = "fd16c4719339c4530435d38e511904438d07cce7950afa3718a84ac36c10e89e" [[package]] name = "chrono" -version = "0.4.37" +version = "0.4.38" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8a0d04d43504c61aa6c7531f1871dd0d418d91130162063b789da00fd7057a5e" +checksum = "a21f936df1771bf62b77f047b726c4625ff2e8aa607c01ec06e5a05bd8463401" dependencies = [ "android-tzdata", "iana-time-zone", "js-sys", "num-traits", "wasm-bindgen", - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -536,7 +529,7 @@ dependencies = [ "heck", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -547,9 +540,9 @@ checksum = "98cc8fbded0c607b7ba9dd60cd98df59af97e84d24e49c8557331cfc26d301ce" [[package]] name = "colorchoice" -version = "1.0.0" +version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "acbf1af155f9b9ef647e42cdc158db4b64a1b61f743629225fde6f3e0be2a7c7" +checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422" [[package]] name = "colored" @@ -564,9 +557,9 @@ dependencies = [ [[package]] name = "concurrent-queue" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d16048cd947b08fa32c24458a22f5dc5e835264f689f4f5653210c69fd107363" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" dependencies = [ "crossbeam-utils", ] @@ -779,15 +772,15 @@ dependencies = [ [[package]] name = "either" -version = "1.10.0" +version = "1.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "11157ac094ffbdde99aa67b23417ebdd801842852b500e395a45a9c0aac03e4a" +checksum = "a47c1c47d2f5964e29c61246e81db715514cd532db6b5116a25ea3c03d6780a2" [[package]] name = "encoding_rs" -version = "0.8.33" +version = "0.8.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7268b386296a025e474d5140678f75d6de9493ae55a5d709eeb9dd08149945e1" +checksum = "b45de904aa0b010bce2ab45264d0631681847fa7b6f2eaa7dab7619943bc4f59" dependencies = [ "cfg-if 1.0.0", ] @@ -800,9 +793,9 @@ checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" [[package]] name = "errno" -version = "0.3.8" +version = "0.3.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a258e46cdc063eb8519c00b9fc845fc47bcfca4130e2f08e88665ceda8474245" +checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", "windows-sys 0.52.0", @@ -848,9 +841,9 @@ dependencies = [ [[package]] name = "event-listener-strategy" -version = "0.5.1" +version = "0.5.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "332f51cb23d20b0de8458b86580878211da09bcd4503cb579c225b3d124cabb3" +checksum = "0f214dc438f977e6d4e3500aaa277f5ad94ca83fbbd9b1a15713ce2344ccc5a1" dependencies = [ "event-listener 5.3.0", "pin-project-lite", @@ -867,9 +860,9 @@ dependencies = [ [[package]] name = "fastrand" -version = "2.0.2" +version = "2.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "658bd65b1cf4c852a3cc96f18a8ce7b5640f6b703f905c7d74532294c2a63984" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" [[package]] name = "fern" @@ -1021,7 +1014,6 @@ dependencies = [ name = "florestad" version = "0.5.1" dependencies = [ - "anyhow", "async-std", "bitcoin 0.31.0", "chrono", @@ -1050,6 +1042,7 @@ dependencies = [ "serde", "serde_json", "sha2", + "thiserror", "toml 0.5.11", "zmq", ] @@ -1170,7 +1163,7 @@ version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52527eb5074e35e9339c6b4e8d12600c7128b68fb25dcb9fa9dec18f7c25f3a5" dependencies = [ - "fastrand 2.0.2", + "fastrand 2.1.0", "futures-core", "futures-io", "parking", @@ -1185,7 +1178,7 @@ checksum = "87750cf4b7a4c0625b1529e4c543c2182106e4dedc60a2a6455e00d212c489ac" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -1264,9 +1257,9 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.2.14" +version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "94b22e06ecb0110981051723910cbf0b5f5e09a2062dd7663334ee79a9d1286c" +checksum = "c4567c8db10ae91089c99af84c68c38da3ec2f087c3f82960bcdbf3656b6f4d7" dependencies = [ "cfg-if 1.0.0", "libc", @@ -1319,15 +1312,15 @@ dependencies = [ "indexmap", "slab", "tokio", - "tokio-util 0.7.10", + "tokio-util 0.7.11", "tracing", ] [[package]] name = "hashbrown" -version = "0.14.3" +version = "0.14.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "290f1a1d9242c78d09ce40a5e87e7554ee637af1351968159f4952f028f75604" +checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" dependencies = [ "ahash", "allocator-api2", @@ -1353,9 +1346,9 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hex-conservative" -version = "0.1.1" +version = "0.1.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30ed443af458ccb6d81c1e7e661545f94d3176752fb1df2f543b902a1e0f51e2" +checksum = "212ab92002354b4819390025006c897e8140934349e8635c9b077f47b4dcbd20" dependencies = [ "core2 0.3.3", ] @@ -1417,7 +1410,7 @@ dependencies = [ "httpdate", "itoa", "pin-project-lite", - "socket2 0.5.6", + "socket2 0.5.7", "tokio", "tower-service", "tracing", @@ -1528,6 +1521,12 @@ dependencies = [ "windows-sys 0.52.0", ] +[[package]] +name = "is_terminal_polyfill" +version = "1.70.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800" + [[package]] name = "itoa" version = "1.0.11" @@ -1536,9 +1535,9 @@ checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b" [[package]] name = "jobserver" -version = "0.1.28" +version = "0.1.31" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ab46a6e9526ddef3ae7f787c06f0f2600639ba80ea3eade3d8e670a2230f51d6" +checksum = "d2b099aaa34a9751c5bf0878add70444e1ed2dd73f347be99003d4577277de6e" dependencies = [ "libc", ] @@ -1702,9 +1701,9 @@ checksum = "e2abad23fbc42b3700f2f279844dc832adb2b2eb069b2df918f455c4e18cc646" [[package]] name = "libc" -version = "0.2.153" +version = "0.2.154" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c198f91728a82281a64e1f4f9eeb25d82cb32a5de251c6bd1b5154d63a8e7bd" +checksum = "ae743338b92ff9146ce83992f766a31066a91a8c84a45e0e9f21e7cf6de6d346" [[package]] name = "libredox" @@ -1730,9 +1729,9 @@ checksum = "01cda141df6706de531b6c46c3a33ecca755538219bd484262fa09410c13539c" [[package]] name = "lock_api" -version = "0.4.11" +version = "0.4.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3c168f8615b12bc01f9c17e2eb0cc07dcae1940121185446edc3744920e8ef45" +checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" dependencies = [ "autocfg", "scopeguard", @@ -1882,9 +1881,9 @@ dependencies = [ [[package]] name = "num-traits" -version = "0.2.18" +version = "0.2.19" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da0df0e5185db44f69b44f26786fe401b6c293d1907744beaa7fa62b2e5a517a" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" dependencies = [ "autocfg", ] @@ -1946,7 +1945,7 @@ checksum = "a948666b637a0f465e8564c73e89d4dde00d72d4d473cc972f390fc3dcee7d9c" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -1992,12 +1991,12 @@ dependencies = [ [[package]] name = "parking_lot" -version = "0.12.1" +version = "0.12.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3742b2c103b9f06bc9fff0a37ff4912935851bee6d36f3c02bcc755bcfec228f" +checksum = "7e4af0ca4f6caed20e900d564c242b8e5d4903fdacf31d3daf527b66fe6f42fb" dependencies = [ "lock_api", - "parking_lot_core 0.9.9", + "parking_lot_core 0.9.10", ] [[package]] @@ -2016,15 +2015,15 @@ dependencies = [ [[package]] name = "parking_lot_core" -version = "0.9.9" +version = "0.9.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4c42a9226546d68acdd9c0a280d17ce19bfe27a46bf68784e4066115788d008e" +checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" dependencies = [ "cfg-if 1.0.0", "libc", - "redox_syscall 0.4.1", + "redox_syscall 0.5.1", "smallvec", - "windows-targets 0.48.5", + "windows-targets 0.52.5", ] [[package]] @@ -2053,12 +2052,12 @@ checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" [[package]] name = "piper" -version = "0.2.1" +version = "0.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "668d31b1c4eba19242f2088b2bf3316b82ca31082a8335764db4e083db7485d4" +checksum = "464db0c665917b13ebb5d453ccdec4add5658ee1adc7affc7677615356a8afaf" dependencies = [ "atomic-waker", - "fastrand 2.0.2", + "fastrand 2.1.0", "futures-io", ] @@ -2086,15 +2085,15 @@ dependencies = [ [[package]] name = "polling" -version = "3.6.0" +version = "3.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e0c976a60b2d7e99d6f229e414670a9b85d13ac305cc6d1e9c134de58c5aaaf6" +checksum = "645493cf344456ef24219d02a768cf1fb92ddf8c92161679ae3d91b91a637be3" dependencies = [ "cfg-if 1.0.0", "concurrent-queue", "hermit-abi", "pin-project-lite", - "rustix 0.38.32", + "rustix 0.38.34", "tracing", "windows-sys 0.52.0", ] @@ -2126,18 +2125,18 @@ dependencies = [ [[package]] name = "proc-macro2" -version = "1.0.79" +version = "1.0.82" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e835ff2298f5721608eb1a980ecaee1aef2c132bf95ecc026a11b7bf3c01c02e" +checksum = "8ad3d49ab951a01fbaafe34f2ec74122942fe18a3f9814c3268f1bb72042131b" dependencies = [ "unicode-ident", ] [[package]] name = "quote" -version = "1.0.35" +version = "1.0.36" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "291ec9ab5efd934aaf503a6466c5d5251535d108ee747472c3977cc5acc868ef" +checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7" dependencies = [ "proc-macro2", ] @@ -2201,7 +2200,7 @@ version = "0.6.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c" dependencies = [ - "getrandom 0.2.14", + "getrandom 0.2.15", ] [[package]] @@ -2244,11 +2243,11 @@ dependencies = [ [[package]] name = "redox_syscall" -version = "0.4.1" +version = "0.5.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4722d768eff46b75989dd134e5c353f0d6296e5aaa3132e776cbdb56be7731aa" +checksum = "469052894dcb553421e483e4209ee581a45100d31b4018de03e5a7ad86374a7e" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", ] [[package]] @@ -2257,7 +2256,7 @@ version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bd283d9651eeda4b2a83a43c1c91b266c40fd76ecd39a50a8c630ae69dc72891" dependencies = [ - "getrandom 0.2.14", + "getrandom 0.2.15", "libredox", "thiserror", ] @@ -2348,9 +2347,9 @@ dependencies = [ [[package]] name = "rustc-demangle" -version = "0.1.23" +version = "0.1.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76" +checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" [[package]] name = "rustc_version" @@ -2377,9 +2376,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.32" +version = "0.38.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "65e04861e65f21776e67888bfbea442b3642beaa0138fdb1dd7a84a52dffdb89" +checksum = "70dc5ec042f7a43c4a73241207cecc9873a06d45debb38b329f8541d85c2730f" dependencies = [ "bitflags 2.5.0", "errno", @@ -2408,15 +2407,15 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.15" +version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "80af6f9131f277a45a3fba6ce8e2258037bb0477a67e610d3c1fe046ab31de47" +checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" [[package]] name = "ryu" -version = "1.0.17" +version = "1.0.18" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1" +checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f" [[package]] name = "same-file" @@ -2507,11 +2506,11 @@ dependencies = [ [[package]] name = "security-framework" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "770452e37cad93e0a50d5abc3990d2bc351c36d0328f86cefec2f2fb206eaef6" +checksum = "c627723fd09706bacdb5cf41499e95098555af3c3c29d014dc3c458ef6be11c0" dependencies = [ - "bitflags 1.3.2", + "bitflags 2.5.0", "core-foundation", "core-foundation-sys", "libc", @@ -2520,9 +2519,9 @@ dependencies = [ [[package]] name = "security-framework-sys" -version = "2.10.0" +version = "2.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "41f3cc463c0ef97e11c3461a9d3787412d30e8e7eb907c79180c4a57bf7c04ef" +checksum = "317936bbbd05227752583946b9e66d7ce3b489f84e11a94a510b4437fef407d7" dependencies = [ "core-foundation-sys", "libc", @@ -2530,35 +2529,35 @@ dependencies = [ [[package]] name = "semver" -version = "1.0.22" +version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "92d43fe69e652f3df9bdc2b85b2854a0825b86e4fb76bc44d945137d053639ca" +checksum = "61697e0a1c7e512e84a621326239844a24d8207b4669b41bc18b32ea5cbf988b" [[package]] name = "serde" -version = "1.0.197" +version = "1.0.202" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fb1c873e1b9b056a4dc4c0c198b24c3ffa059243875552b2bd0933b1aee4ce2" +checksum = "226b61a0d411b2ba5ff6d7f73a476ac4f8bb900373459cd00fab8512828ba395" dependencies = [ "serde_derive", ] [[package]] name = "serde_derive" -version = "1.0.197" +version = "1.0.202" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7eb0b34b42edc17f6b7cac84a52a1c5f0e1bb2227e997ca9011ea3dd34e8610b" +checksum = "6048858004bcff69094cd972ed40a32500f153bd3be9f716b2eed2e8217c4838" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] name = "serde_json" -version = "1.0.115" +version = "1.0.117" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12dc5c46daa8e9fdf4f5e71b6cf9a53f2487da0e86e55808e2d35539666497dd" +checksum = "455182ea6142b14f93f4bc5320a2b31c1f266b66a4a5c858b013302a5d8cbfc3" dependencies = [ "itoa", "ryu", @@ -2608,9 +2607,9 @@ dependencies = [ [[package]] name = "signal-hook-registry" -version = "1.4.1" +version = "1.4.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d8229b473baa5980ac72ef434c4415e70c4b5e71b423043adb4ba059f89c99a1" +checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" dependencies = [ "libc", ] @@ -2658,9 +2657,9 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.6" +version = "0.5.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05ffd9c0a93b7543e062e759284fcf5f5e3b098501104bfbdde4d404db792871" +checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" dependencies = [ "libc", "windows-sys 0.52.0", @@ -2694,9 +2693,9 @@ dependencies = [ [[package]] name = "syn" -version = "2.0.58" +version = "2.0.63" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44cfb93f38070beee36b3fef7d4f5a16f27751d94b187b666a5cc5e9b0d30687" +checksum = "bf5be731623ca1a1fb7d8be6f261a3be6d3e2337b8a1f97be944d020c8fcb704" dependencies = [ "proc-macro2", "quote", @@ -2756,29 +2755,29 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "85b77fafb263dd9d05cbeac119526425676db3784113aa9295c88498cbf8bff1" dependencies = [ "cfg-if 1.0.0", - "fastrand 2.0.2", - "rustix 0.38.32", + "fastrand 2.1.0", + "rustix 0.38.34", "windows-sys 0.52.0", ] [[package]] name = "thiserror" -version = "1.0.58" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03468839009160513471e86a034bb2c5c0e4baae3b43f79ffc55c4a5427b3297" +checksum = "579e9083ca58dd9dcf91a9923bb9054071b9ebbd800b342194c9feb0ee89fc18" dependencies = [ "thiserror-impl", ] [[package]] name = "thiserror-impl" -version = "1.0.58" +version = "1.0.60" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c61f3ba182994efc43764a46c018c347bc492c79f024e705f46567b418f6d4f7" +checksum = "e2470041c06ec3ac1ab38d0356a6119054dedaea53e12fbefc0de730a1c08524" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -2817,10 +2816,10 @@ dependencies = [ "libc", "mio", "num_cpus", - "parking_lot 0.12.1", + "parking_lot 0.12.2", "pin-project-lite", "signal-hook-registry", - "socket2 0.5.6", + "socket2 0.5.7", "tokio-macros", "windows-sys 0.48.0", ] @@ -2833,7 +2832,7 @@ checksum = "5b8a1e28f2deaa14e508979454cb3a223b10b938b45af148bc0986de36f1923b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -2873,16 +2872,15 @@ dependencies = [ [[package]] name = "tokio-util" -version = "0.7.10" +version = "0.7.11" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5419f34732d9eb6ee4c3578b7989078579b7f039cbbb9ca2c4da015749371e15" +checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" dependencies = [ "bytes", "futures-core", "futures-sink", "pin-project-lite", "tokio", - "tracing", ] [[package]] @@ -2917,9 +2915,9 @@ dependencies = [ [[package]] name = "toml_edit" -version = "0.22.9" +version = "0.22.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8e40bb779c5187258fd7aad0eb68cb8706a0a81fa712fbea808ab43c4b8374c4" +checksum = "d3328d4f68a705b2a4498da1d580585d39a6510f98318a2cec3018a7ec61ddef" dependencies = [ "indexmap", "serde", @@ -2953,7 +2951,7 @@ checksum = "34704c8d6ebcbc939824180af020566b01a7c01f80641264eba0999f6c2b6be7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] @@ -3073,9 +3071,9 @@ checksum = "830b7e5d4d90034032940e4ace0d9a9a057e7a45cd94e6c007832e39edb82f6d" [[package]] name = "value-bag" -version = "1.8.1" +version = "1.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74797339c3b98616c009c7c3eb53a0ce41e85c8ec66bd3db96ed132d20cfdee8" +checksum = "5a84c137d37ab0142f0f2ddfe332651fdbf252e7b7dbb4e67b6c1f1b2e925101" [[package]] name = "vcpkg" @@ -3097,9 +3095,9 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f" [[package]] name = "waker-fn" -version = "1.1.1" +version = "1.2.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f3c4517f54858c779bbcbf228f4fca63d121bf85fbecb2dc578cdf4a39395690" +checksum = "317211a0dc0ceedd78fb2ca9a44aed3d7b9b26f81870d485c07122b4350673b7" [[package]] name = "walkdir" @@ -3153,7 +3151,7 @@ dependencies = [ "once_cell", "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", "wasm-bindgen-shared", ] @@ -3187,7 +3185,7 @@ checksum = "e94f17b526d0a461a191c78ea52bbce64071ed5c04c9ffe424dcb38f74171bb7" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", "wasm-bindgen-backend", "wasm-bindgen-shared", ] @@ -3226,11 +3224,11 @@ checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" [[package]] name = "winapi-util" -version = "0.1.6" +version = "0.1.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f29e6f9198ba0d26b4c9f07dbe6f9ed633e1f3d5b8b414090084349e46a52596" +checksum = "4d4cc384e1e73b93bafa6fb4f1df8c41695c8a91cf9c4c64358067d15a7b6c6b" dependencies = [ - "winapi", + "windows-sys 0.52.0", ] [[package]] @@ -3254,7 +3252,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "33ab640c8d7e35bf8ba19b884ba838ceb4fba93a4e8c65a9059d08afcfc683d9" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -3272,7 +3270,7 @@ version = "0.52.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" dependencies = [ - "windows-targets 0.52.4", + "windows-targets 0.52.5", ] [[package]] @@ -3292,17 +3290,18 @@ dependencies = [ [[package]] name = "windows-targets" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd37b7e5ab9018759f893a1952c9420d060016fc19a472b4bb20d1bdd694d1b" +checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb" dependencies = [ - "windows_aarch64_gnullvm 0.52.4", - "windows_aarch64_msvc 0.52.4", - "windows_i686_gnu 0.52.4", - "windows_i686_msvc 0.52.4", - "windows_x86_64_gnu 0.52.4", - "windows_x86_64_gnullvm 0.52.4", - "windows_x86_64_msvc 0.52.4", + "windows_aarch64_gnullvm 0.52.5", + "windows_aarch64_msvc 0.52.5", + "windows_i686_gnu 0.52.5", + "windows_i686_gnullvm", + "windows_i686_msvc 0.52.5", + "windows_x86_64_gnu 0.52.5", + "windows_x86_64_gnullvm 0.52.5", + "windows_x86_64_msvc 0.52.5", ] [[package]] @@ -3313,9 +3312,9 @@ checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8" [[package]] name = "windows_aarch64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bcf46cf4c365c6f2d1cc93ce535f2c8b244591df96ceee75d8e83deb70a9cac9" +checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263" [[package]] name = "windows_aarch64_msvc" @@ -3325,9 +3324,9 @@ checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc" [[package]] name = "windows_aarch64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "da9f259dd3bcf6990b55bffd094c4f7235817ba4ceebde8e6d11cd0c5633b675" +checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6" [[package]] name = "windows_i686_gnu" @@ -3337,9 +3336,15 @@ checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e" [[package]] name = "windows_i686_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b474d8268f99e0995f25b9f095bc7434632601028cf86590aea5c8a5cb7801d3" +checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9" [[package]] name = "windows_i686_msvc" @@ -3349,9 +3354,9 @@ checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406" [[package]] name = "windows_i686_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1515e9a29e5bed743cb4415a9ecf5dfca648ce85ee42e15873c3cd8610ff8e02" +checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf" [[package]] name = "windows_x86_64_gnu" @@ -3361,9 +3366,9 @@ checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e" [[package]] name = "windows_x86_64_gnu" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5eee091590e89cc02ad514ffe3ead9eb6b660aedca2183455434b93546371a03" +checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9" [[package]] name = "windows_x86_64_gnullvm" @@ -3373,9 +3378,9 @@ checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc" [[package]] name = "windows_x86_64_gnullvm" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "77ca79f2451b49fa9e2af39f0747fe999fcda4f5e241b2898624dca97a1f2177" +checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596" [[package]] name = "windows_x86_64_msvc" @@ -3385,15 +3390,15 @@ checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538" [[package]] name = "windows_x86_64_msvc" -version = "0.52.4" +version = "0.52.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32b752e52a2da0ddfbdbcc6fceadfeede4c939ed16d13e648833a61dfb611ed8" +checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0" [[package]] name = "winnow" -version = "0.6.5" +version = "0.6.8" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "dffa400e67ed5a4dd237983829e66475f0a4a26938c4b04c21baede6262215b8" +checksum = "c3c52e9c97a68071b23e836c9380edae937f17b9c4667bd021973efc689f618d" dependencies = [ "memchr", ] @@ -3416,22 +3421,22 @@ checksum = "09041cd90cf85f7f8b2df60c646f853b7f535ce68f85244eb6731cf89fa498ec" [[package]] name = "zerocopy" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "74d4d3961e53fa4c9a25a8637fc2bfaf2595b3d3ae34875568a5cf64787716be" +checksum = "ae87e3fcd617500e5d106f0380cf7b77f3c6092aae37191433159dda23cfb087" dependencies = [ "zerocopy-derive", ] [[package]] name = "zerocopy-derive" -version = "0.7.32" +version = "0.7.34" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ce1b18ccd8e73a9321186f97e46f9f04b778851177567b1975109d26a08d2a6" +checksum = "15e934569e47891f7d9411f1a451d947a60e000ab3bd24fbb970f000387d1b3b" dependencies = [ "proc-macro2", "quote", - "syn 2.0.58", + "syn 2.0.63", ] [[package]] diff --git a/crates/floresta-cli/src/error.rs b/crates/floresta-cli/src/error.rs index 16377ff6..53658c71 100644 --- a/crates/floresta-cli/src/error.rs +++ b/crates/floresta-cli/src/error.rs @@ -1,5 +1,5 @@ -use thiserror::Error; use floresta_cli::rpc_types::Error as RpcError; +use thiserror::Error; #[derive(Error, Debug)] pub enum AppError { @@ -24,4 +24,4 @@ impl From for AppError { fn from(error: RpcError) -> Self { AppError::FlorestaRpcError(error) } -} \ No newline at end of file +} diff --git a/crates/floresta-cli/src/main.rs b/crates/floresta-cli/src/main.rs index a1a83475..32e17d30 100644 --- a/crates/floresta-cli/src/main.rs +++ b/crates/floresta-cli/src/main.rs @@ -1,11 +1,11 @@ use std::fmt::Debug; +use crate::error::AppError; use bitcoin::BlockHash; use bitcoin::Network; use bitcoin::Txid; use clap::Parser; use clap::Subcommand; -use crate::error::AppError; use floresta_cli::reqwest_client::ReqwestClient; use floresta_cli::rpc::FlorestaRPC; diff --git a/crates/floresta-cli/src/rpc_types.rs b/crates/floresta-cli/src/rpc_types.rs index 72b36567..5c3f4b29 100644 --- a/crates/floresta-cli/src/rpc_types.rs +++ b/crates/floresta-cli/src/rpc_types.rs @@ -1,8 +1,6 @@ -use crate::error::AppError; -use std::fmt::Display; - use serde::Deserialize; use serde::Serialize; +use thiserror::Error; #[derive(Debug, Deserialize, Serialize)] pub struct GetBlockchainInfoRes { @@ -249,53 +247,20 @@ pub struct GetBlockRes { pub nextblockhash: Option, } -#[derive(Debug)] +#[derive(Error, Debug)] /// All possible errors returned by the jsonrpc pub enum Error { + #[error(transparent)] /// An error while deserializing our response - Serde(serde_json::Error), + Serde(#[from] serde_json::Error), #[cfg(feature = "with-reqwest")] /// An internal reqwest error - Reqwest(reqwest::Error), + #[error(transparent)] + Reqwest(#[from] reqwest::Error), /// An error internal to our jsonrpc server - Api(serde_json::Value), + #[error(transparent)] + Api(#[from] serde_json::Value), /// The server sent an empty response + #[error("Empty response")] EmtpyResponse, } - -impl From for Error { - fn from(value: serde_json::Error) -> Self { - Error::Serde(value) - } -} - -impl From for Error { - fn from(value: reqwest::Error) -> Self { - Error::Reqwest(value) - } -} - -impl From for AppError { - fn from(error: Error) -> Self { - match error { - Error::Serde(e) => AppError::SerializationError(e), - #[cfg(feature = "with-reqwest")] - Error::Reqwest(e) => AppError::CustomRpcError(e), - Error::Api(e) => AppError::ApiError(format!("{}", e)), - Error::EmtpyResponse => AppError::ApiError("Empty response from server".to_string()), - } - } -} - -impl Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - match self { - Error::Reqwest(e) => write!(f, "reqwest returned an error {e}"), - Error::Api(e) => write!(f, "general jsonrpc error: {e}"), - Error::Serde(e) => write!(f, "error while deserializing the response: {e}"), - Error::EmtpyResponse => write!(f, "got an empty response from server"), - } - } -} - -impl std::error::Error for Error {} diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000..cf925804 --- /dev/null +++ b/flake.lock @@ -0,0 +1,210 @@ +{ + "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1696426674, + "narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "0f9255e01c2351cc7d116c072cb317785dd33b33", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1715542476, + "narHash": "sha256-FF593AtlzQqa8JpzrXyRws4CeKbc5W86o8tHt4nRfIg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "44072e24566c5bcc0b7aa9178a0104f4cfffab19", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1710695816, + "narHash": "sha256-3Eh7fhEID17pv9ZxrPwCLfqXnYP006RKzSs0JptsN84=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "614b4613980a522ba49f0d194531beddbb7220d3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.11", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1710765496, + "narHash": "sha256-p7ryWEeQfMwTB6E0wIUd5V2cFTgq+DRRBz2hYGnJZyA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e367f7a1fb93137af22a3908f00b9a35e2d286a7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils_2", + "gitignore": "gitignore", + "nixpkgs": "nixpkgs_2", + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1715609711, + "narHash": "sha256-/5u29K0c+4jyQ8x7dUIEUWlz2BoTSZWUP2quPwFCE7M=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "c182c876690380f8d3b9557c4609472ebfa1b141", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1715652909, + "narHash": "sha256-aCLEDvzL1j51Rf2mCFOqK1mieMO3pAn5ItCIdr5h2LA=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "1d8fcbbfcfd3476c2665384a46ee9d07ef2b4dd9", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000..a4ace344 --- /dev/null +++ b/flake.nix @@ -0,0 +1,94 @@ +{ + description = "Floresta Dev Flake"; + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; + + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; + + }; + flake-utils.url = "github:numtide/flake-utils"; + + pre-commit-hooks.url = "github:cachix/pre-commit-hooks.nix"; + }; + + outputs = { self, nixpkgs, rust-overlay, flake-utils, pre-commit-hooks, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + overlays = [ (import rust-overlay) ]; + + pkgs = import nixpkgs { + inherit system overlays; + }; + + lib = pkgs.lib; + stdenv = pkgs.stdenv; + + isDarwin = stdenv.isDarwin; + libsDarwin = with pkgs.darwin.apple_sdk.frameworks; lib.optionals isDarwin [ + # Additional darwin specific inputs can be set here + Security + ]; + + msrv = pkgs.rust-bin.stable."1.74.0".default; + + nightly_fmt = pkgs.rustfmt.override { + asNightly = true; + }; + + buildInputs = with pkgs; [ + bashInteractive + msrv + openssl + ] ++ libsDarwin; + nativeBuildInputs = with pkgs; + [ + pkg-config + ]; + in + with pkgs; + { + checks = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + typos.enable = true; + + rustfmt = { + enable = true; + package = nightly_fmt; + }; + + clippy.enable = true; + + nixpkgs-fmt.enable = true; + }; + }; + }; + + devShells.default = + let + # pre-commit-checks + _shellHook = (self.checks.${system}.pre-commit-check.shellHook or ""); + in + mkShell { + inherit buildInputs; + + shellHook = "${ _shellHook}"; + }; + + packages. default = import ./build.nix { + inherit (pkgs) lib rustPlatform; + inherit buildInputs nativeBuildInputs; + rust = msrv; + }; + + flake.overlays.default = (final: prev: { + dead-man-switch = self.packages.${final.system}.default; + }); + }); +} diff --git a/florestad/Cargo.toml b/florestad/Cargo.toml index c02e944f..6206b2ac 100644 --- a/florestad/Cargo.toml +++ b/florestad/Cargo.toml @@ -4,6 +4,7 @@ version = "0.5.1" edition = "2021" [dependencies] +thiserror = "1.0.60" rustreexo = "0.1.0" clap = { version = "4.0.29", features = ["derive"] } sha2 = "^0.10.6" @@ -27,8 +28,6 @@ floresta-electrum = { path = "../crates/floresta-electrum" } floresta-watch-only = { path = "../crates/floresta-watch-only" } floresta-wire = { path = "../crates/floresta-wire" } floresta-compact-filters = { path = "../crates/floresta-compact-filters", optional=true } - -anyhow = "1.0.40" jsonrpc-http-server = { version = "18.0.0", optional = true } jsonrpc-derive = { version = "18.0.0", optional = true } jsonrpc-core = { version = "18.0.0", optional = true } diff --git a/florestad/src/config_file.rs b/florestad/src/config_file.rs index 38e02a4e..6bdd7bf4 100644 --- a/florestad/src/config_file.rs +++ b/florestad/src/config_file.rs @@ -13,7 +13,7 @@ pub struct ConfigFile { } impl ConfigFile { - pub fn from_file(filename: &str) -> Result { + pub fn from_file(filename: &str) -> Result { let file = std::fs::read_to_string(filename)?; Ok(toml::from_str(&file)?) } diff --git a/florestad/src/error.rs b/florestad/src/error.rs index 3127209b..f39621c3 100644 --- a/florestad/src/error.rs +++ b/florestad/src/error.rs @@ -1,12 +1,11 @@ -use crate::slip132; use bitcoin::consensus::encode; #[cfg(feature = "cli-blockchain")] use btcd_rpc::error::UtreexodError; -use floresta_chain::BlockValidationErrors; -use floresta_chain::BlockchainError; use thiserror::Error; + +use crate::slip132; #[derive(Error, Debug)] -pub enum Error { +pub enum FlorestadError { #[cfg(feature = "cli-blockchain")] #[error(transparent)] UtreexodError(#[from] UtreexodError), @@ -17,25 +16,19 @@ pub enum Error { #[error(transparent)] ParseNum(#[from] std::num::ParseIntError), #[error(transparent)] - Rustreexo(#[from] String), - #[error(transparent)] Io(#[from] std::io::Error), #[error(transparent)] - BlockValidation(#[from] BlockValidationErrors), - #[error(transparent)] ScriptValidation(#[from] bitcoin::blockdata::script::Error), #[error(transparent)] - Blockchain(#[from] BlockchainError), - #[error(transparent)] SerdeJson(#[from] serde_json::Error), #[error(transparent)] TomlParsing(#[from] toml::de::Error), #[error(transparent)] - WalletInput(#[from] slip132::Error), - #[error(transparent)] AddressParsing(#[from] bitcoin::address::ParseError), #[error(transparent)] Address(#[from] bitcoin::address::Error), #[error(transparent)] Miniscript(#[from] miniscript::Error), + #[error(transparent)] + Slip132(#[from] slip132::Error), } diff --git a/florestad/src/florestad.rs b/florestad/src/florestad.rs index bb54a340..ad1c5925 100644 --- a/florestad/src/florestad.rs +++ b/florestad/src/florestad.rs @@ -41,6 +41,7 @@ use zmq::ZMQServer; use crate::cli; pub use crate::cli::FilterType; use crate::config_file::ConfigFile; +use crate::error::FlorestadError; use crate::json_rpc; use crate::wallet_input::InitialWalletSetup; @@ -513,12 +514,12 @@ impl Florestad { data } else { match data.unwrap_err() { - crate::error::Error::TomlParsing(e) => { + FlorestadError::TomlParsing(e) => { error!("Error while parsing config file, ignoring it"); debug!("{e}"); ConfigFile::default() } - crate::error::Error::Io(e) => { + FlorestadError::Io(e) => { error!("Error reading config file, ignoring it"); debug!("{e}"); ConfigFile::default() @@ -583,7 +584,7 @@ impl Florestad { addresses: Vec, wallet: &mut AddressCache, network: cli::Network, - ) -> anyhow::Result<()> { + ) -> Result<(), FlorestadError> { if let Some(key) = Self::get_key_from_env() { xpubs.push(key); } @@ -604,7 +605,7 @@ impl Florestad { wallet.cache_address(addresses.script_pubkey()); } info!("Wallet setup completed!"); - anyhow::Ok(()) + Ok(()) } fn get_both_vec(a: Option>, b: Option>) -> Vec { diff --git a/florestad/src/slip132.rs b/florestad/src/slip132.rs index ccc8a630..b2661da6 100644 --- a/florestad/src/slip132.rs +++ b/florestad/src/slip132.rs @@ -14,9 +14,7 @@ extern crate strict_encoding; #[cfg(feature = "serde")] #[macro_use] extern crate serde_crate as serde; - -use std::fmt::Debug; -use std::str::FromStr; +use thiserror::Error; use bitcoin::base58; use bitcoin::bip32; @@ -83,7 +81,7 @@ pub const VERSION_MAGIC_VPUB_MULTISIG: [u8; 4] = [0x02, 0x57, 0x54, 0x83]; pub const VERSION_MAGIC_VPRV_MULTISIG: [u8; 4] = [0x02, 0x57, 0x50, 0x48]; /// Extended public and private key processing errors -#[derive(Clone, PartialEq, Eq, Debug)] +#[derive(Error, Clone, PartialEq, Eq, Debug)] pub enum Error { /// error in BASE58 key encoding. Details: {0} Base58(base58::Error), diff --git a/florestad/src/wallet_input.rs b/florestad/src/wallet_input.rs index 5e53de38..74a971ce 100644 --- a/florestad/src/wallet_input.rs +++ b/florestad/src/wallet_input.rs @@ -7,6 +7,8 @@ use bitcoin::Address; use miniscript::Descriptor; use miniscript::DescriptorPublicKey; +use crate::error::FlorestadError; + pub mod extended_pub_key { use bitcoin::bip32::Xpub; @@ -17,9 +19,7 @@ pub mod extended_pub_key { } } -fn parse_xpubs( - xpubs: &[String], -) -> Result>, crate::error::Error> { +fn parse_xpubs(xpubs: &[String]) -> Result>, FlorestadError> { let mut descriptors = Vec::new(); for key in xpubs { // Parses the descriptor and get an external and change descriptors @@ -48,7 +48,7 @@ impl InitialWalletSetup { addresses: &[String], network: bitcoin::Network, addresses_per_descriptor: u32, - ) -> Result { + ) -> Result { let mut descriptors = parse_xpubs(xpubs)?; descriptors.extend(parse_descriptors(initial_descriptors)?); descriptors.sort(); @@ -83,7 +83,7 @@ impl InitialWalletSetup { pub fn parse_descriptors( descriptors: &[String], -) -> Result>, crate::error::Error> { +) -> Result>, FlorestadError> { let descriptors = descriptors .iter() .map(|descriptor| { From 1f1230ab609a16f6ff45684ebb0f70e8db707f4c Mon Sep 17 00:00:00 2001 From: jaoleal Date: Fri, 17 May 2024 18:36:18 -0300 Subject: [PATCH 4/7] Watch-only module Errors delegated Signed-off-by: jaoleal --- crates/floresta-watch-only/Cargo.toml | 1 + crates/floresta-watch-only/src/kv_database.rs | 60 +++++------------- crates/floresta-watch-only/src/lib.rs | 63 ++++++------------- .../src/memory_database.rs | 40 +++++------- 4 files changed, 50 insertions(+), 114 deletions(-) diff --git a/crates/floresta-watch-only/Cargo.toml b/crates/floresta-watch-only/Cargo.toml index 0992aab4..d5853344 100644 --- a/crates/floresta-watch-only/Cargo.toml +++ b/crates/floresta-watch-only/Cargo.toml @@ -18,6 +18,7 @@ kv = "0.24.0" log = "0.4" thiserror = "1.0" floresta-common = { path = "../floresta-common" } +floresta-errors = { path = "../floresta-errors" } hex = "0.4.3" [features] diff --git a/crates/floresta-watch-only/src/kv_database.rs b/crates/floresta-watch-only/src/kv_database.rs index b973f226..b2d27716 100644 --- a/crates/floresta-watch-only/src/kv_database.rs +++ b/crates/floresta-watch-only/src/kv_database.rs @@ -1,10 +1,9 @@ use bitcoin::consensus::deserialize; -use bitcoin::consensus::encode::Error; use bitcoin::consensus::serialize; use bitcoin::hashes::Hash; use bitcoin::Txid; -use floresta_common::impl_error_from; use floresta_common::prelude::*; +use floresta_errors::watch_only::commom::DbError; use kv::Bucket; use kv::Config; use kv::Store; @@ -14,7 +13,7 @@ use super::Stats; pub struct KvDatabase(Store, Bucket<'static, String, Vec>); impl KvDatabase { - pub fn new(datadir: String) -> Result { + pub fn new(datadir: String) -> Result { // Configure the database let cfg = Config::new(datadir); @@ -24,37 +23,8 @@ impl KvDatabase { Ok(KvDatabase(store, bucket)) } } -#[derive(Debug)] -pub enum KvDatabaseError { - KvError(kv::Error), - SerdeJsonError(serde_json::Error), - WalletNotInitialized, - DeserializeError(Error), - TransactionNotFound, -} -impl_error_from!(KvDatabaseError, serde_json::Error, SerdeJsonError); -impl_error_from!(KvDatabaseError, kv::Error, KvError); -impl_error_from!(KvDatabaseError, Error, DeserializeError); - -impl Display for KvDatabaseError { - fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result { - match self { - KvDatabaseError::KvError(e) => write!(f, "KvError: {}", e), - KvDatabaseError::SerdeJsonError(e) => write!(f, "SerdeJsonError: {}", e), - KvDatabaseError::WalletNotInitialized => write!(f, "WalletNotInitialized"), - KvDatabaseError::DeserializeError(e) => write!(f, "DeserializeError: {}", e), - KvDatabaseError::TransactionNotFound => write!(f, "TransactionNotFound"), - } - } -} - -impl floresta_common::prelude::Error for KvDatabaseError {} - -type Result = floresta_common::prelude::Result; - impl AddressCacheDatabase for KvDatabase { - type Error = KvDatabaseError; - fn load(&self) -> Result> { + fn load(&self) -> Result, DbError> { let mut addresses = Vec::new(); for item in self.1.iter() { let item = item?; @@ -80,20 +50,20 @@ impl AddressCacheDatabase for KvDatabase { fn update(&self, address: &super::CachedAddress) { self.save(address); } - fn get_cache_height(&self) -> Result { + fn get_cache_height(&self) -> Result { let height = self.1.get(&String::from("height"))?; if let Some(height) = height { return Ok(deserialize(&height)?); } - Err(KvDatabaseError::WalletNotInitialized) + Err(DbError::WalletNotInitialized) } - fn set_cache_height(&self, height: u32) -> Result<()> { + fn set_cache_height(&self, height: u32) -> Result<(), DbError> { self.1.set(&String::from("height"), &serialize(&height))?; self.1.flush()?; Ok(()) } - fn desc_save(&self, descriptor: &str) -> Result<()> { + fn desc_save(&self, descriptor: &str) -> Result<(), DbError> { let mut descs = self.descs_get()?; descs.push(String::from(descriptor)); self.1 @@ -103,7 +73,7 @@ impl AddressCacheDatabase for KvDatabase { Ok(()) } - fn descs_get(&self) -> Result> { + fn descs_get(&self) -> Result, DbError> { let res = self.1.get(&String::from("desc"))?; if let Some(res) = res { return Ok(serde_json::de::from_slice(&res)?); @@ -111,16 +81,16 @@ impl AddressCacheDatabase for KvDatabase { Ok(Vec::new()) } - fn get_transaction(&self, txid: &bitcoin::Txid) -> Result { + fn get_transaction(&self, txid: &bitcoin::Txid) -> Result { let store = self.0.bucket::<&[u8], Vec>(Some("transactions"))?; let res = store.get(&txid.as_byte_array().to_vec().as_slice())?; if let Some(res) = res { return Ok(serde_json::de::from_slice(&res)?); } - Err(KvDatabaseError::TransactionNotFound) + Err(DbError::TransactionNotFound) } - fn save_transaction(&self, tx: &super::CachedTransaction) -> Result<()> { + fn save_transaction(&self, tx: &super::CachedTransaction) -> Result<(), DbError> { let store = self.0.bucket::<&[u8], Vec>(Some("transactions"))?; let ser_tx = serde_json::to_vec(&tx)?; store.set(&tx.tx.txid().as_byte_array().to_vec().as_slice(), &ser_tx)?; @@ -129,16 +99,16 @@ impl AddressCacheDatabase for KvDatabase { Ok(()) } - fn get_stats(&self) -> Result { + fn get_stats(&self) -> Result { let store = self.0.bucket::<&[u8], Vec>(Some("stats"))?; let res = store.get(&String::from("stats").as_bytes())?; if let Some(res) = res { return Ok(serde_json::de::from_slice(&res)?); } - Err(KvDatabaseError::TransactionNotFound) + Err(DbError::TransactionNotFound) } - fn save_stats(&self, stats: &Stats) -> Result<()> { + fn save_stats(&self, stats: &Stats) -> Result<(), DbError> { let store = self.0.bucket::<&[u8], Vec>(Some("stats"))?; let ser_stats = serde_json::to_vec(&stats)?; store.set(&String::from("stats").as_bytes(), &ser_stats)?; @@ -147,7 +117,7 @@ impl AddressCacheDatabase for KvDatabase { Ok(()) } - fn list_transactions(&self) -> Result> { + fn list_transactions(&self) -> Result, DbError> { let mut transactions = Vec::new(); let store = self.0.bucket::<&[u8], Vec>(Some("transactions"))?; diff --git a/crates/floresta-watch-only/src/lib.rs b/crates/floresta-watch-only/src/lib.rs index 87262e6d..72d5aefc 100644 --- a/crates/floresta-watch-only/src/lib.rs +++ b/crates/floresta-watch-only/src/lib.rs @@ -2,6 +2,7 @@ use core::cmp::Ordering; use core::fmt::Debug; + use bitcoin::hashes::sha256; use bitcoin::ScriptBuf; use floresta_common::get_spk_hash; @@ -24,38 +25,11 @@ use bitcoin::OutPoint; use bitcoin::Transaction; use bitcoin::TxOut; use floresta_common::prelude::*; +use floresta_errors::watch_only::commom::DbError; +use floresta_errors::watch_only::commom::WatchOnlyError; use merkle::MerkleProof; use serde::Deserialize; use serde::Serialize; - -#[derive(Debug)] -pub enum WatchOnlyError { - WalletNotInitialized, - TransactionNotFound, - DatabaseError(DatabaseError), -} -impl Display for WatchOnlyError { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - match self { - WatchOnlyError::WalletNotInitialized => { - write!(f, "Wallet isn't initialized") - } - WatchOnlyError::TransactionNotFound => { - write!(f, "Transaction not found") - } - WatchOnlyError::DatabaseError(e) => { - write!(f, "Database error: {:?}", e) - } - } - } -} -impl From for WatchOnlyError { - fn from(e: DatabaseError) -> Self { - WatchOnlyError::DatabaseError(e) - } -} -impl floresta_common::prelude::Error for WatchOnlyError {} - /// Every address contains zero or more associated transactions, this struct defines what /// data we store for those. #[derive(Debug, Clone, Eq, Serialize, Deserialize)] @@ -121,33 +95,32 @@ pub struct Stats { } /// Public trait defining a common interface for databases to be used with our cache pub trait AddressCacheDatabase { - type Error: fmt::Debug + Send + Sync + 'static; /// Saves a new address to the database. If the address already exists, `update` should /// be used instead fn save(&self, address: &CachedAddress); /// Loads all addresses we have cached so far - fn load(&self) -> Result, Self::Error>; + fn load(&self) -> Result, DbError>; /// Loads the data associated with our watch-only wallet. - fn get_stats(&self) -> Result; + fn get_stats(&self) -> Result; /// Saves the data associated with our watch-only wallet. - fn save_stats(&self, stats: &Stats) -> Result<(), Self::Error>; + fn save_stats(&self, stats: &Stats) -> Result<(), DbError>; /// Updates an address, probably because a new transaction arrived fn update(&self, address: &CachedAddress); /// TODO: Maybe turn this into another db /// Returns the height of the last block we filtered - fn get_cache_height(&self) -> Result; + fn get_cache_height(&self) -> Result; /// Saves the height of the last block we filtered - fn set_cache_height(&self, height: u32) -> Result<(), Self::Error>; + fn set_cache_height(&self, height: u32) -> Result<(), DbError>; /// Saves the descriptor of associated cache - fn desc_save(&self, descriptor: &str) -> Result<(), Self::Error>; + fn desc_save(&self, descriptor: &str) -> Result<(), DbError>; /// Get associated descriptors - fn descs_get(&self) -> Result, Self::Error>; + fn descs_get(&self) -> Result, DbError>; /// Get a transaction from the database - fn get_transaction(&self, txid: &Txid) -> Result; + fn get_transaction(&self, txid: &Txid) -> Result; /// Saves a transaction to the database - fn save_transaction(&self, tx: &CachedTransaction) -> Result<(), Self::Error>; + fn save_transaction(&self, tx: &CachedTransaction) -> Result<(), DbError>; /// Returns all transaction we have cached so far - fn list_transactions(&self) -> Result, Self::Error>; + fn list_transactions(&self) -> Result, DbError>; } /// Holds all addresses and associated transactions. We need a database with some basic /// methods, to store all data @@ -361,21 +334,21 @@ impl AddressCache { } /// Setup is the first command that should be executed. In a new cache. It sets our wallet's /// state, like the height we should start scanning and the wallet's descriptor. - pub fn setup(&self) -> Result<(), WatchOnlyError> { + pub fn setup(&self) -> Result<(), WatchOnlyError>{ if self.database.descs_get().is_err() { self.database.set_cache_height(0)?; } Ok(()) } /// Tells whether or not a descriptor is already cached - pub fn is_cached(&self, desc: &String) -> Result> { + pub fn is_cached(&self, desc: &String) -> Result { let known_descs = self.database.descs_get()?; Ok(known_descs.contains(desc)) } - pub fn push_descriptor(&self, descriptor: &str) -> Result<(), WatchOnlyError> { + pub fn push_descriptor(&self, descriptor: &str) -> Result<(), WatchOnlyError> { Ok(self.database.desc_save(descriptor)?) } - fn derive_addresses(&mut self) -> Result<(), WatchOnlyError> { + fn derive_addresses(&mut self) -> Result<(), WatchOnlyError> { let mut stats = self.get_stats(); let descriptors = self.database.descs_get()?; let descriptors = parse_descriptors(&descriptors).expect("We validate those descriptors"); @@ -401,7 +374,7 @@ impl AddressCache { } } } - pub fn find_unconfirmed(&self) -> Result, WatchOnlyError> { + pub fn find_unconfirmed(&self) -> Result, WatchOnlyError> { let transactions = self.database.list_transactions()?; let mut unconfirmed = Vec::new(); diff --git a/crates/floresta-watch-only/src/memory_database.rs b/crates/floresta-watch-only/src/memory_database.rs index f2b78d85..be2f1e3a 100644 --- a/crates/floresta-watch-only/src/memory_database.rs +++ b/crates/floresta-watch-only/src/memory_database.rs @@ -7,6 +7,7 @@ use bitcoin::hashes::sha256; use bitcoin::Txid; use floresta_common::prelude::sync::RwLock; use floresta_common::prelude::*; +use floresta_errors::watch_only::commom::DbError; use super::AddressCacheDatabase; use super::CachedAddress; @@ -20,28 +21,20 @@ struct Inner { height: u32, descriptors: Vec, } - -#[derive(Debug)] -pub enum MemoryDatabaseError { - PoisonedLock, -} #[derive(Debug, Default)] pub struct MemoryDatabase { inner: RwLock, } - -type Result = floresta_common::prelude::Result; - impl MemoryDatabase { - fn get_inner(&self) -> Result> { + fn get_inner(&self) -> Result, DbError> { self.inner .read() - .map_err(|_| MemoryDatabaseError::PoisonedLock) + .map_err(|_| DbError::PoisonedLock) } - fn get_inner_mut(&self) -> Result> { + fn get_inner_mut(&self) -> Result, DbError> { self.inner .write() - .map_err(|_| MemoryDatabaseError::PoisonedLock) + .map_err(|_| DbError::PoisonedLock) } pub fn new() -> MemoryDatabase { MemoryDatabase { @@ -50,7 +43,6 @@ impl MemoryDatabase { } } impl AddressCacheDatabase for MemoryDatabase { - type Error = MemoryDatabaseError; fn save(&self, address: &CachedAddress) { self.get_inner_mut() .map(|mut inner| { @@ -61,15 +53,15 @@ impl AddressCacheDatabase for MemoryDatabase { .unwrap(); } - fn load(&self) -> Result> { + fn load(&self) -> Result, DbError> { Ok(self.get_inner()?.addresses.values().cloned().collect()) } - fn get_stats(&self) -> Result { + fn get_stats(&self) -> Result { Ok(self.get_inner()?.stats.to_owned()) } - fn save_stats(&self, stats: &super::Stats) -> Result<()> { + fn save_stats(&self, stats: &super::Stats) -> Result<(), DbError> { self.get_inner_mut().map(|mut inner| { inner.stats.clone_from(stats); })?; @@ -87,40 +79,40 @@ impl AddressCacheDatabase for MemoryDatabase { .unwrap(); } - fn get_cache_height(&self) -> Result { + fn get_cache_height(&self) -> Result { Ok(self.get_inner()?.height) } - fn set_cache_height(&self, height: u32) -> Result<()> { + fn set_cache_height(&self, height: u32) -> Result<(), DbError> { self.get_inner_mut()?.height = height; Ok(()) } - fn desc_save(&self, descriptor: &str) -> Result<()> { + fn desc_save(&self, descriptor: &str) -> Result<(), DbError> { self.get_inner_mut().map(|mut inner| { inner.descriptors.push(descriptor.into()); }) } - fn descs_get(&self) -> Result> { + fn descs_get(&self) -> Result, DbError> { Ok(self.get_inner()?.descriptors.to_owned()) } - fn get_transaction(&self, txid: &bitcoin::Txid) -> Result { + fn get_transaction(&self, txid: &bitcoin::Txid) -> Result { if let Some(tx) = self.get_inner()?.transactions.get(txid) { return Ok(tx.clone()); } - Err(MemoryDatabaseError::PoisonedLock) + Err(DbError::PoisonedLock) } - fn save_transaction(&self, tx: &super::CachedTransaction) -> Result<()> { + fn save_transaction(&self, tx: &super::CachedTransaction) -> Result<(), DbError> { self.get_inner_mut()? .transactions .insert(tx.hash, tx.to_owned()); Ok(()) } - fn list_transactions(&self) -> Result> { + fn list_transactions(&self) -> Result, DbError> { Ok(self.get_inner()?.transactions.keys().copied().collect()) } } From 7a84760378759e211952c714eba3d09df6f3c392 Mon Sep 17 00:00:00 2001 From: jaoleal Date: Fri, 17 May 2024 18:37:03 -0300 Subject: [PATCH 5/7] Included Floresta-errors Crate Signed-off-by: jaoleal --- Cargo.lock | 15 ++++++++++++++- Cargo.toml | 1 + 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/Cargo.lock b/Cargo.lock index b8cef73d..6b702836 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -974,12 +974,25 @@ dependencies = [ "toml 0.5.11", ] +[[package]] +name = "floresta-errors" +version = "0.1.0" +dependencies = [ + "bitcoin 0.31.0", + "kv", + "miniscript 11.0.0", + "serde_json", + "thiserror", + "toml 0.5.11", +] + [[package]] name = "floresta-watch-only" version = "0.1.0" dependencies = [ "bitcoin 0.31.0", "floresta-common", + "floresta-errors", "hex", "kv", "log", @@ -1025,6 +1038,7 @@ dependencies = [ "floresta-common", "floresta-compact-filters", "floresta-electrum", + "floresta-errors", "floresta-watch-only", "floresta-wire", "futures 0.3.30", @@ -1042,7 +1056,6 @@ dependencies = [ "serde", "serde_json", "sha2", - "thiserror", "toml 0.5.11", "zmq", ] diff --git a/Cargo.toml b/Cargo.toml index 5e8616a1..76ccc2d6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ resolver = "2" members = [ "florestad", "crates/floresta", + "crates/floresta-errors", "crates/floresta-chain", "crates/floresta-cli", "crates/floresta-common", From d01e5b827bc7ea4a3e0a72ae083f64929dd8c13e Mon Sep 17 00:00:00 2001 From: jaoleal Date: Fri, 17 May 2024 18:37:22 -0300 Subject: [PATCH 6/7] Floresta errors module Signed-off-by: jaoleal --- crates/floresta-errors/Cargo.toml | 21 ++++++++ .../floresta-errors/src/florestad/commom.rs | 37 +++++++++++++ crates/floresta-errors/src/florestad/mod.rs | 2 + .../floresta-errors/src/florestad/slip123.rs | 54 +++++++++++++++++++ crates/floresta-errors/src/lib.rs | 2 + .../floresta-errors/src/watch_only/commom.rs | 28 ++++++++++ crates/floresta-errors/src/watch_only/mod.rs | 1 + 7 files changed, 145 insertions(+) create mode 100644 crates/floresta-errors/Cargo.toml create mode 100644 crates/floresta-errors/src/florestad/commom.rs create mode 100644 crates/floresta-errors/src/florestad/mod.rs create mode 100644 crates/floresta-errors/src/florestad/slip123.rs create mode 100644 crates/floresta-errors/src/lib.rs create mode 100644 crates/floresta-errors/src/watch_only/commom.rs create mode 100644 crates/floresta-errors/src/watch_only/mod.rs diff --git a/crates/floresta-errors/Cargo.toml b/crates/floresta-errors/Cargo.toml new file mode 100644 index 00000000..9801e5f6 --- /dev/null +++ b/crates/floresta-errors/Cargo.toml @@ -0,0 +1,21 @@ +[package] +name = "floresta-errors" +version = "0.1.0" +edition = "2021" +authors = ["Joao Leal "] +description = """ + A lib including all floresta's errors +""" +repository = "https://github.com/Davidson-Souza/Floresta" +license = "MIT" +readme = "README.md" +keywords = ["bitcoin", "utreexo", "node", "blockchain", "rust"] +categories = ["bitcoin", "blockchain", "node"] + +[dependencies] +kv = "0.24.0" +bitcoin = { version = "0.31", features = ["std"] } +thiserror = "1.0.60" +serde_json = "1.0" +miniscript = "11" +toml = "0.5.10" \ No newline at end of file diff --git a/crates/floresta-errors/src/florestad/commom.rs b/crates/floresta-errors/src/florestad/commom.rs new file mode 100644 index 00000000..2729f95e --- /dev/null +++ b/crates/floresta-errors/src/florestad/commom.rs @@ -0,0 +1,37 @@ +use thiserror::Error; +use bitcoin::consensus::encode; +#[cfg(feature = "cli-blockchain")] +use btcd_rpc::error::UtreexodError; + +use super::slip123::Slip32Errors; + + + +#[derive(Error, Debug)] +pub enum FlorestadError { + #[cfg(feature = "cli-blockchain")] + #[error(transparent)] + UtreexodError(#[from] UtreexodError), + #[error(transparent)] + Encode(#[from] encode::Error), + #[error(transparent)] + Db(#[from] kv::Error), + #[error(transparent)] + ParseNum(#[from] std::num::ParseIntError), + #[error(transparent)] + Io(#[from] std::io::Error), + #[error(transparent)] + ScriptValidation(#[from] bitcoin::blockdata::script::Error), + #[error(transparent)] + SerdeJson(#[from] serde_json::Error), + #[error(transparent)] + TomlParsing(#[from] toml::de::Error), + #[error(transparent)] + AddressParsing(#[from] bitcoin::address::ParseError), + #[error(transparent)] + Address(#[from] bitcoin::address::Error), + #[error(transparent)] + Miniscript(#[from] miniscript::Error), + #[error(transparent)] + Slip132(#[from] Slip32Errors), +} diff --git a/crates/floresta-errors/src/florestad/mod.rs b/crates/floresta-errors/src/florestad/mod.rs new file mode 100644 index 00000000..856a92c2 --- /dev/null +++ b/crates/floresta-errors/src/florestad/mod.rs @@ -0,0 +1,2 @@ +pub mod commom; +pub mod slip123; \ No newline at end of file diff --git a/crates/floresta-errors/src/florestad/slip123.rs b/crates/floresta-errors/src/florestad/slip123.rs new file mode 100644 index 00000000..db594742 --- /dev/null +++ b/crates/floresta-errors/src/florestad/slip123.rs @@ -0,0 +1,54 @@ +use bitcoin::base58; +use thiserror::Error; + +#[derive(Error, Clone, PartialEq, Eq, Debug)] +pub enum Slip32Errors { + /// error in BASE58 key encoding. Details: {0} + #[error(transparent)] + Base58(#[from] base58::Error), + + /// error in hex key encoding. Details: {0} + #[error(transparent)] + Hex(#[from] bitcoin::hashes::hex::HexToArrayError), + + /// pk->pk derivation was attempted on a hardened key. + #[error("cannot derive a hardened key from a hardened key")] + CannotDeriveFromHardenedKey, + + /// child number {0} is out of range. + #[error("child number {0} is out of range")] + InvalidChildNumber(u32), + + /// invalid child number format. + #[error("invalid child number format")] + InvalidChildNumberFormat, + + /// invalid derivation path format. + #[error("invalid derivation path format")] + InvalidDerivationPathFormat, + + /// unknown version magic bytes {0:#06X?} + #[error("unknown version magic bytes {0:#06X?}")] + UnknownVersion([u8; 4]), + + /// encoded extended key data has wrong length {0} + #[error("encoded extended key data has wrong length {0}")] + WrongExtendedKeyLength(usize), + + /// unrecognized or unsupported extended key prefix (please check SLIP 32 + /// for possible values) + #[error("unrecognized or unsupported extended key prefix")] + UnknownSlip32Prefix, + /// Unknown string representation of KeyApplication enum + #[error("invalid key data {0}")] + UnknownKeyApplicationError(String), + // failure in rust bitcoin library [docstring] + // Todo: remake this error... + // a fatal error should not carry any information about the internal state of the library + //#[error()] + //InternalFailure, + #[error(transparent)] + Bip32(#[from] bitcoin::bip32::Error), + //#[error(transparent)] + //WOError(#[from] WatchOnlyError), +} \ No newline at end of file diff --git a/crates/floresta-errors/src/lib.rs b/crates/floresta-errors/src/lib.rs new file mode 100644 index 00000000..44f8ce25 --- /dev/null +++ b/crates/floresta-errors/src/lib.rs @@ -0,0 +1,2 @@ +pub mod florestad; +pub mod watch_only; \ No newline at end of file diff --git a/crates/floresta-errors/src/watch_only/commom.rs b/crates/floresta-errors/src/watch_only/commom.rs new file mode 100644 index 00000000..7ff10942 --- /dev/null +++ b/crates/floresta-errors/src/watch_only/commom.rs @@ -0,0 +1,28 @@ +use thiserror::Error; +use bitcoin::{address::error, consensus::encode::Error as BitcoinEncodeError}; + +#[derive(Error, Debug)] +pub enum WatchOnlyError { + #[error("Wallet not initialized")] + WalletNotInitialized, + #[error("Transaction not found")] + TransactionNotFound, + #[error(transparent)] + DbError(#[from] DbError), + +} +#[derive(Error, Debug)] +pub enum DbError{ + #[error("Poisoned lock")] + PoisonedLock, + #[error(transparent)] + KvError(#[from] kv::Error), + #[error(transparent)] + SerdeJsonError(#[from] serde_json::Error), + #[error("WalletNotInitialized")] + WalletNotInitialized, + #[error(transparent)] + DeserializeError(#[from] BitcoinEncodeError), + #[error("TransactionNotFound")] + TransactionNotFound, +} \ No newline at end of file diff --git a/crates/floresta-errors/src/watch_only/mod.rs b/crates/floresta-errors/src/watch_only/mod.rs new file mode 100644 index 00000000..eada7a28 --- /dev/null +++ b/crates/floresta-errors/src/watch_only/mod.rs @@ -0,0 +1 @@ +pub mod commom; \ No newline at end of file From 55977a169a4584965c8baabcc9c18a9479b99346 Mon Sep 17 00:00:00 2001 From: jaoleal Date: Fri, 17 May 2024 18:55:50 -0300 Subject: [PATCH 7/7] Florestad errors to Floresta-errors::FLorestad::commom Signed-off-by: jaoleal --- florestad/Cargo.toml | 2 +- florestad/src/config_file.rs | 3 +- florestad/src/error.rs | 34 --------------- florestad/src/florestad.rs | 5 +-- florestad/src/lib.rs | 1 - florestad/src/main.rs | 1 - florestad/src/slip132.rs | 78 ++++------------------------------- florestad/src/wallet_input.rs | 6 ++- 8 files changed, 18 insertions(+), 112 deletions(-) delete mode 100644 florestad/src/error.rs diff --git a/florestad/Cargo.toml b/florestad/Cargo.toml index 6206b2ac..c5ed7164 100644 --- a/florestad/Cargo.toml +++ b/florestad/Cargo.toml @@ -4,7 +4,6 @@ version = "0.5.1" edition = "2021" [dependencies] -thiserror = "1.0.60" rustreexo = "0.1.0" clap = { version = "4.0.29", features = ["derive"] } sha2 = "^0.10.6" @@ -22,6 +21,7 @@ bitcoin = { version = "0.31", features = ["serde", "std", "bitcoinconsensus"] } ctrlc = "3.2.5" fern = { version = "0.6", features = ["colored"] } chrono = "0.4.19" +floresta-errors = { path = "../crates/floresta-errors"} floresta-chain = { path = "../crates/floresta-chain" } floresta-common = { path = "../crates/floresta-common" } floresta-electrum = { path = "../crates/floresta-electrum" } diff --git a/florestad/src/config_file.rs b/florestad/src/config_file.rs index 6bdd7bf4..aaa89b28 100644 --- a/florestad/src/config_file.rs +++ b/florestad/src/config_file.rs @@ -1,4 +1,5 @@ use serde::Deserialize; +use floresta_errors::florestad::commom::FlorestadError; #[derive(Default, Debug, Deserialize)] pub struct Wallet { @@ -13,7 +14,7 @@ pub struct ConfigFile { } impl ConfigFile { - pub fn from_file(filename: &str) -> Result { + pub fn from_file(filename: &str) -> Result { let file = std::fs::read_to_string(filename)?; Ok(toml::from_str(&file)?) } diff --git a/florestad/src/error.rs b/florestad/src/error.rs deleted file mode 100644 index f39621c3..00000000 --- a/florestad/src/error.rs +++ /dev/null @@ -1,34 +0,0 @@ -use bitcoin::consensus::encode; -#[cfg(feature = "cli-blockchain")] -use btcd_rpc::error::UtreexodError; -use thiserror::Error; - -use crate::slip132; -#[derive(Error, Debug)] -pub enum FlorestadError { - #[cfg(feature = "cli-blockchain")] - #[error(transparent)] - UtreexodError(#[from] UtreexodError), - #[error(transparent)] - Encode(#[from] encode::Error), - #[error(transparent)] - Db(#[from] kv::Error), - #[error(transparent)] - ParseNum(#[from] std::num::ParseIntError), - #[error(transparent)] - Io(#[from] std::io::Error), - #[error(transparent)] - ScriptValidation(#[from] bitcoin::blockdata::script::Error), - #[error(transparent)] - SerdeJson(#[from] serde_json::Error), - #[error(transparent)] - TomlParsing(#[from] toml::de::Error), - #[error(transparent)] - AddressParsing(#[from] bitcoin::address::ParseError), - #[error(transparent)] - Address(#[from] bitcoin::address::Error), - #[error(transparent)] - Miniscript(#[from] miniscript::Error), - #[error(transparent)] - Slip132(#[from] slip132::Error), -} diff --git a/florestad/src/florestad.rs b/florestad/src/florestad.rs index ad1c5925..6be6a3fb 100644 --- a/florestad/src/florestad.rs +++ b/florestad/src/florestad.rs @@ -5,7 +5,6 @@ use std::str::FromStr; use std::sync::Arc; use std::sync::Mutex; use std::sync::OnceLock; - use async_std::sync::RwLock; use async_std::task; use async_std::task::block_on; @@ -23,7 +22,7 @@ use floresta_compact_filters::kv_filter_database::KvFilterStore; use floresta_compact_filters::FilterBackendBuilder; use floresta_electrum::electrum_protocol::client_accept_loop; use floresta_electrum::electrum_protocol::ElectrumServer; -use floresta_watch_only::kv_database::KvDatabase; +use z::kv_database::KvDatabase; use floresta_watch_only::AddressCache; use floresta_watch_only::AddressCacheDatabase; use floresta_wire::address_man::LocalAddress; @@ -41,7 +40,7 @@ use zmq::ZMQServer; use crate::cli; pub use crate::cli::FilterType; use crate::config_file::ConfigFile; -use crate::error::FlorestadError; +use floresta_errors::florestad::commom::FlorestadError; use crate::json_rpc; use crate::wallet_input::InitialWalletSetup; diff --git a/florestad/src/lib.rs b/florestad/src/lib.rs index f8799cd4..2b10e61f 100644 --- a/florestad/src/lib.rs +++ b/florestad/src/lib.rs @@ -1,6 +1,5 @@ mod cli; mod config_file; -mod error; mod florestad; #[cfg(feature = "json-rpc")] mod json_rpc; diff --git a/florestad/src/main.rs b/florestad/src/main.rs index 5b98ed83..61446f09 100644 --- a/florestad/src/main.rs +++ b/florestad/src/main.rs @@ -19,7 +19,6 @@ mod cli; mod config_file; -mod error; mod florestad; #[cfg(feature = "json-rpc")] mod json_rpc; diff --git a/florestad/src/slip132.rs b/florestad/src/slip132.rs index b2661da6..739d1dc7 100644 --- a/florestad/src/slip132.rs +++ b/florestad/src/slip132.rs @@ -14,8 +14,6 @@ extern crate strict_encoding; #[cfg(feature = "serde")] #[macro_use] extern crate serde_crate as serde; -use thiserror::Error; - use bitcoin::base58; use bitcoin::bip32; use bitcoin::bip32::Xpriv; @@ -81,39 +79,7 @@ pub const VERSION_MAGIC_VPUB_MULTISIG: [u8; 4] = [0x02, 0x57, 0x54, 0x83]; pub const VERSION_MAGIC_VPRV_MULTISIG: [u8; 4] = [0x02, 0x57, 0x50, 0x48]; /// Extended public and private key processing errors -#[derive(Error, Clone, PartialEq, Eq, Debug)] -pub enum Error { - /// error in BASE58 key encoding. Details: {0} - Base58(base58::Error), - - /// error in hex key encoding. Details: {0} - Hex(bitcoin::hashes::hex::HexToArrayError), - - /// pk->pk derivation was attempted on a hardened key. - CannotDeriveFromHardenedKey, - - /// child number {0} is out of range. - InvalidChildNumber(u32), - - /// invalid child number format. - InvalidChildNumberFormat, - /// invalid derivation path format. - InvalidDerivationPathFormat, - - /// unknown version magic bytes {0:#06X?} - UnknownVersion([u8; 4]), - - /// encoded extended key data has wrong length {0} - WrongExtendedKeyLength(usize), - - /// unrecognized or unsupported extended key prefix (please check SLIP 32 - /// for possible values) - UnknownSlip32Prefix, - - /// failure in rust bitcoin library - InternalFailure, -} #[cfg(feature = "strict_encoding")] impl strict_encoding::StrictEncode for Error { @@ -129,28 +95,6 @@ impl strict_encoding::StrictDecode for Error { } } -impl From for Error { - fn from(err: bip32::Error) -> Self { - match err { - bip32::Error::CannotDeriveFromHardenedKey => Error::CannotDeriveFromHardenedKey, - bip32::Error::InvalidChildNumber(no) => Error::InvalidChildNumber(no), - bip32::Error::InvalidChildNumberFormat => Error::InvalidChildNumberFormat, - bip32::Error::InvalidDerivationPathFormat => Error::InvalidDerivationPathFormat, - bip32::Error::Secp256k1(_) => Error::InternalFailure, - bip32::Error::UnknownVersion(ver) => Error::UnknownVersion(ver), - bip32::Error::WrongExtendedKeyLength(len) => Error::WrongExtendedKeyLength(len), - bip32::Error::Base58(err) => Error::Base58(err), - bip32::Error::Hex(err) => Error::Hex(err), - _ => Error::InternalFailure, - } - } -} - -impl From for Error { - fn from(err: base58::Error) -> Self { - Error::Base58(err) - } -} /// Structure holding 4 version bytes with magical numbers representing /// different versions of extended public and private keys according to BIP-32. @@ -217,14 +161,10 @@ pub enum KeyApplication { #[cfg_attr(feature = "serde", serde(rename = "bip48-nested"))] NestedMultisig, } - -/// Unknown string representation of [`KeyApplication`] enum -#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Debug)] -pub struct UnknownKeyApplicationError; - +use floresta_errors::florestad::slip123::{Slip32Errors, Slip32Errors::UnknownKeyApplicationError}; +use std::str::FromStr; impl FromStr for KeyApplication { - type Err = UnknownKeyApplicationError; - + type Err = Slip32Errors; fn from_str(s: &str) -> Result { Ok(match s.to_lowercase().as_str() { "bip44" => KeyApplication::Hashed, @@ -232,7 +172,7 @@ impl FromStr for KeyApplication { "bip48-native" => KeyApplication::SegWitMultisig, "bip49" => KeyApplication::Nested, "bip48-nested" => KeyApplication::NestedMultisig, - _ => return Err(UnknownKeyApplicationError), + _ => return Err(UnknownKeyApplicationError(s.to_string())), }) } } @@ -240,13 +180,13 @@ impl FromStr for KeyApplication { /// Trait for building standard BIP32 extended keys from SLIP132 variant. pub trait FromSlip132 { /// Constructs standard BIP32 extended key from SLIP132 string. - fn from_slip132_str(s: &str) -> Result + fn from_slip132_str(s: &str) -> Result where Self: Sized; } impl FromSlip132 for Xpub { - fn from_slip132_str(s: &str) -> Result { + fn from_slip132_str(s: &str) -> Result { let mut data = base58::decode_check(s)?; let mut prefix = [0u8; 4]; @@ -264,7 +204,7 @@ impl FromSlip132 for Xpub { | VERSION_MAGIC_UPUB_MULTISIG | VERSION_MAGIC_VPUB_MULTISIG => VERSION_MAGIC_TPUB, - _ => return Err(Error::UnknownSlip32Prefix), + _ => return Err(Slip32Errors::UnknownSlip32Prefix), }; data[0..4].copy_from_slice(&slice); @@ -275,7 +215,7 @@ impl FromSlip132 for Xpub { } impl FromSlip132 for Xpriv { - fn from_slip132_str(s: &str) -> Result { + fn from_slip132_str(s: &str) -> Result { let mut data = base58::decode_check(s)?; let mut prefix = [0u8; 4]; @@ -293,7 +233,7 @@ impl FromSlip132 for Xpriv { | VERSION_MAGIC_UPRV_MULTISIG | VERSION_MAGIC_VPRV_MULTISIG => VERSION_MAGIC_TPRV, - _ => return Err(Error::UnknownSlip32Prefix), + _ => return Err(Slip32Errors::UnknownSlip32Prefix), }; data[0..4].copy_from_slice(&slice); diff --git a/florestad/src/wallet_input.rs b/florestad/src/wallet_input.rs index 74a971ce..546c1e41 100644 --- a/florestad/src/wallet_input.rs +++ b/florestad/src/wallet_input.rs @@ -7,14 +7,16 @@ use bitcoin::Address; use miniscript::Descriptor; use miniscript::DescriptorPublicKey; -use crate::error::FlorestadError; +use floresta_errors::florestad::commom::FlorestadError; + pub mod extended_pub_key { use bitcoin::bip32::Xpub; + use floresta_errors::florestad::slip123::Slip32Errors; use crate::slip132; - pub fn from_str(s: &str) -> Result { + pub fn from_str(s: &str) -> Result { slip132::FromSlip132::from_slip132_str(s) } }