X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FFilter.java;h=b5ab9fe76b97243181ac8db6c4912c1565dd8a9f;hb=HEAD;hp=3250da58ad888548d1507367ba7983a0210be192;hpb=13cdf8bde340072288b39a5e29f0946d3e095ad4;p=ldk-java diff --git a/src/main/java/org/ldk/structs/Filter.java b/src/main/java/org/ldk/structs/Filter.java index 3250da58..b5ab9fe7 100644 --- a/src/main/java/org/ldk/structs/Filter.java +++ b/src/main/java/org/ldk/structs/Filter.java @@ -23,9 +23,9 @@ import javax.annotation.Nullable; * 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`]. + * invocation that has called the `Filter` must return [`InProgress`]. * - * [`TemporaryFailure`]: ChannelMonitorUpdateErr::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 */ @@ -42,7 +42,19 @@ public class Filter extends CommonBase { protected void finalize() throws Throwable { if (ptr != 0) { bindings.Filter_free(ptr); } super.finalize(); } - + /** + * Destroys the object, freeing associated resources. After this call, any access + * to this object may result in a SEGFAULT or worse. + * + * You should generally NEVER call this method. You should let the garbage collector + * do this for you when it finalizes objects. However, it may be useful for types + * which represent locks and should be closed immediately to avoid holding locks + * until the GC runs. + */ + public void destroy() { + if (ptr != 0) { bindings.Filter_free(ptr); } + ptr = 0; + } public static interface FilterInterface { /** * Registers interest in a transaction with `txid` and having an output with `script_pubkey` as @@ -52,15 +64,12 @@ public class Filter extends CommonBase { /** * Registers interest in spends of a transaction output. * - * Optionally, when `output.block_hash` is set, should return any transaction spending the - * output that is found in the corresponding block along with its index. - * - * This return value is useful for Electrum clients in order to supply in-block descendant - * transactions which otherwise were not included. This is not necessary for other clients if - * such descendant transactions were already included (e.g., when a BIP 157 client provides the - * full block). + * 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. */ - Option_C2Tuple_usizeTransactionZZ register_output(WatchedOutput output); + void register_output(WatchedOutput output); } private static class LDKFilterHolder { Filter held; } public static Filter new_impl(FilterInterface arg) { @@ -70,13 +79,11 @@ public class Filter extends CommonBase { arg.register_tx(txid, script_pubkey); Reference.reachabilityFence(arg); } - @Override public long register_output(long output) { + @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); } - output_hu_conv.ptrs_to.add(this); - Option_C2Tuple_usizeTransactionZZ ret = arg.register_output(output_hu_conv); + if (output_hu_conv != null) { output_hu_conv.ptrs_to.add(this); }; + arg.register_output(output_hu_conv); Reference.reachabilityFence(arg); - long result = ret == null ? 0 : ret.clone_ptr(); - return result; } }); return impl_holder.held; @@ -95,23 +102,16 @@ public class Filter extends CommonBase { /** * Registers interest in spends of a transaction output. * - * Optionally, when `output.block_hash` is set, should return any transaction spending the - * output that is found in the corresponding block along with its index. - * - * This return value is useful for Electrum clients in order to supply in-block descendant - * transactions which otherwise were not included. This is not necessary for other clients if - * such descendant transactions were already included (e.g., when a BIP 157 client provides the - * full block). + * 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 Option_C2Tuple_usizeTransactionZZ register_output(WatchedOutput output) { - long ret = bindings.Filter_register_output(this.ptr, output == null ? 0 : output.ptr); + public void register_output(org.ldk.structs.WatchedOutput output) { + bindings.Filter_register_output(this.ptr, output.ptr); Reference.reachabilityFence(this); Reference.reachabilityFence(output); - if (ret >= 0 && ret <= 4096) { return null; } - org.ldk.structs.Option_C2Tuple_usizeTransactionZZ ret_hu_conv = org.ldk.structs.Option_C2Tuple_usizeTransactionZZ.constr_from_ptr(ret); - ret_hu_conv.ptrs_to.add(this); - this.ptrs_to.add(output); - return ret_hu_conv; + if (this != null) { this.ptrs_to.add(output); }; } }