From: Matt Corallo Date: Tue, 2 Feb 2021 03:02:01 +0000 (-0500) Subject: bindings updates X-Git-Tag: v0.0.1~4 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=3a507eb07003be3e6714e8a87fb397c09b401ce9;p=ldk-java bindings updates --- diff --git a/liblightningjni.so b/liblightningjni.so index a1c44c61..8d8c8395 100755 Binary files a/liblightningjni.so and b/liblightningjni.so differ diff --git a/src/main/java/org/ldk/structs/ChannelKeys.java b/src/main/java/org/ldk/structs/ChannelKeys.java index dbad7616..500e6930 100644 --- a/src/main/java/org/ldk/structs/ChannelKeys.java +++ b/src/main/java/org/ldk/structs/ChannelKeys.java @@ -110,7 +110,9 @@ public class ChannelKeys extends CommonBase { long ret = bindings.ChannelKeys_key_derivation_params(this.ptr); long ret_a = bindings.LDKC2Tuple_u64u64Z_get_a(ret); long ret_b = bindings.LDKC2Tuple_u64u64Z_get_b(ret); - TwoTuple ret_conv = new TwoTuple(ret_a, ret_b); + TwoTuple ret_conv = new TwoTuple(ret_a, ret_b, () -> { + bindings.C2Tuple_u64u64Z_free(ret); + }); return ret_conv; } diff --git a/src/main/java/org/ldk/structs/ChannelMonitor.java b/src/main/java/org/ldk/structs/ChannelMonitor.java index 2b102329..e19dfe42 100644 --- a/src/main/java/org/ldk/structs/ChannelMonitor.java +++ b/src/main/java/org/ldk/structs/ChannelMonitor.java @@ -47,7 +47,10 @@ public class ChannelMonitor extends CommonBase { OutPoint ret_a_hu_conv = new OutPoint(null, ret_a); ret_a_hu_conv.ptrs_to.add(this);; byte[] ret_b = bindings.LDKC2Tuple_OutPointScriptZ_get_b(ret); - TwoTuple ret_conv = new TwoTuple(ret_a_hu_conv, ret_b); + TwoTuple ret_conv = new TwoTuple(ret_a_hu_conv, ret_b, () -> { + bindings.C2Tuple_OutPointScriptZ_free(ret); + }); + ret_a_hu_conv.ptrs_to.add(ret_conv); return ret_conv; } @@ -94,10 +97,14 @@ public class ChannelMonitor extends CommonBase { int arr_conv_26_a = bindings.LDKC2Tuple_u32TxOutZ_get_a(arr_conv_26); long arr_conv_26_b = bindings.TxOut_clone(bindings.LDKC2Tuple_u32TxOutZ_get_b(arr_conv_26)); TxOut arr_conv_26_b_conv = new TxOut(null, arr_conv_26_b);; - TwoTuple arr_conv_26_conv = new TwoTuple(arr_conv_26_a, arr_conv_26_b_conv); + TwoTuple arr_conv_26_conv = new TwoTuple(arr_conv_26_a, arr_conv_26_b_conv, () -> { + bindings.C2Tuple_u32TxOutZ_free(arr_conv_26); + }); + arr_conv_26_b_conv.ptrs_to.add(arr_conv_26_conv); arr_conv_26_arr[a] = arr_conv_26_conv; }; TwoTuple[]> arr_conv_46_conv = new TwoTuple[]>(arr_conv_46_a, arr_conv_26_arr); + // Warning: We may not free the C tuple object! arr_conv_46_arr[u] = arr_conv_46_conv; } /* TODO 2 TwoTuple */; diff --git a/src/main/java/org/ldk/structs/Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.java b/src/main/java/org/ldk/structs/Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.java index 70127ff0..dc57ee07 100644 --- a/src/main/java/org/ldk/structs/Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.java @@ -28,7 +28,10 @@ public class Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ extends CommonB long res_b = bindings.LDKC2Tuple_BlockHashChannelManagerZ_get_b(res); ChannelManager res_b_hu_conv = new ChannelManager(null, res_b); res_b_hu_conv.ptrs_to.add(this);; - TwoTuple res_conv = new TwoTuple(res_a, res_b_hu_conv); + TwoTuple res_conv = new TwoTuple(res_a, res_b_hu_conv, () -> { + bindings.C2Tuple_BlockHashChannelManagerZ_free(res); + }); + res_b_hu_conv.ptrs_to.add(res_conv); this.res = res_conv; } public Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK(TwoTuple res) { diff --git a/src/main/java/org/ldk/structs/Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.java b/src/main/java/org/ldk/structs/Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.java index a3e3d231..5daf871c 100644 --- a/src/main/java/org/ldk/structs/Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.java +++ b/src/main/java/org/ldk/structs/Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.java @@ -28,7 +28,10 @@ public class Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ extends CommonB long res_b = bindings.LDKC2Tuple_BlockHashChannelMonitorZ_get_b(res); ChannelMonitor res_b_hu_conv = new ChannelMonitor(null, res_b); res_b_hu_conv.ptrs_to.add(this);; - TwoTuple res_conv = new TwoTuple(res_a, res_b_hu_conv); + TwoTuple res_conv = new TwoTuple(res_a, res_b_hu_conv, () -> { + bindings.C2Tuple_BlockHashChannelMonitorZ_free(res); + }); + res_b_hu_conv.ptrs_to.add(res_conv); this.res = res_conv; } public Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK(TwoTuple res) { diff --git a/src/main/java/org/ldk/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.java b/src/main/java/org/ldk/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.java index b58d3a8b..1a610732 100644 --- a/src/main/java/org/ldk/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.java +++ b/src/main/java/org/ldk/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.java @@ -26,7 +26,9 @@ public class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ extends CommonBase { long res = bindings.LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_get_ok(ptr); byte[] res_a = bindings.LDKC2Tuple_SignatureCVec_SignatureZZ_get_a(res); byte[][] res_b = bindings.LDKC2Tuple_SignatureCVec_SignatureZZ_get_b(res); - TwoTuple res_conv = new TwoTuple(res_a, res_b); + TwoTuple res_conv = new TwoTuple(res_a, res_b, () -> { + bindings.C2Tuple_SignatureCVec_SignatureZZ_free(res); + }); this.res = res_conv; } public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_OK(TwoTuple res) { diff --git a/src/main/java/org/ldk/structs/RoutingMessageHandler.java b/src/main/java/org/ldk/structs/RoutingMessageHandler.java index a4f5353d..8a50a54b 100644 --- a/src/main/java/org/ldk/structs/RoutingMessageHandler.java +++ b/src/main/java/org/ldk/structs/RoutingMessageHandler.java @@ -146,7 +146,12 @@ public class RoutingMessageHandler extends CommonBase { long arr_conv_63_c = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_c(arr_conv_63); ChannelUpdate arr_conv_63_c_hu_conv = new ChannelUpdate(null, arr_conv_63_c); arr_conv_63_c_hu_conv.ptrs_to.add(this);; - ThreeTuple arr_conv_63_conv = new ThreeTuple(arr_conv_63_a_hu_conv, arr_conv_63_b_hu_conv, arr_conv_63_c_hu_conv); + ThreeTuple arr_conv_63_conv = new ThreeTuple(arr_conv_63_a_hu_conv, arr_conv_63_b_hu_conv, arr_conv_63_c_hu_conv, () -> { + bindings.C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(arr_conv_63); + }); + arr_conv_63_a_hu_conv.ptrs_to.add(arr_conv_63_conv); + arr_conv_63_b_hu_conv.ptrs_to.add(arr_conv_63_conv); + arr_conv_63_c_hu_conv.ptrs_to.add(arr_conv_63_conv); arr_conv_63_arr[l] = arr_conv_63_conv; } return arr_conv_63_arr; diff --git a/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java b/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java index 5558dd7f..eda82f8e 100644 --- a/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java +++ b/src/main/java/org/ldk/structs/SpendableOutputDescriptor.java @@ -62,7 +62,9 @@ public class SpendableOutputDescriptor extends CommonBase { long key_derivation_params = obj.key_derivation_params; long key_derivation_params_a = bindings.LDKC2Tuple_u64u64Z_get_a(key_derivation_params); long key_derivation_params_b = bindings.LDKC2Tuple_u64u64Z_get_b(key_derivation_params); - TwoTuple key_derivation_params_conv = new TwoTuple(key_derivation_params_a, key_derivation_params_b); + TwoTuple key_derivation_params_conv = new TwoTuple(key_derivation_params_a, key_derivation_params_b, () -> { + bindings.C2Tuple_u64u64Z_free(key_derivation_params); + }); this.key_derivation_params = key_derivation_params_conv; this.revocation_pubkey = obj.revocation_pubkey; } @@ -83,7 +85,9 @@ public class SpendableOutputDescriptor extends CommonBase { long key_derivation_params = obj.key_derivation_params; long key_derivation_params_a = bindings.LDKC2Tuple_u64u64Z_get_a(key_derivation_params); long key_derivation_params_b = bindings.LDKC2Tuple_u64u64Z_get_b(key_derivation_params); - TwoTuple key_derivation_params_conv = new TwoTuple(key_derivation_params_a, key_derivation_params_b); + TwoTuple key_derivation_params_conv = new TwoTuple(key_derivation_params_a, key_derivation_params_b, () -> { + bindings.C2Tuple_u64u64Z_free(key_derivation_params); + }); this.key_derivation_params = key_derivation_params_conv; } } diff --git a/src/main/jni/bindings.c b/src/main/jni/bindings.c index 3aa76d3c..a1374eec 100644 --- a/src/main/jni/bindings.c +++ b/src/main/jni/bindings.c @@ -112,15 +112,15 @@ static inline jstring str_ref_to_java(JNIEnv *env, const char* chars, size_t len FREE(err_buf); return err_conv; } -static jclass arr_of_J_clz = NULL; static jclass arr_of_B_clz = NULL; +static jclass arr_of_J_clz = NULL; JNIEXPORT void Java_org_ldk_impl_bindings_init_1class_1cache(JNIEnv * env, jclass clz) { - arr_of_J_clz = (*env)->FindClass(env, "[J"); - CHECK(arr_of_J_clz != NULL); - arr_of_J_clz = (*env)->NewGlobalRef(env, arr_of_J_clz); arr_of_B_clz = (*env)->FindClass(env, "[B"); CHECK(arr_of_B_clz != NULL); arr_of_B_clz = (*env)->NewGlobalRef(env, arr_of_B_clz); + arr_of_J_clz = (*env)->FindClass(env, "[J"); + CHECK(arr_of_J_clz != NULL); + arr_of_J_clz = (*env)->NewGlobalRef(env, arr_of_J_clz); } static inline struct LDKThirtyTwoBytes ThirtyTwoBytes_clone(const struct LDKThirtyTwoBytes *orig) { struct LDKThirtyTwoBytes ret; memcpy(ret.data, orig->data, 32); return ret; } static inline LDKAccessError LDKAccessError_from_java(JNIEnv *env, jclass clz) { diff --git a/ts/structs/ChannelKeys.ts b/ts/structs/ChannelKeys.ts index 957dc512..61daa256 100644 --- a/ts/structs/ChannelKeys.ts +++ b/ts/structs/ChannelKeys.ts @@ -138,7 +138,9 @@ import * as bindings from '../bindings' // TODO: figure out location number ret = bindings.ChannelKeys_key_derivation_params(this.ptr); number ret_a = bindings.LDKC2Tuple_u64u64Z_get_a(ret); number ret_b = bindings.LDKC2Tuple_u64u64Z_get_b(ret); - TwoTuple ret_conv = new TwoTuple(ret_a, ret_b); + TwoTuple ret_conv = new TwoTuple(ret_a, ret_b, () -> { + bindings.C2Tuple_u64u64Z_free(ret); + }); return ret_conv; } diff --git a/ts/structs/ChannelMonitor.ts b/ts/structs/ChannelMonitor.ts index 8baaf189..ff746a20 100644 --- a/ts/structs/ChannelMonitor.ts +++ b/ts/structs/ChannelMonitor.ts @@ -51,7 +51,10 @@ import * as bindings from '../bindings' // TODO: figure out location const ret_a_hu_conv: OutPoint = new OutPoint(null, ret_a); ret_a_hu_conv.ptrs_to.add(this);; Uint8Array ret_b = bindings.LDKC2Tuple_OutPointScriptZ_get_b(ret); - TwoTuple ret_conv = new TwoTuple(ret_a_hu_conv, ret_b); + TwoTuple ret_conv = new TwoTuple(ret_a_hu_conv, ret_b, () -> { + bindings.C2Tuple_OutPointScriptZ_free(ret); + }); + ret_a_hu_conv.ptrs_to.add(ret_conv); return ret_conv; } @@ -98,10 +101,14 @@ import * as bindings from '../bindings' // TODO: figure out location number arr_conv_25_a = bindings.LDKC2Tuple_u32TxOutZ_get_a(arr_conv_25); number arr_conv_25_b = bindings.TxOut_clone(bindings.LDKC2Tuple_u32TxOutZ_get_b(arr_conv_25)); TxOut arr_conv_25_b_conv = new TxOut(null, arr_conv_25_b);; - TwoTuple arr_conv_25_conv = new TwoTuple(arr_conv_25_a, arr_conv_25_b_conv); + TwoTuple arr_conv_25_conv = new TwoTuple(arr_conv_25_a, arr_conv_25_b_conv, () -> { + bindings.C2Tuple_u32TxOutZ_free(arr_conv_25); + }); + arr_conv_25_b_conv.ptrs_to.add(arr_conv_25_conv); arr_conv_25_arr[z] = arr_conv_25_conv; }; TwoTuple[]> arr_conv_49_conv = new TwoTuple[]>(arr_conv_49_a, arr_conv_25_arr); + // Warning: We may not free the C tuple object! arr_conv_49_arr[x] = arr_conv_49_conv; } /* TODO 2 TwoTuple */; diff --git a/ts/structs/Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.ts b/ts/structs/Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.ts index 81d95ece..91fcaa40 100644 --- a/ts/structs/Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.ts +++ b/ts/structs/Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ.ts @@ -24,7 +24,10 @@ public class Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ extends CommonB number res_b = bindings.LDKC2Tuple_BlockHashChannelManagerZ_get_b(res); const res_b_hu_conv: ChannelManager = new ChannelManager(null, res_b); res_b_hu_conv.ptrs_to.add(this);; - TwoTuple res_conv = new TwoTuple(res_a, res_b_hu_conv); + TwoTuple res_conv = new TwoTuple(res_a, res_b_hu_conv, () -> { + bindings.C2Tuple_BlockHashChannelManagerZ_free(res); + }); + res_b_hu_conv.ptrs_to.add(res_conv); this.res = res_conv; } public Result_C2Tuple_BlockHashChannelManagerZDecodeErrorZ_OK(TwoTuple res) { diff --git a/ts/structs/Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.ts b/ts/structs/Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.ts index 5b2d6c20..c563f848 100644 --- a/ts/structs/Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.ts +++ b/ts/structs/Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ.ts @@ -24,7 +24,10 @@ public class Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ extends CommonB number res_b = bindings.LDKC2Tuple_BlockHashChannelMonitorZ_get_b(res); const res_b_hu_conv: ChannelMonitor = new ChannelMonitor(null, res_b); res_b_hu_conv.ptrs_to.add(this);; - TwoTuple res_conv = new TwoTuple(res_a, res_b_hu_conv); + TwoTuple res_conv = new TwoTuple(res_a, res_b_hu_conv, () -> { + bindings.C2Tuple_BlockHashChannelMonitorZ_free(res); + }); + res_b_hu_conv.ptrs_to.add(res_conv); this.res = res_conv; } public Result_C2Tuple_BlockHashChannelMonitorZDecodeErrorZ_OK(TwoTuple res) { diff --git a/ts/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.ts b/ts/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.ts index eb356463..23aad79f 100644 --- a/ts/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.ts +++ b/ts/structs/Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.ts @@ -22,7 +22,9 @@ public class Result_C2Tuple_SignatureCVec_SignatureZZNoneZ extends CommonBase { number res = bindings.LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ_get_ok(ptr); Uint8Array res_a = bindings.LDKC2Tuple_SignatureCVec_SignatureZZ_get_a(res); Uint8Array[] res_b = bindings.LDKC2Tuple_SignatureCVec_SignatureZZ_get_b(res); - TwoTuple res_conv = new TwoTuple(res_a, res_b); + TwoTuple res_conv = new TwoTuple(res_a, res_b, () -> { + bindings.C2Tuple_SignatureCVec_SignatureZZ_free(res); + }); this.res = res_conv; } public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ_OK(TwoTuple res) { diff --git a/ts/structs/RoutingMessageHandler.ts b/ts/structs/RoutingMessageHandler.ts index 2ab676ca..28552c66 100644 --- a/ts/structs/RoutingMessageHandler.ts +++ b/ts/structs/RoutingMessageHandler.ts @@ -174,7 +174,12 @@ import * as bindings from '../bindings' // TODO: figure out location number arr_conv_63_c = bindings.LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_get_c(arr_conv_63); const arr_conv_63_c_hu_conv: ChannelUpdate = new ChannelUpdate(null, arr_conv_63_c); arr_conv_63_c_hu_conv.ptrs_to.add(this);; - ThreeTuple arr_conv_63_conv = new ThreeTuple(arr_conv_63_a_hu_conv, arr_conv_63_b_hu_conv, arr_conv_63_c_hu_conv); + ThreeTuple arr_conv_63_conv = new ThreeTuple(arr_conv_63_a_hu_conv, arr_conv_63_b_hu_conv, arr_conv_63_c_hu_conv, () -> { + bindings.C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_free(arr_conv_63); + }); + arr_conv_63_a_hu_conv.ptrs_to.add(arr_conv_63_conv); + arr_conv_63_b_hu_conv.ptrs_to.add(arr_conv_63_conv); + arr_conv_63_c_hu_conv.ptrs_to.add(arr_conv_63_conv); arr_conv_63_arr[l] = arr_conv_63_conv; } return arr_conv_63_arr; diff --git a/ts/structs/SpendableOutputDescriptor.ts b/ts/structs/SpendableOutputDescriptor.ts index 79a3f6ce..005b9741 100644 --- a/ts/structs/SpendableOutputDescriptor.ts +++ b/ts/structs/SpendableOutputDescriptor.ts @@ -58,7 +58,9 @@ export class DynamicOutputP2WSH extends SpendableOutputDescriptor { const key_derivation_params: number = obj.key_derivation_params; number key_derivation_params_a = bindings.LDKC2Tuple_u64u64Z_get_a(key_derivation_params); number key_derivation_params_b = bindings.LDKC2Tuple_u64u64Z_get_b(key_derivation_params); - TwoTuple key_derivation_params_conv = new TwoTuple(key_derivation_params_a, key_derivation_params_b); + TwoTuple key_derivation_params_conv = new TwoTuple(key_derivation_params_a, key_derivation_params_b, () -> { + bindings.C2Tuple_u64u64Z_free(key_derivation_params); + }); this.key_derivation_params = key_derivation_params_conv; this.revocation_pubkey = obj.revocation_pubkey; } @@ -79,7 +81,9 @@ export class StaticOutputCounterpartyPayment extends SpendableOutputDescriptor { const key_derivation_params: number = obj.key_derivation_params; number key_derivation_params_a = bindings.LDKC2Tuple_u64u64Z_get_a(key_derivation_params); number key_derivation_params_b = bindings.LDKC2Tuple_u64u64Z_get_b(key_derivation_params); - TwoTuple key_derivation_params_conv = new TwoTuple(key_derivation_params_a, key_derivation_params_b); + TwoTuple key_derivation_params_conv = new TwoTuple(key_derivation_params_a, key_derivation_params_b, () -> { + bindings.C2Tuple_u64u64Z_free(key_derivation_params); + }); this.key_derivation_params = key_derivation_params_conv; } }