lexe_common/lib.rs
1//! `lexe-common` contains types and functionality shared between most Lexe
2//! crates.
3
4// Ignore this issue with `proptest_derive::Arbitrary`.
5#![allow(clippy::arc_with_non_send_sync)]
6// `proptest_derive::Arbitrary` issue. This will hard-error for edition 2024 so
7// hopefully it gets fixed soon...
8// See: <https://github.com/proptest-rs/proptest/issues/447>
9#![allow(non_local_definitions)]
10// We don't export our traits currently so auto trait stability is not relevant.
11#![allow(async_fn_in_trait)]
12
13use std::path::PathBuf;
14
15use anyhow::anyhow;
16// Some re-exports to prevent having to re-declare dependencies
17pub use lexe_byte_array::ByteArray;
18pub use ref_cast::RefCast;
19pub use secrecy::{ExposeSecret, Secret};
20
21/// API definitions, errors, clients, and structs sent across the wire.
22pub mod api;
23/// [`tokio::Bytes`](bytes::Bytes) but must contain a string.
24pub mod byte_str;
25/// Application-level constants.
26pub mod constants;
27/// [`dotenvy`] extensions.
28pub mod dotenv;
29/// `DeployEnv`.
30pub mod env;
31/// Bitcoin / Lightning Lexe newtypes which can't go in lexe-ln
32pub mod ln;
33/// Networking utilities.
34pub mod net;
35/// `OrEnvExt` utility trait.
36pub mod or_env;
37/// Types related to `releases.json`.
38pub mod releases;
39/// Random number generation.
40pub mod rng;
41/// `RootSeed`.
42pub mod root_seed;
43/// Global `Secp256k1` context
44pub mod secp256k1_ctx;
45/// `TimestampMs` and `DisplayMs`.
46pub mod time;
47
48/// Feature-gated test utilities that can be shared across crate boundaries.
49#[cfg(any(test, feature = "test-utils"))]
50pub mod test_utils;
51
52/// Returns the default Lexe data directory (`~/.lexe`).
53pub fn default_lexe_data_dir() -> anyhow::Result<PathBuf> {
54 #[allow(deprecated)] // home_dir is fine for our use case
55 let home = std::env::home_dir()
56 .ok_or_else(|| anyhow!("Could not determine home directory"))?;
57 Ok(home.join(".lexe"))
58}
59
60/// `panic!(..)`s in debug mode, `tracing::error!(..)`s in release mode
61#[macro_export]
62macro_rules! debug_panic_release_log {
63 ($($arg:tt)*) => {
64 if core::cfg!(debug_assertions) {
65 core::panic!($($arg)*);
66 } else {
67 tracing::error!($($arg)*);
68 }
69 };
70}