]> git.bitcoin.ninja Git - ldk-java/commitdiff
Provide human versions of trait interfaces, with a bunch of fixes to make it work
authorMatt Corallo <git@bluematt.me>
Thu, 22 Oct 2020 04:09:49 +0000 (00:09 -0400)
committerMatt Corallo <git@bluematt.me>
Thu, 22 Oct 2020 04:10:52 +0000 (00:10 -0400)
Sadly gave up trying to get returns to be sane, so now returning an
object from a trait implies that object is now unusable :(.

119 files changed:
genbindings.py
src/main/java/org/ldk/impl/bindings.java
src/main/java/org/ldk/structs/APIError.java
src/main/java/org/ldk/structs/AcceptChannel.java
src/main/java/org/ldk/structs/Access.java
src/main/java/org/ldk/structs/AnnouncementSignatures.java
src/main/java/org/ldk/structs/BroadcasterInterface.java
src/main/java/org/ldk/structs/ChainMonitor.java
src/main/java/org/ldk/structs/ChannelAnnouncement.java
src/main/java/org/ldk/structs/ChannelConfig.java
src/main/java/org/ldk/structs/ChannelDetails.java
src/main/java/org/ldk/structs/ChannelFeatures.java
src/main/java/org/ldk/structs/ChannelHandshakeConfig.java
src/main/java/org/ldk/structs/ChannelHandshakeLimits.java
src/main/java/org/ldk/structs/ChannelInfo.java
src/main/java/org/ldk/structs/ChannelKeys.java
src/main/java/org/ldk/structs/ChannelManager.java
src/main/java/org/ldk/structs/ChannelManagerReadArgs.java
src/main/java/org/ldk/structs/ChannelMessageHandler.java
src/main/java/org/ldk/structs/ChannelMonitor.java
src/main/java/org/ldk/structs/ChannelMonitorUpdate.java
src/main/java/org/ldk/structs/ChannelPublicKeys.java
src/main/java/org/ldk/structs/ChannelReestablish.java
src/main/java/org/ldk/structs/ChannelUpdate.java
src/main/java/org/ldk/structs/ClosingSigned.java
src/main/java/org/ldk/structs/CommitmentSigned.java
src/main/java/org/ldk/structs/CommitmentUpdate.java
src/main/java/org/ldk/structs/CommonBase.java
src/main/java/org/ldk/structs/DataLossProtect.java
src/main/java/org/ldk/structs/DecodeError.java
src/main/java/org/ldk/structs/DirectionalChannelInfo.java
src/main/java/org/ldk/structs/ErrorAction.java
src/main/java/org/ldk/structs/ErrorMessage.java
src/main/java/org/ldk/structs/Event.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/FundingCreated.java
src/main/java/org/ldk/structs/FundingLocked.java
src/main/java/org/ldk/structs/FundingSigned.java
src/main/java/org/ldk/structs/GossipTimestampFilter.java
src/main/java/org/ldk/structs/HTLCFailChannelUpdate.java
src/main/java/org/ldk/structs/HTLCOutputInCommitment.java
src/main/java/org/ldk/structs/HTLCUpdate.java
src/main/java/org/ldk/structs/HolderCommitmentTransaction.java
src/main/java/org/ldk/structs/InMemoryChannelKeys.java
src/main/java/org/ldk/structs/Init.java
src/main/java/org/ldk/structs/InitFeatures.java
src/main/java/org/ldk/structs/KeysInterface.java
src/main/java/org/ldk/structs/KeysManager.java
src/main/java/org/ldk/structs/LightningError.java
src/main/java/org/ldk/structs/LockedNetworkGraph.java
src/main/java/org/ldk/structs/Logger.java
src/main/java/org/ldk/structs/MessageHandler.java
src/main/java/org/ldk/structs/MessageSendEvent.java
src/main/java/org/ldk/structs/MessageSendEventsProvider.java
src/main/java/org/ldk/structs/MonitorEvent.java
src/main/java/org/ldk/structs/MonitorUpdateError.java
src/main/java/org/ldk/structs/NetAddress.java
src/main/java/org/ldk/structs/NetGraphMsgHandler.java
src/main/java/org/ldk/structs/NetworkGraph.java
src/main/java/org/ldk/structs/NodeAnnouncement.java
src/main/java/org/ldk/structs/NodeAnnouncementInfo.java
src/main/java/org/ldk/structs/NodeFeatures.java
src/main/java/org/ldk/structs/NodeInfo.java
src/main/java/org/ldk/structs/OpenChannel.java
src/main/java/org/ldk/structs/OutPoint.java
src/main/java/org/ldk/structs/PaymentSendFailure.java
src/main/java/org/ldk/structs/PeerHandleError.java
src/main/java/org/ldk/structs/PeerManager.java
src/main/java/org/ldk/structs/Ping.java
src/main/java/org/ldk/structs/Pong.java
src/main/java/org/ldk/structs/PreCalculatedTxCreationKeys.java
src/main/java/org/ldk/structs/QueryChannelRange.java
src/main/java/org/ldk/structs/QueryShortChannelIds.java
src/main/java/org/ldk/structs/ReplyChannelRange.java
src/main/java/org/ldk/structs/ReplyShortChannelIdsEnd.java
src/main/java/org/ldk/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.java
src/main/java/org/ldk/structs/Result_CVec_SignatureZNoneZ.java
src/main/java/org/ldk/structs/Result_CVec_u8ZPeerHandleErrorZ.java
src/main/java/org/ldk/structs/Result_NoneAPIErrorZ.java
src/main/java/org/ldk/structs/Result_NoneChannelMonitorUpdateErrZ.java
src/main/java/org/ldk/structs/Result_NoneMonitorUpdateErrorZ.java
src/main/java/org/ldk/structs/Result_NonePaymentSendFailureZ.java
src/main/java/org/ldk/structs/Result_NonePeerHandleErrorZ.java
src/main/java/org/ldk/structs/Result_PublicKeySecpErrorZ.java
src/main/java/org/ldk/structs/Result_RouteLightningErrorZ.java
src/main/java/org/ldk/structs/Result_SecretKeySecpErrorZ.java
src/main/java/org/ldk/structs/Result_SignatureNoneZ.java
src/main/java/org/ldk/structs/Result_TxCreationKeysSecpErrorZ.java
src/main/java/org/ldk/structs/Result_TxOutAccessErrorZ.java
src/main/java/org/ldk/structs/Result_boolLightningErrorZ.java
src/main/java/org/ldk/structs/Result_boolPeerHandleErrorZ.java
src/main/java/org/ldk/structs/RevokeAndACK.java
src/main/java/org/ldk/structs/Route.java
src/main/java/org/ldk/structs/RouteHint.java
src/main/java/org/ldk/structs/RouteHop.java
src/main/java/org/ldk/structs/RoutingFees.java
src/main/java/org/ldk/structs/RoutingMessageHandler.java
src/main/java/org/ldk/structs/Shutdown.java
src/main/java/org/ldk/structs/SocketDescriptor.java
src/main/java/org/ldk/structs/SpendableOutputDescriptor.java
src/main/java/org/ldk/structs/Transaction.java
src/main/java/org/ldk/structs/TxCreationKeys.java
src/main/java/org/ldk/structs/TxOut.java
src/main/java/org/ldk/structs/UnsignedChannelAnnouncement.java
src/main/java/org/ldk/structs/UnsignedChannelUpdate.java
src/main/java/org/ldk/structs/UnsignedNodeAnnouncement.java
src/main/java/org/ldk/structs/UpdateAddHTLC.java
src/main/java/org/ldk/structs/UpdateFailHTLC.java
src/main/java/org/ldk/structs/UpdateFailMalformedHTLC.java
src/main/java/org/ldk/structs/UpdateFee.java
src/main/java/org/ldk/structs/UpdateFulfillHTLC.java
src/main/java/org/ldk/structs/UserConfig.java
src/main/java/org/ldk/structs/Watch.java
src/main/jni/bindings.c
src/main/jni/org_ldk_impl_bindings.h
src/test/java/org/ldk/HumanObjectPeerTest.java
src/test/java/org/ldk/PeerTest.java

index b70b0e4839d2ad11ffbb5b1c4d4597be14940c4e..b09d930b4e03992063e579c32f094dc7936c7b3e 100755 (executable)
@@ -98,6 +98,9 @@ trait_structs = set()
 result_types = set()
 tuple_types = {}
 
+def is_common_base_ext(struct_name):
+    return struct_name in complex_enums or struct_name in opaque_structs or struct_name in trait_structs or struct_name in result_types
+
 var_is_arr_regex = re.compile("\(\*([A-za-z0-9_]*)\)\[([a-z0-9]*)\]")
 var_ty_regex = re.compile("([A-za-z_0-9]*)(.*)")
 java_c_types_none_allowed = True # Unset when we do the real pass that populates the above sets
@@ -562,7 +565,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                             ret_conv = ("CANT PASS TRAIT TO Java?", ""), ret_conv_name = "NO CONV POSSIBLE",
                             to_hu_conv = "DUMMY", to_hu_conv_name = None,
                             from_hu_conv = (ty_info.var_name + " == null ? 0 : " + ty_info.var_name + ".ptr", "this.ptrs_to.add(" + ty_info.var_name + ")"))
-                    if ty_info.rust_obj != "LDKu8slice":
+                    if ty_info.rust_obj != "LDKu8slice" and ty_info.rust_obj != "LDKTransaction":
                         # Don't bother free'ing slices passed in - Rust doesn't auto-free the
                         # underlying unlike Vecs, and it gives Java more freedom.
                         base_conv = base_conv + "\nFREE((void*)" + ty_info.var_name + ");";
@@ -576,38 +579,64 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                             arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
                             ret_conv = ret_conv, ret_conv_name = ty_info.var_name + "_ref",
                             to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_hu_conv = " + ty_info.java_hu_ty + ".constr_from_ptr(" + ty_info.var_name + ");",
-                            to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = (ty_info.var_name + ".conv_to_c()", ""))
+                            to_hu_conv_name = ty_info.var_name + "_hu_conv", from_hu_conv = (ty_info.var_name + ".ptr", ""))
                     if ty_info.rust_obj in tuple_types:
+                        from_hu_conv = "bindings." + tuple_types[ty_info.rust_obj][1].replace("LDK", "") + "_new("
                         to_hu_conv_pfx = ""
                         to_hu_conv_sfx = ty_info.java_hu_ty + " " + ty_info.var_name + "_conv = new " + ty_info.java_hu_ty + "("
                         for idx, conv in enumerate(tuple_types[ty_info.rust_obj][0]):
                             if idx != 0:
                                 to_hu_conv_sfx = to_hu_conv_sfx + ", "
+                                from_hu_conv = from_hu_conv + ", "
                             conv.var_name = ty_info.var_name + "_" + chr(idx + ord("a"))
                             conv_map = map_type_with_info(conv, False, None, is_free, holds_ref)
                             to_hu_conv_pfx = to_hu_conv_pfx + conv.java_ty + " " + ty_info.var_name + "_" + chr(idx + ord("a")) + " = " + "bindings." + tuple_types[ty_info.rust_obj][1] + "_get_" + chr(idx + ord("a")) + "(" + ty_info.var_name + ");\n"
                             if conv_map.to_hu_conv is not None:
                                 to_hu_conv_pfx = to_hu_conv_pfx + conv_map.to_hu_conv + ";\n"
-                                to_hu_conv_sfx = to_hu_conv_sfx + conv_map.to_hu_conv_name;
+                                to_hu_conv_sfx = to_hu_conv_sfx + conv_map.to_hu_conv_name
+                            else:
+                                to_hu_conv_sfx = to_hu_conv_sfx + ty_info.var_name + "_" + chr(idx + ord("a"))
+                            if conv_map.from_hu_conv is not None:
+                                from_hu_conv = from_hu_conv + conv_map.from_hu_conv[0].replace(ty_info.var_name + "_" + chr(idx + ord("a")), ty_info.var_name + "." + chr(idx + ord("a")))
+                                if conv_map.from_hu_conv[1] != "":
+                                    from_hu_conv = from_hu_conv + "/*XXX: Need to call " + conv_map.from_hu_conv[1] + "*/"
                             else:
-                                to_hu_conv_sfx = to_hu_conv_sfx + ty_info.var_name + "_" + chr(idx + ord("a"));
+                                from_hu_conv = from_hu_conv + ty_info.var_name + "." + chr(idx + ord("a"))
                         return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
                             arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
                             ret_conv = ("long " + ty_info.var_name + "_ref = (long)&", ";"), ret_conv_name = ty_info.var_name + "_ref",
-                            to_hu_conv = to_hu_conv_pfx + to_hu_conv_sfx + ");", to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = ("/*TODO b*/0", ""))
+                            to_hu_conv = to_hu_conv_pfx + to_hu_conv_sfx + ");", to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = (from_hu_conv + ")", ""))
 
                     # The manually-defined types - TxOut and Transaction
+                    assert ty_info.rust_obj == "LDKTransaction" or ty_info.rust_obj == "LDKTxOut"
+                    if ty_info.rust_obj == "LDKTransaction":
+                        return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
+                            arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
+                            ret_conv = ("LDKTransaction *" + ty_info.var_name + "_copy = MALLOC(sizeof(LDKTransaction), \"LDKTransaction\");\n*" + ty_info.var_name + "_copy = ", ";\nlong " + ty_info.var_name + "_ref = (long)" + ty_info.var_name + "_copy;"),
+                            ret_conv_name = ty_info.var_name + "_ref",
+                            to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_conv = new " +ty_info.java_hu_ty + "(null, " + ty_info.var_name + ");",
+                            to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = (ty_info.var_name + ".ptr", ""))
                     return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
-                        arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
-                        ret_conv = ("long " + ty_info.var_name + "_ref = (long)&", ";"), ret_conv_name = ty_info.var_name + "_ref",
-                        to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_conv = new " +ty_info.java_hu_ty + "(null, " + ty_info.var_name + ");",
-                        to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = ("/*TODO 1*/0", ""))
+                            arg_conv = base_conv, arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
+                            ret_conv = ("long " + ty_info.var_name + "_ref = (long)&", ";"), ret_conv_name = ty_info.var_name + "_ref",
+                            to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_conv = new " +ty_info.java_hu_ty + "(null, " + ty_info.var_name + ");",
+                            to_hu_conv_name = ty_info.var_name + "_conv", from_hu_conv = (ty_info.var_name + ".ptr", ""))
                 else:
                     assert(not is_free)
                     if ty_info.rust_obj in opaque_structs:
                         return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
                             arg_conv = opaque_arg_conv, arg_conv_name = "&" + ty_info.var_name + "_conv", arg_conv_cleanup = None,
-                            ret_conv = None, ret_conv_name = None, to_hu_conv = "TODO 2", to_hu_conv_name = None,
+                            ret_conv = None, ret_conv_name = None,
+                            to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_hu_conv = new " + ty_info.java_hu_ty + "(null, " + ty_info.var_name + ");",
+                            to_hu_conv_name = ty_info.var_name + "_hu_conv",
+                            from_hu_conv = (ty_info.var_name + " == null ? 0 : " + ty_info.var_name + ".ptr & ~1", "this.ptrs_to.add(" + ty_info.var_name + ")")) # its a pointer, no conv needed
+                    elif ty_info.rust_obj in complex_enums:
+                        return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
+                            arg_conv = ty_info.rust_obj + "* " + ty_info.var_name + "_conv = (" + ty_info.rust_obj + "*)" + ty_info.var_name + ";",
+                            arg_conv_name = ty_info.var_name + "_conv", arg_conv_cleanup = None,
+                            ret_conv = None, ret_conv_name = None,
+                            to_hu_conv = ty_info.java_hu_ty + " " + ty_info.var_name + "_hu_conv = " + ty_info.java_hu_ty + ".constr_from_ptr(" + ty_info.var_name + ");",
+                            to_hu_conv_name = ty_info.var_name + "_hu_conv",
                             from_hu_conv = (ty_info.var_name + " == null ? 0 : " + ty_info.var_name + ".ptr & ~1", "this.ptrs_to.add(" + ty_info.var_name + ")")) # its a pointer, no conv needed
                     elif ty_info.rust_obj in trait_structs:
                         return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
@@ -622,7 +651,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
             elif ty_info.is_ptr:
                 return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
                     arg_conv = None, arg_conv_name = ty_info.var_name, arg_conv_cleanup = None,
-                    ret_conv = None, ret_conv_name = None, to_hu_conv = "TODO 4", to_hu_conv_name = None, from_hu_conv = None)
+                    ret_conv = None, ret_conv_name = None, to_hu_conv = None, to_hu_conv_name = None, from_hu_conv = None)
             else:
                 return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
                     arg_conv = None, arg_conv_name = ty_info.var_name, arg_conv_cleanup = None,
@@ -656,7 +685,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                             ret_conv_name = "(long)ret",
                             arg_conv = None, arg_conv_name = None, arg_conv_cleanup = None,
                             to_hu_conv = ty_info.java_hu_ty + " ret_hu_conv = " + ty_info.java_hu_ty + ".constr_from_ptr(ret);\nret_hu_conv.ptrs_to.add(this);",
-                            to_hu_conv_name = "ret_hu_conv", from_hu_conv = (ty_info.var_name + ".conv_to_c()", ""))
+                            to_hu_conv_name = "ret_hu_conv", from_hu_conv = ("ret != null ? ret.ptr : 0", ""))
                     if ty_info.rust_obj in opaque_structs:
                         # If we're returning a newly-allocated struct, we don't want Rust to ever
                         # free, instead relying on the Java GC to lose the ref. We undo this in
@@ -674,7 +703,14 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                             ret_conv_name = "(long)ret",
                             arg_conv = None, arg_conv_name = None, arg_conv_cleanup = None,
                             to_hu_conv = ty_info.java_hu_ty + " ret_hu_conv = new " + ty_info.java_hu_ty + "(null, ret);\nret_hu_conv.ptrs_to.add(this);",
