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