ldk-node 0.1.0

A ready-to-go node implementation built using LDK.
Documentation
namespace ldk_node {
	Mnemonic generate_entropy_mnemonic();
};

dictionary Config {
	string storage_dir_path = "/tmp/ldk_node/";
	Network network = "Bitcoin";
	NetAddress? listening_address = null;
	u32 default_cltv_expiry_delta = 144;
	u64 onchain_wallet_sync_interval_secs = 80;
	u64 wallet_sync_interval_secs = 30;
	u64 fee_rate_cache_update_interval_secs = 600;
	LogLevel log_level = "Debug";
	sequence<PublicKey> trusted_peers_0conf = [];
};

interface Builder {
	constructor();
	[Name=from_config]
	constructor(Config config);
	void set_entropy_seed_path(string seed_path);
	[Throws=BuildError]
	void set_entropy_seed_bytes(sequence<u8> seed_bytes);
	void set_entropy_bip39_mnemonic(Mnemonic mnemonic, string? passphrase);
	void set_esplora_server(string esplora_server_url);
	void set_gossip_source_p2p();
	void set_gossip_source_rgs(string rgs_server_url);
	void set_storage_dir_path(string storage_dir_path);
	void set_network(Network network);
	void set_listening_address(NetAddress listening_address);
	[Throws=BuildError]
	LDKNode build();
};

interface LDKNode {
	[Throws=NodeError]
	void start();
	[Throws=NodeError]
	void stop();
	Event? next_event();
	Event wait_next_event();
	void event_handled();
	PublicKey node_id();
	NetAddress? listening_address();
	[Throws=NodeError]
	Address new_onchain_address();
	[Throws=NodeError]
	Txid send_to_onchain_address([ByRef]Address address, u64 amount_msat);
	[Throws=NodeError]
	Txid send_all_to_onchain_address([ByRef]Address address);
	[Throws=NodeError]
	u64 spendable_onchain_balance_sats();
	[Throws=NodeError]
	u64 total_onchain_balance_sats();
	[Throws=NodeError]
	void connect(PublicKey node_id, NetAddress address, boolean persist);
	[Throws=NodeError]
	void disconnect(PublicKey node_id);
	[Throws=NodeError]
	void connect_open_channel(PublicKey node_id, NetAddress address, u64 channel_amount_sats, u64? push_to_counterparty_msat, ChannelConfig? channel_config, boolean announce_channel);
	[Throws=NodeError]
	void close_channel([ByRef]ChannelId channel_id, PublicKey counterparty_node_id);
	[Throws=NodeError]
	void update_channel_config([ByRef]ChannelId channel_id, PublicKey counterparty_node_id, [ByRef]ChannelConfig channel_config);
	[Throws=NodeError]
	void sync_wallets();
	[Throws=NodeError]
	PaymentHash send_payment([ByRef]Invoice invoice);
	[Throws=NodeError]
	PaymentHash send_payment_using_amount([ByRef]Invoice invoice, u64 amount_msat);
	[Throws=NodeError]
	PaymentHash send_spontaneous_payment(u64 amount_msat, PublicKey node_id);
	[Throws=NodeError]
	Invoice receive_payment(u64 amount_msat, [ByRef]string description, u32 expiry_secs);
	[Throws=NodeError]
	Invoice receive_variable_amount_payment([ByRef]string description, u32 expiry_secs);
	PaymentDetails? payment([ByRef]PaymentHash payment_hash);
	[Throws=NodeError]
	boolean remove_payment([ByRef]PaymentHash payment_hash);
	sequence<PaymentDetails> list_payments();
	sequence<PeerDetails> list_peers();
	sequence<ChannelDetails> list_channels();
	[Throws=NodeError]
	string sign_message([ByRef]sequence<u8> msg);
	boolean verify_signature([ByRef]sequence<u8> msg, [ByRef]string sig, [ByRef]PublicKey pkey);
};

