[Java] Update auto-generated bindings
[ldk-java] / src / main / java / org / ldk / structs / Balance.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  * Details about the balance(s) available for spending once the channel appears on chain.
13  * 
14  * See [`ChannelMonitor::get_claimable_balances`] for more details on when these will or will not
15  * be provided.
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class Balance extends CommonBase {
19         private Balance(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.Balance_free(ptr); }
24         }
25         static Balance constr_from_ptr(long ptr) {
26                 bindings.LDKBalance raw_val = bindings.LDKBalance_ref_from_ptr(ptr);
27                 if (raw_val.getClass() == bindings.LDKBalance.ClaimableOnChannelClose.class) {
28                         return new ClaimableOnChannelClose(ptr, (bindings.LDKBalance.ClaimableOnChannelClose)raw_val);
29                 }
30                 if (raw_val.getClass() == bindings.LDKBalance.ClaimableAwaitingConfirmations.class) {
31                         return new ClaimableAwaitingConfirmations(ptr, (bindings.LDKBalance.ClaimableAwaitingConfirmations)raw_val);
32                 }
33                 if (raw_val.getClass() == bindings.LDKBalance.ContentiousClaimable.class) {
34                         return new ContentiousClaimable(ptr, (bindings.LDKBalance.ContentiousClaimable)raw_val);
35                 }
36                 if (raw_val.getClass() == bindings.LDKBalance.MaybeClaimableHTLCAwaitingTimeout.class) {
37                         return new MaybeClaimableHTLCAwaitingTimeout(ptr, (bindings.LDKBalance.MaybeClaimableHTLCAwaitingTimeout)raw_val);
38                 }
39                 assert false; return null; // Unreachable without extending the (internal) bindings interface
40         }
41
42         /**
43          * The channel is not yet closed (or the commitment or closing transaction has not yet
44          * appeared in a block). The given balance is claimable (less on-chain fees) if the channel is
45          * force-closed now.
46          */
47         public final static class ClaimableOnChannelClose extends Balance {
48                 /**
49                  * The amount available to claim, in satoshis, excluding the on-chain fees which will be
50                  * required to do so.
51                 */
52                 public final long claimable_amount_satoshis;
53                 private ClaimableOnChannelClose(long ptr, bindings.LDKBalance.ClaimableOnChannelClose obj) {
54                         super(null, ptr);
55                         this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
56                 }
57         }
58         /**
59          * The channel has been closed, and the given balance is ours but awaiting confirmations until
60          * we consider it spendable.
61          */
62         public final static class ClaimableAwaitingConfirmations extends Balance {
63                 /**
64                  * The amount available to claim, in satoshis, possibly excluding the on-chain fees which
65                  * were spent in broadcasting the transaction.
66                 */
67                 public final long claimable_amount_satoshis;
68                 /**
69                  * The height at which an [`Event::SpendableOutputs`] event will be generated for this
70                  * amount.
71                 */
72                 public final int confirmation_height;
73                 private ClaimableAwaitingConfirmations(long ptr, bindings.LDKBalance.ClaimableAwaitingConfirmations obj) {
74                         super(null, ptr);
75                         this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
76                         this.confirmation_height = obj.confirmation_height;
77                 }
78         }
79         /**
80          * The channel has been closed, and the given balance should be ours but awaiting spending
81          * transaction confirmation. If the spending transaction does not confirm in time, it is
82          * possible our counterparty can take the funds by broadcasting an HTLC timeout on-chain.
83          * 
84          * Once the spending transaction confirms, before it has reached enough confirmations to be
85          * considered safe from chain reorganizations, the balance will instead be provided via
86          * [`Balance::ClaimableAwaitingConfirmations`].
87          */
88         public final static class ContentiousClaimable extends Balance {
89                 /**
90                  * The amount available to claim, in satoshis, excluding the on-chain fees which will be
91                  * required to do so.
92                 */
93                 public final long claimable_amount_satoshis;
94                 /**
95                  * The height at which the counterparty may be able to claim the balance if we have not
96                  * done so.
97                 */
98                 public final int timeout_height;
99                 private ContentiousClaimable(long ptr, bindings.LDKBalance.ContentiousClaimable obj) {
100                         super(null, ptr);
101                         this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
102                         this.timeout_height = obj.timeout_height;
103                 }
104         }
105         /**
106          * HTLCs which we sent to our counterparty which are claimable after a timeout (less on-chain
107          * fees) if the counterparty does not know the preimage for the HTLCs. These are somewhat
108          * likely to be claimed by our counterparty before we do.
109          */
110         public final static class MaybeClaimableHTLCAwaitingTimeout extends Balance {
111                 /**
112                  * The amount available to claim, in satoshis, excluding the on-chain fees which will be
113                  * required to do so.
114                 */
115                 public final long claimable_amount_satoshis;
116                 /**
117                  * The height at which we will be able to claim the balance if our counterparty has not
118                  * done so.
119                 */
120                 public final int claimable_height;
121                 private MaybeClaimableHTLCAwaitingTimeout(long ptr, bindings.LDKBalance.MaybeClaimableHTLCAwaitingTimeout obj) {
122                         super(null, ptr);
123                         this.claimable_amount_satoshis = obj.claimable_amount_satoshis;
124                         this.claimable_height = obj.claimable_height;
125                 }
126         }
127         long clone_ptr() {
128                 long ret = bindings.Balance_clone_ptr(this.ptr);
129                 Reference.reachabilityFence(this);
130                 return ret;
131         }
132
133         /**
134          * Creates a copy of the Balance
135          */
136         public Balance clone() {
137                 long ret = bindings.Balance_clone(this.ptr);
138                 Reference.reachabilityFence(this);
139                 if (ret >= 0 && ret <= 4096) { return null; }
140                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
141                 ret_hu_conv.ptrs_to.add(this);
142                 return ret_hu_conv;
143         }
144
145         /**
146          * Utility method to constructs a new ClaimableOnChannelClose-variant Balance
147          */
148         public static Balance claimable_on_channel_close(long claimable_amount_satoshis) {
149                 long ret = bindings.Balance_claimable_on_channel_close(claimable_amount_satoshis);
150                 Reference.reachabilityFence(claimable_amount_satoshis);
151                 if (ret >= 0 && ret <= 4096) { return null; }
152                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
153                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
154                 return ret_hu_conv;
155         }
156
157         /**
158          * Utility method to constructs a new ClaimableAwaitingConfirmations-variant Balance
159          */
160         public static Balance claimable_awaiting_confirmations(long claimable_amount_satoshis, int confirmation_height) {
161                 long ret = bindings.Balance_claimable_awaiting_confirmations(claimable_amount_satoshis, confirmation_height);
162                 Reference.reachabilityFence(claimable_amount_satoshis);
163                 Reference.reachabilityFence(confirmation_height);
164                 if (ret >= 0 && ret <= 4096) { return null; }
165                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
166                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
167                 return ret_hu_conv;
168         }
169
170         /**
171          * Utility method to constructs a new ContentiousClaimable-variant Balance
172          */
173         public static Balance contentious_claimable(long claimable_amount_satoshis, int timeout_height) {
174                 long ret = bindings.Balance_contentious_claimable(claimable_amount_satoshis, timeout_height);
175                 Reference.reachabilityFence(claimable_amount_satoshis);
176                 Reference.reachabilityFence(timeout_height);
177                 if (ret >= 0 && ret <= 4096) { return null; }
178                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
179                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
180                 return ret_hu_conv;
181         }
182
183         /**
184          * Utility method to constructs a new MaybeClaimableHTLCAwaitingTimeout-variant Balance
185          */
186         public static Balance maybe_claimable_htlcawaiting_timeout(long claimable_amount_satoshis, int claimable_height) {
187                 long ret = bindings.Balance_maybe_claimable_htlcawaiting_timeout(claimable_amount_satoshis, claimable_height);
188                 Reference.reachabilityFence(claimable_amount_satoshis);
189                 Reference.reachabilityFence(claimable_height);
190                 if (ret >= 0 && ret <= 4096) { return null; }
191                 org.ldk.structs.Balance ret_hu_conv = org.ldk.structs.Balance.constr_from_ptr(ret);
192                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
193                 return ret_hu_conv;
194         }
195
196         /**
197          * Checks if two Balances contain equal inner contents.
198          * This ignores pointers and is_owned flags and looks at the values in fields.
199          */
200         public boolean eq(Balance b) {
201                 boolean ret = bindings.Balance_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
202                 Reference.reachabilityFence(this);
203                 Reference.reachabilityFence(b);
204                 return ret;
205         }
206
207         @Override public boolean equals(Object o) {
208                 if (!(o instanceof Balance)) return false;
209                 return this.eq((Balance)o);
210         }
211 }