} as ldk.LoggerInterface);
const persister = ldk.Persist.new_impl({
- persist_new_channel(channel_id: ldk.OutPoint, data: ldk.ChannelMonitor, update_id: ldk.MonitorUpdateId): ldk.Result_NoneChannelMonitorUpdateErrZ {
- return ldk.Result_NoneChannelMonitorUpdateErrZ.constructor_ok();
+ persist_new_channel(channel_id: ldk.OutPoint, data: ldk.ChannelMonitor, update_id: ldk.MonitorUpdateId): ldk.ChannelMonitorUpdateStatus {
+ return ldk.ChannelMonitorUpdateStatus.LDKChannelMonitorUpdateStatus_Completed;
},
- update_persisted_channel(channel_id: ldk.OutPoint, update: ldk.ChannelMonitorUpdate, data: ldk.ChannelMonitor, update_id: ldk.MonitorUpdateId): ldk.Result_NoneChannelMonitorUpdateErrZ {
- return ldk.Result_NoneChannelMonitorUpdateErrZ.constructor_ok();
+ update_persisted_channel(channel_id: ldk.OutPoint, update: ldk.ChannelMonitorUpdate, data: ldk.ChannelMonitor, update_id: ldk.MonitorUpdateId): ldk.ChannelMonitorUpdateStatus {
+ return ldk.ChannelMonitorUpdateStatus.LDKChannelMonitorUpdateStatus_Completed;
}
} as ldk.PersistInterface);
const msg = msgs[j];
if (msg instanceof ldk.MessageSendEvent_SendOpenChannel) {
if (!array_eq(msg.node_id, to.get_our_node_id())) return false;
- to.as_ChannelMessageHandler().handle_open_channel(from.get_our_node_id(), ldk.InitFeatures.constructor_known(), msg.msg);
+ const features = from.as_ChannelMessageHandler().provided_init_features(to.get_our_node_id());
+ to.as_ChannelMessageHandler().handle_open_channel(from.get_our_node_id(), features, msg.msg);
} else if (msg instanceof ldk.MessageSendEvent_SendAcceptChannel) {
if (!array_eq(msg.node_id, to.get_our_node_id())) return false;
- to.as_ChannelMessageHandler().handle_accept_channel(from.get_our_node_id(), ldk.InitFeatures.constructor_known(), msg.msg);
+ const features = from.as_ChannelMessageHandler().provided_init_features(to.get_our_node_id());
+ to.as_ChannelMessageHandler().handle_accept_channel(from.get_our_node_id(), features, msg.msg);
} else if (msg instanceof ldk.MessageSendEvent_SendFundingCreated) {
if (!array_eq(msg.node_id, to.get_our_node_id())) return false;
to.as_ChannelMessageHandler().handle_funding_created(from.get_our_node_id(), msg.msg);
const a = get_chanman();
const b = get_chanman();
- a.chan_man.as_ChannelMessageHandler().peer_connected(b.chan_man.get_our_node_id(), ldk.Init.constructor_new(ldk.InitFeatures.constructor_known(), ldk.Option_NetAddressZ.constructor_none()));
- b.chan_man.as_ChannelMessageHandler().peer_connected(a.chan_man.get_our_node_id(), ldk.Init.constructor_new(ldk.InitFeatures.constructor_known(), ldk.Option_NetAddressZ.constructor_none()));
+ const features = a.chan_man.as_ChannelMessageHandler().provided_init_features(b.chan_man.get_our_node_id());
+
+ a.chan_man.as_ChannelMessageHandler().peer_connected(b.chan_man.get_our_node_id(), ldk.Init.constructor_new(features, ldk.Option_NetAddressZ.constructor_none()));
+ b.chan_man.as_ChannelMessageHandler().peer_connected(a.chan_man.get_our_node_id(), ldk.Init.constructor_new(features, ldk.Option_NetAddressZ.constructor_none()));
const chan_create_err = a.chan_man.create_channel(b.chan_man.get_our_node_id(), BigInt(0), BigInt(400), BigInt(0), ldk.UserConfig.constructor_default());
if (chan_create_err.is_ok()) return false;
const b = get_chanman();
const ignorer = ldk.IgnoringMessageHandler.constructor_new();
- const pm_a = ldk.PeerManager.constructor_new(a.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), ignorer.as_OnionMessageHandler(), a.node_secret, 0xdeadbeefn, a.node_secret, a.logger, ignorer.as_CustomMessageHandler());
- const pm_b = ldk.PeerManager.constructor_new(b.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), ignorer.as_OnionMessageHandler(), b.node_secret, 0xdeadbeefn, b.node_secret, b.logger, ignorer.as_CustomMessageHandler());
+ const pm_a = ldk.PeerManager.constructor_new(a.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), ignorer.as_OnionMessageHandler(), a.node_secret, 0xdeadbeef, a.node_secret, a.logger, ignorer.as_CustomMessageHandler());
+ const pm_b = ldk.PeerManager.constructor_new(b.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), ignorer.as_OnionMessageHandler(), b.node_secret, 0xdeadbeef, b.node_secret, b.logger, ignorer.as_CustomMessageHandler());
var sock_b: ldk.SocketDescriptor;
const sock_a = ldk.SocketDescriptor.new_impl({
const ignorer = ldk.IgnoringMessageHandler.constructor_new();
- const underlying_om_a = ldk.OnionMessenger.constructor_new(a.keys_interface, a.logger);
+ var a_handled_msg = false;
+ const om_handler_a = ldk.CustomOnionMessageHandler.new_impl({
+ read_custom_message(message_type: bigint, buffer: Uint8Array): ldk.Result_COption_CustomOnionMessageContentsZDecodeErrorZ {
+ console.assert(message_type == 4343n);
+ console.assert(buffer.length == 44);
+ for (var i = 0; i < 44; i++) console.assert(buffer[i] == 67);
+ return ldk.Result_COption_CustomOnionMessageContentsZDecodeErrorZ.constructor_ok(ldk.Option_CustomOnionMessageContentsZ.constructor_some(ldk.CustomOnionMessageContents.new_impl({
+ tlv_type(): bigint { return 9998n; },
+ write(): Uint8Array { console.assert(false); return null; }
+ } as ldk.CustomOnionMessageContentsInterface)));
+ },
+ handle_custom_message(msg: ldk.CustomOnionMessageContents) {
+ console.assert(msg.tlv_type() == 9998n);
+ a_handled_msg = true;
+ },
+ } as ldk.CustomOnionMessageHandlerInterface);
+
+ const underlying_om_a = ldk.OnionMessenger.constructor_new(a.keys_interface, a.logger, om_handler_a);
const om_provider_a = {
next_onion_message_for_peer(peer_node_id: Uint8Array): ldk.OnionMessage {
return underlying_om_a.as_OnionMessageProvider().next_onion_message_for_peer(peer_node_id);
handle_onion_message(peer_node_id: Uint8Array, msg: ldk.OnionMessage) {
underlying_om_a.as_OnionMessageHandler().handle_onion_message(peer_node_id, msg);
},
- peer_connected(their_node_id: Uint8Array, init: ldk.Init) {
- underlying_om_a.as_OnionMessageHandler().peer_connected(their_node_id, init);
+ peer_connected(their_node_id: Uint8Array, init: ldk.Init): ldk.Result_NoneNoneZ {
+ return underlying_om_a.as_OnionMessageHandler().peer_connected(their_node_id, init)
},
peer_disconnected(their_node_id: Uint8Array, no_connection_possible: boolean) {
underlying_om_a.as_OnionMessageHandler().peer_disconnected(their_node_id, no_connection_possible);
}
} as ldk.OnionMessageHandlerInterface, om_provider_a);
- const om_b = ldk.OnionMessenger.constructor_new(b.keys_interface, b.logger);
+ var b_handled_msg = false;
+ const om_handler_b = ldk.CustomOnionMessageHandler.new_impl({
+ read_custom_message(message_type: bigint, buffer: Uint8Array): ldk.Result_COption_CustomOnionMessageContentsZDecodeErrorZ {
+ console.assert(message_type == 4242n);
+ console.assert(buffer.length == 43);
+ for (var i = 0; i < 43; i++) console.assert(buffer[i] == 66);
+ return ldk.Result_COption_CustomOnionMessageContentsZDecodeErrorZ.constructor_ok(ldk.Option_CustomOnionMessageContentsZ.constructor_some(ldk.CustomOnionMessageContents.new_impl({
+ tlv_type(): bigint { return 9999n; },
+ write(): Uint8Array { console.assert(false); return null; }
+ } as ldk.CustomOnionMessageContentsInterface)));
+ },
+ handle_custom_message(msg: ldk.CustomOnionMessageContents) {
+ console.assert(msg.tlv_type() == 9999n);
+ b_handled_msg = true;
+ },
+ } as ldk.CustomOnionMessageHandlerInterface);
+ const om_b = ldk.OnionMessenger.constructor_new(b.keys_interface, b.logger, om_handler_b);
- const pm_a = ldk.PeerManager.constructor_new(a.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), om_a, a.node_secret, 0xdeadbeefn, a.node_secret, a.logger, ignorer.as_CustomMessageHandler());
- const pm_b = ldk.PeerManager.constructor_new(b.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), om_b.as_OnionMessageHandler(), b.node_secret, 0xdeadbeefn, b.node_secret, b.logger, ignorer.as_CustomMessageHandler());
+ const pm_a = ldk.PeerManager.constructor_new(a.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), om_a, a.node_secret, 0xdeadbeef, a.node_secret, a.logger, ignorer.as_CustomMessageHandler());
+ const pm_b = ldk.PeerManager.constructor_new(b.chan_man.as_ChannelMessageHandler(), ignorer.as_RoutingMessageHandler(), om_b.as_OnionMessageHandler(), b.node_secret, 0xdeadbeef, b.node_secret, b.logger, ignorer.as_CustomMessageHandler());
var sock_b: ldk.SocketDescriptor;
const sock_a = ldk.SocketDescriptor.new_impl({
console.assert(pm_a.get_peer_node_ids().length == 1);
console.assert(pm_b.get_peer_node_ids().length == 1);
- underlying_om_a.send_onion_message([], ldk.Destination.constructor_node(b.node_id), null);
+ underlying_om_a.send_custom_onion_message([], ldk.Destination.constructor_node(b.node_id), ldk.CustomOnionMessageContents.new_impl({
+ tlv_type(): bigint { return 4242n; },
+ write(): Uint8Array {
+ const ret = new Uint8Array(43);
+ for (var i = 0; i < 43; i++) ret[i] = 66;
+ return ret;
+ }
+ } as ldk.CustomOnionMessageContentsInterface), null);
pm_a.process_events();
- om_b.send_onion_message([], ldk.Destination.constructor_node(a.node_id), null);
+ console.assert(b_handled_msg);
+
+ om_b.send_custom_onion_message([], ldk.Destination.constructor_node(a.node_id), ldk.CustomOnionMessageContents.new_impl({
+ tlv_type(): bigint { return 4343n; },
+ write(): Uint8Array {
+ const ret = new Uint8Array(44);
+ for (var i = 0; i < 44; i++) ret[i] = 67;
+ return ret;
+ }
+ } as ldk.CustomOnionMessageContentsInterface), null);
pm_b.process_events();
-
- // TODO: Once OnionMessenger supports actually passing messages up, check that we received the
- // messages here.
+ console.assert(a_handled_msg);
return true;
});