1164d5869f3e8fadc68fd59da76d67233ca561c7
[ldk-java] / src / main / java / org / ldk / structs / InFlightHtlcs.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 java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * A data structure for tracking in-flight HTLCs. May be used during pathfinding to account for
13  * in-use channel liquidity.
14  */
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 {
20                 super.finalize();
21                 if (ptr != 0) { bindings.InFlightHtlcs_free(ptr); }
22         }
23
24         long clone_ptr() {
25                 long ret = bindings.InFlightHtlcs_clone_ptr(this.ptr);
26                 Reference.reachabilityFence(this);
27                 return ret;
28         }
29
30         /**
31          * Creates a copy of the InFlightHtlcs
32          */
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); };
39                 return ret_hu_conv;
40         }
41
42         /**
43          * Constructs an empty `InFlightHtlcs`.
44          */
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); };
50                 return ret_hu_conv;
51         }
52
53         /**
54          * Returns liquidity in msat given the public key of the HTLC source, target, and short channel
55          * id.
56          */
57         public Option_u64Z used_liquidity_msat(org.ldk.structs.NodeId source, org.ldk.structs.NodeId target, long channel_scid) {
58                 long ret = bindings.InFlightHtlcs_used_liquidity_msat(this.ptr, source == null ? 0 : source.ptr, target == null ? 0 : target.ptr, channel_scid);
59                 Reference.reachabilityFence(this);
60                 Reference.reachabilityFence(source);
61                 Reference.reachabilityFence(target);
62                 Reference.reachabilityFence(channel_scid);
63                 if (ret >= 0 && ret <= 4096) { return null; }
64                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
65                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
66                 if (this != null) { this.ptrs_to.add(source); };
67                 if (this != null) { this.ptrs_to.add(target); };
68                 return ret_hu_conv;
69         }
70
71         /**
72          * Serialize the InFlightHtlcs object into a byte array which can be read by InFlightHtlcs_read
73          */
74         public byte[] write() {
75                 byte[] ret = bindings.InFlightHtlcs_write(this.ptr);
76                 Reference.reachabilityFence(this);
77                 return ret;
78         }
79
80         /**
81          * Read a InFlightHtlcs from a byte array, created by InFlightHtlcs_write
82          */
83         public static Result_InFlightHtlcsDecodeErrorZ read(byte[] ser) {
84                 long ret = bindings.InFlightHtlcs_read(ser);
85                 Reference.reachabilityFence(ser);
86                 if (ret >= 0 && ret <= 4096) { return null; }
87                 Result_InFlightHtlcsDecodeErrorZ ret_hu_conv = Result_InFlightHtlcsDecodeErrorZ.constr_from_ptr(ret);
88                 return ret_hu_conv;
89         }
90
91 }