]> git.bitcoin.ninja Git - ldk-java/blobdiff - src/main/jni/bindings.c
Expose SecretKey as byte[32], expose trait call fns in human structs
[ldk-java] / src / main / jni / bindings.c
index 35fd0101dbfaacc752c5539df335dcabe8505496..f3c8a5531c73620b640aba90d212f5b69bd2b1c2 100644 (file)
@@ -171,10 +171,6 @@ _Static_assert(sizeof(LDKCVec_u8Z) == sizeof(LDKu8slice), "Vec<u8> and [u8] need
 _Static_assert(offsetof(LDKCVec_u8Z, data) == offsetof(LDKu8slice, data), "Vec<u8> and [u8] need to have been mapped identically");
 _Static_assert(offsetof(LDKCVec_u8Z, datalen) == offsetof(LDKu8slice, datalen), "Vec<u8> and [u8] need to have been mapped identically");
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKSecretKey_1new(JNIEnv * _env, jclass _b) {
-       LDKSecretKey* key = (LDKSecretKey*)MALLOC(sizeof(LDKSecretKey), "LDKSecretKey");
-       return (long)key;
-}
 static inline LDKAccessError LDKAccessError_from_java(JNIEnv *env, jclass val) {
        switch ((*env)->CallIntMethod(env, val, ordinal_meth)) {
                case 0: return LDKAccessError_UnknownChain;
@@ -475,6 +471,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1OutPoint_1_1
        LDKOutPoint a_conv;
        a_conv.inner = (void*)(a & (~1));
        a_conv.is_owned = (a & 1) || (a == 0);
+       if (a_conv.inner != NULL)
+               a_conv = OutPoint_clone(&a_conv);
        ret->a = a_conv;
        LDKCVec_u8Z b_conv = *(LDKCVec_u8Z*)b;
        FREE((void*)b);
@@ -673,14 +671,20 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC3TupleTempl_1ChannelAnnou
        LDKChannelAnnouncement a_conv;
        a_conv.inner = (void*)(a & (~1));
        a_conv.is_owned = (a & 1) || (a == 0);
+       if (a_conv.inner != NULL)
+               a_conv = ChannelAnnouncement_clone(&a_conv);
        ret->a = a_conv;
        LDKChannelUpdate b_conv;
        b_conv.inner = (void*)(b & (~1));
        b_conv.is_owned = (b & 1) || (b == 0);
+       if (b_conv.inner != NULL)
+               b_conv = ChannelUpdate_clone(&b_conv);
        ret->b = b_conv;
        LDKChannelUpdate c_conv;
        c_conv.inner = (void*)(c & (~1));
        c_conv.is_owned = (c & 1) || (c == 0);
+       if (c_conv.inner != NULL)
+               c_conv = ChannelUpdate_clone(&c_conv);
        ret->c = c_conv;
        return (long)ret;
 }
@@ -700,6 +704,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKC2TupleTempl_1HTLCOutputIn
        LDKHTLCOutputInCommitment a_conv;
        a_conv.inner = (void*)(a & (~1));
        a_conv.is_owned = (a & 1) || (a == 0);
+       if (a_conv.inner != NULL)
+               a_conv = HTLCOutputInCommitment_clone(&a_conv);
        ret->a = a_conv;
        LDKSignature b_conv = *(LDKSignature*)b;
        FREE((void*)b);
@@ -1415,10 +1421,10 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvide
        DO_ASSERT(ret != NULL);
        return ret;
 }
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1call_1get_1and_1clear_1pending_1msg_1events(JNIEnv * _env, jclass _b, jlong arg) {
-       LDKMessageSendEventsProvider* arg_conv = (LDKMessageSendEventsProvider*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_MessageSendEventsProvider_1call_1get_1and_1clear_1pending_1msg_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
+       LDKMessageSendEventsProvider* this_arg_conv = (LDKMessageSendEventsProvider*)this_arg;
        LDKCVec_MessageSendEventZ* ret = MALLOC(sizeof(LDKCVec_MessageSendEventZ), "LDKCVec_MessageSendEventZ");
-       *ret = (arg_conv->get_and_clear_pending_msg_events)(arg_conv->this_arg);
+       *ret = (this_arg_conv->get_and_clear_pending_msg_events)(this_arg_conv->this_arg);
        return (long)ret;
 }
 
@@ -1502,10 +1508,10 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1get_1obj
        DO_ASSERT(ret != NULL);
        return ret;
 }
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1call_1get_1and_1clear_1pending_1events(JNIEnv * _env, jclass _b, jlong arg) {
-       LDKEventsProvider* arg_conv = (LDKEventsProvider*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_EventsProvider_1call_1get_1and_1clear_1pending_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
+       LDKEventsProvider* this_arg_conv = (LDKEventsProvider*)this_arg;
        LDKCVec_EventZ* ret = MALLOC(sizeof(LDKCVec_EventZ), "LDKCVec_EventZ");
-       *ret = (arg_conv->get_and_clear_pending_events)(arg_conv->this_arg);
+       *ret = (this_arg_conv->get_and_clear_pending_events)(this_arg_conv->this_arg);
        return (long)ret;
 }
 
@@ -1636,13 +1642,13 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAccess_1get_1obj_1from_1
        DO_ASSERT(ret != NULL);
        return ret;
 }
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKAccess_1call_1get_1utxo(JNIEnv * _env, jclass _b, jlong arg, jbyteArray genesis_hash, jlong short_channel_id) {
-       LDKAccess* arg_conv = (LDKAccess*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Access_1call_1get_1utxo(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray genesis_hash, jlong short_channel_id) {
+       LDKAccess* this_arg_conv = (LDKAccess*)this_arg;
        unsigned char genesis_hash_arr[32];
        (*_env)->GetByteArrayRegion (_env, genesis_hash, 0, 32, genesis_hash_arr);
        unsigned char (*genesis_hash_ref)[32] = &genesis_hash_arr;
        LDKCResult_TxOutAccessErrorZ* ret = MALLOC(sizeof(LDKCResult_TxOutAccessErrorZ), "LDKCResult_TxOutAccessErrorZ");
-       *ret = (arg_conv->get_utxo)(arg_conv->this_arg, genesis_hash_ref, short_channel_id);
+       *ret = (this_arg_conv->get_utxo)(this_arg_conv->this_arg, genesis_hash_ref, short_channel_id);
        return (long)ret;
 }
 
@@ -1670,6 +1676,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1HTLCOutputInCom
                        LDKHTLCOutputInCommitment arr_elem_conv;
                        arr_elem_conv.inner = (void*)(arr_elem & (~1));
                        arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
+                       if (arr_elem_conv.inner != NULL)
+                               arr_elem_conv = HTLCOutputInCommitment_clone(&arr_elem_conv);
                        ret->data[i] = arr_elem_conv;
                }
                (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
@@ -1891,29 +1899,29 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1get_1obj_1f
        DO_ASSERT(ret != NULL);
        return ret;
 }
-JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1call_1get_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong arg, jlong idx) {
-       LDKChannelKeys* arg_conv = (LDKChannelKeys*)arg;
+JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1call_1get_1per_1commitment_1point(JNIEnv * _env, jclass _b, jlong this_arg, jlong idx) {
+       LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
-       (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, (arg_conv->get_per_commitment_point)(arg_conv->this_arg, idx).compressed_form);
+       (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, (this_arg_conv->get_per_commitment_point)(this_arg_conv->this_arg, idx).compressed_form);
        return arg_arr;
 }
 
-JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1call_1release_1commitment_1secret(JNIEnv * _env, jclass _b, jlong arg, jlong idx) {
-       LDKChannelKeys* arg_conv = (LDKChannelKeys*)arg;
+JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1call_1release_1commitment_1secret(JNIEnv * _env, jclass _b, jlong this_arg, jlong idx) {
+       LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
-       (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (arg_conv->release_commitment_secret)(arg_conv->this_arg, idx).data);
+       (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->release_commitment_secret)(this_arg_conv->this_arg, idx).data);
        return arg_arr;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1call_1key_1derivation_1params(JNIEnv * _env, jclass _b, jlong arg) {
-       LDKChannelKeys* arg_conv = (LDKChannelKeys*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1call_1key_1derivation_1params(JNIEnv * _env, jclass _b, jlong this_arg) {
+       LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        LDKC2Tuple_u64u64Z* ret = MALLOC(sizeof(LDKC2Tuple_u64u64Z), "LDKC2Tuple_u64u64Z");
-       *ret = (arg_conv->key_derivation_params)(arg_conv->this_arg);
+       *ret = (this_arg_conv->key_derivation_params)(this_arg_conv->this_arg);
        return (long)ret;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1call_1sign_1counterparty_1commitment(JNIEnv * _env, jclass _b, jlong arg, jint feerate_per_kw, jlong commitment_tx, jlong keys, jlong htlcs) {
-       LDKChannelKeys* arg_conv = (LDKChannelKeys*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1call_1sign_1counterparty_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jint feerate_per_kw, jlong commitment_tx, jlong keys, jlong htlcs) {
+       LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        LDKTransaction commitment_tx_conv = *(LDKTransaction*)commitment_tx;
        FREE((void*)commitment_tx);
        LDKPreCalculatedTxCreationKeys keys_conv;
@@ -1922,32 +1930,32 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1call_1sign_1c
        LDKCVec_HTLCOutputInCommitmentZ htlcs_conv = *(LDKCVec_HTLCOutputInCommitmentZ*)htlcs;
        FREE((void*)htlcs);
        LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ* ret = MALLOC(sizeof(LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ), "LDKCResult_C2Tuple_SignatureCVec_SignatureZZNoneZ");
-       *ret = (arg_conv->sign_counterparty_commitment)(arg_conv->this_arg, feerate_per_kw, commitment_tx_conv, &keys_conv, htlcs_conv);
+       *ret = (this_arg_conv->sign_counterparty_commitment)(this_arg_conv->this_arg, feerate_per_kw, commitment_tx_conv, &keys_conv, htlcs_conv);
        return (long)ret;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1call_1sign_1holder_1commitment(JNIEnv * _env, jclass _b, jlong arg, jlong holder_commitment_tx) {
-       LDKChannelKeys* arg_conv = (LDKChannelKeys*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1call_1sign_1holder_1commitment(JNIEnv * _env, jclass _b, jlong this_arg, jlong holder_commitment_tx) {
+       LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        LDKHolderCommitmentTransaction holder_commitment_tx_conv;
        holder_commitment_tx_conv.inner = (void*)(holder_commitment_tx & (~1));
        holder_commitment_tx_conv.is_owned = (holder_commitment_tx & 1) || (holder_commitment_tx == 0);
        LDKCResult_SignatureNoneZ* ret = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
-       *ret = (arg_conv->sign_holder_commitment)(arg_conv->this_arg, &holder_commitment_tx_conv);
+       *ret = (this_arg_conv->sign_holder_commitment)(this_arg_conv->this_arg, &holder_commitment_tx_conv);
        return (long)ret;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1call_1sign_1holder_1commitment_1htlc_1transactions(JNIEnv * _env, jclass _b, jlong arg, jlong holder_commitment_tx) {
-       LDKChannelKeys* arg_conv = (LDKChannelKeys*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1call_1sign_1holder_1commitment_1htlc_1transactions(JNIEnv * _env, jclass _b, jlong this_arg, jlong holder_commitment_tx) {
+       LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        LDKHolderCommitmentTransaction holder_commitment_tx_conv;
        holder_commitment_tx_conv.inner = (void*)(holder_commitment_tx & (~1));
        holder_commitment_tx_conv.is_owned = (holder_commitment_tx & 1) || (holder_commitment_tx == 0);
        LDKCResult_CVec_SignatureZNoneZ* ret = MALLOC(sizeof(LDKCResult_CVec_SignatureZNoneZ), "LDKCResult_CVec_SignatureZNoneZ");
-       *ret = (arg_conv->sign_holder_commitment_htlc_transactions)(arg_conv->this_arg, &holder_commitment_tx_conv);
+       *ret = (this_arg_conv->sign_holder_commitment_htlc_transactions)(this_arg_conv->this_arg, &holder_commitment_tx_conv);
        return (long)ret;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1call_1sign_1justice_1transaction(JNIEnv * _env, jclass _b, jlong arg, jlong justice_tx, jlong input, jlong amount, jbyteArray per_commitment_key, jlong htlc) {
-       LDKChannelKeys* arg_conv = (LDKChannelKeys*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1call_1sign_1justice_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong justice_tx, jlong input, jlong amount, jbyteArray per_commitment_key, jlong htlc) {
+       LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        LDKTransaction justice_tx_conv = *(LDKTransaction*)justice_tx;
        FREE((void*)justice_tx);
        unsigned char per_commitment_key_arr[32];
@@ -1957,12 +1965,12 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1call_1sign_1j
        htlc_conv.inner = (void*)(htlc & (~1));
        htlc_conv.is_owned = (htlc & 1) || (htlc == 0);
        LDKCResult_SignatureNoneZ* ret = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
-       *ret = (arg_conv->sign_justice_transaction)(arg_conv->this_arg, justice_tx_conv, input, amount, per_commitment_key_ref, &htlc_conv);
+       *ret = (this_arg_conv->sign_justice_transaction)(this_arg_conv->this_arg, justice_tx_conv, input, amount, per_commitment_key_ref, &htlc_conv);
        return (long)ret;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1call_1sign_1counterparty_1htlc_1transaction(JNIEnv * _env, jclass _b, jlong arg, jlong htlc_tx, jlong input, jlong amount, jbyteArray per_commitment_point, jlong htlc) {
-       LDKChannelKeys* arg_conv = (LDKChannelKeys*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1call_1sign_1counterparty_1htlc_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong htlc_tx, jlong input, jlong amount, jbyteArray per_commitment_point, jlong htlc) {
+       LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        LDKTransaction htlc_tx_conv = *(LDKTransaction*)htlc_tx;
        FREE((void*)htlc_tx);
        LDKPublicKey per_commitment_point_ref;
@@ -1971,35 +1979,35 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1call_1sign_1c
        htlc_conv.inner = (void*)(htlc & (~1));
        htlc_conv.is_owned = (htlc & 1) || (htlc == 0);
        LDKCResult_SignatureNoneZ* ret = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
-       *ret = (arg_conv->sign_counterparty_htlc_transaction)(arg_conv->this_arg, htlc_tx_conv, input, amount, per_commitment_point_ref, &htlc_conv);
+       *ret = (this_arg_conv->sign_counterparty_htlc_transaction)(this_arg_conv->this_arg, htlc_tx_conv, input, amount, per_commitment_point_ref, &htlc_conv);
        return (long)ret;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1call_1sign_1closing_1transaction(JNIEnv * _env, jclass _b, jlong arg, jlong closing_tx) {
-       LDKChannelKeys* arg_conv = (LDKChannelKeys*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1call_1sign_1closing_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong closing_tx) {
+       LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        LDKTransaction closing_tx_conv = *(LDKTransaction*)closing_tx;
        FREE((void*)closing_tx);
        LDKCResult_SignatureNoneZ* ret = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
-       *ret = (arg_conv->sign_closing_transaction)(arg_conv->this_arg, closing_tx_conv);
+       *ret = (this_arg_conv->sign_closing_transaction)(this_arg_conv->this_arg, closing_tx_conv);
        return (long)ret;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1call_1sign_1channel_1announcement(JNIEnv * _env, jclass _b, jlong arg, jlong msg) {
-       LDKChannelKeys* arg_conv = (LDKChannelKeys*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1call_1sign_1channel_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
+       LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        LDKUnsignedChannelAnnouncement msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
        LDKCResult_SignatureNoneZ* ret = MALLOC(sizeof(LDKCResult_SignatureNoneZ), "LDKCResult_SignatureNoneZ");
-       *ret = (arg_conv->sign_channel_announcement)(arg_conv->this_arg, &msg_conv);
+       *ret = (this_arg_conv->sign_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
        return (long)ret;
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1call_1on_1accept(JNIEnv * _env, jclass _b, jlong arg, jlong channel_points, jshort counterparty_selected_contest_delay, jshort holder_selected_contest_delay) {
-       LDKChannelKeys* arg_conv = (LDKChannelKeys*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelKeys_1call_1on_1accept(JNIEnv * _env, jclass _b, jlong this_arg, jlong channel_points, jshort counterparty_selected_contest_delay, jshort holder_selected_contest_delay) {
+       LDKChannelKeys* this_arg_conv = (LDKChannelKeys*)this_arg;
        LDKChannelPublicKeys channel_points_conv;
        channel_points_conv.inner = (void*)(channel_points & (~1));
        channel_points_conv.is_owned = (channel_points & 1) || (channel_points == 0);
-       return (arg_conv->on_accept)(arg_conv->this_arg, &channel_points_conv, counterparty_selected_contest_delay, holder_selected_contest_delay);
+       return (this_arg_conv->on_accept)(this_arg_conv->this_arg, &channel_points_conv, counterparty_selected_contest_delay, holder_selected_contest_delay);
 }
 
 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1MonitorEvent_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
@@ -2156,36 +2164,42 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKWatch_1get_1obj_1from_1j
        DO_ASSERT(ret != NULL);
        return ret;
 }
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKWatch_1call_1watch_1channel(JNIEnv * _env, jclass _b, jlong arg, jlong funding_txo, jlong monitor) {
-       LDKWatch* arg_conv = (LDKWatch*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Watch_1call_1watch_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong funding_txo, jlong monitor) {
+       LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
        LDKOutPoint funding_txo_conv;
        funding_txo_conv.inner = (void*)(funding_txo & (~1));
        funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
+       if (funding_txo_conv.inner != NULL)
+               funding_txo_conv = OutPoint_clone(&funding_txo_conv);
        LDKChannelMonitor monitor_conv;
        monitor_conv.inner = (void*)(monitor & (~1));
        monitor_conv.is_owned = (monitor & 1) || (monitor == 0);
        LDKCResult_NoneChannelMonitorUpdateErrZ* ret = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
-       *ret = (arg_conv->watch_channel)(arg_conv->this_arg, funding_txo_conv, monitor_conv);
+       *ret = (this_arg_conv->watch_channel)(this_arg_conv->this_arg, funding_txo_conv, monitor_conv);
        return (long)ret;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKWatch_1call_1update_1channel(JNIEnv * _env, jclass _b, jlong arg, jlong funding_txo, jlong update) {
-       LDKWatch* arg_conv = (LDKWatch*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Watch_1call_1update_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jlong funding_txo, jlong update) {
+       LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
        LDKOutPoint funding_txo_conv;
        funding_txo_conv.inner = (void*)(funding_txo & (~1));
        funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
+       if (funding_txo_conv.inner != NULL)
+               funding_txo_conv = OutPoint_clone(&funding_txo_conv);
        LDKChannelMonitorUpdate update_conv;
        update_conv.inner = (void*)(update & (~1));
        update_conv.is_owned = (update & 1) || (update == 0);
+       if (update_conv.inner != NULL)
+               update_conv = ChannelMonitorUpdate_clone(&update_conv);
        LDKCResult_NoneChannelMonitorUpdateErrZ* ret = MALLOC(sizeof(LDKCResult_NoneChannelMonitorUpdateErrZ), "LDKCResult_NoneChannelMonitorUpdateErrZ");
-       *ret = (arg_conv->update_channel)(arg_conv->this_arg, funding_txo_conv, update_conv);
+       *ret = (this_arg_conv->update_channel)(this_arg_conv->this_arg, funding_txo_conv, update_conv);
        return (long)ret;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKWatch_1call_1release_1pending_1monitor_1events(JNIEnv * _env, jclass _b, jlong arg) {
-       LDKWatch* arg_conv = (LDKWatch*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_Watch_1call_1release_1pending_1monitor_1events(JNIEnv * _env, jclass _b, jlong this_arg) {
+       LDKWatch* this_arg_conv = (LDKWatch*)this_arg;
        LDKCVec_MonitorEventZ* ret = MALLOC(sizeof(LDKCVec_MonitorEventZ), "LDKCVec_MonitorEventZ");
-       *ret = (arg_conv->release_pending_monitor_events)(arg_conv->this_arg);
+       *ret = (this_arg_conv->release_pending_monitor_events)(this_arg_conv->this_arg);
        return (long)ret;
 }
 
@@ -2260,22 +2274,22 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFilter_1get_1obj_1from_1
        DO_ASSERT(ret != NULL);
        return ret;
 }
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKFilter_1call_1register_1tx(JNIEnv * _env, jclass _b, jlong arg, jbyteArray txid, jlong script_pubkey) {
-       LDKFilter* arg_conv = (LDKFilter*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1call_1register_1tx(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray txid, jlong script_pubkey) {
+       LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
        unsigned char txid_arr[32];
        (*_env)->GetByteArrayRegion (_env, txid, 0, 32, txid_arr);
        unsigned char (*txid_ref)[32] = &txid_arr;
        LDKu8slice script_pubkey_conv = *(LDKu8slice*)script_pubkey;
-       return (arg_conv->register_tx)(arg_conv->this_arg, txid_ref, script_pubkey_conv);
+       return (this_arg_conv->register_tx)(this_arg_conv->this_arg, txid_ref, script_pubkey_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKFilter_1call_1register_1output(JNIEnv * _env, jclass _b, jlong arg, jlong outpoint, jlong script_pubkey) {
-       LDKFilter* arg_conv = (LDKFilter*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_Filter_1call_1register_1output(JNIEnv * _env, jclass _b, jlong this_arg, jlong outpoint, jlong script_pubkey) {
+       LDKFilter* this_arg_conv = (LDKFilter*)this_arg;
        LDKOutPoint outpoint_conv;
        outpoint_conv.inner = (void*)(outpoint & (~1));
        outpoint_conv.is_owned = (outpoint & 1) || (outpoint == 0);
        LDKu8slice script_pubkey_conv = *(LDKu8slice*)script_pubkey;
-       return (arg_conv->register_output)(arg_conv->this_arg, &outpoint_conv, script_pubkey_conv);
+       return (this_arg_conv->register_output)(this_arg_conv->this_arg, &outpoint_conv, script_pubkey_conv);
 }
 
 typedef struct LDKBroadcasterInterface_JCalls {
@@ -2334,11 +2348,11 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1ge
        DO_ASSERT(ret != NULL);
        return ret;
 }
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1call_1broadcast_1transaction(JNIEnv * _env, jclass _b, jlong arg, jlong tx) {
-       LDKBroadcasterInterface* arg_conv = (LDKBroadcasterInterface*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_BroadcasterInterface_1call_1broadcast_1transaction(JNIEnv * _env, jclass _b, jlong this_arg, jlong tx) {
+       LDKBroadcasterInterface* this_arg_conv = (LDKBroadcasterInterface*)this_arg;
        LDKTransaction tx_conv = *(LDKTransaction*)tx;
        FREE((void*)tx);
-       return (arg_conv->broadcast_transaction)(arg_conv->this_arg, tx_conv);
+       return (this_arg_conv->broadcast_transaction)(this_arg_conv->this_arg, tx_conv);
 }
 
 typedef struct LDKFeeEstimator_JCalls {
@@ -2397,10 +2411,10 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1get_1obj_1
        DO_ASSERT(ret != NULL);
        return ret;
 }
-JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1call_1get_1est_1sat_1per_11000_1weight(JNIEnv * _env, jclass _b, jlong arg, jclass confirmation_target) {
-       LDKFeeEstimator* arg_conv = (LDKFeeEstimator*)arg;
+JNIEXPORT jint JNICALL Java_org_ldk_impl_bindings_FeeEstimator_1call_1get_1est_1sat_1per_11000_1weight(JNIEnv * _env, jclass _b, jlong this_arg, jclass confirmation_target) {
+       LDKFeeEstimator* this_arg_conv = (LDKFeeEstimator*)this_arg;
        LDKConfirmationTarget confirmation_target_conv = LDKConfirmationTarget_from_java(_env, confirmation_target);
-       return (arg_conv->get_est_sat_per_1000_weight)(arg_conv->this_arg, confirmation_target_conv);
+       return (this_arg_conv->get_est_sat_per_1000_weight)(this_arg_conv->this_arg, confirmation_target_conv);
 }
 
 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1C2TupleTempl_1usize_1_1Transaction_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
@@ -2485,10 +2499,10 @@ LDKSecretKey get_node_secret_jcall(const void* this_arg) {
        DO_ASSERT((*j_calls->vm)->GetEnv(j_calls->vm, (void**)&env, JNI_VERSION_1_8) == JNI_OK);
        jobject obj = (*env)->NewLocalRef(env, j_calls->o);
        DO_ASSERT(obj != NULL);
-       LDKSecretKey* ret = (LDKSecretKey*)(*env)->CallLongMethod(env, obj, j_calls->get_node_secret_meth);
-       LDKSecretKey res = *ret;
-       FREE(ret);
-       return res;
+       jbyteArray jret = (*env)->CallObjectMethod(env, obj, j_calls->get_node_secret_meth);
+       LDKSecretKey ret;
+       (*env)->GetByteArrayRegion(env, jret, 0, 32, ret.bytes);
+       return ret;
 }
 LDKCVec_u8Z get_destination_script_jcall(const void* this_arg) {
        LDKKeysInterface_JCalls *j_calls = (LDKKeysInterface_JCalls*) this_arg;
@@ -2555,7 +2569,7 @@ static inline LDKKeysInterface LDKKeysInterface_init (JNIEnv * env, jclass _a, j
        atomic_init(&calls->refcnt, 1);
        DO_ASSERT((*env)->GetJavaVM(env, &calls->vm) == 0);
        calls->o = (*env)->NewWeakGlobalRef(env, o);
-       calls->get_node_secret_meth = (*env)->GetMethodID(env, c, "get_node_secret", "()J");
+       calls->get_node_secret_meth = (*env)->GetMethodID(env, c, "get_node_secret", "()[B");
        DO_ASSERT(calls->get_node_secret_meth != NULL);
        calls->get_destination_script_meth = (*env)->GetMethodID(env, c, "get_destination_script", "()J");
        DO_ASSERT(calls->get_destination_script_meth != NULL);
@@ -2587,38 +2601,38 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1get_1obj_
        DO_ASSERT(ret != NULL);
        return ret;
 }
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1call_1get_1node_1secret(JNIEnv * _env, jclass _b, jlong arg) {
-       LDKKeysInterface* arg_conv = (LDKKeysInterface*)arg;
-       LDKSecretKey* ret = MALLOC(sizeof(LDKSecretKey), "LDKSecretKey");
-       *ret = (arg_conv->get_node_secret)(arg_conv->this_arg);
-       return (long)ret;
+JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1call_1get_1node_1secret(JNIEnv * _env, jclass _b, jlong this_arg) {
+       LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
+       jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
+       (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->get_node_secret)(this_arg_conv->this_arg).bytes);
+       return arg_arr;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1call_1get_1destination_1script(JNIEnv * _env, jclass _b, jlong arg) {
-       LDKKeysInterface* arg_conv = (LDKKeysInterface*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_KeysInterface_1call_1get_1destination_1script(JNIEnv * _env, jclass _b, jlong this_arg) {
+       LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
        LDKCVec_u8Z* ret = MALLOC(sizeof(LDKCVec_u8Z), "LDKCVec_u8Z");
-       *ret = (arg_conv->get_destination_script)(arg_conv->this_arg);
+       *ret = (this_arg_conv->get_destination_script)(this_arg_conv->this_arg);
        return (long)ret;
 }
 
-JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1call_1get_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong arg) {
-       LDKKeysInterface* arg_conv = (LDKKeysInterface*)arg;
+JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1call_1get_1shutdown_1pubkey(JNIEnv * _env, jclass _b, jlong this_arg) {
+       LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
        jbyteArray arg_arr = (*_env)->NewByteArray(_env, 33);
-       (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, (arg_conv->get_shutdown_pubkey)(arg_conv->this_arg).compressed_form);
+       (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 33, (this_arg_conv->get_shutdown_pubkey)(this_arg_conv->this_arg).compressed_form);
        return arg_arr;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1call_1get_1channel_1keys(JNIEnv * _env, jclass _b, jlong arg, jboolean inbound, jlong channel_value_satoshis) {
-       LDKKeysInterface* arg_conv = (LDKKeysInterface*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_KeysInterface_1call_1get_1channel_1keys(JNIEnv * _env, jclass _b, jlong this_arg, jboolean inbound, jlong channel_value_satoshis) {
+       LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
        LDKChannelKeys* ret = MALLOC(sizeof(LDKChannelKeys), "LDKChannelKeys");
-       *ret = (arg_conv->get_channel_keys)(arg_conv->this_arg, inbound, channel_value_satoshis);
+       *ret = (this_arg_conv->get_channel_keys)(this_arg_conv->this_arg, inbound, channel_value_satoshis);
        return (long)ret;
 }
 
-JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1call_1get_1secure_1random_1bytes(JNIEnv * _env, jclass _b, jlong arg) {
-       LDKKeysInterface* arg_conv = (LDKKeysInterface*)arg;
+JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_KeysInterface_1call_1get_1secure_1random_1bytes(JNIEnv * _env, jclass _b, jlong this_arg) {
+       LDKKeysInterface* this_arg_conv = (LDKKeysInterface*)this_arg;
        jbyteArray arg_arr = (*_env)->NewByteArray(_env, 32);
-       (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (arg_conv->get_secure_random_bytes)(arg_conv->this_arg).data);
+       (*_env)->SetByteArrayRegion(_env, arg_arr, 0, 32, (this_arg_conv->get_secure_random_bytes)(this_arg_conv->this_arg).data);
        return arg_arr;
 }
 
@@ -3058,8 +3072,8 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1g
        DO_ASSERT(ret != NULL);
        return ret;
 }
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1open_1channel(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong their_features, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1open_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong their_features, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKInitFeatures their_features_conv;
@@ -3068,11 +3082,11 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call
        LDKOpenChannel msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_open_channel)(arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
+       return (this_arg_conv->handle_open_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1accept_1channel(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong their_features, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1accept_1channel(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong their_features, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKInitFeatures their_features_conv;
@@ -3081,174 +3095,174 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call
        LDKAcceptChannel msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_accept_channel)(arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
+       return (this_arg_conv->handle_accept_channel)(this_arg_conv->this_arg, their_node_id_ref, their_features_conv, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1funding_1created(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1funding_1created(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKFundingCreated msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_funding_created)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_funding_created)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1funding_1signed(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1funding_1signed(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKFundingSigned msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_funding_signed)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_funding_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1funding_1locked(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1funding_1locked(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKFundingLocked msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_funding_locked)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_funding_locked)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1shutdown(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1shutdown(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKShutdown msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_shutdown)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_shutdown)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1closing_1signed(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1closing_1signed(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKClosingSigned msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_closing_signed)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_closing_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1update_1add_1htlc(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1update_1add_1htlc(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKUpdateAddHTLC msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_update_add_htlc)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_update_add_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1update_1fulfill_1htlc(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1update_1fulfill_1htlc(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKUpdateFulfillHTLC msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_update_fulfill_htlc)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_update_fulfill_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1update_1fail_1htlc(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1update_1fail_1htlc(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKUpdateFailHTLC msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_update_fail_htlc)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_update_fail_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1update_1fail_1malformed_1htlc(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1update_1fail_1malformed_1htlc(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKUpdateFailMalformedHTLC msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_update_fail_malformed_htlc)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_update_fail_malformed_htlc)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1commitment_1signed(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1commitment_1signed(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKCommitmentSigned msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_commitment_signed)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_commitment_signed)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1revoke_1and_1ack(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1revoke_1and_1ack(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKRevokeAndACK msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_revoke_and_ack)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_revoke_and_ack)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1update_1fee(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1update_1fee(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKUpdateFee msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_update_fee)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_update_fee)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1announcement_1signatures(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1announcement_1signatures(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKAnnouncementSignatures msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_announcement_signatures)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_announcement_signatures)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1peer_1disconnected(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jboolean no_connection_possible) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1peer_1disconnected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jboolean no_connection_possible) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
-       return (arg_conv->peer_disconnected)(arg_conv->this_arg, their_node_id_ref, no_connection_possible);
+       return (this_arg_conv->peer_disconnected)(this_arg_conv->this_arg, their_node_id_ref, no_connection_possible);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1peer_1connected(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1peer_1connected(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKInit msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->peer_connected)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->peer_connected)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1channel_1reestablish(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1channel_1reestablish(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKChannelReestablish msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_channel_reestablish)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_channel_reestablish)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1call_1handle_1error(JNIEnv * _env, jclass _b, jlong arg, jbyteArray their_node_id, jlong msg) {
-       LDKChannelMessageHandler* arg_conv = (LDKChannelMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelMessageHandler_1call_1handle_1error(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray their_node_id, jlong msg) {
+       LDKChannelMessageHandler* this_arg_conv = (LDKChannelMessageHandler*)this_arg;
        LDKPublicKey their_node_id_ref;
        (*_env)->GetByteArrayRegion (_env, their_node_id, 0, 33, their_node_id_ref.compressed_form);
        LDKErrorMessage msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
-       return (arg_conv->handle_error)(arg_conv->this_arg, their_node_id_ref, &msg_conv);
+       return (this_arg_conv->handle_error)(this_arg_conv->this_arg, their_node_id_ref, &msg_conv);
 }
 
 JNIEXPORT jlongArray JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1ChannelMonitor_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
@@ -3324,6 +3338,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateAddHTLC_1
                        LDKUpdateAddHTLC arr_elem_conv;
                        arr_elem_conv.inner = (void*)(arr_elem & (~1));
                        arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
+                       if (arr_elem_conv.inner != NULL)
+                               arr_elem_conv = UpdateAddHTLC_clone(&arr_elem_conv);
                        ret->data[i] = arr_elem_conv;
                }
                (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
@@ -3354,6 +3370,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFulfillHT
                        LDKUpdateFulfillHTLC arr_elem_conv;
                        arr_elem_conv.inner = (void*)(arr_elem & (~1));
                        arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
+                       if (arr_elem_conv.inner != NULL)
+                               arr_elem_conv = UpdateFulfillHTLC_clone(&arr_elem_conv);
                        ret->data[i] = arr_elem_conv;
                }
                (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
@@ -3384,6 +3402,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFailHTLC_
                        LDKUpdateFailHTLC arr_elem_conv;
                        arr_elem_conv.inner = (void*)(arr_elem & (~1));
                        arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
+                       if (arr_elem_conv.inner != NULL)
+                               arr_elem_conv = UpdateFailHTLC_clone(&arr_elem_conv);
                        ret->data[i] = arr_elem_conv;
                }
                (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
@@ -3414,6 +3434,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1UpdateFailMalfo
                        LDKUpdateFailMalformedHTLC arr_elem_conv;
                        arr_elem_conv.inner = (void*)(arr_elem & (~1));
                        arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
+                       if (arr_elem_conv.inner != NULL)
+                               arr_elem_conv = UpdateFailMalformedHTLC_clone(&arr_elem_conv);
                        ret->data[i] = arr_elem_conv;
                }
                (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
@@ -3477,6 +3499,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1NodeAnnouncemen
                        LDKNodeAnnouncement arr_elem_conv;
                        arr_elem_conv.inner = (void*)(arr_elem & (~1));
                        arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
+                       if (arr_elem_conv.inner != NULL)
+                               arr_elem_conv = NodeAnnouncement_clone(&arr_elem_conv);
                        ret->data[i] = arr_elem_conv;
                }
                (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
@@ -3629,63 +3653,63 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1g
        DO_ASSERT(ret != NULL);
        return ret;
 }
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1call_1handle_1node_1announcement(JNIEnv * _env, jclass _b, jlong arg, jlong msg) {
-       LDKRoutingMessageHandler* arg_conv = (LDKRoutingMessageHandler*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1call_1handle_1node_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
+       LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
        LDKNodeAnnouncement msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
        LDKCResult_boolLightningErrorZ* ret = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
-       *ret = (arg_conv->handle_node_announcement)(arg_conv->this_arg, &msg_conv);
+       *ret = (this_arg_conv->handle_node_announcement)(this_arg_conv->this_arg, &msg_conv);
        return (long)ret;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1call_1handle_1channel_1announcement(JNIEnv * _env, jclass _b, jlong arg, jlong msg) {
-       LDKRoutingMessageHandler* arg_conv = (LDKRoutingMessageHandler*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1call_1handle_1channel_1announcement(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
+       LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
        LDKChannelAnnouncement msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
        LDKCResult_boolLightningErrorZ* ret = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
-       *ret = (arg_conv->handle_channel_announcement)(arg_conv->this_arg, &msg_conv);
+       *ret = (this_arg_conv->handle_channel_announcement)(this_arg_conv->this_arg, &msg_conv);
        return (long)ret;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1call_1handle_1channel_1update(JNIEnv * _env, jclass _b, jlong arg, jlong msg) {
-       LDKRoutingMessageHandler* arg_conv = (LDKRoutingMessageHandler*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1call_1handle_1channel_1update(JNIEnv * _env, jclass _b, jlong this_arg, jlong msg) {
+       LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
        LDKChannelUpdate msg_conv;
        msg_conv.inner = (void*)(msg & (~1));
        msg_conv.is_owned = (msg & 1) || (msg == 0);
        LDKCResult_boolLightningErrorZ* ret = MALLOC(sizeof(LDKCResult_boolLightningErrorZ), "LDKCResult_boolLightningErrorZ");
-       *ret = (arg_conv->handle_channel_update)(arg_conv->this_arg, &msg_conv);
+       *ret = (this_arg_conv->handle_channel_update)(this_arg_conv->this_arg, &msg_conv);
        return (long)ret;
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1call_1handle_1htlc_1fail_1channel_1update(JNIEnv * _env, jclass _b, jlong arg, jlong update) {
-       LDKRoutingMessageHandler* arg_conv = (LDKRoutingMessageHandler*)arg;
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1call_1handle_1htlc_1fail_1channel_1update(JNIEnv * _env, jclass _b, jlong this_arg, jlong update) {
+       LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
        LDKHTLCFailChannelUpdate* update_conv = (LDKHTLCFailChannelUpdate*)update;
-       return (arg_conv->handle_htlc_fail_channel_update)(arg_conv->this_arg, update_conv);
+       return (this_arg_conv->handle_htlc_fail_channel_update)(this_arg_conv->this_arg, update_conv);
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1call_1get_1next_1channel_1announcements(JNIEnv * _env, jclass _b, jlong arg, jlong starting_point, jbyte batch_amount) {
-       LDKRoutingMessageHandler* arg_conv = (LDKRoutingMessageHandler*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1call_1get_1next_1channel_1announcements(JNIEnv * _env, jclass _b, jlong this_arg, jlong starting_point, jbyte batch_amount) {
+       LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
        LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ* ret = MALLOC(sizeof(LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ), "LDKCVec_C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZZ");
-       *ret = (arg_conv->get_next_channel_announcements)(arg_conv->this_arg, starting_point, batch_amount);
+       *ret = (this_arg_conv->get_next_channel_announcements)(this_arg_conv->this_arg, starting_point, batch_amount);
        return (long)ret;
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1call_1get_1next_1node_1announcements(JNIEnv * _env, jclass _b, jlong arg, jbyteArray starting_point, jbyte batch_amount) {
-       LDKRoutingMessageHandler* arg_conv = (LDKRoutingMessageHandler*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1call_1get_1next_1node_1announcements(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray starting_point, jbyte batch_amount) {
+       LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
        LDKPublicKey starting_point_ref;
        (*_env)->GetByteArrayRegion (_env, starting_point, 0, 33, starting_point_ref.compressed_form);
        LDKCVec_NodeAnnouncementZ* ret = MALLOC(sizeof(LDKCVec_NodeAnnouncementZ), "LDKCVec_NodeAnnouncementZ");
-       *ret = (arg_conv->get_next_node_announcements)(arg_conv->this_arg, starting_point_ref, batch_amount);
+       *ret = (this_arg_conv->get_next_node_announcements)(this_arg_conv->this_arg, starting_point_ref, batch_amount);
        return (long)ret;
 }
 
-JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1call_1should_1request_1full_1sync(JNIEnv * _env, jclass _b, jlong arg, jbyteArray node_id) {
-       LDKRoutingMessageHandler* arg_conv = (LDKRoutingMessageHandler*)arg;
+JNIEXPORT jboolean JNICALL Java_org_ldk_impl_bindings_RoutingMessageHandler_1call_1should_1request_1full_1sync(JNIEnv * _env, jclass _b, jlong this_arg, jbyteArray node_id) {
+       LDKRoutingMessageHandler* this_arg_conv = (LDKRoutingMessageHandler*)this_arg;
        LDKPublicKey node_id_ref;
        (*_env)->GetByteArrayRegion (_env, node_id, 0, 33, node_id_ref.compressed_form);
-       return (arg_conv->should_request_full_sync)(arg_conv->this_arg, node_id_ref);
+       return (this_arg_conv->should_request_full_sync)(this_arg_conv->this_arg, node_id_ref);
 }
 
 typedef struct LDKSocketDescriptor_JCalls {
@@ -3781,20 +3805,20 @@ JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1get_1o
        DO_ASSERT(ret != NULL);
        return ret;
 }
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1call_1send_1data(JNIEnv * _env, jclass _b, jlong arg, jlong data, jboolean resume_read) {
-       LDKSocketDescriptor* arg_conv = (LDKSocketDescriptor*)arg;
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1call_1send_1data(JNIEnv * _env, jclass _b, jlong this_arg, jlong data, jboolean resume_read) {
+       LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
        LDKu8slice data_conv = *(LDKu8slice*)data;
-       return (arg_conv->send_data)(arg_conv->this_arg, data_conv, resume_read);
+       return (this_arg_conv->send_data)(this_arg_conv->this_arg, data_conv, resume_read);
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1call_1disconnect_1socket(JNIEnv * _env, jclass _b, jlong arg) {
-       LDKSocketDescriptor* arg_conv = (LDKSocketDescriptor*)arg;
-       return (arg_conv->disconnect_socket)(arg_conv->this_arg);
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1call_1disconnect_1socket(JNIEnv * _env, jclass _b, jlong this_arg) {
+       LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
+       return (this_arg_conv->disconnect_socket)(this_arg_conv->this_arg);
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1call_1hash(JNIEnv * _env, jclass _b, jlong arg) {
-       LDKSocketDescriptor* arg_conv = (LDKSocketDescriptor*)arg;
-       return (arg_conv->hash)(arg_conv->this_arg);
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_SocketDescriptor_1call_1hash(JNIEnv * _env, jclass _b, jlong this_arg) {
+       LDKSocketDescriptor* this_arg_conv = (LDKSocketDescriptor*)this_arg;
+       return (this_arg_conv->hash)(this_arg_conv->this_arg);
 }
 
 JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1PublicKey_1arr_1info(JNIEnv *env, jclass _b, jlong ptr) {
@@ -3902,6 +3926,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKCVecTempl_1RouteHop_1new(J
                        LDKRouteHop arr_elem_conv;
                        arr_elem_conv.inner = (void*)(arr_elem & (~1));
                        arr_elem_conv.is_owned = (arr_elem & 1) || (arr_elem == 0);
+                       if (arr_elem_conv.inner != NULL)
+                               arr_elem_conv = RouteHop_clone(&arr_elem_conv);
                        ret->data[i] = arr_elem_conv;
                }
                (*env)->ReleasePrimitiveArrayCritical(env, elems, java_elems, 0);
@@ -4191,11 +4217,11 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1
        return CResult_SecretKeySecpErrorZ_free(arg_conv);
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1ok(JNIEnv * _env, jclass _b, jlong arg) {
-       LDKSecretKey arg_conv = *(LDKSecretKey*)arg;
-       FREE((void*)arg);
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CResult_1SecretKeySecpErrorZ_1ok(JNIEnv * _env, jclass _b, jbyteArray arg) {
+       LDKSecretKey arg_ref;
+       (*_env)->GetByteArrayRegion (_env, arg, 0, 32, arg_ref.bytes);
        LDKCResult_SecretKeySecpErrorZ* ret = MALLOC(sizeof(LDKCResult_SecretKeySecpErrorZ), "LDKCResult_SecretKeySecpErrorZ");
-       *ret = CResult_SecretKeySecpErrorZ_ok(arg_conv);
+       *ret = CResult_SecretKeySecpErrorZ_ok(arg_ref);
        return (long)ret;
 }
 
@@ -4489,6 +4515,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1OutPointScriptZ_1new
        LDKOutPoint a_conv;
        a_conv.inner = (void*)(a & (~1));
        a_conv.is_owned = (a & 1) || (a == 0);
+       if (a_conv.inner != NULL)
+               a_conv = OutPoint_clone(&a_conv);
        LDKCVec_u8Z b_conv = *(LDKCVec_u8Z*)b;
        FREE((void*)b);
        LDKC2Tuple_OutPointScriptZ* ret = MALLOC(sizeof(LDKC2Tuple_OutPointScriptZ), "LDKC2Tuple_OutPointScriptZ");
@@ -4556,12 +4584,18 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C3Tuple_1ChannelAnnouncementC
        LDKChannelAnnouncement a_conv;
        a_conv.inner = (void*)(a & (~1));
        a_conv.is_owned = (a & 1) || (a == 0);
+       if (a_conv.inner != NULL)
+               a_conv = ChannelAnnouncement_clone(&a_conv);
        LDKChannelUpdate b_conv;
        b_conv.inner = (void*)(b & (~1));
        b_conv.is_owned = (b & 1) || (b == 0);
+       if (b_conv.inner != NULL)
+               b_conv = ChannelUpdate_clone(&b_conv);
        LDKChannelUpdate c_conv;
        c_conv.inner = (void*)(c & (~1));
        c_conv.is_owned = (c & 1) || (c == 0);
+       if (c_conv.inner != NULL)
+               c_conv = ChannelUpdate_clone(&c_conv);
        LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ* ret = MALLOC(sizeof(LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ), "LDKC3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ");
        *ret = C3Tuple_ChannelAnnouncementChannelUpdateChannelUpdateZ_new(a_conv, b_conv, c_conv);
        return (long)ret;
@@ -4577,6 +4611,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_C2Tuple_1HTLCOutputInCommitme
        LDKHTLCOutputInCommitment a_conv;
        a_conv.inner = (void*)(a & (~1));
        a_conv.is_owned = (a & 1) || (a == 0);
+       if (a_conv.inner != NULL)
+               a_conv = HTLCOutputInCommitment_clone(&a_conv);
        LDKSignature b_conv = *(LDKSignature*)b;
        FREE((void*)b);
        LDKC2Tuple_HTLCOutputInCommitmentSignatureZ* ret = MALLOC(sizeof(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ), "LDKC2Tuple_HTLCOutputInCommitmentSignatureZ");
@@ -4969,6 +5005,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1own_1channel_
        LDKChannelHandshakeConfig val_conv;
        val_conv.inner = (void*)(val & (~1));
        val_conv.is_owned = (val & 1) || (val == 0);
+       if (val_conv.inner != NULL)
+               val_conv = ChannelHandshakeConfig_clone(&val_conv);
        return UserConfig_set_own_channel_config(&this_ptr_conv, val_conv);
 }
 
@@ -4987,6 +5025,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1peer_1channel
        LDKChannelHandshakeLimits val_conv;
        val_conv.inner = (void*)(val & (~1));
        val_conv.is_owned = (val & 1) || (val == 0);
+       if (val_conv.inner != NULL)
+               val_conv = ChannelHandshakeLimits_clone(&val_conv);
        return UserConfig_set_peer_channel_config_limits(&this_ptr_conv, val_conv);
 }
 
@@ -5005,6 +5045,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_UserConfig_1set_1channel_1opti
        LDKChannelConfig val_conv;
        val_conv.inner = (void*)(val & (~1));
        val_conv.is_owned = (val & 1) || (val == 0);
+       if (val_conv.inner != NULL)
+               val_conv = ChannelConfig_clone(&val_conv);
        return UserConfig_set_channel_options(&this_ptr_conv, val_conv);
 }
 
@@ -5012,12 +5054,18 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_UserConfig_1new(JNIEnv * _env
        LDKChannelHandshakeConfig own_channel_config_arg_conv;
        own_channel_config_arg_conv.inner = (void*)(own_channel_config_arg & (~1));
        own_channel_config_arg_conv.is_owned = (own_channel_config_arg & 1) || (own_channel_config_arg == 0);
+       if (own_channel_config_arg_conv.inner != NULL)
+               own_channel_config_arg_conv = ChannelHandshakeConfig_clone(&own_channel_config_arg_conv);
        LDKChannelHandshakeLimits peer_channel_config_limits_arg_conv;
        peer_channel_config_limits_arg_conv.inner = (void*)(peer_channel_config_limits_arg & (~1));
        peer_channel_config_limits_arg_conv.is_owned = (peer_channel_config_limits_arg & 1) || (peer_channel_config_limits_arg == 0);
+       if (peer_channel_config_limits_arg_conv.inner != NULL)
+               peer_channel_config_limits_arg_conv = ChannelHandshakeLimits_clone(&peer_channel_config_limits_arg_conv);
        LDKChannelConfig channel_options_arg_conv;
        channel_options_arg_conv.inner = (void*)(channel_options_arg & (~1));
        channel_options_arg_conv.is_owned = (channel_options_arg & 1) || (channel_options_arg == 0);
+       if (channel_options_arg_conv.inner != NULL)
+               channel_options_arg_conv = ChannelConfig_clone(&channel_options_arg_conv);
        LDKUserConfig ret = UserConfig_new(own_channel_config_arg_conv, peer_channel_config_limits_arg_conv, channel_options_arg_conv);
        return ((long)ret.inner) | (ret.is_owned ? 1 : 0);
 }
@@ -5227,6 +5275,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelMonitor_1update_1monit
        LDKChannelMonitorUpdate updates_conv;
        updates_conv.inner = (void*)(updates & (~1));
        updates_conv.is_owned = (updates & 1) || (updates == 0);
+       if (updates_conv.inner != NULL)
+               updates_conv = ChannelMonitorUpdate_clone(&updates_conv);
        LDKBroadcasterInterface* broadcaster_conv = (LDKBroadcasterInterface*)broadcaster;
        LDKLogger* logger_conv = (LDKLogger*)logger;
        LDKCResult_NoneMonitorUpdateErrorZ* ret = MALLOC(sizeof(LDKCResult_NoneMonitorUpdateErrorZ), "LDKCResult_NoneMonitorUpdateErrorZ");
@@ -5452,13 +5502,13 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get
        return ret_arr;
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1funding_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1funding_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
        LDKInMemoryChannelKeys this_ptr_conv;
        this_ptr_conv.inner = (void*)(this_ptr & (~1));
        this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
-       LDKSecretKey val_conv = *(LDKSecretKey*)val;
-       FREE((void*)val);
-       return InMemoryChannelKeys_set_funding_key(&this_ptr_conv, val_conv);
+       LDKSecretKey val_ref;
+       (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
+       return InMemoryChannelKeys_set_funding_key(&this_ptr_conv, val_ref);
 }
 
 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1revocation_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
@@ -5470,13 +5520,13 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get
        return ret_arr;
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1revocation_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1revocation_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
        LDKInMemoryChannelKeys this_ptr_conv;
        this_ptr_conv.inner = (void*)(this_ptr & (~1));
        this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
-       LDKSecretKey val_conv = *(LDKSecretKey*)val;
-       FREE((void*)val);
-       return InMemoryChannelKeys_set_revocation_base_key(&this_ptr_conv, val_conv);
+       LDKSecretKey val_ref;
+       (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
+       return InMemoryChannelKeys_set_revocation_base_key(&this_ptr_conv, val_ref);
 }
 
 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
@@ -5488,13 +5538,13 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get
        return ret_arr;
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1payment_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
        LDKInMemoryChannelKeys this_ptr_conv;
        this_ptr_conv.inner = (void*)(this_ptr & (~1));
        this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
-       LDKSecretKey val_conv = *(LDKSecretKey*)val;
-       FREE((void*)val);
-       return InMemoryChannelKeys_set_payment_key(&this_ptr_conv, val_conv);
+       LDKSecretKey val_ref;
+       (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
+       return InMemoryChannelKeys_set_payment_key(&this_ptr_conv, val_ref);
 }
 
 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1delayed_1payment_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
@@ -5506,13 +5556,13 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get
        return ret_arr;
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1delayed_1payment_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1delayed_1payment_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
        LDKInMemoryChannelKeys this_ptr_conv;
        this_ptr_conv.inner = (void*)(this_ptr & (~1));
        this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
-       LDKSecretKey val_conv = *(LDKSecretKey*)val;
-       FREE((void*)val);
-       return InMemoryChannelKeys_set_delayed_payment_base_key(&this_ptr_conv, val_conv);
+       LDKSecretKey val_ref;
+       (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
+       return InMemoryChannelKeys_set_delayed_payment_base_key(&this_ptr_conv, val_ref);
 }
 
 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1htlc_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr) {
@@ -5524,13 +5574,13 @@ JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get
        return ret_arr;
 }
 
-JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1htlc_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jlong val) {
+JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1htlc_1base_1key(JNIEnv * _env, jclass _b, jlong this_ptr, jbyteArray val) {
        LDKInMemoryChannelKeys this_ptr_conv;
        this_ptr_conv.inner = (void*)(this_ptr & (~1));
        this_ptr_conv.is_owned = (this_ptr & 1) || (this_ptr == 0);
-       LDKSecretKey val_conv = *(LDKSecretKey*)val;
-       FREE((void*)val);
-       return InMemoryChannelKeys_set_htlc_base_key(&this_ptr_conv, val_conv);
+       LDKSecretKey val_ref;
+       (*_env)->GetByteArrayRegion (_env, val, 0, 32, val_ref.bytes);
+       return InMemoryChannelKeys_set_htlc_base_key(&this_ptr_conv, val_ref);
 }
 
 JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1get_1commitment_1seed(JNIEnv * _env, jclass _b, jlong this_ptr) {
@@ -5551,22 +5601,22 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1set_1comm
        return InMemoryChannelKeys_set_commitment_seed(&this_ptr_conv, val_ref);
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1new(JNIEnv * _env, jclass _b, jlong funding_key, jlong revocation_base_key, jlong payment_key, jlong delayed_payment_base_key, jlong htlc_base_key, jbyteArray commitment_seed, jlong channel_value_satoshis, jlong key_derivation_params) {
-       LDKSecretKey funding_key_conv = *(LDKSecretKey*)funding_key;
-       FREE((void*)funding_key);
-       LDKSecretKey revocation_base_key_conv = *(LDKSecretKey*)revocation_base_key;
-       FREE((void*)revocation_base_key);
-       LDKSecretKey payment_key_conv = *(LDKSecretKey*)payment_key;
-       FREE((void*)payment_key);
-       LDKSecretKey delayed_payment_base_key_conv = *(LDKSecretKey*)delayed_payment_base_key;
-       FREE((void*)delayed_payment_base_key);
-       LDKSecretKey htlc_base_key_conv = *(LDKSecretKey*)htlc_base_key;
-       FREE((void*)htlc_base_key);
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_InMemoryChannelKeys_1new(JNIEnv * _env, jclass _b, jbyteArray funding_key, jbyteArray revocation_base_key, jbyteArray payment_key, jbyteArray delayed_payment_base_key, jbyteArray htlc_base_key, jbyteArray commitment_seed, jlong channel_value_satoshis, jlong key_derivation_params) {
+       LDKSecretKey funding_key_ref;
+       (*_env)->GetByteArrayRegion (_env, funding_key, 0, 32, funding_key_ref.bytes);
+       LDKSecretKey revocation_base_key_ref;
+       (*_env)->GetByteArrayRegion (_env, revocation_base_key, 0, 32, revocation_base_key_ref.bytes);
+       LDKSecretKey payment_key_ref;
+       (*_env)->GetByteArrayRegion (_env, payment_key, 0, 32, payment_key_ref.bytes);
+       LDKSecretKey delayed_payment_base_key_ref;
+       (*_env)->GetByteArrayRegion (_env, delayed_payment_base_key, 0, 32, delayed_payment_base_key_ref.bytes);
+       LDKSecretKey htlc_base_key_ref;
+       (*_env)->GetByteArrayRegion (_env, htlc_base_key, 0, 32, htlc_base_key_ref.bytes);
        LDKThirtyTwoBytes commitment_seed_ref;
        (*_env)->GetByteArrayRegion (_env, commitment_seed, 0, 32, commitment_seed_ref.data);
        LDKC2Tuple_u64u64Z key_derivation_params_conv = *(LDKC2Tuple_u64u64Z*)key_derivation_params;
        FREE((void*)key_derivation_params);
-       LDKInMemoryChannelKeys ret = InMemoryChannelKeys_new(funding_key_conv, revocation_base_key_conv, payment_key_conv, delayed_payment_base_key_conv, htlc_base_key_conv, commitment_seed_ref, channel_value_satoshis, key_derivation_params_conv);
+       LDKInMemoryChannelKeys ret = InMemoryChannelKeys_new(funding_key_ref, revocation_base_key_ref, payment_key_ref, delayed_payment_base_key_ref, htlc_base_key_ref, commitment_seed_ref, channel_value_satoshis, key_derivation_params_conv);
        return ((long)ret.inner) | (ret.is_owned ? 1 : 0);
 }
 
@@ -5824,6 +5874,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1new(JNIEnv *
        LDKUserConfig config_conv;
        config_conv.inner = (void*)(config & (~1));
        config_conv.is_owned = (config & 1) || (config == 0);
+       if (config_conv.inner != NULL)
+               config_conv = UserConfig_clone(&config_conv);
        LDKChannelManager ret = ChannelManager_new(network_conv, fee_est_conv, chain_monitor_conv, tx_broadcaster_conv, logger_conv, keys_manager_conv, config_conv, current_blockchain_height);
        return ((long)ret.inner) | (ret.is_owned ? 1 : 0);
 }
@@ -5837,6 +5889,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManager_1create_1chann
        LDKUserConfig override_config_conv;
        override_config_conv.inner = (void*)(override_config & (~1));
        override_config_conv.is_owned = (override_config & 1) || (override_config == 0);
+       if (override_config_conv.inner != NULL)
+               override_config_conv = UserConfig_clone(&override_config_conv);
        LDKCResult_NoneAPIErrorZ* ret = MALLOC(sizeof(LDKCResult_NoneAPIErrorZ), "LDKCResult_NoneAPIErrorZ");
        *ret = ChannelManager_create_channel(&this_arg_conv, their_network_key_ref, channel_value_satoshis, push_msat, user_id, override_config_conv);
        return (long)ret;
@@ -5915,6 +5969,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManager_1funding_1trans
        LDKOutPoint funding_txo_conv;
        funding_txo_conv.inner = (void*)(funding_txo & (~1));
        funding_txo_conv.is_owned = (funding_txo & 1) || (funding_txo == 0);
+       if (funding_txo_conv.inner != NULL)
+               funding_txo_conv = OutPoint_clone(&funding_txo_conv);
        return ChannelManager_funding_transaction_generated(&this_arg_conv, temporary_channel_id_ref, funding_txo_conv);
 }
 
@@ -6158,6 +6214,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1set_1d
        LDKUserConfig val_conv;
        val_conv.inner = (void*)(val & (~1));
        val_conv.is_owned = (val & 1) || (val == 0);
+       if (val_conv.inner != NULL)
+               val_conv = UserConfig_clone(&val_conv);
        return ChannelManagerReadArgs_set_default_config(&this_ptr_conv, val_conv);
 }
 
@@ -6190,6 +6248,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelManagerReadArgs_1new(J
        LDKUserConfig default_config_conv;
        default_config_conv.inner = (void*)(default_config & (~1));
        default_config_conv.is_owned = (default_config & 1) || (default_config == 0);
+       if (default_config_conv.inner != NULL)
+               default_config_conv = UserConfig_clone(&default_config_conv);
        LDKCVec_ChannelMonitorZ channel_monitors_conv = *(LDKCVec_ChannelMonitorZ*)channel_monitors;
        FREE((void*)channel_monitors);
        LDKChannelManagerReadArgs ret = ChannelManagerReadArgs_new(keys_manager_conv, fee_estimator_conv, chain_monitor_conv, tx_broadcaster_conv, logger_conv, default_config_conv, channel_monitors_conv);
@@ -8081,6 +8141,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1set_1content
        LDKUnsignedNodeAnnouncement val_conv;
        val_conv.inner = (void*)(val & (~1));
        val_conv.is_owned = (val & 1) || (val == 0);
+       if (val_conv.inner != NULL)
+               val_conv = UnsignedNodeAnnouncement_clone(&val_conv);
        return NodeAnnouncement_set_contents(&this_ptr_conv, val_conv);
 }
 
@@ -8090,6 +8152,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncement_1new(JNIEnv
        LDKUnsignedNodeAnnouncement contents_arg_conv;
        contents_arg_conv.inner = (void*)(contents_arg & (~1));
        contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
+       if (contents_arg_conv.inner != NULL)
+               contents_arg_conv = UnsignedNodeAnnouncement_clone(&contents_arg_conv);
        LDKNodeAnnouncement ret = NodeAnnouncement_new(signature_arg_conv, contents_arg_conv);
        return ((long)ret.inner) | (ret.is_owned ? 1 : 0);
 }
@@ -8333,6 +8397,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1set_1cont
        LDKUnsignedChannelAnnouncement val_conv;
        val_conv.inner = (void*)(val & (~1));
        val_conv.is_owned = (val & 1) || (val == 0);
+       if (val_conv.inner != NULL)
+               val_conv = UnsignedChannelAnnouncement_clone(&val_conv);
        return ChannelAnnouncement_set_contents(&this_ptr_conv, val_conv);
 }
 
@@ -8348,6 +8414,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelAnnouncement_1new(JNIE
        LDKUnsignedChannelAnnouncement contents_arg_conv;
        contents_arg_conv.inner = (void*)(contents_arg & (~1));
        contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
+       if (contents_arg_conv.inner != NULL)
+               contents_arg_conv = UnsignedChannelAnnouncement_clone(&contents_arg_conv);
        LDKChannelAnnouncement ret = ChannelAnnouncement_new(node_signature_1_arg_conv, node_signature_2_arg_conv, bitcoin_signature_1_arg_conv, bitcoin_signature_2_arg_conv, contents_arg_conv);
        return ((long)ret.inner) | (ret.is_owned ? 1 : 0);
 }
@@ -8531,6 +8599,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1set_1contents(J
        LDKUnsignedChannelUpdate val_conv;
        val_conv.inner = (void*)(val & (~1));
        val_conv.is_owned = (val & 1) || (val == 0);
+       if (val_conv.inner != NULL)
+               val_conv = UnsignedChannelUpdate_clone(&val_conv);
        return ChannelUpdate_set_contents(&this_ptr_conv, val_conv);
 }
 
@@ -8540,6 +8610,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_ChannelUpdate_1new(JNIEnv * _
        LDKUnsignedChannelUpdate contents_arg_conv;
        contents_arg_conv.inner = (void*)(contents_arg & (~1));
        contents_arg_conv.is_owned = (contents_arg & 1) || (contents_arg == 0);
+       if (contents_arg_conv.inner != NULL)
+               contents_arg_conv = UnsignedChannelUpdate_clone(&contents_arg_conv);
        LDKChannelUpdate ret = ChannelUpdate_new(signature_arg_conv, contents_arg_conv);
        return ((long)ret.inner) | (ret.is_owned ? 1 : 0);
 }
@@ -9002,6 +9074,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1update_
        LDKUpdateFee val_conv;
        val_conv.inner = (void*)(val & (~1));
        val_conv.is_owned = (val & 1) || (val == 0);
+       if (val_conv.inner != NULL)
+               val_conv = UpdateFee_clone(&val_conv);
        return CommitmentUpdate_set_update_fee(&this_ptr_conv, val_conv);
 }
 
@@ -9020,6 +9094,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1set_1commitm
        LDKCommitmentSigned val_conv;
        val_conv.inner = (void*)(val & (~1));
        val_conv.is_owned = (val & 1) || (val == 0);
+       if (val_conv.inner != NULL)
+               val_conv = CommitmentSigned_clone(&val_conv);
        return CommitmentUpdate_set_commitment_signed(&this_ptr_conv, val_conv);
 }
 
@@ -9035,9 +9111,13 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_CommitmentUpdate_1new(JNIEnv
        LDKUpdateFee update_fee_arg_conv;
        update_fee_arg_conv.inner = (void*)(update_fee_arg & (~1));
        update_fee_arg_conv.is_owned = (update_fee_arg & 1) || (update_fee_arg == 0);
+       if (update_fee_arg_conv.inner != NULL)
+               update_fee_arg_conv = UpdateFee_clone(&update_fee_arg_conv);
        LDKCommitmentSigned commitment_signed_arg_conv;
        commitment_signed_arg_conv.inner = (void*)(commitment_signed_arg & (~1));
        commitment_signed_arg_conv.is_owned = (commitment_signed_arg & 1) || (commitment_signed_arg == 0);
+       if (commitment_signed_arg_conv.inner != NULL)
+               commitment_signed_arg_conv = CommitmentSigned_clone(&commitment_signed_arg_conv);
        LDKCommitmentUpdate ret = CommitmentUpdate_new(update_add_htlcs_arg_conv, update_fulfill_htlcs_arg_conv, update_fail_htlcs_arg_conv, update_fail_malformed_htlcs_arg_conv, update_fee_arg_conv, commitment_signed_arg_conv);
        return ((long)ret.inner) | (ret.is_owned ? 1 : 0);
 }
@@ -9626,12 +9706,12 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_PeerManager_1free(JNIEnv * _en
        return PeerManager_free(this_ptr_conv);
 }
 
-JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1new(JNIEnv * _env, jclass _b, jlong message_handler, jlong our_node_secret, jbyteArray ephemeral_random_data, jlong logger) {
+JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1new(JNIEnv * _env, jclass _b, jlong message_handler, jbyteArray our_node_secret, jbyteArray ephemeral_random_data, jlong logger) {
        LDKMessageHandler message_handler_conv;
        message_handler_conv.inner = (void*)(message_handler & (~1));
        message_handler_conv.is_owned = (message_handler & 1) || (message_handler == 0);
-       LDKSecretKey our_node_secret_conv = *(LDKSecretKey*)our_node_secret;
-       FREE((void*)our_node_secret);
+       LDKSecretKey our_node_secret_ref;
+       (*_env)->GetByteArrayRegion (_env, our_node_secret, 0, 32, our_node_secret_ref.bytes);
        unsigned char ephemeral_random_data_arr[32];
        (*_env)->GetByteArrayRegion (_env, ephemeral_random_data, 0, 32, ephemeral_random_data_arr);
        unsigned char (*ephemeral_random_data_ref)[32] = &ephemeral_random_data_arr;
@@ -9640,7 +9720,7 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PeerManager_1new(JNIEnv * _en
                // If this_arg is a JCalls struct, then we need to increment the refcnt in it.
                LDKLogger_JCalls_clone(logger_conv.this_arg);
        }
-       LDKPeerManager ret = PeerManager_new(message_handler_conv, our_node_secret_conv, ephemeral_random_data_ref, logger_conv);
+       LDKPeerManager ret = PeerManager_new(message_handler_conv, our_node_secret_ref, ephemeral_random_data_ref, logger_conv);
        return ((long)ret.inner) | (ret.is_owned ? 1 : 0);
 }
 
@@ -9924,6 +10004,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_PreCalculatedTxCreationKeys_1
        LDKTxCreationKeys keys_conv;
        keys_conv.inner = (void*)(keys & (~1));
        keys_conv.is_owned = (keys & 1) || (keys == 0);
+       if (keys_conv.inner != NULL)
+               keys_conv = TxCreationKeys_clone(&keys_conv);
        LDKPreCalculatedTxCreationKeys ret = PreCalculatedTxCreationKeys_new(keys_conv);
        return ((long)ret.inner) | (ret.is_owned ? 1 : 0);
 }
@@ -10320,6 +10402,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_HolderCommitmentTransaction_1
        LDKTxCreationKeys keys_conv;
        keys_conv.inner = (void*)(keys & (~1));
        keys_conv.is_owned = (keys & 1) || (keys == 0);
+       if (keys_conv.inner != NULL)
+               keys_conv = TxCreationKeys_clone(&keys_conv);
        LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ htlc_data_conv = *(LDKCVec_C2Tuple_HTLCOutputInCommitmentSignatureZZ*)htlc_data;
        FREE((void*)htlc_data);
        LDKHolderCommitmentTransaction ret = HolderCommitmentTransaction_new_missing_holder_sig(unsigned_tx_conv, counterparty_sig_conv, holder_funding_key_ref, counterparty_funding_key_ref, keys_conv, feerate_per_kw, htlc_data_conv);
@@ -10628,6 +10712,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_RouteHint_1set_1fees(JNIEnv *
        LDKRoutingFees val_conv;
        val_conv.inner = (void*)(val & (~1));
        val_conv.is_owned = (val & 1) || (val == 0);
+       if (val_conv.inner != NULL)
+               val_conv = RoutingFees_clone(&val_conv);
        return RouteHint_set_fees(&this_ptr_conv, val_conv);
 }
 
@@ -10665,6 +10751,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_RouteHint_1new(JNIEnv * _env,
        LDKRoutingFees fees_arg_conv;
        fees_arg_conv.inner = (void*)(fees_arg & (~1));
        fees_arg_conv.is_owned = (fees_arg & 1) || (fees_arg == 0);
+       if (fees_arg_conv.inner != NULL)
+               fees_arg_conv = RoutingFees_clone(&fees_arg_conv);
        LDKRouteHint ret = RouteHint_new(src_node_id_arg_ref, short_channel_id_arg, fees_arg_conv, cltv_expiry_delta_arg, htlc_minimum_msat_arg);
        return ((long)ret.inner) | (ret.is_owned ? 1 : 0);
 }
@@ -10839,6 +10927,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_DirectionalChannelInfo_1set_1l
        LDKChannelUpdate val_conv;
        val_conv.inner = (void*)(val & (~1));
        val_conv.is_owned = (val & 1) || (val == 0);
+       if (val_conv.inner != NULL)
+               val_conv = ChannelUpdate_clone(&val_conv);
        return DirectionalChannelInfo_set_last_update_message(&this_ptr_conv, val_conv);
 }
 
@@ -10969,6 +11059,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_ChannelInfo_1set_1announcement
        LDKChannelAnnouncement val_conv;
        val_conv.inner = (void*)(val & (~1));
        val_conv.is_owned = (val & 1) || (val == 0);
+       if (val_conv.inner != NULL)
+               val_conv = ChannelAnnouncement_clone(&val_conv);
        return ChannelInfo_set_announcement_message(&this_ptr_conv, val_conv);
 }
 
@@ -11149,6 +11241,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1set_1ann
        LDKNodeAnnouncement val_conv;
        val_conv.inner = (void*)(val & (~1));
        val_conv.is_owned = (val & 1) || (val == 0);
+       if (val_conv.inner != NULL)
+               val_conv = NodeAnnouncement_clone(&val_conv);
        return NodeAnnouncementInfo_set_announcement_message(&this_ptr_conv, val_conv);
 }
 
@@ -11165,6 +11259,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeAnnouncementInfo_1new(JNI
        LDKNodeAnnouncement announcement_message_arg_conv;
        announcement_message_arg_conv.inner = (void*)(announcement_message_arg & (~1));
        announcement_message_arg_conv.is_owned = (announcement_message_arg & 1) || (announcement_message_arg == 0);
+       if (announcement_message_arg_conv.inner != NULL)
+               announcement_message_arg_conv = NodeAnnouncement_clone(&announcement_message_arg_conv);
        LDKNodeAnnouncementInfo ret = NodeAnnouncementInfo_new(features_arg_conv, last_update_arg, rgb_arg_conv, alias_arg_ref, addresses_arg_conv, announcement_message_arg_conv);
        return ((long)ret.inner) | (ret.is_owned ? 1 : 0);
 }
@@ -11215,6 +11311,8 @@ JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_NodeInfo_1set_1lowest_1inbound
        LDKRoutingFees val_conv;
        val_conv.inner = (void*)(val & (~1));
        val_conv.is_owned = (val & 1) || (val == 0);
+       if (val_conv.inner != NULL)
+               val_conv = RoutingFees_clone(&val_conv);
        return NodeInfo_set_lowest_inbound_channel_fees(&this_ptr_conv, val_conv);
 }
 
@@ -11242,6 +11340,8 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_NodeInfo_1new(JNIEnv * _env,
        LDKRoutingFees lowest_inbound_channel_fees_arg_conv;
        lowest_inbound_channel_fees_arg_conv.inner = (void*)(lowest_inbound_channel_fees_arg & (~1));
        lowest_inbound_channel_fees_arg_conv.is_owned = (lowest_inbound_channel_fees_arg & 1) || (lowest_inbound_channel_fees_arg == 0);
+       if (lowest_inbound_channel_fees_arg_conv.inner != NULL)
+               lowest_inbound_channel_fees_arg_conv = RoutingFees_clone(&lowest_inbound_channel_fees_arg_conv);
        LDKNodeAnnouncementInfo announcement_info_arg_conv;
        announcement_info_arg_conv.inner = (void*)(announcement_info_arg & (~1));
        announcement_info_arg_conv.is_owned = (announcement_info_arg & 1) || (announcement_info_arg == 0);