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