-                            to_hu_conv_name = "ret_hu_conv", from_hu_conv = None)
+                            to_hu_conv_name = "ret_hu_conv", from_hu_conv = ("ret.ptr", ""))
+                    elif ty_info.rust_obj in tuple_types:
+                        return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
+                            ret_conv = (ty_info.rust_obj + "* ret = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n*ret = ", ";"),
+                            ret_conv_name = "(long)ret",
+                            arg_conv = None, arg_conv_name = None, arg_conv_cleanup = None,
+                            to_hu_conv = ty_info.java_hu_ty + " ret_hu_conv = new " + ty_info.java_hu_ty + "(null, ret);\nret_hu_conv.ptrs_to.add(this);",
+                            to_hu_conv_name = "ret_hu_conv", from_hu_conv = ("bindings." + ty_info.rust_obj.replace("LDK", "") + "_new(ret.a, ret.b)", ""))
                     else:
                         return ConvInfo(ty_info = ty_info, arg_name = ty_info.var_name,
                             ret_conv = (ty_info.rust_obj + "* ret = MALLOC(sizeof(" + ty_info.rust_obj + "), \"" + ty_info.rust_obj + "\");\n*ret = ", ";"),
@@ -932,9 +968,8 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
             out_java_enum.write("\t@Override @SuppressWarnings(\"deprecation\")\n")
             out_java_enum.write("\tprotected void finalize() throws Throwable {\n")
             out_java_enum.write("\t\tsuper.finalize();\n")
-            out_java_enum.write("\t\tbindings." + java_hu_type + "_free(ptr);\n")
+            out_java_enum.write("\t\tif (ptr != 0) { bindings." + java_hu_type + "_free(ptr); }\n")
             out_java_enum.write("\t}\n")
-            out_java_enum.write("\tlong conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ }\n")
             out_java_enum.write("\tstatic " + java_hu_type + " constr_from_ptr(long ptr) {\n")
             out_java_enum.write("\t\tbindings." + struct_name + " raw_val = bindings." + struct_name + "_ref_from_ptr(ptr);\n")
             java_hu_subclasses = ""
@@ -970,7 +1005,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                             if idx != 0 and idx < len(enum_var_lines) - 2:
                                 field_ty = map_type(field.strip(' ;'), False, None, False, True)
                                 out_java.write("\t\t\tpublic " + field_ty.java_ty + " " + field_ty.arg_name + ";\n")
-                                java_hu_subclasses = java_hu_subclasses + "\t\tpublic " + field_ty.java_hu_ty + " " + field_ty.arg_name + ";\n"
+                                java_hu_subclasses = java_hu_subclasses + "\t\tpublic final " + field_ty.java_hu_ty + " " + field_ty.arg_name + ";\n"
                                 if field_ty.to_hu_conv is not None:
                                     hu_conv_body = hu_conv_body + "\t\t\t" + field_ty.java_ty + " " + field_ty.arg_name + " = obj." + field_ty.arg_name + ";\n"
                                     hu_conv_body = hu_conv_body + "\t\t\t" + field_ty.to_hu_conv.replace("\n", "\n\t\t\t") + "\n"
@@ -989,8 +1024,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                     out_java_enum.write("\t\t}\n")
                     java_hu_subclasses = java_hu_subclasses + "\t\tprivate " + var_name + "(long ptr, bindings." + struct_name + "." + var_name + " obj) {\n\t\t\tsuper(null, ptr);\n"
                     java_hu_subclasses = java_hu_subclasses + hu_conv_body
-                    java_hu_subclasses = java_hu_subclasses + "\t\t}\n\t\t@Override long conv_to_c() { return 0; /*XXX*/ }\n"
-                    java_hu_subclasses = java_hu_subclasses + "\t}\n"
+                    java_hu_subclasses = java_hu_subclasses + "\t\t}\n\t}\n"
                     init_meth_jty_strs[var_name] = init_meth_jty_str
             out_java_enum.write("\t\tassert false; return null; // Unreachable without extending the (internal) bindings interface\n\t}\n\n")
             out_java_enum.write(java_hu_subclasses)
@@ -1049,8 +1083,9 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
 
             out_java_trait.write(hu_struct_file_prefix)
             out_java_trait.write("public class " + struct_name.replace("LDK","") + " extends CommonBase {\n")
-            out_java_trait.write("\t" + struct_name.replace("LDK", "") + "(Object _dummy, long ptr) { super(ptr); }\n")
-            out_java_trait.write("\tpublic " + struct_name.replace("LDK", "") + "(bindings." + struct_name + " arg") # XXX: Should be priv ( but is currently used in tests
+            out_java_trait.write("\tfinal bindings." + struct_name + " bindings_instance;\n")
+            out_java_trait.write("\t" + struct_name.replace("LDK", "") + "(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }\n")
+            out_java_trait.write("\tprivate " + struct_name.replace("LDK", "") + "(bindings." + struct_name + " arg")
             for var_line in field_var_lines:
                 if var_line.group(1) in trait_structs:
                     out_java_trait.write(", bindings." + var_line.group(1) + " " + var_line.group(2))
@@ -1061,15 +1096,21 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                     out_java_trait.write(", " + var_line.group(2))
             out_java_trait.write("));\n")
             out_java_trait.write("\t\tthis.ptrs_to.add(arg);\n")
+            out_java_trait.write("\t\tthis.bindings_instance = arg;\n")
             out_java_trait.write("\t}\n")
             out_java_trait.write("\t@Override @SuppressWarnings(\"deprecation\")\n")
             out_java_trait.write("\tprotected void finalize() throws Throwable {\n")
-            out_java_trait.write("\t\tbindings." + struct_name.replace("LDK","") + "_free(ptr); super.finalize();\n")
+            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) {\n"
-            java_trait_constr = java_trait_constr + "\t\tthis(new bindings." + struct_name + "() {\n"
-            #out_java_trait.write("\tpublic static interface " + struct_name.replace("LDK", "") + "Interface {\n")
+            java_trait_constr = "\tpublic " + struct_name.replace("LDK", "") + "(" + struct_name.replace("LDK", "") + "Interface arg"
+            for var_line in 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 + ") {\n\t\tthis(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 = []
             for fn_line in trait_fn_lines:
@@ -1079,7 +1120,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
 
                     out_java.write("\t\t " + ret_ty_info.java_ty + " " + fn_line.group(2) + "(")
                     java_trait_constr = java_trait_constr + "\t\t\t@Override public " + ret_ty_info.java_ty + " " + fn_line.group(2) + "("
-                    #out_java_trait.write("\t\t" + ret_ty_info.java_hu_ty + " " + fn_line.group(2) + "(")
+                    out_java_trait.write("\t\t" + ret_ty_info.java_hu_ty + " " + fn_line.group(2) + "(")
                     is_const = fn_line.group(3) is not None
                     out_c.write(fn_line.group(1) + fn_line.group(2) + "_jcall(")
                     if is_const:
@@ -1094,12 +1135,12 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                         if idx >= 2:
                             out_java.write(", ")
                             java_trait_constr = java_trait_constr + ", "
-                            #out_java_trait.write(", ")
+                            out_java_trait.write(", ")
                         out_c.write(", ")
                         arg_conv_info = map_type(arg, True, None, False, False)
                         out_c.write(arg.strip())
                         out_java.write(arg_conv_info.java_ty + " " + arg_conv_info.arg_name)
-                        #out_java_trait.write(arg_conv_info.java_ty + " " + arg_conv_info.arg_name)
+                        out_java_trait.write(arg_conv_info.java_hu_ty + " " + arg_conv_info.arg_name)
                         java_trait_constr = java_trait_constr + arg_conv_info.java_ty + " " + arg_conv_info.arg_name
                         arg_names.append(arg_conv_info)
                         java_meth_descr = java_meth_descr + arg_conv_info.java_fn_ty_arg
@@ -1107,7 +1148,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                     java_meths.append(java_meth_descr)
 
                     out_java.write(");\n")
-                    #out_java_trait.write(");\n")
+                    out_java_trait.write(");\n")
                     java_trait_constr = java_trait_constr + ") {\n"
                     out_c.write(") {\n")
                     out_c.write("\t" + struct_name + "_JCalls *j_calls = (" + struct_name + "_JCalls*) this_arg;\n")
@@ -1119,6 +1160,8 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                             out_c.write("\t" + arg_info.ret_conv[0].replace('\n', '\n\t'));
                             out_c.write(arg_info.arg_name)
                             out_c.write(arg_info.ret_conv[1].replace('\n', '\n\t') + "\n")
+                        if arg_info.to_hu_conv is not None:
+                            java_trait_constr = java_trait_constr + "\t\t\t\t" + arg_info.to_hu_conv.replace("\n", "\n\t\t\t\t") + "\n"
 
                     out_c.write("\tjobject obj = (*_env)->NewLocalRef(_env, j_calls->o);\n\tCHECK(obj != NULL);\n")
                     if ret_ty_info.c_ty.endswith("Array"):
@@ -1128,15 +1171,21 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                     else:
                         out_c.write("\t" + fn_line.group(1).strip() + "* ret = (" + fn_line.group(1).strip() + "*)(*_env)->CallLongMethod(_env, obj, j_calls->" + fn_line.group(2) + "_meth");
                     if ret_ty_info.java_ty != "void":
-                        java_trait_constr = java_trait_constr + "\t\t\t\treturn arg." + fn_line.group(2) + "("
+                        java_trait_constr = java_trait_constr + "\t\t\t\t" + ret_ty_info.java_hu_ty + " ret = arg." + fn_line.group(2) + "("
                     else:
                         java_trait_constr = java_trait_constr + "\t\t\t\targ." + fn_line.group(2) + "("
 
-                    for arg_info in arg_names:
+                    for idx, arg_info in enumerate(arg_names):
                         if arg_info.ret_conv is not None:
                             out_c.write(", " + arg_info.ret_conv_name)
                         else:
                             out_c.write(", " + arg_info.arg_name)
+                        if idx != 0:
+                            java_trait_constr = java_trait_constr + ", "
+                        if arg_info.to_hu_conv_name is not None:
+                            java_trait_constr = java_trait_constr + arg_info.to_hu_conv_name
+                        else:
+                            java_trait_constr = java_trait_constr + arg_info.arg_name
                     out_c.write(");\n");
                     if ret_ty_info.arg_conv is not None:
                         out_c.write("\t" + ret_ty_info.arg_conv.replace("\n", "\n\t").replace("arg", "ret") + "\n\treturn " + ret_ty_info.arg_conv_name.replace("arg", "ret") + ";\n")
@@ -1146,7 +1195,18 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                         out_c.write("\tFREE(ret);\n")
                         out_c.write("\treturn res;\n")
                     out_c.write("}\n")
-                    java_trait_constr = java_trait_constr + ");\n\t\t\t}\n"
+                    java_trait_constr = java_trait_constr + ");\n"
+                    if ret_ty_info.java_ty != "void":
+                        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" + ret_ty_info.from_hu_conv[1] + "\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"
+                        else:
+                            java_trait_constr = java_trait_constr + "\t\t\t\treturn ret;\n"
+                    java_trait_constr = java_trait_constr + "\t\t\t}\n"
                 elif fn_line.group(2) == "free":
                     out_c.write("static void " + struct_name + "_JCalls_free(void* this_arg) {\n")
                     out_c.write("\t" + struct_name + "_JCalls *j_calls = (" + struct_name + "_JCalls*) this_arg;\n")
@@ -1156,8 +1216,12 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg
                     out_c.write("\t\t(*env)->DeleteWeakGlobalRef(env, j_calls->o);\n")
                     out_c.write("\t\tFREE(j_calls);\n")
                     out_c.write("\t}\n}\n")
-            #out_java_trait.write("\t}\n")
-            #out_java_trait.write(java_trait_constr + "\t\t});\n\t}\n")
+            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"
+            out_java_trait.write("\t}\n")
+            out_java_trait.write(java_trait_constr + ");\n\t}\n")
 
             # Write out a clone function whether we need one or not, as we use them in moving to rust
             out_c.write("static void* " + struct_name + "_JCalls_clone(const void* this_arg) {\n")
@@ -1302,7 +1366,13 @@ static void alloc_freed(void* ptr) {
        allocation* p = NULL;
        DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success);
        allocation* it = allocation_ll;
-       while (it->ptr != ptr) { p = it; it = it->next; }
+       while (it->ptr != ptr) {
+               p = it; it = it->next;
+               if (it == NULL) {
+                       fprintf(stderr, "Tried to free unknown pointer %p!\\n", ptr);
+                       return; // addrsan should catch malloc-unknown and print more info than we have
+               }
+       }
        if (p) { p->next = it->next; } else { allocation_ll = it->next; }
        DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
        DO_ASSERT(it->ptr == ptr);
@@ -1375,6 +1445,7 @@ public class bindings {
        public static native byte[] get_u8_slice_bytes(long slice_ptr);
        public static native long bytes_to_u8_vec(byte[] bytes);
        public static native long new_txpointer_copy_data(byte[] txdata);
+       public static native void txpointer_free(long ptr);
        public static native long vec_slice_len(long vec);
        public static native long new_empty_slice_vec();
 
@@ -1423,12 +1494,18 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data (JN
        LDKTransaction *txdata = (LDKTransaction*)MALLOC(sizeof(LDKTransaction), "LDKTransaction");
        txdata->datalen = (*env)->GetArrayLength(env, bytes);
        txdata->data = (uint8_t*)MALLOC(txdata->datalen, "Tx Data Bytes");
-       txdata->data_is_owned = true;
+       txdata->data_is_owned = false;
        (*env)->GetByteArrayRegion (env, bytes, 0, txdata->datalen, txdata->data);
        return (long)txdata;
 }
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_txpointer_1free (JNIEnv * env, jclass _b, jlong ptr) {
+       LDKTransaction *tx = (LDKTransaction*)ptr;
+       tx->data_is_owned = true;
+       Transaction_free(*tx);
+       FREE((void*)ptr);
+}
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env, jclass _a, jlong ptr) {
-        // Check offsets of a few Vec types are all consistent as we're meant to be generic across types
+       // Check offsets of a few Vec types are all consistent as we're meant to be generic across types
        _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_SignatureZ, datalen), "Vec<*> needs to be mapped identically");
        _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_MessageSendEventZ, datalen), "Vec<*> needs to be mapped identically");
        _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_EventZ, datalen), "Vec<*> needs to be mapped identically");
@@ -1437,7 +1514,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env
        return (long)vec->datalen;
 }
 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1empty_1slice_1vec (JNIEnv * _env, jclass _b) {
-        // Check sizes of a few Vec types are all consistent as we're meant to be generic across types
+       // Check sizes of a few Vec types are all consistent as we're meant to be generic across types
        _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_SignatureZ), "Vec<*> needs to be mapped identically");
        _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_MessageSendEventZ), "Vec<*> needs to be mapped identically");
        _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_EventZ), "Vec<*> needs to be mapped identically");
