import org.ldk.enums.*;
import org.ldk.util.*;
import java.util.Arrays;
+import java.lang.ref.Reference;
+import javax.annotation.Nullable;
/**
* The `Filter` trait defines behavior for indicating chain activity of interest pertaining to
*
* Note that use as part of a [`Watch`] implementation involves reentrancy. Therefore, the `Filter`
* should not block on I/O. Implementations should instead queue the newly monitored data to be
- * processed later. Then, in order to block until the data has been processed, any `Watch`
- * invocation that has called the `Filter` must return [`TemporaryFailure`].
+ * processed later. Then, in order to block until the data has been processed, any [`Watch`]
+ * invocation that has called the `Filter` must return [`InProgress`].
*
- * [`Watch`]: trait.Watch.html
- * [`TemporaryFailure`]: channelmonitor/enum.ChannelMonitorUpdateErr.html#variant.TemporaryFailure
+ * [`InProgress`]: ChannelMonitorUpdateStatus::InProgress
* [BIP 157]: https://github.com/bitcoin/bips/blob/master/bip-0157.mediawiki
* [BIP 158]: https://github.com/bitcoin/bips/blob/master/bip-0158.mediawiki
*/
*/
void register_tx(byte[] txid, byte[] script_pubkey);
/**
- * Registers interest in spends of a transaction output identified by `outpoint` having
- * `script_pubkey` as the spending condition.
+ * Registers interest in spends of a transaction output.
+ *
+ * Note that this method might be called during processing of a new block. You therefore need
+ * to ensure that also dependent output spents within an already connected block are correctly
+ * handled, e.g., by re-scanning the block in question whenever new outputs have been
+ * registered mid-processing.
*/
- void register_output(OutPoint outpoint, byte[] script_pubkey);
+ void register_output(WatchedOutput output);
}
private static class LDKFilterHolder { Filter held; }
public static Filter new_impl(FilterInterface arg) {
impl_holder.held = new Filter(new bindings.LDKFilter() {
@Override public void register_tx(byte[] txid, byte[] script_pubkey) {
arg.register_tx(txid, script_pubkey);
+ Reference.reachabilityFence(arg);
}
- @Override public void register_output(long outpoint, byte[] script_pubkey) {
- OutPoint outpoint_hu_conv = new OutPoint(null, outpoint);
- arg.register_output(outpoint_hu_conv, script_pubkey);
+ @Override public void register_output(long output) {
+ org.ldk.structs.WatchedOutput output_hu_conv = null; if (output < 0 || output > 4096) { output_hu_conv = new org.ldk.structs.WatchedOutput(null, output); }
+ if (output_hu_conv != null) { output_hu_conv.ptrs_to.add(this); };
+ arg.register_output(output_hu_conv);
+ Reference.reachabilityFence(arg);
}
});
return impl_holder.held;
* a spending condition.
*/
public void register_tx(byte[] txid, byte[] script_pubkey) {
- bindings.Filter_register_tx(this.ptr, txid, script_pubkey);
+ bindings.Filter_register_tx(this.ptr, InternalUtils.check_arr_len(txid, 32), script_pubkey);
+ Reference.reachabilityFence(this);
+ Reference.reachabilityFence(txid);
+ Reference.reachabilityFence(script_pubkey);
}
/**
- * Registers interest in spends of a transaction output identified by `outpoint` having
- * `script_pubkey` as the spending condition.
+ * Registers interest in spends of a transaction output.
+ *
+ * Note that this method might be called during processing of a new block. You therefore need
+ * to ensure that also dependent output spents within an already connected block are correctly
+ * handled, e.g., by re-scanning the block in question whenever new outputs have been
+ * registered mid-processing.
*/
- public void register_output(OutPoint outpoint, byte[] script_pubkey) {
- bindings.Filter_register_output(this.ptr, outpoint == null ? 0 : outpoint.ptr & ~1, script_pubkey);
- this.ptrs_to.add(outpoint);
+ public void register_output(WatchedOutput output) {
+ bindings.Filter_register_output(this.ptr, output == null ? 0 : output.ptr);
+ Reference.reachabilityFence(this);
+ Reference.reachabilityFence(output);
+ if (this != null) { this.ptrs_to.add(output); };
}
}