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;
81 private Total(long ptr, bindings.LDKEffectiveCapacity.Total obj) {
83 this.capacity_msat = obj.capacity_msat;
87 * A capacity sufficient to route any payment, typically used for private channels provided by
90 public final static class Infinite extends EffectiveCapacity {
91 private Infinite(long ptr, bindings.LDKEffectiveCapacity.Infinite obj) {
96 * A capacity that is unknown possibly because either the chain state is unavailable to know
97 * the total capacity or the `htlc_maximum_msat` was not advertised on the gossip network.
99 public final static class Unknown extends EffectiveCapacity {
100 private Unknown(long ptr, bindings.LDKEffectiveCapacity.Unknown obj) {
105 long ret = bindings.EffectiveCapacity_clone_ptr(this.ptr);
106 Reference.reachabilityFence(this);
111 * Creates a copy of the EffectiveCapacity
113 public EffectiveCapacity clone() {
114 long ret = bindings.EffectiveCapacity_clone(this.ptr);
115 Reference.reachabilityFence(this);
116 if (ret >= 0 && ret <= 4096) { return null; }
117 EffectiveCapacity ret_hu_conv = EffectiveCapacity.constr_from_ptr(ret);
118 ret_hu_conv.ptrs_to.add(this);
123 * Utility method to constructs a new ExactLiquidity-variant EffectiveCapacity
125 public static EffectiveCapacity exact_liquidity(long liquidity_msat) {
126 long ret = bindings.EffectiveCapacity_exact_liquidity(liquidity_msat);
127 Reference.reachabilityFence(liquidity_msat);
128 if (ret >= 0 && ret <= 4096) { return null; }
129 EffectiveCapacity ret_hu_conv = EffectiveCapacity.constr_from_ptr(ret);
130 ret_hu_conv.ptrs_to.add(ret_hu_conv);
135 * Utility method to constructs a new MaximumHTLC-variant EffectiveCapacity
137 public static EffectiveCapacity maximum_htlc(long amount_msat) {
138 long ret = bindings.EffectiveCapacity_maximum_htlc(amount_msat);
139 Reference.reachabilityFence(amount_msat);
140 if (ret >= 0 && ret <= 4096) { return null; }
141 EffectiveCapacity ret_hu_conv = EffectiveCapacity.constr_from_ptr(ret);
142 ret_hu_conv.ptrs_to.add(ret_hu_conv);
147 * Utility method to constructs a new Total-variant EffectiveCapacity
149 public static EffectiveCapacity total(long capacity_msat) {
150 long ret = bindings.EffectiveCapacity_total(capacity_msat);
151 Reference.reachabilityFence(capacity_msat);
152 if (ret >= 0 && ret <= 4096) { return null; }
153 EffectiveCapacity ret_hu_conv = EffectiveCapacity.constr_from_ptr(ret);
154 ret_hu_conv.ptrs_to.add(ret_hu_conv);
159 * Utility method to constructs a new Infinite-variant EffectiveCapacity
161 public static EffectiveCapacity infinite() {
162 long ret = bindings.EffectiveCapacity_infinite();
163 if (ret >= 0 && ret <= 4096) { return null; }
164 EffectiveCapacity ret_hu_conv = EffectiveCapacity.constr_from_ptr(ret);
165 ret_hu_conv.ptrs_to.add(ret_hu_conv);
170 * Utility method to constructs a new Unknown-variant EffectiveCapacity
172 public static EffectiveCapacity unknown() {
173 long ret = bindings.EffectiveCapacity_unknown();
174 if (ret >= 0 && ret <= 4096) { return null; }
175 EffectiveCapacity ret_hu_conv = EffectiveCapacity.constr_from_ptr(ret);
176 ret_hu_conv.ptrs_to.add(ret_hu_conv);
181 * Returns the effective capacity denominated in millisatoshi.
183 public long as_msat() {
184 long ret = bindings.EffectiveCapacity_as_msat(this.ptr);
185 Reference.reachabilityFence(this);