]> git.bitcoin.ninja Git - ldk-java/commitdiff
Properly handle java refs in traits returning traits
authorMatt Corallo <git@bluematt.me>
Sat, 24 Oct 2020 22:11:18 +0000 (18:11 -0400)
committerMatt Corallo <git@bluematt.me>
Sat, 24 Oct 2020 22:11:18 +0000 (18:11 -0400)
15 files changed:
genbindings.py
src/main/java/org/ldk/structs/Access.java
src/main/java/org/ldk/structs/BroadcasterInterface.java
src/main/java/org/ldk/structs/ChannelKeys.java
src/main/java/org/ldk/structs/ChannelMessageHandler.java
src/main/java/org/ldk/structs/EventsProvider.java
src/main/java/org/ldk/structs/FeeEstimator.java
src/main/java/org/ldk/structs/Filter.java
src/main/java/org/ldk/structs/KeysInterface.java
src/main/java/org/ldk/structs/Logger.java
src/main/java/org/ldk/structs/MessageSendEventsProvider.java
src/main/java/org/ldk/structs/PreCalculatedTxCreationKeys.java
src/main/java/org/ldk/structs/RoutingMessageHandler.java
src/main/java/org/ldk/structs/SocketDescriptor.java
src/main/java/org/ldk/structs/Watch.java

index 3c9235118f1e3fe4217563c70aabad99f5709aed..d96447bd37eb36a5a47692c26ced8894389f2166 100755 (executable)
@@ -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")
index 15b3d7423df26c1bb581c2a75b7393295ae382da..7a9b89c03bc057e0ce8591b64b6b536a7ef48a41 100644 (file)
@@ -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);
index b2541a836105bb8dfcc617f3df4ebf5db249035a..64979feca7fd04068ba731960d34d3ef7adb8ea2 100644 (file)
@@ -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);
index d2e8ff2221980b8b08ade8cddfdcc5901940dfaa..7283363a61fee779e76818a938a5a47d6d3e3cd9 100644 (file)
@@ -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);
index 5dc8103c30e56c5af069bf7f702bd7338a7ea7b5..d286901e7fb8399994beab0349b38468044a4fbc 100644 (file)
@@ -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
index be33c91528c566ba24601fab0eebca1f0dee138c..f7218d2b1e63a70b92d0b54aafda2c6bc38d54a7 100644 (file)
@@ -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);
index dd7c05f28434b1f2c5e5129a688bdda9754c1d01..910edae72d6ab5cc0ad9c6a3cedc3514252fb299 100644 (file)
@@ -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);
index 6ec794e6479b99070ba00eef14f95b9f3130c6a9..648823106a4e607e1f169366b3259b9ed73fea89 100644 (file)
@@ -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);
index 3aa894b83be1b9e32118370da4f2b6dd4893425e..f93c7a0e776a0f53d82e066ad56bc8e8192bdb87 100644 (file)
@@ -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);
index 613273d4957f38cc98d4229757529b8a6df7c0a8..02b5075a86c581fedcb89b39b27b677f7c2668f6 100644 (file)
@@ -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;
        }
 }
index d62fc7683df4642674107b676a938f258177646d..6237ba355e59e88824d40cd0ee1851176b519849 100644 (file)
@@ -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);
index 4f71b5672739774a5a10f05e63d4f91a376a5a9e..a05b2a723e7e97c220b4e547826dea5ef309abce 100644 (file)
@@ -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);
index 86671cb4a711d7e8b15141302a296cc0c0efa289..3bedb69800109af0335c23089ec6bdccdef8c4b2 100644 (file)
@@ -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<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] 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<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>  */;
+                               /* TODO 2 ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>  */;
                                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);
index 9c4f9e7b251d69148aca10dddf1f0f20f59152c9..0784a608532103f2ce560ce8dc2f67cc7b8a812a 100644 (file)
@@ -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);
index a83f691ec467afe650b6748bb45bcccc3a4a4fe3..8b4f3219a2e6133d25deab6c73b6598e8afbbe38 100644 (file)
@@ -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) {