Merge pull request #119 from TheBlueMatt/main
[ldk-java] / src / main / java / org / ldk / structs / Confirm.java
index 67594fde1b66ccae89ae9d11c822f1a969ff79cc..4ecf6a8c3e4132c627ce55e746a220310ec4084f 100644 (file)
@@ -4,6 +4,8 @@ import org.ldk.impl.bindings;
 import org.ldk.enums.*;
 import org.ldk.util.*;
 import java.util.Arrays;
+import java.lang.ref.Reference;
+import javax.annotation.Nullable;
 
 /**
  * The `Confirm` trait is used to notify when transactions have been confirmed on chain or
@@ -66,16 +68,16 @@ public class Confirm extends CommonBase {
                 * in the event of a chain reorganization, it must not be called with a `header` that is no
                 * longer in the chain as of the last call to [`best_block_updated`].
                 * 
-                * [chain order]: Confirm#Order
+                * [chain order]: Confirm#order
                 * [`best_block_updated`]: Self::best_block_updated
                 */
-               void transactions_confirmed(byte[] header, TwoTuple<Long, byte[]>[] txdata, int height);
+               void transactions_confirmed(byte[] header, TwoTuple_usizeTransactionZ[] txdata, int height);
                /**
                 * Processes a transaction that is no longer confirmed as result of a chain reorganization.
                 * 
                 * Should be called for any transaction returned by [`get_relevant_txids`] if it has been
-                * reorganized out of the best chain. Once called, the given transaction should not be returned
-                * by [`get_relevant_txids`] unless it has been reconfirmed via [`transactions_confirmed`].
+                * reorganized out of the best chain. Once called, the given transaction will not be returned
+                * by [`get_relevant_txids`], unless it has been reconfirmed via [`transactions_confirmed`].
                 * 
                 * [`get_relevant_txids`]: Self::get_relevant_txids
                 * [`transactions_confirmed`]: Self::transactions_confirmed
@@ -91,9 +93,9 @@ public class Confirm extends CommonBase {
                /**
                 * Returns transactions that should be monitored for reorganization out of the chain.
                 * 
-                * Should include any transactions passed to [`transactions_confirmed`] that have insufficient
-                * confirmations to be safe from a chain reorganization. Should not include any transactions
-                * passed to [`transaction_unconfirmed`] unless later reconfirmed.
+                * Will include any transactions passed to [`transactions_confirmed`] that have insufficient
+                * confirmations to be safe from a chain reorganization. Will not include any transactions
+                * passed to [`transaction_unconfirmed`], unless later reconfirmed.
                 * 
                 * May be called to determine the subset of transactions that must still be monitored for
                 * reorganization. Will be idempotent between calls but may change as a result of calls to the
@@ -110,27 +112,30 @@ public class Confirm extends CommonBase {
                final LDKConfirmHolder impl_holder = new LDKConfirmHolder();
                impl_holder.held = new Confirm(new bindings.LDKConfirm() {
                        @Override public void transactions_confirmed(byte[] header, long[] txdata, int height) {
-                               TwoTuple<Long, byte[]>[] txdata_conv_24_arr = new TwoTuple[txdata.length];
-                               for (int y = 0; y < txdata.length; y++) {
-                                       long txdata_conv_24 = txdata[y];
-                                       long txdata_conv_24_a = bindings.LDKC2Tuple_usizeTransactionZ_get_a(txdata_conv_24);
-                                       byte[] txdata_conv_24_b = bindings.LDKC2Tuple_usizeTransactionZ_get_b(txdata_conv_24);
-                                       TwoTuple<Long, byte[]> txdata_conv_24_conv = new TwoTuple<Long, byte[]>(txdata_conv_24_a, txdata_conv_24_b, () -> {
-                                               bindings.C2Tuple_usizeTransactionZ_free(txdata_conv_24);
-                                       });
-                                       txdata_conv_24_arr[y] = txdata_conv_24_conv;
+                               int txdata_conv_28_len = txdata.length;
+                               TwoTuple_usizeTransactionZ[] txdata_conv_28_arr = new TwoTuple_usizeTransactionZ[txdata_conv_28_len];
+                               for (int c = 0; c < txdata_conv_28_len; c++) {
+                                       long txdata_conv_28 = txdata[c];
+                                       TwoTuple_usizeTransactionZ txdata_conv_28_hu_conv = new TwoTuple_usizeTransactionZ(null, txdata_conv_28);
+                                       if (txdata_conv_28_hu_conv != null) { txdata_conv_28_hu_conv.ptrs_to.add(this); };
+                                       txdata_conv_28_arr[c] = txdata_conv_28_hu_conv;
                                }
-                               arg.transactions_confirmed(header, txdata_conv_24_arr, height);
+                               arg.transactions_confirmed(header, txdata_conv_28_arr, height);
+                               Reference.reachabilityFence(arg);
                        }
                        @Override public void transaction_unconfirmed(byte[] txid) {
                                arg.transaction_unconfirmed(txid);
+                               Reference.reachabilityFence(arg);
                        }
                        @Override public void best_block_updated(byte[] header, int height) {
                                arg.best_block_updated(header, height);
+                               Reference.reachabilityFence(arg);
                        }
                        @Override public byte[][] get_relevant_txids() {
                                byte[][] ret = arg.get_relevant_txids();
-                               return ret;
+                               Reference.reachabilityFence(arg);
+                               byte[][] result = ret != null ? Arrays.stream(ret).map(ret_conv_8 -> InternalUtils.check_arr_len(ret_conv_8, 32)).toArray(byte[][]::new) : null;
+                               return result;
                        }
                });
                return impl_holder.held;
@@ -147,26 +152,31 @@ public class Confirm extends CommonBase {
         * in the event of a chain reorganization, it must not be called with a `header` that is no
         * longer in the chain as of the last call to [`best_block_updated`].
         * 
-        * [chain order]: Confirm#Order
+        * [chain order]: Confirm#order
         * [`best_block_updated`]: Self::best_block_updated
         */
