lightning/util/mod.rs
1// This file is Copyright its original authors, visible in version control
2// history.
3//
4// This file is licensed under the Apache License, Version 2.0 <LICENSE-APACHE
5// or http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your option.
7// You may not use this file except in accordance with one or both of these
8// licenses.
9
10//! Some utility modules live here. See individual sub-modules for more info.
11
12#[macro_use]
13pub(crate) mod fuzz_wrappers;
14
15#[macro_use]
16pub mod ser_macros;
17
18#[cfg(any(test, feature = "_test_utils"))]
19pub mod mut_global;
20
21pub mod anchor_channel_reserves;
22
23pub mod async_poll;
24#[cfg(fuzzing)]
25pub mod base32;
26#[cfg(not(fuzzing))]
27pub(crate) mod base32;
28pub mod errors;
29pub mod message_signing;
30pub mod native_async;
31pub mod persist;
32pub mod scid_utils;
33pub mod ser;
34pub mod sweep;
35pub mod wakers;
36
37pub(crate) mod atomic_counter;
38pub(crate) mod byte_utils;
39pub mod hash_tables;
40pub(crate) mod transaction_utils;
41
42#[cfg(feature = "std")]
43pub(crate) mod time;
44
45pub mod indexed_map;
46
47/// Logging macro utilities.
48#[macro_use]
49pub(crate) mod macro_logger;
50
51// These have to come after macro_logger to build
52pub mod config;
53pub mod logger;
54
55#[cfg(any(test, feature = "_test_utils"))]
56pub mod test_utils;
57
58/// impls of traits that add exra enforcement on the way they're called. Useful for detecting state
59/// machine errors and used in fuzz targets and tests.
60#[cfg(any(test, feature = "_test_utils"))]
61pub mod test_channel_signer;
62
63/// A macro to delegate trait implementations to a field of a struct.
64///
65/// For example:
66/// ```ignore
67/// use lightning::delegate;
68/// delegate!(A, T, inner,
69/// fn b(, c: u64) -> u64,
70/// fn m(mut, d: u64) -> (),
71/// fn o(, ) -> u64,
72/// #[cfg(debug_assertions)]
73/// fn t(,) -> (),
74/// ;
75/// type O = u64,
76/// #[cfg(debug_assertions)]
77/// type T = (),
78/// );
79/// ```
80///
81/// where T is the trait to be implemented, A is the struct
82/// to implement the trait for, and inner is the field of A
83/// to delegate the trait implementation to.
84#[cfg(any(test, feature = "_test_utils"))]
85macro_rules! delegate {
86 ($N: ident, $T: ident, $ref: ident,
87 $($(#[$fpat: meta])? fn $f: ident($($mu: ident)?, $($n: ident: $t: ty),*) -> $r: ty),* $(,)?
88 $(;$($(#[$tpat: meta])? type $TN: ident = $TT: ty),*)? $(,)?
89 ) => {
90 impl $T for $N {
91 $(
92 $(#[$fpat])?
93 fn $f(&$($mu)? self, $($n: $t),*) -> $r {
94 $T::$f(&$($mu)? *self.$ref, $($n),*)
95 }
96 )*
97 $($(
98 $(#[$tpat])?
99 type $TN = $TT;
100 )*)?
101 }
102 };
103}
104
105#[cfg(any(test, feature = "_test_utils"))]
106pub mod dyn_signer;