ln_gateway::lightning

Trait ILnRpcClient

Source
pub trait ILnRpcClient:
    Debug
    + Send
    + Sync {
Show 14 methods // Required methods fn info<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<GetNodeInfoResponse, LightningRpcError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn routehints<'life0, 'async_trait>( &'life0 self, num_route_hints: usize, ) -> Pin<Box<dyn Future<Output = Result<GetRouteHintsResponse, LightningRpcError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn route_htlcs<'a, 'life0, 'async_trait>( self: Box<Self>, task_group: &'life0 TaskGroup, ) -> Pin<Box<dyn Future<Output = Result<(RouteHtlcStream<'a>, Arc<dyn ILnRpcClient>), LightningRpcError>> + Send + 'async_trait>> where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait; fn complete_htlc<'life0, 'async_trait>( &'life0 self, htlc: InterceptPaymentResponse, ) -> Pin<Box<dyn Future<Output = Result<(), LightningRpcError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn create_invoice<'life0, 'async_trait>( &'life0 self, create_invoice_request: CreateInvoiceRequest, ) -> Pin<Box<dyn Future<Output = Result<CreateInvoiceResponse, LightningRpcError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_ln_onchain_address<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<GetLnOnchainAddressResponse, LightningRpcError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn send_onchain<'life0, 'async_trait>( &'life0 self, payload: SendOnchainPayload, ) -> Pin<Box<dyn Future<Output = Result<SendOnchainResponse, LightningRpcError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn open_channel<'life0, 'async_trait>( &'life0 self, payload: OpenChannelPayload, ) -> Pin<Box<dyn Future<Output = Result<OpenChannelResponse, LightningRpcError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn close_channels_with_peer<'life0, 'async_trait>( &'life0 self, payload: CloseChannelsWithPeerPayload, ) -> Pin<Box<dyn Future<Output = Result<CloseChannelsWithPeerResponse, LightningRpcError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn list_active_channels<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChannelInfo>, LightningRpcError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_balances<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<GetBalancesResponse, LightningRpcError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; // Provided methods fn pay<'life0, 'async_trait>( &'life0 self, invoice: Bolt11Invoice, max_delay: u64, max_fee: Amount, ) -> Pin<Box<dyn Future<Output = Result<PayInvoiceResponse, LightningRpcError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn pay_private<'life0, 'async_trait>( &'life0 self, _invoice: PrunedInvoice, _max_delay: u64, _max_fee: Amount, ) -> Pin<Box<dyn Future<Output = Result<PayInvoiceResponse, LightningRpcError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait { ... } fn supports_private_payments(&self) -> bool { ... }
}
Expand description

A trait that the gateway uses to interact with a lightning node. This allows the gateway to be agnostic to the specific lightning node implementation being used.

Required Methods§

Source

fn info<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<GetNodeInfoResponse, LightningRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns high-level info about the lightning node.

Source

