Update java bindings with new generator and new upstream code
[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  * [`Watch`]: trait.Watch.html
27  * [`TemporaryFailure`]: channelmonitor/enum.ChannelMonitorUpdateErr.html#variant.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 identified by `outpoint` having
53                  * `script_pubkey` as the spending condition.
54                  */
55                 void register_output(OutPoint outpoint, byte[] script_pubkey);
56         }
57         private static class LDKFilterHolder { Filter held; }
58         public static Filter new_impl(FilterInterface arg) {
59                 final LDKFilterHolder impl_holder = new LDKFilterHolder();
60                 impl_holder.held = new Filter(new bindings.LDKFilter() {
61                         @Override public void register_tx(byte[] txid, byte[] script_pubkey) {
62                                 arg.register_tx(txid, script_pubkey);
63                         }
64                         @Override public void register_output(long outpoint, byte[] script_pubkey) {
65                                 OutPoint outpoint_hu_conv = new OutPoint(null, outpoint);
66                                 arg.register_output(outpoint_hu_conv, script_pubkey);
67                         }
68                 });
69                 return impl_holder.held;
70         }
71         /**
72          * Registers interest in a transaction with `txid` and having an output with `script_pubkey` as
73          * a spending condition.
74          */
75         public void register_tx(byte[] txid, byte[] script_pubkey) {
76                 bindings.Filter_register_tx(this.ptr, txid, script_pubkey);
77         }
78
79         /**
80          * Registers interest in spends of a transaction output identified by `outpoint` having
81          * `script_pubkey` as the spending condition.
82          */
83         public void register_output(OutPoint outpoint, byte[] script_pubkey) {
84                 bindings.Filter_register_output(this.ptr, outpoint == null ? 0 : outpoint.ptr & ~1, script_pubkey);
85                 this.ptrs_to.add(outpoint);
86         }
87
88 }