1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * The effective capacity of a channel for routing purposes.
14 * While this may be smaller than the actual channel capacity, amounts greater than
15 * [`Self::as_msat`] should not be routed through the channel.
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class EffectiveCapacity extends CommonBase {
19 private EffectiveCapacity(Object _dummy, long ptr) { super(ptr); }
20 @Override @SuppressWarnings("deprecation")
21 protected void finalize() throws Throwable {
23 if (ptr != 0) { bindings.EffectiveCapacity_free(ptr); }
25 static EffectiveCapacity constr_from_ptr(long ptr) {
26 bindings.LDKEffectiveCapacity raw_val = bindings.LDKEffectiveCapacity_ref_from_ptr(ptr);
27 if (raw_val.getClass() == bindings.LDKEffectiveCapacity.ExactLiquidity.class) {
28 return new ExactLiquidity(ptr, (bindings.LDKEffectiveCapacity.ExactLiquidity)raw_val);
30 if (raw_val.getClass() == bindings.LDKEffectiveCapacity.AdvertisedMaxHTLC.class) {
31 return new AdvertisedMaxHTLC(ptr, (bindings.LDKEffectiveCapacity.AdvertisedMaxHTLC)raw_val);
33 if (raw_val.getClass() == bindings.LDKEffectiveCapacity.Total.class) {
34 return new Total(ptr, (bindings.LDKEffectiveCapacity.Total)raw_val);
36 if (raw_val.getClass() == bindings.LDKEffectiveCapacity.Infinite.class) {
37 return new Infinite(ptr, (bindings.LDKEffectiveCapacity.Infinite)raw_val);
39 if (raw_val.getClass() == bindings.LDKEffectiveCapacity.HintMaxHTLC.class) {
40 return new HintMaxHTLC(ptr, (bindings.LDKEffectiveCapacity.HintMaxHTLC)raw_val);
42 if (raw_val.getClass() == bindings.LDKEffectiveCapacity.Unknown.class) {
43 return new Unknown(ptr, (bindings.LDKEffectiveCapacity.Unknown)raw_val);
45 assert false; return null; // Unreachable without extending the (internal) bindings interface
49 * The available liquidity in the channel known from being a channel counterparty, and thus a
52 public final static class ExactLiquidity extends EffectiveCapacity {
54 * Either the inbound or outbound liquidity depending on the direction, denominated in
57 public final long liquidity_msat;
58 private ExactLiquidity(long ptr, bindings.LDKEffectiveCapacity.ExactLiquidity obj) {
60 this.liquidity_msat = obj.liquidity_msat;
64 * The maximum HTLC amount in one direction as advertised on the gossip network.
66 public final static class AdvertisedMaxHTLC extends EffectiveCapacity {
68 * The maximum HTLC amount denominated in millisatoshi.
70 public final long amount_msat;
71 private AdvertisedMaxHTLC(long ptr, bindings.LDKEffectiveCapacity.AdvertisedMaxHTLC obj) {
73 this.amount_msat = obj.amount_msat;
77 * The total capacity of the channel as determined by the funding transaction.
79 public final static class Total extends EffectiveCapacity {
81 * The funding amount denominated in millisatoshi.
83 public final long capacity_msat;
85 * The maximum HTLC amount denominated in millisatoshi.
87 public final long htlc_maximum_msat;
88 private Total(long ptr, bindings.LDKEffectiveCapacity.Total obj) {
90 this.capacity_msat = obj.capacity_msat;
91 this.htlc_maximum_msat = obj.htlc_maximum_msat;
95 * A capacity sufficient to route any payment, typically used for private channels provided by
98 public final static class Infinite extends EffectiveCapacity {
99 private Infinite(long ptr, bindings.LDKEffectiveCapacity.Infinite obj) {
104 * The maximum HTLC amount as provided by an invoice route hint.
106 public final static class HintMaxHTLC extends EffectiveCapacity {
108 * The maximum HTLC amount denominated in millisatoshi.
110 public final long amount_msat;
111 private HintMaxHTLC(long ptr, bindings.LDKEffectiveCapacity.HintMaxHTLC obj) {
113 this.amount_msat = obj.amount_msat;
117 * A capacity that is unknown possibly because either the chain state is unavailable to know
118 * the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network.
120 public final static class Unknown extends EffectiveCapacity {
121 private Unknown(long ptr, bindings.LDKEffectiveCapacity.Unknown obj) {
126 long ret = bindings.EffectiveCapacity_clone_ptr(this.ptr);
127 Reference.reachabilityFence(this);
132 * Creates a copy of the EffectiveCapacity
134 public EffectiveCapacity clone() {
135 long ret = bindings.EffectiveCapacity_clone(this.ptr);
136 Reference.reachabilityFence(this);
137 if (ret >= 0 && ret <= 4096) { return null; }
138 org.ldk.structs.EffectiveCapacity ret_hu_conv = org.ldk.structs.EffectiveCapacity.constr_from_ptr(ret);
139 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
144 * Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity
146 public static EffectiveCapacity exact_liquidity(long liquidity_msat) {
147 long ret = bindings.EffectiveCapacity_exact_liquidity(liquidity_msat);
148 Reference.reachabilityFence(liquidity_msat);
149 if (ret >= 0 && ret <= 4096) { return null; }
150 org.ldk.structs.EffectiveCapacity ret_hu_conv = org.ldk.structs.EffectiveCapacity.constr_from_ptr(ret);
151 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
156 * Utility method to constructs a new AdvertisedMaxHTLC-variant EffectiveCapacity
158 public static EffectiveCapacity advertised_max_htlc(long amount_msat) {
159 long ret = bindings.EffectiveCapacity_advertised_max_htlc(amount_msat);
160 Reference.reachabilityFence(amount_msat);
161 if (ret >= 0 && ret <= 4096) { return null; }
162 org.ldk.structs.EffectiveCapacity ret_hu_conv = org.ldk.structs.EffectiveCapacity.constr_from_ptr(ret);
163 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
168 * Utility method to constructs a new Total-variant EffectiveCapacity
170 public static EffectiveCapacity total(long capacity_msat, long htlc_maximum_msat) {
171 long ret = bindings.EffectiveCapacity_total(capacity_msat, htlc_maximum_msat);
172 Reference.reachabilityFence(capacity_msat);
173 Reference.reachabilityFence(htlc_maximum_msat);
174 if (ret >= 0 && ret <= 4096) { return null; }
175 org.ldk.structs.EffectiveCapacity ret_hu_conv = org.ldk.structs.EffectiveCapacity.constr_from_ptr(ret);
176 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
181 * Utility method to constructs a new Infinite-variant EffectiveCapacity
183 public static EffectiveCapacity infinite() {
184 long ret = bindings.EffectiveCapacity_infinite();
185 if (ret >= 0 && ret <= 4096) { return null; }
186 org.ldk.structs.EffectiveCapacity ret_hu_conv = org.ldk.structs.EffectiveCapacity.constr_from_ptr(ret);
187 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
192 * Utility method to constructs a new HintMaxHTLC-variant EffectiveCapacity
194 public static EffectiveCapacity hint_max_htlc(long amount_msat) {
195 long ret = bindings.EffectiveCapacity_hint_max_htlc(amount_msat);
196 Reference.reachabilityFence(amount_msat);
197 if (ret >= 0 && ret <= 4096) { return null; }
198 org.ldk.structs.EffectiveCapacity ret_hu_conv = org.ldk.structs.EffectiveCapacity.constr_from_ptr(ret);
199 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
204 * Utility method to constructs a new Unknown-variant EffectiveCapacity
206 public static EffectiveCapacity unknown() {
207 long ret = bindings.EffectiveCapacity_unknown();
208 if (ret >= 0 && ret <= 4096) { return null; }
209 org.ldk.structs.EffectiveCapacity ret_hu_conv = org.ldk.structs.EffectiveCapacity.constr_from_ptr(ret);
210 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
215 * Returns the effective capacity denominated in millisatoshi.
217 public long as_msat() {
218 long ret = bindings.EffectiveCapacity_as_msat(this.ptr);
219 Reference.reachabilityFence(this);