fn routehints<'life0, 'async_trait>( &'life0 self, num_route_hints: usize, ) -> Pin<Box<dyn Future<Output = Result<GetRouteHintsResponse, LightningRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns route hints to the lightning node.

Note: This is only used for inbound LNv1 payments and will be removed when we switch to LNv2.

Source

fn route_htlcs<'a, 'life0, 'async_trait>( self: Box<Self>, task_group: &'life0 TaskGroup, ) -> Pin<Box<dyn Future<Output = Result<(RouteHtlcStream<'a>, Arc<dyn ILnRpcClient>), LightningRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'a: 'async_trait, 'life0: 'async_trait,

Consumes the current client and returns a stream of intercepted HTLCs and a new client. complete_htlc must be called for all successfully intercepted HTLCs sent to the returned stream.

route_htlcs can only be called once for a given client, since the returned stream grants exclusive routing decisions to the caller. For this reason, route_htlc consumes the client and returns one wrapped in an Arc. This lets the compiler enforce that route_htlcs can only be called once for a given client, since the value inside the Arc cannot be consumed.

Source

fn complete_htlc<'life0, 'async_trait>( &'life0 self, htlc: InterceptPaymentResponse, ) -> Pin<Box<dyn Future<Output = Result<(), LightningRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Completes an HTLC that was intercepted by the gateway. Must be called for all successfully intercepted HTLCs sent to the stream returned by route_htlcs.

Source

fn create_invoice<'life0, 'async_trait>( &'life0 self, create_invoice_request: CreateInvoiceRequest, ) -> Pin<Box<dyn Future<Output = Result<CreateInvoiceResponse, LightningRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Requests the lightning node to create an invoice. The presence of a payment hash in the CreateInvoiceRequest determines if the invoice is intended to be an ecash payment or a direct payment to this lightning node.

Source

fn get_ln_onchain_address<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<GetLnOnchainAddressResponse, LightningRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Gets a funding address belonging to the lightning node’s on-chain wallet.

Source

fn send_onchain<'life0, 'async_trait>( &'life0 self, payload: SendOnchainPayload, ) -> Pin<Box<dyn Future<Output = Result<SendOnchainResponse, LightningRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Executes an onchain transaction using the lightning node’s on-chain wallet.

Source

fn open_channel<'life0, 'async_trait>( &'life0 self, payload: OpenChannelPayload, ) -> Pin<Box<dyn Future<Output = Result<OpenChannelResponse, LightningRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Opens a channel with a peer lightning node.

Source

fn close_channels_with_peer<'life0, 'async_trait>( &'life0 self, payload: CloseChannelsWithPeerPayload, ) -> Pin<Box<dyn Future<Output = Result<CloseChannelsWithPeerResponse, LightningRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Closes all channels with a peer lightning node.

Source

fn list_active_channels<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<ChannelInfo>, LightningRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Lists the lightning node’s active channels with all peers.

Source

fn get_balances<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<GetBalancesResponse, LightningRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns a summary of the lightning node’s balance, including the onchain wallet, outbound liquidity, and inbound liquidity.

Provided Methods§

Source

fn pay<'life0, 'async_trait>( &'life0 self, invoice: Bolt11Invoice, max_delay: u64, max_fee: Amount, ) -> Pin<Box<dyn Future<Output = Result<PayInvoiceResponse, LightningRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Attempts to pay an invoice using the lightning node, waiting for the payment to complete and returning the preimage.

Caller restrictions: May be called multiple times for the same invoice, but should be done with all the same parameters. This is because the payment may be in-flight from a previous call, in which case fee or delay limits cannot be changed and will be ignored.

Implementor restrictions: This must be idempotent for a given invoice, since it is called by state machines. In more detail, when called for a given invoice:

  • If the payment is already in-flight, wait for that payment to complete as if it were the first call.
  • If the payment has already been attempted and failed, return an error.
  • If the payment has already succeeded, return a success response.
Source

fn pay_private<'life0, 'async_trait>( &'life0 self, _invoice: PrunedInvoice, _max_delay: u64, _max_fee: Amount, ) -> Pin<Box<dyn Future<Output = Result<PayInvoiceResponse, LightningRpcError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Attempts to pay an invoice using the lightning node, waiting for the payment to complete and returning the preimage.

This is more private than ILnRpcClient::pay, as it does not require the invoice description. If this is implemented, ILnRpcClient::supports_private_payments must return true.

Note: This is only used for outbound LNv1 payments and will be removed when we switch to LNv2.

Source

fn supports_private_payments(&self) -> bool

Returns true if the lightning backend supports payments without full invoices. If this returns true, ILnRpcClient::pay_private must be implemented.

Implementations§

Source§

impl dyn ILnRpcClient

Source

pub async fn parsed_route_hints(&self, num_route_hints: u32) -> Vec<RouteHint>

Retrieve route hints from the Lightning node, capped at num_route_hints. The route hints should be ordered based on liquidity of incoming channels.

Source

pub async fn parsed_node_info( &self, ) -> Result<(PublicKey, String, Network, u32, bool), LightningRpcError>

Retrieves the basic information about the Gateway’s connected Lightning node.

Source

pub async fn wait_for_chain_sync(&self) -> Result<(), LightningRpcError>

Waits for the Lightning node to be synced to the Bitcoin blockchain.

Implementors§