[Java] Update auto-generated bindings to 0.0.115
[ldk-java] / src / main / java / org / ldk / structs / Path.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 path in a [`Route`] to the payment recipient. Must always be at least length one.
13  * If no [`Path::blinded_tail`] is present, then [`Path::hops`] length may be up to 19.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class Path extends CommonBase {
17         Path(Object _dummy, long ptr) { super(ptr); }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 super.finalize();
21                 if (ptr != 0) { bindings.Path_free(ptr); }
22         }
23
24         /**
25          * The list of unblinded hops in this [`Path`]. Must be at least length one.
26          */
27         public RouteHop[] get_hops() {
28                 long[] ret = bindings.Path_get_hops(this.ptr);
29                 Reference.reachabilityFence(this);
30                 int ret_conv_10_len = ret.length;
31                 RouteHop[] ret_conv_10_arr = new RouteHop[ret_conv_10_len];
32                 for (int k = 0; k < ret_conv_10_len; k++) {
33                         long ret_conv_10 = ret[k];
34                         org.ldk.structs.RouteHop ret_conv_10_hu_conv = null; if (ret_conv_10 < 0 || ret_conv_10 > 4096) { ret_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, ret_conv_10); }
35                         if (ret_conv_10_hu_conv != null) { ret_conv_10_hu_conv.ptrs_to.add(this); };
36                         ret_conv_10_arr[k] = ret_conv_10_hu_conv;
37                 }
38                 return ret_conv_10_arr;
39         }
40
41         /**
42          * The list of unblinded hops in this [`Path`]. Must be at least length one.
43          */
44         public void set_hops(RouteHop[] val) {
45                 bindings.Path_set_hops(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_10 -> val_conv_10 == null ? 0 : val_conv_10.ptr).toArray() : null);
46                 Reference.reachabilityFence(this);
47                 Reference.reachabilityFence(val);
48                 for (RouteHop val_conv_10: val) { if (this != null) { this.ptrs_to.add(val_conv_10); }; };
49         }
50
51         /**
52          * The blinded path at which this path terminates, if we're sending to one, and its metadata.
53          * 
54          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
55          */
56         @Nullable
57         public BlindedTail get_blinded_tail() {
58                 long ret = bindings.Path_get_blinded_tail(this.ptr);
59                 Reference.reachabilityFence(this);
60                 if (ret >= 0 && ret <= 4096) { return null; }
61                 org.ldk.structs.BlindedTail ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BlindedTail(null, ret); }
62                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
63                 return ret_hu_conv;
64         }
65
66         /**
67          * The blinded path at which this path terminates, if we're sending to one, and its metadata.
68          * 
69          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
70          */
71         public void set_blinded_tail(@Nullable org.ldk.structs.BlindedTail val) {
72                 bindings.Path_set_blinded_tail(this.ptr, val == null ? 0 : val.ptr);
73                 Reference.reachabilityFence(this);
74                 Reference.reachabilityFence(val);
75                 if (this != null) { this.ptrs_to.add(val); };
76         }
77
78         /**
79          * Constructs a new Path given each field
80          */
81         public static Path of(RouteHop[] hops_arg, org.ldk.structs.BlindedTail blinded_tail_arg) {
82                 long ret = bindings.Path_new(hops_arg != null ? Arrays.stream(hops_arg).mapToLong(hops_arg_conv_10 -> hops_arg_conv_10 == null ? 0 : hops_arg_conv_10.ptr).toArray() : null, blinded_tail_arg == null ? 0 : blinded_tail_arg.ptr);
83                 Reference.reachabilityFence(hops_arg);
84                 Reference.reachabilityFence(blinded_tail_arg);
85                 if (ret >= 0 && ret <= 4096) { return null; }
86                 org.ldk.structs.Path ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Path(null, ret); }
87                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
88                 for (RouteHop hops_arg_conv_10: hops_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(hops_arg_conv_10); }; };
89                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(blinded_tail_arg); };
90                 return ret_hu_conv;
91         }
92
93         long clone_ptr() {
94                 long ret = bindings.Path_clone_ptr(this.ptr);
95                 Reference.reachabilityFence(this);
96                 return ret;
97         }
98
99         /**
100          * Creates a copy of the Path
101          */
102         public Path clone() {
103                 long ret = bindings.Path_clone(this.ptr);
104                 Reference.reachabilityFence(this);
105                 if (ret >= 0 && ret <= 4096) { return null; }
106                 org.ldk.structs.Path ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Path(null, ret); }
107                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
108                 return ret_hu_conv;
109         }
110
111         /**
112          * Generates a non-cryptographic 64-bit hash of the Path.
113          */
114         public long hash() {
115                 long ret = bindings.Path_hash(this.ptr);
116                 Reference.reachabilityFence(this);
117                 return ret;
118         }
119
120         @Override public int hashCode() {
121                 return (int)this.hash();
122         }
123         /**
124          * Checks if two Paths contain equal inner contents.
125          * This ignores pointers and is_owned flags and looks at the values in fields.
126          * Two objects with NULL inner values will be considered "equal" here.
127          */
128         public boolean eq(org.ldk.structs.Path b) {
129                 boolean ret = bindings.Path_eq(this.ptr, b == null ? 0 : b.ptr);
130                 Reference.reachabilityFence(this);
131                 Reference.reachabilityFence(b);
132                 if (this != null) { this.ptrs_to.add(b); };
133                 return ret;
134         }
135
136         @Override public boolean equals(Object o) {
137                 if (!(o instanceof Path)) return false;
138                 return this.eq((Path)o);
139         }
140         /**
141          * Gets the fees for a given path, excluding any excess paid to the recipient.
142          */
143         public long fee_msat() {
144                 long ret = bindings.Path_fee_msat(this.ptr);
145                 Reference.reachabilityFence(this);
146                 return ret;
147         }
148
149         /**
150          * Gets the total amount paid on this [`Path`], excluding the fees.
151          */
152         public long final_value_msat() {
153                 long ret = bindings.Path_final_value_msat(this.ptr);
154                 Reference.reachabilityFence(this);
155                 return ret;
156         }
157
158         /**
159          * Gets the final hop's CLTV expiry delta.
160          */
161         public Option_u32Z final_cltv_expiry_delta() {
162                 long ret = bindings.Path_final_cltv_expiry_delta(this.ptr);
163                 Reference.reachabilityFence(this);
164                 if (ret >= 0 && ret <= 4096) { return null; }
165                 org.ldk.structs.Option_u32Z ret_hu_conv = org.ldk.structs.Option_u32Z.constr_from_ptr(ret);
166                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
167                 return ret_hu_conv;
168         }
169
170 }