[Error]
enum NodeError {
	"AlreadyRunning",
	"NotRunning",
	"OnchainTxCreationFailed",
	"ConnectionFailed",
	"InvoiceCreationFailed",
	"PaymentSendingFailed",
	"ChannelCreationFailed",
	"ChannelClosingFailed",
	"ChannelConfigUpdateFailed",
	"PersistenceFailed",
	"WalletOperationFailed",
	"OnchainTxSigningFailed",
	"MessageSigningFailed",
	"TxSyncFailed",
	"GossipUpdateFailed",
	"InvalidAddress",
	"InvalidNetAddress",
	"InvalidPublicKey",
	"InvalidSecretKey",
	"InvalidPaymentHash",
	"InvalidPaymentPreimage",
	"InvalidPaymentSecret",
	"InvalidAmount",
	"InvalidInvoice",
	"InvalidChannelId",
	"InvalidNetwork",
	"DuplicatePayment",
	"InsufficientFunds",
};

[Error]
enum BuildError {
	"InvalidSeedBytes",
	"InvalidSeedFile",
	"InvalidSystemTime",
	"ReadFailed",
	"WriteFailed",
	"StoragePathAccessFailed",
	"WalletSetupFailed",
	"LoggerSetupFailed",
};

[Enum]
interface Event {
	PaymentSuccessful( PaymentHash payment_hash );
	PaymentFailed( PaymentHash payment_hash );
	PaymentReceived( PaymentHash payment_hash, u64 amount_msat);
	ChannelPending ( ChannelId channel_id, UserChannelId user_channel_id, ChannelId former_temporary_channel_id, PublicKey counterparty_node_id, OutPoint funding_txo );
	ChannelReady ( ChannelId channel_id, UserChannelId user_channel_id );
	ChannelClosed ( ChannelId channel_id, UserChannelId user_channel_id );
};

enum PaymentDirection {
	"Inbound",
	"Outbound",
};

enum PaymentStatus {
	"Pending",
	"Succeeded",
	"Failed",
};

enum Network {
	"Bitcoin",
	"Testnet",
	"Signet",
	"Regtest",
};

dictionary PaymentDetails {
	PaymentHash hash;
	PaymentPreimage? preimage;
	PaymentSecret? secret;
	u64? amount_msat;
	PaymentDirection direction;
	PaymentStatus status;
};

dictionary OutPoint {
	Txid txid;
	u32 vout;
};

dictionary ChannelDetails {
	ChannelId channel_id;
	PublicKey counterparty_node_id;
	OutPoint? funding_txo;
	u64 channel_value_sats;
	u64? unspendable_punishment_reserve;
	UserChannelId user_channel_id;
	u32 feerate_sat_per_1000_weight;
	u64 balance_msat;
	u64 outbound_capacity_msat;
	u64 inbound_capacity_msat;
	u32? confirmations_required;
	u32? confirmations;
	boolean is_outbound;
	boolean is_channel_ready;
	boolean is_usable;
	boolean is_public;
	u16? cltv_expiry_delta;
};

dictionary PeerDetails {
	PublicKey node_id;
	NetAddress address;
	boolean is_persisted;
	boolean is_connected;
};

dictionary ChannelConfig {
	u32 forwarding_fee_proportional_millionths;
	u32 forwarding_fee_base_msat;
	u16 cltv_expiry_delta;
	u64 max_dust_htlc_exposure_msat;
	u64 force_close_avoidance_max_fee_satoshis;
};

enum LogLevel {
	"Gossip",
	"Trace",
	"Debug",
	"Info",
	"Warn",
	"Error",
};

[Custom]
typedef string Txid;

[Custom]
typedef string NetAddress;

[Custom]
typedef string PublicKey;

[Custom]
typedef string Address;

[Custom]
typedef string Invoice;

[Custom]
typedef string PaymentHash;

[Custom]
typedef string PaymentPreimage;

[Custom]
typedef string PaymentSecret;

[Custom]
typedef string ChannelId;

[Custom]
typedef string UserChannelId;

[Custom]
typedef string Mnemonic;