Skip to main content

Node

Struct Node 

Source
pub struct Node { /* private fields */ }
Expand description

The Node is an RPC stub representing the node running in the cloud. It is the main entrypoint to interact with the node.

Implementations§

Source§

impl Node

Source

pub fn signerless(credentials: Credentials) -> Result<Self, Error>

Construct a signerless Node — credentials only, no SDK-side signer running. The actual signing happens elsewhere (a paired device, a hardware signer, the CLN node’s local signer). Operations that require signing fall through to the node side.

Not a UniFFI export. UniFFI consumers reach this via NodeBuilder::connect(credentials, None) (mnemonic omitted). Sibling Rust crates (e.g. gl-sdk-napi) call this directly when wrapping signerless flows into their own bindings.

Source§

impl Node

Source

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

Stop the node if it is currently running.

Source

pub fn credentials(&self) -> Result<Vec<u8>, Error>

Returns the serialized credentials for this node. The app should persist these bytes and pass them to connect() on next launch.

Source

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

Disconnects from the node and stops the signer if running. After disconnect, all RPC methods will return an error. Safe to call multiple times.

Source

pub fn receive( &self, label: String, description: String, amount_msat: Option<u64>, ) -> Result<ReceiveResponse, Error>

Receive an off-chain payment.

This method generates a request for a payment, also called an invoice, that encodes all the information, including amount and destination, for a prospective sender to send a lightning payment. The invoice includes negotiation of an LSPS2 / JIT channel, meaning that if there is no channel sufficient to receive the requested funds, the node will negotiate an opening, and when/if executed the payment will cause a channel to be created, and the incoming payment to be forwarded.

Source

pub fn send( &self, invoice: String, amount_msat: Option<u64>, ) -> Result<SendResponse, Error>

Source

pub fn onchain_send( &self, destination: String, amount_or_all: String, sat_per_vbyte: Option<u32>, utxos: Option<Vec<Outpoint>>, ) -> Result<OnchainSendResponse, Error>

Send bitcoin on-chain to a destination address.

§Arguments
  • destination — A Bitcoin address (bech32, p2sh, or p2tr).
  • amount_or_all — Amount to send. Accepts:
    • "50000" or "50000sat" — 50,000 satoshis
    • "50000msat" — 50,000 millisatoshis
    • "all" — sweep the entire on-chain balance
  • sat_per_vbyte — Optional fee rate in sats per virtual byte. Pass None to let the node pick. Pass the value from a prior prepare_onchain_send to reproduce the previewed fee.
  • utxos — Optional pinned input set. Pass the utxos returned by prepare_onchain_send (together with the same sat_per_vbyte) to broadcast a transaction with the exact inputs and fee shown in the preview. Pass None to let the node coin-select.

Returns the raw transaction, txid, and PSBT once broadcast. The transaction is broadcast immediately — this is not a dry run.

Source

pub fn prepare_onchain_send( &self, destination: String, amount_or_all: String, sat_per_vbyte: Option<u32>, ) -> Result<PreparedOnchainSend, Error>

Preview an on-chain send without broadcasting or reserving UTXOs.

Runs CLN’s coin selection at the given fee rate and returns the inputs that would be spent, the fee, and the amount the recipient would receive. Safe to call repeatedly (e.g. while the user adjusts a fee slider) — nothing is locked.

To broadcast with the previewed values, pass the returned utxos and sat_per_vbyte back to onchain_send. Identical inputs at the same fee rate yield the same fee.

Use this for “Send Max” UIs. recipient_sat is the only authoritative post-fee amount the destination will receive for a sweep. NodeState.onchain_balance_msat includes the emergency reserve and the fee — neither of which leaves the wallet with the recipient. For the entry-point button label (a pre-fee approximation that updates without an RPC), use OnchainBalanceState::Available.withdrawable_sat.

§Arguments
  • destination — A Bitcoin address (bech32, p2sh, or p2tr).
  • amount_or_all — Amount to send. Accepts:
    • "50000" or "50000sat" — 50,000 satoshis
    • "50000msat" — 50,000 millisatoshis
    • "all" — sweep the entire on-chain balance
  • sat_per_vbyte — Fee rate in sats per virtual byte. Pass None to use the node’s “normal” priority feerate; the effective rate CLN picked is reported back in the result’s sat_per_vbyte field, which can be passed to onchain_send to reproduce it.
Source

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

Classify the on-chain wallet for the withdraw entry-point UI.

Runs three RPCs concurrently:

  • list_funds — current confirmed/unconfirmed/immature on-chain balances.
  • list_peer_channels — pending channel-close payouts that haven’t yet hit the wallet.
  • fund_psbt(satoshi=All, reserve=0, normal feerate) — a non-locking probe whose response tells us exactly how much CLN will carve as the anchor-channel emergency reserve for this specific node, no client-side guessing required. The carved amount is computed from the response as total_inputs − excess − fee, which is identical to what CLN would carve on a real broadcast.

Cheaper to call than node_state() and answers a different question. Wallets typically call it once per render of the home screen.

For the exact post-fee recipient amount of a withdraw, use prepare_onchain_send; the withdrawable_sat returned here is a pre-fee, reserve-aware figure for the entry-point label.

Source

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

On-chain fee rates, in sats per virtual byte, at several confirmation targets.

Sourced from the connected node’s view of the network — no 3rd-party HTTP calls. Use as the basis for a fee-picker UI; minimum_relay_sat_per_vbyte is the relay floor enforced at broadcast time and should be the lower bound of any slider.

Source

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

Generate a fresh on-chain Bitcoin address for receiving funds.

Returns both a bech32 (SegWit v0) and a p2tr (Taproot) address. Either can be shared with a sender. Deposited funds will appear in node_state().onchain_balance_msat once confirmed.

