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 * A data structure for tracking in-flight HTLCs. May be used during pathfinding to account for
13 * in-use channel liquidity.
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class InFlightHtlcs extends CommonBase {
17 InFlightHtlcs(Object _dummy, long ptr) { super(ptr); }
18 @Override @SuppressWarnings("deprecation")
19 protected void finalize() throws Throwable {
21 if (ptr != 0) { bindings.InFlightHtlcs_free(ptr); }
25 long ret = bindings.InFlightHtlcs_clone_ptr(this.ptr);
26 Reference.reachabilityFence(this);
31 * Creates a copy of the InFlightHtlcs
33 public InFlightHtlcs clone() {
34 long ret = bindings.InFlightHtlcs_clone(this.ptr);
35 Reference.reachabilityFence(this);
36 if (ret >= 0 && ret <= 4096) { return null; }
37 org.ldk.structs.InFlightHtlcs ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InFlightHtlcs(null, ret); }
38 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
43 * Constructs an empty `InFlightHtlcs`.
45 public static InFlightHtlcs of() {
46 long ret = bindings.InFlightHtlcs_new();
47 if (ret >= 0 && ret <= 4096) { return null; }
48 org.ldk.structs.InFlightHtlcs ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InFlightHtlcs(null, ret); }
49 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
54 * Takes in a path with payer's node id and adds the path's details to `InFlightHtlcs`.
56 public void process_path(org.ldk.structs.Path path, byte[] payer_node_id) {
57 bindings.InFlightHtlcs_process_path(this.ptr, path == null ? 0 : path.ptr, InternalUtils.check_arr_len(payer_node_id, 33));
58 Reference.reachabilityFence(this);
59 Reference.reachabilityFence(path);
60 Reference.reachabilityFence(payer_node_id);
61 if (this != null) { this.ptrs_to.add(path); };
65 * Adds a known HTLC given the public key of the HTLC source, target, and short channel
68 public void add_inflight_htlc(org.ldk.structs.NodeId source, org.ldk.structs.NodeId target, long channel_scid, long used_msat) {
69 bindings.InFlightHtlcs_add_inflight_htlc(this.ptr, source == null ? 0 : source.ptr, target == null ? 0 : target.ptr, channel_scid, used_msat);
70 Reference.reachabilityFence(this);
71 Reference.reachabilityFence(source);
72 Reference.reachabilityFence(target);
73 Reference.reachabilityFence(channel_scid);
74 Reference.reachabilityFence(used_msat);
75 if (this != null) { this.ptrs_to.add(source); };
76 if (this != null) { this.ptrs_to.add(target); };
80 * Returns liquidity in msat given the public key of the HTLC source, target, and short channel
83 public Option_u64Z used_liquidity_msat(org.ldk.structs.NodeId source, org.ldk.structs.NodeId target, long channel_scid) {
84 long ret = bindings.InFlightHtlcs_used_liquidity_msat(this.ptr, source == null ? 0 : source.ptr, target == null ? 0 : target.ptr, channel_scid);
85 Reference.reachabilityFence(this);
86 Reference.reachabilityFence(source);
87 Reference.reachabilityFence(target);
88 Reference.reachabilityFence(channel_scid);
89 if (ret >= 0 && ret <= 4096) { return null; }
90 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
91 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
92 if (this != null) { this.ptrs_to.add(source); };
93 if (this != null) { this.ptrs_to.add(target); };
98 * Serialize the InFlightHtlcs object into a byte array which can be read by InFlightHtlcs_read
100 public byte[] write() {
101 byte[] ret = bindings.InFlightHtlcs_write(this.ptr);
102 Reference.reachabilityFence(this);
107 * Read a InFlightHtlcs from a byte array, created by InFlightHtlcs_write
109 public static Result_InFlightHtlcsDecodeErrorZ read(byte[] ser) {
110 long ret = bindings.InFlightHtlcs_read(ser);
111 Reference.reachabilityFence(ser);
112 if (ret >= 0 && ret <= 4096) { return null; }
113 Result_InFlightHtlcsDecodeErrorZ ret_hu_conv = Result_InFlightHtlcsDecodeErrorZ.constr_from_ptr(ret);