pub struct Node { /* private fields */ }Expand description
The main interface object of LDK Node, wrapping the necessary LDK and BDK functionalities.
Needs to be initialized and instantiated through Builder::build.
Implementations§
source§impl Node
impl Node
sourcepub fn start(&self) -> Result<(), Error>
pub fn start(&self) -> Result<(), Error>
Starts the necessary background tasks, such as handling events coming from user input, LDK/BDK, and the peer-to-peer network.
After this returns, the Node instance can be controlled via the provided API methods in
a thread-safe manner.
sourcepub fn stop(&self) -> Result<(), Error>
pub fn stop(&self) -> Result<(), Error>
Disconnects all peers, stops all running background tasks, and shuts down Node.
After this returns most API methods will return Error::NotRunning.
sourcepub fn next_event(&self) -> Event
pub fn next_event(&self) -> Event
Blocks until the next event is available.
Note: this will always return the same event until handling is confirmed via Node::event_handled.
sourcepub fn event_handled(&self)
pub fn event_handled(&self)
Confirm the last retrieved event handled.
Note: This MUST be called after each event has been handled.
sourcepub fn listening_address(&self) -> Option<&SocketAddr>
pub fn listening_address(&self) -> Option<&SocketAddr>
Returns our own listening address.
sourcepub fn new_funding_address(&self) -> Result<Address, Error>
pub fn new_funding_address(&self) -> Result<Address, Error>
Retrieve a new on-chain/funding address.
sourcepub fn onchain_balance(&self) -> Result<Balance, Error>
pub fn onchain_balance(&self) -> Result<Balance, Error>
Retrieve the current on-chain balance.
sourcepub fn send_to_onchain_address(
&self,
address: &Address,
amount_sats: u64
) -> Result<Txid, Error>
pub fn send_to_onchain_address( &self, address: &Address, amount_sats: u64 ) -> Result<Txid, Error>
Send an on-chain payment to the given address.
sourcepub fn send_all_to_onchain_address(
&self,
address: &Address
) -> Result<Txid, Error>
pub fn send_all_to_onchain_address( &self, address: &Address ) -> Result<Txid, Error>
Send an on-chain payment to the given address, draining all the available funds.
sourcepub fn list_channels(&self) -> Vec<ChannelDetails>
pub fn list_channels(&self) -> Vec<ChannelDetails>
Retrieve a list of known channels.
sourcepub fn connect(
&self,
node_id: PublicKey,
address: SocketAddr,
permanently: bool
) -> Result<(), Error>
pub fn connect( &self, node_id: PublicKey, address: SocketAddr, permanently: bool ) -> Result<(), Error>
Connect to a node on the peer-to-peer network.
If permanently is set to true, we’ll remember the peer and reconnect to it on restart.
sourcepub fn disconnect(&self, counterparty_node_id: &PublicKey) -> Result<(), Error>
pub fn disconnect(&self, counterparty_node_id: &PublicKey) -> Result<(), Error>
Disconnects the peer with the given node id.
Will also remove the peer from the peer store, i.e., after this has been called we won’t try to reconnect on restart.
sourcepub fn connect_open_channel(
&self,
node_id: PublicKey,
address: SocketAddr,
channel_amount_sats: u64,
push_to_counterparty_msat: Option<u64>,
announce_channel: bool
) -> Result<(), Error>
pub fn connect_open_channel( &self, node_id: PublicKey, address: SocketAddr, channel_amount_sats: u64, push_to_counterparty_msat: Option<u64>, announce_channel: bool ) -> Result<(), Error>
Connect to a node and open a new channel. Disconnects and re-connects are handled automatically
Disconnects and reconnects are handled automatically.
If push_to_counterparty_msat is set, the given value will be pushed (read: sent) to the
channel counterparty on channel open. This can be useful to start out with the balance not
entirely shifted to one side, therefore allowing to receive payments from the getgo.
Returns a temporary channel id.
sourcepub fn sync_wallets(&self) -> Result<(), Error>
pub fn sync_wallets(&self) -> Result<(), Error>
Sync the LDK and BDK wallets with the current chain state.
Note that the wallets will be also synced regularly in the background.
sourcepub fn close_channel(
&self,
channel_id: &[u8; 32],
counterparty_node_id: &PublicKey
) -> Result<(), Error>
pub fn close_channel( &self, channel_id: &[u8; 32], counterparty_node_id: &PublicKey ) -> Result<(), Error>
Close a previously opened channel.
sourcepub fn send_payment(&self, invoice: &Invoice) -> Result<PaymentHash, Error>
pub fn send_payment(&self, invoice: &Invoice) -> Result<PaymentHash, Error>
Send a payement given an invoice.
sourcepub fn send_payment_using_amount(
&self,
invoice: &Invoice,
amount_msat: u64
) -> Result<PaymentHash, Error>
pub fn send_payment_using_amount( &self, invoice: &Invoice, amount_msat: u64 ) -> Result<PaymentHash, Error>
Send a payment given an invoice and an amount in millisatoshi.
This will fail if the amount given is less than the value required by the given invoice.
This can be used to pay a so-called “zero-amount” invoice, i.e., an invoice that leaves the amount paid to be determined by the user.
sourcepub fn send_spontaneous_payment(
&self,
amount_msat: u64,
node_id: &PublicKey
) -> Result<PaymentHash, Error>
pub fn send_spontaneous_payment( &self, amount_msat: u64, node_id: &PublicKey ) -> Result<PaymentHash, Error>
Send a spontaneous, aka. “keysend”, payment
sourcepub fn receive_payment(
&self,
amount_msat: u64,
description: &str,
expiry_secs: u32
) -> Result<Invoice, Error>
pub fn receive_payment( &self, amount_msat: u64, description: &str, expiry_secs: u32 ) -> Result<Invoice, Error>
Returns a payable invoice that can be used to request and receive a payment of the amount given.
sourcepub fn receive_variable_amount_payment(
&self,
description: &str,
expiry_secs: u32
) -> Result<Invoice, Error>
pub fn receive_variable_amount_payment( &self, description: &str, expiry_secs: u32 ) -> Result<Invoice, Error>
Returns a payable invoice that can be used to request and receive a payment for which the amount is to be determined by the user, also known as a “zero-amount” invoice.
sourcepub fn payment(&self, payment_hash: &PaymentHash) -> Option<PaymentDetails>
pub fn payment(&self, payment_hash: &PaymentHash) -> Option<PaymentDetails>
Retrieve the details of a specific payment with the given hash.
Returns Some if the payment was known and None otherwise.
sourcepub fn remove_payment(&self, payment_hash: &PaymentHash) -> Result<bool, Error>
pub fn remove_payment(&self, payment_hash: &PaymentHash) -> Result<bool, Error>
Remove the payment with the given hash from the store.
Returns true if the payment was present and false otherwise.
sourcepub fn list_payments_with_filter<F: FnMut(&&PaymentDetails) -> bool>(
&self,
f: F
) -> Vec<PaymentDetails>
pub fn list_payments_with_filter<F: FnMut(&&PaymentDetails) -> bool>( &self, f: F ) -> Vec<PaymentDetails>
Retrieves all payments that match the given predicate.
For example, you could retrieve all stored outbound payments as follows:
node.list_payments_with_filter(|p| p.direction == PaymentDirection::Outbound);