]> git.bitcoin.ninja Git - ldk-java/commitdiff
Add ability to get serialized transaction bytes
authorMatt Corallo <git@bluematt.me>
Fri, 23 Oct 2020 20:55:57 +0000 (16:55 -0400)
committerMatt Corallo <git@bluematt.me>
Fri, 23 Oct 2020 20:55:57 +0000 (16:55 -0400)
genbindings.py
src/main/java/org/ldk/impl/bindings.java
src/main/java/org/ldk/structs/Transaction.java
src/main/jni/bindings.c
src/main/jni/org_ldk_impl_bindings.h

index 22bca7cb4fd11262731c339436ea11c7e3d4ae00..3283b30793d7722f861e0c6c772a381d84dca1bc 100755 (executable)
@@ -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:
index d62f0866a3aa00f92ae31df025348f3991fddef4..140c58ad6892c58b651aaae3270aef91d1474327 100644 (file)
@@ -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();
 
index 91f19373f90011c8c9ff14db7f19b63007e03830..9c90b3c02cf01b9ce672275e8fa8310e127b5cb7 100644 (file)
@@ -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
index ed414a5d1b1c46da7c0e65afe14b4e213426e69a..27a8e615bd3eb613f93b459aa172d3a62cbee3ed 100644 (file)
@@ -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);
index cde70db81b9d2a5e6d89302d15492a8c1180a03f..0f706f4e9ba637e45d3c572a4f4bbd827102f28c 100644 (file)
@@ -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