From: Matt Corallo Date: Fri, 23 Oct 2020 20:55:57 +0000 (-0400) Subject: Add ability to get serialized transaction bytes X-Git-Tag: v0.0.1~88 X-Git-Url: http://git.bitcoin.ninja/?a=commitdiff_plain;h=00002bc824325a7a1310027da9f39541fd8e14ff;p=ldk-java Add ability to get serialized transaction bytes --- diff --git a/genbindings.py b/genbindings.py index 22bca7cb..3283b307 100755 --- a/genbindings.py +++ b/genbindings.py @@ -1447,6 +1447,7 @@ public class bindings { public static native long bytes_to_u8_vec(byte[] bytes); public static native long new_txpointer_copy_data(byte[] txdata); public static native void txpointer_free(long ptr); + public static native byte[] txpointer_get_buffer(long ptr); public static native long vec_slice_len(long vec); public static native long new_empty_slice_vec(); @@ -1491,6 +1492,13 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec (JNIEnv * _ (*_env)->GetByteArrayRegion (_env, bytes, 0, vec->datalen, vec->data); return (long)vec; } +JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_txpointer_1get_1buffer (JNIEnv * env, jclass _b, jlong ptr) { + LDKTransaction *txdata = (LDKTransaction*)ptr; + LDKu8slice slice; + slice.data = txdata->data; + slice.datalen = txdata->datalen; + return Java_org_ldk_impl_bindings_get_1u8_1slice_1bytes(env, _b, (long)&slice); +} JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data (JNIEnv * env, jclass _b, jbyteArray bytes) { LDKTransaction *txdata = (LDKTransaction*)MALLOC(sizeof(LDKTransaction), "LDKTransaction"); txdata->datalen = (*env)->GetArrayLength(env, bytes); @@ -1763,6 +1771,7 @@ class CommonBase { out_java_struct.write("\tTransaction(java.lang.Object _dummy, long ptr) { super(ptr); }\n") out_java_struct.write("\tpublic Transaction(byte[] data) { super(bindings.new_txpointer_copy_data(data)); }\n") out_java_struct.write("\t@Override public void finalize() throws Throwable { super.finalize(); bindings.txpointer_free(ptr); }\n") + out_java_struct.write("\tpublic byte[] get_contents() { return bindings.txpointer_get_buffer(ptr); }\n") # TODO: Transaction body out_java_struct.write("}") else: diff --git a/src/main/java/org/ldk/impl/bindings.java b/src/main/java/org/ldk/impl/bindings.java index d62f0866..140c58ad 100644 --- a/src/main/java/org/ldk/impl/bindings.java +++ b/src/main/java/org/ldk/impl/bindings.java @@ -24,6 +24,7 @@ public class bindings { public static native long bytes_to_u8_vec(byte[] bytes); public static native long new_txpointer_copy_data(byte[] txdata); public static native void txpointer_free(long ptr); + public static native byte[] txpointer_get_buffer(long ptr); public static native long vec_slice_len(long vec); public static native long new_empty_slice_vec(); diff --git a/src/main/java/org/ldk/structs/Transaction.java b/src/main/java/org/ldk/structs/Transaction.java index 91f19373..9c90b3c0 100644 --- a/src/main/java/org/ldk/structs/Transaction.java +++ b/src/main/java/org/ldk/structs/Transaction.java @@ -10,4 +10,5 @@ public class Transaction extends CommonBase{ Transaction(java.lang.Object _dummy, long ptr) { super(ptr); } public Transaction(byte[] data) { super(bindings.new_txpointer_copy_data(data)); } @Override public void finalize() throws Throwable { super.finalize(); bindings.txpointer_free(ptr); } + public byte[] get_contents() { return bindings.txpointer_get_buffer(ptr); } } \ No newline at end of file diff --git a/src/main/jni/bindings.c b/src/main/jni/bindings.c index ed414a5d..27a8e615 100644 --- a/src/main/jni/bindings.c +++ b/src/main/jni/bindings.c @@ -152,6 +152,13 @@ JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_bytes_1to_1u8_1vec (JNIEnv * _ (*_env)->GetByteArrayRegion (_env, bytes, 0, vec->datalen, vec->data); return (long)vec; } +JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_txpointer_1get_1buffer (JNIEnv * env, jclass _b, jlong ptr) { + LDKTransaction *txdata = (LDKTransaction*)ptr; + LDKu8slice slice; + slice.data = txdata->data; + slice.datalen = txdata->datalen; + return Java_org_ldk_impl_bindings_get_1u8_1slice_1bytes(env, _b, (long)&slice); +} JNIEXPORT long JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data (JNIEnv * env, jclass _b, jbyteArray bytes) { LDKTransaction *txdata = (LDKTransaction*)MALLOC(sizeof(LDKTransaction), "LDKTransaction"); txdata->datalen = (*env)->GetArrayLength(env, bytes); diff --git a/src/main/jni/org_ldk_impl_bindings.h b/src/main/jni/org_ldk_impl_bindings.h index cde70db8..0f706f4e 100644 --- a/src/main/jni/org_ldk_impl_bindings.h +++ b/src/main/jni/org_ldk_impl_bindings.h @@ -79,6 +79,14 @@ JNIEXPORT jlong JNICALL Java_org_ldk_impl_bindings_new_1txpointer_1copy_1data JNIEXPORT void JNICALL Java_org_ldk_impl_bindings_txpointer_1free (JNIEnv *, jclass, jlong); +/* + * Class: org_ldk_impl_bindings + * Method: txpointer_get_buffer + * Signature: (J)[B + */ +JNIEXPORT jbyteArray JNICALL Java_org_ldk_impl_bindings_txpointer_1get_1buffer + (JNIEnv *, jclass, jlong); + /* * Class: org_ldk_impl_bindings * Method: vec_slice_len