From b2b0222f51397c5d7e0b3bf0cad6439edde3c1f3 Mon Sep 17 00:00:00 2001 From: Matt Corallo Date: Sat, 24 Oct 2020 18:11:18 -0400 Subject: [PATCH] Properly handle java refs in traits returning traits --- genbindings.py | 14 ++++++++------ src/main/java/org/ldk/structs/Access.java | 7 +++++-- .../java/org/ldk/structs/BroadcasterInterface.java | 7 +++++-- src/main/java/org/ldk/structs/ChannelKeys.java | 7 +++++-- .../org/ldk/structs/ChannelMessageHandler.java | 9 ++++++--- src/main/java/org/ldk/structs/EventsProvider.java | 9 ++++++--- src/main/java/org/ldk/structs/FeeEstimator.java | 7 +++++-- src/main/java/org/ldk/structs/Filter.java | 7 +++++-- src/main/java/org/ldk/structs/KeysInterface.java | 9 ++++++--- src/main/java/org/ldk/structs/Logger.java | 7 +++++-- .../org/ldk/structs/MessageSendEventsProvider.java | 9 ++++++--- .../ldk/structs/PreCalculatedTxCreationKeys.java | 7 +++++++ .../org/ldk/structs/RoutingMessageHandler.java | 11 +++++++---- .../java/org/ldk/structs/SocketDescriptor.java | 7 +++++-- src/main/java/org/ldk/structs/Watch.java | 9 ++++++--- 15 files changed, 87 insertions(+), 39 deletions(-) diff --git a/genbindings.py b/genbindings.py index 3c923511..d96447bd 100755 --- a/genbindings.py +++ b/genbindings.py @@ -1224,15 +1224,17 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: out_java_trait.write("\t\tif (ptr != 0) { bindings." + struct_name.replace("LDK","") + "_free(ptr); } super.finalize();\n") out_java_trait.write("\t}\n\n") - java_trait_constr = "\tpublic " + struct_name.replace("LDK", "") + "(" + struct_name.replace("LDK", "") + "Interface arg" + java_trait_constr = "\tprivate static class " + struct_name + "Holder { " + struct_name.replace("LDK", "") + " held; }\n" + java_trait_constr = java_trait_constr + "\tpublic static " + struct_name.replace("LDK", "") + " new_impl(" + struct_name.replace("LDK", "") + "Interface arg" for idx, var_line in enumerate(field_var_lines): if var_line.group(1) in trait_structs: # Ideally we'd be able to take any instance of the interface, but our C code can only represent # Java-implemented version, so we require users pass a Java implementation here :/ - java_trait_constr = java_trait_constr + ", " + var_line.group(1).replace("LDK", "") + "." + var_line.group(1).replace("LDK", "") + "Interface " + var_line.group(2) + java_trait_constr = java_trait_constr + ", " + var_line.group(1).replace("LDK", "") + "." + var_line.group(1).replace("LDK", "") + "Interface " + var_line.group(2) + "_impl" else: java_trait_constr = java_trait_constr + ", " + field_var_convs[idx].java_hu_ty + " " + var_line.group(2) - java_trait_constr = java_trait_constr + ") {\n\t\tthis(new bindings." + struct_name + "() {\n" + java_trait_constr = java_trait_constr + ") {\n\t\tfinal " + struct_name + "Holder impl_holder = new " + struct_name + "Holder();\n" + java_trait_constr = java_trait_constr + "\t\timpl_holder.held = new " + struct_name.replace("LDK", "") + "(new bindings." + struct_name + "() {\n" out_java_trait.write("\tpublic static interface " + struct_name.replace("LDK", "") + "Interface {\n") out_java.write("\tpublic interface " + struct_name + " {\n") java_meths = [] @@ -1319,7 +1321,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: if ret_ty_info.from_hu_conv is not None: java_trait_constr = java_trait_constr + "\t\t\t\t" + ret_ty_info.java_ty + " result = " + ret_ty_info.from_hu_conv[0] + ";\n" if ret_ty_info.from_hu_conv[1] != "": - java_trait_constr = java_trait_constr + "\t\t\t\t//TODO: May need to call: " + ret_ty_info.from_hu_conv[1] + ";\n" + java_trait_constr = java_trait_constr + "\t\t\t\t" + ret_ty_info.from_hu_conv[1].replace("this", "impl_holder.held") + ";\n" if is_common_base_ext(ret_ty_info.rust_obj): java_trait_constr = java_trait_constr + "\t\t\t\tret.ptr = 0;\n" java_trait_constr = java_trait_constr + "\t\t\t\treturn result;\n" @@ -1338,11 +1340,11 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: java_trait_constr = java_trait_constr + "\t\t}" for var_line in field_var_lines: if var_line.group(1) in trait_structs: - java_trait_constr = java_trait_constr + ", new " + var_line.group(2) + "(" + var_line.group(2) + ").bindings_instance" + java_trait_constr = java_trait_constr + ", " + var_line.group(2) + ".new_impl(" + var_line.group(2) + "_impl).bindings_instance" else: java_trait_constr = java_trait_constr + ", " + var_line.group(2) out_java_trait.write("\t}\n") - out_java_trait.write(java_trait_constr + ");\n\t}\n") + out_java_trait.write(java_trait_constr + ");\n\t\treturn impl_holder.held;\n\t}\n") # Write out a clone function whether we need one or not, as we use them in moving to rust write_c("static void* " + struct_name + "_JCalls_clone(const void* this_arg) {\n") diff --git a/src/main/java/org/ldk/structs/Access.java b/src/main/java/org/ldk/structs/Access.java index 15b3d742..7a9b89c0 100644 --- a/src/main/java/org/ldk/structs/Access.java +++ b/src/main/java/org/ldk/structs/Access.java @@ -22,8 +22,10 @@ public class Access extends CommonBase { public static interface AccessInterface { Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id); } - public Access(AccessInterface arg) { - this(new bindings.LDKAccess() { + private static class LDKAccessHolder { Access held; } + public static Access new_impl(AccessInterface arg) { + final LDKAccessHolder impl_holder = new LDKAccessHolder(); + impl_holder.held = new Access(new bindings.LDKAccess() { @Override public long get_utxo(byte[] genesis_hash, long short_channel_id) { Result_TxOutAccessErrorZ ret = arg.get_utxo(genesis_hash, short_channel_id); long result = ret != null ? ret.ptr : 0; @@ -31,6 +33,7 @@ public class Access extends CommonBase { return result; } }); + return impl_holder.held; } public Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id) { long ret = bindings.Access_get_utxo(this.ptr, genesis_hash, short_channel_id); diff --git a/src/main/java/org/ldk/structs/BroadcasterInterface.java b/src/main/java/org/ldk/structs/BroadcasterInterface.java index b2541a83..64979fec 100644 --- a/src/main/java/org/ldk/structs/BroadcasterInterface.java +++ b/src/main/java/org/ldk/structs/BroadcasterInterface.java @@ -22,13 +22,16 @@ public class BroadcasterInterface extends CommonBase { public static interface BroadcasterInterfaceInterface { void broadcast_transaction(Transaction tx); } - public BroadcasterInterface(BroadcasterInterfaceInterface arg) { - this(new bindings.LDKBroadcasterInterface() { + private static class LDKBroadcasterInterfaceHolder { BroadcasterInterface held; } + public static BroadcasterInterface new_impl(BroadcasterInterfaceInterface arg) { + final LDKBroadcasterInterfaceHolder impl_holder = new LDKBroadcasterInterfaceHolder(); + impl_holder.held = new BroadcasterInterface(new bindings.LDKBroadcasterInterface() { @Override public void broadcast_transaction(long tx) { Transaction tx_conv = new Transaction(null, tx); arg.broadcast_transaction(tx_conv); } }); + return impl_holder.held; } public void broadcast_transaction(Transaction tx) { bindings.BroadcasterInterface_broadcast_transaction(this.ptr, tx.ptr); diff --git a/src/main/java/org/ldk/structs/ChannelKeys.java b/src/main/java/org/ldk/structs/ChannelKeys.java index d2e8ff22..7283363a 100644 --- a/src/main/java/org/ldk/structs/ChannelKeys.java +++ b/src/main/java/org/ldk/structs/ChannelKeys.java @@ -33,8 +33,10 @@ public class ChannelKeys extends CommonBase { Result_SignatureNoneZ sign_channel_announcement(UnsignedChannelAnnouncement msg); void on_accept(ChannelPublicKeys channel_points, short counterparty_selected_contest_delay, short holder_selected_contest_delay); } - public ChannelKeys(ChannelKeysInterface arg, ChannelPublicKeys pubkeys) { - this(new bindings.LDKChannelKeys() { + private static class LDKChannelKeysHolder { ChannelKeys held; } + public static ChannelKeys new_impl(ChannelKeysInterface arg, ChannelPublicKeys pubkeys) { + final LDKChannelKeysHolder impl_holder = new LDKChannelKeysHolder(); + impl_holder.held = new ChannelKeys(new bindings.LDKChannelKeys() { @Override public byte[] get_per_commitment_point(long idx) { byte[] ret = arg.get_per_commitment_point(idx); return ret; @@ -111,6 +113,7 @@ public class ChannelKeys extends CommonBase { arg.on_accept(channel_points_hu_conv, counterparty_selected_contest_delay, holder_selected_contest_delay); } }, pubkeys); + return impl_holder.held; } public byte[] get_per_commitment_point(long idx) { byte[] ret = bindings.ChannelKeys_get_per_commitment_point(this.ptr, idx); diff --git a/src/main/java/org/ldk/structs/ChannelMessageHandler.java b/src/main/java/org/ldk/structs/ChannelMessageHandler.java index 5dc8103c..d286901e 100644 --- a/src/main/java/org/ldk/structs/ChannelMessageHandler.java +++ b/src/main/java/org/ldk/structs/ChannelMessageHandler.java @@ -41,8 +41,10 @@ public class ChannelMessageHandler extends CommonBase { void handle_channel_reestablish(byte[] their_node_id, ChannelReestablish msg); void handle_error(byte[] their_node_id, ErrorMessage msg); } - public ChannelMessageHandler(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider) { - this(new bindings.LDKChannelMessageHandler() { + private static class LDKChannelMessageHandlerHolder { ChannelMessageHandler held; } + public static ChannelMessageHandler new_impl(ChannelMessageHandlerInterface arg, MessageSendEventsProvider.MessageSendEventsProviderInterface MessageSendEventsProvider_impl) { + final LDKChannelMessageHandlerHolder impl_holder = new LDKChannelMessageHandlerHolder(); + impl_holder.held = new ChannelMessageHandler(new bindings.LDKChannelMessageHandler() { @Override public void handle_open_channel(byte[] their_node_id, long their_features, long msg) { InitFeatures their_features_hu_conv = new InitFeatures(null, their_features); OpenChannel msg_hu_conv = new OpenChannel(null, msg); @@ -120,7 +122,8 @@ public class ChannelMessageHandler extends CommonBase { ErrorMessage msg_hu_conv = new ErrorMessage(null, msg); arg.handle_error(their_node_id, msg_hu_conv); } - }, new MessageSendEventsProvider(MessageSendEventsProvider).bindings_instance); + }, MessageSendEventsProvider.new_impl(MessageSendEventsProvider_impl).bindings_instance); + return impl_holder.held; } // Skipped ChannelMessageHandler_handle_open_channel // Skipped ChannelMessageHandler_handle_accept_channel diff --git a/src/main/java/org/ldk/structs/EventsProvider.java b/src/main/java/org/ldk/structs/EventsProvider.java index be33c915..f7218d2b 100644 --- a/src/main/java/org/ldk/structs/EventsProvider.java +++ b/src/main/java/org/ldk/structs/EventsProvider.java @@ -22,15 +22,18 @@ public class EventsProvider extends CommonBase { public static interface EventsProviderInterface { Event[] get_and_clear_pending_events(); } - public EventsProvider(EventsProviderInterface arg) { - this(new bindings.LDKEventsProvider() { + private static class LDKEventsProviderHolder { EventsProvider held; } + public static EventsProvider new_impl(EventsProviderInterface arg) { + final LDKEventsProviderHolder impl_holder = new LDKEventsProviderHolder(); + impl_holder.held = new EventsProvider(new bindings.LDKEventsProvider() { @Override public long[] get_and_clear_pending_events() { Event[] ret = arg.get_and_clear_pending_events(); long[] result = Arrays.stream(ret).mapToLong(arr_conv_7 -> arr_conv_7.ptr).toArray(); - //TODO: May need to call: /* TODO 2 Event */; + /* TODO 2 Event */; return result; } }); + return impl_holder.held; } public Event[] get_and_clear_pending_events() { long[] ret = bindings.EventsProvider_get_and_clear_pending_events(this.ptr); diff --git a/src/main/java/org/ldk/structs/FeeEstimator.java b/src/main/java/org/ldk/structs/FeeEstimator.java index dd7c05f2..910edae7 100644 --- a/src/main/java/org/ldk/structs/FeeEstimator.java +++ b/src/main/java/org/ldk/structs/FeeEstimator.java @@ -22,13 +22,16 @@ public class FeeEstimator extends CommonBase { public static interface FeeEstimatorInterface { int get_est_sat_per_1000_weight(LDKConfirmationTarget confirmation_target); } - public FeeEstimator(FeeEstimatorInterface arg) { - this(new bindings.LDKFeeEstimator() { + private static class LDKFeeEstimatorHolder { FeeEstimator held; } + public static FeeEstimator new_impl(FeeEstimatorInterface arg) { + final LDKFeeEstimatorHolder impl_holder = new LDKFeeEstimatorHolder(); + impl_holder.held = new FeeEstimator(new bindings.LDKFeeEstimator() { @Override public int get_est_sat_per_1000_weight(LDKConfirmationTarget confirmation_target) { int ret = arg.get_est_sat_per_1000_weight(confirmation_target); return ret; } }); + return impl_holder.held; } public int get_est_sat_per_1000_weight(LDKConfirmationTarget confirmation_target) { int ret = bindings.FeeEstimator_get_est_sat_per_1000_weight(this.ptr, confirmation_target); diff --git a/src/main/java/org/ldk/structs/Filter.java b/src/main/java/org/ldk/structs/Filter.java index 6ec794e6..64882310 100644 --- a/src/main/java/org/ldk/structs/Filter.java +++ b/src/main/java/org/ldk/structs/Filter.java @@ -23,8 +23,10 @@ public class Filter extends CommonBase { void register_tx(byte[] txid, byte[] script_pubkey); void register_output(OutPoint outpoint, byte[] script_pubkey); } - public Filter(FilterInterface arg) { - this(new bindings.LDKFilter() { + private static class LDKFilterHolder { Filter held; } + public static Filter new_impl(FilterInterface arg) { + final LDKFilterHolder impl_holder = new LDKFilterHolder(); + impl_holder.held = new Filter(new bindings.LDKFilter() { @Override public void register_tx(byte[] txid, byte[] script_pubkey) { arg.register_tx(txid, script_pubkey); } @@ -33,6 +35,7 @@ public class Filter extends CommonBase { arg.register_output(outpoint_hu_conv, script_pubkey); } }); + return impl_holder.held; } public void register_tx(byte[] txid, byte[] script_pubkey) { bindings.Filter_register_tx(this.ptr, txid, script_pubkey); diff --git a/src/main/java/org/ldk/structs/KeysInterface.java b/src/main/java/org/ldk/structs/KeysInterface.java index 3aa894b8..f93c7a0e 100644 --- a/src/main/java/org/ldk/structs/KeysInterface.java +++ b/src/main/java/org/ldk/structs/KeysInterface.java @@ -26,8 +26,10 @@ public class KeysInterface extends CommonBase { ChannelKeys get_channel_keys(boolean inbound, long channel_value_satoshis); byte[] get_secure_random_bytes(); } - public KeysInterface(KeysInterfaceInterface arg) { - this(new bindings.LDKKeysInterface() { + private static class LDKKeysInterfaceHolder { KeysInterface held; } + public static KeysInterface new_impl(KeysInterfaceInterface arg) { + final LDKKeysInterfaceHolder impl_holder = new LDKKeysInterfaceHolder(); + impl_holder.held = new KeysInterface(new bindings.LDKKeysInterface() { @Override public byte[] get_node_secret() { byte[] ret = arg.get_node_secret(); return ret; @@ -43,7 +45,7 @@ public class KeysInterface extends CommonBase { @Override public long get_channel_keys(boolean inbound, long channel_value_satoshis) { ChannelKeys ret = arg.get_channel_keys(inbound, channel_value_satoshis); long result = ret == null ? 0 : ret.ptr; - //TODO: May need to call: this.ptrs_to.add(ret); + impl_holder.held.ptrs_to.add(ret); ret.ptr = 0; return result; } @@ -52,6 +54,7 @@ public class KeysInterface extends CommonBase { return ret; } }); + return impl_holder.held; } public byte[] get_node_secret() { byte[] ret = bindings.KeysInterface_get_node_secret(this.ptr); diff --git a/src/main/java/org/ldk/structs/Logger.java b/src/main/java/org/ldk/structs/Logger.java index 613273d4..02b5075a 100644 --- a/src/main/java/org/ldk/structs/Logger.java +++ b/src/main/java/org/ldk/structs/Logger.java @@ -22,11 +22,14 @@ public class Logger extends CommonBase { public static interface LoggerInterface { void log(String record); } - public Logger(LoggerInterface arg) { - this(new bindings.LDKLogger() { + private static class LDKLoggerHolder { Logger held; } + public static Logger new_impl(LoggerInterface arg) { + final LDKLoggerHolder impl_holder = new LDKLoggerHolder(); + impl_holder.held = new Logger(new bindings.LDKLogger() { @Override public void log(String record) { arg.log(record); } }); + return impl_holder.held; } } diff --git a/src/main/java/org/ldk/structs/MessageSendEventsProvider.java b/src/main/java/org/ldk/structs/MessageSendEventsProvider.java index d62fc768..6237ba35 100644 --- a/src/main/java/org/ldk/structs/MessageSendEventsProvider.java +++ b/src/main/java/org/ldk/structs/MessageSendEventsProvider.java @@ -22,15 +22,18 @@ public class MessageSendEventsProvider extends CommonBase { public static interface MessageSendEventsProviderInterface { MessageSendEvent[] get_and_clear_pending_msg_events(); } - public MessageSendEventsProvider(MessageSendEventsProviderInterface arg) { - this(new bindings.LDKMessageSendEventsProvider() { + private static class LDKMessageSendEventsProviderHolder { MessageSendEventsProvider held; } + public static MessageSendEventsProvider new_impl(MessageSendEventsProviderInterface arg) { + final LDKMessageSendEventsProviderHolder impl_holder = new LDKMessageSendEventsProviderHolder(); + impl_holder.held = new MessageSendEventsProvider(new bindings.LDKMessageSendEventsProvider() { @Override public long[] get_and_clear_pending_msg_events() { MessageSendEvent[] ret = arg.get_and_clear_pending_msg_events(); long[] result = Arrays.stream(ret).mapToLong(arr_conv_18 -> arr_conv_18.ptr).toArray(); - //TODO: May need to call: /* TODO 2 MessageSendEvent */; + /* TODO 2 MessageSendEvent */; return result; } }); + return impl_holder.held; } public MessageSendEvent[] get_and_clear_pending_msg_events() { long[] ret = bindings.MessageSendEventsProvider_get_and_clear_pending_msg_events(this.ptr); diff --git a/src/main/java/org/ldk/structs/PreCalculatedTxCreationKeys.java b/src/main/java/org/ldk/structs/PreCalculatedTxCreationKeys.java index 4f71b567..a05b2a72 100644 --- a/src/main/java/org/ldk/structs/PreCalculatedTxCreationKeys.java +++ b/src/main/java/org/ldk/structs/PreCalculatedTxCreationKeys.java @@ -14,6 +14,13 @@ public class PreCalculatedTxCreationKeys extends CommonBase { if (ptr != 0) { bindings.PreCalculatedTxCreationKeys_free(ptr); } } + public static PreCalculatedTxCreationKeys constructor_clone(PreCalculatedTxCreationKeys orig) { + long ret = bindings.PreCalculatedTxCreationKeys_clone(orig == null ? 0 : orig.ptr & ~1); + PreCalculatedTxCreationKeys ret_hu_conv = new PreCalculatedTxCreationKeys(null, ret); + ret_hu_conv.ptrs_to.add(orig); + return ret_hu_conv; + } + public static PreCalculatedTxCreationKeys constructor_new(TxCreationKeys keys) { long ret = bindings.PreCalculatedTxCreationKeys_new(keys == null ? 0 : keys.ptr & ~1); PreCalculatedTxCreationKeys ret_hu_conv = new PreCalculatedTxCreationKeys(null, ret); diff --git a/src/main/java/org/ldk/structs/RoutingMessageHandler.java b/src/main/java/org/ldk/structs/RoutingMessageHandler.java index 86671cb4..3bedb698 100644 --- a/src/main/java/org/ldk/structs/RoutingMessageHandler.java +++ b/src/main/java/org/ldk/structs/RoutingMessageHandler.java @@ -28,8 +28,10 @@ public class RoutingMessageHandler extends CommonBase { NodeAnnouncement[] get_next_node_announcements(byte[] starting_point, byte batch_amount); boolean should_request_full_sync(byte[] node_id); } - public RoutingMessageHandler(RoutingMessageHandlerInterface arg) { - this(new bindings.LDKRoutingMessageHandler() { + private static class LDKRoutingMessageHandlerHolder { RoutingMessageHandler held; } + public static RoutingMessageHandler new_impl(RoutingMessageHandlerInterface arg) { + final LDKRoutingMessageHandlerHolder impl_holder = new LDKRoutingMessageHandlerHolder(); + impl_holder.held = new RoutingMessageHandler(new bindings.LDKRoutingMessageHandler() { @Override public long handle_node_announcement(long msg) { NodeAnnouncement msg_hu_conv = new NodeAnnouncement(null, msg); Result_boolLightningErrorZ ret = arg.handle_node_announcement(msg_hu_conv); @@ -58,13 +60,13 @@ public class RoutingMessageHandler extends CommonBase { @Override public long[] get_next_channel_announcements(long starting_point, byte batch_amount) { ThreeTuple[] ret = arg.get_next_channel_announcements(starting_point, batch_amount); long[] result = Arrays.stream(ret).mapToLong(arr_conv_63 -> bindings.C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(arr_conv_63.a == null ? 0 : arr_conv_63.a.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_63_a)*/, arr_conv_63.b == null ? 0 : arr_conv_63.b.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_63_b)*/, arr_conv_63.c == null ? 0 : arr_conv_63.c.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_63_c)*/)).toArray(); - //TODO: May need to call: /* TODO 2 ThreeTuple */; + /* TODO 2 ThreeTuple */; return result; } @Override public long[] get_next_node_announcements(byte[] starting_point, byte batch_amount) { NodeAnnouncement[] ret = arg.get_next_node_announcements(starting_point, batch_amount); long[] result = Arrays.stream(ret).mapToLong(arr_conv_18 -> arr_conv_18 == null ? 0 : arr_conv_18.ptr & ~1).toArray(); - //TODO: May need to call: /* TODO 2 NodeAnnouncement */; + /* TODO 2 NodeAnnouncement */; return result; } @Override public boolean should_request_full_sync(byte[] node_id) { @@ -72,6 +74,7 @@ public class RoutingMessageHandler extends CommonBase { return ret; } }); + return impl_holder.held; } public Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg) { long ret = bindings.RoutingMessageHandler_handle_node_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1); diff --git a/src/main/java/org/ldk/structs/SocketDescriptor.java b/src/main/java/org/ldk/structs/SocketDescriptor.java index 9c4f9e7b..0784a608 100644 --- a/src/main/java/org/ldk/structs/SocketDescriptor.java +++ b/src/main/java/org/ldk/structs/SocketDescriptor.java @@ -25,8 +25,10 @@ public class SocketDescriptor extends CommonBase { boolean eq(long other_arg); long hash(); } - public SocketDescriptor(SocketDescriptorInterface arg) { - this(new bindings.LDKSocketDescriptor() { + private static class LDKSocketDescriptorHolder { SocketDescriptor held; } + public static SocketDescriptor new_impl(SocketDescriptorInterface arg) { + final LDKSocketDescriptorHolder impl_holder = new LDKSocketDescriptorHolder(); + impl_holder.held = new SocketDescriptor(new bindings.LDKSocketDescriptor() { @Override public long send_data(byte[] data, boolean resume_read) { long ret = arg.send_data(data, resume_read); return ret; @@ -43,6 +45,7 @@ public class SocketDescriptor extends CommonBase { return ret; } }); + return impl_holder.held; } public long send_data(byte[] data, boolean resume_read) { long ret = bindings.SocketDescriptor_send_data(this.ptr, data, resume_read); diff --git a/src/main/java/org/ldk/structs/Watch.java b/src/main/java/org/ldk/structs/Watch.java index a83f691e..8b4f3219 100644 --- a/src/main/java/org/ldk/structs/Watch.java +++ b/src/main/java/org/ldk/structs/Watch.java @@ -24,8 +24,10 @@ public class Watch extends CommonBase { Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update); MonitorEvent[] release_pending_monitor_events(); } - public Watch(WatchInterface arg) { - this(new bindings.LDKWatch() { + private static class LDKWatchHolder { Watch held; } + public static Watch new_impl(WatchInterface arg) { + final LDKWatchHolder impl_holder = new LDKWatchHolder(); + impl_holder.held = new Watch(new bindings.LDKWatch() { @Override public long watch_channel(long funding_txo, long monitor) { OutPoint funding_txo_hu_conv = new OutPoint(null, funding_txo); ChannelMonitor monitor_hu_conv = new ChannelMonitor(null, monitor); @@ -45,10 +47,11 @@ public class Watch extends CommonBase { @Override public long[] release_pending_monitor_events() { MonitorEvent[] ret = arg.release_pending_monitor_events(); long[] result = Arrays.stream(ret).mapToLong(arr_conv_14 -> arr_conv_14 == null ? 0 : arr_conv_14.ptr & ~1).toArray(); - //TODO: May need to call: /* TODO 2 MonitorEvent */; + /* TODO 2 MonitorEvent */; return result; } }); + return impl_holder.held; } // Skipped Watch_watch_channel public Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update) { -- 2.39.5