UNPKG

lightningdevkit

Version:
343 lines (342 loc) 17 kB
import { Option_CVec_ThirtyTwoBytesZZ } from '../structs/Option_CVec_ThirtyTwoBytesZZ.mjs'; import { Result_NoneNoneZ } from '../structs/Result_NoneNoneZ.mjs'; import { ChannelUpdate } from '../structs/ChannelUpdate.mjs'; import { AcceptChannel } from '../structs/AcceptChannel.mjs'; import { AcceptChannelV2 } from '../structs/AcceptChannelV2.mjs'; import { OpenChannel } from '../structs/OpenChannel.mjs'; import { OpenChannelV2 } from '../structs/OpenChannelV2.mjs'; import { FundingCreated } from '../structs/FundingCreated.mjs'; import { FundingSigned } from '../structs/FundingSigned.mjs'; import { Stfu } from '../structs/Stfu.mjs'; import { TxAddInput } from '../structs/TxAddInput.mjs'; import { TxAddOutput } from '../structs/TxAddOutput.mjs'; import { TxRemoveInput } from '../structs/TxRemoveInput.mjs'; import { TxRemoveOutput } from '../structs/TxRemoveOutput.mjs'; import { TxComplete } from '../structs/TxComplete.mjs'; import { TxSignatures } from '../structs/TxSignatures.mjs'; import { TxInitRbf } from '../structs/TxInitRbf.mjs'; import { TxAckRbf } from '../structs/TxAckRbf.mjs'; import { TxAbort } from '../structs/TxAbort.mjs'; import { ChannelReady } from '../structs/ChannelReady.mjs'; import { AnnouncementSignatures } from '../structs/AnnouncementSignatures.mjs'; import { RevokeAndACK } from '../structs/RevokeAndACK.mjs'; import { ClosingSigned } from '../structs/ClosingSigned.mjs'; import { Shutdown } from '../structs/Shutdown.mjs'; import { ChannelReestablish } from '../structs/ChannelReestablish.mjs'; import { ErrorMessage } from '../structs/ErrorMessage.mjs'; import { UpdateAddHTLC } from '../structs/UpdateAddHTLC.mjs'; import { UpdateFulfillHTLC } from '../structs/UpdateFulfillHTLC.mjs'; import { UpdateFailHTLC } from '../structs/UpdateFailHTLC.mjs'; import { UpdateFailMalformedHTLC } from '../structs/UpdateFailMalformedHTLC.mjs'; import { CommitmentSigned } from '../structs/CommitmentSigned.mjs'; import { Init } from '../structs/Init.mjs'; import { UpdateFee } from '../structs/UpdateFee.mjs'; import { InitFeatures } from '../structs/InitFeatures.mjs'; import { NodeFeatures } from '../structs/NodeFeatures.mjs'; import { MessageSendEventsProviderInterface } from '../structs/MessageSendEventsProvider.mjs'; import { CommonBase } from './CommonBase.mjs'; /** An implementation of ChannelMessageHandler */ export interface ChannelMessageHandlerInterface { /**Handle an incoming `open_channel` message from the given peer. */ handle_open_channel(their_node_id: Uint8Array, msg: OpenChannel): void; /**Handle an incoming `open_channel2` message from the given peer. */ handle_open_channel_v2(their_node_id: Uint8Array, msg: OpenChannelV2): void; /**Handle an incoming `accept_channel` message from the given peer. */ handle_accept_channel(their_node_id: Uint8Array, msg: AcceptChannel): void; /**Handle an incoming `accept_channel2` message from the given peer. */ handle_accept_channel_v2(their_node_id: Uint8Array, msg: AcceptChannelV2): void; /**Handle an incoming `funding_created` message from the given peer. */ handle_funding_created(their_node_id: Uint8Array, msg: FundingCreated): void; /**Handle an incoming `funding_signed` message from the given peer. */ handle_funding_signed(their_node_id: Uint8Array, msg: FundingSigned): void; /**Handle an incoming `channel_ready` message from the given peer. */ handle_channel_ready(their_node_id: Uint8Array, msg: ChannelReady): void; /**Handle an incoming `shutdown` message from the given peer. */ handle_shutdown(their_node_id: Uint8Array, msg: Shutdown): void; /**Handle an incoming `closing_signed` message from the given peer. */ handle_closing_signed(their_node_id: Uint8Array, msg: ClosingSigned): void; /**Handle an incoming `stfu` message from the given peer. */ handle_stfu(their_node_id: Uint8Array, msg: Stfu): void; /**Handle an incoming `tx_add_input message` from the given peer. */ handle_tx_add_input(their_node_id: Uint8Array, msg: TxAddInput): void; /**Handle an incoming `tx_add_output` message from the given peer. */ handle_tx_add_output(their_node_id: Uint8Array, msg: TxAddOutput): void; /**Handle an incoming `tx_remove_input` message from the given peer. */ handle_tx_remove_input(their_node_id: Uint8Array, msg: TxRemoveInput): void; /**Handle an incoming `tx_remove_output` message from the given peer. */ handle_tx_remove_output(their_node_id: Uint8Array, msg: TxRemoveOutput): void; /**Handle an incoming `tx_complete message` from the given peer. */ handle_tx_complete(their_node_id: Uint8Array, msg: TxComplete): void; /**Handle an incoming `tx_signatures` message from the given peer. */ handle_tx_signatures(their_node_id: Uint8Array, msg: TxSignatures): void; /**Handle an incoming `tx_init_rbf` message from the given peer. */ handle_tx_init_rbf(their_node_id: Uint8Array, msg: TxInitRbf): void; /**Handle an incoming `tx_ack_rbf` message from the given peer. */ handle_tx_ack_rbf(their_node_id: Uint8Array, msg: TxAckRbf): void; /**Handle an incoming `tx_abort message` from the given peer. */ handle_tx_abort(their_node_id: Uint8Array, msg: TxAbort): void; /**Handle an incoming `update_add_htlc` message from the given peer. */ handle_update_add_htlc(their_node_id: Uint8Array, msg: UpdateAddHTLC): void; /**Handle an incoming `update_fulfill_htlc` message from the given peer. */ handle_update_fulfill_htlc(their_node_id: Uint8Array, msg: UpdateFulfillHTLC): void; /**Handle an incoming `update_fail_htlc` message from the given peer. */ handle_update_fail_htlc(their_node_id: Uint8Array, msg: UpdateFailHTLC): void; /**Handle an incoming `update_fail_malformed_htlc` message from the given peer. */ handle_update_fail_malformed_htlc(their_node_id: Uint8Array, msg: UpdateFailMalformedHTLC): void; /**Handle an incoming `commitment_signed` message from the given peer. */ handle_commitment_signed(their_node_id: Uint8Array, msg: CommitmentSigned): void; /**Handle an incoming `revoke_and_ack` message from the given peer. */ handle_revoke_and_ack(their_node_id: Uint8Array, msg: RevokeAndACK): void; /**Handle an incoming `update_fee` message from the given peer. */ handle_update_fee(their_node_id: Uint8Array, msg: UpdateFee): void; /**Handle an incoming `announcement_signatures` message from the given peer. */ handle_announcement_signatures(their_node_id: Uint8Array, msg: AnnouncementSignatures): void; /**Indicates a connection to the peer failed/an existing connection was lost. */ peer_disconnected(their_node_id: Uint8Array): void; /**Handle a peer reconnecting, possibly generating `channel_reestablish` message(s). * * May return an `Err(())` if the features the peer supports are not sufficient to communicate * with us. Implementors should be somewhat conservative about doing so, however, as other * message handlers may still wish to communicate with this peer. * * [`Self::peer_disconnected`] will not be called if `Err(())` is returned. */ peer_connected(their_node_id: Uint8Array, msg: Init, inbound: boolean): Result_NoneNoneZ; /**Handle an incoming `channel_reestablish` message from the given peer. */ handle_channel_reestablish(their_node_id: Uint8Array, msg: ChannelReestablish): void; /**Handle an incoming `channel_update` message from the given peer. */ handle_channel_update(their_node_id: Uint8Array, msg: ChannelUpdate): void; /**Handle an incoming `error` message from the given peer. */ handle_error(their_node_id: Uint8Array, msg: ErrorMessage): void; /**Gets the node feature flags which this handler itself supports. All available handlers are * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`] * which are broadcasted in our [`NodeAnnouncement`] message. */ provided_node_features(): NodeFeatures; /**Gets the init feature flags which should be sent to the given peer. All available handlers * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`] * which are sent in our [`Init`] message. * * Note that this method is called before [`Self::peer_connected`]. */ provided_init_features(their_node_id: Uint8Array): InitFeatures; /**Gets the chain hashes for this `ChannelMessageHandler` indicating which chains it supports. * * If it's `None`, then no particular network chain hash compatibility will be enforced when * connecting to peers. */ get_chain_hashes(): Option_CVec_ThirtyTwoBytesZZ; /**Indicates that a message was received from any peer for any handler. * Called before the message is passed to the appropriate handler. * Useful for indicating that a network connection is active. * * Note: Since this function is called frequently, it should be as * efficient as possible for its intended purpose. */ message_received(): void; } /** * A trait to describe an object which can receive channel messages. * * Messages MAY be called in parallel when they originate from different `their_node_ids`, however * they MUST NOT be called in parallel when the two calls have the same `their_node_id`. */ export declare class ChannelMessageHandler extends CommonBase { /** Creates a new instance of ChannelMessageHandler from a given implementation */ static new_impl(arg: ChannelMessageHandlerInterface, messageSendEventsProvider_impl: MessageSendEventsProviderInterface): ChannelMessageHandler; /** * Handle an incoming `open_channel` message from the given peer. */ handle_open_channel(their_node_id: Uint8Array, msg: OpenChannel): void; /** * Handle an incoming `open_channel2` message from the given peer. */ handle_open_channel_v2(their_node_id: Uint8Array, msg: OpenChannelV2): void; /** * Handle an incoming `accept_channel` message from the given peer. */ handle_accept_channel(their_node_id: Uint8Array, msg: AcceptChannel): void; /** * Handle an incoming `accept_channel2` message from the given peer. */ handle_accept_channel_v2(their_node_id: Uint8Array, msg: AcceptChannelV2): void; /** * Handle an incoming `funding_created` message from the given peer. */ handle_funding_created(their_node_id: Uint8Array, msg: FundingCreated): void; /** * Handle an incoming `funding_signed` message from the given peer. */ handle_funding_signed(their_node_id: Uint8Array, msg: FundingSigned): void; /** * Handle an incoming `channel_ready` message from the given peer. */ handle_channel_ready(their_node_id: Uint8Array, msg: ChannelReady): void; /** * Handle an incoming `shutdown` message from the given peer. */ handle_shutdown(their_node_id: Uint8Array, msg: Shutdown): void; /** * Handle an incoming `closing_signed` message from the given peer. */ handle_closing_signed(their_node_id: Uint8Array, msg: ClosingSigned): void; /** * Handle an incoming `stfu` message from the given peer. */ handle_stfu(their_node_id: Uint8Array, msg: Stfu): void; /** * Handle an incoming `tx_add_input message` from the given peer. */ handle_tx_add_input(their_node_id: Uint8Array, msg: TxAddInput): void; /** * Handle an incoming `tx_add_output` message from the given peer. */ handle_tx_add_output(their_node_id: Uint8Array, msg: TxAddOutput): void; /** * Handle an incoming `tx_remove_input` message from the given peer. */ handle_tx_remove_input(their_node_id: Uint8Array, msg: TxRemoveInput): void; /** * Handle an incoming `tx_remove_output` message from the given peer. */ handle_tx_remove_output(their_node_id: Uint8Array, msg: TxRemoveOutput): void; /** * Handle an incoming `tx_complete message` from the given peer. */ handle_tx_complete(their_node_id: Uint8Array, msg: TxComplete): void; /** * Handle an incoming `tx_signatures` message from the given peer. */ handle_tx_signatures(their_node_id: Uint8Array, msg: TxSignatures): void; /** * Handle an incoming `tx_init_rbf` message from the given peer. */ handle_tx_init_rbf(their_node_id: Uint8Array, msg: TxInitRbf): void; /** * Handle an incoming `tx_ack_rbf` message from the given peer. */ handle_tx_ack_rbf(their_node_id: Uint8Array, msg: TxAckRbf): void; /** * Handle an incoming `tx_abort message` from the given peer. */ handle_tx_abort(their_node_id: Uint8Array, msg: TxAbort): void; /** * Handle an incoming `update_add_htlc` message from the given peer. */ handle_update_add_htlc(their_node_id: Uint8Array, msg: UpdateAddHTLC): void; /** * Handle an incoming `update_fulfill_htlc` message from the given peer. */ handle_update_fulfill_htlc(their_node_id: Uint8Array, msg: UpdateFulfillHTLC): void; /** * Handle an incoming `update_fail_htlc` message from the given peer. */ handle_update_fail_htlc(their_node_id: Uint8Array, msg: UpdateFailHTLC): void; /** * Handle an incoming `update_fail_malformed_htlc` message from the given peer. */ handle_update_fail_malformed_htlc(their_node_id: Uint8Array, msg: UpdateFailMalformedHTLC): void; /** * Handle an incoming `commitment_signed` message from the given peer. */ handle_commitment_signed(their_node_id: Uint8Array, msg: CommitmentSigned): void; /** * Handle an incoming `revoke_and_ack` message from the given peer. */ handle_revoke_and_ack(their_node_id: Uint8Array, msg: RevokeAndACK): void; /** * Handle an incoming `update_fee` message from the given peer. */ handle_update_fee(their_node_id: Uint8Array, msg: UpdateFee): void; /** * Handle an incoming `announcement_signatures` message from the given peer. */ handle_announcement_signatures(their_node_id: Uint8Array, msg: AnnouncementSignatures): void; /** * Indicates a connection to the peer failed/an existing connection was lost. */ peer_disconnected(their_node_id: Uint8Array): void; /** * Handle a peer reconnecting, possibly generating `channel_reestablish` message(s). * * May return an `Err(())` if the features the peer supports are not sufficient to communicate * with us. Implementors should be somewhat conservative about doing so, however, as other * message handlers may still wish to communicate with this peer. * * [`Self::peer_disconnected`] will not be called if `Err(())` is returned. */ peer_connected(their_node_id: Uint8Array, msg: Init, inbound: boolean): Result_NoneNoneZ; /** * Handle an incoming `channel_reestablish` message from the given peer. */ handle_channel_reestablish(their_node_id: Uint8Array, msg: ChannelReestablish): void; /** * Handle an incoming `channel_update` message from the given peer. */ handle_channel_update(their_node_id: Uint8Array, msg: ChannelUpdate): void; /** * Handle an incoming `error` message from the given peer. */ handle_error(their_node_id: Uint8Array, msg: ErrorMessage): void; /** * Gets the node feature flags which this handler itself supports. All available handlers are * queried similarly and their feature flags are OR'd together to form the [`NodeFeatures`] * which are broadcasted in our [`NodeAnnouncement`] message. */ provided_node_features(): NodeFeatures; /** * Gets the init feature flags which should be sent to the given peer. All available handlers * are queried similarly and their feature flags are OR'd together to form the [`InitFeatures`] * which are sent in our [`Init`] message. * * Note that this method is called before [`Self::peer_connected`]. */ provided_init_features(their_node_id: Uint8Array): InitFeatures; /** * Gets the chain hashes for this `ChannelMessageHandler` indicating which chains it supports. * * If it's `None`, then no particular network chain hash compatibility will be enforced when * connecting to peers. */ get_chain_hashes(): Option_CVec_ThirtyTwoBytesZZ; /** * Indicates that a message was received from any peer for any handler. * Called before the message is passed to the appropriate handler. * Useful for indicating that a network connection is active. * * Note: Since this function is called frequently, it should be as * efficient as possible for its intended purpose. */ message_received(): void; }