-       public void transactions_confirmed(byte[] header, TwoTuple<Long, byte[]>[] txdata, int height) {
-               bindings.Confirm_transactions_confirmed(this.ptr, header, Arrays.stream(txdata).mapToLong(txdata_conv_24 -> bindings.C2Tuple_usizeTransactionZ_new(txdata_conv_24.a, txdata_conv_24.b)).toArray(), height);
-               /* TODO 2 TwoTuple<Long, byte[]>  */;
+       public void transactions_confirmed(byte[] header, TwoTuple_usizeTransactionZ[] txdata, int height) {
+               bindings.Confirm_transactions_confirmed(this.ptr, InternalUtils.check_arr_len(header, 80), txdata != null ? Arrays.stream(txdata).mapToLong(txdata_conv_28 -> txdata_conv_28 != null ? txdata_conv_28.ptr : 0).toArray() : null, height);
+               Reference.reachabilityFence(this);
+               Reference.reachabilityFence(header);
+               Reference.reachabilityFence(txdata);
+               Reference.reachabilityFence(height);
        }
 
        /**
         * Processes a transaction that is no longer confirmed as result of a chain reorganization.
         * 
         * Should be called for any transaction returned by [`get_relevant_txids`] if it has been
-        * reorganized out of the best chain. Once called, the given transaction should not be returned
-        * by [`get_relevant_txids`] unless it has been reconfirmed via [`transactions_confirmed`].
+        * reorganized out of the best chain. Once called, the given transaction will not be returned
+        * by [`get_relevant_txids`], unless it has been reconfirmed via [`transactions_confirmed`].
         * 
         * [`get_relevant_txids`]: Self::get_relevant_txids
         * [`transactions_confirmed`]: Self::transactions_confirmed
         */
        public void transaction_unconfirmed(byte[] txid) {
-               bindings.Confirm_transaction_unconfirmed(this.ptr, txid);
+               bindings.Confirm_transaction_unconfirmed(this.ptr, InternalUtils.check_arr_len(txid, 32));
+               Reference.reachabilityFence(this);
+               Reference.reachabilityFence(txid);
        }
 
        /**
@@ -176,15 +186,18 @@ public class Confirm extends CommonBase {
         * if they become available at the same time.
         */
        public void best_block_updated(byte[] header, int height) {
-               bindings.Confirm_best_block_updated(this.ptr, header, height);
+               bindings.Confirm_best_block_updated(this.ptr, InternalUtils.check_arr_len(header, 80), height);
+               Reference.reachabilityFence(this);
+               Reference.reachabilityFence(header);
+               Reference.reachabilityFence(height);
        }
 
        /**
         * Returns transactions that should be monitored for reorganization out of the chain.
         * 
-        * Should include any transactions passed to [`transactions_confirmed`] that have insufficient
-        * confirmations to be safe from a chain reorganization. Should not include any transactions
-        * passed to [`transaction_unconfirmed`] unless later reconfirmed.
+        * Will include any transactions passed to [`transactions_confirmed`] that have insufficient
+        * confirmations to be safe from a chain reorganization. Will not include any transactions
+        * passed to [`transaction_unconfirmed`], unless later reconfirmed.
         * 
         * May be called to determine the subset of transactions that must still be monitored for
         * reorganization. Will be idempotent between calls but may change as a result of calls to the
@@ -196,6 +209,7 @@ public class Confirm extends CommonBase {
         */
        public byte[][] get_relevant_txids() {
                byte[][] ret = bindings.Confirm_get_relevant_txids(this.ptr);
+               Reference.reachabilityFence(this);
                return ret;
        }