3 import CommonBase from './CommonBase';
4 import * as bindings from '../bindings' // TODO: figure out location
8 export class ChannelMessageHandler extends CommonBase {
10 bindings_instance?: bindings.LDKChannelMessageHandler;
12 constructor(ptr?: number, arg?: bindings.LDKChannelMessageHandler, messageSendEventsProvider?: bindings.LDKMessageSendEventsProvider) {
13 if (Number.isFinite(ptr)) {
15 this.bindings_instance = null;
17 // TODO: private constructor instantiation
18 super(bindings.LDKChannelMessageHandler_new(arg, messageSendEventsProvider));
19 this.ptrs_to.push(arg);
20 this.ptrs_to.push(messageSendEventsProvider);
25 protected finalize() {
27 bindings.ChannelMessageHandler_free(this.ptr);
32 static new_impl(arg: ChannelMessageHandlerInterface, messageSendEventsProvider_impl: MessageSendEventsProvider.MessageSendEventsProviderInterface): ChannelMessageHandler {
33 const impl_holder: LDKChannelMessageHandlerHolder = new LDKChannelMessageHandlerHolder();
34 let structImplementation = <bindings.LDKChannelMessageHandler>{
35 // todo: in-line interface filling
36 handle_open_channel (their_node_id: Uint8Array, their_features: number, msg: number): void {
37 const their_features_hu_conv: InitFeatures = new InitFeatures(null, their_features);
38 their_features_hu_conv.ptrs_to.add(this);
39 const msg_hu_conv: OpenChannel = new OpenChannel(null, msg);
40 arg.handle_open_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
43 handle_accept_channel (their_node_id: Uint8Array, their_features: number, msg: number): void {
44 const their_features_hu_conv: InitFeatures = new InitFeatures(null, their_features);
45 their_features_hu_conv.ptrs_to.add(this);
46 const msg_hu_conv: AcceptChannel = new AcceptChannel(null, msg);
47 arg.handle_accept_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
50 handle_funding_created (their_node_id: Uint8Array, msg: number): void {
51 const msg_hu_conv: FundingCreated = new FundingCreated(null, msg);
52 arg.handle_funding_created(their_node_id, msg_hu_conv);
55 handle_funding_signed (their_node_id: Uint8Array, msg: number): void {
56 const msg_hu_conv: FundingSigned = new FundingSigned(null, msg);
57 arg.handle_funding_signed(their_node_id, msg_hu_conv);
60 handle_funding_locked (their_node_id: Uint8Array, msg: number): void {
61 const msg_hu_conv: FundingLocked = new FundingLocked(null, msg);
62 arg.handle_funding_locked(their_node_id, msg_hu_conv);
65 handle_shutdown (their_node_id: Uint8Array, their_features: number, msg: number): void {
66 const their_features_hu_conv: InitFeatures = new InitFeatures(null, their_features);
67 const msg_hu_conv: Shutdown = new Shutdown(null, msg);
68 arg.handle_shutdown(their_node_id, their_features_hu_conv, msg_hu_conv);
71 handle_closing_signed (their_node_id: Uint8Array, msg: number): void {
72 const msg_hu_conv: ClosingSigned = new ClosingSigned(null, msg);
73 arg.handle_closing_signed(their_node_id, msg_hu_conv);
76 handle_update_add_htlc (their_node_id: Uint8Array, msg: number): void {
77 const msg_hu_conv: UpdateAddHTLC = new UpdateAddHTLC(null, msg);
78 arg.handle_update_add_htlc(their_node_id, msg_hu_conv);
81 handle_update_fulfill_htlc (their_node_id: Uint8Array, msg: number): void {
82 const msg_hu_conv: UpdateFulfillHTLC = new UpdateFulfillHTLC(null, msg);
83 arg.handle_update_fulfill_htlc(their_node_id, msg_hu_conv);
86 handle_update_fail_htlc (their_node_id: Uint8Array, msg: number): void {
87 const msg_hu_conv: UpdateFailHTLC = new UpdateFailHTLC(null, msg);
88 arg.handle_update_fail_htlc(their_node_id, msg_hu_conv);
91 handle_update_fail_malformed_htlc (their_node_id: Uint8Array, msg: number): void {
92 const msg_hu_conv: UpdateFailMalformedHTLC = new UpdateFailMalformedHTLC(null, msg);
93 arg.handle_update_fail_malformed_htlc(their_node_id, msg_hu_conv);
96 handle_commitment_signed (their_node_id: Uint8Array, msg: number): void {
97 const msg_hu_conv: CommitmentSigned = new CommitmentSigned(null, msg);
98 arg.handle_commitment_signed(their_node_id, msg_hu_conv);
101 handle_revoke_and_ack (their_node_id: Uint8Array, msg: number): void {
102 const msg_hu_conv: RevokeAndACK = new RevokeAndACK(null, msg);
103 arg.handle_revoke_and_ack(their_node_id, msg_hu_conv);
106 handle_update_fee (their_node_id: Uint8Array, msg: number): void {
107 const msg_hu_conv: UpdateFee = new UpdateFee(null, msg);
108 arg.handle_update_fee(their_node_id, msg_hu_conv);
111 handle_announcement_signatures (their_node_id: Uint8Array, msg: number): void {
112 const msg_hu_conv: AnnouncementSignatures = new AnnouncementSignatures(null, msg);
113 arg.handle_announcement_signatures(their_node_id, msg_hu_conv);
116 peer_disconnected (their_node_id: Uint8Array, no_connection_possible: boolean): void {
117 arg.peer_disconnected(their_node_id, no_connection_possible);
120 peer_connected (their_node_id: Uint8Array, msg: number): void {
121 const msg_hu_conv: Init = new Init(null, msg);
122 arg.peer_connected(their_node_id, msg_hu_conv);
125 handle_channel_reestablish (their_node_id: Uint8Array, msg: number): void {
126 const msg_hu_conv: ChannelReestablish = new ChannelReestablish(null, msg);
127 arg.handle_channel_reestablish(their_node_id, msg_hu_conv);
130 handle_channel_update (their_node_id: Uint8Array, msg: number): void {
131 const msg_hu_conv: ChannelUpdate = new ChannelUpdate(null, msg);
132 arg.handle_channel_update(their_node_id, msg_hu_conv);
135 handle_error (their_node_id: Uint8Array, msg: number): void {
136 const msg_hu_conv: ErrorMessage = new ErrorMessage(null, msg);
137 arg.handle_error(their_node_id, msg_hu_conv);
142 impl_holder.held = new ChannelMessageHandler (null, structImplementation, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance);
146 export interface ChannelMessageHandlerInterface {
147 handle_open_channel(their_node_id: Uint8Array, their_features: InitFeatures, msg: OpenChannel): void;
148 handle_accept_channel(their_node_id: Uint8Array, their_features: InitFeatures, msg: AcceptChannel): void;
149 handle_funding_created(their_node_id: Uint8Array, msg: FundingCreated): void;
150 handle_funding_signed(their_node_id: Uint8Array, msg: FundingSigned): void;
151 handle_funding_locked(their_node_id: Uint8Array, msg: FundingLocked): void;
152 handle_shutdown(their_node_id: Uint8Array, their_features: InitFeatures, msg: Shutdown): void;
153 handle_closing_signed(their_node_id: Uint8Array, msg: ClosingSigned): void;
154 handle_update_add_htlc(their_node_id: Uint8Array, msg: UpdateAddHTLC): void;
155 handle_update_fulfill_htlc(their_node_id: Uint8Array, msg: UpdateFulfillHTLC): void;
156 handle_update_fail_htlc(their_node_id: Uint8Array, msg: UpdateFailHTLC): void;
157 handle_update_fail_malformed_htlc(their_node_id: Uint8Array, msg: UpdateFailMalformedHTLC): void;
158 handle_commitment_signed(their_node_id: Uint8Array, msg: CommitmentSigned): void;
159 handle_revoke_and_ack(their_node_id: Uint8Array, msg: RevokeAndACK): void;
160 handle_update_fee(their_node_id: Uint8Array, msg: UpdateFee): void;
161 handle_announcement_signatures(their_node_id: Uint8Array, msg: AnnouncementSignatures): void;
162 peer_disconnected(their_node_id: Uint8Array, no_connection_possible: boolean): void;
163 peer_connected(their_node_id: Uint8Array, msg: Init): void;
164 handle_channel_reestablish(their_node_id: Uint8Array, msg: ChannelReestablish): void;
165 handle_channel_update(their_node_id: Uint8Array, msg: ChannelUpdate): void;
166 handle_error(their_node_id: Uint8Array, msg: ErrorMessage): void;
170 class LDKChannelMessageHandlerHolder {
171 held: ChannelMessageHandler;
173 public void handle_open_channel(Uint8Array their_node_id, InitFeatures their_features, OpenChannel msg) {
174 bindings.ChannelMessageHandler_handle_open_channel(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
175 this.ptrs_to.add(their_features);
176 this.ptrs_to.add(msg);
179 public void handle_accept_channel(Uint8Array their_node_id, InitFeatures their_features, AcceptChannel msg) {
180 bindings.ChannelMessageHandler_handle_accept_channel(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
181 this.ptrs_to.add(their_features);
182 this.ptrs_to.add(msg);
185 public void handle_funding_created(Uint8Array their_node_id, FundingCreated msg) {
186 bindings.ChannelMessageHandler_handle_funding_created(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
187 this.ptrs_to.add(msg);
190 public void handle_funding_signed(Uint8Array their_node_id, FundingSigned msg) {
191 bindings.ChannelMessageHandler_handle_funding_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
192 this.ptrs_to.add(msg);
195 public void handle_funding_locked(Uint8Array their_node_id, FundingLocked msg) {
196 bindings.ChannelMessageHandler_handle_funding_locked(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
197 this.ptrs_to.add(msg);
200 public void handle_shutdown(Uint8Array their_node_id, InitFeatures their_features, Shutdown msg) {
201 bindings.ChannelMessageHandler_handle_shutdown(this.ptr, their_node_id, their_features == null ? 0 : their_features.ptr & ~1, msg == null ? 0 : msg.ptr & ~1);
202 this.ptrs_to.add(their_features);
203 this.ptrs_to.add(msg);
206 public void handle_closing_signed(Uint8Array their_node_id, ClosingSigned msg) {
207 bindings.ChannelMessageHandler_handle_closing_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
208 this.ptrs_to.add(msg);
211 public void handle_update_add_htlc(Uint8Array their_node_id, UpdateAddHTLC msg) {
212 bindings.ChannelMessageHandler_handle_update_add_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
213 this.ptrs_to.add(msg);
216 public void handle_update_fulfill_htlc(Uint8Array their_node_id, UpdateFulfillHTLC msg) {
217 bindings.ChannelMessageHandler_handle_update_fulfill_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
218 this.ptrs_to.add(msg);
221 public void handle_update_fail_htlc(Uint8Array their_node_id, UpdateFailHTLC msg) {
222 bindings.ChannelMessageHandler_handle_update_fail_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
223 this.ptrs_to.add(msg);
226 public void handle_update_fail_malformed_htlc(Uint8Array their_node_id, UpdateFailMalformedHTLC msg) {
227 bindings.ChannelMessageHandler_handle_update_fail_malformed_htlc(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
228 this.ptrs_to.add(msg);
231 public void handle_commitment_signed(Uint8Array their_node_id, CommitmentSigned msg) {
232 bindings.ChannelMessageHandler_handle_commitment_signed(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
233 this.ptrs_to.add(msg);
236 public void handle_revoke_and_ack(Uint8Array their_node_id, RevokeAndACK msg) {
237 bindings.ChannelMessageHandler_handle_revoke_and_ack(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
238 this.ptrs_to.add(msg);
241 public void handle_update_fee(Uint8Array their_node_id, UpdateFee msg) {
242 bindings.ChannelMessageHandler_handle_update_fee(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
243 this.ptrs_to.add(msg);
246 public void handle_announcement_signatures(Uint8Array their_node_id, AnnouncementSignatures msg) {
247 bindings.ChannelMessageHandler_handle_announcement_signatures(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
248 this.ptrs_to.add(msg);
251 public void peer_disconnected(Uint8Array their_node_id, boolean no_connection_possible) {
252 bindings.ChannelMessageHandler_peer_disconnected(this.ptr, their_node_id, no_connection_possible);
255 public void peer_connected(Uint8Array their_node_id, Init msg) {
256 bindings.ChannelMessageHandler_peer_connected(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
257 this.ptrs_to.add(msg);
260 public void handle_channel_reestablish(Uint8Array their_node_id, ChannelReestablish msg) {
261 bindings.ChannelMessageHandler_handle_channel_reestablish(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
262 this.ptrs_to.add(msg);
265 public void handle_channel_update(Uint8Array their_node_id, ChannelUpdate msg) {
266 bindings.ChannelMessageHandler_handle_channel_update(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
267 this.ptrs_to.add(msg);
270 public void handle_error(Uint8Array their_node_id, ErrorMessage msg) {
271 bindings.ChannelMessageHandler_handle_error(this.ptr, their_node_id, msg == null ? 0 : msg.ptr & ~1);
272 this.ptrs_to.add(msg);