From: Matt Corallo Date: Tue, 6 Oct 2020 00:53:46 +0000 (-0400) Subject: Add ability to get the Java object underlying a _JCalls struct X-Git-Tag: v0.0.1~139 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=0e0ec2d985336ee40f433576744728f4e14c6112;p=ldk-java Add ability to get the Java object underlying a _JCalls struct --- diff --git a/genbindings.py b/genbindings.py index 07de75e8..8c7e7378 100755 --- a/genbindings.py +++ b/genbindings.py @@ -446,6 +446,10 @@ with open(sys.argv[1]) as in_h, open(sys.argv[2], "w") as out_java, open(sys.arg out_c.write("\treturn (long)res_ptr;\n") out_c.write("}\n") + out_java.write("\tpublic static native " + struct_name + " " + struct_name + "_get_obj_from_jcalls(long val);\n") + out_c.write("JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_" + struct_name.replace("_", "_1") + "_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) {\n") + out_c.write("\treturn ((" + struct_name + "_JCalls*)val)->o;\n") + out_c.write("}\n") out_java.write("""package org.ldk.impl; diff --git a/src/main/java/org/ldk/impl/bindings.java b/src/main/java/org/ldk/impl/bindings.java index 3812dff6..b57129d3 100644 --- a/src/main/java/org/ldk/impl/bindings.java +++ b/src/main/java/org/ldk/impl/bindings.java @@ -50,18 +50,22 @@ public class bindings { long get_and_clear_pending_msg_events(); } public static native long LDKMessageSendEventsProvider_new(LDKMessageSendEventsProvider impl); + public static native LDKMessageSendEventsProvider LDKMessageSendEventsProvider_get_obj_from_jcalls(long val); public interface LDKEventsProvider { long get_and_clear_pending_events(); } public static native long LDKEventsProvider_new(LDKEventsProvider impl); + public static native LDKEventsProvider LDKEventsProvider_get_obj_from_jcalls(long val); public interface LDKLogger { void log(String record); } public static native long LDKLogger_new(LDKLogger impl); + public static native LDKLogger LDKLogger_get_obj_from_jcalls(long val); public interface LDKAccess { long get_utxo(byte[] genesis_hash, long short_channel_id); } public static native long LDKAccess_new(LDKAccess impl); + public static native LDKAccess LDKAccess_get_obj_from_jcalls(long val); public interface LDKChannelKeys { long get_per_commitment_point(long idx); long release_commitment_secret(long idx); @@ -76,25 +80,30 @@ public class bindings { void on_accept(long channel_points, short counterparty_selected_contest_delay, short holder_selected_contest_delay); } public static native long LDKChannelKeys_new(LDKChannelKeys impl); + public static native LDKChannelKeys LDKChannelKeys_get_obj_from_jcalls(long val); public interface LDKWatch { long watch_channel(long funding_txo, long monitor); long update_channel(long funding_txo, long update); long release_pending_monitor_events(); } public static native long LDKWatch_new(LDKWatch impl); + public static native LDKWatch LDKWatch_get_obj_from_jcalls(long val); public interface LDKFilter { void register_tx(byte[] txid, long script_pubkey); void register_output(long outpoint, long script_pubkey); } public static native long LDKFilter_new(LDKFilter impl); + public static native LDKFilter LDKFilter_get_obj_from_jcalls(long val); public interface LDKBroadcasterInterface { void broadcast_transaction(long tx); } public static native long LDKBroadcasterInterface_new(LDKBroadcasterInterface impl); + public static native LDKBroadcasterInterface LDKBroadcasterInterface_get_obj_from_jcalls(long val); public interface LDKFeeEstimator { int get_est_sat_per_1000_weight(LDKConfirmationTarget confirmation_target); } public static native long LDKFeeEstimator_new(LDKFeeEstimator impl); + public static native LDKFeeEstimator LDKFeeEstimator_get_obj_from_jcalls(long val); public interface LDKKeysInterface { long get_node_secret(); long get_destination_script(); @@ -103,6 +112,7 @@ public class bindings { long get_secure_random_bytes(); } public static native long LDKKeysInterface_new(LDKKeysInterface impl); + public static native LDKKeysInterface LDKKeysInterface_get_obj_from_jcalls(long val); public interface LDKChannelMessageHandler { void handle_open_channel(long their_node_id, long their_features, long msg); void handle_accept_channel(long their_node_id, long their_features, long msg); @@ -125,6 +135,7 @@ public class bindings { void handle_error(long their_node_id, long msg); } public static native long LDKChannelMessageHandler_new(LDKChannelMessageHandler impl, LDKMessageSendEventsProvider MessageSendEventsProvider); + public static native LDKChannelMessageHandler LDKChannelMessageHandler_get_obj_from_jcalls(long val); public interface LDKRoutingMessageHandler { long handle_node_announcement(long msg); long handle_channel_announcement(long msg); @@ -135,6 +146,7 @@ public class bindings { boolean should_request_full_sync(long node_id); } public static native long LDKRoutingMessageHandler_new(LDKRoutingMessageHandler impl); + public static native LDKRoutingMessageHandler LDKRoutingMessageHandler_get_obj_from_jcalls(long val); public interface LDKSocketDescriptor { long send_data(long data, boolean resume_read); void disconnect_socket(); @@ -142,6 +154,7 @@ public class bindings { long hash(); } public static native long LDKSocketDescriptor_new(LDKSocketDescriptor impl); + public static native LDKSocketDescriptor LDKSocketDescriptor_get_obj_from_jcalls(long val); /// extern const void (*C2Tuple_HTLCOutputInCommitmentSignatureZ_free)(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ); public static native void C2Tuple_HTLCOutputInCommitmentSignatureZ_free(long arg); /// extern const void (*C2Tuple_OutPointScriptZ_free)(LDKC2Tuple_OutPointScriptZ); diff --git a/src/main/jni/bindings.c b/src/main/jni/bindings.c index b06a370f..d5a01775 100644 --- a/src/main/jni/bindings.c +++ b/src/main/jni/bindings.c @@ -299,6 +299,9 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1 *res_ptr = LDKMessageSendEventsProvider_init(env, _a, o); return (long)res_ptr; } +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) { + return ((LDKMessageSendEventsProvider_JCalls*)val)->o; +} typedef struct LDKEventsProvider_JCalls { atomic_size_t refcnt; JNIEnv *env; @@ -346,6 +349,9 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1new (JNIEnv *res_ptr = LDKEventsProvider_init(env, _a, o); return (long)res_ptr; } +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) { + return ((LDKEventsProvider_JCalls*)val)->o; +} typedef struct LDKLogger_JCalls { atomic_size_t refcnt; JNIEnv *env; @@ -391,6 +397,9 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKLogger_1new (JNIEnv * env, *res_ptr = LDKLogger_init(env, _a, o); return (long)res_ptr; } +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKLogger_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) { + return ((LDKLogger_JCalls*)val)->o; +} typedef struct LDKAccess_JCalls { atomic_size_t refcnt; JNIEnv *env; @@ -440,6 +449,9 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKAccess_1new (JNIEnv * env, *res_ptr = LDKAccess_init(env, _a, o); return (long)res_ptr; } +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAccess_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) { + return ((LDKAccess_JCalls*)val)->o; +} typedef struct LDKChannelKeys_JCalls { atomic_size_t refcnt; JNIEnv *env; @@ -597,6 +609,9 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1new (JNIEnv * *res_ptr = LDKChannelKeys_init(env, _a, o); return (long)res_ptr; } +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) { + return ((LDKChannelKeys_JCalls*)val)->o; +} typedef struct LDKWatch_JCalls { atomic_size_t refcnt; JNIEnv *env; @@ -666,6 +681,9 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKWatch_1new (JNIEnv * env, j *res_ptr = LDKWatch_init(env, _a, o); return (long)res_ptr; } +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKWatch_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) { + return ((LDKWatch_JCalls*)val)->o; +} typedef struct LDKFilter_JCalls { atomic_size_t refcnt; JNIEnv *env; @@ -720,6 +738,9 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFilter_1new (JNIEnv * env, *res_ptr = LDKFilter_init(env, _a, o); return (long)res_ptr; } +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFilter_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) { + return ((LDKFilter_JCalls*)val)->o; +} typedef struct LDKBroadcasterInterface_JCalls { atomic_size_t refcnt; JNIEnv *env; @@ -764,6 +785,9 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1new ( *res_ptr = LDKBroadcasterInterface_init(env, _a, o); return (long)res_ptr; } +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) { + return ((LDKBroadcasterInterface_JCalls*)val)->o; +} typedef struct LDKFeeEstimator_JCalls { atomic_size_t refcnt; JNIEnv *env; @@ -809,6 +833,9 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1new (JNIEnv * *res_ptr = LDKFeeEstimator_init(env, _a, o); return (long)res_ptr; } +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) { + return ((LDKFeeEstimator_JCalls*)val)->o; +} typedef struct LDKKeysInterface_JCalls { atomic_size_t refcnt; JNIEnv *env; @@ -900,6 +927,9 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1new (JNIEnv *res_ptr = LDKKeysInterface_init(env, _a, o); return (long)res_ptr; } +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) { + return ((LDKKeysInterface_JCalls*)val)->o; +} typedef struct LDKChannelMessageHandler_JCalls { atomic_size_t refcnt; JNIEnv *env; @@ -1092,6 +1122,9 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1new *res_ptr = LDKChannelMessageHandler_init(env, _a, o, MessageSendEventsProvider); return (long)res_ptr; } +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) { + return ((LDKChannelMessageHandler_JCalls*)val)->o; +} typedef struct LDKRoutingMessageHandler_JCalls { atomic_size_t refcnt; JNIEnv *env; @@ -1199,6 +1232,9 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1new *res_ptr = LDKRoutingMessageHandler_init(env, _a, o); return (long)res_ptr; } +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) { + return ((LDKRoutingMessageHandler_JCalls*)val)->o; +} typedef struct LDKSocketDescriptor_JCalls { atomic_size_t refcnt; JNIEnv *env; @@ -1268,6 +1304,9 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1new (JNIE *res_ptr = LDKSocketDescriptor_init(env, _a, o); return (long)res_ptr; } +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1get_1obj_1from_1jcalls (JNIEnv * env, jclass _a, jlong val) { + return ((LDKSocketDescriptor_JCalls*)val)->o; +} JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_C2Tuple_1HTLCOutputInCommitmentSignatureZ_1free(JNIEnv * _env, jclass _b, jlong arg) { LDKC2Tuple_HTLCOutputInCommitmentSignatureZ arg_conv = *(LDKC2Tuple_HTLCOutputInCommitmentSignatureZ*)arg; FREE((void*)arg); diff --git a/src/main/jni/org_ldk_impl_bindings.h b/src/main/jni/org_ldk_impl_bindings.h index c159fb7e..0a93322a 100644 --- a/src/main/jni/org_ldk_impl_bindings.h +++ b/src/main/jni/org_ldk_impl_bindings.h @@ -31,6 +31,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKSecretKey_1new JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1new (JNIEnv *, jclass, jobject); +/* + * Class: org_ldk_impl_bindings + * Method: LDKMessageSendEventsProvider_get_obj_from_jcalls + * Signature: (J)Lorg/ldk/impl/bindings/LDKMessageSendEventsProvider; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_1get_1obj_1from_1jcalls + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: LDKEventsProvider_new @@ -39,6 +47,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKMessageSendEventsProvider_ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1new (JNIEnv *, jclass, jobject); +/* + * Class: org_ldk_impl_bindings + * Method: LDKEventsProvider_get_obj_from_jcalls + * Signature: (J)Lorg/ldk/impl/bindings/LDKEventsProvider; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1get_1obj_1from_1jcalls + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: LDKLogger_new @@ -47,6 +63,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKEventsProvider_1new JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKLogger_1new (JNIEnv *, jclass, jobject); +/* + * Class: org_ldk_impl_bindings + * Method: LDKLogger_get_obj_from_jcalls + * Signature: (J)Lorg/ldk/impl/bindings/LDKLogger; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKLogger_1get_1obj_1from_1jcalls + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: LDKAccess_new @@ -55,6 +79,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKLogger_1new JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKAccess_1new (JNIEnv *, jclass, jobject); +/* + * Class: org_ldk_impl_bindings + * Method: LDKAccess_get_obj_from_jcalls + * Signature: (J)Lorg/ldk/impl/bindings/LDKAccess; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKAccess_1get_1obj_1from_1jcalls + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: LDKChannelKeys_new @@ -63,6 +95,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKAccess_1new JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1new (JNIEnv *, jclass, jobject); +/* + * Class: org_ldk_impl_bindings + * Method: LDKChannelKeys_get_obj_from_jcalls + * Signature: (J)Lorg/ldk/impl/bindings/LDKChannelKeys; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1get_1obj_1from_1jcalls + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: LDKWatch_new @@ -71,6 +111,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelKeys_1new JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKWatch_1new (JNIEnv *, jclass, jobject); +/* + * Class: org_ldk_impl_bindings + * Method: LDKWatch_get_obj_from_jcalls + * Signature: (J)Lorg/ldk/impl/bindings/LDKWatch; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKWatch_1get_1obj_1from_1jcalls + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: LDKFilter_new @@ -79,6 +127,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKWatch_1new JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKFilter_1new (JNIEnv *, jclass, jobject); +/* + * Class: org_ldk_impl_bindings + * Method: LDKFilter_get_obj_from_jcalls + * Signature: (J)Lorg/ldk/impl/bindings/LDKFilter; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFilter_1get_1obj_1from_1jcalls + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: LDKBroadcasterInterface_new @@ -87,6 +143,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKFilter_1new JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1new (JNIEnv *, jclass, jobject); +/* + * Class: org_ldk_impl_bindings + * Method: LDKBroadcasterInterface_get_obj_from_jcalls + * Signature: (J)Lorg/ldk/impl/bindings/LDKBroadcasterInterface; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1get_1obj_1from_1jcalls + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: LDKFeeEstimator_new @@ -95,6 +159,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKBroadcasterInterface_1new JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1new (JNIEnv *, jclass, jobject); +/* + * Class: org_ldk_impl_bindings + * Method: LDKFeeEstimator_get_obj_from_jcalls + * Signature: (J)Lorg/ldk/impl/bindings/LDKFeeEstimator; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1get_1obj_1from_1jcalls + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: LDKKeysInterface_new @@ -103,6 +175,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKFeeEstimator_1new JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1new (JNIEnv *, jclass, jobject); +/* + * Class: org_ldk_impl_bindings + * Method: LDKKeysInterface_get_obj_from_jcalls + * Signature: (J)Lorg/ldk/impl/bindings/LDKKeysInterface; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1get_1obj_1from_1jcalls + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: LDKChannelMessageHandler_new @@ -111,6 +191,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKKeysInterface_1new JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1new (JNIEnv *, jclass, jobject, jobject); +/* + * Class: org_ldk_impl_bindings + * Method: LDKChannelMessageHandler_get_obj_from_jcalls + * Signature: (J)Lorg/ldk/impl/bindings/LDKChannelMessageHandler; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1get_1obj_1from_1jcalls + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: LDKRoutingMessageHandler_new @@ -119,6 +207,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKChannelMessageHandler_1new JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1new (JNIEnv *, jclass, jobject); +/* + * Class: org_ldk_impl_bindings + * Method: LDKRoutingMessageHandler_get_obj_from_jcalls + * Signature: (J)Lorg/ldk/impl/bindings/LDKRoutingMessageHandler; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1get_1obj_1from_1jcalls + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: LDKSocketDescriptor_new @@ -127,6 +223,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKRoutingMessageHandler_1new JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1new (JNIEnv *, jclass, jobject); +/* + * Class: org_ldk_impl_bindings + * Method: LDKSocketDescriptor_get_obj_from_jcalls + * Signature: (J)Lorg/ldk/impl/bindings/LDKSocketDescriptor; + */ +JNIEXPORT jobject JNICALL Java_org_ldk_impl_bindings_LDKSocketDescriptor_1get_1obj_1from_1jcalls + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: C2Tuple_HTLCOutputInCommitmentSignatureZ_free