X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FChannelMonitorUpdate.java;h=05913a2f797d130989fc58a415ec5c6fa64bae16;hb=ca313f2eee377bec222fa82b2939751fa9eab32e;hp=2f914b560c34f2369724f580df182fbb074a8151;hpb=166ff04616cfee975ce991607ca0df88857193df;p=ldk-java diff --git a/src/main/java/org/ldk/structs/ChannelMonitorUpdate.java b/src/main/java/org/ldk/structs/ChannelMonitorUpdate.java index 2f914b56..05913a2f 100644 --- a/src/main/java/org/ldk/structs/ChannelMonitorUpdate.java +++ b/src/main/java/org/ldk/structs/ChannelMonitorUpdate.java @@ -2,33 +2,129 @@ package org.ldk.structs; import org.ldk.impl.bindings; import org.ldk.enums.*; +import org.ldk.util.*; +import java.util.Arrays; +import java.lang.ref.Reference; +import javax.annotation.Nullable; + +/** + * An update generated by the underlying channel itself which contains some new information the + * [`ChannelMonitor`] should be made aware of. + * + * Because this represents only a small number of updates to the underlying state, it is generally + * much smaller than a full [`ChannelMonitor`]. However, for large single commitment transaction + * updates (e.g. ones during which there are hundreds of HTLCs pending on the commitment + * transaction), a single update may reach upwards of 1 MiB in serialized size. + */ +@SuppressWarnings("unchecked") // We correctly assign various generic arrays public class ChannelMonitorUpdate extends CommonBase { ChannelMonitorUpdate(Object _dummy, long ptr) { super(ptr); } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.ChannelMonitorUpdate_free(ptr); super.finalize(); + super.finalize(); + if (ptr != 0) { bindings.ChannelMonitorUpdate_free(ptr); } + } + + /** + * The sequence number of this update. Updates *must* be replayed in-order according to this + * sequence number (and updates may panic if they are not). The update_id values are strictly + * increasing and increase by one for each new update, with two exceptions specified below. + * + * This sequence number is also used to track up to which points updates which returned + * [`ChannelMonitorUpdateStatus::InProgress`] have been applied to all copies of a given + * ChannelMonitor when ChannelManager::channel_monitor_updated is called. + * + * The only instances we allow where update_id values are not strictly increasing have a + * special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. This update ID is used for updates that + * will force close the channel by broadcasting the latest commitment transaction or + * special post-force-close updates, like providing preimages necessary to claim outputs on the + * broadcast commitment transaction. See its docs for more details. + * + * [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress + */ + public long get_update_id() { + long ret = bindings.ChannelMonitorUpdate_get_update_id(this.ptr); + Reference.reachabilityFence(this); + return ret; } - public ChannelMonitorUpdate(ChannelMonitorUpdate orig) { - super(bindings.ChannelMonitorUpdate_clone(orig.ptr & ~1)); - this.ptrs_to.add(orig); + /** + * The sequence number of this update. Updates *must* be replayed in-order according to this + * sequence number (and updates may panic if they are not). The update_id values are strictly + * increasing and increase by one for each new update, with two exceptions specified below. + * + * This sequence number is also used to track up to which points updates which returned + * [`ChannelMonitorUpdateStatus::InProgress`] have been applied to all copies of a given + * ChannelMonitor when ChannelManager::channel_monitor_updated is called. + * + * The only instances we allow where update_id values are not strictly increasing have a + * special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. This update ID is used for updates that + * will force close the channel by broadcasting the latest commitment transaction or + * special post-force-close updates, like providing preimages necessary to claim outputs on the + * broadcast commitment transaction. See its docs for more details. + * + * [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress + */ + public void set_update_id(long val) { + bindings.ChannelMonitorUpdate_set_update_id(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } - public long get_update_id(ChannelMonitorUpdate this_ptr) { - long ret = bindings.ChannelMonitorUpdate_get_update_id(this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); + long clone_ptr() { + long ret = bindings.ChannelMonitorUpdate_clone_ptr(this.ptr); + Reference.reachabilityFence(this); return ret; } - public void set_update_id(ChannelMonitorUpdate this_ptr, long val) { - bindings.ChannelMonitorUpdate_set_update_id(this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + /** + * Creates a copy of the ChannelMonitorUpdate + */ + public ChannelMonitorUpdate clone() { + long ret = bindings.ChannelMonitorUpdate_clone(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.ChannelMonitorUpdate ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelMonitorUpdate(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; + return ret_hu_conv; + } + + /** + * Checks if two ChannelMonitorUpdates contain equal inner contents. + * This ignores pointers and is_owned flags and looks at the values in fields. + * Two objects with NULL inner values will be considered "equal" here. + */ + public boolean eq(org.ldk.structs.ChannelMonitorUpdate b) { + boolean ret = bindings.ChannelMonitorUpdate_eq(this.ptr, b == null ? 0 : b.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(b); + if (this != null) { this.ptrs_to.add(b); }; + return ret; + } + + @Override public boolean equals(Object o) { + if (!(o instanceof ChannelMonitorUpdate)) return false; + return this.eq((ChannelMonitorUpdate)o); + } + /** + * Serialize the ChannelMonitorUpdate object into a byte array which can be read by ChannelMonitorUpdate_read + */ + public byte[] write() { + byte[] ret = bindings.ChannelMonitorUpdate_write(this.ptr); + Reference.reachabilityFence(this); + return ret; } - // Skipped ChannelMonitorUpdate_write - public ChannelMonitorUpdate(byte[] ser) { - super(bindings.ChannelMonitorUpdate_read(ser)); + /** + * Read a ChannelMonitorUpdate from a byte array, created by ChannelMonitorUpdate_write + */ + public static Result_ChannelMonitorUpdateDecodeErrorZ read(byte[] ser) { + long ret = bindings.ChannelMonitorUpdate_read(ser); + Reference.reachabilityFence(ser); + if (ret >= 0 && ret <= 4096) { return null; } + Result_ChannelMonitorUpdateDecodeErrorZ ret_hu_conv = Result_ChannelMonitorUpdateDecodeErrorZ.constr_from_ptr(ret); + return ret_hu_conv; } }