cbf5769feaf658677d3ea2d743f1a5701d94351f
[ldk-java] / src / main / java / org / ldk / structs / ChannelMonitorUpdate.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 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * An update generated by the underlying channel itself which contains some new information the
13  * [`ChannelMonitor`] should be made aware of.
14  * 
15  * Because this represents only a small number of updates to the underlying state, it is generally
16  * much smaller than a full [`ChannelMonitor`]. However, for large single commitment transaction
17  * updates (e.g. ones during which there are hundreds of HTLCs pending on the commitment
18  * transaction), a single update may reach upwards of 1 MiB in serialized size.
19  */
20 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
21 public class ChannelMonitorUpdate extends CommonBase {
22         ChannelMonitorUpdate(Object _dummy, long ptr) { super(ptr); }
23         @Override @SuppressWarnings("deprecation")
24         protected void finalize() throws Throwable {
25                 super.finalize();
26                 if (ptr != 0) { bindings.ChannelMonitorUpdate_free(ptr); }
27         }
28
29         /**
30          * The sequence number of this update. Updates *must* be replayed in-order according to this
31          * sequence number (and updates may panic if they are not). The update_id values are strictly
32          * increasing and increase by one for each new update, with one exception specified below.
33          * 
34          * This sequence number is also used to track up to which points updates which returned
35          * [`ChannelMonitorUpdateStatus::InProgress`] have been applied to all copies of a given
36          * ChannelMonitor when ChannelManager::channel_monitor_updated is called.
37          * 
38          * The only instance where update_id values are not strictly increasing is the case where we
39          * allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See
40          * its docs for more details.
41          * 
42          * [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
43          */
44         public long get_update_id() {
45                 long ret = bindings.ChannelMonitorUpdate_get_update_id(this.ptr);
46                 Reference.reachabilityFence(this);
47                 return ret;
48         }
49
50         /**
51          * The sequence number of this update. Updates *must* be replayed in-order according to this
52          * sequence number (and updates may panic if they are not). The update_id values are strictly
53          * increasing and increase by one for each new update, with one exception specified below.
54          * 
55          * This sequence number is also used to track up to which points updates which returned
56          * [`ChannelMonitorUpdateStatus::InProgress`] have been applied to all copies of a given
57          * ChannelMonitor when ChannelManager::channel_monitor_updated is called.
58          * 
59          * The only instance where update_id values are not strictly increasing is the case where we
60          * allow post-force-close updates with a special update ID of [`CLOSED_CHANNEL_UPDATE_ID`]. See
61          * its docs for more details.
62          * 
63          * [`ChannelMonitorUpdateStatus::InProgress`]: super::ChannelMonitorUpdateStatus::InProgress
64          */
65         public void set_update_id(long val) {
66                 bindings.ChannelMonitorUpdate_set_update_id(this.ptr, val);
67                 Reference.reachabilityFence(this);
68                 Reference.reachabilityFence(val);
69         }
70
71         long clone_ptr() {
72                 long ret = bindings.ChannelMonitorUpdate_clone_ptr(this.ptr);
73                 Reference.reachabilityFence(this);
74                 return ret;
75         }
76
77         /**
78          * Creates a copy of the ChannelMonitorUpdate
79          */
80         public ChannelMonitorUpdate clone() {
81                 long ret = bindings.ChannelMonitorUpdate_clone(this.ptr);
82                 Reference.reachabilityFence(this);
83                 if (ret >= 0 && ret <= 4096) { return null; }
84                 org.ldk.structs.ChannelMonitorUpdate ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelMonitorUpdate(null, ret); }
85                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
86                 return ret_hu_conv;
87         }
88
89         /**
90          * Serialize the ChannelMonitorUpdate object into a byte array which can be read by ChannelMonitorUpdate_read
91          */
92         public byte[] write() {
93                 byte[] ret = bindings.ChannelMonitorUpdate_write(this.ptr);
94                 Reference.reachabilityFence(this);
95                 return ret;
96         }
97
98         /**
99          * Read a ChannelMonitorUpdate from a byte array, created by ChannelMonitorUpdate_write
100          */
101         public static Result_ChannelMonitorUpdateDecodeErrorZ read(byte[] ser) {
102                 long ret = bindings.ChannelMonitorUpdate_read(ser);
103                 Reference.reachabilityFence(ser);
104                 if (ret >= 0 && ret <= 4096) { return null; }
105                 Result_ChannelMonitorUpdateDecodeErrorZ ret_hu_conv = Result_ChannelMonitorUpdateDecodeErrorZ.constr_from_ptr(ret);
106                 return ret_hu_conv;
107         }
108
109 }