Struct ldk_node::Node

source ·
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

source

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.

source

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.

source

pub fn status(&self) -> NodeStatus

Returns the status of the Node.

source

pub fn config(&self) -> Config

Returns the config with which the Node was initialized.

source

pub fn next_event(&self) -> Option<Event>

Returns the next event in the event queue, if currently available.

Will return Some(..) if an event is available and None otherwise.

Note: this will always return the same event until handling is confirmed via Node::event_handled.

source

pub async fn next_event_async(&self) -> Event

Returns the next event in the event queue.

Will asynchronously poll the event queue until the next event is ready.

Note: this will always return the same event until handling is confirmed via Node::event_handled.

source

pub fn wait_next_event(&self) -> Event

Returns the next event in the event queue.

Will block the current thread until the next event is available.

Note: this will always return the same event until handling is confirmed via Node::event_handled.

source

pub fn event_handled(&self)

Confirm the last retrieved event handled.

Note: This MUST be called after each event has been handled.

source

pub fn node_id(&self) -> PublicKey

Returns our own node id

source

pub fn listening_addresses(&self) -> Option<Vec<SocketAddress>>

Returns our own listening addresses.

source

pub fn bolt11_payment(&self) -> Bolt11Payment

Available on non-crate feature uniffi only.

Returns a payment handler allowing to create and pay BOLT 11 invoices.

source

pub fn bolt12_payment(&self) -> Arc<Bolt12Payment>

Available on non-crate feature uniffi only.

Returns a payment handler allowing to create and pay BOLT 12 offers and refunds.

source

pub fn spontaneous_payment(&self) -> SpontaneousPayment

Available on non-crate feature uniffi only.

Returns a payment handler allowing to send spontaneous (“keysend”) payments.

source

pub fn onchain_payment(&self) -> OnchainPayment

Available on non-crate feature uniffi only.

Returns a payment handler allowing to send and receive on-chain payments.

source

pub fn list_channels(&self) -> Vec<ChannelDetails>

Retrieve a list of known channels.

source

pub fn connect( &self, node_id: PublicKey, address: SocketAddress, persist: bool, ) -> Result<(), Error>

Connect to a node on the peer-to-peer network.

If persist is set to true, we’ll remember the peer and reconnect to it on restart.

source

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.

source

pub fn connect_open_channel( &self, node_id: PublicKey, address: SocketAddress, channel_amount_sats: u64, push_to_counterparty_msat: Option<u64>, channel_config: Option<Arc<ChannelConfig>>, announce_channel: bool, ) -> Result<UserChannelId, 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.

If Anchor channels are enabled, this will ensure the configured AnchorChannelsConfig::per_channel_reserve_sats is available and will be retained before opening the channel.

Returns a UserChannelId allowing to locally keep track of the channel.

source

pub fn sync_wallets(&self) -> Result<(), Error>

Manually sync the LDK and BDK wallets with the current chain state and update the fee rate cache.

Note: The wallets are regularly synced in the background, which is configurable via Config::onchain_wallet_sync_interval_secs and Config::wallet_sync_interval_secs. Therefore, using this blocking sync method is almost always redundant and should be avoided where possible.

source

pub fn close_channel( &self, user_channel_id: &UserChannelId, counterparty_node_id: PublicKey, ) -> Result<(), Error>

Close a previously opened channel.

Will attempt to close a channel coopertively. If this fails, users might need to resort to Node::force_close_channel.

source

pub fn force_close_channel( &self, user_channel_id: &UserChannelId, counterparty_node_id: PublicKey, ) -> Result<(), Error>

Force-close a previously opened channel.

Will force-close the channel, potentially broadcasting our latest state. Note that in contrast to cooperative closure, force-closing will have the channel funds time-locked, i.e., they will only be available after the counterparty had time to contest our claim. Force-closing channels also more costly in terms of on-chain fees. So cooperative closure should always be preferred (and tried first).

Broadcasting the closing transactions will be omitted for Anchor channels if we trust the counterparty to broadcast for us (see AnchorChannelsConfig::trusted_peers_no_reserve for more information).

source

pub fn update_channel_config( &self, user_channel_id: &UserChannelId, counterparty_node_id: PublicKey, channel_config: Arc<ChannelConfig>, ) -> Result<(), Error>

Update the config for a previously opened channel.

source

pub fn payment(&self, payment_id: &PaymentId) -> Option<PaymentDetails>

Retrieve the details of a specific payment with the given id.

Returns Some if the payment was known and None otherwise.

source

pub fn remove_payment(&self, payment_id: &PaymentId) -> Result<(), Error>

Remove the payment with the given id from the store.

source

pub fn list_balances(&self) -> BalanceDetails

Retrieves an overview of all known balances.

source

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);
source

pub fn list_payments(&self) -> Vec<PaymentDetails>

Retrieves all payments.

source

pub fn list_peers(&self) -> Vec<PeerDetails>

Retrieves a list of known peers.

source

pub fn network_graph(&self) -> NetworkGraph

Available on non-crate feature uniffi only.

Returns a handler allowing to query the network graph.

source

pub fn sign_message(&self, msg: &[u8]) -> Result<String, Error>

Creates a digital ECDSA signature of a message with the node’s secret key.

A receiver knowing the corresponding PublicKey (e.g. the node’s id) and the message can be sure that the signature was generated by the caller. Signatures are EC recoverable, meaning that given the message and the signature the PublicKey of the signer can be extracted.

source

pub fn verify_signature(&self, msg: &[u8], sig: &str, pkey: &PublicKey) -> bool

Verifies that the given ECDSA signature was created for the given message with the secret key corresponding to the given public key.

Trait Implementations§

source§

impl Drop for Node

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

Auto Trait Implementations§

§

impl Freeze for Node

§

impl !RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl !UnwindSafe for Node

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more