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.

Create a node

NOTE: you must persist the node yourself if it is new.

Restore a node.

Set the node’s validator factory

Get the node ID, which is the same as the node public key

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

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.

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 to Node::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 input
  • values_sat - the amount in satoshi per input
  • spendtypes - spend type per input, or Invalid 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 the ipaths 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

See MyKeysManager::spend_spendable_outputs.

For LDK compatibility.

Returns the node’s current allowlist.

Adds addresses to the node’s current allowlist.

Removes addresses from the node’s current allowlist.

Chain tracker with lock

Trait Implementations

Formats the value using the given formatter. Read more

Returns true if script_pubkey is in the node’s allowlist.

True if the wallet can spend the given output with a derived key

Returns the network

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.