Skip to main content

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/// [`rust_decimal::Decimal`] extensions.
28pub mod decimal;
29/// [`dotenvy`] extensions.
30pub mod dotenv;
31/// `DeployEnv`.
32pub mod env;
33/// Bitcoin / Lightning Lexe newtypes which can't go in lexe-ln
34pub mod ln;
35/// Networking utilities.
36pub mod net;
37/// `OrEnvExt` utility trait.
38pub mod or_env;
39/// `Ppm` - parts per million newtype for proportional fee rates.
40pub mod ppm;
41/// Types related to `releases.json`.
42pub mod releases;
43/// Random number generation.
44pub mod rng;
45/// `RootSeed`.
46pub mod root_seed;
47/// Global `Secp256k1` context
48pub mod secp256k1_ctx;
49/// `TimestampMs` and `DisplayMs`.
50pub mod time;
51
52/// Feature-gated test utilities that can be shared across crate boundaries.
53#[cfg(any(test, feature = "test-utils"))]
54pub mod test_utils;
55
56/// Returns the default Lexe data directory (`~/.lexe`).
57pub fn default_lexe_data_dir() -> anyhow::Result<PathBuf> {
58    #[allow(deprecated)] // home_dir is fine for our use case
59    let home = std::env::home_dir()
60        .ok_or_else(|| anyhow!("Could not determine home directory"))?;
61    Ok(home.join(".lexe"))
62}
63
64/// `panic!(..)`s in debug mode, `tracing::error!(..)`s in release mode
65#[macro_export]
66macro_rules! debug_panic_release_log {
67    ($($arg:tt)*) => {
68        if core::cfg!(debug_assertions) {
69            core::panic!($($arg)*);
70        } else {
71            tracing::error!($($arg)*);
72        }
73    };
74}