1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
#![crate_name = "lightning_signer"]

//! A policy-enforcing signer for Lightning
//! See [`node::Node`] for the entry point.

#![forbid(unsafe_code)]
#![allow(bare_trait_objects)]
#![allow(ellipsis_inclusive_range_patterns)]
#![warn(broken_intra_doc_links)]
#![warn(missing_docs)]
#![cfg_attr(all(not(feature = "std"), not(test)), no_std)]

#[cfg(not(any(feature = "std", feature = "no-std")))]
compile_error!("at least one of the `std` or `no-std` features must be enabled");

#[cfg(not(feature = "std"))]
extern crate core2;

#[macro_use]
extern crate alloc;
extern crate core;
#[cfg(feature = "std")]
extern crate rand;
#[cfg(feature = "grpc")]
extern crate tonic;

pub use bitcoin;
pub use lightning;

/// Chain tracking and validation
pub mod chain;
/// Various utilities
#[macro_use]
pub mod util;
/// Channel
pub mod channel;
/// Channel on-chain monitor
pub mod monitor;
/// Node
pub mod node;
/// Persistence
pub mod persist;
/// Policy enforcement
pub mod policy;
/// KeysManager
pub mod signer;
/// Transaction parsing and construction
pub mod tx;
/// Layer-1 wallet
pub mod wallet;

#[cfg(not(feature = "std"))]
mod io_extras {
    pub use core2::io::{self, Error, Read, Write};

    /// A writer which will move data into the void.
    pub struct Sink {
        _priv: (),
    }

    /// Creates an instance of a writer which will successfully consume all data.
    pub const fn sink() -> Sink {
        Sink { _priv: () }
    }

    impl core2::io::Write for Sink {
        #[inline]
        fn write(&mut self, buf: &[u8]) -> core2::io::Result<usize> {
            Ok(buf.len())
        }

        #[inline]
        fn flush(&mut self) -> core2::io::Result<()> {
            Ok(())
        }
    }
}

#[cfg(feature = "std")]
mod io_extras {
    pub use std::io::{sink, Error, Read};
}

pub use alloc::collections::BTreeSet as OrderedSet;
pub use alloc::rc::Rc;
pub use alloc::sync::{Arc, Weak};

#[cfg(not(feature = "std"))]
mod nostd;

pub(crate) mod prelude {
    pub use alloc::{boxed::Box, string::String, vec, vec::Vec};
    pub use hashbrown::HashMap as Map;
    pub use hashbrown::HashSet as UnorderedSet;

    pub use alloc::borrow::ToOwned;
    pub use alloc::string::ToString;

    #[cfg(not(feature = "std"))]
    pub use crate::nostd::*;

    #[cfg(feature = "std")]
    pub use std::sync::{Mutex, MutexGuard};

    /// Convenience trait for Send + Sync
    #[cfg(feature = "std")]
    pub trait SendSync: Send + Sync {}
}

pub use prelude::SendSync;

#[cfg(feature = "std")]
mod sync {
    pub use ::std::sync::{Arc, Condvar, Mutex, MutexGuard, RwLock, RwLockReadGuard, Weak};
}

#[cfg(not(feature = "std"))]
#[allow(unused)]
mod sync;

#[cfg(test)]
mod ready_channel_tests;
#[cfg(test)]
mod sign_counterparty_commitment_tests;
#[cfg(test)]
mod sign_counterparty_htlc_sweep_tests;
#[cfg(test)]
mod sign_delayed_sweep_tests;
#[cfg(test)]
mod sign_holder_commitment_tests;
#[cfg(test)]
mod sign_htlc_tx_tests;
#[cfg(test)]
mod sign_justice_sweep_tests;
#[cfg(test)]
mod sign_mutual_close_tests;
#[cfg(test)]
mod sign_onchain_tx_tests;
#[cfg(test)]
mod validate_counterparty_revocation_tests;
#[cfg(test)]
mod validate_holder_commitment_tests;