Struct lightning_signer::node::Node [−][src]
pub struct Node { /* fields omitted */ }
Expand description
A signer for one Lightning node.
use lightning_signer::node::{Node, NodeConfig};
use lightning_signer::channel::{ChannelSlot, ChannelBase};
use lightning_signer::persist::{DummyPersister, Persist};
use lightning_signer::util::test_utils::TEST_NODE_CONFIG;
use lightning_signer::util::test_logger::TestLogger;
use lightning_signer::node::SyncLogger;
use std::sync::Arc;
let persister: Arc<dyn Persist> = Arc::new(DummyPersister {});
let seed = [0; 32];
let config = TEST_NODE_CONFIG;
let node = Arc::new(Node::new(config, &seed, &persister, vec![]));
let (channel_id, opt_stub) = node.new_channel(None, None, &node).expect("new channel");
assert!(opt_stub.is_some());
let channel_slot_mutex = node.get_channel(&channel_id).expect("get channel");
let channel_slot = channel_slot_mutex.lock().expect("lock");
match &*channel_slot {
ChannelSlot::Stub(stub) => {
// Do things with the stub, such as readying it or getting the points
let holder_basepoints = stub.get_channel_basepoints();
}
ChannelSlot::Ready(_) => panic!("expected a stub")
}
Implementations
Create a node.
NOTE: you must persist the node yourself if it is new.
pub fn new_extended(
node_config: NodeConfig,
seed: &[u8],
persister: &Arc<dyn Persist>,
allowlist: Vec<Script>,
tracker: ChainTracker<ChainMonitor>,
validator_factory: Box<dyn ValidatorFactory>
) -> Node
pub fn new_extended(
node_config: NodeConfig,
seed: &[u8],
persister: &Arc<dyn Persist>,
allowlist: Vec<Script>,
tracker: ChainTracker<ChainMonitor>,
validator_factory: Box<dyn ValidatorFactory>
) -> Node
Create a node
NOTE: you must persist the node yourself if it is new.
pub fn new_from_persistence(
node_config: NodeConfig,
seed: &[u8],
persister: &Arc<dyn Persist>,
allowlist: Vec<Script>,
tracker: ChainTracker<ChainMonitor>
) -> Node
pub fn new_from_persistence(
node_config: NodeConfig,
seed: &[u8],
persister: &Arc<dyn Persist>,
allowlist: Vec<Script>,
tracker: ChainTracker<ChainMonitor>
) -> Node
Restore a node.
Set the node’s validator factory
Get secret key material as bytes for use in encrypting and decrypting inbound payment data.
This method must return the same value each time it is called.
Get the Mutex protected channel slot
pub fn with_channel_base<F: Sized, T>(
&self,
channel_id: &ChannelId,
f: F
) -> Result<T, Status> where
F: Fn(&mut dyn ChannelBase) -> Result<T, Status>,
pub fn with_channel_base<F: Sized, T>(
&self,
channel_id: &ChannelId,
f: F
) -> Result<T, Status> where
F: Fn(&mut dyn ChannelBase) -> Result<T, Status>,
Execute a function with an existing channel.
The channel may be a stub or a ready channel. An invalid_argument Status will be returned if the channel does not exist.
Execute a function with an existing ready channel.
An invalid_argument Status will be returned if the channel does not exist.
pub fn find_channel_with_funding_outpoint(
&self,
outpoint: &OutPoint
) -> Option<Arc<Mutex<ChannelSlot>>>
pub fn find_channel_with_funding_outpoint(
&self,
outpoint: &OutPoint
) -> Option<Arc<Mutex<ChannelSlot>>>
Get a channel given its funding outpoint, or None if no such channel exists.
Create a new channel, which starts out as a stub.
The initial channel ID may be specified in opt_channel_id
. If the channel
with this ID already exists, the existing stub is returned.
If unspecified, the channel nonce will default to the channel ID.
This function will return an invalid_argument Status if there is an existing channel with this ID and it’s not a compatible stub channel.
Returns the channel ID and the stub.
Restore a node from a persisted NodeEntry.
You can get the NodeEntry from Persist::get_nodes.
The channels are also restored from the persister
.
Restore all nodes from persister
.
The channels of each node are also restored.
Ready a new channel, making it available for use.
This populates fields that are known later in the channel creation flow, such as fields that are supplied by the counterparty and funding outpoint.
channel_id0
- the original channel ID supplied toNode::new_channel
opt_channel_id
- the permanent channel ID
The channel is promoted from a ChannelStub to a Channel. After this call, the channel may be referred to by either ID.
Sign an onchain transaction (funding tx or simple sweeps).
The transaction may fund multiple channels at once. Returns a witness stack for each input. Inputs that are marked as SpendType::Invalid are not signed and get an empty witness stack.
ipaths
- derivation path for the wallet key per inputvalues_sat
- the amount in satoshi per inputspendtypes
- spend type per input, orInvalid
if this input is to be signed by someone else.uniclosekeys
- an optional unilateral close key to use instead of the wallet key. Takes precedence over theipaths
entry. This is used when we are sweeping a unilateral close and funding a channel in a single tx.opaths
- derivation path for change, one per output. Empty for non-change outputs.
Get the node secret key This function will be eliminated once the node key related items are implemented. This includes onion decoding and p2p handshake.
Get shutdown_pubkey to use as PublicKey at channel closure
Get the layer-1 xprv
Get the layer-1 xpub
Sign a node announcement using the node key
Sign a channel update using the node key
Sign an invoice
Sign an invoice
Sign a Lightning message
Get the channels this node knows about. Currently, channels are not pruned once closed, but this will change.
Perform an ECDH operation between the node key and a public key This can be used for onion packet decoding
pub fn spend_spendable_outputs(
&self,
descriptors: &[&SpendableOutputDescriptor],
outputs: Vec<TxOut>,
change_destination_script: Script,
feerate_sat_per_1000_weight: u32,
secp_ctx: &Secp256k1<All>
) -> Result<Transaction, ()>
pub fn spend_spendable_outputs(
&self,
descriptors: &[&SpendableOutputDescriptor],
outputs: Vec<TxOut>,
change_destination_script: Script,
feerate_sat_per_1000_weight: u32,
secp_ctx: &Secp256k1<All>
) -> Result<Transaction, ()>
See MyKeysManager::spend_spendable_outputs
.
For LDK compatibility.
Adds addresses to the node’s current allowlist.
Removes addresses from the node’s current allowlist.
Chain tracker with lock
Trait Implementations
Returns true if script_pubkey is in the node’s allowlist.
True if the wallet can spend the given output with a derived key