@@ -1459,7 +1536,7 @@ _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen),
         out_java_struct.write("""package org.ldk.structs;
 import java.util.LinkedList;
 class CommonBase {
-       final long ptr;
+       long ptr;
        LinkedList<Object> ptrs_to = new LinkedList();
        protected CommonBase(long ptr) { this.ptr = ptr; }
        public long _test_only_get_ptr() { return this.ptr; }
@@ -1568,7 +1645,7 @@ class CommonBase {
                             out_java_struct.write("\t@Override @SuppressWarnings(\"deprecation\")\n")
                             out_java_struct.write("\tprotected void finalize() throws Throwable {\n")
                             out_java_struct.write("\t\tsuper.finalize();\n")
-                        out_java_struct.write("\t\tbindings." + struct_name.replace("LDK","") + "_free(ptr);\n")
+                        out_java_struct.write("\t\tif (ptr != 0) { bindings." + struct_name.replace("LDK","") + "_free(ptr); }\n")
                         out_java_struct.write("\t}\n\n")
                 elif result_contents is not None:
                     result_templ_structs.add(struct_name)
@@ -1674,6 +1751,7 @@ class CommonBase {
                         out_java_struct.write(hu_struct_file_prefix)
                         out_java_struct.write("public class TxOut extends CommonBase{\n")
                         out_java_struct.write("\tTxOut(java.lang.Object _dummy, long ptr) { super(ptr); }\n")
+                        out_java_struct.write("\tlong to_c_ptr() { return 0; }\n")
                         # TODO: TxOut body
                         out_java_struct.write("}")
                 elif struct_name == "LDKTransaction":
@@ -1681,6 +1759,8 @@ class CommonBase {
                         out_java_struct.write(hu_struct_file_prefix)
                         out_java_struct.write("public class Transaction extends CommonBase{\n")
                         out_java_struct.write("\tTransaction(java.lang.Object _dummy, long ptr) { super(ptr); }\n")
+                        out_java_struct.write("\tpublic Transaction(byte[] data) { super(bindings.new_txpointer_copy_data(data)); }\n")
+                        out_java_struct.write("\t@Override public void finalize() throws Throwable { super.finalize(); bindings.txpointer_free(ptr); }\n")
                         # TODO: Transaction body
                         out_java_struct.write("}")
                 else:
@@ -1721,7 +1801,7 @@ class CommonBase {
                         out_java_struct.write("public class " + human_ty + " extends CommonBase {\n")
                         out_java_struct.write("\tprivate " + human_ty + "(Object _dummy, long ptr) { super(ptr); }\n")
                         out_java_struct.write("\tprotected void finalize() throws Throwable {\n")
-                        out_java_struct.write("\t\tbindings." + alias_match.group(2).replace("LDK","") + "_free(ptr); super.finalize();\n")
+                        out_java_struct.write("\t\tif (ptr != 0) { bindings." + alias_match.group(2).replace("LDK","") + "_free(ptr); } super.finalize();\n")
                         out_java_struct.write("\t}\n\n")
                         out_java_struct.write("\tstatic " + human_ty + " constr_from_ptr(long ptr) {\n")
                         out_java_struct.write("\t\tif (bindings." + alias_match.group(2) + "_result_ok(ptr)) {\n")
@@ -1753,7 +1833,7 @@ class CommonBase {
                             out_c.write("return *val->contents.result")
                         out_c.write(";\n}\n")
 
-                        out_java_struct.write("\t\tpublic " + res_map.java_hu_ty + " res;\n")
+                        out_java_struct.write("\t\tpublic final " + res_map.java_hu_ty + " res;\n")
                         out_java_struct.write("\t\tprivate " + human_ty + "_OK(Object _dummy, long ptr) {\n")
                         out_java_struct.write("\t\t\tsuper(_dummy, ptr);\n")
                         if res_map.to_hu_conv is not None:
@@ -1762,13 +1842,24 @@ class CommonBase {
                             out_java_struct.write("\n\t\t\tthis.res = " + res_map.to_hu_conv_name + ";\n")
                         else:
                             out_java_struct.write("\t\t\tthis.res = bindings." + alias_match.group(2) + "_get_ok(ptr);\n")
-                        out_java_struct.write("\t\t}\n\n")
+                        out_java_struct.write("\t\t}\n")
+                        if alias_match.group(2).startswith("LDKCResult_None"):
+                            out_java_struct.write("\t\tpublic " + human_ty + "_OK() {\n\t\t\tthis(null, bindings.C" + human_ty + "_ok());\n")
+                        else:
+                            out_java_struct.write("\t\tpublic " + human_ty + "_OK(" + res_map.java_hu_ty + " res) {\n")
+                            if res_map.from_hu_conv is not None:
+                                out_java_struct.write("\t\t\tthis(null, bindings.C" + human_ty + "_ok(" + res_map.from_hu_conv[0] + "));\n")
+                                if res_map.from_hu_conv[1] != "":
+                                    out_java_struct.write("\t\t\t" + res_map.from_hu_conv[1] + ";\n")
+                            else:
+                                out_java_struct.write("\t\t\tthis(null, bindings.C" + human_ty + "_ok(res));\n")
+                        out_java_struct.write("\t\t}\n\t}\n\n")
 
                         out_java.write("\tpublic static native " + err_map.java_ty + " " + alias_match.group(2) + "_get_err(long arg);\n")
                         out_c.write("JNIEXPORT " + err_map.c_ty + " JNICALL Java_org_ldk_impl_bindings_" + alias_match.group(2).replace("_", "_1") + "_1get_1err (JNIEnv * _env, jclass _a, jlong arg) {\n")
                         out_c.write("\t" + alias_match.group(2) + " *val = (" + alias_match.group(2) + "*)arg;\n")
                         out_c.write("\tCHECK(!val->result_ok);\n\t")
-                        out_java_struct.write("\t}\n\tpublic static final class " + human_ty + "_Err extends " + human_ty + " {\n")
+                        out_java_struct.write("\tpublic static final class " + human_ty + "_Err extends " + human_ty + " {\n")
                         if err_map.ret_conv is not None:
                             out_c.write(err_map.ret_conv[0].replace("\n", "\n\t") + "(*val->contents.err)")
                             out_c.write(err_map.ret_conv[1].replace("\n", "\n\t") + "\n\treturn " + err_map.ret_conv_name)
@@ -1776,7 +1867,7 @@ class CommonBase {
                             out_c.write("return *val->contents.err")
                         out_c.write(";\n}\n")
 
-                        out_java_struct.write("\t\tpublic " + err_map.java_hu_ty + " err;\n")
+                        out_java_struct.write("\t\tpublic final " + err_map.java_hu_ty + " err;\n")
                         out_java_struct.write("\t\tprivate " + human_ty + "_Err(Object _dummy, long ptr) {\n")
                         out_java_struct.write("\t\t\tsuper(_dummy, ptr);\n")
                         if err_map.to_hu_conv is not None:
@@ -1785,6 +1876,18 @@ class CommonBase {
                             out_java_struct.write("\n\t\t\tthis.err = " + err_map.to_hu_conv_name + ";\n")
                         else:
                             out_java_struct.write("\t\t\tthis.err = bindings." + alias_match.group(2) + "_get_err(ptr);\n")
+                        out_java_struct.write("\t\t}\n")
+
+                        if alias_match.group(2).endswith("NoneZ"):
+                            out_java_struct.write("\t\tpublic " + human_ty + "_Err() {\n\t\t\tthis(null, bindings.C" + human_ty + "_err());\n")
+                        else:
+                            out_java_struct.write("\t\tpublic " + human_ty + "_Err(" + err_map.java_hu_ty + " err) {\n")
+                            if err_map.from_hu_conv is not None:
+                                out_java_struct.write("\t\t\tthis(null, bindings.C" + human_ty + "_err(" + err_map.from_hu_conv[0] + "));\n")
+                                if err_map.from_hu_conv[1] != "":
+                                    out_java_struct.write("\t\t\t" + err_map.from_hu_conv[1] + ";\n")
+                            else:
+                                out_java_struct.write("\t\t\tthis(null, bindings.C" + human_ty + "_err(err));\n")
                         out_java_struct.write("\t\t}\n\t}\n}\n")
             elif fn_ptr is not None:
                 map_fn(line, fn_ptr, None, None)
index 6754b4af7519afa49c304b1683625b0b06503f53..f9c07cfb060809ae086b5a2d5d920b2083d35075 100644 (file)
@@ -23,6 +23,7 @@ public class bindings {
        public static native byte[] get_u8_slice_bytes(long slice_ptr);
        public static native long bytes_to_u8_vec(byte[] bytes);
        public static native long new_txpointer_copy_data(byte[] txdata);
+       public static native void txpointer_free(long ptr);
        public static native long vec_slice_len(long vec);
        public static native long new_empty_slice_vec();
 
index 40704400b512c24e6e696f568d1ede5de3826a1e..fdcfc09b7bb4b43601b9794f8890442439544434 100644 (file)
@@ -11,9 +11,8 @@ public class APIError extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.APIError_free(ptr);
+               if (ptr != 0) { bindings.APIError_free(ptr); }
        }
-       long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ }
        static APIError constr_from_ptr(long ptr) {
                bindings.LDKAPIError raw_val = bindings.LDKAPIError_ref_from_ptr(ptr);
                if (raw_val.getClass() == bindings.LDKAPIError.APIMisuseError.class) {
@@ -35,43 +34,38 @@ public class APIError extends CommonBase {
        }
 
        public final static class APIMisuseError extends APIError {
-               public byte[] err;
+               public final byte[] err;
                private APIMisuseError(long ptr, bindings.LDKAPIError.APIMisuseError obj) {
                        super(null, ptr);
                        this.err = obj.err;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class FeeRateTooHigh extends APIError {
-               public byte[] err;
-               public int feerate;
+               public final byte[] err;
+               public final int feerate;
                private FeeRateTooHigh(long ptr, bindings.LDKAPIError.FeeRateTooHigh obj) {
                        super(null, ptr);
                        this.err = obj.err;
                        this.feerate = obj.feerate;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class RouteError extends APIError {
-               public String err;
+               public final String err;
                private RouteError(long ptr, bindings.LDKAPIError.RouteError obj) {
                        super(null, ptr);
                        this.err = obj.err;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class ChannelUnavailable extends APIError {
-               public byte[] err;
+               public final byte[] err;
                private ChannelUnavailable(long ptr, bindings.LDKAPIError.ChannelUnavailable obj) {
                        super(null, ptr);
                        this.err = obj.err;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class MonitorUpdateFailed extends APIError {
                private MonitorUpdateFailed(long ptr, bindings.LDKAPIError.MonitorUpdateFailed obj) {
                        super(null, ptr);
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
 }
index e53d364dc6b57c4a62f1db3e5f481515d30602eb..f0f0a39afc54193b24a5ba654e9d89b63e4a340a 100644 (file)
@@ -11,7 +11,7 @@ public class AcceptChannel extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.AcceptChannel_free(ptr);
+               if (ptr != 0) { bindings.AcceptChannel_free(ptr); }
        }
 
        public static AcceptChannel constructor_clone(AcceptChannel orig) {
index 375dca92159062dd63a1b3a524a322fc97ad3073..15b3d7423df26c1bb581c2a75b7393295ae382da 100644 (file)
@@ -7,16 +7,31 @@ import java.util.Arrays;
 
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class Access extends CommonBase {
-       Access(Object _dummy, long ptr) { super(ptr); }
-       public Access(bindings.LDKAccess arg) {
+       final bindings.LDKAccess bindings_instance;
+       Access(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private Access(bindings.LDKAccess arg) {
                super(bindings.LDKAccess_new(arg));
                this.ptrs_to.add(arg);
+               this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
-               bindings.Access_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.Access_free(ptr); } super.finalize();
        }
 
+       public static interface AccessInterface {
+               Result_TxOutAccessErrorZ get_utxo(byte[] genesis_hash, long short_channel_id);
+       }
+       public Access(AccessInterface arg) {
+               this(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;
+                               ret.ptr = 0;
+                               return result;
+                       }
+               });
+       }
        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);
                Result_TxOutAccessErrorZ ret_hu_conv = Result_TxOutAccessErrorZ.constr_from_ptr(ret);
index f28ff8ad912622efad00a08895c0f4d5862f1db0..a3bbf117914545cf0a2cc9405aee4ad13b2ca0ae 100644 (file)
@@ -11,7 +11,7 @@ public class AnnouncementSignatures extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.AnnouncementSignatures_free(ptr);
+               if (ptr != 0) { bindings.AnnouncementSignatures_free(ptr); }
        }
 
        public static AnnouncementSignatures constructor_clone(AnnouncementSignatures orig) {
index 8ba7bf4cfae9f629dcf2b59f2fff26ccef5e7978..2af8bc66510bfb991ba61eb2059eb0ffc944aafc 100644 (file)
@@ -7,15 +7,28 @@ import java.util.Arrays;
 
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class BroadcasterInterface extends CommonBase {
-       BroadcasterInterface(Object _dummy, long ptr) { super(ptr); }
-       public BroadcasterInterface(bindings.LDKBroadcasterInterface arg) {
+       final bindings.LDKBroadcasterInterface bindings_instance;
+       BroadcasterInterface(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private BroadcasterInterface(bindings.LDKBroadcasterInterface arg) {
                super(bindings.LDKBroadcasterInterface_new(arg));
                this.ptrs_to.add(arg);
+               this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
-               bindings.BroadcasterInterface_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.BroadcasterInterface_free(ptr); } super.finalize();
        }
 
+       public static interface BroadcasterInterfaceInterface {
+               void broadcast_transaction(Transaction tx);
+       }
+       public BroadcasterInterface(BroadcasterInterfaceInterface arg) {
+               this(new bindings.LDKBroadcasterInterface() {
+                       @Override public void broadcast_transaction(long tx) {
+                               Transaction tx_conv = new Transaction(null, tx);
+                               arg.broadcast_transaction(tx_conv);
+                       }
+               });
+       }
        // Skipped BroadcasterInterface_broadcast_transaction
 }
index 90a3aa7549770da828356e43b46b089b80c3d253..236f8e3914e5167f1ad380749d840add4bd36bb9 100644 (file)
@@ -11,11 +11,11 @@ public class ChainMonitor extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChainMonitor_free(ptr);
+               if (ptr != 0) { bindings.ChainMonitor_free(ptr); }
        }
 
        public void block_connected(byte[] header, TwoTuple<Long, Transaction>[] txdata, int height) {
-               bindings.ChainMonitor_block_connected(this.ptr, header, Arrays.stream(txdata).mapToLong(arr_conv_29 -> /*TODO b*/0).toArray(), height);
+               bindings.ChainMonitor_block_connected(this.ptr, header, Arrays.stream(txdata).mapToLong(arr_conv_29 -> bindings.C2Tuple_usizeTransactionZ_new(arr_conv_29.a, arr_conv_29.b.ptr)).toArray(), height);
                /* TODO 2 TwoTuple<Long, Transaction>  */;
        }
 
index a15f3619fbe37d98aa614f20148f01b5b58cb5f0..1d481940a01ab926500c38aa5b82e6795a6bbd42 100644 (file)
@@ -11,7 +11,7 @@ public class ChannelAnnouncement extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChannelAnnouncement_free(ptr);
+               if (ptr != 0) { bindings.ChannelAnnouncement_free(ptr); }
        }
 
        public static ChannelAnnouncement constructor_clone(ChannelAnnouncement orig) {
index 6ac3d712a02d37ed2c36f480d1d32ef84a4585d7..ed37eb1d7e0d0e7b97000d4ad96cb0f57d5725cf 100644 (file)
@@ -11,7 +11,7 @@ public class ChannelConfig extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChannelConfig_free(ptr);
+               if (ptr != 0) { bindings.ChannelConfig_free(ptr); }
        }
 
        public static ChannelConfig constructor_clone(ChannelConfig orig) {
index 6e4f5bb89029a39908dbabca9983420b993584c7..dfc373e5a805a70412d2250bbce4f6622e1e1441 100644 (file)
@@ -11,7 +11,7 @@ public class ChannelDetails extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChannelDetails_free(ptr);
+               if (ptr != 0) { bindings.ChannelDetails_free(ptr); }
        }
 
        public static ChannelDetails constructor_clone(ChannelDetails orig) {
index 97bba12d5ded1bf2552b5738f6f6d441c2df840f..428ed8b7d8733fb30107a1aba6bb402255da3669 100644 (file)
@@ -11,7 +11,7 @@ public class ChannelFeatures extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChannelFeatures_free(ptr);
+               if (ptr != 0) { bindings.ChannelFeatures_free(ptr); }
        }
 
 }
index 33cf8e719b5e909630d10e2a995d10c3013734ef..98578edcf2afbdeb253108b464cb024b23b90575 100644 (file)
@@ -11,7 +11,7 @@ public class ChannelHandshakeConfig extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChannelHandshakeConfig_free(ptr);
+               if (ptr != 0) { bindings.ChannelHandshakeConfig_free(ptr); }
        }
 
        public static ChannelHandshakeConfig constructor_clone(ChannelHandshakeConfig orig) {
index bc99da646302b6130c82a1d71733eec91f118198..bf8249d00a0ce8f4718bd22cc80154755b5b9e89 100644 (file)
@@ -11,7 +11,7 @@ public class ChannelHandshakeLimits extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChannelHandshakeLimits_free(ptr);
+               if (ptr != 0) { bindings.ChannelHandshakeLimits_free(ptr); }
        }
 
        public static ChannelHandshakeLimits constructor_clone(ChannelHandshakeLimits orig) {
index 412f646ee8ac7a26c7e788b506b4496098b66f32..ae95717da10252fb50c30bbb0a35c9b3734231f2 100644 (file)
@@ -11,7 +11,7 @@ public class ChannelInfo extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChannelInfo_free(ptr);
+               if (ptr != 0) { bindings.ChannelInfo_free(ptr); }
        }
 
        public ChannelFeatures get_features() {
index 9dfce22c111698d86f48c796996e0a1bbc9cc94d..2639799f3f651d7653491274bd181b4b70a4b599 100644 (file)
@@ -7,16 +7,110 @@ import java.util.Arrays;
 
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class ChannelKeys extends CommonBase {
-       ChannelKeys(Object _dummy, long ptr) { super(ptr); }
-       public ChannelKeys(bindings.LDKChannelKeys arg) {
+       final bindings.LDKChannelKeys bindings_instance;
+       ChannelKeys(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private ChannelKeys(bindings.LDKChannelKeys arg) {
                super(bindings.LDKChannelKeys_new(arg));
                this.ptrs_to.add(arg);
+               this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
-               bindings.ChannelKeys_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.ChannelKeys_free(ptr); } super.finalize();
        }
 
+       public static interface ChannelKeysInterface {
+               byte[] get_per_commitment_point(long idx);
+               byte[] release_commitment_secret(long idx);
+               TwoTuple<Long, Long> key_derivation_params();
+               Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(int feerate_per_kw, Transaction commitment_tx, PreCalculatedTxCreationKeys keys, HTLCOutputInCommitment[] htlcs);
+               Result_SignatureNoneZ sign_holder_commitment(HolderCommitmentTransaction holder_commitment_tx);
+               Result_CVec_SignatureZNoneZ sign_holder_commitment_htlc_transactions(HolderCommitmentTransaction holder_commitment_tx);
+               Result_SignatureNoneZ sign_justice_transaction(Transaction justice_tx, long input, long amount, byte[] per_commitment_key, HTLCOutputInCommitment htlc);
+               Result_SignatureNoneZ sign_counterparty_htlc_transaction(Transaction htlc_tx, long input, long amount, byte[] per_commitment_point, HTLCOutputInCommitment htlc);
+               Result_SignatureNoneZ sign_closing_transaction(Transaction closing_tx);
+               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) {
+               this(new bindings.LDKChannelKeys() {
+                       @Override public byte[] get_per_commitment_point(long idx) {
+                               byte[] ret = arg.get_per_commitment_point(idx);
+                               return ret;
+                       }
+                       @Override public byte[] release_commitment_secret(long idx) {
+                               byte[] ret = arg.release_commitment_secret(idx);
+                               return ret;
+                       }
+                       @Override public long key_derivation_params() {
+                               TwoTuple<Long, Long> ret = arg.key_derivation_params();
+                               long result = bindings.C2Tuple_u64u64Z_new(ret.a, ret.b);
+                               return result;
+                       }
+                       @Override public long sign_counterparty_commitment(int feerate_per_kw, long commitment_tx, long keys, long[] htlcs) {
+                               Transaction commitment_tx_conv = new Transaction(null, commitment_tx);
+                               PreCalculatedTxCreationKeys keys_hu_conv = new PreCalculatedTxCreationKeys(null, keys);
+                               HTLCOutputInCommitment[] arr_conv_24_arr = new HTLCOutputInCommitment[htlcs.length];
+                               for (int y = 0; y < htlcs.length; y++) {
+                                       long arr_conv_24 = htlcs[y];
+                                       HTLCOutputInCommitment arr_conv_24_hu_conv = new HTLCOutputInCommitment(null, arr_conv_24);
+                                       arr_conv_24_arr[y] = arr_conv_24_hu_conv;
+                               }
+                               Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret = arg.sign_counterparty_commitment(feerate_per_kw, commitment_tx_conv, keys_hu_conv, arr_conv_24_arr);
+                               long result = ret != null ? ret.ptr : 0;
+                               ret.ptr = 0;
+                               return result;
+                       }
+                       @Override public long sign_holder_commitment(long holder_commitment_tx) {
+                               HolderCommitmentTransaction holder_commitment_tx_hu_conv = new HolderCommitmentTransaction(null, holder_commitment_tx);
+                               Result_SignatureNoneZ ret = arg.sign_holder_commitment(holder_commitment_tx_hu_conv);
+                               long result = ret != null ? ret.ptr : 0;
+                               ret.ptr = 0;
+                               return result;
+                       }
+                       @Override public long sign_holder_commitment_htlc_transactions(long holder_commitment_tx) {
+                               HolderCommitmentTransaction holder_commitment_tx_hu_conv = new HolderCommitmentTransaction(null, holder_commitment_tx);
+                               Result_CVec_SignatureZNoneZ ret = arg.sign_holder_commitment_htlc_transactions(holder_commitment_tx_hu_conv);
+                               long result = ret != null ? ret.ptr : 0;
+                               ret.ptr = 0;
+                               return result;
+                       }
+                       @Override public long sign_justice_transaction(long justice_tx, long input, long amount, byte[] per_commitment_key, long htlc) {
+                               Transaction justice_tx_conv = new Transaction(null, justice_tx);
+                               HTLCOutputInCommitment htlc_hu_conv = new HTLCOutputInCommitment(null, htlc);
+                               Result_SignatureNoneZ ret = arg.sign_justice_transaction(justice_tx_conv, input, amount, per_commitment_key, htlc_hu_conv);
+                               long result = ret != null ? ret.ptr : 0;
+                               ret.ptr = 0;
+                               return result;
+                       }
+                       @Override public long sign_counterparty_htlc_transaction(long htlc_tx, long input, long amount, byte[] per_commitment_point, long htlc) {
+                               Transaction htlc_tx_conv = new Transaction(null, htlc_tx);
+                               HTLCOutputInCommitment htlc_hu_conv = new HTLCOutputInCommitment(null, htlc);
+                               Result_SignatureNoneZ ret = arg.sign_counterparty_htlc_transaction(htlc_tx_conv, input, amount, per_commitment_point, htlc_hu_conv);
+                               long result = ret != null ? ret.ptr : 0;
+                               ret.ptr = 0;
+                               return result;
+                       }
+                       @Override public long sign_closing_transaction(long closing_tx) {
+                               Transaction closing_tx_conv = new Transaction(null, closing_tx);
+                               Result_SignatureNoneZ ret = arg.sign_closing_transaction(closing_tx_conv);
+                               long result = ret != null ? ret.ptr : 0;
+                               ret.ptr = 0;
+                               return result;
+                       }
+                       @Override public long sign_channel_announcement(long msg) {
+                               UnsignedChannelAnnouncement msg_hu_conv = new UnsignedChannelAnnouncement(null, msg);
+                               Result_SignatureNoneZ ret = arg.sign_channel_announcement(msg_hu_conv);
+                               long result = ret != null ? ret.ptr : 0;
+                               ret.ptr = 0;
+                               return result;
+                       }
+                       @Override public void on_accept(long channel_points, short counterparty_selected_contest_delay, short holder_selected_contest_delay) {
+                               ChannelPublicKeys channel_points_hu_conv = new ChannelPublicKeys(null, channel_points);
+                               arg.on_accept(channel_points_hu_conv, counterparty_selected_contest_delay, holder_selected_contest_delay);
+                       }
+               });
+       }
        public byte[] get_per_commitment_point(long idx) {
                byte[] ret = bindings.ChannelKeys_get_per_commitment_point(this.ptr, idx);
                return ret;
index 56198363c4804ac1551d6db38989dcceed41b3e3..10dc95a2fe21b6cb8fe4c552c5f5bf78685b5b70 100644 (file)
@@ -11,7 +11,7 @@ public class ChannelManager extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChannelManager_free(ptr);
+               if (ptr != 0) { bindings.ChannelManager_free(ptr); }
        }
 
        public static ChannelManager constructor_new(LDKNetwork network, FeeEstimator fee_est, Watch chain_monitor, BroadcasterInterface tx_broadcaster, Logger logger, KeysInterface keys_manager, UserConfig config, long current_blockchain_height) {
@@ -85,7 +85,7 @@ public class ChannelManager extends CommonBase {
        }
 
        public void broadcast_node_announcement(byte[] rgb, byte[] alias, NetAddress[] addresses) {
-               bindings.ChannelManager_broadcast_node_announcement(this.ptr, rgb, alias, Arrays.stream(addresses).mapToLong(arr_conv_12 -> arr_conv_12.conv_to_c()).toArray());
+               bindings.ChannelManager_broadcast_node_announcement(this.ptr, rgb, alias, Arrays.stream(addresses).mapToLong(arr_conv_12 -> arr_conv_12.ptr).toArray());
                /* TODO 2 NetAddress  */;
        }
 
@@ -132,7 +132,7 @@ public class ChannelManager extends CommonBase {
        }
 
        public void block_connected(byte[] header, TwoTuple<Long, Transaction>[] txdata, int height) {
-               bindings.ChannelManager_block_connected(this.ptr, header, Arrays.stream(txdata).mapToLong(arr_conv_29 -> /*TODO b*/0).toArray(), height);
+               bindings.ChannelManager_block_connected(this.ptr, header, Arrays.stream(txdata).mapToLong(arr_conv_29 -> bindings.C2Tuple_usizeTransactionZ_new(arr_conv_29.a, arr_conv_29.b.ptr)).toArray(), height);
                /* TODO 2 TwoTuple<Long, Transaction>  */;
        }
 
index 26dc48ae2ab9eac2d42b4a71490e17300fb0dfe8..de589498ea32038c12ab02916ee27fe77203ef25 100644 (file)
@@ -11,7 +11,7 @@ public class ChannelManagerReadArgs extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChannelManagerReadArgs_free(ptr);
+               if (ptr != 0) { bindings.ChannelManagerReadArgs_free(ptr); }
        }
 
        public KeysInterface get_keys_manager() {
index 4ad07c9a7a4eeed41a31fb4dba41ec5b1aabcb79..d920f2d49697fd70003c19d85d13cc88c1280e80 100644 (file)
@@ -7,16 +7,120 @@ import java.util.Arrays;
 
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class ChannelMessageHandler extends CommonBase {
-       ChannelMessageHandler(Object _dummy, long ptr) { super(ptr); }
-       public ChannelMessageHandler(bindings.LDKChannelMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) {
+       final bindings.LDKChannelMessageHandler bindings_instance;
+       ChannelMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private ChannelMessageHandler(bindings.LDKChannelMessageHandler arg, bindings.LDKMessageSendEventsProvider MessageSendEventsProvider) {
                super(bindings.LDKChannelMessageHandler_new(arg, MessageSendEventsProvider));
                this.ptrs_to.add(arg);
+               this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
-               bindings.ChannelMessageHandler_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.ChannelMessageHandler_free(ptr); } super.finalize();
+       }
+
+       public static interface ChannelMessageHandlerInterface {
+               void handle_open_channel(byte[] their_node_id, InitFeatures their_features, OpenChannel msg);
+               void handle_accept_channel(byte[] their_node_id, InitFeatures their_features, AcceptChannel msg);
+               void handle_funding_created(byte[] their_node_id, FundingCreated msg);
+               void handle_funding_signed(byte[] their_node_id, FundingSigned msg);
+               void handle_funding_locked(byte[] their_node_id, FundingLocked msg);
+               void handle_shutdown(byte[] their_node_id, Shutdown msg);
+               void handle_closing_signed(byte[] their_node_id, ClosingSigned msg);
+               void handle_update_add_htlc(byte[] their_node_id, UpdateAddHTLC msg);
+               void handle_update_fulfill_htlc(byte[] their_node_id, UpdateFulfillHTLC msg);
+               void handle_update_fail_htlc(byte[] their_node_id, UpdateFailHTLC msg);
+               void handle_update_fail_malformed_htlc(byte[] their_node_id, UpdateFailMalformedHTLC msg);
+               void handle_commitment_signed(byte[] their_node_id, CommitmentSigned msg);
+               void handle_revoke_and_ack(byte[] their_node_id, RevokeAndACK msg);
+               void handle_update_fee(byte[] their_node_id, UpdateFee msg);
+               void handle_announcement_signatures(byte[] their_node_id, AnnouncementSignatures msg);
+               void peer_disconnected(byte[] their_node_id, boolean no_connection_possible);
+               void peer_connected(byte[] their_node_id, Init msg);
+               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() {
+                       @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);
+                               arg.handle_open_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
+                       }
+                       @Override public void handle_accept_channel(byte[] their_node_id, long their_features, long msg) {
+                               InitFeatures their_features_hu_conv = new InitFeatures(null, their_features);
+                               AcceptChannel msg_hu_conv = new AcceptChannel(null, msg);
+                               arg.handle_accept_channel(their_node_id, their_features_hu_conv, msg_hu_conv);
+                       }
+                       @Override public void handle_funding_created(byte[] their_node_id, long msg) {
+                               FundingCreated msg_hu_conv = new FundingCreated(null, msg);
+                               arg.handle_funding_created(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void handle_funding_signed(byte[] their_node_id, long msg) {
+                               FundingSigned msg_hu_conv = new FundingSigned(null, msg);
+                               arg.handle_funding_signed(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void handle_funding_locked(byte[] their_node_id, long msg) {
+                               FundingLocked msg_hu_conv = new FundingLocked(null, msg);
+                               arg.handle_funding_locked(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void handle_shutdown(byte[] their_node_id, long msg) {
+                               Shutdown msg_hu_conv = new Shutdown(null, msg);
+                               arg.handle_shutdown(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void handle_closing_signed(byte[] their_node_id, long msg) {
+                               ClosingSigned msg_hu_conv = new ClosingSigned(null, msg);
+                               arg.handle_closing_signed(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void handle_update_add_htlc(byte[] their_node_id, long msg) {
+                               UpdateAddHTLC msg_hu_conv = new UpdateAddHTLC(null, msg);
+                               arg.handle_update_add_htlc(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void handle_update_fulfill_htlc(byte[] their_node_id, long msg) {
+                               UpdateFulfillHTLC msg_hu_conv = new UpdateFulfillHTLC(null, msg);
+                               arg.handle_update_fulfill_htlc(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void handle_update_fail_htlc(byte[] their_node_id, long msg) {
+                               UpdateFailHTLC msg_hu_conv = new UpdateFailHTLC(null, msg);
+                               arg.handle_update_fail_htlc(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void handle_update_fail_malformed_htlc(byte[] their_node_id, long msg) {
+                               UpdateFailMalformedHTLC msg_hu_conv = new UpdateFailMalformedHTLC(null, msg);
+                               arg.handle_update_fail_malformed_htlc(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void handle_commitment_signed(byte[] their_node_id, long msg) {
+                               CommitmentSigned msg_hu_conv = new CommitmentSigned(null, msg);
+                               arg.handle_commitment_signed(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void handle_revoke_and_ack(byte[] their_node_id, long msg) {
+                               RevokeAndACK msg_hu_conv = new RevokeAndACK(null, msg);
+                               arg.handle_revoke_and_ack(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void handle_update_fee(byte[] their_node_id, long msg) {
+                               UpdateFee msg_hu_conv = new UpdateFee(null, msg);
+                               arg.handle_update_fee(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void handle_announcement_signatures(byte[] their_node_id, long msg) {
+                               AnnouncementSignatures msg_hu_conv = new AnnouncementSignatures(null, msg);
+                               arg.handle_announcement_signatures(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void peer_disconnected(byte[] their_node_id, boolean no_connection_possible) {
+                               arg.peer_disconnected(their_node_id, no_connection_possible);
+                       }
+                       @Override public void peer_connected(byte[] their_node_id, long msg) {
+                               Init msg_hu_conv = new Init(null, msg);
+                               arg.peer_connected(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void handle_channel_reestablish(byte[] their_node_id, long msg) {
+                               ChannelReestablish msg_hu_conv = new ChannelReestablish(null, msg);
+                               arg.handle_channel_reestablish(their_node_id, msg_hu_conv);
+                       }
+                       @Override public void handle_error(byte[] their_node_id, long msg) {
+                               ErrorMessage msg_hu_conv = new ErrorMessage(null, msg);
+                               arg.handle_error(their_node_id, msg_hu_conv);
+                       }
+               }, new MessageSendEventsProvider(MessageSendEventsProvider).bindings_instance);
        }
-
        // Skipped ChannelMessageHandler_handle_open_channel
        // Skipped ChannelMessageHandler_handle_accept_channel
        public void handle_funding_created(byte[] their_node_id, FundingCreated msg) {
index 1e95a1b56818f5489adac1eacaab0b17dbed1155..a641c59f1583c930bd47f3f60418e767037ef6aa 100644 (file)
@@ -11,7 +11,7 @@ public class ChannelMonitor extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChannelMonitor_free(ptr);
+               if (ptr != 0) { bindings.ChannelMonitor_free(ptr); }
        }
 
        public Result_NoneMonitorUpdateErrorZ update_monitor(ChannelMonitorUpdate updates, BroadcasterInterface broadcaster, Logger logger) {
@@ -65,7 +65,7 @@ public class ChannelMonitor extends CommonBase {
        }
 
        public TwoTuple<byte[], TxOut[]>[] block_connected(byte[] header, TwoTuple<Long, Transaction>[] txdata, int height, BroadcasterInterface broadcaster, FeeEstimator fee_estimator, Logger logger) {
-               long[] ret = bindings.ChannelMonitor_block_connected(this.ptr, header, Arrays.stream(txdata).mapToLong(arr_conv_29 -> /*TODO b*/0).toArray(), height, broadcaster == null ? 0 : broadcaster.ptr, fee_estimator == null ? 0 : fee_estimator.ptr, logger == null ? 0 : logger.ptr);
+               long[] ret = bindings.ChannelMonitor_block_connected(this.ptr, header, Arrays.stream(txdata).mapToLong(arr_conv_29 -> bindings.C2Tuple_usizeTransactionZ_new(arr_conv_29.a, arr_conv_29.b.ptr)).toArray(), height, broadcaster == null ? 0 : broadcaster.ptr, fee_estimator == null ? 0 : fee_estimator.ptr, logger == null ? 0 : logger.ptr);
                TwoTuple<byte[], TxOut[]>[] arr_conv_27_arr = new TwoTuple[ret.length];
                for (int b = 0; b < ret.length; b++) {
                        long arr_conv_27 = ret[b];
index 9cc36c1af04178997b4e97d41c9ad58fb501c7eb..59c53a73e4c5edd32497abde44740e029aeb372f 100644 (file)
@@ -11,7 +11,7 @@ public class ChannelMonitorUpdate extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChannelMonitorUpdate_free(ptr);
+               if (ptr != 0) { bindings.ChannelMonitorUpdate_free(ptr); }
        }
 
        public static ChannelMonitorUpdate constructor_clone(ChannelMonitorUpdate orig) {
index 882bdd0812e0513eccbe5f9f0a3df9a7dcbb22d4..3dfd7c06e9efdd28b865d03257666e01832bd6a8 100644 (file)
@@ -11,7 +11,7 @@ public class ChannelPublicKeys extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChannelPublicKeys_free(ptr);
+               if (ptr != 0) { bindings.ChannelPublicKeys_free(ptr); }
        }
 
        public static ChannelPublicKeys constructor_clone(ChannelPublicKeys orig) {
index ceb78ed4e59b9fdb008421db20a80ee6ec1bcd3f..1869145a8834b129b68a1228e99e0b589d2aba4e 100644 (file)
@@ -11,7 +11,7 @@ public class ChannelReestablish extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChannelReestablish_free(ptr);
+               if (ptr != 0) { bindings.ChannelReestablish_free(ptr); }
        }
 
        public static ChannelReestablish constructor_clone(ChannelReestablish orig) {
index 3fe97d5ac2bd2ddc6469830ba4f02b78d7b8dab0..2409134c233e4b4932e16c193b0339e74ea98159 100644 (file)
@@ -11,7 +11,7 @@ public class ChannelUpdate extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ChannelUpdate_free(ptr);
+               if (ptr != 0) { bindings.ChannelUpdate_free(ptr); }
        }
 
        public static ChannelUpdate constructor_clone(ChannelUpdate orig) {
index a8a0063ea4c9654dd01ac124d68a8f07283323ab..fe05ebef55ffd58e4ad28ee05cde39958adf1b31 100644 (file)
@@ -11,7 +11,7 @@ public class ClosingSigned extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ClosingSigned_free(ptr);
+               if (ptr != 0) { bindings.ClosingSigned_free(ptr); }
        }
 
        public static ClosingSigned constructor_clone(ClosingSigned orig) {
index bffa91b785f967a1fc3efc11cd1633fff11395a3..a29b4623976ced2947cb848dd9ee69a122cb1404 100644 (file)
@@ -11,7 +11,7 @@ public class CommitmentSigned extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.CommitmentSigned_free(ptr);
+               if (ptr != 0) { bindings.CommitmentSigned_free(ptr); }
        }
 
        public static CommitmentSigned constructor_clone(CommitmentSigned orig) {
index b78bf90731df7e76758229ff87384ebbd9578c77..01e7a975e85964e2cdabaeed420023440a59edfd 100644 (file)
@@ -11,7 +11,7 @@ public class CommitmentUpdate extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.CommitmentUpdate_free(ptr);
+               if (ptr != 0) { bindings.CommitmentUpdate_free(ptr); }
        }
 
        public static CommitmentUpdate constructor_clone(CommitmentUpdate orig) {
index 42971b3f35b3e36f04d0946f96cf47921c4b5af7..acff6661da49875fe3379c8c4dab9052827246ab 100644 (file)
@@ -1,7 +1,7 @@
 package org.ldk.structs;
 import java.util.LinkedList;
 class CommonBase {
-       final long ptr;
+       long ptr;
        LinkedList<Object> ptrs_to = new LinkedList();
        protected CommonBase(long ptr) { this.ptr = ptr; }
        public long _test_only_get_ptr() { return this.ptr; }
index 2a5438e1836483a2cc41345c25905393c0499421..fa0cd512c59c1cb6731ecd543c1c53b2a2399d2d 100644 (file)
@@ -11,7 +11,7 @@ public class DataLossProtect extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.DataLossProtect_free(ptr);
+               if (ptr != 0) { bindings.DataLossProtect_free(ptr); }
        }
 
        public static DataLossProtect constructor_clone(DataLossProtect orig) {
index 4ed9f4de51186748c8c58e63429cc62258952312..e8cec47071df259dcd5318d91d8e9bd1392502f7 100644 (file)
@@ -11,7 +11,7 @@ public class DecodeError extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.DecodeError_free(ptr);
+               if (ptr != 0) { bindings.DecodeError_free(ptr); }
        }
 
 }
index 0b6383564586d24709b2bfe0489f02bcc752dbbf..6120b30e6cbfb178e9d7fcf8780e9f150de2b2e0 100644 (file)
@@ -11,7 +11,7 @@ public class DirectionalChannelInfo extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.DirectionalChannelInfo_free(ptr);
+               if (ptr != 0) { bindings.DirectionalChannelInfo_free(ptr); }
        }
 
        public int get_last_update() {
index e5ccec8d4c8606978893365203868c49adfbadfb..efe34dd55c7401786611254727266e07f6265807 100644 (file)
@@ -11,9 +11,8 @@ public class ErrorAction extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ErrorAction_free(ptr);
+               if (ptr != 0) { bindings.ErrorAction_free(ptr); }
        }
-       long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ }
        static ErrorAction constr_from_ptr(long ptr) {
                bindings.LDKErrorAction raw_val = bindings.LDKErrorAction_ref_from_ptr(ptr);
                if (raw_val.getClass() == bindings.LDKErrorAction.DisconnectPeer.class) {
@@ -29,29 +28,26 @@ public class ErrorAction extends CommonBase {
        }
 
        public final static class DisconnectPeer extends ErrorAction {
-               public ErrorMessage msg;
+               public final ErrorMessage msg;
                private DisconnectPeer(long ptr, bindings.LDKErrorAction.DisconnectPeer obj) {
                        super(null, ptr);
                        long msg = obj.msg;
                        ErrorMessage msg_hu_conv = new ErrorMessage(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class IgnoreError extends ErrorAction {
                private IgnoreError(long ptr, bindings.LDKErrorAction.IgnoreError obj) {
                        super(null, ptr);
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class SendErrorMessage extends ErrorAction {
-               public ErrorMessage msg;
+               public final ErrorMessage msg;
                private SendErrorMessage(long ptr, bindings.LDKErrorAction.SendErrorMessage obj) {
                        super(null, ptr);
                        long msg = obj.msg;
                        ErrorMessage msg_hu_conv = new ErrorMessage(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
 }
index d0182f319b3e18ef8248c7549c7c47277a35ed7b..73788d483eba68a0dc03e86d524397c18af0589a 100644 (file)
@@ -11,7 +11,7 @@ public class ErrorMessage extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ErrorMessage_free(ptr);
+               if (ptr != 0) { bindings.ErrorMessage_free(ptr); }
        }
 
        public static ErrorMessage constructor_clone(ErrorMessage orig) {
index 01a59a8f84a7dc95ba172fd3a38fcebc15b32cb8..9e3ee3f2aeacd95e073b9953c3302333d105d1a6 100644 (file)
@@ -11,9 +11,8 @@ public class Event extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.Event_free(ptr);
+               if (ptr != 0) { bindings.Event_free(ptr); }
        }
-       long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ }
        static Event constr_from_ptr(long ptr) {
                bindings.LDKEvent raw_val = bindings.LDKEvent_ref_from_ptr(ptr);
                if (raw_val.getClass() == bindings.LDKEvent.FundingGenerationReady.class) {
@@ -41,10 +40,10 @@ public class Event extends CommonBase {
        }
 
        public final static class FundingGenerationReady extends Event {
-               public byte[] temporary_channel_id;
-               public long channel_value_satoshis;
-               public byte[] output_script;
-               public long user_channel_id;
+               public final byte[] temporary_channel_id;
+               public final long channel_value_satoshis;
+               public final byte[] output_script;
+               public final long user_channel_id;
                private FundingGenerationReady(long ptr, bindings.LDKEvent.FundingGenerationReady obj) {
                        super(null, ptr);
                        this.temporary_channel_id = obj.temporary_channel_id;
@@ -52,11 +51,10 @@ public class Event extends CommonBase {
                        this.output_script = obj.output_script;
                        this.user_channel_id = obj.user_channel_id;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class FundingBroadcastSafe extends Event {
-               public OutPoint funding_txo;
-               public long user_channel_id;
+               public final OutPoint funding_txo;
+               public final long user_channel_id;
                private FundingBroadcastSafe(long ptr, bindings.LDKEvent.FundingBroadcastSafe obj) {
                        super(null, ptr);
                        long funding_txo = obj.funding_txo;
@@ -64,48 +62,43 @@ public class Event extends CommonBase {
                        this.funding_txo = funding_txo_hu_conv;
                        this.user_channel_id = obj.user_channel_id;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class PaymentReceived extends Event {
-               public byte[] payment_hash;
-               public byte[] payment_secret;
-               public long amt;
+               public final byte[] payment_hash;
+               public final byte[] payment_secret;
+               public final long amt;
                private PaymentReceived(long ptr, bindings.LDKEvent.PaymentReceived obj) {
                        super(null, ptr);
                        this.payment_hash = obj.payment_hash;
                        this.payment_secret = obj.payment_secret;
                        this.amt = obj.amt;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class PaymentSent extends Event {
-               public byte[] payment_preimage;
+               public final byte[] payment_preimage;
                private PaymentSent(long ptr, bindings.LDKEvent.PaymentSent obj) {
                        super(null, ptr);
                        this.payment_preimage = obj.payment_preimage;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class PaymentFailed extends Event {
-               public byte[] payment_hash;
-               public boolean rejected_by_dest;
+               public final byte[] payment_hash;
+               public final boolean rejected_by_dest;
                private PaymentFailed(long ptr, bindings.LDKEvent.PaymentFailed obj) {
                        super(null, ptr);
                        this.payment_hash = obj.payment_hash;
                        this.rejected_by_dest = obj.rejected_by_dest;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class PendingHTLCsForwardable extends Event {
-               public long time_forwardable;
+               public final long time_forwardable;
                private PendingHTLCsForwardable(long ptr, bindings.LDKEvent.PendingHTLCsForwardable obj) {
                        super(null, ptr);
                        this.time_forwardable = obj.time_forwardable;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class SpendableOutputs extends Event {
-               public SpendableOutputDescriptor[] outputs;
+               public final SpendableOutputDescriptor[] outputs;
                private SpendableOutputs(long ptr, bindings.LDKEvent.SpendableOutputs obj) {
                        super(null, ptr);
                        long[] outputs = obj.outputs;
@@ -117,6 +110,5 @@ public class Event extends CommonBase {
                        }
                        this.outputs = arr_conv_27_arr;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
 }
index ed6ef60239d1f9df74caa63b69150a29cb50ed21..960ab4494333f475f11286740592d7870071f834 100644 (file)
@@ -7,16 +7,31 @@ import java.util.Arrays;
 
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class EventsProvider extends CommonBase {
-       EventsProvider(Object _dummy, long ptr) { super(ptr); }
-       public EventsProvider(bindings.LDKEventsProvider arg) {
+       final bindings.LDKEventsProvider bindings_instance;
+       EventsProvider(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private EventsProvider(bindings.LDKEventsProvider arg) {
                super(bindings.LDKEventsProvider_new(arg));
                this.ptrs_to.add(arg);
+               this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
-               bindings.EventsProvider_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.EventsProvider_free(ptr); } super.finalize();
        }
 
+       public static interface EventsProviderInterface {
+               Event[] get_and_clear_pending_events();
+       }
+       public EventsProvider(EventsProviderInterface arg) {
+               this(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 2 Event  */
+                               return result;
+                       }
+               });
+       }
        public Event[] get_and_clear_pending_events() {
                long[] ret = bindings.EventsProvider_get_and_clear_pending_events(this.ptr);
                Event[] arr_conv_7_arr = new Event[ret.length];
index 13c16315a47745dee7b01e08832b77afc1d8e960..dd7c05f28434b1f2c5e5129a688bdda9754c1d01 100644 (file)
@@ -7,16 +7,29 @@ import java.util.Arrays;
 
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class FeeEstimator extends CommonBase {
-       FeeEstimator(Object _dummy, long ptr) { super(ptr); }
-       public FeeEstimator(bindings.LDKFeeEstimator arg) {
+       final bindings.LDKFeeEstimator bindings_instance;
+       FeeEstimator(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private FeeEstimator(bindings.LDKFeeEstimator arg) {
                super(bindings.LDKFeeEstimator_new(arg));
                this.ptrs_to.add(arg);
+               this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
-               bindings.FeeEstimator_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.FeeEstimator_free(ptr); } super.finalize();
        }
 
+       public static interface FeeEstimatorInterface {
+               int get_est_sat_per_1000_weight(LDKConfirmationTarget confirmation_target);
+       }
+       public FeeEstimator(FeeEstimatorInterface arg) {
+               this(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;
+                       }
+               });
+       }
        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);
                return ret;
index b4094bd1f3f3dc7dafc9265f9de490e4e5bbe22f..6ec794e6479b99070ba00eef14f95b9f3130c6a9 100644 (file)
@@ -7,16 +7,33 @@ import java.util.Arrays;
 
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class Filter extends CommonBase {
-       Filter(Object _dummy, long ptr) { super(ptr); }
-       public Filter(bindings.LDKFilter arg) {
+       final bindings.LDKFilter bindings_instance;
+       Filter(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private Filter(bindings.LDKFilter arg) {
                super(bindings.LDKFilter_new(arg));
                this.ptrs_to.add(arg);
+               this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
-               bindings.Filter_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.Filter_free(ptr); } super.finalize();
        }
 
+       public static interface FilterInterface {
+               void register_tx(byte[] txid, byte[] script_pubkey);
+               void register_output(OutPoint outpoint, byte[] script_pubkey);
+       }
+       public Filter(FilterInterface arg) {
+               this(new bindings.LDKFilter() {
+                       @Override public void register_tx(byte[] txid, byte[] script_pubkey) {
+                               arg.register_tx(txid, script_pubkey);
+                       }
+                       @Override public void register_output(long outpoint, byte[] script_pubkey) {
+                               OutPoint outpoint_hu_conv = new OutPoint(null, outpoint);
+                               arg.register_output(outpoint_hu_conv, script_pubkey);
+                       }
+               });
+       }
        public void register_tx(byte[] txid, byte[] script_pubkey) {
                bindings.Filter_register_tx(this.ptr, txid, script_pubkey);
        }
index f45f2c6889509ecda4229cb4c96de296ee59cbe9..e5e0ff9aa9f20ec17d035768e9b10d8268c0852c 100644 (file)
@@ -11,7 +11,7 @@ public class FundingCreated extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.FundingCreated_free(ptr);
+               if (ptr != 0) { bindings.FundingCreated_free(ptr); }
        }
 
        public static FundingCreated constructor_clone(FundingCreated orig) {
index 1cf7d7ac492064421b23077d5082af9fd3891da9..e6e2eea5fccca2bbbccbbb2087ff1a85d6a87bd1 100644 (file)
@@ -11,7 +11,7 @@ public class FundingLocked extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.FundingLocked_free(ptr);
+               if (ptr != 0) { bindings.FundingLocked_free(ptr); }
        }
 
        public static FundingLocked constructor_clone(FundingLocked orig) {
index 640c3c1e279e7b102e479f64a67ea55da0f347ce..9af23467cc4d3273cee9b774f01d444b2d362e60 100644 (file)
@@ -11,7 +11,7 @@ public class FundingSigned extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.FundingSigned_free(ptr);
+               if (ptr != 0) { bindings.FundingSigned_free(ptr); }
        }
 
        public static FundingSigned constructor_clone(FundingSigned orig) {
index 5efcccf8665230d26b03a8e1f7c59b7d9df243b2..abc141b3458684e7230560adde93b7dcf9ef3cb2 100644 (file)
@@ -11,7 +11,7 @@ public class GossipTimestampFilter extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.GossipTimestampFilter_free(ptr);
+               if (ptr != 0) { bindings.GossipTimestampFilter_free(ptr); }
        }
 
        public static GossipTimestampFilter constructor_clone(GossipTimestampFilter orig) {
index 69dccb8e76a2d5e8ceab5b068e74204d41f7e0f9..92a5c0188bf302edd9dd66b14f677648994b02b7 100644 (file)
@@ -11,9 +11,8 @@ public class HTLCFailChannelUpdate extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.HTLCFailChannelUpdate_free(ptr);
+               if (ptr != 0) { bindings.HTLCFailChannelUpdate_free(ptr); }
        }
-       long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ }
        static HTLCFailChannelUpdate constr_from_ptr(long ptr) {
                bindings.LDKHTLCFailChannelUpdate raw_val = bindings.LDKHTLCFailChannelUpdate_ref_from_ptr(ptr);
                if (raw_val.getClass() == bindings.LDKHTLCFailChannelUpdate.ChannelUpdateMessage.class) {
@@ -29,33 +28,30 @@ public class HTLCFailChannelUpdate extends CommonBase {
        }
 
        public final static class ChannelUpdateMessage extends HTLCFailChannelUpdate {
-               public ChannelUpdate msg;
+               public final ChannelUpdate msg;
                private ChannelUpdateMessage(long ptr, bindings.LDKHTLCFailChannelUpdate.ChannelUpdateMessage obj) {
                        super(null, ptr);
                        long msg = obj.msg;
                        ChannelUpdate msg_hu_conv = new ChannelUpdate(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class ChannelClosed extends HTLCFailChannelUpdate {
-               public long short_channel_id;
-               public boolean is_permanent;
+               public final long short_channel_id;
+               public final boolean is_permanent;
                private ChannelClosed(long ptr, bindings.LDKHTLCFailChannelUpdate.ChannelClosed obj) {
                        super(null, ptr);
                        this.short_channel_id = obj.short_channel_id;
                        this.is_permanent = obj.is_permanent;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class NodeFailure extends HTLCFailChannelUpdate {
-               public byte[] node_id;
-               public boolean is_permanent;
+               public final byte[] node_id;
+               public final boolean is_permanent;
                private NodeFailure(long ptr, bindings.LDKHTLCFailChannelUpdate.NodeFailure obj) {
                        super(null, ptr);
                        this.node_id = obj.node_id;
                        this.is_permanent = obj.is_permanent;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
 }
index c6e730a75d43fd079857d924644f3278909b1117..54745ba91a66e4f00c0c9c22081c79238776b836 100644 (file)
@@ -11,7 +11,7 @@ public class HTLCOutputInCommitment extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.HTLCOutputInCommitment_free(ptr);
+               if (ptr != 0) { bindings.HTLCOutputInCommitment_free(ptr); }
        }
 
        public static HTLCOutputInCommitment constructor_clone(HTLCOutputInCommitment orig) {
index 008ca802d19095baad392c0ddb168220adee456e..2f5fb3e3ce4db56c860c3fae849c121fb0c1e664 100644 (file)
@@ -11,7 +11,7 @@ public class HTLCUpdate extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.HTLCUpdate_free(ptr);
+               if (ptr != 0) { bindings.HTLCUpdate_free(ptr); }
        }
 
        public static HTLCUpdate constructor_clone(HTLCUpdate orig) {
index 5b26ba423b712674c5e33a1ff4b374a030aa629a..eb8dbe0c6a547d4d9f302916e4075c0ded30a9e2 100644 (file)
@@ -11,7 +11,7 @@ public class HolderCommitmentTransaction extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.HolderCommitmentTransaction_free(ptr);
+               if (ptr != 0) { bindings.HolderCommitmentTransaction_free(ptr); }
        }
 
        public static HolderCommitmentTransaction constructor_clone(HolderCommitmentTransaction orig) {
@@ -42,7 +42,7 @@ public class HolderCommitmentTransaction extends CommonBase {
        }
 
        public void set_per_htlc(TwoTuple<HTLCOutputInCommitment, byte[]>[] val) {
-               bindings.HolderCommitmentTransaction_set_per_htlc(this.ptr, Arrays.stream(val).mapToLong(arr_conv_42 -> /*TODO b*/0).toArray());
+               bindings.HolderCommitmentTransaction_set_per_htlc(this.ptr, Arrays.stream(val).mapToLong(arr_conv_42 -> bindings.C2Tuple_HTLCOutputInCommitmentSignatureZ_new(arr_conv_42.a == null ? 0 : arr_conv_42.a.ptr & ~1/*XXX: this.ptrs_to.add(arr_conv_42_a)*/, arr_conv_42.b)).toArray());
                /* TODO 2 TwoTuple<HTLCOutputInCommitment, byte[]>  */;
        }
 
index 00825ab32738701ba8132c24aa0b6b7f6a08a6da..10875ee7f84b038a1d7fa35dc6d4ed355145f110 100644 (file)
@@ -11,7 +11,7 @@ public class InMemoryChannelKeys extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.InMemoryChannelKeys_free(ptr);
+               if (ptr != 0) { bindings.InMemoryChannelKeys_free(ptr); }
        }
 
        public static InMemoryChannelKeys constructor_clone(InMemoryChannelKeys orig) {
index 37f87de703dc633a88ebb5ee0aa5ed2d09a4b50e..12236335695c3b8b28b94470fae1631ca5e88b0d 100644 (file)
@@ -11,7 +11,7 @@ public class Init extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.Init_free(ptr);
+               if (ptr != 0) { bindings.Init_free(ptr); }
        }
 
        public static Init constructor_clone(Init orig) {
index c6184f09c0b82a9ed12eda3c863fb58f03d0f722..f4d8a7e8bf70838e0d69b1fe6e68db37df66139f 100644 (file)
@@ -11,7 +11,7 @@ public class InitFeatures extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.InitFeatures_free(ptr);
+               if (ptr != 0) { bindings.InitFeatures_free(ptr); }
        }
 
 }
index 589793e4108dbedaf7842901f354caeded4b2d81..e60efc5a2cc710edd092e1a5dac3c9e69bb7e07c 100644 (file)
@@ -7,16 +7,51 @@ import java.util.Arrays;
 
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class KeysInterface extends CommonBase {
-       KeysInterface(Object _dummy, long ptr) { super(ptr); }
-       public KeysInterface(bindings.LDKKeysInterface arg) {
+       final bindings.LDKKeysInterface bindings_instance;
+       KeysInterface(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private KeysInterface(bindings.LDKKeysInterface arg) {
                super(bindings.LDKKeysInterface_new(arg));
                this.ptrs_to.add(arg);
+               this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
-               bindings.KeysInterface_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.KeysInterface_free(ptr); } super.finalize();
        }
 
+       public static interface KeysInterfaceInterface {
+               byte[] get_node_secret();
+               byte[] get_destination_script();
+               byte[] get_shutdown_pubkey();
+               ChannelKeys get_channel_keys(boolean inbound, long channel_value_satoshis);
+               byte[] get_secure_random_bytes();
+       }
+       public KeysInterface(KeysInterfaceInterface arg) {
+               this(new bindings.LDKKeysInterface() {
+                       @Override public byte[] get_node_secret() {
+                               byte[] ret = arg.get_node_secret();
+                               return ret;
+                       }
+                       @Override public byte[] get_destination_script() {
+                               byte[] ret = arg.get_destination_script();
+                               return ret;
+                       }
+                       @Override public byte[] get_shutdown_pubkey() {
+                               byte[] ret = arg.get_shutdown_pubkey();
+                               return ret;
+                       }
+                       @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.ptr;
+                               ret.ptr = 0;
+                               return result;
+                       }
+                       @Override public byte[] get_secure_random_bytes() {
+                               byte[] ret = arg.get_secure_random_bytes();
+                               return ret;
+                       }
+               });
+       }
        public byte[] get_node_secret() {
                byte[] ret = bindings.KeysInterface_get_node_secret(this.ptr);
                return ret;
index 5269c40d78ff7d061225a8f878bb5541088c5c87..a208bfeae48c03d361a4ec6c63b57e73a188fd72 100644 (file)
@@ -11,7 +11,7 @@ public class KeysManager extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.KeysManager_free(ptr);
+               if (ptr != 0) { bindings.KeysManager_free(ptr); }
        }
 
        public static KeysManager constructor_new(byte[] seed, LDKNetwork network, long starting_time_secs, int starting_time_nanos) {
index b82c5711c3f26cdbfb55bdad0fc7e60483f41343..cb89872c906080dfde1bc106a10264bf7127c3dd 100644 (file)
@@ -11,7 +11,7 @@ public class LightningError extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.LightningError_free(ptr);
+               if (ptr != 0) { bindings.LightningError_free(ptr); }
        }
 
        public String get_err() {
index 55f1dad8f131ecd732e845020c53d1a51fce595b..2313ec9a1b4477009ffd5495a0c107cb020f5a4b 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class LockedNetworkGraph extends CommonBase implements AutoCloseable {
        LockedNetworkGraph(Object _dummy, long ptr) { super(ptr); }
        @Override public void close() {
-               bindings.LockedNetworkGraph_free(ptr);
+               if (ptr != 0) { bindings.LockedNetworkGraph_free(ptr); }
        }
 
        public NetworkGraph graph() {
index 1daafb3b0242b141792d20078ba6d2d35bd1e9a1..613273d4957f38cc98d4229757529b8a6df7c0a8 100644 (file)
@@ -7,14 +7,26 @@ import java.util.Arrays;
 
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class Logger extends CommonBase {
-       Logger(Object _dummy, long ptr) { super(ptr); }
-       public Logger(bindings.LDKLogger arg) {
+       final bindings.LDKLogger bindings_instance;
+       Logger(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private Logger(bindings.LDKLogger arg) {
                super(bindings.LDKLogger_new(arg));
                this.ptrs_to.add(arg);
+               this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
-               bindings.Logger_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.Logger_free(ptr); } super.finalize();
        }
 
+       public static interface LoggerInterface {
+               void log(String record);
+       }
+       public Logger(LoggerInterface arg) {
+               this(new bindings.LDKLogger() {
+                       @Override public void log(String record) {
+                               arg.log(record);
+                       }
+               });
+       }
 }
index d2f3892cbd67399e5541c457f9e2e48a994088d0..09578c892cb118f542c07cb73655684145d6f076 100644 (file)
@@ -11,7 +11,7 @@ public class MessageHandler extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.MessageHandler_free(ptr);
+               if (ptr != 0) { bindings.MessageHandler_free(ptr); }
        }
 
        public ChannelMessageHandler get_chan_handler() {
index a19a60a20d4a8ea0d31cd8f3ddc6b5a15148abd9..5eb255afea785cb12c88d6465bc5bc19c75e87f4 100644 (file)
@@ -11,9 +11,8 @@ public class MessageSendEvent extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.MessageSendEvent_free(ptr);
+               if (ptr != 0) { bindings.MessageSendEvent_free(ptr); }
        }
-       long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ }
        static MessageSendEvent constr_from_ptr(long ptr) {
                bindings.LDKMessageSendEvent raw_val = bindings.LDKMessageSendEvent_ref_from_ptr(ptr);
                if (raw_val.getClass() == bindings.LDKMessageSendEvent.SendAcceptChannel.class) {
@@ -68,8 +67,8 @@ public class MessageSendEvent extends CommonBase {
        }
 
        public final static class SendAcceptChannel extends MessageSendEvent {
-               public byte[] node_id;
-               public AcceptChannel msg;
+               public final byte[] node_id;
+               public final AcceptChannel msg;
                private SendAcceptChannel(long ptr, bindings.LDKMessageSendEvent.SendAcceptChannel obj) {
                        super(null, ptr);
                        this.node_id = obj.node_id;
@@ -77,11 +76,10 @@ public class MessageSendEvent extends CommonBase {
                        AcceptChannel msg_hu_conv = new AcceptChannel(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class SendOpenChannel extends MessageSendEvent {
-               public byte[] node_id;
-               public OpenChannel msg;
+               public final byte[] node_id;
+               public final OpenChannel msg;
                private SendOpenChannel(long ptr, bindings.LDKMessageSendEvent.SendOpenChannel obj) {
                        super(null, ptr);
                        this.node_id = obj.node_id;
@@ -89,11 +87,10 @@ public class MessageSendEvent extends CommonBase {
                        OpenChannel msg_hu_conv = new OpenChannel(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class SendFundingCreated extends MessageSendEvent {
-               public byte[] node_id;
-               public FundingCreated msg;
+               public final byte[] node_id;
+               public final FundingCreated msg;
                private SendFundingCreated(long ptr, bindings.LDKMessageSendEvent.SendFundingCreated obj) {
                        super(null, ptr);
                        this.node_id = obj.node_id;
@@ -101,11 +98,10 @@ public class MessageSendEvent extends CommonBase {
                        FundingCreated msg_hu_conv = new FundingCreated(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class SendFundingSigned extends MessageSendEvent {
-               public byte[] node_id;
-               public FundingSigned msg;
+               public final byte[] node_id;
+               public final FundingSigned msg;
                private SendFundingSigned(long ptr, bindings.LDKMessageSendEvent.SendFundingSigned obj) {
                        super(null, ptr);
                        this.node_id = obj.node_id;
@@ -113,11 +109,10 @@ public class MessageSendEvent extends CommonBase {
                        FundingSigned msg_hu_conv = new FundingSigned(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class SendFundingLocked extends MessageSendEvent {
-               public byte[] node_id;
-               public FundingLocked msg;
+               public final byte[] node_id;
+               public final FundingLocked msg;
                private SendFundingLocked(long ptr, bindings.LDKMessageSendEvent.SendFundingLocked obj) {
                        super(null, ptr);
                        this.node_id = obj.node_id;
@@ -125,11 +120,10 @@ public class MessageSendEvent extends CommonBase {
                        FundingLocked msg_hu_conv = new FundingLocked(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class SendAnnouncementSignatures extends MessageSendEvent {
-               public byte[] node_id;
-               public AnnouncementSignatures msg;
+               public final byte[] node_id;
+               public final AnnouncementSignatures msg;
                private SendAnnouncementSignatures(long ptr, bindings.LDKMessageSendEvent.SendAnnouncementSignatures obj) {
                        super(null, ptr);
                        this.node_id = obj.node_id;
@@ -137,11 +131,10 @@ public class MessageSendEvent extends CommonBase {
                        AnnouncementSignatures msg_hu_conv = new AnnouncementSignatures(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class UpdateHTLCs extends MessageSendEvent {
-               public byte[] node_id;
-               public CommitmentUpdate updates;
+               public final byte[] node_id;
+               public final CommitmentUpdate updates;
                private UpdateHTLCs(long ptr, bindings.LDKMessageSendEvent.UpdateHTLCs obj) {
                        super(null, ptr);
                        this.node_id = obj.node_id;
@@ -149,11 +142,10 @@ public class MessageSendEvent extends CommonBase {
                        CommitmentUpdate updates_hu_conv = new CommitmentUpdate(null, updates);
                        this.updates = updates_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class SendRevokeAndACK extends MessageSendEvent {
-               public byte[] node_id;
-               public RevokeAndACK msg;
+               public final byte[] node_id;
+               public final RevokeAndACK msg;
                private SendRevokeAndACK(long ptr, bindings.LDKMessageSendEvent.SendRevokeAndACK obj) {
                        super(null, ptr);
                        this.node_id = obj.node_id;
@@ -161,11 +153,10 @@ public class MessageSendEvent extends CommonBase {
                        RevokeAndACK msg_hu_conv = new RevokeAndACK(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class SendClosingSigned extends MessageSendEvent {
-               public byte[] node_id;
-               public ClosingSigned msg;
+               public final byte[] node_id;
+               public final ClosingSigned msg;
                private SendClosingSigned(long ptr, bindings.LDKMessageSendEvent.SendClosingSigned obj) {
                        super(null, ptr);
                        this.node_id = obj.node_id;
@@ -173,11 +164,10 @@ public class MessageSendEvent extends CommonBase {
                        ClosingSigned msg_hu_conv = new ClosingSigned(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class SendShutdown extends MessageSendEvent {
-               public byte[] node_id;
-               public Shutdown msg;
+               public final byte[] node_id;
+               public final Shutdown msg;
                private SendShutdown(long ptr, bindings.LDKMessageSendEvent.SendShutdown obj) {
                        super(null, ptr);
                        this.node_id = obj.node_id;
@@ -185,11 +175,10 @@ public class MessageSendEvent extends CommonBase {
                        Shutdown msg_hu_conv = new Shutdown(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class SendChannelReestablish extends MessageSendEvent {
-               public byte[] node_id;
-               public ChannelReestablish msg;
+               public final byte[] node_id;
+               public final ChannelReestablish msg;
                private SendChannelReestablish(long ptr, bindings.LDKMessageSendEvent.SendChannelReestablish obj) {
                        super(null, ptr);
                        this.node_id = obj.node_id;
@@ -197,11 +186,10 @@ public class MessageSendEvent extends CommonBase {
                        ChannelReestablish msg_hu_conv = new ChannelReestablish(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class BroadcastChannelAnnouncement extends MessageSendEvent {
-               public ChannelAnnouncement msg;
-               public ChannelUpdate update_msg;
+               public final ChannelAnnouncement msg;
+               public final ChannelUpdate update_msg;
                private BroadcastChannelAnnouncement(long ptr, bindings.LDKMessageSendEvent.BroadcastChannelAnnouncement obj) {
                        super(null, ptr);
                        long msg = obj.msg;
@@ -211,31 +199,28 @@ public class MessageSendEvent extends CommonBase {
                        ChannelUpdate update_msg_hu_conv = new ChannelUpdate(null, update_msg);
                        this.update_msg = update_msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class BroadcastNodeAnnouncement extends MessageSendEvent {
-               public NodeAnnouncement msg;
+               public final NodeAnnouncement msg;
                private BroadcastNodeAnnouncement(long ptr, bindings.LDKMessageSendEvent.BroadcastNodeAnnouncement obj) {
                        super(null, ptr);
                        long msg = obj.msg;
                        NodeAnnouncement msg_hu_conv = new NodeAnnouncement(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class BroadcastChannelUpdate extends MessageSendEvent {
-               public ChannelUpdate msg;
+               public final ChannelUpdate msg;
                private BroadcastChannelUpdate(long ptr, bindings.LDKMessageSendEvent.BroadcastChannelUpdate obj) {
                        super(null, ptr);
                        long msg = obj.msg;
                        ChannelUpdate msg_hu_conv = new ChannelUpdate(null, msg);
                        this.msg = msg_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class HandleError extends MessageSendEvent {
-               public byte[] node_id;
-               public ErrorAction action;
+               public final byte[] node_id;
+               public final ErrorAction action;
                private HandleError(long ptr, bindings.LDKMessageSendEvent.HandleError obj) {
                        super(null, ptr);
                        this.node_id = obj.node_id;
@@ -243,16 +228,14 @@ public class MessageSendEvent extends CommonBase {
                        ErrorAction action_hu_conv = ErrorAction.constr_from_ptr(action);
                        this.action = action_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class PaymentFailureNetworkUpdate extends MessageSendEvent {
-               public HTLCFailChannelUpdate update;
+               public final HTLCFailChannelUpdate update;
                private PaymentFailureNetworkUpdate(long ptr, bindings.LDKMessageSendEvent.PaymentFailureNetworkUpdate obj) {
                        super(null, ptr);
                        long update = obj.update;
                        HTLCFailChannelUpdate update_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(update);
                        this.update = update_hu_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
 }
index 6073cb6434047f0db862e109c51d43296e654eed..e02769e37c48d45edd5279cd683fb19645f23d4c 100644 (file)
@@ -7,16 +7,31 @@ import java.util.Arrays;
 
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class MessageSendEventsProvider extends CommonBase {
-       MessageSendEventsProvider(Object _dummy, long ptr) { super(ptr); }
-       public MessageSendEventsProvider(bindings.LDKMessageSendEventsProvider arg) {
+       final bindings.LDKMessageSendEventsProvider bindings_instance;
+       MessageSendEventsProvider(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private MessageSendEventsProvider(bindings.LDKMessageSendEventsProvider arg) {
                super(bindings.LDKMessageSendEventsProvider_new(arg));
                this.ptrs_to.add(arg);
+               this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
-               bindings.MessageSendEventsProvider_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.MessageSendEventsProvider_free(ptr); } super.finalize();
        }
 
+       public static interface MessageSendEventsProviderInterface {
+               MessageSendEvent[] get_and_clear_pending_msg_events();
+       }
+       public MessageSendEventsProvider(MessageSendEventsProviderInterface arg) {
+               this(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 2 MessageSendEvent  */
+                               return result;
+                       }
+               });
+       }
        public MessageSendEvent[] get_and_clear_pending_msg_events() {
                long[] ret = bindings.MessageSendEventsProvider_get_and_clear_pending_msg_events(this.ptr);
                MessageSendEvent[] arr_conv_18_arr = new MessageSendEvent[ret.length];
index 030ef6990bbfd18fbf92e9f4516589b2123cb620..5837f072b29d08a812b643edc916b29cd4be8113 100644 (file)
@@ -11,7 +11,7 @@ public class MonitorEvent extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.MonitorEvent_free(ptr);
+               if (ptr != 0) { bindings.MonitorEvent_free(ptr); }
        }
 
 }
index 4537e5fa328abcec0d04b2efb0c6dd63cbe35c21..b6589a9feaf8b32ebe938024c88ad18143a82326 100644 (file)
@@ -11,7 +11,7 @@ public class MonitorUpdateError extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.MonitorUpdateError_free(ptr);
+               if (ptr != 0) { bindings.MonitorUpdateError_free(ptr); }
        }
 
 }
index 32e333f2fb7982adbb432421ebd32036bcfed1c7..6dd3708a36acd2378b8bd0a49d31f6a609cb2120 100644 (file)
@@ -11,9 +11,8 @@ public class NetAddress extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.NetAddress_free(ptr);
+               if (ptr != 0) { bindings.NetAddress_free(ptr); }
        }
-       long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ }
        static NetAddress constr_from_ptr(long ptr) {
                bindings.LDKNetAddress raw_val = bindings.LDKNetAddress_ref_from_ptr(ptr);
                if (raw_val.getClass() == bindings.LDKNetAddress.IPv4.class) {
@@ -32,40 +31,37 @@ public class NetAddress extends CommonBase {
        }
 
        public final static class IPv4 extends NetAddress {
-               public byte[] addr;
-               public short port;
+               public final byte[] addr;
+               public final short port;
                private IPv4(long ptr, bindings.LDKNetAddress.IPv4 obj) {
                        super(null, ptr);
                        this.addr = obj.addr;
                        this.port = obj.port;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class IPv6 extends NetAddress {
-               public byte[] addr;
-               public short port;
+               public final byte[] addr;
+               public final short port;
                private IPv6(long ptr, bindings.LDKNetAddress.IPv6 obj) {
                        super(null, ptr);
                        this.addr = obj.addr;
                        this.port = obj.port;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class OnionV2 extends NetAddress {
-               public byte[] addr;
-               public short port;
+               public final byte[] addr;
+               public final short port;
                private OnionV2(long ptr, bindings.LDKNetAddress.OnionV2 obj) {
                        super(null, ptr);
                        this.addr = obj.addr;
                        this.port = obj.port;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class OnionV3 extends NetAddress {
-               public byte[] ed25519_pubkey;
-               public short checksum;
-               public byte version;
-               public short port;
+               public final byte[] ed25519_pubkey;
+               public final short checksum;
+               public final byte version;
+               public final short port;
                private OnionV3(long ptr, bindings.LDKNetAddress.OnionV3 obj) {
                        super(null, ptr);
                        this.ed25519_pubkey = obj.ed25519_pubkey;
@@ -73,6 +69,5 @@ public class NetAddress extends CommonBase {
                        this.version = obj.version;
                        this.port = obj.port;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
 }
index d5d4780e5821fd32c31b41a60b9350fe2f60946e..4327d100a689a4cf37e9e94afbda4b52dbed0d0a 100644 (file)
@@ -11,7 +11,7 @@ public class NetGraphMsgHandler extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.NetGraphMsgHandler_free(ptr);
+               if (ptr != 0) { bindings.NetGraphMsgHandler_free(ptr); }
        }
 
        public static NetGraphMsgHandler constructor_new(Access chain_access, Logger logger) {
index 1bb8f5d89be87024feb4521896b2db8ebd2b2eaf..cb8f31f9f4b1ab9ce7e909138a6c7163dc87ce12 100644 (file)
@@ -11,7 +11,7 @@ public class NetworkGraph extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.NetworkGraph_free(ptr);
+               if (ptr != 0) { bindings.NetworkGraph_free(ptr); }
        }
 
        public byte[] write(NetworkGraph obj) {
index f75a8c3dbe967268ebf3126b32f32786b89c316c..55b766553e1cf8cf8e8abc8eb92853c09f5f8b0c 100644 (file)
@@ -11,7 +11,7 @@ public class NodeAnnouncement extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.NodeAnnouncement_free(ptr);
+               if (ptr != 0) { bindings.NodeAnnouncement_free(ptr); }
        }
 
        public static NodeAnnouncement constructor_clone(NodeAnnouncement orig) {
index e426a0e2ddafdb3ae85e50e423a33592cf0f8e26..b180a5091a018f7dc18978bde59d3df8ad1b8b57 100644 (file)
@@ -11,7 +11,7 @@ public class NodeAnnouncementInfo extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.NodeAnnouncementInfo_free(ptr);
+               if (ptr != 0) { bindings.NodeAnnouncementInfo_free(ptr); }
        }
 
        public NodeFeatures get_features() {
@@ -49,7 +49,7 @@ public class NodeAnnouncementInfo extends CommonBase {
        }
 
        public void set_addresses(NetAddress[] val) {
-               bindings.NodeAnnouncementInfo_set_addresses(this.ptr, Arrays.stream(val).mapToLong(arr_conv_12 -> arr_conv_12.conv_to_c()).toArray());
+               bindings.NodeAnnouncementInfo_set_addresses(this.ptr, Arrays.stream(val).mapToLong(arr_conv_12 -> arr_conv_12.ptr).toArray());
                /* TODO 2 NetAddress  */;
        }
 
index 71281dd78c277f972c9042d9bd921d9583927fd1..d1dfb5b4640b7f9c189bd18e2b42463c0b596054 100644 (file)
@@ -11,7 +11,7 @@ public class NodeFeatures extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.NodeFeatures_free(ptr);
+               if (ptr != 0) { bindings.NodeFeatures_free(ptr); }
        }
 
 }
index bc45360944282cfc299970df8066c17e5d8d03ea..1916d9ec1e7e3464f38e77b44505c18bf5c33f8d 100644 (file)
@@ -11,7 +11,7 @@ public class NodeInfo extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.NodeInfo_free(ptr);
+               if (ptr != 0) { bindings.NodeInfo_free(ptr); }
        }
 
        public void set_channels(long[] val) {
index 8dfe7bf566d95e09925cd49217ca93566d27cb95..32fe0ec723228002aa44ad692c956d5fe05ddf25 100644 (file)
@@ -11,7 +11,7 @@ public class OpenChannel extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.OpenChannel_free(ptr);
+               if (ptr != 0) { bindings.OpenChannel_free(ptr); }
        }
 
        public static OpenChannel constructor_clone(OpenChannel orig) {
index 0d9085c92d579dac598978d9995a5a088c30b888..74af3416719026f74c7abdd711fd914a1a705fdf 100644 (file)
@@ -11,7 +11,7 @@ public class OutPoint extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.OutPoint_free(ptr);
+               if (ptr != 0) { bindings.OutPoint_free(ptr); }
        }
 
        public static OutPoint constructor_clone(OutPoint orig) {
index 5db694eed14b84de99545c97f5b97c298f53ada4..7b7f363236902d3ef1c746f6e406a3703fe4143f 100644 (file)
@@ -11,7 +11,7 @@ public class PaymentSendFailure extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.PaymentSendFailure_free(ptr);
+               if (ptr != 0) { bindings.PaymentSendFailure_free(ptr); }
        }
 
 }
index a7240bc69dfa973d1c6646e80c8476ccd1cad7d5..1b7b3987dce97363fb5bb06cc21f92f9775e819d 100644 (file)
@@ -11,7 +11,7 @@ public class PeerHandleError extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.PeerHandleError_free(ptr);
+               if (ptr != 0) { bindings.PeerHandleError_free(ptr); }
        }
 
        public boolean get_no_connection_possible() {
index 93837b5e26378f1ecf14a24784c86187eb7924f3..2bb4ba9b395114d3e96c3d1414aa0f4b02ddf938 100644 (file)
@@ -11,7 +11,7 @@ public class PeerManager extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.PeerManager_free(ptr);
+               if (ptr != 0) { bindings.PeerManager_free(ptr); }
        }
 
        public static PeerManager constructor_new(ChannelMessageHandler message_handler_chan_handler_arg, RoutingMessageHandler message_handler_route_handler_arg, byte[] our_node_secret, byte[] ephemeral_random_data, Logger logger) {
index 5ca952f10dab6b049c0973ea86bf47cd215bcdb8..7159f0f4b8a9ee2d85433aaea03c991e8a114c9b 100644 (file)
@@ -11,7 +11,7 @@ public class Ping extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.Ping_free(ptr);
+               if (ptr != 0) { bindings.Ping_free(ptr); }
        }
 
        public static Ping constructor_clone(Ping orig) {
index 80f2995d2628e036e313b52a82535576ffd46293..54b83e7a2e4e5e0ecd653ca87f6ffcd1d3b50f8f 100644 (file)
@@ -11,7 +11,7 @@ public class Pong extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.Pong_free(ptr);
+               if (ptr != 0) { bindings.Pong_free(ptr); }
        }
 
        public static Pong constructor_clone(Pong orig) {
index 1f4bae790f6680011171a7dbd800c5cc1168525e..4f71b5672739774a5a10f05e63d4f91a376a5a9e 100644 (file)
@@ -11,7 +11,7 @@ public class PreCalculatedTxCreationKeys extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.PreCalculatedTxCreationKeys_free(ptr);
+               if (ptr != 0) { bindings.PreCalculatedTxCreationKeys_free(ptr); }
        }
 
        public static PreCalculatedTxCreationKeys constructor_new(TxCreationKeys keys) {
index fe20587244532e50cdbcc2a00cbd198b23536c3d..f12c69aab830c946ad20e9e438c26efb76af8175 100644 (file)
@@ -11,7 +11,7 @@ public class QueryChannelRange extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.QueryChannelRange_free(ptr);
+               if (ptr != 0) { bindings.QueryChannelRange_free(ptr); }
        }
 
        public static QueryChannelRange constructor_clone(QueryChannelRange orig) {
index c68d42091feb185c9e131198afef851a66945842..3fb876512fa4134508021ce3d80351f9d9920473 100644 (file)
@@ -11,7 +11,7 @@ public class QueryShortChannelIds extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.QueryShortChannelIds_free(ptr);
+               if (ptr != 0) { bindings.QueryShortChannelIds_free(ptr); }
        }
 
        public static QueryShortChannelIds constructor_clone(QueryShortChannelIds orig) {
index 939620ba32e8ca23362107a3b968c2140e8acaf8..ac5bb1b1a3409f374ee0ba817867fcb42ca8cf6a 100644 (file)
@@ -11,7 +11,7 @@ public class ReplyChannelRange extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ReplyChannelRange_free(ptr);
+               if (ptr != 0) { bindings.ReplyChannelRange_free(ptr); }
        }
 
        public static ReplyChannelRange constructor_clone(ReplyChannelRange orig) {
index 947ca85acdab71a920ba860c490f3f792519b24a..6e3163c3a77fa9134ec37135bec2653dfaef3dfa 100644 (file)
@@ -11,7 +11,7 @@ public class ReplyShortChannelIdsEnd extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.ReplyShortChannelIdsEnd_free(ptr);
+               if (ptr != 0) { bindings.ReplyShortChannelIdsEnd_free(ptr); }
        }
 
        public static ReplyShortChannelIdsEnd constructor_clone(ReplyShortChannelIdsEnd orig) {
index 8fbfa3861c0450243171ccbcbf25caeb8ca5c147..db81132c10b717827b98904b5fd006b75053514e 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ extends CommonBase {
        private Result_C2Tuple_SignatureCVec_SignatureZZNoneZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_free(ptr); } super.finalize();
        }
 
        static Result_C2Tuple_SignatureCVec_SignatureZZNoneZ constr_from_ptr(long ptr) {
@@ -20,7 +20,7 @@ public class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ extends CommonBase {
                }
        }
        public static final class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_OK extends Result_C2Tuple_SignatureCVec_SignatureZZNoneZ {
-               public TwoTuple<byte[], byte[][]> res;
+               public final TwoTuple<byte[], byte[][]> res;
                private Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        long res = bindings.LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_get_ok(ptr);
@@ -29,13 +29,19 @@ public class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ extends CommonBase {
                        TwoTuple<byte[], byte[][]> res_conv = new TwoTuple<byte[], byte[][]>(res_a, res_b);
                        this.res = res_conv;
                }
-
+               public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_OK(TwoTuple<byte[], byte[][]> res) {
+                       this(null, bindings.CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_ok(bindings.C2Tuple_SignatureCVec_SignatureZZ_new(res.a, res.b)));
+               }
        }
+
        public static final class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_Err extends Result_C2Tuple_SignatureCVec_SignatureZZNoneZ {
-               public byte err;
+               public final byte err;
                private Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.err = bindings.LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_get_err(ptr);
                }
+               public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_Err() {
+                       this(null, bindings.CResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_err());
+               }
        }
 }
index 1d709cf165a7d0d84a5f69a4cfba936efd0474ab..b1bc15c9c766fba18d4ae0f26b3c1d6efcd9cadb 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_CVec_SignatureZNoneZ extends CommonBase {
        private Result_CVec_SignatureZNoneZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_CVec_SignatureZNoneZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_CVec_SignatureZNoneZ_free(ptr); } super.finalize();
        }
 
        static Result_CVec_SignatureZNoneZ constr_from_ptr(long ptr) {
@@ -20,18 +20,24 @@ public class Result_CVec_SignatureZNoneZ extends CommonBase {
                }
        }
        public static final class Result_CVec_SignatureZNoneZ_OK extends Result_CVec_SignatureZNoneZ {
-               public byte[][] res;
+               public final byte[][] res;
                private Result_CVec_SignatureZNoneZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.res = bindings.LDKCResult_CVec_SignatureZNoneZ_get_ok(ptr);
                }
-
+               public Result_CVec_SignatureZNoneZ_OK(byte[][] res) {
+                       this(null, bindings.CResult_CVec_SignatureZNoneZ_ok(res));
+               }
        }
+
        public static final class Result_CVec_SignatureZNoneZ_Err extends Result_CVec_SignatureZNoneZ {
-               public byte err;
+               public final byte err;
                private Result_CVec_SignatureZNoneZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.err = bindings.LDKCResult_CVec_SignatureZNoneZ_get_err(ptr);
                }
+               public Result_CVec_SignatureZNoneZ_Err() {
+                       this(null, bindings.CResult_CVec_SignatureZNoneZ_err());
+               }
        }
 }
index 490b7afc8dc7378b9724c70e393fe86f80f6c9cb..3ef723e6c19d4f8e8d0a1f351aa3cfc4c7cb3608 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_CVec_u8ZPeerHandleErrorZ extends CommonBase {
        private Result_CVec_u8ZPeerHandleErrorZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_CVec_u8ZPeerHandleErrorZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_CVec_u8ZPeerHandleErrorZ_free(ptr); } super.finalize();
        }
 
        static Result_CVec_u8ZPeerHandleErrorZ constr_from_ptr(long ptr) {
@@ -20,20 +20,27 @@ public class Result_CVec_u8ZPeerHandleErrorZ extends CommonBase {
                }
        }
        public static final class Result_CVec_u8ZPeerHandleErrorZ_OK extends Result_CVec_u8ZPeerHandleErrorZ {
-               public byte[] res;
+               public final byte[] res;
                private Result_CVec_u8ZPeerHandleErrorZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.res = bindings.LDKCResult_CVec_u8ZPeerHandleErrorZ_get_ok(ptr);
                }
-
+               public Result_CVec_u8ZPeerHandleErrorZ_OK(byte[] res) {
+                       this(null, bindings.CResult_CVec_u8ZPeerHandleErrorZ_ok(res));
+               }
        }
+
        public static final class Result_CVec_u8ZPeerHandleErrorZ_Err extends Result_CVec_u8ZPeerHandleErrorZ {
-               public PeerHandleError err;
+               public final PeerHandleError err;
                private Result_CVec_u8ZPeerHandleErrorZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        long err = bindings.LDKCResult_CVec_u8ZPeerHandleErrorZ_get_err(ptr);
                        PeerHandleError err_hu_conv = new PeerHandleError(null, err);
                        this.err = err_hu_conv;
                }
+               public Result_CVec_u8ZPeerHandleErrorZ_Err(PeerHandleError err) {
+                       this(null, bindings.CResult_CVec_u8ZPeerHandleErrorZ_err(err == null ? 0 : err.ptr & ~1));
+                       this.ptrs_to.add(err);
+               }
        }
 }
index 5935b6477c56519e38e274101c97eec39311410e..846cc797e0378bbe6960f200ef19738faaadb16a 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_NoneAPIErrorZ extends CommonBase {
        private Result_NoneAPIErrorZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_NoneAPIErrorZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_NoneAPIErrorZ_free(ptr); } super.finalize();
        }
 
        static Result_NoneAPIErrorZ constr_from_ptr(long ptr) {
@@ -20,20 +20,26 @@ public class Result_NoneAPIErrorZ extends CommonBase {
                }
        }
        public static final class Result_NoneAPIErrorZ_OK extends Result_NoneAPIErrorZ {
-               public byte res;
+               public final byte res;
                private Result_NoneAPIErrorZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.res = bindings.LDKCResult_NoneAPIErrorZ_get_ok(ptr);
                }
-
+               public Result_NoneAPIErrorZ_OK() {
+                       this(null, bindings.CResult_NoneAPIErrorZ_ok());
+               }
        }
+
        public static final class Result_NoneAPIErrorZ_Err extends Result_NoneAPIErrorZ {
-               public APIError err;
+               public final APIError err;
                private Result_NoneAPIErrorZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        long err = bindings.LDKCResult_NoneAPIErrorZ_get_err(ptr);
                        APIError err_hu_conv = APIError.constr_from_ptr(err);
                        this.err = err_hu_conv;
                }
+               public Result_NoneAPIErrorZ_Err(APIError err) {
+                       this(null, bindings.CResult_NoneAPIErrorZ_err(err.ptr));
+               }
        }
 }
index 3c18a0bfc381d61f92cb831f4ebb54c45dd9284a..68d715e354d85a50722182d0c33bc1512039f112 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_NoneChannelMonitorUpdateErrZ extends CommonBase {
        private Result_NoneChannelMonitorUpdateErrZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_NoneChannelMonitorUpdateErrZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_NoneChannelMonitorUpdateErrZ_free(ptr); } super.finalize();
        }
 
        static Result_NoneChannelMonitorUpdateErrZ constr_from_ptr(long ptr) {
@@ -20,18 +20,24 @@ public class Result_NoneChannelMonitorUpdateErrZ extends CommonBase {
                }
        }
        public static final class Result_NoneChannelMonitorUpdateErrZ_OK extends Result_NoneChannelMonitorUpdateErrZ {
-               public byte res;
+               public final byte res;
                private Result_NoneChannelMonitorUpdateErrZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.res = bindings.LDKCResult_NoneChannelMonitorUpdateErrZ_get_ok(ptr);
                }
-
+               public Result_NoneChannelMonitorUpdateErrZ_OK() {
+                       this(null, bindings.CResult_NoneChannelMonitorUpdateErrZ_ok());
+               }
        }
+
        public static final class Result_NoneChannelMonitorUpdateErrZ_Err extends Result_NoneChannelMonitorUpdateErrZ {
-               public LDKChannelMonitorUpdateErr err;
+               public final LDKChannelMonitorUpdateErr err;
                private Result_NoneChannelMonitorUpdateErrZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.err = bindings.LDKCResult_NoneChannelMonitorUpdateErrZ_get_err(ptr);
                }
+               public Result_NoneChannelMonitorUpdateErrZ_Err(LDKChannelMonitorUpdateErr err) {
+                       this(null, bindings.CResult_NoneChannelMonitorUpdateErrZ_err(err));
+               }
        }
 }
index c071d7b08a7d73fe09f064ebcafd40abaa0000fd..281dce01e54bb20dbdc2f32ceccc9d70a4b83d77 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_NoneMonitorUpdateErrorZ extends CommonBase {
        private Result_NoneMonitorUpdateErrorZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_NoneMonitorUpdateErrorZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_NoneMonitorUpdateErrorZ_free(ptr); } super.finalize();
        }
 
        static Result_NoneMonitorUpdateErrorZ constr_from_ptr(long ptr) {
@@ -20,20 +20,27 @@ public class Result_NoneMonitorUpdateErrorZ extends CommonBase {
                }
        }
        public static final class Result_NoneMonitorUpdateErrorZ_OK extends Result_NoneMonitorUpdateErrorZ {
-               public byte res;
+               public final byte res;
                private Result_NoneMonitorUpdateErrorZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.res = bindings.LDKCResult_NoneMonitorUpdateErrorZ_get_ok(ptr);
                }
-
+               public Result_NoneMonitorUpdateErrorZ_OK() {
+                       this(null, bindings.CResult_NoneMonitorUpdateErrorZ_ok());
+               }
        }
+
        public static final class Result_NoneMonitorUpdateErrorZ_Err extends Result_NoneMonitorUpdateErrorZ {
-               public MonitorUpdateError err;
+               public final MonitorUpdateError err;
                private Result_NoneMonitorUpdateErrorZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        long err = bindings.LDKCResult_NoneMonitorUpdateErrorZ_get_err(ptr);
                        MonitorUpdateError err_hu_conv = new MonitorUpdateError(null, err);
                        this.err = err_hu_conv;
                }
+               public Result_NoneMonitorUpdateErrorZ_Err(MonitorUpdateError err) {
+                       this(null, bindings.CResult_NoneMonitorUpdateErrorZ_err(err == null ? 0 : err.ptr & ~1));
+                       this.ptrs_to.add(err);
+               }
        }
 }
index b9496fd023a0080fc751cfe60e819af217ab2233..b6a4772025d75468309dd4950c82de9545a0bc4a 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_NonePaymentSendFailureZ extends CommonBase {
        private Result_NonePaymentSendFailureZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_NonePaymentSendFailureZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_NonePaymentSendFailureZ_free(ptr); } super.finalize();
        }
 
        static Result_NonePaymentSendFailureZ constr_from_ptr(long ptr) {
@@ -20,20 +20,27 @@ public class Result_NonePaymentSendFailureZ extends CommonBase {
                }
        }
        public static final class Result_NonePaymentSendFailureZ_OK extends Result_NonePaymentSendFailureZ {
-               public byte res;
+               public final byte res;
                private Result_NonePaymentSendFailureZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.res = bindings.LDKCResult_NonePaymentSendFailureZ_get_ok(ptr);
                }
-
+               public Result_NonePaymentSendFailureZ_OK() {
+                       this(null, bindings.CResult_NonePaymentSendFailureZ_ok());
+               }
        }
+
        public static final class Result_NonePaymentSendFailureZ_Err extends Result_NonePaymentSendFailureZ {
-               public PaymentSendFailure err;
+               public final PaymentSendFailure err;
                private Result_NonePaymentSendFailureZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        long err = bindings.LDKCResult_NonePaymentSendFailureZ_get_err(ptr);
                        PaymentSendFailure err_hu_conv = new PaymentSendFailure(null, err);
                        this.err = err_hu_conv;
                }
+               public Result_NonePaymentSendFailureZ_Err(PaymentSendFailure err) {
+                       this(null, bindings.CResult_NonePaymentSendFailureZ_err(err == null ? 0 : err.ptr & ~1));
+                       this.ptrs_to.add(err);
+               }
        }
 }
index 385e571b5dd03c83fc6b250d9688953f85b36e61..c7b31e13e8df7304b19a78c9e0bd8137c5b3a938 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_NonePeerHandleErrorZ extends CommonBase {
        private Result_NonePeerHandleErrorZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_NonePeerHandleErrorZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_NonePeerHandleErrorZ_free(ptr); } super.finalize();
        }
 
        static Result_NonePeerHandleErrorZ constr_from_ptr(long ptr) {
@@ -20,20 +20,27 @@ public class Result_NonePeerHandleErrorZ extends CommonBase {
                }
        }
        public static final class Result_NonePeerHandleErrorZ_OK extends Result_NonePeerHandleErrorZ {
-               public byte res;
+               public final byte res;
                private Result_NonePeerHandleErrorZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.res = bindings.LDKCResult_NonePeerHandleErrorZ_get_ok(ptr);
                }
-
+               public Result_NonePeerHandleErrorZ_OK() {
+                       this(null, bindings.CResult_NonePeerHandleErrorZ_ok());
+               }
        }
+
        public static final class Result_NonePeerHandleErrorZ_Err extends Result_NonePeerHandleErrorZ {
-               public PeerHandleError err;
+               public final PeerHandleError err;
                private Result_NonePeerHandleErrorZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        long err = bindings.LDKCResult_NonePeerHandleErrorZ_get_err(ptr);
                        PeerHandleError err_hu_conv = new PeerHandleError(null, err);
                        this.err = err_hu_conv;
                }
+               public Result_NonePeerHandleErrorZ_Err(PeerHandleError err) {
+                       this(null, bindings.CResult_NonePeerHandleErrorZ_err(err == null ? 0 : err.ptr & ~1));
+                       this.ptrs_to.add(err);
+               }
        }
 }
index 0f0bcc31f318d9623485b9249c1538fd82275663..15c27f432b95ae5ac358c9112f88a6915c1b5673 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_PublicKeySecpErrorZ extends CommonBase {
        private Result_PublicKeySecpErrorZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_PublicKeySecpErrorZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_PublicKeySecpErrorZ_free(ptr); } super.finalize();
        }
 
        static Result_PublicKeySecpErrorZ constr_from_ptr(long ptr) {
@@ -20,18 +20,24 @@ public class Result_PublicKeySecpErrorZ extends CommonBase {
                }
        }
        public static final class Result_PublicKeySecpErrorZ_OK extends Result_PublicKeySecpErrorZ {
-               public byte[] res;
+               public final byte[] res;
                private Result_PublicKeySecpErrorZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.res = bindings.LDKCResult_PublicKeySecpErrorZ_get_ok(ptr);
                }
-
+               public Result_PublicKeySecpErrorZ_OK(byte[] res) {
+                       this(null, bindings.CResult_PublicKeySecpErrorZ_ok(res));
+               }
        }
+
        public static final class Result_PublicKeySecpErrorZ_Err extends Result_PublicKeySecpErrorZ {
-               public LDKSecp256k1Error err;
+               public final LDKSecp256k1Error err;
                private Result_PublicKeySecpErrorZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.err = bindings.LDKCResult_PublicKeySecpErrorZ_get_err(ptr);
                }
+               public Result_PublicKeySecpErrorZ_Err(LDKSecp256k1Error err) {
+                       this(null, bindings.CResult_PublicKeySecpErrorZ_err(err));
+               }
        }
 }
index b4d436640c16906024d01383531ed874b79eb559..09c430f294828695c1c57754e6f32fccf697e6bf 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_RouteLightningErrorZ extends CommonBase {
        private Result_RouteLightningErrorZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_RouteLightningErrorZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_RouteLightningErrorZ_free(ptr); } super.finalize();
        }
 
        static Result_RouteLightningErrorZ constr_from_ptr(long ptr) {
@@ -20,22 +20,30 @@ public class Result_RouteLightningErrorZ extends CommonBase {
                }
        }
        public static final class Result_RouteLightningErrorZ_OK extends Result_RouteLightningErrorZ {
-               public Route res;
+               public final Route res;
                private Result_RouteLightningErrorZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        long res = bindings.LDKCResult_RouteLightningErrorZ_get_ok(ptr);
                        Route res_hu_conv = new Route(null, res);
                        this.res = res_hu_conv;
                }
-
+               public Result_RouteLightningErrorZ_OK(Route res) {
+                       this(null, bindings.CResult_RouteLightningErrorZ_ok(res == null ? 0 : res.ptr & ~1));
+                       this.ptrs_to.add(res);
+               }
        }
+
        public static final class Result_RouteLightningErrorZ_Err extends Result_RouteLightningErrorZ {
-               public LightningError err;
+               public final LightningError err;
                private Result_RouteLightningErrorZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        long err = bindings.LDKCResult_RouteLightningErrorZ_get_err(ptr);
                        LightningError err_hu_conv = new LightningError(null, err);
                        this.err = err_hu_conv;
                }
+               public Result_RouteLightningErrorZ_Err(LightningError err) {
+                       this(null, bindings.CResult_RouteLightningErrorZ_err(err == null ? 0 : err.ptr & ~1));
+                       this.ptrs_to.add(err);
+               }
        }
 }
index 04bb874a9ffd740336722226a733932de96aa992..01744beefac7dc4a02f47dee14a73d8f25a7d633 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_SecretKeySecpErrorZ extends CommonBase {
        private Result_SecretKeySecpErrorZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_SecretKeySecpErrorZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_SecretKeySecpErrorZ_free(ptr); } super.finalize();
        }
 
        static Result_SecretKeySecpErrorZ constr_from_ptr(long ptr) {
@@ -20,18 +20,24 @@ public class Result_SecretKeySecpErrorZ extends CommonBase {
                }
        }
        public static final class Result_SecretKeySecpErrorZ_OK extends Result_SecretKeySecpErrorZ {
-               public byte[] res;
+               public final byte[] res;
                private Result_SecretKeySecpErrorZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.res = bindings.LDKCResult_SecretKeySecpErrorZ_get_ok(ptr);
                }
-
+               public Result_SecretKeySecpErrorZ_OK(byte[] res) {
+                       this(null, bindings.CResult_SecretKeySecpErrorZ_ok(res));
+               }
        }
+
        public static final class Result_SecretKeySecpErrorZ_Err extends Result_SecretKeySecpErrorZ {
-               public LDKSecp256k1Error err;
+               public final LDKSecp256k1Error err;
                private Result_SecretKeySecpErrorZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.err = bindings.LDKCResult_SecretKeySecpErrorZ_get_err(ptr);
                }
+               public Result_SecretKeySecpErrorZ_Err(LDKSecp256k1Error err) {
+                       this(null, bindings.CResult_SecretKeySecpErrorZ_err(err));
+               }
        }
 }
index 877a9b30bc6462db0d2a4c1eea180afdef5ea4dc..0e054a3b2627763a22483df7b78112820b7fd3a9 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_SignatureNoneZ extends CommonBase {
        private Result_SignatureNoneZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_SignatureNoneZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_SignatureNoneZ_free(ptr); } super.finalize();
        }
 
        static Result_SignatureNoneZ constr_from_ptr(long ptr) {
@@ -20,18 +20,24 @@ public class Result_SignatureNoneZ extends CommonBase {
                }
        }
        public static final class Result_SignatureNoneZ_OK extends Result_SignatureNoneZ {
-               public byte[] res;
+               public final byte[] res;
                private Result_SignatureNoneZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.res = bindings.LDKCResult_SignatureNoneZ_get_ok(ptr);
                }
-
+               public Result_SignatureNoneZ_OK(byte[] res) {
+                       this(null, bindings.CResult_SignatureNoneZ_ok(res));
+               }
        }
+
        public static final class Result_SignatureNoneZ_Err extends Result_SignatureNoneZ {
-               public byte err;
+               public final byte err;
                private Result_SignatureNoneZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.err = bindings.LDKCResult_SignatureNoneZ_get_err(ptr);
                }
+               public Result_SignatureNoneZ_Err() {
+                       this(null, bindings.CResult_SignatureNoneZ_err());
+               }
        }
 }
index dfe085cd97037801723c940a8a70183137d889b2..86e637aabb72888491db12912d3113383af68e73 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_TxCreationKeysSecpErrorZ extends CommonBase {
        private Result_TxCreationKeysSecpErrorZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_TxCreationKeysSecpErrorZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_TxCreationKeysSecpErrorZ_free(ptr); } super.finalize();
        }
 
        static Result_TxCreationKeysSecpErrorZ constr_from_ptr(long ptr) {
@@ -20,20 +20,27 @@ public class Result_TxCreationKeysSecpErrorZ extends CommonBase {
                }
        }
        public static final class Result_TxCreationKeysSecpErrorZ_OK extends Result_TxCreationKeysSecpErrorZ {
-               public TxCreationKeys res;
+               public final TxCreationKeys res;
                private Result_TxCreationKeysSecpErrorZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        long res = bindings.LDKCResult_TxCreationKeysSecpErrorZ_get_ok(ptr);
                        TxCreationKeys res_hu_conv = new TxCreationKeys(null, res);
                        this.res = res_hu_conv;
                }
-
+               public Result_TxCreationKeysSecpErrorZ_OK(TxCreationKeys res) {
+                       this(null, bindings.CResult_TxCreationKeysSecpErrorZ_ok(res == null ? 0 : res.ptr & ~1));
+                       this.ptrs_to.add(res);
+               }
        }
+
        public static final class Result_TxCreationKeysSecpErrorZ_Err extends Result_TxCreationKeysSecpErrorZ {
-               public LDKSecp256k1Error err;
+               public final LDKSecp256k1Error err;
                private Result_TxCreationKeysSecpErrorZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.err = bindings.LDKCResult_TxCreationKeysSecpErrorZ_get_err(ptr);
                }
+               public Result_TxCreationKeysSecpErrorZ_Err(LDKSecp256k1Error err) {
+                       this(null, bindings.CResult_TxCreationKeysSecpErrorZ_err(err));
+               }
        }
 }
index 1c1f7e9018692d1264f809d480e49054143341e4..e4851630cd47cdb7dea3c67272a8cc4f2e76ccaa 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_TxOutAccessErrorZ extends CommonBase {
        private Result_TxOutAccessErrorZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_TxOutAccessErrorZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_TxOutAccessErrorZ_free(ptr); } super.finalize();
        }
 
        static Result_TxOutAccessErrorZ constr_from_ptr(long ptr) {
@@ -20,20 +20,26 @@ public class Result_TxOutAccessErrorZ extends CommonBase {
                }
        }
        public static final class Result_TxOutAccessErrorZ_OK extends Result_TxOutAccessErrorZ {
-               public TxOut res;
+               public final TxOut res;
                private Result_TxOutAccessErrorZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        long res = bindings.LDKCResult_TxOutAccessErrorZ_get_ok(ptr);
                        TxOut res_conv = new TxOut(null, res);
                        this.res = res_conv;
                }
-
+               public Result_TxOutAccessErrorZ_OK(TxOut res) {
+                       this(null, bindings.CResult_TxOutAccessErrorZ_ok(res.ptr));
+               }
        }
+
        public static final class Result_TxOutAccessErrorZ_Err extends Result_TxOutAccessErrorZ {
-               public LDKAccessError err;
+               public final LDKAccessError err;
                private Result_TxOutAccessErrorZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.err = bindings.LDKCResult_TxOutAccessErrorZ_get_err(ptr);
                }
+               public Result_TxOutAccessErrorZ_Err(LDKAccessError err) {
+                       this(null, bindings.CResult_TxOutAccessErrorZ_err(err));
+               }
        }
 }
index bb9597f7e45a5349b7330753351e75e7f6db2be0..5eb4ab80258a931729163642a3fafa096809e53a 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_boolLightningErrorZ extends CommonBase {
        private Result_boolLightningErrorZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_boolLightningErrorZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_boolLightningErrorZ_free(ptr); } super.finalize();
        }
 
        static Result_boolLightningErrorZ constr_from_ptr(long ptr) {
@@ -20,20 +20,27 @@ public class Result_boolLightningErrorZ extends CommonBase {
                }
        }
        public static final class Result_boolLightningErrorZ_OK extends Result_boolLightningErrorZ {
-               public boolean res;
+               public final boolean res;
                private Result_boolLightningErrorZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.res = bindings.LDKCResult_boolLightningErrorZ_get_ok(ptr);
                }
-
+               public Result_boolLightningErrorZ_OK(boolean res) {
+                       this(null, bindings.CResult_boolLightningErrorZ_ok(res));
+               }
        }
+
        public static final class Result_boolLightningErrorZ_Err extends Result_boolLightningErrorZ {
-               public LightningError err;
+               public final LightningError err;
                private Result_boolLightningErrorZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        long err = bindings.LDKCResult_boolLightningErrorZ_get_err(ptr);
                        LightningError err_hu_conv = new LightningError(null, err);
                        this.err = err_hu_conv;
                }
+               public Result_boolLightningErrorZ_Err(LightningError err) {
+                       this(null, bindings.CResult_boolLightningErrorZ_err(err == null ? 0 : err.ptr & ~1));
+                       this.ptrs_to.add(err);
+               }
        }
 }
index ac33e40c5c112fa24103e5f136040f5cccdf5d7c..e29335b6b91b10b01915b9ae913119637e49e1ca 100644 (file)
@@ -9,7 +9,7 @@ import java.util.Arrays;
 public class Result_boolPeerHandleErrorZ extends CommonBase {
        private Result_boolPeerHandleErrorZ(Object _dummy, long ptr) { super(ptr); }
        protected void finalize() throws Throwable {
-               bindings.CResult_boolPeerHandleErrorZ_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.CResult_boolPeerHandleErrorZ_free(ptr); } super.finalize();
        }
 
        static Result_boolPeerHandleErrorZ constr_from_ptr(long ptr) {
@@ -20,20 +20,27 @@ public class Result_boolPeerHandleErrorZ extends CommonBase {
                }
        }
        public static final class Result_boolPeerHandleErrorZ_OK extends Result_boolPeerHandleErrorZ {
-               public boolean res;
+               public final boolean res;
                private Result_boolPeerHandleErrorZ_OK(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        this.res = bindings.LDKCResult_boolPeerHandleErrorZ_get_ok(ptr);
                }
-
+               public Result_boolPeerHandleErrorZ_OK(boolean res) {
+                       this(null, bindings.CResult_boolPeerHandleErrorZ_ok(res));
+               }
        }
+
        public static final class Result_boolPeerHandleErrorZ_Err extends Result_boolPeerHandleErrorZ {
-               public PeerHandleError err;
+               public final PeerHandleError err;
                private Result_boolPeerHandleErrorZ_Err(Object _dummy, long ptr) {
                        super(_dummy, ptr);
                        long err = bindings.LDKCResult_boolPeerHandleErrorZ_get_err(ptr);
                        PeerHandleError err_hu_conv = new PeerHandleError(null, err);
                        this.err = err_hu_conv;
                }
+               public Result_boolPeerHandleErrorZ_Err(PeerHandleError err) {
+                       this(null, bindings.CResult_boolPeerHandleErrorZ_err(err == null ? 0 : err.ptr & ~1));
+                       this.ptrs_to.add(err);
+               }
        }
 }
index 5409d3b94bc0a78c49402b235bc39eece542e611..176f5db7f125a3c15135c5ec9f4a59341983aa6f 100644 (file)
@@ -11,7 +11,7 @@ public class RevokeAndACK extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.RevokeAndACK_free(ptr);
+               if (ptr != 0) { bindings.RevokeAndACK_free(ptr); }
        }
 
        public static RevokeAndACK constructor_clone(RevokeAndACK orig) {
index b7864b495a7035dc10445a490cfa727e62b6e95f..7e2387cdd244383296d3df1d7e3890f024632e00 100644 (file)
@@ -11,7 +11,7 @@ public class Route extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.Route_free(ptr);
+               if (ptr != 0) { bindings.Route_free(ptr); }
        }
 
        public static Route constructor_clone(Route orig) {
index 9c6e0f79f97f40f6b4413488dbb48729804f4e73..e5c54d699c4a39055092b36813ab40ee4356971b 100644 (file)
@@ -11,7 +11,7 @@ public class RouteHint extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.RouteHint_free(ptr);
+               if (ptr != 0) { bindings.RouteHint_free(ptr); }
        }
 
        public static RouteHint constructor_clone(RouteHint orig) {
index 74e5816dea82a784763c4ef5a493b0cf13acd516..e54845e51add8e7c53af0a83d93f2d4d7a14ddc3 100644 (file)
@@ -11,7 +11,7 @@ public class RouteHop extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.RouteHop_free(ptr);
+               if (ptr != 0) { bindings.RouteHop_free(ptr); }
        }
 
        public static RouteHop constructor_clone(RouteHop orig) {
index a182fea63cb4768f618bb3464eb44d18c26ba26d..8ea88fcad6f0eba975f56a2ed2633f3898db256d 100644 (file)
@@ -11,7 +11,7 @@ public class RoutingFees extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.RoutingFees_free(ptr);
+               if (ptr != 0) { bindings.RoutingFees_free(ptr); }
        }
 
        public static RoutingFees constructor_clone(RoutingFees orig) {
index e547b766ee22788aa900b949ec43afb13ad441ac..23fd8c9ff3855cd73a8d4c590eae0e8c10f3c852 100644 (file)
@@ -7,16 +7,72 @@ import java.util.Arrays;
 
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class RoutingMessageHandler extends CommonBase {
-       RoutingMessageHandler(Object _dummy, long ptr) { super(ptr); }
-       public RoutingMessageHandler(bindings.LDKRoutingMessageHandler arg) {
+       final bindings.LDKRoutingMessageHandler bindings_instance;
+       RoutingMessageHandler(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private RoutingMessageHandler(bindings.LDKRoutingMessageHandler arg) {
                super(bindings.LDKRoutingMessageHandler_new(arg));
                this.ptrs_to.add(arg);
+               this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
-               bindings.RoutingMessageHandler_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.RoutingMessageHandler_free(ptr); } super.finalize();
        }
 
+       public static interface RoutingMessageHandlerInterface {
+               Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg);
+               Result_boolLightningErrorZ handle_channel_announcement(ChannelAnnouncement msg);
+               Result_boolLightningErrorZ handle_channel_update(ChannelUpdate msg);
+               void handle_htlc_fail_channel_update(HTLCFailChannelUpdate update);
+               ThreeTuple<ChannelAnnouncement, ChannelUpdate, ChannelUpdate>[] get_next_channel_announcements(long starting_point, byte batch_amount);
+               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() {
+                       @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);
+                               long result = ret != null ? ret.ptr : 0;
+                               ret.ptr = 0;
+                               return result;
+                       }
+                       @Override public long handle_channel_announcement(long msg) {
+                               ChannelAnnouncement msg_hu_conv = new ChannelAnnouncement(null, msg);
+                               Result_boolLightningErrorZ ret = arg.handle_channel_announcement(msg_hu_conv);
+                               long result = ret != null ? ret.ptr : 0;
+                               ret.ptr = 0;
+                               return result;
+                       }
+                       @Override public long handle_channel_update(long msg) {
+                               ChannelUpdate msg_hu_conv = new ChannelUpdate(null, msg);
+                               Result_boolLightningErrorZ ret = arg.handle_channel_update(msg_hu_conv);
+                               long result = ret != null ? ret.ptr : 0;
+                               ret.ptr = 0;
+                               return result;
+                       }
+                       @Override public void handle_htlc_fail_channel_update(long update) {
+                               HTLCFailChannelUpdate update_hu_conv = HTLCFailChannelUpdate.constr_from_ptr(update);
+                               arg.handle_htlc_fail_channel_update(update_hu_conv);
+                       }
+                       @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 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 2 NodeAnnouncement  */
+                               return result;
+                       }
+                       @Override public boolean should_request_full_sync(byte[] node_id) {
+                               boolean ret = arg.should_request_full_sync(node_id);
+                               return ret;
+                       }
+               });
+       }
        public Result_boolLightningErrorZ handle_node_announcement(NodeAnnouncement msg) {
                long ret = bindings.RoutingMessageHandler_handle_node_announcement(this.ptr, msg == null ? 0 : msg.ptr & ~1);
                Result_boolLightningErrorZ ret_hu_conv = Result_boolLightningErrorZ.constr_from_ptr(ret);
index 6b95b56863ce9ce1d730003780e749b4d808d5cc..1d1c91d5cc3fd7afe2edaeb6e1804534e557d708 100644 (file)
@@ -11,7 +11,7 @@ public class Shutdown extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.Shutdown_free(ptr);
+               if (ptr != 0) { bindings.Shutdown_free(ptr); }
        }
 
        public static Shutdown constructor_clone(Shutdown orig) {
index ae56a98315ff2b6522757d88fa371073cf157b79..9c4f9e7b251d69148aca10dddf1f0f20f59152c9 100644 (file)
@@ -7,16 +7,43 @@ import java.util.Arrays;
 
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class SocketDescriptor extends CommonBase {
-       SocketDescriptor(Object _dummy, long ptr) { super(ptr); }
-       public SocketDescriptor(bindings.LDKSocketDescriptor arg) {
+       final bindings.LDKSocketDescriptor bindings_instance;
+       SocketDescriptor(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private SocketDescriptor(bindings.LDKSocketDescriptor arg) {
                super(bindings.LDKSocketDescriptor_new(arg));
                this.ptrs_to.add(arg);
+               this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
-               bindings.SocketDescriptor_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.SocketDescriptor_free(ptr); } super.finalize();
        }
 
+       public static interface SocketDescriptorInterface {
+               long send_data(byte[] data, boolean resume_read);
+               void disconnect_socket();
+               boolean eq(long other_arg);
+               long hash();
+       }
+       public SocketDescriptor(SocketDescriptorInterface arg) {
+               this(new bindings.LDKSocketDescriptor() {
+                       @Override public long send_data(byte[] data, boolean resume_read) {
+                               long ret = arg.send_data(data, resume_read);
+                               return ret;
+                       }
+                       @Override public void disconnect_socket() {
+                               arg.disconnect_socket();
+                       }
+                       @Override public boolean eq(long other_arg) {
+                               boolean ret = arg.eq(other_arg);
+                               return ret;
+                       }
+                       @Override public long hash() {
+                               long ret = arg.hash();
+                               return ret;
+                       }
+               });
+       }
        public long send_data(byte[] data, boolean resume_read) {
                long ret = bindings.SocketDescriptor_send_data(this.ptr, data, resume_read);
                return ret;
index c812679b1602466eba48c8a39b759918ea12ea88..74c70391ebe149e977ee0a7acfcf51caf940d397 100644 (file)
@@ -11,9 +11,8 @@ public class SpendableOutputDescriptor extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.SpendableOutputDescriptor_free(ptr);
+               if (ptr != 0) { bindings.SpendableOutputDescriptor_free(ptr); }
        }
-       long conv_to_c() { assert false; return 0; /* Should only be called on subclasses */ }
        static SpendableOutputDescriptor constr_from_ptr(long ptr) {
                bindings.LDKSpendableOutputDescriptor raw_val = bindings.LDKSpendableOutputDescriptor_ref_from_ptr(ptr);
                if (raw_val.getClass() == bindings.LDKSpendableOutputDescriptor.StaticOutput.class) {
@@ -29,8 +28,8 @@ public class SpendableOutputDescriptor extends CommonBase {
        }
 
        public final static class StaticOutput extends SpendableOutputDescriptor {
-               public OutPoint outpoint;
-               public TxOut output;
+               public final OutPoint outpoint;
+               public final TxOut output;
                private StaticOutput(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutput obj) {
                        super(null, ptr);
                        long outpoint = obj.outpoint;
@@ -40,15 +39,14 @@ public class SpendableOutputDescriptor extends CommonBase {
                        TxOut output_conv = new TxOut(null, output);
                        this.output = output_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class DynamicOutputP2WSH extends SpendableOutputDescriptor {
-               public OutPoint outpoint;
-               public byte[] per_commitment_point;
-               public short to_self_delay;
-               public TxOut output;
-               public TwoTuple<Long, Long> key_derivation_params;
-               public byte[] revocation_pubkey;
+               public final OutPoint outpoint;
+               public final byte[] per_commitment_point;
+               public final short to_self_delay;
+               public final TxOut output;
+               public final TwoTuple<Long, Long> key_derivation_params;
+               public final byte[] revocation_pubkey;
                private DynamicOutputP2WSH(long ptr, bindings.LDKSpendableOutputDescriptor.DynamicOutputP2WSH obj) {
                        super(null, ptr);
                        long outpoint = obj.outpoint;
@@ -66,12 +64,11 @@ public class SpendableOutputDescriptor extends CommonBase {
                        this.key_derivation_params = key_derivation_params_conv;
                        this.revocation_pubkey = obj.revocation_pubkey;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
        public final static class StaticOutputCounterpartyPayment extends SpendableOutputDescriptor {
-               public OutPoint outpoint;
-               public TxOut output;
-               public TwoTuple<Long, Long> key_derivation_params;
+               public final OutPoint outpoint;
+               public final TxOut output;
+               public final TwoTuple<Long, Long> key_derivation_params;
                private StaticOutputCounterpartyPayment(long ptr, bindings.LDKSpendableOutputDescriptor.StaticOutputCounterpartyPayment obj) {
                        super(null, ptr);
                        long outpoint = obj.outpoint;
@@ -86,6 +83,5 @@ public class SpendableOutputDescriptor extends CommonBase {
                        TwoTuple<Long, Long> key_derivation_params_conv = new TwoTuple<Long, Long>(key_derivation_params_a, key_derivation_params_b);
                        this.key_derivation_params = key_derivation_params_conv;
                }
-               @Override long conv_to_c() { return 0; /*XXX*/ }
        }
 }
index 203c34c3585a9219bf3a3864b0b59629b5775527..91f19373f90011c8c9ff14db7f19b63007e03830 100644 (file)
@@ -8,4 +8,6 @@ import java.util.Arrays;
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class Transaction extends CommonBase{
        Transaction(java.lang.Object _dummy, long ptr) { super(ptr); }
+       public Transaction(byte[] data) { super(bindings.new_txpointer_copy_data(data)); }
+       @Override public void finalize() throws Throwable { super.finalize(); bindings.txpointer_free(ptr); }
 }
\ No newline at end of file
index 9cc92e5b521dbc6b71ca0a01e44a1c50026fef8d..eda469d90d04bc5d94d453bae86b666baadd258e 100644 (file)
@@ -11,7 +11,7 @@ public class TxCreationKeys extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.TxCreationKeys_free(ptr);
+               if (ptr != 0) { bindings.TxCreationKeys_free(ptr); }
        }
 
        public static TxCreationKeys constructor_clone(TxCreationKeys orig) {
index 438c92a0d87e06cbd853e542064931887b523d99..709450f8745fcc6cc90d11e8f224b836092f7b70 100644 (file)
@@ -8,4 +8,5 @@ import java.util.Arrays;
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class TxOut extends CommonBase{
        TxOut(java.lang.Object _dummy, long ptr) { super(ptr); }
+       long to_c_ptr() { return 0; }
 }
\ No newline at end of file
index a5b624b1da2209fc975340f06f5e8e1f07a8c07d..67c3d2e969f95f1eb0c5ac852d1a561af75d0ae3 100644 (file)
@@ -11,7 +11,7 @@ public class UnsignedChannelAnnouncement extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.UnsignedChannelAnnouncement_free(ptr);
+               if (ptr != 0) { bindings.UnsignedChannelAnnouncement_free(ptr); }
        }
 
        public static UnsignedChannelAnnouncement constructor_clone(UnsignedChannelAnnouncement orig) {
index 0fa6b1e55e12a27bc2cbc40aecf75c41226f34d7..d9ca14447338eb2832baa589a4477c9c9c43a3ba 100644 (file)
@@ -11,7 +11,7 @@ public class UnsignedChannelUpdate extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.UnsignedChannelUpdate_free(ptr);
+               if (ptr != 0) { bindings.UnsignedChannelUpdate_free(ptr); }
        }
 
        public static UnsignedChannelUpdate constructor_clone(UnsignedChannelUpdate orig) {
index 4c905aa1aaac7e7de4ee2c818b8ac91913518918..8a38275f8633a291ac64d8f063bc6dc5f0d1f932 100644 (file)
@@ -11,7 +11,7 @@ public class UnsignedNodeAnnouncement extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.UnsignedNodeAnnouncement_free(ptr);
+               if (ptr != 0) { bindings.UnsignedNodeAnnouncement_free(ptr); }
        }
 
        public static UnsignedNodeAnnouncement constructor_clone(UnsignedNodeAnnouncement orig) {
@@ -65,7 +65,7 @@ public class UnsignedNodeAnnouncement extends CommonBase {
        }
 
        public void set_addresses(NetAddress[] val) {
-               bindings.UnsignedNodeAnnouncement_set_addresses(this.ptr, Arrays.stream(val).mapToLong(arr_conv_12 -> arr_conv_12.conv_to_c()).toArray());
+               bindings.UnsignedNodeAnnouncement_set_addresses(this.ptr, Arrays.stream(val).mapToLong(arr_conv_12 -> arr_conv_12.ptr).toArray());
                /* TODO 2 NetAddress  */;
        }
 
index 7e33edf0a6c90251affea97b6fa9e66f5b055723..c4aa0936e2a54246620bb30f46b14271fd37e783 100644 (file)
@@ -11,7 +11,7 @@ public class UpdateAddHTLC extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.UpdateAddHTLC_free(ptr);
+               if (ptr != 0) { bindings.UpdateAddHTLC_free(ptr); }
        }
 
        public static UpdateAddHTLC constructor_clone(UpdateAddHTLC orig) {
index f533eb376134d60bb0e0c58b04ebd06b5b844426..171cbaffb3eed8f84dd49adf429bec2f0fa0ff85 100644 (file)
@@ -11,7 +11,7 @@ public class UpdateFailHTLC extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.UpdateFailHTLC_free(ptr);
+               if (ptr != 0) { bindings.UpdateFailHTLC_free(ptr); }
        }
 
        public static UpdateFailHTLC constructor_clone(UpdateFailHTLC orig) {
index 1a6c8aea5afb1c7b79c29384f9c4856d21b582e3..3009fcbdfdeb05a371d0f718fca257cb5f810024 100644 (file)
@@ -11,7 +11,7 @@ public class UpdateFailMalformedHTLC extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.UpdateFailMalformedHTLC_free(ptr);
+               if (ptr != 0) { bindings.UpdateFailMalformedHTLC_free(ptr); }
        }
 
        public static UpdateFailMalformedHTLC constructor_clone(UpdateFailMalformedHTLC orig) {
index 77f14f6cb9ff38fa27b8433380915fdccaa91eed..ecc9f0f0af0d815a15a96b9e5b31581f7e17d738 100644 (file)
@@ -11,7 +11,7 @@ public class UpdateFee extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.UpdateFee_free(ptr);
+               if (ptr != 0) { bindings.UpdateFee_free(ptr); }
        }
 
        public static UpdateFee constructor_clone(UpdateFee orig) {
index cf1a60c1dff89b413a7f4523fa4229f0cbd67c8a..d28bf4609fd78b1ad8f27e2b0ec71a04be421c19 100644 (file)
@@ -11,7 +11,7 @@ public class UpdateFulfillHTLC extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.UpdateFulfillHTLC_free(ptr);
+               if (ptr != 0) { bindings.UpdateFulfillHTLC_free(ptr); }
        }
 
        public static UpdateFulfillHTLC constructor_clone(UpdateFulfillHTLC orig) {
index 446270d48d307e962e6aa13d0bc79e4c102c0329..4967fbf39272d0d8bb179ef3119a69a873acc6ba 100644 (file)
@@ -11,7 +11,7 @@ public class UserConfig extends CommonBase {
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
                super.finalize();
-               bindings.UserConfig_free(ptr);
+               if (ptr != 0) { bindings.UserConfig_free(ptr); }
        }
 
        public static UserConfig constructor_clone(UserConfig orig) {
index 7ed2211f8bedc3429b531570bf3aed9aebbfa2bf..e1bf3751aa938bac607e66aa2a13747fe3ba043d 100644 (file)
@@ -7,16 +7,49 @@ import java.util.Arrays;
 
 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
 public class Watch extends CommonBase {
-       Watch(Object _dummy, long ptr) { super(ptr); }
-       public Watch(bindings.LDKWatch arg) {
+       final bindings.LDKWatch bindings_instance;
+       Watch(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
+       private Watch(bindings.LDKWatch arg) {
                super(bindings.LDKWatch_new(arg));
                this.ptrs_to.add(arg);
+               this.bindings_instance = arg;
        }
        @Override @SuppressWarnings("deprecation")
        protected void finalize() throws Throwable {
-               bindings.Watch_free(ptr); super.finalize();
+               if (ptr != 0) { bindings.Watch_free(ptr); } super.finalize();
        }
 
+       public static interface WatchInterface {
+               Result_NoneChannelMonitorUpdateErrZ watch_channel(OutPoint funding_txo, ChannelMonitor monitor);
+               Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update);
+               MonitorEvent[] release_pending_monitor_events();
+       }
+       public Watch(WatchInterface arg) {
+               this(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);
+                               Result_NoneChannelMonitorUpdateErrZ ret = arg.watch_channel(funding_txo_hu_conv, monitor_hu_conv);
+                               long result = ret != null ? ret.ptr : 0;
+                               ret.ptr = 0;
+                               return result;
+                       }
+                       @Override public long update_channel(long funding_txo, long update) {
+                               OutPoint funding_txo_hu_conv = new OutPoint(null, funding_txo);
+                               ChannelMonitorUpdate update_hu_conv = new ChannelMonitorUpdate(null, update);
+                               Result_NoneChannelMonitorUpdateErrZ ret = arg.update_channel(funding_txo_hu_conv, update_hu_conv);
+                               long result = ret != null ? ret.ptr : 0;
+                               ret.ptr = 0;
+                               return result;
+                       }
+                       @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 2 MonitorEvent  */
+                               return result;
+                       }
+               });
+       }
        // Skipped Watch_watch_channel
        public Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update) {
                long ret = bindings.Watch_update_channel(this.ptr, funding_txo == null ? 0 : funding_txo.ptr & ~1, update == null ? 0 : update.ptr & ~1);
index 6f0b606a1d6b23ea2edb85bc8f6c6a225091a099..f949d8785c08715f9689cc2792db66f0548a465f 100644 (file)
@@ -54,7 +54,13 @@ static void alloc_freed(void* ptr) {
        allocation* p = NULL;
        DO_ASSERT(mtx_lock(&allocation_mtx) == thrd_success);
        allocation* it = allocation_ll;
-       while (it->ptr != ptr) { p = it; it = it->next; }
+       while (it->ptr != ptr) {
+               p = it; it = it->next;
+               if (it == NULL) {
+                       fprintf(stderr, "Tried to free unknown pointer %p!\n", ptr);
+                       return; // addrsan should catch malloc-unknown and print more info than we have
+               }
+       }
        if (p) { p->next = it->next; } else { allocation_ll = it->next; }
        DO_ASSERT(mtx_unlock(&allocation_mtx) == thrd_success);
        DO_ASSERT(it->ptr == ptr);
@@ -145,12 +151,18 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data (JN
        LDKTransaction *txdata = (LDKTransaction*)MALLOC(sizeof(LDKTransaction), "LDKTransaction");
        txdata->datalen = (*env)->GetArrayLength(env, bytes);
        txdata->data = (uint8_t*)MALLOC(txdata->datalen, "Tx Data Bytes");
-       txdata->data_is_owned = true;
+       txdata->data_is_owned = false;
        (*env)->GetByteArrayRegion (env, bytes, 0, txdata->datalen, txdata->data);
        return (long)txdata;
 }
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_txpointer_1free (JNIEnv * env, jclass _b, jlong ptr) {
+       LDKTransaction *tx = (LDKTransaction*)ptr;
+       tx->data_is_owned = true;
+       Transaction_free(*tx);
+       FREE((void*)ptr);
+}
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env, jclass _a, jlong ptr) {
-        // Check offsets of a few Vec types are all consistent as we're meant to be generic across types
+       // Check offsets of a few Vec types are all consistent as we're meant to be generic across types
        _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_SignatureZ, datalen), "Vec<*> needs to be mapped identically");
        _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_MessageSendEventZ, datalen), "Vec<*> needs to be mapped identically");
        _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKCVec_EventZ, datalen), "Vec<*> needs to be mapped identically");
@@ -159,7 +171,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_vec_1slice_1len (JNIEnv * env
        return (long)vec->datalen;
 }
 JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1empty_1slice_1vec (JNIEnv * _env, jclass _b) {
-        // Check sizes of a few Vec types are all consistent as we're meant to be generic across types
+       // Check sizes of a few Vec types are all consistent as we're meant to be generic across types
        _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_SignatureZ), "Vec<*> needs to be mapped identically");
        _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_MessageSendEventZ), "Vec<*> needs to be mapped identically");
        _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKCVec_EventZ), "Vec<*> needs to be mapped identically");
@@ -444,7 +456,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1usize_1_1Tra
        LDKC2TupleTempl_usize__Transaction* ret = MALLOC(sizeof(LDKC2TupleTempl_usize__Transaction), "LDKC2TupleTempl_usize__Transaction");
        ret->a = a;
        LDKTransaction b_conv = *(LDKTransaction*)b;
-       FREE((void*)b);
        ret->b = b_conv;
        return (long)ret;
 }
@@ -1750,7 +1761,9 @@ LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment_j
        LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
        JNIEnv *_env;
        DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
-       long commitment_tx_ref = (long)&commitment_tx;
+       LDKTransaction *commitment_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
+       *commitment_tx_copy = commitment_tx;
+       long commitment_tx_ref = (long)commitment_tx_copy;
        LDKCVec_HTLCOutputInCommitmentZ htlcs_var = htlcs;
        jlongArray htlcs_arr = (*_env)->NewLongArray(_env, htlcs_var.datalen);
        jlong *htlcs_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, htlcs_arr, NULL);
@@ -1801,7 +1814,9 @@ LDKCResult_SignatureNoneZ sign_justice_transaction_jcall(const void* this_arg, L
        LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
        JNIEnv *_env;
        DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
-       long justice_tx_ref = (long)&justice_tx;
+       LDKTransaction *justice_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
+       *justice_tx_copy = justice_tx;
+       long justice_tx_ref = (long)justice_tx_copy;
        jbyteArray per_commitment_key_arr = (*_env)->NewByteArray(_env, 32);
        (*_env)->SetByteArrayRegion(_env, per_commitment_key_arr, 0, 32, *per_commitment_key);
        jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
@@ -1815,7 +1830,9 @@ LDKCResult_SignatureNoneZ sign_counterparty_htlc_transaction_jcall(const void* t
        LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
        JNIEnv *_env;
        DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
-       long htlc_tx_ref = (long)&htlc_tx;
+       LDKTransaction *htlc_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
+       *htlc_tx_copy = htlc_tx;
+       long htlc_tx_ref = (long)htlc_tx_copy;
        jbyteArray per_commitment_point_arr = (*_env)->NewByteArray(_env, 33);
        (*_env)->SetByteArrayRegion(_env, per_commitment_point_arr, 0, 33, per_commitment_point.compressed_form);
        jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
@@ -1829,7 +1846,9 @@ LDKCResult_SignatureNoneZ sign_closing_transaction_jcall(const void* this_arg, L
        LDKChannelKeys_JCalls *j_calls = (LDKChannelKeys_JCalls*) this_arg;
        JNIEnv *_env;
        DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
-       long closing_tx_ref = (long)&closing_tx;
+       LDKTransaction *closing_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
+       *closing_tx_copy = closing_tx;
+       long closing_tx_ref = (long)closing_tx_copy;
        jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
        CHECK(obj != NULL);
        LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_closing_transaction_meth, closing_tx_ref);
@@ -1952,7 +1971,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1key_1derivation_
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jint feerate_per_kw, jlong commitment_tx, jlong keys, jlongArray htlcs) {
        LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        LDKTransaction commitment_tx_conv = *(LDKTransaction*)commitment_tx;
-       FREE((void*)commitment_tx);
        LDKPreCalculatedTxCreationKeys keys_conv;
        keys_conv.inner = (void*)(keys & (~1));
        keys_conv.is_owned = (keys & 1) || (keys == 0);
@@ -2001,7 +2019,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1co
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1justice_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong justice_tx, jlong input, jlong amount, jbyteArray per_commitment_key, jlong htlc) {
        LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        LDKTransaction justice_tx_conv = *(LDKTransaction*)justice_tx;
-       FREE((void*)justice_tx);
        unsigned char per_commitment_key_arr[32];
        CHECK((*_env)->GetArrayLength (_env, per_commitment_key) == 32);
        (*_env)->GetByteArrayRegion (_env, per_commitment_key, 0, 32, per_commitment_key_arr);
@@ -2017,7 +2034,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1justice_1t
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1htlc_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong htlc_tx, jlong input, jlong amount, jbyteArray per_commitment_point, jlong htlc) {
        LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        LDKTransaction htlc_tx_conv = *(LDKTransaction*)htlc_tx;
-       FREE((void*)htlc_tx);
        LDKPublicKey per_commitment_point_ref;
        CHECK((*_env)->GetArrayLength (_env, per_commitment_point) == 33);
        (*_env)->GetByteArrayRegion (_env, per_commitment_point, 0, 33, per_commitment_point_ref.compressed_form);
@@ -2032,7 +2048,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterpar
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1closing_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong closing_tx) {
        LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        LDKTransaction closing_tx_conv = *(LDKTransaction*)closing_tx;
-       FREE((void*)closing_tx);
        LDKCResult_SignatureNoneZ* ret = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
        *ret = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_conv);
        return (long)ret;
@@ -2390,7 +2405,9 @@ void broadcast_transaction_jcall(const void* this_arg, LDKTransaction tx) {
        LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg;
        JNIEnv *_env;
        DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&_env, JNI_VERSION_1_8) == JNI_OK);
-       long tx_ref = (long)&tx;
+       LDKTransaction *tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
+       *tx_copy = tx;
+       long tx_ref = (long)tx_copy;
        jobject obj = (*_env)->NewLocalRef(_env, j_calls->o);
        CHECK(obj != NULL);
        return (*_env)->CallVoidMethod(_env, obj, j_calls->broadcast_transaction_meth, tx_ref);
@@ -2439,7 +2456,6 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1ge
 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1broadcast_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong tx) {
        LDKBroadcasterInterface* this_arg_conv = (LDKBroadcasterInterface*)this_arg;
        LDKTransaction tx_conv = *(LDKTransaction*)tx;
-       FREE((void*)tx);
        (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_conv);
 }
 
@@ -2543,7 +2559,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Transaction_1ne
                for (size_t i = 0; i < ret->datalen; i++) {
                        jlong arr_elem = java_elems[i];
                        LDKTransaction arr_elem_conv = *(LDKTransaction*)arr_elem;
-                       FREE((void*)arr_elem);
                        ret->data[i] = arr_elem_conv;
                }
                (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
@@ -4903,7 +4918,6 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TransactionZ_1free(JNIEn
        for (size_t n = 0; n < arg_constr.datalen; n++) {
                long arr_conv_13 = arg_vals[n];
                LDKTransaction arr_conv_13_conv = *(LDKTransaction*)arr_conv_13;
-               FREE((void*)arr_conv_13);
                arg_constr.data[n] = arr_conv_13_conv;
        }
        (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0);
@@ -5030,7 +5044,6 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u8Z_1free(JNIEnv * _env,
 
 JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Transaction_1free(JNIEnv * _env, jclass _b, jlong _res) {
        LDKTransaction _res_conv = *(LDKTransaction*)_res;
-       FREE((void*)_res);
        Transaction_free(_res_conv);
 }
 
@@ -5042,7 +5055,6 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxOut_1free(JNIEnv * _env, jcl
 
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1new(JNIEnv * _env, jclass _b, jlong a, jlong b) {
        LDKTransaction b_conv = *(LDKTransaction*)b;
-       FREE((void*)b);
        LDKC2Tuple_usizeTransactionZ* ret = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ");
        *ret = C2Tuple_usizeTransactionZ_new(a, b_conv);
        return (long)ret;
@@ -6020,7 +6032,9 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1lat
        jlongArray ret_arr = (*_env)->NewLongArray(_env, ret_var.datalen);
        jlong *ret_arr_ptr = (*_env)->GetPrimitiveArrayCritical(_env, ret_arr, NULL);
        for (size_t n = 0; n < ret_var.datalen; n++) {
-               long arr_conv_13_ref = (long)&ret_var.data[n];
+               LDKTransaction *arr_conv_13_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction");
+               *arr_conv_13_copy = ret_var.data[n];
+               long arr_conv_13_ref = (long)arr_conv_13_copy;
                ret_arr_ptr[n] = arr_conv_13_ref;
        }
        (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0);
@@ -11847,7 +11861,6 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1s
        this_ptr_conv.inner = (void*)(this_ptr & (~1));
        this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
        LDKTransaction val_conv = *(LDKTransaction*)val;
-       FREE((void*)val);
        HolderCommitmentTransaction_set_unsigned_tx(&this_ptr_conv, val_conv);
 }
 
@@ -11908,7 +11921,6 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1s
 
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1new_1missing_1holder_1sig(JNIEnv * _env, jclass _b, jlong unsigned_tx, jbyteArray counterparty_sig, jbyteArray holder_funding_key, jbyteArray counterparty_funding_key, jlong keys, jint feerate_per_kw, jlongArray htlc_data) {
        LDKTransaction unsigned_tx_conv = *(LDKTransaction*)unsigned_tx;
-       FREE((void*)unsigned_tx);
        LDKSignature counterparty_sig_ref;
        CHECK((*_env)->GetArrayLength (_env, counterparty_sig) == 64);
        (*_env)->GetByteArrayRegion (_env, counterparty_sig, 0, 64, counterparty_sig_ref.compact_form);
index 8337a4ca24955737334e7de749e8d883d27e0a6c..a371a5ca6835557716254a8bb0a1f2c0729c9d6b 100644 (file)
@@ -71,6 +71,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec
 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data
   (JNIEnv *, jclass, jbyteArray);
 
+/*
+ * Class:     org_ldk_impl_bindings
+ * Method:    txpointer_free
+ * Signature: (J)V
+ */
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_txpointer_1free
+  (JNIEnv *, jclass, jlong);
+
 /*
  * Class:     org_ldk_impl_bindings
  * Method:    vec_slice_len
index f3ba872f58554102a965eb85dcd7420564cae8a5..a1a6f47bf831360fbe7fc6b79999cc40495eb81a 100644 (file)
@@ -7,67 +7,63 @@ import org.junit.jupiter.api.Test;
 import org.ldk.enums.LDKNetwork;
 import org.ldk.impl.bindings;
 import org.ldk.structs.*;
+import org.ldk.util.TwoTuple;
 
 import java.lang.ref.WeakReference;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.LinkedList;
 import java.util.concurrent.ConcurrentLinkedQueue;
 
 public class HumanObjectPeerTest {
     class Peer {
-        final long logger;
-        final long fee_estimator;
-        final long tx_broadcaster;
+        final Logger logger;
+        final FeeEstimator fee_estimator;
+        final BroadcasterInterface tx_broadcaster;
         final KeysManager keys;
         final KeysInterface keys_interface;
         final ChannelManager chan_manager;
         final EventsProvider chan_manager_events;
         final NetGraphMsgHandler router;
         final PeerManager peer_manager;
-        HashMap<String, Long> monitors; // Wow I forgot just how terrible Java is - we can't put a byte array here.
+        final HashMap<String, ChannelMonitor> monitors; // Wow I forgot just how terrible Java is - we can't put a byte array here.
         byte[] node_id;
+        final LinkedList<org.ldk.structs.Transaction> broadcast_set = new LinkedList<>();
 
         Peer(byte seed) {
-            bindings.LDKLogger log_trait = (String arg) -> System.out.println(seed + ": " + arg);
-            logger = bindings.LDKLogger_new(log_trait);
-            this.fee_estimator = bindings.LDKFeeEstimator_new(confirmation_target -> 0);
-            this.tx_broadcaster = bindings.LDKBroadcasterInterface_new(tx -> {
-                // We should broadcast
+            logger = new Logger((String arg) -> System.out.println(seed + ": " + arg));
+            fee_estimator = new FeeEstimator((confirmation_target -> 253));
+            tx_broadcaster = new BroadcasterInterface(tx -> {
+                broadcast_set.add(tx);
             });
             this.monitors = new HashMap<>();
-            Watch chain_monitor = new Watch(new bindings.LDKWatch() {
-                @Override
-                public long watch_channel(long funding_txo, long monitor) {
+            Watch chain_monitor = new Watch(new Watch.WatchInterface() {
+                public Result_NoneChannelMonitorUpdateErrZ watch_channel(OutPoint funding_txo, ChannelMonitor monitor) {
                     synchronized (monitors) {
-                        assert monitors.put(Arrays.toString(bindings.OutPoint_get_txid(funding_txo)), monitor) == null;
+                        assert monitors.put(Arrays.toString(funding_txo.get_txid()), monitor) == null;
                     }
-                    bindings.OutPoint_free(funding_txo);
-                    return bindings.CResult_NoneChannelMonitorUpdateErrZ_ok();
+                    return new Result_NoneChannelMonitorUpdateErrZ.Result_NoneChannelMonitorUpdateErrZ_OK();
                 }
 
-                @Override
-                public long update_channel(long funding_txo, long update) {
+                public Result_NoneChannelMonitorUpdateErrZ update_channel(OutPoint funding_txo, ChannelMonitorUpdate update) {
                     synchronized (monitors) {
-                        String txid = Arrays.toString(bindings.OutPoint_get_txid(funding_txo));
+                        String txid = Arrays.toString(funding_txo.get_txid());
                         assert monitors.containsKey(txid);
-                        long update_res = bindings.ChannelMonitor_update_monitor(monitors.get(txid), update, tx_broadcaster, logger);
-                        assert bindings.LDKCResult_NoneMonitorUpdateErrorZ_result_ok(update_res);
-                        bindings.CResult_NoneMonitorUpdateErrorZ_free(update_res);
+                        Result_NoneMonitorUpdateErrorZ update_res = monitors.get(txid).update_monitor(update, tx_broadcaster, logger);
+                        assert update_res instanceof Result_NoneMonitorUpdateErrorZ.Result_NoneMonitorUpdateErrorZ_OK;
                     }
-                    bindings.OutPoint_free(funding_txo);
-                    bindings.ChannelMonitorUpdate_free(update);
-                    return bindings.CResult_NoneChannelMonitorUpdateErrZ_ok();
+                    return new Result_NoneChannelMonitorUpdateErrZ.Result_NoneChannelMonitorUpdateErrZ_OK();
                 }
 
                 @Override
-                public long[] release_pending_monitor_events() {
+                public MonitorEvent[] release_pending_monitor_events() {
                     synchronized (monitors) {
                         assert monitors.size() <= 1;
-                        for (Long mon : monitors.values()) {
-                            return bindings.ChannelMonitor_get_and_clear_pending_monitor_events(mon);
+                        for (ChannelMonitor mon : monitors.values()) {
+                            return mon.get_and_clear_pending_monitor_events();
                         }
                     }
-                    return new long[0];
+                    return new MonitorEvent[0];
                 }
             });
 
@@ -77,49 +73,32 @@ public class HumanObjectPeerTest {
             }
             this.keys = KeysManager.constructor_new(key_seed, LDKNetwork.LDKNetwork_Bitcoin, System.currentTimeMillis() / 1000, (int) (System.currentTimeMillis() * 1000) & 0xffffffff);
             this.keys_interface = keys.as_KeysInterface();
-            this.chan_manager = ChannelManager.constructor_new(LDKNetwork.LDKNetwork_Bitcoin, new FeeEstimator(confirmation_target -> 0), chain_monitor,
-                    new BroadcasterInterface(tx -> {
-                    }), new Logger(log_trait), keys.as_KeysInterface(), UserConfig.constructor_default(), 1);
+            this.chan_manager = ChannelManager.constructor_new(LDKNetwork.LDKNetwork_Bitcoin, new FeeEstimator(confirmation_target -> 0), chain_monitor, tx_broadcaster, logger, keys.as_KeysInterface(), UserConfig.constructor_default(), 1);
             this.node_id = chan_manager.get_our_node_id();
             this.chan_manager_events = chan_manager.as_EventsProvider();
-            this.router = NetGraphMsgHandler.constructor_new(null, new Logger(log_trait));
+            this.router = NetGraphMsgHandler.constructor_new(null, logger);
 
             byte[] random_data = new byte[32];
             for (byte i = 0; i < 32; i++) {
                 random_data[i] = (byte) ((i ^ seed) ^ 0xf0);
             }
-            this.peer_manager = PeerManager.constructor_new(chan_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, new Logger(log_trait));
+            this.peer_manager = PeerManager.constructor_new(chan_manager.as_ChannelMessageHandler(), router.as_RoutingMessageHandler(), keys_interface.get_node_secret(), random_data, logger);
             System.gc();
         }
 
         void connect_block(Block b, Transaction t, int height) {
             byte[] header = Arrays.copyOfRange(b.bitcoinSerialize(), 0, 80);
-            long[] txn;
-            if (t != null)
-                txn = new long[]{bindings.C2Tuple_usizeTransactionZ_new(1, bindings.new_txpointer_copy_data(t.bitcoinSerialize()))};
-            else
-                txn = new long[0];
-            bindings.ChannelManager_block_connected(chan_manager._test_only_get_ptr(), header, txn, height);
-            synchronized (monitors) {
-                for (Long mon : monitors.values()) {
-                    if (t != null)
-                        txn = new long[]{bindings.C2Tuple_usizeTransactionZ_new(1, bindings.new_txpointer_copy_data(t.bitcoinSerialize()))};
-                    else
-                        txn = new long[0];
-                    long[] ret = bindings.ChannelMonitor_block_connected(mon, header, txn, height, tx_broadcaster, fee_estimator, logger);
-                    for (long r : ret) bindings.C2Tuple_TxidCVec_TxOutZZ_free(r);
-                }
-            }
-        }
-
-        void free() {
-            // Note that we can't rely on finalizer order, so don't bother trying to rely on it here
-            bindings.Logger_free(logger);
-            bindings.FeeEstimator_free(fee_estimator);
-            bindings.BroadcasterInterface_free(tx_broadcaster);
+            TwoTuple<Long, org.ldk.structs.Transaction>[] txn;
+            if (t != null) {
+                TwoTuple<Long, org.ldk.structs.Transaction> txp = new TwoTuple<>((long) 1, new org.ldk.structs.Transaction(t.bitcoinSerialize()));
+                txn = new TwoTuple[]{txp};
+            } else
+                txn = new TwoTuple[0];
+            chan_manager.block_connected(header, txn, height);
             synchronized (monitors) {
-                for (Long mon : monitors.values()) {
-                    bindings.ChannelMonitor_free(mon);
+                for (ChannelMonitor mon : monitors.values()) {
+                    TwoTuple<byte[], TxOut[]>[] ret = mon.block_connected(header, txn, height, tx_broadcaster, fee_estimator, logger);
+                    assert ret.length == 0;
                 }
             }
         }
@@ -128,7 +107,7 @@ public class HumanObjectPeerTest {
             try (LockedNetworkGraph netgraph = this.router.read_locked_graph()) {
                 NetworkGraph graph = netgraph.graph();
                 long res = bindings.get_route(this.node_id, graph._test_only_get_ptr(), dest_node, new long[] {our_chans[0]._test_only_get_ptr()},
-                        new long[0], 1000, 42, this.logger);
+                        new long[0], 1000, 42, this.logger._test_only_get_ptr());
                 assert bindings.LDKCResult_RouteLightningErrorZ_result_ok(res);
                 byte[] serialized_route = bindings.Route_write(bindings.LDKCResult_RouteLightningErrorZ_get_ok(res));
                 must_free_objs.add(new WeakReference<>(serialized_route));
@@ -293,14 +272,29 @@ public class HumanObjectPeerTest {
         while (!list.isEmpty()) { list.poll().join(); }
         peer1.peer_manager.process_events();
         while (!list.isEmpty()) { list.poll().join(); }
+        peer2.peer_manager.process_events();
+        while (!list.isEmpty()) { list.poll().join(); }
 
         events = peer1.chan_manager_events.get_and_clear_pending_events();
         assert events.length == 1;
         assert events[0] instanceof Event.PaymentSent;
         assert Arrays.equals(((Event.PaymentSent) events[0]).payment_preimage, payment_preimage);
 
-        peer1.free();
-        peer2.free();
+        Result_NoneAPIErrorZ close_res = peer1.chan_manager.close_channel(peer1_chans[0].get_channel_id());
+        assert close_res instanceof Result_NoneAPIErrorZ.Result_NoneAPIErrorZ_OK;
+
+        peer1.peer_manager.process_events();
+        while (!list.isEmpty()) { list.poll().join(); }
+        peer2.peer_manager.process_events();
+        while (!list.isEmpty()) { list.poll().join(); }
+        peer1.peer_manager.process_events();
+        while (!list.isEmpty()) { list.poll().join(); }
+        peer2.peer_manager.process_events();
+        while (!list.isEmpty()) { list.poll().join(); }
+
+        assert peer1.broadcast_set.size() == 1;
+        assert peer2.broadcast_set.size() == 1;
+
         bindings.SocketDescriptor_free(descriptor2);
         bindings.SocketDescriptor_free(descriptor1.val);
     }
@@ -315,4 +309,4 @@ public class HumanObjectPeerTest {
         for (WeakReference<Object> o : must_free_objs)
             assert o.get() == null;
     }
-}
\ No newline at end of file
+}
index 884a08305590fbd439b34490ec832c8e201dd1de..746307862d04cda0a7cec84fa2ecbe49fbb46edb 100644 (file)
@@ -102,18 +102,23 @@ public class PeerTest {
         void connect_block(Block b, Transaction t, int height) {
             byte[] header = Arrays.copyOfRange(b.bitcoinSerialize(), 0, 80);
             long[] txn;
-            if (t != null)
-                txn = new long[] {bindings.C2Tuple_usizeTransactionZ_new(1, bindings.new_txpointer_copy_data(t.bitcoinSerialize()))};
-            else
+            long txdata = 0;
+            if (t != null) {
+                txdata = bindings.new_txpointer_copy_data(t.bitcoinSerialize());
+                txn = new long[]{bindings.C2Tuple_usizeTransactionZ_new(1, txdata)};
+            } else
                 txn = new long[0];
             bindings.ChannelManager_block_connected(chan_manager, header, txn, height);
+            if (txdata != 0) bindings.txpointer_free(txdata);
             synchronized (monitors) {
                 for (Long mon : monitors.values()) {
-                    if (t != null)
-                        txn = new long[] {bindings.C2Tuple_usizeTransactionZ_new(1, bindings.new_txpointer_copy_data(t.bitcoinSerialize()))};
-                    else
+                    if (t != null) {
+                        txdata = bindings.new_txpointer_copy_data(t.bitcoinSerialize());
+                        txn = new long[]{bindings.C2Tuple_usizeTransactionZ_new(1, txdata)};
+                    } else
                         txn = new long[0];
                     long[] ret = bindings.ChannelMonitor_block_connected(mon, header, txn, height, tx_broadcaster, fee_estimator, logger);
+                    if (txdata != 0) bindings.txpointer_free(txdata);
                     for (long r : ret) {
                         bindings.C2Tuple_TxidCVec_TxOutZZ_free(r);
                     }