From: Matt Corallo Date: Sun, 25 Oct 2020 01:43:44 +0000 (-0400) Subject: Map Transactions as byte[] instead of trying to keep a ptr X-Git-Tag: v0.0.1~79 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=18faab2952bff2302d55528dea556246be63950a;p=ldk-java Map Transactions as byte[] instead of trying to keep a ptr --- diff --git a/genbindings.py b/genbindings.py index 0356da08..54d085a5 100755 --- a/genbindings.py +++ b/genbindings.py @@ -305,6 +305,11 @@ def java_c_types(fn_arg, ret_arr_len): rust_obj = "LDKCVec_u8Z" assert var_is_arr_regex.match(fn_arg[8:]) arr_access = "data" + elif fn_arg.startswith("LDKTransaction"): + fn_arg = "uint8_t (*" + fn_arg[15:] + ")[datalen]" + rust_obj = "LDKTransaction" + assert var_is_arr_regex.match(fn_arg[8:]) + arr_access = "data" elif fn_arg.startswith("LDKCVecTempl_") or fn_arg.startswith("LDKCVec_"): is_ptr = False if "*" in fn_arg: @@ -520,14 +525,20 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: arg_conv_cleanup = None if not arr_len.isdigit(): arg_conv = ty_info.rust_obj + " " + arr_name + "_ref;\n" - arg_conv = arg_conv + arr_name + "_ref." + ty_info.arr_access + " = (*_env)->GetByteArrayElements (_env, " + arr_name + ", NULL);\n" - arg_conv = arg_conv + arr_name + "_ref." + arr_len + " = (*_env)->GetArrayLength (_env, " + arr_name + ");" - arg_conv_cleanup = "(*_env)->ReleaseByteArrayElements(_env, " + arr_name + ", (int8_t*)" + arr_name + "_ref." + ty_info.arr_access + ", 0);" + arg_conv = arg_conv + arr_name + "_ref." + arr_len + " = (*_env)->GetArrayLength (_env, " + arr_name + ");\n" + if (not ty_info.is_ptr or not holds_ref) and ty_info.rust_obj != "LDKu8slice": + arg_conv = arg_conv + arr_name + "_ref." + ty_info.arr_access + " = MALLOC(" + arr_name + "_ref." + arr_len + ", \"" + ty_info.rust_obj + " Bytes\");\n" + arg_conv = arg_conv + "(*_env)->GetByteArrayRegion(_env, " + arr_name + ", 0, " + arr_name + "_ref." + arr_len + ", " + arr_name + "_ref." + ty_info.arr_access + ");" + else: + arg_conv = arg_conv + arr_name + "_ref." + ty_info.arr_access + " = (*_env)->GetByteArrayElements (_env, " + arr_name + ", NULL);" + arg_conv_cleanup = "(*_env)->ReleaseByteArrayElements(_env, " + arr_name + ", (int8_t*)" + arr_name + "_ref." + ty_info.arr_access + ", 0);" + if ty_info.rust_obj == "LDKTransaction": + arg_conv = arg_conv + "\n" + arr_name + "_ref.data_is_owned = " + str(holds_ref).lower() + ";" ret_conv = (ty_info.rust_obj + " " + arr_name + "_var = ", "") ret_conv = (ret_conv[0], ";\njbyteArray " + arr_name + "_arr = (*_env)->NewByteArray(_env, " + arr_name + "_var." + arr_len + ");\n") ret_conv = (ret_conv[0], ret_conv[1] + "(*_env)->SetByteArrayRegion(_env, " + arr_name + "_arr, 0, " + arr_name + "_var." + arr_len + ", " + arr_name + "_var." + ty_info.arr_access + ");") - if not holds_ref and ty_info.rust_obj == "LDKCVec_u8Z": - ret_conv = (ret_conv[0], ret_conv[1] + "\nCVec_u8Z_free(" + arr_name + "_var);") + if not holds_ref and ty_info.rust_obj != "LDKu8slice": + ret_conv = (ret_conv[0], ret_conv[1] + "\n" + ty_info.rust_obj.replace("LDK", "") + "_free(" + arr_name + "_var);") elif ty_info.rust_obj is not None: arg_conv = ty_info.rust_obj + " " + arr_name + "_ref;\n" arg_conv = arg_conv + "CHECK((*_env)->GetArrayLength (_env, " + arr_name + ") == " + arr_len + ");\n" @@ -741,7 +752,7 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: 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 = (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" and ty_info.rust_obj != "LDKTransaction": + if ty_info.rust_obj != "LDKu8slice": # 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 + ");"; @@ -806,20 +817,12 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java: 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", "")) - elif ty_info.rust_obj == "LDKTxOut": - 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 = (ty_info.var_name + ".ptr", "")) + assert ty_info.rust_obj == "LDKTxOut" + 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 = (ty_info.var_name + ".ptr", "")) elif ty_info.is_ptr: assert(not is_free) if ty_info.rust_obj in complex_enums: @@ -1793,16 +1796,6 @@ class CommonBase { out_java_struct.write("\tlong to_c_ptr() { return 0; }\n") # TODO: TxOut body out_java_struct.write("}") - elif struct_name == "LDKTransaction": - with open(sys.argv[3] + "/structs/Transaction.java", "w") as out_java_struct: - 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") - out_java_struct.write("\tpublic byte[] get_contents() { return bindings.txpointer_get_buffer(ptr); }\n") - # TODO: Transaction body - out_java_struct.write("}") else: pass # Everything remaining is a byte[] or some form cur_block_obj = None diff --git a/src/main/java/org/ldk/impl/bindings.java b/src/main/java/org/ldk/impl/bindings.java index d1f596cb..966995a8 100644 --- a/src/main/java/org/ldk/impl/bindings.java +++ b/src/main/java/org/ldk/impl/bindings.java @@ -38,9 +38,9 @@ public class bindings { static { LDKSecp256k1Error.values(); /* Force enum statics to run */ } public static native VecOrSliceDef LDKCVecTempl_u8_arr_info(long vec_ptr); public static native long LDKCVecTempl_u8_new(byte[] elems); - public static native long LDKC2TupleTempl_usize__Transaction_new(long a, long b); + public static native long LDKC2TupleTempl_usize__Transaction_new(long a, byte[] b); public static native long LDKC2Tuple_usizeTransactionZ_get_a(long ptr); - public static native long LDKC2Tuple_usizeTransactionZ_get_b(long ptr); + public static native byte[] LDKC2Tuple_usizeTransactionZ_get_b(long ptr); public static native boolean LDKCResult_NoneChannelMonitorUpdateErrZ_result_ok(long arg); public static native byte LDKCResult_NoneChannelMonitorUpdateErrZ_get_ok(long arg); public static native LDKChannelMonitorUpdateErr LDKCResult_NoneChannelMonitorUpdateErrZ_get_err(long arg); @@ -339,12 +339,12 @@ public class bindings { byte[] get_per_commitment_point(long idx); byte[] release_commitment_secret(long idx); long key_derivation_params(); - long sign_counterparty_commitment(int feerate_per_kw, long commitment_tx, long keys, long[] htlcs); + long sign_counterparty_commitment(int feerate_per_kw, byte[] commitment_tx, long keys, long[] htlcs); long sign_holder_commitment(long holder_commitment_tx); long sign_holder_commitment_htlc_transactions(long holder_commitment_tx); - long sign_justice_transaction(long justice_tx, long input, long amount, byte[] per_commitment_key, long htlc); - long sign_counterparty_htlc_transaction(long htlc_tx, long input, long amount, byte[] per_commitment_point, long htlc); - long sign_closing_transaction(long closing_tx); + long sign_justice_transaction(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, long htlc); + long sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, long htlc); + long sign_closing_transaction(byte[] closing_tx); long sign_channel_announcement(long msg); void on_accept(long channel_points, short counterparty_selected_contest_delay, short holder_selected_contest_delay); } @@ -357,17 +357,17 @@ public class bindings { // LDKC2Tuple_u64u64Z ChannelKeys_key_derivation_params LDKChannelKeys* this_arg public static native long ChannelKeys_key_derivation_params(long this_arg); // LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ ChannelKeys_sign_counterparty_commitment LDKChannelKeys* this_arg, uint32_t feerate_per_kw, LDKTransaction commitment_tx, const LDKPreCalculatedTxCreationKeys *keys, LDKCVec_HTLCOutputInCommitmentZ htlcs - public static native long ChannelKeys_sign_counterparty_commitment(long this_arg, int feerate_per_kw, long commitment_tx, long keys, long[] htlcs); + public static native long ChannelKeys_sign_counterparty_commitment(long this_arg, int feerate_per_kw, byte[] commitment_tx, long keys, long[] htlcs); // LDKCResult_SignatureNoneZ ChannelKeys_sign_holder_commitment LDKChannelKeys* this_arg, const LDKHolderCommitmentTransaction *holder_commitment_tx public static native long ChannelKeys_sign_holder_commitment(long this_arg, long holder_commitment_tx); // LDKCResult_CVec_SignatureZNoneZ ChannelKeys_sign_holder_commitment_htlc_transactions LDKChannelKeys* this_arg, const LDKHolderCommitmentTransaction *holder_commitment_tx public static native long ChannelKeys_sign_holder_commitment_htlc_transactions(long this_arg, long holder_commitment_tx); // LDKCResult_SignatureNoneZ ChannelKeys_sign_justice_transaction LDKChannelKeys* this_arg, LDKTransaction justice_tx, uintptr_t input, uint64_t amount, const uint8_t (*per_commitment_key)[32], const LDKHTLCOutputInCommitment *htlc - public static native long ChannelKeys_sign_justice_transaction(long this_arg, long justice_tx, long input, long amount, byte[] per_commitment_key, long htlc); + public static native long ChannelKeys_sign_justice_transaction(long this_arg, byte[] justice_tx, long input, long amount, byte[] per_commitment_key, long htlc); // LDKCResult_SignatureNoneZ ChannelKeys_sign_counterparty_htlc_transaction LDKChannelKeys* this_arg, LDKTransaction htlc_tx, uintptr_t input, uint64_t amount, LDKPublicKey per_commitment_point, const LDKHTLCOutputInCommitment *htlc - public static native long ChannelKeys_sign_counterparty_htlc_transaction(long this_arg, long htlc_tx, long input, long amount, byte[] per_commitment_point, long htlc); + public static native long ChannelKeys_sign_counterparty_htlc_transaction(long this_arg, byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, long htlc); // LDKCResult_SignatureNoneZ ChannelKeys_sign_closing_transaction LDKChannelKeys* this_arg, LDKTransaction closing_tx - public static native long ChannelKeys_sign_closing_transaction(long this_arg, long closing_tx); + public static native long ChannelKeys_sign_closing_transaction(long this_arg, byte[] closing_tx); // LDKCResult_SignatureNoneZ ChannelKeys_sign_channel_announcement LDKChannelKeys* this_arg, const LDKUnsignedChannelAnnouncement *msg public static native long ChannelKeys_sign_channel_announcement(long this_arg, long msg); // void ChannelKeys_on_accept LDKChannelKeys* this_arg, const LDKChannelPublicKeys *channel_points, uint16_t counterparty_selected_contest_delay, uint16_t holder_selected_contest_delay @@ -400,12 +400,12 @@ public class bindings { // void Filter_register_output LDKFilter* this_arg, const LDKOutPoint *outpoint, LDKu8slice script_pubkey public static native void Filter_register_output(long this_arg, long outpoint, byte[] script_pubkey); public interface LDKBroadcasterInterface { - void broadcast_transaction(long tx); + void broadcast_transaction(byte[] tx); } public static native long LDKBroadcasterInterface_new(LDKBroadcasterInterface impl); public static native LDKBroadcasterInterface LDKBroadcasterInterface_get_obj_from_jcalls(long val); // void BroadcasterInterface_broadcast_transaction LDKBroadcasterInterface* this_arg, LDKTransaction tx - public static native void BroadcasterInterface_broadcast_transaction(long this_arg, long tx); + public static native void BroadcasterInterface_broadcast_transaction(long this_arg, byte[] tx); public interface LDKFeeEstimator { int get_est_sat_per_1000_weight(LDKConfirmationTarget confirmation_target); } @@ -416,7 +416,6 @@ public class bindings { public static native VecOrSliceDef LDKCVecTempl_C2TupleTempl_usize__Transaction_arr_info(long vec_ptr); public static native long LDKCVecTempl_C2TupleTempl_usize__Transaction_new(long[] elems); public static native VecOrSliceDef LDKCVecTempl_Transaction_arr_info(long vec_ptr); - public static native long LDKCVecTempl_Transaction_new(long[] elems); public static native VecOrSliceDef LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut_arr_info(long vec_ptr); public static native long LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut_new(long[] elems); public interface LDKKeysInterface { @@ -746,7 +745,7 @@ public class bindings { // extern const void (*CVec_SpendableOutputDescriptorZ_free)(LDKCVec_SpendableOutputDescriptorZ); public static native void CVec_SpendableOutputDescriptorZ_free(long[] arg); // extern const void (*CVec_TransactionZ_free)(LDKCVec_TransactionZ); - public static native void CVec_TransactionZ_free(long[] arg); + public static native void CVec_TransactionZ_free(byte[][] arg); // extern const void (*CVec_TxOutZ_free)(LDKCVec_TxOutZ); public static native void CVec_TxOutZ_free(long[] arg); // extern const void (*CVec_UpdateAddHTLCZ_free)(LDKCVec_UpdateAddHTLCZ); @@ -762,11 +761,11 @@ public class bindings { // extern const void (*CVec_u8Z_free)(LDKCVec_u8Z); public static native void CVec_u8Z_free(byte[] arg); // void Transaction_free(LDKTransaction _res); - public static native void Transaction_free(long _res); + public static native void Transaction_free(byte[] _res); // void TxOut_free(LDKTxOut _res); public static native void TxOut_free(long _res); // LDKC2Tuple_usizeTransactionZ C2Tuple_usizeTransactionZ_new(uintptr_t a, LDKTransaction b); - public static native long C2Tuple_usizeTransactionZ_new(long a, long b); + public static native long C2Tuple_usizeTransactionZ_new(long a, byte[] b); // LDKCResult_NoneChannelMonitorUpdateErrZ CResult_NoneChannelMonitorUpdateErrZ_ok(void); public static native long CResult_NoneChannelMonitorUpdateErrZ_ok(); // LDKCResult_NoneMonitorUpdateErrorZ CResult_NoneMonitorUpdateErrorZ_ok(void); @@ -996,7 +995,7 @@ public class bindings { // MUST_USE_RES LDKCVec_EventZ ChannelMonitor_get_and_clear_pending_events(LDKChannelMonitor *this_arg); public static native long[] ChannelMonitor_get_and_clear_pending_events(long this_arg); // MUST_USE_RES LDKCVec_TransactionZ ChannelMonitor_get_latest_holder_commitment_txn(LDKChannelMonitor *this_arg, const LDKLogger *logger); - public static native long[] ChannelMonitor_get_latest_holder_commitment_txn(long this_arg, long logger); + public static native byte[][] ChannelMonitor_get_latest_holder_commitment_txn(long this_arg, long logger); // MUST_USE_RES LDKCVec_C2Tuple_TxidCVec_TxOutZZZ ChannelMonitor_block_connected(LDKChannelMonitor *this_arg, const uint8_t (*header)[80], LDKCVec_C2Tuple_usizeTransactionZZ txdata, uint32_t height, LDKBroadcasterInterface broadcaster, LDKFeeEstimator fee_estimator, LDKLogger logger); public static native long[] ChannelMonitor_block_connected(long this_arg, byte[] header, long[] txdata, int height, long broadcaster, long fee_estimator, long logger); // void ChannelMonitor_block_disconnected(LDKChannelMonitor *this_arg, const uint8_t (*header)[80], uint32_t height, LDKBroadcasterInterface broadcaster, LDKFeeEstimator fee_estimator, LDKLogger logger); @@ -2184,15 +2183,15 @@ public class bindings { // LDKCVec_u8Z make_funding_redeemscript(LDKPublicKey broadcaster, LDKPublicKey countersignatory); public static native byte[] make_funding_redeemscript(byte[] broadcaster, byte[] countersignatory); // LDKTransaction build_htlc_transaction(const uint8_t (*prev_hash)[32], uint32_t feerate_per_kw, uint16_t contest_delay, const LDKHTLCOutputInCommitment *htlc, LDKPublicKey broadcaster_delayed_payment_key, LDKPublicKey revocation_key); - public static native long build_htlc_transaction(byte[] prev_hash, int feerate_per_kw, short contest_delay, long htlc, byte[] broadcaster_delayed_payment_key, byte[] revocation_key); + public static native byte[] build_htlc_transaction(byte[] prev_hash, int feerate_per_kw, short contest_delay, long htlc, byte[] broadcaster_delayed_payment_key, byte[] revocation_key); // void HolderCommitmentTransaction_free(LDKHolderCommitmentTransaction this_ptr); public static native void HolderCommitmentTransaction_free(long this_ptr); // LDKHolderCommitmentTransaction HolderCommitmentTransaction_clone(const LDKHolderCommitmentTransaction *orig); public static native long HolderCommitmentTransaction_clone(long orig); // LDKTransaction HolderCommitmentTransaction_get_unsigned_tx(const LDKHolderCommitmentTransaction *this_ptr); - public static native long HolderCommitmentTransaction_get_unsigned_tx(long this_ptr); + public static native byte[] HolderCommitmentTransaction_get_unsigned_tx(long this_ptr); // void HolderCommitmentTransaction_set_unsigned_tx(LDKHolderCommitmentTransaction *this_ptr, LDKTransaction val); - public static native void HolderCommitmentTransaction_set_unsigned_tx(long this_ptr, long val); + public static native void HolderCommitmentTransaction_set_unsigned_tx(long this_ptr, byte[] val); // LDKSignature HolderCommitmentTransaction_get_counterparty_sig(const LDKHolderCommitmentTransaction *this_ptr); public static native byte[] HolderCommitmentTransaction_get_counterparty_sig(long this_ptr); // void HolderCommitmentTransaction_set_counterparty_sig(LDKHolderCommitmentTransaction *this_ptr, LDKSignature val); @@ -2204,7 +2203,7 @@ public class bindings { // void HolderCommitmentTransaction_set_per_htlc(LDKHolderCommitmentTransaction *this_ptr, LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ val); public static native void HolderCommitmentTransaction_set_per_htlc(long this_ptr, long[] val); // MUST_USE_RES LDKHolderCommitmentTransaction HolderCommitmentTransaction_new_missing_holder_sig(LDKTransaction unsigned_tx, LDKSignature counterparty_sig, LDKPublicKey holder_funding_key, LDKPublicKey counterparty_funding_key, LDKTxCreationKeys keys, uint32_t feerate_per_kw, LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ htlc_data); - public static native long HolderCommitmentTransaction_new_missing_holder_sig(long unsigned_tx, byte[] counterparty_sig, byte[] holder_funding_key, byte[] counterparty_funding_key, long keys, int feerate_per_kw, long[] htlc_data); + public static native long HolderCommitmentTransaction_new_missing_holder_sig(byte[] unsigned_tx, byte[] counterparty_sig, byte[] holder_funding_key, byte[] counterparty_funding_key, long keys, int feerate_per_kw, long[] htlc_data); // MUST_USE_RES LDKTxCreationKeys HolderCommitmentTransaction_trust_key_derivation(const LDKHolderCommitmentTransaction *this_arg); public static native long HolderCommitmentTransaction_trust_key_derivation(long this_arg); // MUST_USE_RES LDKThirtyTwoBytes HolderCommitmentTransaction_txid(const LDKHolderCommitmentTransaction *this_arg); diff --git a/src/main/java/org/ldk/structs/BroadcasterInterface.java b/src/main/java/org/ldk/structs/BroadcasterInterface.java index 64979fec..df6b6493 100644 --- a/src/main/java/org/ldk/structs/BroadcasterInterface.java +++ b/src/main/java/org/ldk/structs/BroadcasterInterface.java @@ -20,21 +20,20 @@ public class BroadcasterInterface extends CommonBase { } public static interface BroadcasterInterfaceInterface { - void broadcast_transaction(Transaction tx); + void broadcast_transaction(byte[] tx); } private static class LDKBroadcasterInterfaceHolder { BroadcasterInterface held; } public static BroadcasterInterface new_impl(BroadcasterInterfaceInterface arg) { final LDKBroadcasterInterfaceHolder impl_holder = new LDKBroadcasterInterfaceHolder(); impl_holder.held = new BroadcasterInterface(new bindings.LDKBroadcasterInterface() { - @Override public void broadcast_transaction(long tx) { - Transaction tx_conv = new Transaction(null, tx); - arg.broadcast_transaction(tx_conv); + @Override public void broadcast_transaction(byte[] tx) { + arg.broadcast_transaction(tx); } }); return impl_holder.held; } - public void broadcast_transaction(Transaction tx) { - bindings.BroadcasterInterface_broadcast_transaction(this.ptr, tx.ptr); + public void broadcast_transaction(byte[] tx) { + bindings.BroadcasterInterface_broadcast_transaction(this.ptr, tx); } } diff --git a/src/main/java/org/ldk/structs/ChainMonitor.java b/src/main/java/org/ldk/structs/ChainMonitor.java index 236f8e39..ae957504 100644 --- a/src/main/java/org/ldk/structs/ChainMonitor.java +++ b/src/main/java/org/ldk/structs/ChainMonitor.java @@ -14,9 +14,9 @@ public class ChainMonitor extends CommonBase { if (ptr != 0) { bindings.ChainMonitor_free(ptr); } } - public void block_connected(byte[] header, TwoTuple[] txdata, int 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 */; + public void block_connected(byte[] header, TwoTuple[] txdata, int height) { + bindings.ChainMonitor_block_connected(this.ptr, header, Arrays.stream(txdata).mapToLong(arr_conv_24 -> bindings.C2Tuple_usizeTransactionZ_new(arr_conv_24.a, arr_conv_24.b)).toArray(), height); + /* TODO 2 TwoTuple */; } public void block_disconnected(byte[] header, int disconnected_height) { diff --git a/src/main/java/org/ldk/structs/ChannelKeys.java b/src/main/java/org/ldk/structs/ChannelKeys.java index 7283363a..9a37199b 100644 --- a/src/main/java/org/ldk/structs/ChannelKeys.java +++ b/src/main/java/org/ldk/structs/ChannelKeys.java @@ -24,12 +24,12 @@ public class ChannelKeys extends CommonBase { byte[] get_per_commitment_point(long idx); byte[] release_commitment_secret(long idx); TwoTuple key_derivation_params(); - Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(int feerate_per_kw, Transaction commitment_tx, PreCalculatedTxCreationKeys keys, HTLCOutputInCommitment[] htlcs); + Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(int feerate_per_kw, byte[] 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_justice_transaction(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, HTLCOutputInCommitment htlc); + Result_SignatureNoneZ sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, HTLCOutputInCommitment htlc); + Result_SignatureNoneZ sign_closing_transaction(byte[] 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); } @@ -50,8 +50,7 @@ public class ChannelKeys extends CommonBase { 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); + @Override public long sign_counterparty_commitment(int feerate_per_kw, byte[] commitment_tx, long keys, long[] htlcs) { 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++) { @@ -59,7 +58,7 @@ public class ChannelKeys extends CommonBase { 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); + Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret = arg.sign_counterparty_commitment(feerate_per_kw, commitment_tx, keys_hu_conv, arr_conv_24_arr); long result = ret != null ? ret.ptr : 0; ret.ptr = 0; return result; @@ -78,25 +77,22 @@ public class ChannelKeys extends CommonBase { 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); + @Override public long sign_justice_transaction(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, long htlc) { 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); + Result_SignatureNoneZ ret = arg.sign_justice_transaction(justice_tx, 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); + @Override public long sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, long htlc) { 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); + Result_SignatureNoneZ ret = arg.sign_counterparty_htlc_transaction(htlc_tx, 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); + @Override public long sign_closing_transaction(byte[] closing_tx) { + Result_SignatureNoneZ ret = arg.sign_closing_transaction(closing_tx); long result = ret != null ? ret.ptr : 0; ret.ptr = 0; return result; @@ -126,8 +122,8 @@ public class ChannelKeys extends CommonBase { } // Skipped ChannelKeys_key_derivation_params - public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(int feerate_per_kw, Transaction commitment_tx, PreCalculatedTxCreationKeys keys, HTLCOutputInCommitment[] htlcs) { - long ret = bindings.ChannelKeys_sign_counterparty_commitment(this.ptr, feerate_per_kw, commitment_tx.ptr, keys == null ? 0 : keys.ptr & ~1, Arrays.stream(htlcs).mapToLong(arr_conv_24 -> arr_conv_24 == null ? 0 : arr_conv_24.ptr & ~1).toArray()); + public Result_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment(int feerate_per_kw, byte[] commitment_tx, PreCalculatedTxCreationKeys keys, HTLCOutputInCommitment[] htlcs) { + long ret = bindings.ChannelKeys_sign_counterparty_commitment(this.ptr, feerate_per_kw, commitment_tx, keys == null ? 0 : keys.ptr & ~1, Arrays.stream(htlcs).mapToLong(arr_conv_24 -> arr_conv_24 == null ? 0 : arr_conv_24.ptr & ~1).toArray()); Result_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_hu_conv = Result_C2Tuple_SignatureCVec_SignatureZZNoneZ.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(this); this.ptrs_to.add(keys); @@ -151,24 +147,24 @@ public class ChannelKeys extends CommonBase { return ret_hu_conv; } - public Result_SignatureNoneZ sign_justice_transaction(Transaction justice_tx, long input, long amount, byte[] per_commitment_key, HTLCOutputInCommitment htlc) { - long ret = bindings.ChannelKeys_sign_justice_transaction(this.ptr, justice_tx.ptr, input, amount, per_commitment_key, htlc == null ? 0 : htlc.ptr & ~1); + public Result_SignatureNoneZ sign_justice_transaction(byte[] justice_tx, long input, long amount, byte[] per_commitment_key, HTLCOutputInCommitment htlc) { + long ret = bindings.ChannelKeys_sign_justice_transaction(this.ptr, justice_tx, input, amount, per_commitment_key, htlc == null ? 0 : htlc.ptr & ~1); Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(this); this.ptrs_to.add(htlc); return ret_hu_conv; } - public Result_SignatureNoneZ sign_counterparty_htlc_transaction(Transaction htlc_tx, long input, long amount, byte[] per_commitment_point, HTLCOutputInCommitment htlc) { - long ret = bindings.ChannelKeys_sign_counterparty_htlc_transaction(this.ptr, htlc_tx.ptr, input, amount, per_commitment_point, htlc == null ? 0 : htlc.ptr & ~1); + public Result_SignatureNoneZ sign_counterparty_htlc_transaction(byte[] htlc_tx, long input, long amount, byte[] per_commitment_point, HTLCOutputInCommitment htlc) { + long ret = bindings.ChannelKeys_sign_counterparty_htlc_transaction(this.ptr, htlc_tx, input, amount, per_commitment_point, htlc == null ? 0 : htlc.ptr & ~1); Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(this); this.ptrs_to.add(htlc); return ret_hu_conv; } - public Result_SignatureNoneZ sign_closing_transaction(Transaction closing_tx) { - long ret = bindings.ChannelKeys_sign_closing_transaction(this.ptr, closing_tx.ptr); + public Result_SignatureNoneZ sign_closing_transaction(byte[] closing_tx) { + long ret = bindings.ChannelKeys_sign_closing_transaction(this.ptr, closing_tx); Result_SignatureNoneZ ret_hu_conv = Result_SignatureNoneZ.constr_from_ptr(ret); ret_hu_conv.ptrs_to.add(this); return ret_hu_conv; diff --git a/src/main/java/org/ldk/structs/ChannelManager.java b/src/main/java/org/ldk/structs/ChannelManager.java index 10dc95a2..a2c6859f 100644 --- a/src/main/java/org/ldk/structs/ChannelManager.java +++ b/src/main/java/org/ldk/structs/ChannelManager.java @@ -131,9 +131,9 @@ public class ChannelManager extends CommonBase { return ret_hu_conv; } - public void block_connected(byte[] header, TwoTuple[] txdata, int 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 */; + public void block_connected(byte[] header, TwoTuple[] txdata, int height) { + bindings.ChannelManager_block_connected(this.ptr, header, Arrays.stream(txdata).mapToLong(arr_conv_24 -> bindings.C2Tuple_usizeTransactionZ_new(arr_conv_24.a, arr_conv_24.b)).toArray(), height); + /* TODO 2 TwoTuple */; } public void block_disconnected(byte[] header) { diff --git a/src/main/java/org/ldk/structs/ChannelMonitor.java b/src/main/java/org/ldk/structs/ChannelMonitor.java index b484c92f..5281d6d0 100644 --- a/src/main/java/org/ldk/structs/ChannelMonitor.java +++ b/src/main/java/org/ldk/structs/ChannelMonitor.java @@ -53,20 +53,14 @@ public class ChannelMonitor extends CommonBase { return arr_conv_7_arr; } - public Transaction[] get_latest_holder_commitment_txn(Logger logger) { - long[] ret = bindings.ChannelMonitor_get_latest_holder_commitment_txn(this.ptr, logger == null ? 0 : logger.ptr); - Transaction[] arr_conv_13_arr = new Transaction[ret.length]; - for (int n = 0; n < ret.length; n++) { - long arr_conv_13 = ret[n]; - Transaction arr_conv_13_conv = new Transaction(null, arr_conv_13); - arr_conv_13_arr[n] = arr_conv_13_conv; - } + public byte[][] get_latest_holder_commitment_txn(Logger logger) { + byte[][] ret = bindings.ChannelMonitor_get_latest_holder_commitment_txn(this.ptr, logger == null ? 0 : logger.ptr); this.ptrs_to.add(logger); - return arr_conv_13_arr; + return ret; } - public TwoTuple[] block_connected(byte[] header, TwoTuple[] 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 -> 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); + public TwoTuple[] block_connected(byte[] header, TwoTuple[] 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_24 -> bindings.C2Tuple_usizeTransactionZ_new(arr_conv_24.a, arr_conv_24.b)).toArray(), height, broadcaster == null ? 0 : broadcaster.ptr, fee_estimator == null ? 0 : fee_estimator.ptr, logger == null ? 0 : logger.ptr); TwoTuple[] arr_conv_27_arr = new TwoTuple[ret.length]; for (int b = 0; b < ret.length; b++) { long arr_conv_27 = ret[b]; @@ -81,7 +75,7 @@ public class ChannelMonitor extends CommonBase { TwoTuple arr_conv_27_conv = new TwoTuple(arr_conv_27_a, arr_conv_7_arr); arr_conv_27_arr[b] = arr_conv_27_conv; } - /* TODO 2 TwoTuple */; + /* TODO 2 TwoTuple */; this.ptrs_to.add(broadcaster); this.ptrs_to.add(fee_estimator); this.ptrs_to.add(logger); diff --git a/src/main/java/org/ldk/structs/HolderCommitmentTransaction.java b/src/main/java/org/ldk/structs/HolderCommitmentTransaction.java index acd07f36..713d4a40 100644 --- a/src/main/java/org/ldk/structs/HolderCommitmentTransaction.java +++ b/src/main/java/org/ldk/structs/HolderCommitmentTransaction.java @@ -21,9 +21,13 @@ public class HolderCommitmentTransaction extends CommonBase { return ret_hu_conv; } - // Skipped HolderCommitmentTransaction_get_unsigned_tx - public void set_unsigned_tx(Transaction val) { - bindings.HolderCommitmentTransaction_set_unsigned_tx(this.ptr, val.ptr); + public byte[] get_unsigned_tx() { + byte[] ret = bindings.HolderCommitmentTransaction_get_unsigned_tx(this.ptr); + return ret; + } + + public void set_unsigned_tx(byte[] val) { + bindings.HolderCommitmentTransaction_set_unsigned_tx(this.ptr, val); } public byte[] get_counterparty_sig() { @@ -49,8 +53,8 @@ public class HolderCommitmentTransaction extends CommonBase { /* TODO 2 TwoTuple */; } - public static HolderCommitmentTransaction constructor_new_missing_holder_sig(Transaction unsigned_tx, byte[] counterparty_sig, byte[] holder_funding_key, byte[] counterparty_funding_key, TxCreationKeys keys, int feerate_per_kw, TwoTuple[] htlc_data) { - long ret = bindings.HolderCommitmentTransaction_new_missing_holder_sig(unsigned_tx.ptr, counterparty_sig, holder_funding_key, counterparty_funding_key, keys == null ? 0 : keys.ptr & ~1, feerate_per_kw, Arrays.stream(htlc_data).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()); + public static HolderCommitmentTransaction constructor_new_missing_holder_sig(byte[] unsigned_tx, byte[] counterparty_sig, byte[] holder_funding_key, byte[] counterparty_funding_key, TxCreationKeys keys, int feerate_per_kw, TwoTuple[] htlc_data) { + long ret = bindings.HolderCommitmentTransaction_new_missing_holder_sig(unsigned_tx, counterparty_sig, holder_funding_key, counterparty_funding_key, keys == null ? 0 : keys.ptr & ~1, feerate_per_kw, Arrays.stream(htlc_data).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()); HolderCommitmentTransaction ret_hu_conv = new HolderCommitmentTransaction(null, ret); ret_hu_conv.ptrs_to.add(keys); /* TODO 2 TwoTuple */; diff --git a/src/main/java/org/ldk/structs/Transaction.java b/src/main/java/org/ldk/structs/Transaction.java deleted file mode 100644 index 9c90b3c0..00000000 --- a/src/main/java/org/ldk/structs/Transaction.java +++ /dev/null @@ -1,14 +0,0 @@ -package org.ldk.structs; - -import org.ldk.impl.bindings; -import org.ldk.enums.*; -import org.ldk.util.*; -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); } - public byte[] get_contents() { return bindings.txpointer_get_buffer(ptr); } -} \ No newline at end of file diff --git a/src/main/jni/bindings.c b/src/main/jni/bindings.c index d3a83a6b..77a75f1f 100644 --- a/src/main/jni/bindings.c +++ b/src/main/jni/bindings.c @@ -471,23 +471,27 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1u8_1new(JNIEnv } return (long)ret; } -JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1usize_1_1Transaction_1new(JNIEnv *_env, jclass _b, jlong a, jlong b) { +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1usize_1_1Transaction_1new(JNIEnv *_env, jclass _b, jlong a, jbyteArray b) { LDKC2TupleTempl_usize__Transaction* ret = MALLOC(sizeof(LDKC2TupleTempl_usize__Transaction), "LDKC2TupleTempl_usize__Transaction"); ret->a = a; - LDKTransaction b_conv = *(LDKTransaction*)b; - ret->b = b_conv; + LDKTransaction b_ref; + b_ref.datalen = (*_env)->GetArrayLength (_env, b); + b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes"); + (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data); + b_ref.data_is_owned = false; + ret->b = b_ref; return (long)ret; } JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) { LDKC2TupleTempl_usize__Transaction *tuple = (LDKC2TupleTempl_usize__Transaction*)ptr; return tuple->a; } -JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) { +JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1b(JNIEnv *_env, jclass _b, jlong ptr) { LDKC2TupleTempl_usize__Transaction *tuple = (LDKC2TupleTempl_usize__Transaction*)ptr; - LDKTransaction *b_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction"); - *b_copy = tuple->b; - long b_ref = (long)b_copy; - return b_ref; + LDKTransaction b_var = tuple->b; + jbyteArray b_arr = (*_env)->NewByteArray(_env, b_var.datalen); + (*_env)->SetByteArrayRegion(_env, b_arr, 0, b_var.datalen, b_var.data); + return b_arr; } JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKCResult_1NoneChannelMonitorUpdateErrZ_1result_1ok (JNIEnv * env, jclass _a, jlong arg) { return ((LDKCResult_NoneChannelMonitorUpdateErrZ*)arg)->result_ok; @@ -529,10 +533,10 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1OutPoint_1_1 a_conv = OutPoint_clone(&a_conv); ret->a = a_conv; LDKCVec_u8Z b_ref; - b_ref.data = (*_env)->GetByteArrayElements (_env, b, NULL); b_ref.datalen = (*_env)->GetArrayLength (_env, b); + b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes"); + (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data); ret->b = b_ref; - //TODO: Really need to call (*_env)->ReleaseByteArrayElements(_env, b, (int8_t*)b_ref.data, 0); here return (long)ret; } JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1OutPointScriptZ_1get_1a(JNIEnv *_env, jclass _b, jlong ptr) { @@ -1887,9 +1891,10 @@ 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); - LDKTransaction *commitment_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction"); - *commitment_tx_copy = commitment_tx; - long commitment_tx_ref = (long)commitment_tx_copy; + LDKTransaction commitment_tx_var = commitment_tx; + jbyteArray commitment_tx_arr = (*_env)->NewByteArray(_env, commitment_tx_var.datalen); + (*_env)->SetByteArrayRegion(_env, commitment_tx_arr, 0, commitment_tx_var.datalen, commitment_tx_var.data); + Transaction_free(commitment_tx_var); LDKPreCalculatedTxCreationKeys keys_var = *keys; if (keys->inner != NULL) keys_var = PreCalculatedTxCreationKeys_clone(keys); @@ -1913,7 +1918,7 @@ LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ sign_counterparty_commitment_j FREE(htlcs_var.data); jobject obj = (*_env)->NewLocalRef(_env, j_calls->o); CHECK(obj != NULL); - LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_counterparty_commitment_meth, feerate_per_kw, commitment_tx_ref, keys_ref, htlcs_arr); + LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret = (LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_counterparty_commitment_meth, feerate_per_kw, commitment_tx_arr, keys_ref, htlcs_arr); LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ ret_conv = *(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ*)ret; FREE((void*)ret); return ret_conv; @@ -1956,9 +1961,10 @@ 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); - LDKTransaction *justice_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction"); - *justice_tx_copy = justice_tx; - long justice_tx_ref = (long)justice_tx_copy; + LDKTransaction justice_tx_var = justice_tx; + jbyteArray justice_tx_arr = (*_env)->NewByteArray(_env, justice_tx_var.datalen); + (*_env)->SetByteArrayRegion(_env, justice_tx_arr, 0, justice_tx_var.datalen, justice_tx_var.data); + Transaction_free(justice_tx_var); jbyteArray per_commitment_key_arr = (*_env)->NewByteArray(_env, 32); (*_env)->SetByteArrayRegion(_env, per_commitment_key_arr, 0, 32, *per_commitment_key); LDKHTLCOutputInCommitment htlc_var = *htlc; @@ -1969,7 +1975,7 @@ LDKCResult_SignatureNoneZ sign_justice_transaction_jcall(const void* this_arg, L long htlc_ref = (long)htlc_var.inner & ~1; jobject obj = (*_env)->NewLocalRef(_env, j_calls->o); CHECK(obj != NULL); - LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_justice_transaction_meth, justice_tx_ref, input, amount, per_commitment_key_arr, htlc_ref); + LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_justice_transaction_meth, justice_tx_arr, input, amount, per_commitment_key_arr, htlc_ref); LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret; FREE((void*)ret); return ret_conv; @@ -1978,9 +1984,10 @@ 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); - LDKTransaction *htlc_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction"); - *htlc_tx_copy = htlc_tx; - long htlc_tx_ref = (long)htlc_tx_copy; + LDKTransaction htlc_tx_var = htlc_tx; + jbyteArray htlc_tx_arr = (*_env)->NewByteArray(_env, htlc_tx_var.datalen); + (*_env)->SetByteArrayRegion(_env, htlc_tx_arr, 0, htlc_tx_var.datalen, htlc_tx_var.data); + Transaction_free(htlc_tx_var); jbyteArray per_commitment_point_arr = (*_env)->NewByteArray(_env, 33); (*_env)->SetByteArrayRegion(_env, per_commitment_point_arr, 0, 33, per_commitment_point.compressed_form); LDKHTLCOutputInCommitment htlc_var = *htlc; @@ -1991,7 +1998,7 @@ LDKCResult_SignatureNoneZ sign_counterparty_htlc_transaction_jcall(const void* t long htlc_ref = (long)htlc_var.inner & ~1; jobject obj = (*_env)->NewLocalRef(_env, j_calls->o); CHECK(obj != NULL); - LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_counterparty_htlc_transaction_meth, htlc_tx_ref, input, amount, per_commitment_point_arr, htlc_ref); + LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_counterparty_htlc_transaction_meth, htlc_tx_arr, input, amount, per_commitment_point_arr, htlc_ref); LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret; FREE((void*)ret); return ret_conv; @@ -2000,12 +2007,13 @@ 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); - LDKTransaction *closing_tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction"); - *closing_tx_copy = closing_tx; - long closing_tx_ref = (long)closing_tx_copy; + LDKTransaction closing_tx_var = closing_tx; + jbyteArray closing_tx_arr = (*_env)->NewByteArray(_env, closing_tx_var.datalen); + (*_env)->SetByteArrayRegion(_env, closing_tx_arr, 0, closing_tx_var.datalen, closing_tx_var.data); + Transaction_free(closing_tx_var); 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); + LDKCResult_SignatureNoneZ* ret = (LDKCResult_SignatureNoneZ*)(*_env)->CallLongMethod(_env, obj, j_calls->sign_closing_transaction_meth, closing_tx_arr); LDKCResult_SignatureNoneZ ret_conv = *(LDKCResult_SignatureNoneZ*)ret; FREE((void*)ret); return ret_conv; @@ -2068,17 +2076,17 @@ static inline LDKChannelKeys LDKChannelKeys_init (JNIEnv * env, jclass _a, jobje CHECK(calls->release_commitment_secret_meth != NULL); calls->key_derivation_params_meth = (*env)->GetMethodID(env, c, "key_derivation_params", "()J"); CHECK(calls->key_derivation_params_meth != NULL); - calls->sign_counterparty_commitment_meth = (*env)->GetMethodID(env, c, "sign_counterparty_commitment", "(IJJ[J)J"); + calls->sign_counterparty_commitment_meth = (*env)->GetMethodID(env, c, "sign_counterparty_commitment", "(I[BJ[J)J"); CHECK(calls->sign_counterparty_commitment_meth != NULL); calls->sign_holder_commitment_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment", "(J)J"); CHECK(calls->sign_holder_commitment_meth != NULL); calls->sign_holder_commitment_htlc_transactions_meth = (*env)->GetMethodID(env, c, "sign_holder_commitment_htlc_transactions", "(J)J"); CHECK(calls->sign_holder_commitment_htlc_transactions_meth != NULL); - calls->sign_justice_transaction_meth = (*env)->GetMethodID(env, c, "sign_justice_transaction", "(JJJ[BJ)J"); + calls->sign_justice_transaction_meth = (*env)->GetMethodID(env, c, "sign_justice_transaction", "([BJJ[BJ)J"); CHECK(calls->sign_justice_transaction_meth != NULL); - calls->sign_counterparty_htlc_transaction_meth = (*env)->GetMethodID(env, c, "sign_counterparty_htlc_transaction", "(JJJ[BJ)J"); + calls->sign_counterparty_htlc_transaction_meth = (*env)->GetMethodID(env, c, "sign_counterparty_htlc_transaction", "([BJJ[BJ)J"); CHECK(calls->sign_counterparty_htlc_transaction_meth != NULL); - calls->sign_closing_transaction_meth = (*env)->GetMethodID(env, c, "sign_closing_transaction", "(J)J"); + calls->sign_closing_transaction_meth = (*env)->GetMethodID(env, c, "sign_closing_transaction", "([B)J"); CHECK(calls->sign_closing_transaction_meth != NULL); calls->sign_channel_announcement_meth = (*env)->GetMethodID(env, c, "sign_channel_announcement", "(J)J"); CHECK(calls->sign_channel_announcement_meth != NULL); @@ -2142,9 +2150,13 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1key_1derivation_ return (long)ret_ref; } -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) { +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jint feerate_per_kw, jbyteArray commitment_tx, jlong keys, jlongArray htlcs) { LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg; - LDKTransaction commitment_tx_conv = *(LDKTransaction*)commitment_tx; + LDKTransaction commitment_tx_ref; + commitment_tx_ref.datalen = (*_env)->GetArrayLength (_env, commitment_tx); + commitment_tx_ref.data = MALLOC(commitment_tx_ref.datalen, "LDKTransaction Bytes"); + (*_env)->GetByteArrayRegion(_env, commitment_tx, 0, commitment_tx_ref.datalen, commitment_tx_ref.data); + commitment_tx_ref.data_is_owned = true; LDKPreCalculatedTxCreationKeys keys_conv; keys_conv.inner = (void*)(keys & (~1)); keys_conv.is_owned = false; @@ -2166,7 +2178,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterpar } (*_env)->ReleaseLongArrayElements (_env, htlcs, htlcs_vals, 0); LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ"); - *ret_conv = (this_arg_conv->sign_counterparty_commitment)(this_arg_conv->this_arg, feerate_per_kw, commitment_tx_conv, &keys_conv, htlcs_constr); + *ret_conv = (this_arg_conv->sign_counterparty_commitment)(this_arg_conv->this_arg, feerate_per_kw, commitment_tx_ref, &keys_conv, htlcs_constr); return (long)ret_conv; } @@ -2190,9 +2202,13 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1co return (long)ret_conv; } -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) { +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1justice_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray 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; + LDKTransaction justice_tx_ref; + justice_tx_ref.datalen = (*_env)->GetArrayLength (_env, justice_tx); + justice_tx_ref.data = MALLOC(justice_tx_ref.datalen, "LDKTransaction Bytes"); + (*_env)->GetByteArrayRegion(_env, justice_tx, 0, justice_tx_ref.datalen, justice_tx_ref.data); + justice_tx_ref.data_is_owned = true; 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); @@ -2201,13 +2217,17 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1justice_1t htlc_conv.inner = (void*)(htlc & (~1)); htlc_conv.is_owned = false; LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ"); - *ret_conv = (this_arg_conv->sign_justice_transaction)(this_arg_conv->this_arg, justice_tx_conv, input, amount, per_commitment_key_ref, &htlc_conv); + *ret_conv = (this_arg_conv->sign_justice_transaction)(this_arg_conv->this_arg, justice_tx_ref, input, amount, per_commitment_key_ref, &htlc_conv); return (long)ret_conv; } -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) { +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1htlc_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray 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; + LDKTransaction htlc_tx_ref; + htlc_tx_ref.datalen = (*_env)->GetArrayLength (_env, htlc_tx); + htlc_tx_ref.data = MALLOC(htlc_tx_ref.datalen, "LDKTransaction Bytes"); + (*_env)->GetByteArrayRegion(_env, htlc_tx, 0, htlc_tx_ref.datalen, htlc_tx_ref.data); + htlc_tx_ref.data_is_owned = true; 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); @@ -2215,15 +2235,19 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterpar htlc_conv.inner = (void*)(htlc & (~1)); htlc_conv.is_owned = false; LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ"); - *ret_conv = (this_arg_conv->sign_counterparty_htlc_transaction)(this_arg_conv->this_arg, htlc_tx_conv, input, amount, per_commitment_point_ref, &htlc_conv); + *ret_conv = (this_arg_conv->sign_counterparty_htlc_transaction)(this_arg_conv->this_arg, htlc_tx_ref, input, amount, per_commitment_point_ref, &htlc_conv); return (long)ret_conv; } -JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1closing_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong closing_tx) { +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1closing_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray closing_tx) { LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg; - LDKTransaction closing_tx_conv = *(LDKTransaction*)closing_tx; + LDKTransaction closing_tx_ref; + closing_tx_ref.datalen = (*_env)->GetArrayLength (_env, closing_tx); + closing_tx_ref.data = MALLOC(closing_tx_ref.datalen, "LDKTransaction Bytes"); + (*_env)->GetByteArrayRegion(_env, closing_tx, 0, closing_tx_ref.datalen, closing_tx_ref.data); + closing_tx_ref.data_is_owned = true; LDKCResult_SignatureNoneZ* ret_conv = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ"); - *ret_conv = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_conv); + *ret_conv = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_ref); return (long)ret_conv; } @@ -2566,8 +2590,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1register_1tx(JNIEnv * (*_env)->GetByteArrayRegion (_env, txid, 0, 32, txid_arr); unsigned char (*txid_ref)[32] = &txid_arr; LDKu8slice script_pubkey_ref; - script_pubkey_ref.data = (*_env)->GetByteArrayElements (_env, script_pubkey, NULL); script_pubkey_ref.datalen = (*_env)->GetArrayLength (_env, script_pubkey); + script_pubkey_ref.data = (*_env)->GetByteArrayElements (_env, script_pubkey, NULL); (this_arg_conv->register_tx)(this_arg_conv->this_arg, txid_ref, script_pubkey_ref); (*_env)->ReleaseByteArrayElements(_env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0); } @@ -2578,8 +2602,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1register_1output(JNIEn outpoint_conv.inner = (void*)(outpoint & (~1)); outpoint_conv.is_owned = false; LDKu8slice script_pubkey_ref; - script_pubkey_ref.data = (*_env)->GetByteArrayElements (_env, script_pubkey, NULL); script_pubkey_ref.datalen = (*_env)->GetArrayLength (_env, script_pubkey); + script_pubkey_ref.data = (*_env)->GetByteArrayElements (_env, script_pubkey, NULL); (this_arg_conv->register_output)(this_arg_conv->this_arg, &outpoint_conv, script_pubkey_ref); (*_env)->ReleaseByteArrayElements(_env, script_pubkey, (int8_t*)script_pubkey_ref.data, 0); } @@ -2594,12 +2618,13 @@ 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); - LDKTransaction *tx_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction"); - *tx_copy = tx; - long tx_ref = (long)tx_copy; + LDKTransaction tx_var = tx; + jbyteArray tx_arr = (*_env)->NewByteArray(_env, tx_var.datalen); + (*_env)->SetByteArrayRegion(_env, tx_arr, 0, tx_var.datalen, tx_var.data); + Transaction_free(tx_var); jobject obj = (*_env)->NewLocalRef(_env, j_calls->o); CHECK(obj != NULL); - return (*_env)->CallVoidMethod(_env, obj, j_calls->broadcast_transaction_meth, tx_ref); + return (*_env)->CallVoidMethod(_env, obj, j_calls->broadcast_transaction_meth, tx_arr); } static void LDKBroadcasterInterface_JCalls_free(void* this_arg) { LDKBroadcasterInterface_JCalls *j_calls = (LDKBroadcasterInterface_JCalls*) this_arg; @@ -2622,7 +2647,7 @@ static inline LDKBroadcasterInterface LDKBroadcasterInterface_init (JNIEnv * env atomic_init(&calls->refcnt, 1); DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0); calls->o = (*env)->NewWeakGlobalRef(env, o); - calls->broadcast_transaction_meth = (*env)->GetMethodID(env, c, "broadcast_transaction", "(J)V"); + calls->broadcast_transaction_meth = (*env)->GetMethodID(env, c, "broadcast_transaction", "([B)V"); CHECK(calls->broadcast_transaction_meth != NULL); LDKBroadcasterInterface ret = { @@ -2642,10 +2667,14 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1ge CHECK(ret != NULL); return ret; } -JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1broadcast_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong tx) { +JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1broadcast_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray tx) { LDKBroadcasterInterface* this_arg_conv = (LDKBroadcasterInterface*)this_arg; - LDKTransaction tx_conv = *(LDKTransaction*)tx; - (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_conv); + LDKTransaction tx_ref; + tx_ref.datalen = (*_env)->GetArrayLength (_env, tx); + tx_ref.data = MALLOC(tx_ref.datalen, "LDKTransaction Bytes"); + (*_env)->GetByteArrayRegion(_env, tx, 0, tx_ref.datalen, tx_ref.data); + tx_ref.data_is_owned = true; + (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_ref); } typedef struct LDKFeeEstimator_JCalls { @@ -2737,23 +2766,6 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Transaction_1 LDKCVecTempl_Transaction *vec = (LDKCVecTempl_Transaction*)ptr; return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKTransaction)); } -JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Transaction_1new(JNIEnv *env, jclass _b, jlongArray elems){ - LDKCVecTempl_Transaction *ret = MALLOC(sizeof(LDKCVecTempl_Transaction), "LDKCVecTempl_Transaction"); - ret->datalen = (*env)->GetArrayLength(env, elems); - if (ret->datalen == 0) { - ret->data = NULL; - } else { - ret->data = MALLOC(sizeof(LDKTransaction) * ret->datalen, "LDKCVecTempl_Transaction Data"); - jlong *java_elems = (*env)->GetPrimitiveArrayCritical(env, elems, NULL); - for (size_t i = 0; i < ret->datalen; i++) { - jlong arr_elem = java_elems[i]; - LDKTransaction arr_elem_conv = *(LDKTransaction*)arr_elem; - ret->data[i] = arr_elem_conv; - } - (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0); - } - return (long)ret; -} JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1ThirtyTwoBytes_1_1CVecTempl_1TxOut_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) { LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut *vec = (LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut*)ptr; return (*env)->NewObject(env, slicedef_cls, slicedef_meth, (long)vec->data, (long)vec->datalen, sizeof(LDKC2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut)); @@ -2806,8 +2818,9 @@ LDKCVec_u8Z get_destination_script_jcall(const void* this_arg) { CHECK(obj != NULL); jbyteArray arg = (*_env)->CallObjectMethod(_env, obj, j_calls->get_destination_script_meth); LDKCVec_u8Z arg_ref; - arg_ref.data = (*_env)->GetByteArrayElements (_env, arg, NULL); arg_ref.datalen = (*_env)->GetArrayLength (_env, arg); + arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes"); + (*_env)->GetByteArrayRegion(_env, arg, 0, arg_ref.datalen, arg_ref.data); return arg_ref; } LDKPublicKey get_shutdown_pubkey_jcall(const void* this_arg) { @@ -4319,8 +4332,8 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1get_1o JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1send_1data(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray data, jboolean resume_read) { LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg; LDKu8slice data_ref; - data_ref.data = (*_env)->GetByteArrayElements (_env, data, NULL); data_ref.datalen = (*_env)->GetArrayLength (_env, data); + data_ref.data = (*_env)->GetByteArrayElements (_env, data, NULL); jlong ret_val = (this_arg_conv->send_data)(this_arg_conv->this_arg, data_ref, resume_read); (*_env)->ReleaseByteArrayElements(_env, data, (int8_t*)data_ref.data, 0); return ret_val; @@ -4636,11 +4649,11 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleEr JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1CVec_1u8ZPeerHandleErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray arg) { LDKCVec_u8Z arg_ref; - arg_ref.data = (*_env)->GetByteArrayElements (_env, arg, NULL); arg_ref.datalen = (*_env)->GetArrayLength (_env, arg); + arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes"); + (*_env)->GetByteArrayRegion(_env, arg, 0, arg_ref.datalen, arg_ref.data); LDKCResult_CVec_u8ZPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_CVec_u8ZPeerHandleErrorZ), "LDKCResult_CVec_u8ZPeerHandleErrorZ"); *ret_conv = CResult_CVec_u8ZPeerHandleErrorZ_ok(arg_ref); - (*_env)->ReleaseByteArrayElements(_env, arg, (int8_t*)arg_ref.data, 0); return (long)ret_conv; } @@ -4925,11 +4938,11 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1C2Tuple_1usizeTransactio else arg_constr.data = NULL; long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL); - for (size_t d = 0; d < arg_constr.datalen; d++) { - long arr_conv_29 = arg_vals[d]; - LDKC2Tuple_usizeTransactionZ arr_conv_29_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_29; - FREE((void*)arr_conv_29); - arg_constr.data[d] = arr_conv_29_conv; + for (size_t y = 0; y < arg_constr.datalen; y++) { + long arr_conv_24 = arg_vals[y]; + LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24; + FREE((void*)arr_conv_24); + arg_constr.data[y] = arr_conv_24_conv; } (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0); CVec_C2Tuple_usizeTransactionZZ_free(arg_constr); @@ -5221,20 +5234,22 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SpendableOutputDescripto CVec_SpendableOutputDescriptorZ_free(arg_constr); } -JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TransactionZ_1free(JNIEnv * _env, jclass _b, jlongArray arg) { +JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TransactionZ_1free(JNIEnv * _env, jclass _b, jobjectArray arg) { LDKCVec_TransactionZ arg_constr; arg_constr.datalen = (*_env)->GetArrayLength (_env, arg); if (arg_constr.datalen > 0) arg_constr.data = MALLOC(arg_constr.datalen * sizeof(LDKTransaction), "LDKCVec_TransactionZ Elements"); else arg_constr.data = NULL; - long* arg_vals = (*_env)->GetLongArrayElements (_env, arg, NULL); - 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; - arg_constr.data[n] = arr_conv_13_conv; + for (size_t i = 0; i < arg_constr.datalen; i++) { + jobject arr_conv_8 = (*_env)->GetObjectArrayElement(_env, arg, i); + LDKTransaction arr_conv_8_ref; + arr_conv_8_ref.datalen = (*_env)->GetArrayLength (_env, arr_conv_8); + arr_conv_8_ref.data = MALLOC(arr_conv_8_ref.datalen, "LDKTransaction Bytes"); + (*_env)->GetByteArrayRegion(_env, arr_conv_8, 0, arr_conv_8_ref.datalen, arr_conv_8_ref.data); + arr_conv_8_ref.data_is_owned = true; + arg_constr.data[i] = arr_conv_8_ref; } - (*_env)->ReleaseLongArrayElements (_env, arg, arg_vals, 0); CVec_TransactionZ_free(arg_constr); } @@ -5350,15 +5365,19 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u64Z_1free(JNIEnv * _env JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u8Z_1free(JNIEnv * _env, jclass _b, jbyteArray arg) { LDKCVec_u8Z arg_ref; - arg_ref.data = (*_env)->GetByteArrayElements (_env, arg, NULL); arg_ref.datalen = (*_env)->GetArrayLength (_env, arg); + arg_ref.data = MALLOC(arg_ref.datalen, "LDKCVec_u8Z Bytes"); + (*_env)->GetByteArrayRegion(_env, arg, 0, arg_ref.datalen, arg_ref.data); CVec_u8Z_free(arg_ref); - (*_env)->ReleaseByteArrayElements(_env, arg, (int8_t*)arg_ref.data, 0); } -JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Transaction_1free(JNIEnv * _env, jclass _b, jlong _res) { - LDKTransaction _res_conv = *(LDKTransaction*)_res; - Transaction_free(_res_conv); +JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Transaction_1free(JNIEnv * _env, jclass _b, jbyteArray _res) { + LDKTransaction _res_ref; + _res_ref.datalen = (*_env)->GetArrayLength (_env, _res); + _res_ref.data = MALLOC(_res_ref.datalen, "LDKTransaction Bytes"); + (*_env)->GetByteArrayRegion(_env, _res, 0, _res_ref.datalen, _res_ref.data); + _res_ref.data_is_owned = true; + Transaction_free(_res_ref); } JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxOut_1free(JNIEnv * _env, jclass _b, jlong _res) { @@ -5367,10 +5386,14 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxOut_1free(JNIEnv * _env, jcl TxOut_free(_res_conv); } -JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1new(JNIEnv * _env, jclass _b, jlong a, jlong b) { - LDKTransaction b_conv = *(LDKTransaction*)b; +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1new(JNIEnv * _env, jclass _b, jlong a, jbyteArray b) { + LDKTransaction b_ref; + b_ref.datalen = (*_env)->GetArrayLength (_env, b); + b_ref.data = MALLOC(b_ref.datalen, "LDKTransaction Bytes"); + (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data); + b_ref.data_is_owned = true; LDKC2Tuple_usizeTransactionZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_usizeTransactionZ), "LDKC2Tuple_usizeTransactionZ"); - *ret_ref = C2Tuple_usizeTransactionZ_new(a, b_conv); + *ret_ref = C2Tuple_usizeTransactionZ_new(a, b_ref); return (long)ret_ref; } @@ -5393,11 +5416,11 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1new if (a_conv.inner != NULL) a_conv = OutPoint_clone(&a_conv); LDKCVec_u8Z b_ref; - b_ref.data = (*_env)->GetByteArrayElements (_env, b, NULL); b_ref.datalen = (*_env)->GetArrayLength (_env, b); + b_ref.data = MALLOC(b_ref.datalen, "LDKCVec_u8Z Bytes"); + (*_env)->GetByteArrayRegion(_env, b, 0, b_ref.datalen, b_ref.data); LDKC2Tuple_OutPointScriptZ* ret_ref = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ"); *ret_ref = C2Tuple_OutPointScriptZ_new(a_conv, b_ref); - (*_env)->ReleaseByteArrayElements(_env, b, (int8_t*)b_ref.data, 0); return (long)ret_ref; } @@ -5976,8 +5999,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1write(JNI JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelConfig_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKChannelConfig ret_var = ChannelConfig_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -6189,11 +6212,11 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChainMonitor_1block_1connected else txdata_constr.data = NULL; long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL); - for (size_t d = 0; d < txdata_constr.datalen; d++) { - long arr_conv_29 = txdata_vals[d]; - LDKC2Tuple_usizeTransactionZ arr_conv_29_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_29; - FREE((void*)arr_conv_29); - txdata_constr.data[d] = arr_conv_29_conv; + for (size_t y = 0; y < txdata_constr.datalen; y++) { + long arr_conv_24 = txdata_vals[y]; + LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24; + FREE((void*)arr_conv_24); + txdata_constr.data[y] = arr_conv_24_conv; } (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0); ChainMonitor_block_connected(&this_arg_conv, header_ref, txdata_constr, height); @@ -6304,8 +6327,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1wr JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitorUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKChannelMonitorUpdate ret_var = ChannelMonitorUpdate_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -6385,8 +6408,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1write(JNIEnv JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKHTLCUpdate ret_var = HTLCUpdate_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -6478,21 +6501,20 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and return ret_arr; } -JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1holder_1commitment_1txn(JNIEnv * _env, jclass _b, jlong this_arg, jlong logger) { +JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1holder_1commitment_1txn(JNIEnv * _env, jclass _b, jlong this_arg, jlong logger) { LDKChannelMonitor this_arg_conv; this_arg_conv.inner = (void*)(this_arg & (~1)); this_arg_conv.is_owned = false; LDKLogger* logger_conv = (LDKLogger*)logger; LDKCVec_TransactionZ ret_var = ChannelMonitor_get_latest_holder_commitment_txn(&this_arg_conv, logger_conv); - 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++) { - 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; + jobjectArray ret_arr = (*_env)->NewObjectArray(_env, ret_var.datalen, arr_of_B_clz, NULL); + for (size_t i = 0; i < ret_var.datalen; i++) { + LDKTransaction arr_conv_8_var = ret_var.data[i]; + jbyteArray arr_conv_8_arr = (*_env)->NewByteArray(_env, arr_conv_8_var.datalen); + (*_env)->SetByteArrayRegion(_env, arr_conv_8_arr, 0, arr_conv_8_var.datalen, arr_conv_8_var.data); + Transaction_free(arr_conv_8_var); + (*_env)->SetObjectArrayElement(_env, ret_arr, i, arr_conv_8_arr); } - (*_env)->ReleasePrimitiveArrayCritical(_env, ret_arr, ret_arr_ptr, 0); CVec_TransactionZ_free(ret_var); return ret_arr; } @@ -6512,11 +6534,11 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1block_1c else txdata_constr.data = NULL; long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL); - for (size_t d = 0; d < txdata_constr.datalen; d++) { - long arr_conv_29 = txdata_vals[d]; - LDKC2Tuple_usizeTransactionZ arr_conv_29_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_29; - FREE((void*)arr_conv_29); - txdata_constr.data[d] = arr_conv_29_conv; + for (size_t y = 0; y < txdata_constr.datalen; y++) { + long arr_conv_24 = txdata_vals[y]; + LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24; + FREE((void*)arr_conv_24); + txdata_constr.data[y] = arr_conv_24_conv; } (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0); LDKBroadcasterInterface broadcaster_conv = *(LDKBroadcasterInterface*)broadcaster; @@ -6664,8 +6686,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OutPoint_1write(JNIEnv * JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OutPoint_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKOutPoint ret_var = OutPoint_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -6921,8 +6943,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1wri JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKInMemoryChannelKeys ret_var = InMemoryChannelKeys_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -7443,11 +7465,11 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1block_1connect else txdata_constr.data = NULL; long* txdata_vals = (*_env)->GetLongArrayElements (_env, txdata, NULL); - for (size_t d = 0; d < txdata_constr.datalen; d++) { - long arr_conv_29 = txdata_vals[d]; - LDKC2Tuple_usizeTransactionZ arr_conv_29_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_29; - FREE((void*)arr_conv_29); - txdata_constr.data[d] = arr_conv_29_conv; + for (size_t y = 0; y < txdata_constr.datalen; y++) { + long arr_conv_24 = txdata_vals[y]; + LDKC2Tuple_usizeTransactionZ arr_conv_24_conv = *(LDKC2Tuple_usizeTransactionZ*)arr_conv_24; + FREE((void*)arr_conv_24); + txdata_constr.data[y] = arr_conv_24_conv; } (*_env)->ReleaseLongArrayElements (_env, txdata, txdata_vals, 0); ChannelManager_block_connected(&this_arg_conv, header_ref, txdata_constr, height); @@ -7748,10 +7770,10 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1set_1data(JNIEnv this_ptr_conv.inner = (void*)(this_ptr & (~1)); this_ptr_conv.is_owned = false; LDKCVec_u8Z val_ref; - val_ref.data = (*_env)->GetByteArrayElements (_env, val, NULL); val_ref.datalen = (*_env)->GetArrayLength (_env, val); + val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes"); + (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data); ErrorMessage_set_data(&this_ptr_conv, val_ref); - (*_env)->ReleaseByteArrayElements(_env, val, (int8_t*)val_ref.data, 0); } JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray data_arg) { @@ -7759,8 +7781,9 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1new(JNIEnv * _e CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32); (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data); LDKCVec_u8Z data_arg_ref; - data_arg_ref.data = (*_env)->GetByteArrayElements (_env, data_arg, NULL); data_arg_ref.datalen = (*_env)->GetArrayLength (_env, data_arg); + data_arg_ref.data = MALLOC(data_arg_ref.datalen, "LDKCVec_u8Z Bytes"); + (*_env)->GetByteArrayRegion(_env, data_arg, 0, data_arg_ref.datalen, data_arg_ref.data); LDKErrorMessage ret_var = ErrorMessage_new(channel_id_arg_ref, data_arg_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -7768,7 +7791,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1new(JNIEnv * _e if (ret_var.is_owned) { ret_ref |= 1; } - (*_env)->ReleaseByteArrayElements(_env, data_arg, (int8_t*)data_arg_ref.data, 0); return ret_ref; } @@ -8783,10 +8805,10 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Shutdown_1set_1scriptpubkey(JN this_ptr_conv.inner = (void*)(this_ptr & (~1)); this_ptr_conv.is_owned = false; LDKCVec_u8Z val_ref; - val_ref.data = (*_env)->GetByteArrayElements (_env, val, NULL); val_ref.datalen = (*_env)->GetArrayLength (_env, val); + val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes"); + (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data); Shutdown_set_scriptpubkey(&this_ptr_conv, val_ref); - (*_env)->ReleaseByteArrayElements(_env, val, (int8_t*)val_ref.data, 0); } JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1new(JNIEnv * _env, jclass _b, jbyteArray channel_id_arg, jbyteArray scriptpubkey_arg) { @@ -8794,8 +8816,9 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1new(JNIEnv * _env, CHECK((*_env)->GetArrayLength (_env, channel_id_arg) == 32); (*_env)->GetByteArrayRegion (_env, channel_id_arg, 0, 32, channel_id_arg_ref.data); LDKCVec_u8Z scriptpubkey_arg_ref; - scriptpubkey_arg_ref.data = (*_env)->GetByteArrayElements (_env, scriptpubkey_arg, NULL); scriptpubkey_arg_ref.datalen = (*_env)->GetArrayLength (_env, scriptpubkey_arg); + scriptpubkey_arg_ref.data = MALLOC(scriptpubkey_arg_ref.datalen, "LDKCVec_u8Z Bytes"); + (*_env)->GetByteArrayRegion(_env, scriptpubkey_arg, 0, scriptpubkey_arg_ref.datalen, scriptpubkey_arg_ref.data); LDKShutdown ret_var = Shutdown_new(channel_id_arg_ref, scriptpubkey_arg_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -8803,7 +8826,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1new(JNIEnv * _env, if (ret_var.is_owned) { ret_ref |= 1; } - (*_env)->ReleaseByteArrayElements(_env, scriptpubkey_arg, (int8_t*)scriptpubkey_arg_ref.data, 0); return ret_ref; } @@ -11019,10 +11041,10 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1err(JNIEn this_ptr_conv.inner = (void*)(this_ptr & (~1)); this_ptr_conv.is_owned = false; LDKCVec_u8Z val_ref; - val_ref.data = (*_env)->GetByteArrayElements (_env, val, NULL); val_ref.datalen = (*_env)->GetArrayLength (_env, val); + val_ref.data = MALLOC(val_ref.datalen, "LDKCVec_u8Z Bytes"); + (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data); LightningError_set_err(&this_ptr_conv, val_ref); - (*_env)->ReleaseByteArrayElements(_env, val, (int8_t*)val_ref.data, 0); } JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LightningError_1get_1action(JNIEnv * _env, jclass _b, jlong this_ptr) { @@ -11046,8 +11068,9 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LightningError_1set_1action(JN JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LightningError_1new(JNIEnv * _env, jclass _b, jbyteArray err_arg, jlong action_arg) { LDKCVec_u8Z err_arg_ref; - err_arg_ref.data = (*_env)->GetByteArrayElements (_env, err_arg, NULL); err_arg_ref.datalen = (*_env)->GetArrayLength (_env, err_arg); + err_arg_ref.data = MALLOC(err_arg_ref.datalen, "LDKCVec_u8Z Bytes"); + (*_env)->GetByteArrayRegion(_env, err_arg, 0, err_arg_ref.datalen, err_arg_ref.data); LDKErrorAction action_arg_conv = *(LDKErrorAction*)action_arg; FREE((void*)action_arg); LDKLightningError ret_var = LightningError_new(err_arg_ref, action_arg_conv); @@ -11057,7 +11080,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LightningError_1new(JNIEnv * if (ret_var.is_owned) { ret_ref |= 1; } - (*_env)->ReleaseByteArrayElements(_env, err_arg, (int8_t*)err_arg_ref.data, 0); return ret_ref; } @@ -11358,8 +11380,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1write(JNI JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AcceptChannel_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKAcceptChannel ret_var = AcceptChannel_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11384,8 +11406,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_AnnouncementSignatures_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKAnnouncementSignatures ret_var = AnnouncementSignatures_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11410,8 +11432,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1writ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelReestablish_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKChannelReestablish ret_var = ChannelReestablish_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11436,8 +11458,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1write(JNI JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ClosingSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKClosingSigned ret_var = ClosingSigned_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11462,8 +11484,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1write( JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKCommitmentSigned ret_var = CommitmentSigned_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11488,8 +11510,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingCreated_1write(JN JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingCreated_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKFundingCreated ret_var = FundingCreated_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11514,8 +11536,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingSigned_1write(JNI JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingSigned_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKFundingSigned ret_var = FundingSigned_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11540,8 +11562,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_FundingLocked_1write(JNI JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_FundingLocked_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKFundingLocked ret_var = FundingLocked_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11566,8 +11588,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Init_1write(JNIEnv * _en JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Init_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKInit ret_var = Init_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11592,8 +11614,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_OpenChannel_1write(JNIEn JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_OpenChannel_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKOpenChannel ret_var = OpenChannel_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11618,8 +11640,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1write(JNIE JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RevokeAndACK_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKRevokeAndACK ret_var = RevokeAndACK_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11644,8 +11666,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Shutdown_1write(JNIEnv * JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Shutdown_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKShutdown ret_var = Shutdown_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11670,8 +11692,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1write(JN JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKUpdateFailHTLC ret_var = UpdateFailHTLC_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11696,8 +11718,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFailMalformedHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKUpdateFailMalformedHTLC ret_var = UpdateFailMalformedHTLC_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11722,8 +11744,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFee_1write(JNIEnv JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFee_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKUpdateFee ret_var = UpdateFee_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11748,8 +11770,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1write JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateFulfillHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKUpdateFulfillHTLC ret_var = UpdateFulfillHTLC_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11774,8 +11796,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1write(JNI JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UpdateAddHTLC_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKUpdateAddHTLC ret_var = UpdateAddHTLC_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11800,8 +11822,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Ping_1write(JNIEnv * _en JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Ping_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKPing ret_var = Ping_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11826,8 +11848,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Pong_1write(JNIEnv * _en JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Pong_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKPong ret_var = Pong_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11852,8 +11874,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncem JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKUnsignedChannelAnnouncement ret_var = UnsignedChannelAnnouncement_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11878,8 +11900,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1wri JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKChannelAnnouncement ret_var = ChannelAnnouncement_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11904,8 +11926,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1w JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedChannelUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKUnsignedChannelUpdate ret_var = UnsignedChannelUpdate_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11930,8 +11952,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1write(JNI JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKChannelUpdate ret_var = ChannelUpdate_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11956,8 +11978,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1write(JNIE JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ErrorMessage_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKErrorMessage ret_var = ErrorMessage_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -11982,8 +12004,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UnsignedNodeAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKUnsignedNodeAnnouncement ret_var = UnsignedNodeAnnouncement_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -12008,8 +12030,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1write( JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKNodeAnnouncement ret_var = NodeAnnouncement_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -12023,8 +12045,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1read(JNIEnv JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKQueryShortChannelIds ret_var = QueryShortChannelIds_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -12049,8 +12071,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryShortChannelIds_1wr JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKReplyShortChannelIdsEnd ret_var = ReplyShortChannelIdsEnd_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -12075,8 +12097,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyShortChannelIdsEnd_ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKQueryChannelRange ret_var = QueryChannelRange_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -12101,8 +12123,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_QueryChannelRange_1write JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKReplyChannelRange ret_var = ReplyChannelRange_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -12127,8 +12149,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ReplyChannelRange_1write JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_GossipTimestampFilter_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKGossipTimestampFilter ret_var = GossipTimestampFilter_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -12354,8 +12376,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1read_1event(JNIE this_arg_conv.is_owned = false; LDKSocketDescriptor* peer_descriptor_conv = (LDKSocketDescriptor*)peer_descriptor; LDKu8slice data_ref; - data_ref.data = (*_env)->GetByteArrayElements (_env, data, NULL); data_ref.datalen = (*_env)->GetArrayLength (_env, data); + data_ref.data = (*_env)->GetByteArrayElements (_env, data, NULL); LDKCResult_boolPeerHandleErrorZ* ret_conv = MALLOC(sizeof(LDKCResult_boolPeerHandleErrorZ), "LDKCResult_boolPeerHandleErrorZ"); *ret_conv = PeerManager_read_event(&this_arg_conv, peer_descriptor_conv, data_ref); (*_env)->ReleaseByteArrayElements(_env, data, (int8_t*)data_ref.data, 0); @@ -12600,8 +12622,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1write(JN JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_TxCreationKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKTxCreationKeys ret_var = TxCreationKeys_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -12828,8 +12850,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1write JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelPublicKeys_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKChannelPublicKeys ret_var = ChannelPublicKeys_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -12974,8 +12996,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HTLCOutputInCommitment_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKHTLCOutputInCommitment ret_var = HTLCOutputInCommitment_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -13015,7 +13037,7 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_make_1funding_1redeemscr return arg_arr; } -JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_build_1htlc_1transaction(JNIEnv * _env, jclass _b, jbyteArray prev_hash, jint feerate_per_kw, jshort contest_delay, jlong htlc, jbyteArray broadcaster_delayed_payment_key, jbyteArray revocation_key) { +JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_build_1htlc_1transaction(JNIEnv * _env, jclass _b, jbyteArray prev_hash, jint feerate_per_kw, jshort contest_delay, jlong htlc, jbyteArray broadcaster_delayed_payment_key, jbyteArray revocation_key) { unsigned char prev_hash_arr[32]; CHECK((*_env)->GetArrayLength (_env, prev_hash) == 32); (*_env)->GetByteArrayRegion (_env, prev_hash, 0, 32, prev_hash_arr); @@ -13029,10 +13051,11 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_build_1htlc_1transaction(JNIE LDKPublicKey revocation_key_ref; CHECK((*_env)->GetArrayLength (_env, revocation_key) == 33); (*_env)->GetByteArrayRegion (_env, revocation_key, 0, 33, revocation_key_ref.compressed_form); - LDKTransaction *ret_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction"); - *ret_copy = build_htlc_transaction(prev_hash_ref, feerate_per_kw, contest_delay, &htlc_conv, broadcaster_delayed_payment_key_ref, revocation_key_ref); - long ret_ref = (long)ret_copy; - return ret_ref; + LDKTransaction arg_var = build_htlc_transaction(prev_hash_ref, feerate_per_kw, contest_delay, &htlc_conv, broadcaster_delayed_payment_key_ref, revocation_key_ref); + jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen); + (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data); + Transaction_free(arg_var); + return arg_arr; } JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1free(JNIEnv * _env, jclass _b, jlong this_ptr) { @@ -13056,22 +13079,27 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1 return ret_ref; } -JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1unsigned_1tx(JNIEnv * _env, jclass _b, jlong this_ptr) { +JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1unsigned_1tx(JNIEnv * _env, jclass _b, jlong this_ptr) { LDKHolderCommitmentTransaction this_ptr_conv; this_ptr_conv.inner = (void*)(this_ptr & (~1)); this_ptr_conv.is_owned = false; - LDKTransaction *ret_copy = MALLOC(sizeof(LDKTransaction), "LDKTransaction"); - *ret_copy = HolderCommitmentTransaction_get_unsigned_tx(&this_ptr_conv); - long ret_ref = (long)ret_copy; - return ret_ref; + LDKTransaction arg_var = HolderCommitmentTransaction_get_unsigned_tx(&this_ptr_conv); + jbyteArray arg_arr = (*_env)->NewByteArray(_env, arg_var.datalen); + (*_env)->SetByteArrayRegion(_env, arg_arr, 0, arg_var.datalen, arg_var.data); + Transaction_free(arg_var); + return arg_arr; } -JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1unsigned_1tx(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) { +JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1unsigned_1tx(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) { LDKHolderCommitmentTransaction this_ptr_conv; this_ptr_conv.inner = (void*)(this_ptr & (~1)); this_ptr_conv.is_owned = false; - LDKTransaction val_conv = *(LDKTransaction*)val; - HolderCommitmentTransaction_set_unsigned_tx(&this_ptr_conv, val_conv); + LDKTransaction val_ref; + val_ref.datalen = (*_env)->GetArrayLength (_env, val); + val_ref.data = MALLOC(val_ref.datalen, "LDKTransaction Bytes"); + (*_env)->GetByteArrayRegion(_env, val, 0, val_ref.datalen, val_ref.data); + val_ref.data_is_owned = true; + HolderCommitmentTransaction_set_unsigned_tx(&this_ptr_conv, val_ref); } JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1counterparty_1sig(JNIEnv * _env, jclass _b, jlong this_ptr) { @@ -13129,8 +13157,12 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1s HolderCommitmentTransaction_set_per_htlc(&this_ptr_conv, val_constr); } -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; +JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1new_1missing_1holder_1sig(JNIEnv * _env, jclass _b, jbyteArray 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_ref; + unsigned_tx_ref.datalen = (*_env)->GetArrayLength (_env, unsigned_tx); + unsigned_tx_ref.data = MALLOC(unsigned_tx_ref.datalen, "LDKTransaction Bytes"); + (*_env)->GetByteArrayRegion(_env, unsigned_tx, 0, unsigned_tx_ref.datalen, unsigned_tx_ref.data); + unsigned_tx_ref.data_is_owned = true; LDKSignature counterparty_sig_ref; CHECK((*_env)->GetArrayLength (_env, counterparty_sig) == 64); (*_env)->GetByteArrayRegion (_env, counterparty_sig, 0, 64, counterparty_sig_ref.compact_form); @@ -13159,7 +13191,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1 htlc_data_constr.data[q] = arr_conv_42_conv; } (*_env)->ReleaseLongArrayElements (_env, htlc_data, htlc_data_vals, 0); - LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_new_missing_holder_sig(unsigned_tx_conv, counterparty_sig_ref, holder_funding_key_ref, counterparty_funding_key_ref, keys_conv, feerate_per_kw, htlc_data_constr); + LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_new_missing_holder_sig(unsigned_tx_ref, counterparty_sig_ref, holder_funding_key_ref, counterparty_funding_key_ref, keys_conv, feerate_per_kw, htlc_data_constr); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. long ret_ref = (long)ret_var.inner; @@ -13201,8 +13233,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransact (*_env)->GetByteArrayRegion (_env, funding_key, 0, 32, funding_key_arr); unsigned char (*funding_key_ref)[32] = &funding_key_arr; LDKu8slice funding_redeemscript_ref; - funding_redeemscript_ref.data = (*_env)->GetByteArrayElements (_env, funding_redeemscript, NULL); funding_redeemscript_ref.datalen = (*_env)->GetArrayLength (_env, funding_redeemscript); + funding_redeemscript_ref.data = (*_env)->GetByteArrayElements (_env, funding_redeemscript, NULL); jbyteArray arg_arr = (*_env)->NewByteArray(_env, 64); (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 64, HolderCommitmentTransaction_get_holder_sig(&this_arg_conv, funding_key_ref, funding_redeemscript_ref, channel_value_satoshis).compact_form); (*_env)->ReleaseByteArrayElements(_env, funding_redeemscript, (int8_t*)funding_redeemscript_ref.data, 0); @@ -13235,8 +13267,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransact JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKHolderCommitmentTransaction ret_var = HolderCommitmentTransaction_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -13532,8 +13564,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_Route_1write(JNIEnv * _e JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Route_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKRoute ret_var = Route_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -13930,8 +13962,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1 JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKDirectionalChannelInfo ret_var = DirectionalChannelInfo_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -14102,8 +14134,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1write(JNIEn JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKChannelInfo ret_var = ChannelInfo_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -14179,8 +14211,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1new(JNIEnv * _en JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingFees_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKRoutingFees ret_var = RoutingFees_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -14388,8 +14420,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1wr JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKNodeAnnouncementInfo ret_var = NodeAnnouncementInfo_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -14523,8 +14555,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NodeInfo_1write(JNIEnv * JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKNodeInfo ret_var = NodeInfo_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. @@ -14549,8 +14581,8 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1write(JNIE JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NetworkGraph_1read(JNIEnv * _env, jclass _b, jbyteArray ser) { LDKu8slice ser_ref; - ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); ser_ref.datalen = (*_env)->GetArrayLength (_env, ser); + ser_ref.data = (*_env)->GetByteArrayElements (_env, ser, NULL); LDKNetworkGraph ret_var = NetworkGraph_read(ser_ref); CHECK((((long)ret_var.inner) & 1) == 0); // We rely on a free low bit, malloc guarantees this. CHECK((((long)&ret_var) & 1) == 0); // We rely on a free low bit, pointer alignment guarantees this. diff --git a/src/main/jni/org_ldk_impl_bindings.h b/src/main/jni/org_ldk_impl_bindings.h index 55e01e8b..d2594975 100644 --- a/src/main/jni/org_ldk_impl_bindings.h +++ b/src/main/jni/org_ldk_impl_bindings.h @@ -130,10 +130,10 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1u8_1new /* * Class: org_ldk_impl_bindings * Method: LDKC2TupleTempl_usize__Transaction_new - * Signature: (JJ)J + * Signature: (J[B)J */ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1usize_1_1Transaction_1new - (JNIEnv *, jclass, jlong, jlong); + (JNIEnv *, jclass, jlong, jbyteArray); /* * Class: org_ldk_impl_bindings @@ -146,9 +146,9 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ /* * Class: org_ldk_impl_bindings * Method: LDKC2Tuple_usizeTransactionZ_get_b - * Signature: (J)J + * Signature: (J)[B */ -JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1b +JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKC2Tuple_1usizeTransactionZ_1get_1b (JNIEnv *, jclass, jlong); /* @@ -786,10 +786,10 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1key_1derivation_ /* * Class: org_ldk_impl_bindings * Method: ChannelKeys_sign_counterparty_commitment - * Signature: (JIJJ[J)J + * Signature: (JI[BJ[J)J */ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1commitment - (JNIEnv *, jclass, jlong, jint, jlong, jlong, jlongArray); + (JNIEnv *, jclass, jlong, jint, jbyteArray, jlong, jlongArray); /* * Class: org_ldk_impl_bindings @@ -810,26 +810,26 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1holder_1co /* * Class: org_ldk_impl_bindings * Method: ChannelKeys_sign_justice_transaction - * Signature: (JJJJ[BJ)J + * Signature: (J[BJJ[BJ)J */ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1justice_1transaction - (JNIEnv *, jclass, jlong, jlong, jlong, jlong, jbyteArray, jlong); + (JNIEnv *, jclass, jlong, jbyteArray, jlong, jlong, jbyteArray, jlong); /* * Class: org_ldk_impl_bindings * Method: ChannelKeys_sign_counterparty_htlc_transaction - * Signature: (JJJJ[BJ)J + * Signature: (J[BJJ[BJ)J */ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1counterparty_1htlc_1transaction - (JNIEnv *, jclass, jlong, jlong, jlong, jlong, jbyteArray, jlong); + (JNIEnv *, jclass, jlong, jbyteArray, jlong, jlong, jbyteArray, jlong); /* * Class: org_ldk_impl_bindings * Method: ChannelKeys_sign_closing_transaction - * Signature: (JJ)J + * Signature: (J[B)J */ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1sign_1closing_1transaction - (JNIEnv *, jclass, jlong, jlong); + (JNIEnv *, jclass, jlong, jbyteArray); /* * Class: org_ldk_impl_bindings @@ -962,10 +962,10 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1ge /* * Class: org_ldk_impl_bindings * Method: BroadcasterInterface_broadcast_transaction - * Signature: (JJ)V + * Signature: (J[B)V */ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1broadcast_1transaction - (JNIEnv *, jclass, jlong, jlong); + (JNIEnv *, jclass, jlong, jbyteArray); /* * Class: org_ldk_impl_bindings @@ -1015,14 +1015,6 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1u JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Transaction_1arr_1info (JNIEnv *, jclass, jlong); -/* - * Class: org_ldk_impl_bindings - * Method: LDKCVecTempl_Transaction_new - * Signature: ([J)J - */ -JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1Transaction_1new - (JNIEnv *, jclass, jlongArray); - /* * Class: org_ldk_impl_bindings * Method: LDKCVecTempl_C2TupleTempl_ThirtyTwoBytes__CVecTempl_TxOut_arr_info @@ -2298,10 +2290,10 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1SpendableOutputDescripto /* * Class: org_ldk_impl_bindings * Method: CVec_TransactionZ_free - * Signature: ([J)V + * Signature: ([[B)V */ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1TransactionZ_1free - (JNIEnv *, jclass, jlongArray); + (JNIEnv *, jclass, jobjectArray); /* * Class: org_ldk_impl_bindings @@ -2362,10 +2354,10 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CVec_1u8Z_1free /* * Class: org_ldk_impl_bindings * Method: Transaction_free - * Signature: (J)V + * Signature: ([B)V */ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Transaction_1free - (JNIEnv *, jclass, jlong); + (JNIEnv *, jclass, jbyteArray); /* * Class: org_ldk_impl_bindings @@ -2378,10 +2370,10 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_TxOut_1free /* * Class: org_ldk_impl_bindings * Method: C2Tuple_usizeTransactionZ_new - * Signature: (JJ)J + * Signature: (J[B)J */ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1usizeTransactionZ_1new - (JNIEnv *, jclass, jlong, jlong); + (JNIEnv *, jclass, jlong, jbyteArray); /* * Class: org_ldk_impl_bindings @@ -3298,9 +3290,9 @@ JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1and /* * Class: org_ldk_impl_bindings * Method: ChannelMonitor_get_latest_holder_commitment_txn - * Signature: (JJ)[J + * Signature: (JJ)[[B */ -JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1holder_1commitment_1txn +JNIEXPORT jobjectArray JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1get_1latest_1holder_1commitment_1txn (JNIEnv *, jclass, jlong, jlong); /* @@ -8050,9 +8042,9 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_make_1funding_1redeemscr /* * Class: org_ldk_impl_bindings * Method: build_htlc_transaction - * Signature: ([BISJ[B[B)J + * Signature: ([BISJ[B[B)[B */ -JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_build_1htlc_1transaction +JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_build_1htlc_1transaction (JNIEnv *, jclass, jbyteArray, jint, jshort, jlong, jbyteArray, jbyteArray); /* @@ -8074,18 +8066,18 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1 /* * Class: org_ldk_impl_bindings * Method: HolderCommitmentTransaction_get_unsigned_tx - * Signature: (J)J + * Signature: (J)[B */ -JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1unsigned_1tx +JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1get_1unsigned_1tx (JNIEnv *, jclass, jlong); /* * Class: org_ldk_impl_bindings * Method: HolderCommitmentTransaction_set_unsigned_tx - * Signature: (JJ)V + * Signature: (J[B)V */ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1set_1unsigned_1tx - (JNIEnv *, jclass, jlong, jlong); + (JNIEnv *, jclass, jlong, jbyteArray); /* * Class: org_ldk_impl_bindings @@ -8130,10 +8122,10 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1s /* * Class: org_ldk_impl_bindings * Method: HolderCommitmentTransaction_new_missing_holder_sig - * Signature: (J[B[B[BJI[J)J + * Signature: ([B[B[B[BJI[J)J */ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1new_1missing_1holder_1sig - (JNIEnv *, jclass, jlong, jbyteArray, jbyteArray, jbyteArray, jlong, jint, jlongArray); + (JNIEnv *, jclass, jbyteArray, jbyteArray, jbyteArray, jbyteArray, jlong, jint, jlongArray); /* * Class: org_ldk_impl_bindings diff --git a/src/test/java/org/ldk/HumanObjectPeerTest.java b/src/test/java/org/ldk/HumanObjectPeerTest.java index 475a2893..c66b4dd8 100644 --- a/src/test/java/org/ldk/HumanObjectPeerTest.java +++ b/src/test/java/org/ldk/HumanObjectPeerTest.java @@ -27,7 +27,7 @@ class HumanObjectPeerTestInstance { final PeerManager peer_manager; final HashMap monitors; // Wow I forgot just how terrible Java is - we can't put a byte array here. byte[] node_id; - final LinkedList broadcast_set = new LinkedList<>(); + final LinkedList broadcast_set = new LinkedList<>(); Peer(byte seed) { logger = Logger.new_impl((String arg) -> System.out.println(seed + ": " + arg)); @@ -87,10 +87,10 @@ class HumanObjectPeerTestInstance { TwoTuple[] connect_block(Block b, int height) { byte[] header = Arrays.copyOfRange(b.bitcoinSerialize(), 0, 80); - TwoTuple[] txn; + TwoTuple[] txn; if (b.hasTransactions()) { assert b.getTransactions().size() == 1; - TwoTuple txp = new TwoTuple<>((long) 1, new org.ldk.structs.Transaction(b.getTransactions().get(0).bitcoinSerialize())); + TwoTuple txp = new TwoTuple<>((long) 1, b.getTransactions().get(0).bitcoinSerialize()); txn = new TwoTuple[]{txp}; } else txn = new TwoTuple[0]; @@ -316,7 +316,7 @@ class HumanObjectPeerTestInstance { assert peer1.broadcast_set.size() == 1; assert peer2.broadcast_set.size() == 0; - Transaction tx = new Transaction(bitcoinj_net, peer1.broadcast_set.getFirst().get_contents()); + Transaction tx = new Transaction(bitcoinj_net, peer1.broadcast_set.getFirst()); b = new Block(bitcoinj_net, 2, b.getHash(), Sha256Hash.ZERO_HASH, 42, 0, 0, Arrays.asList(new Transaction[]{tx})); TwoTuple[] watch_outputs = peer2.connect_block(b, 1); diff --git a/src/test/java/org/ldk/PeerTest.java b/src/test/java/org/ldk/PeerTest.java index 74630786..0479cdca 100644 --- a/src/test/java/org/ldk/PeerTest.java +++ b/src/test/java/org/ldk/PeerTest.java @@ -102,23 +102,18 @@ public class PeerTest { void connect_block(Block b, Transaction t, int height) { byte[] header = Arrays.copyOfRange(b.bitcoinSerialize(), 0, 80); long[] txn; - long txdata = 0; - if (t != null) { - txdata = bindings.new_txpointer_copy_data(t.bitcoinSerialize()); - txn = new long[]{bindings.C2Tuple_usizeTransactionZ_new(1, txdata)}; - } else + if (t != null) + txn = new long[]{bindings.C2Tuple_usizeTransactionZ_new(1, t.bitcoinSerialize())}; + 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) { - txdata = bindings.new_txpointer_copy_data(t.bitcoinSerialize()); - txn = new long[]{bindings.C2Tuple_usizeTransactionZ_new(1, txdata)}; - } else + if (t != null) + txn = new long[]{bindings.C2Tuple_usizeTransactionZ_new(1, t.bitcoinSerialize())}; + 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); }