Update auto-generated bindings to 0.0.103
[ldk-java] / src / main / java / org / ldk / structs / Filter.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 `Filter` trait defines behavior for indicating chain activity of interest pertaining to
11  * channels.
12  * 
13  * This is useful in order to have a [`Watch`] implementation convey to a chain source which
14  * transactions to be notified of. Notification may take the form of pre-filtering blocks or, in
15  * the case of [BIP 157]/[BIP 158], only fetching a block if the compact filter matches. If
16  * receiving full blocks from a chain source, any further filtering is unnecessary.
17  * 
18  * After an output has been registered, subsequent block retrievals from the chain source must not
19  * exclude any transactions matching the new criteria nor any in-block descendants of such
20  * transactions.
21  * 
22  * Note that use as part of a [`Watch`] implementation involves reentrancy. Therefore, the `Filter`
23  * should not block on I/O. Implementations should instead queue the newly monitored data to be
24  * processed later. Then, in order to block until the data has been processed, any [`Watch`]
25  * invocation that has called the `Filter` must return [`TemporaryFailure`].
26  * 
27  * [`TemporaryFailure`]: ChannelMonitorUpdateErr::TemporaryFailure
28  * [BIP 157]: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki
29  * [BIP 158]: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki
30  */
31 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
32 public class Filter extends CommonBase {
33         final bindings.LDKFilter bindings_instance;
34         Filter(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
35         private Filter(bindings.LDKFilter arg) {
36                 super(bindings.LDKFilter_new(arg));
37                 this.ptrs_to.add(arg);
38                 this.bindings_instance = arg;
39         }
40         @Override @SuppressWarnings("deprecation")
41         protected void finalize() throws Throwable {
42                 if (ptr != 0) { bindings.Filter_free(ptr); } super.finalize();
43         }
44
45         public static interface FilterInterface {
46                 /**
47                  * Registers interest in a transaction with `txid` and having an output with `script_pubkey` as
48                  * a spending condition.
49                  */
50                 void register_tx(byte[] txid, byte[] script_pubkey);
51                 /**
52                  * Registers interest in spends of a transaction output.
53                  * 
54                  * Optionally, when `output.block_hash` is set, should return any transaction spending the
55                  * output that is found in the corresponding block along with its index.
56                  * 
57                  * This return value is useful for Electrum clients in order to supply in-block descendant
58                  * transactions which otherwise were not included. This is not necessary for other clients if
59                  * such descendant transactions were already included (e.g., when a BIP 157 client provides the
60                  * full block).
61                  */
62                 Option_C2Tuple_usizeTransactionZZ register_output(WatchedOutput output);
63         }
64         private static class LDKFilterHolder { Filter held; }
65         public static Filter new_impl(FilterInterface arg) {
66                 final LDKFilterHolder impl_holder = new LDKFilterHolder();
67                 impl_holder.held = new Filter(new bindings.LDKFilter() {
68                         @Override public void register_tx(byte[] txid, byte[] script_pubkey) {
69                                 arg.register_tx(txid, script_pubkey);
70                         }
71                         @Override public long register_output(long output) {
72                                 WatchedOutput output_hu_conv = null; if (output < 0 || output > 4096) { output_hu_conv = new WatchedOutput(null, output); }
73                                 output_hu_conv.ptrs_to.add(this);
74                                 Option_C2Tuple_usizeTransactionZZ ret = arg.register_output(output_hu_conv);
75                                 long result = ret.ptr;
76                                 return result;
77                         }
78                 });
79                 return impl_holder.held;
80         }
81         /**
82          * Registers interest in a transaction with `txid` and having an output with `script_pubkey` as
83          * a spending condition.
84          */
85         public void register_tx(byte[] txid, byte[] script_pubkey) {
86                 bindings.Filter_register_tx(this.ptr, txid, script_pubkey);
87         }
88
89         /**
90          * Registers interest in spends of a transaction output.
91          * 
92          * Optionally, when `output.block_hash` is set, should return any transaction spending the
93          * output that is found in the corresponding block along with its index.
94          * 
95          * This return value is useful for Electrum clients in order to supply in-block descendant
96          * transactions which otherwise were not included. This is not necessary for other clients if
97          * such descendant transactions were already included (e.g., when a BIP 157 client provides the
98          * full block).
99          */
100         public Option_C2Tuple_usizeTransactionZZ register_output(WatchedOutput output) {
101                 long ret = bindings.Filter_register_output(this.ptr, output == null ? 0 : output.ptr & ~1);
102                 if (ret >= 0 && ret <= 4096) { return null; }
103                 Option_C2Tuple_usizeTransactionZZ ret_hu_conv = Option_C2Tuple_usizeTransactionZZ.constr_from_ptr(ret);
104                 ret_hu_conv.ptrs_to.add(this);
105                 return ret_hu_conv;
106         }
107
108 }