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.MaximumHTLC.class) {
31 return new MaximumHTLC(ptr, (bindings.LDKEffectiveCapacity.MaximumHTLC)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.Unknown.class) {
40 return new Unknown(ptr, (bindings.LDKEffectiveCapacity.Unknown)raw_val);
42 assert false; return null; // Unreachable without extending the (internal) bindings interface
46 * The available liquidity in the channel known from being a channel counterparty, and thus a
49 public final static class ExactLiquidity extends EffectiveCapacity {
51 * Either the inbound or outbound liquidity depending on the direction, denominated in
54 public final long liquidity_msat;
55 private ExactLiquidity(long ptr, bindings.LDKEffectiveCapacity.ExactLiquidity obj) {
57 this.liquidity_msat = obj.liquidity_msat;
61 * The maximum HTLC amount in one direction as advertised on the gossip network.
63 public final static class MaximumHTLC extends EffectiveCapacity {
65 * The maximum HTLC amount denominated in millisatoshi.
67 public final long amount_msat;
68 private MaximumHTLC(long ptr, bindings.LDKEffectiveCapacity.MaximumHTLC obj) {
70 this.amount_msat = obj.amount_msat;
74 * The total capacity of the channel as determined by the funding transaction.
76 public final static class Total extends EffectiveCapacity {
78 * The funding amount denominated in millisatoshi.
80 public final long capacity_msat;
82 * The maximum HTLC amount denominated in millisatoshi.
84 public final long htlc_maximum_msat;
85 private Total(long ptr, bindings.LDKEffectiveCapacity.Total obj) {
87 this.capacity_msat = obj.capacity_msat;
88 this.htlc_maximum_msat = obj.htlc_maximum_msat;
92 * A capacity sufficient to route any payment, typically used for private channels provided by
95 public final static class Infinite extends EffectiveCapacity {
96 private Infinite(long ptr, bindings.LDKEffectiveCapacity.Infinite obj) {
101 * A capacity that is unknown possibly because either the chain state is unavailable to know
102 * the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network.
104 public final static class Unknown extends EffectiveCapacity {
105 private Unknown(long ptr, bindings.LDKEffectiveCapacity.Unknown obj) {
110 long ret = bindings.EffectiveCapacity_clone_ptr(this.ptr);
111 Reference.reachabilityFence(this);
116 * Creates a copy of the EffectiveCapacity
118 public EffectiveCapacity clone() {
119 long ret = bindings.EffectiveCapacity_clone(this.ptr);
120 Reference.reachabilityFence(this);
121 if (ret >= 0 && ret <= 4096) { return null; }
122 org.ldk.structs.EffectiveCapacity ret_hu_conv = org.ldk.structs.EffectiveCapacity.constr_from_ptr(ret);
123 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
128 * Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity
130 public static EffectiveCapacity exact_liquidity(long liquidity_msat) {
131 long ret = bindings.EffectiveCapacity_exact_liquidity(liquidity_msat);
132 Reference.reachabilityFence(liquidity_msat);
133 if (ret >= 0 && ret <= 4096) { return null; }
134 org.ldk.structs.EffectiveCapacity ret_hu_conv = org.ldk.structs.EffectiveCapacity.constr_from_ptr(ret);
135 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
140 * Utility method to constructs a new MaximumHTLC-variant EffectiveCapacity
142 public static EffectiveCapacity maximum_htlc(long amount_msat) {
143 long ret = bindings.EffectiveCapacity_maximum_htlc(amount_msat);
144 Reference.reachabilityFence(amount_msat);
145 if (ret >= 0 && ret <= 4096) { return null; }
146 org.ldk.structs.EffectiveCapacity ret_hu_conv = org.ldk.structs.EffectiveCapacity.constr_from_ptr(ret);
147 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
152 * Utility method to constructs a new Total-variant EffectiveCapacity
154 public static EffectiveCapacity total(long capacity_msat, long htlc_maximum_msat) {
155 long ret = bindings.EffectiveCapacity_total(capacity_msat, htlc_maximum_msat);
156 Reference.reachabilityFence(capacity_msat);
157 Reference.reachabilityFence(htlc_maximum_msat);
158 if (ret >= 0 && ret <= 4096) { return null; }
159 org.ldk.structs.EffectiveCapacity ret_hu_conv = org.ldk.structs.EffectiveCapacity.constr_from_ptr(ret);
160 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
165 * Utility method to constructs a new Infinite-variant EffectiveCapacity
167 public static EffectiveCapacity infinite() {
168 long ret = bindings.EffectiveCapacity_infinite();
169 if (ret >= 0 && ret <= 4096) { return null; }
170 org.ldk.structs.EffectiveCapacity ret_hu_conv = org.ldk.structs.EffectiveCapacity.constr_from_ptr(ret);
171 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
176 * Utility method to constructs a new Unknown-variant EffectiveCapacity
178 public static EffectiveCapacity unknown() {
179 long ret = bindings.EffectiveCapacity_unknown();
180 if (ret >= 0 && ret <= 4096) { return null; }
181 org.ldk.structs.EffectiveCapacity ret_hu_conv = org.ldk.structs.EffectiveCapacity.constr_from_ptr(ret);
182 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
187 * Returns the effective capacity denominated in millisatoshi.
189 public long as_msat() {
190 long ret = bindings.EffectiveCapacity_as_msat(this.ptr);
191 Reference.reachabilityFence(this);