Source

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

Get information about the node.

Returns basic information about the node including its ID, alias, network, and channel counts.

Source

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

List all peers connected to this node.

Returns information about all peers including their connection status.

Source

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

List all channels with peers.

Returns detailed information about all channels including their state, capacity, and balances.

Source

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

List all funds available to the node.

Returns information about on-chain outputs and channel funds that are available or pending.

Source

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

Get a snapshot of the node’s balances, capacity, and connectivity.

Aggregates data from multiple RPCs into a single NodeState. Queries the node live on each call — not cached.

Source

pub fn list_invoices( &self, label: Option<String>, invstring: Option<String>, payment_hash: Option<Vec<u8>>, offer_id: Option<String>, index: Option<ListIndex>, start: Option<u64>, limit: Option<u32>, ) -> Result<ListInvoicesResponse, Error>

List invoices (received payment requests). All parameters are optional filters; pass None to fetch all.

Source

pub fn list_pays( &self, bolt11: Option<String>, payment_hash: Option<Vec<u8>>, status: Option<PayStatus>, index: Option<ListIndex>, start: Option<u64>, limit: Option<u32>, ) -> Result<ListPaysResponse, Error>

List outgoing payments. All parameters are optional filters; pass None to fetch all.

Source

pub fn list_payments( &self, req: ListPaymentsRequest, ) -> Result<Vec<Payment>, Error>

List payments (sent and received), merged into a single timeline.

Fetches invoices and outgoing payments from the node, merges them into a unified list, and applies optional filters. Use list_invoices/list_pays for direct CLN access. Results are sorted newest-first.

Source

pub fn stream_node_events(&self) -> Result<Arc<NodeEventStream>, Error>

Stream real-time events from the node.

Returns a NodeEventStream iterator. Call next() repeatedly to receive events as they occur (e.g., invoice payments).

The next() method blocks the calling thread until an event is available, but does not block the underlying async runtime, so other node methods can be called concurrently from other threads.

Source

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

Collect a diagnostic snapshot of the node and SDK state.

Returns a pretty-printed JSON string with shape: { "timestamp": <unix-secs>, "node": { ... }, "sdk": { "version": ..., "node_state": ... } }. The node object contains one entry per CLN RPC (getinfo, listpeerchannels, listfunds); each value is the serialized response, or { "error": "..." } if that RPC failed. Payment and invoice history are deliberately excluded to avoid leaking preimages, payment hashes, bolt11 strings, and labels into support dumps. Intended for support tickets.

Source

pub fn lnurl_pay( &self, request: LnUrlPayRequest, ) -> Result<LnUrlPayResult, Error>

Execute an LNURL-pay flow (LUD-06).

Sends the chosen amount (and optional comment) to the service’s callback, receives and validates a BOLT11 invoice, pays it, and processes any success action (LUD-09/10).

Call the top-level parse_input first to obtain the LnUrlPayRequestData, then build an LnUrlPayRequest with the user’s chosen amount.

Source

pub fn lnurl_withdraw( &self, request: LnUrlWithdrawRequest, ) -> Result<LnUrlWithdrawResult, Error>

Execute an LNURL-withdraw flow (LUD-03).

Creates an invoice on this node for the requested amount, sends it to the service’s callback URL, and the service pays it asynchronously.

Call the top-level parse_input first to obtain the LnUrlWithdrawRequestData, then build an LnUrlWithdrawRequest with the user’s chosen amount.

Trait Implementations§

Source§

impl Drop for Node

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl<UT> LiftRef<UT> for Node

Source§

impl<UT> LowerError<UT> for Node

Source§

fn lower_error(obj: Self) -> RustBuffer

Lower this value for scaffolding function return Read more
Source§

impl<UT> LowerReturn<UT> for Node

Source§

type ReturnType = <Arc<Node> as LowerReturn<UniFfiTag>>::ReturnType

The type that should be returned by scaffolding functions for this type. Read more
Source§

fn lower_return(obj: Self) -> Result<Self::ReturnType, RustCallError>

Lower the return value from an scaffolding call Read more
Source§

fn handle_failed_lift( error: LiftArgsError, ) -> Result<Self::ReturnType, RustCallError>

Lower the return value for failed argument lifts Read more
Source§

impl<UT> TypeId<UT> for Node

Auto Trait Implementations§

§

impl !Freeze for Node

§

impl !RefUnwindSafe for Node

§

impl Send for Node

§

impl Sync for Node

§

impl Unpin for Node

§

impl UnsafeUnpin 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> Any for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Source§

fn type_name(&self) -> &'static str

Source§

impl<T> AnySync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Source§

impl<T> AsAny for T
where T: Any,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Source§

fn type_name(&self) -> &'static str

Gets the type name of self
Source§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

Source§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

Source§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

Source§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

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> Downcast for T
where T: AsAny + ?Sized,

Source§

fn is<T>(&self) -> bool
where T: AsAny,

Returns true if the boxed type is the same as T. Read more
Source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: AsAny,

Forward to the method defined on the type Any.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, UT> HandleAlloc<UT> for T
where T: Send + Sync,

Source§

fn new_handle(value: Arc<T>) -> Handle

Create a new handle for an Arc value Read more
Source§

unsafe fn clone_handle(handle: Handle) -> Handle

Clone a handle Read more
Source§

unsafe fn consume_handle(handle: Handle) -> Arc<T>

Consume a handle, getting back the initial Arc<> Read more
Source§

unsafe fn get_arc(handle: Handle) -> Arc<Self>

Get a clone of the Arc<> using a “borrowed” handle. Read more
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> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

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>,

Source§

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