[Java] Update auto-generated bindings to 0.0.117
[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          * Note that blinded_tail_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
82          */
83         public static Path of(RouteHop[] hops_arg, @Nullable org.ldk.structs.BlindedTail blinded_tail_arg) {
84                 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);
85                 Reference.reachabilityFence(hops_arg);
86                 Reference.reachabilityFence(blinded_tail_arg);
87                 if (ret >= 0 && ret <= 4096) { return null; }
88                 org.ldk.structs.Path ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Path(null, ret); }
89                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
90                 for (RouteHop hops_arg_conv_10: hops_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(hops_arg_conv_10); }; };
91                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(blinded_tail_arg); };
92                 return ret_hu_conv;
93         }
94
95         long clone_ptr() {
96                 long ret = bindings.Path_clone_ptr(this.ptr);
97                 Reference.reachabilityFence(this);
98                 return ret;
99         }
100
101         /**
102          * Creates a copy of the Path
103          */
104         public Path clone() {
105                 long ret = bindings.Path_clone(this.ptr);
106                 Reference.reachabilityFence(this);
107                 if (ret >= 0 && ret <= 4096) { return null; }
108                 org.ldk.structs.Path ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Path(null, ret); }
109                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
110                 return ret_hu_conv;
111         }
112
113         /**
114          * Generates a non-cryptographic 64-bit hash of the Path.
115          */
116         public long hash() {
117                 long ret = bindings.Path_hash(this.ptr);
118                 Reference.reachabilityFence(this);
119                 return ret;
120         }
121
122         @Override public int hashCode() {
123                 return (int)this.hash();
124         }
125         /**
126          * Checks if two Paths contain equal inner contents.
127          * This ignores pointers and is_owned flags and looks at the values in fields.
128          * Two objects with NULL inner values will be considered "equal" here.
129          */
130         public boolean eq(org.ldk.structs.Path b) {
131                 boolean ret = bindings.Path_eq(this.ptr, b == null ? 0 : b.ptr);
132                 Reference.reachabilityFence(this);
133                 Reference.reachabilityFence(b);
134                 if (this != null) { this.ptrs_to.add(b); };
135                 return ret;
136         }
137
138         @Override public boolean equals(Object o) {
139                 if (!(o instanceof Path)) return false;
140                 return this.eq((Path)o);
141         }
142         /**
143          * Gets the fees for a given path, excluding any excess paid to the recipient.
144          */
145         public long fee_msat() {
146                 long ret = bindings.Path_fee_msat(this.ptr);
147                 Reference.reachabilityFence(this);
148                 return ret;
149         }
150
151         /**
152          * Gets the total amount paid on this [`Path`], excluding the fees.
153          */
154         public long final_value_msat() {
155                 long ret = bindings.Path_final_value_msat(this.ptr);
156                 Reference.reachabilityFence(this);
157                 return ret;
158         }
159
160         /**
161          * Gets the final hop's CLTV expiry delta.
162          */
163         public Option_u32Z final_cltv_expiry_delta() {
164                 long ret = bindings.Path_final_cltv_expiry_delta(this.ptr);
165                 Reference.reachabilityFence(this);
166                 if (ret >= 0 && ret <= 4096) { return null; }
167                 org.ldk.structs.Option_u32Z ret_hu_conv = org.ldk.structs.Option_u32Z.constr_from_ptr(ret);
168                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
169                 return ret_hu_conv;
170         }
171
172 }