6 namespace org { namespace ldk { namespace structs {
9 * The `Confirm` trait is used to notify LDK when relevant transactions have been confirmed on
10 * chain or unconfirmed during a chain reorganization.
12 * Clients sourcing chain data using a transaction-oriented API should prefer this interface over
13 * [`Listen`]. For instance, an Electrum-based transaction sync implementation may implement
14 * [`Filter`] to subscribe to relevant transactions and unspent outputs it should monitor for
15 * on-chain activity. Then, it needs to notify LDK via this interface upon observing any changes
16 * with reference to the confirmation status of the monitored objects.
19 * The intended use is as follows:
20 * - Call [`transactions_confirmed`] to notify LDK whenever any of the registered transactions or
21 * outputs are, respectively, confirmed or spent on chain.
22 * - Call [`transaction_unconfirmed`] to notify LDK whenever any transaction returned by
23 * [`get_relevant_txids`] is no longer confirmed in the block with the given block hash.
24 * - Call [`best_block_updated`] to notify LDK whenever a new chain tip becomes available.
28 * Clients must call these methods in chain order. Specifically:
29 * - Transactions which are confirmed in a particular block must be given before transactions
30 * confirmed in a later block.
31 * - Dependent transactions within the same block must be given in topological order, possibly in
33 * - All unconfirmed transactions must be given after the original confirmations and before *any*
34 * reconfirmations, i.e., [`transactions_confirmed`] and [`transaction_unconfirmed`] calls should
35 * never be interleaved, but always conduced *en bloc*.
36 * - Any reconfirmed transactions need to be explicitly unconfirmed before they are reconfirmed
37 * in regard to the new block.
39 * See individual method documentation for further details.
41 * [`transactions_confirmed`]: Self::transactions_confirmed
42 * [`transaction_unconfirmed`]: Self::transaction_unconfirmed
43 * [`best_block_updated`]: Self::best_block_updated
44 * [`get_relevant_txids`]: Self::get_relevant_txids
46 public class Confirm : CommonBase {
47 internal readonly bindings.LDKConfirm bindings_instance;
48 internal Confirm(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
49 private Confirm(bindings.LDKConfirm arg) : base(bindings.LDKConfirm_new(arg)) {
50 this.ptrs_to.AddLast(arg);
51 this.bindings_instance = arg;
54 if (ptr != 0) { bindings.Confirm_free(ptr); }
57 public interface ConfirmInterface {
59 * Notifies LDK of transactions confirmed in a block with a given header and height.
61 * Must 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].
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`].
70 * [chain order]: Confirm#order
71 * [`best_block_updated`]: Self::best_block_updated
73 void transactions_confirmed(byte[] _header, TwoTuple_usizeTransactionZ[] _txdata, int _height);
75 * Notifies LDK of a transaction that is no longer confirmed as result of a chain reorganization.
77 * Must be called for any transaction returned by [`get_relevant_txids`] if it has been
78 * reorganized out of the best chain or if it is no longer confirmed in the block with the
79 * given block hash. Once called, the given transaction will not be returned
80 * by [`get_relevant_txids`], unless it has been reconfirmed via [`transactions_confirmed`].
82 * [`get_relevant_txids`]: Self::get_relevant_txids
83 * [`transactions_confirmed`]: Self::transactions_confirmed
85 void transaction_unconfirmed(byte[] _txid);
87 * Notifies LDK of an update to the best header connected at the given height.
89 * Must be called whenever a new chain tip becomes available. May be skipped for intermediary
92 void best_block_updated(byte[] _header, int _height);
94 * Returns transactions that must be monitored for reorganization out of the chain along
95 * with the hash of the block as part of which it had been previously confirmed.
97 * Will include any transactions passed to [`transactions_confirmed`] that have insufficient
98 * confirmations to be safe from a chain reorganization. Will not include any transactions
99 * passed to [`transaction_unconfirmed`], unless later reconfirmed.
101 * Must be called to determine the subset of transactions that must be monitored for
102 * reorganization. Will be idempotent between calls but may change as a result of calls to the
103 * other interface methods. Thus, this is useful to determine which transactions must be
104 * given to [`transaction_unconfirmed`].
106 * If any of the returned transactions are confirmed in a block other than the one with the
107 * given hash, they need to be unconfirmed and reconfirmed via [`transaction_unconfirmed`] and
108 * [`transactions_confirmed`], respectively.
110 * [`transactions_confirmed`]: Self::transactions_confirmed
111 * [`transaction_unconfirmed`]: Self::transaction_unconfirmed
113 TwoTuple_TxidBlockHashZ[] get_relevant_txids();
115 private class LDKConfirmHolder { internal Confirm held; }
116 private class LDKConfirmImpl : bindings.LDKConfirm {
117 internal LDKConfirmImpl(ConfirmInterface arg, LDKConfirmHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
118 private ConfirmInterface arg;
119 private LDKConfirmHolder impl_holder;
120 public void transactions_confirmed(byte[] _header, long[] _txdata, int _height) {
121 int _txdata_conv_28_len = _txdata.Length;
122 TwoTuple_usizeTransactionZ[] _txdata_conv_28_arr = new TwoTuple_usizeTransactionZ[_txdata_conv_28_len];
123 for (int c = 0; c < _txdata_conv_28_len; c++) {
124 long _txdata_conv_28 = _txdata[c];
125 TwoTuple_usizeTransactionZ _txdata_conv_28_hu_conv = new TwoTuple_usizeTransactionZ(null, _txdata_conv_28);
126 if (_txdata_conv_28_hu_conv != null) { _txdata_conv_28_hu_conv.ptrs_to.AddLast(this); };
127 _txdata_conv_28_arr[c] = _txdata_conv_28_hu_conv;
129 arg.transactions_confirmed(_header, _txdata_conv_28_arr, _height);
132 public void transaction_unconfirmed(byte[] _txid) {
133 arg.transaction_unconfirmed(_txid);
136 public void best_block_updated(byte[] _header, int _height) {
137 arg.best_block_updated(_header, _height);
140 public long[] get_relevant_txids() {
141 TwoTuple_TxidBlockHashZ[] ret = arg.get_relevant_txids();
143 long[] result = ret != null ? InternalUtils.mapArray(ret, ret_conv_25 => ret_conv_25 == null ? 0 : ret_conv_25.clone_ptr()) : null;
147 public static Confirm new_impl(ConfirmInterface arg) {
148 LDKConfirmHolder impl_holder = new LDKConfirmHolder();
149 impl_holder.held = new Confirm(new LDKConfirmImpl(arg, impl_holder));
150 return impl_holder.held;
153 * Notifies LDK of transactions confirmed in a block with a given header and height.
155 * Must be called for any transactions registered by [`Filter::register_tx`] or any
156 * transactions spending an output registered by [`Filter::register_output`]. Such transactions
157 * appearing in the same block do not need to be included in the same call; instead, multiple
158 * calls with additional transactions may be made so long as they are made in [chain order].
160 * May be called before or after [`best_block_updated`] for the corresponding block. However,
161 * in the event of a chain reorganization, it must not be called with a `header` that is no
162 * longer in the chain as of the last call to [`best_block_updated`].
164 * [chain order]: Confirm#order
165 * [`best_block_updated`]: Self::best_block_updated
167 public void transactions_confirmed(byte[] header, TwoTuple_usizeTransactionZ[] txdata, int height) {
168 bindings.Confirm_transactions_confirmed(this.ptr, InternalUtils.check_arr_len(header, 80), txdata != null ? InternalUtils.mapArray(txdata, txdata_conv_28 => txdata_conv_28 != null ? txdata_conv_28.ptr : 0) : null, height);
170 GC.KeepAlive(header);
171 GC.KeepAlive(txdata);
172 GC.KeepAlive(height);
176 * Notifies LDK of a transaction that is no longer confirmed as result of a chain reorganization.
178 * Must be called for any transaction returned by [`get_relevant_txids`] if it has been
179 * reorganized out of the best chain or if it is no longer confirmed in the block with the
180 * given block hash. Once called, the given transaction will not be returned
181 * by [`get_relevant_txids`], unless it has been reconfirmed via [`transactions_confirmed`].
183 * [`get_relevant_txids`]: Self::get_relevant_txids
184 * [`transactions_confirmed`]: Self::transactions_confirmed
186 public void transaction_unconfirmed(byte[] txid) {
187 bindings.Confirm_transaction_unconfirmed(this.ptr, InternalUtils.check_arr_len(txid, 32));
193 * Notifies LDK of an update to the best header connected at the given height.
195 * Must be called whenever a new chain tip becomes available. May be skipped for intermediary
198 public void best_block_updated(byte[] header, int height) {
199 bindings.Confirm_best_block_updated(this.ptr, InternalUtils.check_arr_len(header, 80), height);
201 GC.KeepAlive(header);
202 GC.KeepAlive(height);
206 * Returns transactions that must be monitored for reorganization out of the chain along
207 * with the hash of the block as part of which it had been previously confirmed.
209 * Will include any transactions passed to [`transactions_confirmed`] that have insufficient
210 * confirmations to be safe from a chain reorganization. Will not include any transactions
211 * passed to [`transaction_unconfirmed`], unless later reconfirmed.
213 * Must be called to determine the subset of transactions that must be monitored for
214 * reorganization. Will be idempotent between calls but may change as a result of calls to the
215 * other interface methods. Thus, this is useful to determine which transactions must be
216 * given to [`transaction_unconfirmed`].
218 * If any of the returned transactions are confirmed in a block other than the one with the
219 * given hash, they need to be unconfirmed and reconfirmed via [`transaction_unconfirmed`] and
220 * [`transactions_confirmed`], respectively.
222 * [`transactions_confirmed`]: Self::transactions_confirmed
223 * [`transaction_unconfirmed`]: Self::transaction_unconfirmed
225 public TwoTuple_TxidBlockHashZ[] get_relevant_txids() {
226 long[] ret = bindings.Confirm_get_relevant_txids(this.ptr);
228 int ret_conv_25_len = ret.Length;
229 TwoTuple_TxidBlockHashZ[] ret_conv_25_arr = new TwoTuple_TxidBlockHashZ[ret_conv_25_len];
230 for (int z = 0; z < ret_conv_25_len; z++) {
231 long ret_conv_25 = ret[z];
232 TwoTuple_TxidBlockHashZ ret_conv_25_hu_conv = new TwoTuple_TxidBlockHashZ(null, ret_conv_25);
233 if (ret_conv_25_hu_conv != null) { ret_conv_25_hu_conv.ptrs_to.AddLast(this); };
234 ret_conv_25_arr[z] = ret_conv_25_hu_conv;
236 return ret_conv_25_arr;