f49123c4dc67a278e51b678f68cf9ce4b409e8a3
[ldk-java] / src / main / java / org / ldk / structs / BlindedTail.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  * The blinded portion of a [`Path`], if we're routing to a recipient who provided blinded paths in
13  * their BOLT12 [`Invoice`].
14  * 
15  * [`Invoice`]: crate::offers::invoice::Invoice
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class BlindedTail extends CommonBase {
19         BlindedTail(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.BlindedTail_free(ptr); }
24         }
25
26         /**
27          * The hops of the [`BlindedPath`] provided by the recipient.
28          * 
29          * [`BlindedPath`]: crate::blinded_path::BlindedPath
30          */
31         public BlindedHop[] get_hops() {
32                 long[] ret = bindings.BlindedTail_get_hops(this.ptr);
33                 Reference.reachabilityFence(this);
34                 int ret_conv_12_len = ret.length;
35                 BlindedHop[] ret_conv_12_arr = new BlindedHop[ret_conv_12_len];
36                 for (int m = 0; m < ret_conv_12_len; m++) {
37                         long ret_conv_12 = ret[m];
38                         org.ldk.structs.BlindedHop ret_conv_12_hu_conv = null; if (ret_conv_12 < 0 || ret_conv_12 > 4096) { ret_conv_12_hu_conv = new org.ldk.structs.BlindedHop(null, ret_conv_12); }
39                         if (ret_conv_12_hu_conv != null) { ret_conv_12_hu_conv.ptrs_to.add(this); };
40                         ret_conv_12_arr[m] = ret_conv_12_hu_conv;
41                 }
42                 return ret_conv_12_arr;
43         }
44
45         /**
46          * The hops of the [`BlindedPath`] provided by the recipient.
47          * 
48          * [`BlindedPath`]: crate::blinded_path::BlindedPath
49          */
50         public void set_hops(BlindedHop[] val) {
51                 bindings.BlindedTail_set_hops(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_12 -> val_conv_12 == null ? 0 : val_conv_12.ptr).toArray() : null);
52                 Reference.reachabilityFence(this);
53                 Reference.reachabilityFence(val);
54                 for (BlindedHop val_conv_12: val) { if (this != null) { this.ptrs_to.add(val_conv_12); }; };
55         }
56
57         /**
58          * The blinding point of the [`BlindedPath`] provided by the recipient.
59          * 
60          * [`BlindedPath`]: crate::blinded_path::BlindedPath
61          */
62         public byte[] get_blinding_point() {
63                 byte[] ret = bindings.BlindedTail_get_blinding_point(this.ptr);
64                 Reference.reachabilityFence(this);
65                 return ret;
66         }
67
68         /**
69          * The blinding point of the [`BlindedPath`] provided by the recipient.
70          * 
71          * [`BlindedPath`]: crate::blinded_path::BlindedPath
72          */
73         public void set_blinding_point(byte[] val) {
74                 bindings.BlindedTail_set_blinding_point(this.ptr, InternalUtils.check_arr_len(val, 33));
75                 Reference.reachabilityFence(this);
76                 Reference.reachabilityFence(val);
77         }
78
79         /**
80          * Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
81          * inferring the destination. May be 0.
82          */
83         public int get_excess_final_cltv_expiry_delta() {
84                 int ret = bindings.BlindedTail_get_excess_final_cltv_expiry_delta(this.ptr);
85                 Reference.reachabilityFence(this);
86                 return ret;
87         }
88
89         /**
90          * Excess CLTV delta added to the recipient's CLTV expiry to deter intermediate nodes from
91          * inferring the destination. May be 0.
92          */
93         public void set_excess_final_cltv_expiry_delta(int val) {
94                 bindings.BlindedTail_set_excess_final_cltv_expiry_delta(this.ptr, val);
95                 Reference.reachabilityFence(this);
96                 Reference.reachabilityFence(val);
97         }
98
99         /**
100          * The total amount paid on this [`Path`], excluding the fees.
101          */
102         public long get_final_value_msat() {
103                 long ret = bindings.BlindedTail_get_final_value_msat(this.ptr);
104                 Reference.reachabilityFence(this);
105                 return ret;
106         }
107
108         /**
109          * The total amount paid on this [`Path`], excluding the fees.
110          */
111         public void set_final_value_msat(long val) {
112                 bindings.BlindedTail_set_final_value_msat(this.ptr, val);
113                 Reference.reachabilityFence(this);
114                 Reference.reachabilityFence(val);
115         }
116
117         /**
118          * Constructs a new BlindedTail given each field
119          */
120         public static BlindedTail of(BlindedHop[] hops_arg, byte[] blinding_point_arg, int excess_final_cltv_expiry_delta_arg, long final_value_msat_arg) {
121                 long ret = bindings.BlindedTail_new(hops_arg != null ? Arrays.stream(hops_arg).mapToLong(hops_arg_conv_12 -> hops_arg_conv_12 == null ? 0 : hops_arg_conv_12.ptr).toArray() : null, InternalUtils.check_arr_len(blinding_point_arg, 33), excess_final_cltv_expiry_delta_arg, final_value_msat_arg);
122                 Reference.reachabilityFence(hops_arg);
123                 Reference.reachabilityFence(blinding_point_arg);
124                 Reference.reachabilityFence(excess_final_cltv_expiry_delta_arg);
125                 Reference.reachabilityFence(final_value_msat_arg);
126                 if (ret >= 0 && ret <= 4096) { return null; }
127                 org.ldk.structs.BlindedTail ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BlindedTail(null, ret); }
128                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
129                 for (BlindedHop hops_arg_conv_12: hops_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(hops_arg_conv_12); }; };
130                 return ret_hu_conv;
131         }
132
133         long clone_ptr() {
134                 long ret = bindings.BlindedTail_clone_ptr(this.ptr);
135                 Reference.reachabilityFence(this);
136                 return ret;
137         }
138
139         /**
140          * Creates a copy of the BlindedTail
141          */
142         public BlindedTail clone() {
143                 long ret = bindings.BlindedTail_clone(this.ptr);
144                 Reference.reachabilityFence(this);
145                 if (ret >= 0 && ret <= 4096) { return null; }
146                 org.ldk.structs.BlindedTail ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BlindedTail(null, ret); }
147                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
148                 return ret_hu_conv;
149         }
150
151         /**
152          * Generates a non-cryptographic 64-bit hash of the BlindedTail.
153          */
154         public long hash() {
155                 long ret = bindings.BlindedTail_hash(this.ptr);
156                 Reference.reachabilityFence(this);
157                 return ret;
158         }
159
160         @Override public int hashCode() {
161                 return (int)this.hash();
162         }
163         /**
164          * Checks if two BlindedTails contain equal inner contents.
165          * This ignores pointers and is_owned flags and looks at the values in fields.
166          * Two objects with NULL inner values will be considered "equal" here.
167          */
168         public boolean eq(org.ldk.structs.BlindedTail b) {
169                 boolean ret = bindings.BlindedTail_eq(this.ptr, b == null ? 0 : b.ptr);
170                 Reference.reachabilityFence(this);
171                 Reference.reachabilityFence(b);
172                 if (this != null) { this.ptrs_to.add(b); };
173                 return ret;
174         }
175
176         @Override public boolean equals(Object o) {
177                 if (!(o instanceof BlindedTail)) return false;
178                 return this.eq((BlindedTail)o);
179         }
180         /**
181          * Serialize the BlindedTail object into a byte array which can be read by BlindedTail_read
182          */
183         public byte[] write() {
184                 byte[] ret = bindings.BlindedTail_write(this.ptr);
185                 Reference.reachabilityFence(this);
186                 return ret;
187         }
188
189         /**
190          * Read a BlindedTail from a byte array, created by BlindedTail_write
191          */
192         public static Result_BlindedTailDecodeErrorZ read(byte[] ser) {
193                 long ret = bindings.BlindedTail_read(ser);
194                 Reference.reachabilityFence(ser);
195                 if (ret >= 0 && ret <= 4096) { return null; }
196                 Result_BlindedTailDecodeErrorZ ret_hu_conv = Result_BlindedTailDecodeErrorZ.constr_from_ptr(ret);
197                 return ret_hu_conv;
198         }
199
200 }