Update auto-generated bindings
[ldk-java] / src / main / java / org / ldk / structs / Confirm.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
8
9 /**
10  * The `Confirm` trait is used to notify when transactions have been confirmed on chain or
11  * unconfirmed during a chain reorganization.
12  * 
13  * Clients sourcing chain data using a transaction-oriented API should prefer this interface over
14  * [`Listen`]. For instance, an Electrum client may implement [`Filter`] by subscribing to activity
15  * related to registered transactions and outputs. Upon notification, it would pass along the
16  * matching transactions using this interface.
17  * 
18  * # Use
19  * 
20  * The intended use is as follows:
21  * - Call [`transactions_confirmed`] to process any on-chain activity of interest.
22  * - Call [`transaction_unconfirmed`] to process any transaction returned by [`get_relevant_txids`]
23  * that has been reorganized out of the chain.
24  * - Call [`best_block_updated`] whenever a new chain tip becomes available.
25  * 
26  * # Order
27  * 
28  * Clients must call these methods in chain order. Specifically:
29  * - Transactions confirmed in a block must be given before transactions confirmed in a later
30  * block.
31  * - Dependent transactions within the same block must be given in topological order, possibly in
32  * separate calls.
33  * - Unconfirmed transactions must be given after the original confirmations and before any
34  * reconfirmation.
35  * 
36  * See individual method documentation for further details.
37  * 
38  * [`transactions_confirmed`]: Self::transactions_confirmed
39  * [`transaction_unconfirmed`]: Self::transaction_unconfirmed
40  * [`best_block_updated`]: Self::best_block_updated
41  * [`get_relevant_txids`]: Self::get_relevant_txids
42  */
43 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
44 public class Confirm extends CommonBase {
45         final bindings.LDKConfirm bindings_instance;
46         Confirm(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
47         private Confirm(bindings.LDKConfirm arg) {
48                 super(bindings.LDKConfirm_new(arg));
49                 this.ptrs_to.add(arg);
50                 this.bindings_instance = arg;
51         }
52         @Override @SuppressWarnings("deprecation")
53         protected void finalize() throws Throwable {
54                 if (ptr != 0) { bindings.Confirm_free(ptr); } super.finalize();
55         }
56
57         public static interface ConfirmInterface {
58                 /**
59                  * Processes transactions confirmed in a block with a given header and height.
60                  * 
61                  * Should be called for any transactions registered by [`Filter::register_tx`] or any
62                  * transactions spending an output registered by [`Filter::register_output`]. Such transactions
63                  * appearing in the same block do not need to be included in the same call; instead, multiple
64                  * calls with additional transactions may be made so long as they are made in [chain order].
65                  * 
66                  * May be called before or after [`best_block_updated`] for the corresponding block. However,
67                  * in the event of a chain reorganization, it must not be called with a `header` that is no
68                  * longer in the chain as of the last call to [`best_block_updated`].
69                  * 
70                  * [chain order]: Confirm#Order
71                  * [`best_block_updated`]: Self::best_block_updated
72                  */
73                 void transactions_confirmed(byte[] header, TwoTuple_usizeTransactionZ[] txdata, int height);
74                 /**
75                  * Processes a transaction that is no longer confirmed as result of a chain reorganization.
76                  * 
77                  * Should be called for any transaction returned by [`get_relevant_txids`] if it has been
78                  * reorganized out of the best chain. Once called, the given transaction should not be returned
79                  * by [`get_relevant_txids`] unless it has been reconfirmed via [`transactions_confirmed`].
80                  * 
81                  * [`get_relevant_txids`]: Self::get_relevant_txids
82                  * [`transactions_confirmed`]: Self::transactions_confirmed
83                  */
84                 void transaction_unconfirmed(byte[] txid);
85                 /**
86                  * Processes an update to the best header connected at the given height.
87                  * 
88                  * Should be called when a new header is available but may be skipped for intermediary blocks
89                  * if they become available at the same time.
90                  */
91                 void best_block_updated(byte[] header, int height);
92                 /**
93                  * Returns transactions that should be monitored for reorganization out of the chain.
94                  * 
95                  * Should include any transactions passed to [`transactions_confirmed`] that have insufficient
96                  * confirmations to be safe from a chain reorganization. Should not include any transactions
97                  * passed to [`transaction_unconfirmed`] unless later reconfirmed.
98                  * 
99                  * May be called to determine the subset of transactions that must still be monitored for
100                  * reorganization. Will be idempotent between calls but may change as a result of calls to the
101                  * other interface methods. Thus, this is useful to determine which transactions may need to be
102                  * given to [`transaction_unconfirmed`].
103                  * 
104                  * [`transactions_confirmed`]: Self::transactions_confirmed
105                  * [`transaction_unconfirmed`]: Self::transaction_unconfirmed
106                  */
107                 byte[][] get_relevant_txids();
108         }
109         private static class LDKConfirmHolder { Confirm held; }
110         public static Confirm new_impl(ConfirmInterface arg) {
111                 final LDKConfirmHolder impl_holder = new LDKConfirmHolder();
112                 impl_holder.held = new Confirm(new bindings.LDKConfirm() {
113                         @Override public void transactions_confirmed(byte[] header, long[] txdata, int height) {
114                                 TwoTuple_usizeTransactionZ[] txdata_conv_28_arr = new TwoTuple_usizeTransactionZ[txdata.length];
115                                 for (int c = 0; c < txdata.length; c++) {
116                                         long txdata_conv_28 = txdata[c];
117                                         TwoTuple_usizeTransactionZ txdata_conv_28_hu_conv = new TwoTuple_usizeTransactionZ(null, txdata_conv_28);
118                                         txdata_conv_28_hu_conv.ptrs_to.add(this);
119                                         txdata_conv_28_arr[c] = txdata_conv_28_hu_conv;
120                                 }
121                                 arg.transactions_confirmed(header, txdata_conv_28_arr, height);
122                         }
123                         @Override public void transaction_unconfirmed(byte[] txid) {
124                                 arg.transaction_unconfirmed(txid);
125                         }
126                         @Override public void best_block_updated(byte[] header, int height) {
127                                 arg.best_block_updated(header, height);
128                         }
129                         @Override public byte[][] get_relevant_txids() {
130                                 byte[][] ret = arg.get_relevant_txids();
131                                 byte[][] result = ret != null ? Arrays.stream(ret).map(ret_conv_8 -> InternalUtils.check_arr_len(ret_conv_8, 32)).toArray(byte[][]::new) : null;
132                                 return result;
133                         }
134                 });
135                 return impl_holder.held;
136         }
137         /**
138          * Processes transactions confirmed in a block with a given header and height.
139          * 
140          * Should be called for any transactions registered by [`Filter::register_tx`] or any
141          * transactions spending an output registered by [`Filter::register_output`]. Such transactions
142          * appearing in the same block do not need to be included in the same call; instead, multiple
143          * calls with additional transactions may be made so long as they are made in [chain order].
144          * 
145          * May be called before or after [`best_block_updated`] for the corresponding block. However,
146          * in the event of a chain reorganization, it must not be called with a `header` that is no
147          * longer in the chain as of the last call to [`best_block_updated`].
148          * 
149          * [chain order]: Confirm#Order
150          * [`best_block_updated`]: Self::best_block_updated
151          */
152         public void transactions_confirmed(byte[] header, TwoTuple_usizeTransactionZ[] txdata, int height) {
153                 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);
154         }
155
156         /**
157          * Processes a transaction that is no longer confirmed as result of a chain reorganization.
158          * 
159          * Should be called for any transaction returned by [`get_relevant_txids`] if it has been
160          * reorganized out of the best chain. Once called, the given transaction should not be returned
161          * by [`get_relevant_txids`] unless it has been reconfirmed via [`transactions_confirmed`].
162          * 
163          * [`get_relevant_txids`]: Self::get_relevant_txids
164          * [`transactions_confirmed`]: Self::transactions_confirmed
165          */
166         public void transaction_unconfirmed(byte[] txid) {
167                 bindings.Confirm_transaction_unconfirmed(this.ptr, InternalUtils.check_arr_len(txid, 32));
168         }
169
170         /**
171          * Processes an update to the best header connected at the given height.
172          * 
173          * Should be called when a new header is available but may be skipped for intermediary blocks
174          * if they become available at the same time.
175          */
176         public void best_block_updated(byte[] header, int height) {
177                 bindings.Confirm_best_block_updated(this.ptr, InternalUtils.check_arr_len(header, 80), height);
178         }
179
180         /**
181          * Returns transactions that should be monitored for reorganization out of the chain.
182          * 
183          * Should include any transactions passed to [`transactions_confirmed`] that have insufficient
184          * confirmations to be safe from a chain reorganization. Should not include any transactions
185          * passed to [`transaction_unconfirmed`] unless later reconfirmed.
186          * 
187          * May be called to determine the subset of transactions that must still be monitored for
188          * reorganization. Will be idempotent between calls but may change as a result of calls to the
189          * other interface methods. Thus, this is useful to determine which transactions may need to be
190          * given to [`transaction_unconfirmed`].
191          * 
192          * [`transactions_confirmed`]: Self::transactions_confirmed
193          * [`transaction_unconfirmed`]: Self::transaction_unconfirmed
194          */
195         public byte[][] get_relevant_txids() {
196                 byte[][] ret = bindings.Confirm_get_relevant_txids(this.ptr);
197                 return ret;
198         }
199
200 }