lexe/lib.rs
1// Use README.md as module docs
2#![doc = include_str!("../README.md")]
3//
4// NOTE: Docs for all stable APIs (i.e. all public items accessible via this
5// crate) must be written for consumption by external users.
6//
7// Preview the public API rustdoc: `$ just docs-build-rustdoc --open`
8//
9// - Internal-facing documentation can still be written for public items, but
10// should be placed in `//` comments, not `///` comments, to avoid being
11// rendered in the public API docs at <rust.lexe.tech>.
12// - `///` comments are still preferred for private, crate-private, and unstable
13// items.
14#![deny(missing_docs)]
15
16// --- Public API --- //
17//
18// All APIs accessible via these public modules must respect semver guarantees.
19
20/// Configuration options for a `LexeWallet`.
21pub mod config;
22/// Types used by the Lexe SDK.
23pub mod types;
24/// `LexeWallet`: the top-level handle to a Lexe wallet.
25pub mod wallet;
26
27/// Returns the default Lexe data directory (`~/.lexe`).
28pub use lexe_common::default_lexe_data_dir;
29
30/// `BlockingLexeWallet`: synchronous wrapper around `LexeWallet`.
31///
32/// Enabled by the `blocking` feature flag.
33#[cfg(feature = "blocking")]
34pub mod blocking_wallet;
35
36/// General-purpose utilities and re-exports.
37pub mod util {
38 pub use lexe_byte_array::ByteArray;
39 pub use lexe_hex::hex;
40}
41
42// Reexport crates and items reachable through the stable public API surface.
43pub use anyhow;
44pub use bip39;
45pub use bitcoin;
46pub use lightning;
47pub use semver;
48
49/// Initialize the Lexe logger with the given default log level.
50///
51/// Example: `lexe::init_logger("info")`
52pub fn init_logger(default_level: &str) {
53 lexe_logger::init_with_default(default_level);
54}
55
56// Reexport additional dependencies that may be useful to SDK consumers.
57pub use serde_json;
58pub use tracing;
59
60// --- Unstable APIs --- //
61
62/// This module ensures all unstable APIs are accessible within the crate, but
63/// not to external users of the crate, unless they enable the `unstable`
64/// feature, in which case they can access it via the re-export below.
65mod unstable {
66 /// A flat file system abstraction.
67 pub mod ffs;
68 /// Local payments database synced from the user node.
69 pub mod payments_db;
70 /// Provision-related utilities.
71 pub mod provision;
72 /// Wallet database.
73 pub mod wallet_db;
74
75 /// The user agent string used for SDK requests to Lexe infrastructure.
76 ///
77 /// Format: `lexe/<sdk_version> node/<latest_node_version>`
78 ///
79 /// Example: `lexe/0.1.0 node/0.8.11`
80 pub static SDK_USER_AGENT: std::sync::LazyLock<&'static str> =
81 std::sync::LazyLock::new(|| {
82 // Get the latest node version.
83 let releases = provision::releases_json();
84 let node_releases =
85 releases.0.get("node").expect("No 'node' in releases.json");
86 let (latest_node_version, _release) =
87 node_releases.last_key_value().expect("No node releases");
88
89 let sdk_with_version = lexe_api::user_agent_to_lexe!();
90 let user_agent =
91 format!("{sdk_with_version} node/{latest_node_version}");
92
93 Box::leak(user_agent.into_boxed_str())
94 });
95}
96
97/// Opt-in to unstable APIs.
98#[cfg(feature = "unstable")]
99pub use unstable::*;