[Java] Update auto-generated bindings to 0.0.117
[ldk-java] / src / main / java / org / ldk / structs / BlindedPath.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  * Onion messages and payments can be sent and received to blinded paths, which serve to hide the
13  * identity of the recipient.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class BlindedPath extends CommonBase {
17         BlindedPath(Object _dummy, long ptr) { super(ptr); }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 super.finalize();
21                 if (ptr != 0) { bindings.BlindedPath_free(ptr); }
22         }
23
24         /**
25          * To send to a blinded path, the sender first finds a route to the unblinded
26          * `introduction_node_id`, which can unblind its [`encrypted_payload`] to find out the onion
27          * message or payment's next hop and forward it along.
28          * 
29          * [`encrypted_payload`]: BlindedHop::encrypted_payload
30          */
31         public byte[] get_introduction_node_id() {
32                 byte[] ret = bindings.BlindedPath_get_introduction_node_id(this.ptr);
33                 Reference.reachabilityFence(this);
34                 return ret;
35         }
36
37         /**
38          * To send to a blinded path, the sender first finds a route to the unblinded
39          * `introduction_node_id`, which can unblind its [`encrypted_payload`] to find out the onion
40          * message or payment's next hop and forward it along.
41          * 
42          * [`encrypted_payload`]: BlindedHop::encrypted_payload
43          */
44         public void set_introduction_node_id(byte[] val) {
45                 bindings.BlindedPath_set_introduction_node_id(this.ptr, InternalUtils.check_arr_len(val, 33));
46                 Reference.reachabilityFence(this);
47                 Reference.reachabilityFence(val);
48         }
49
50         /**
51          * Used by the introduction node to decrypt its [`encrypted_payload`] to forward the onion
52          * message or payment.
53          * 
54          * [`encrypted_payload`]: BlindedHop::encrypted_payload
55          */
56         public byte[] get_blinding_point() {
57                 byte[] ret = bindings.BlindedPath_get_blinding_point(this.ptr);
58                 Reference.reachabilityFence(this);
59                 return ret;
60         }
61
62         /**
63          * Used by the introduction node to decrypt its [`encrypted_payload`] to forward the onion
64          * message or payment.
65          * 
66          * [`encrypted_payload`]: BlindedHop::encrypted_payload
67          */
68         public void set_blinding_point(byte[] val) {
69                 bindings.BlindedPath_set_blinding_point(this.ptr, InternalUtils.check_arr_len(val, 33));
70                 Reference.reachabilityFence(this);
71                 Reference.reachabilityFence(val);
72         }
73
74         /**
75          * The hops composing the blinded path.
76          */
77         public BlindedHop[] get_blinded_hops() {
78                 long[] ret = bindings.BlindedPath_get_blinded_hops(this.ptr);
79                 Reference.reachabilityFence(this);
80                 int ret_conv_12_len = ret.length;
81                 BlindedHop[] ret_conv_12_arr = new BlindedHop[ret_conv_12_len];
82                 for (int m = 0; m < ret_conv_12_len; m++) {
83                         long ret_conv_12 = ret[m];
84                         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); }
85                         if (ret_conv_12_hu_conv != null) { ret_conv_12_hu_conv.ptrs_to.add(this); };
86                         ret_conv_12_arr[m] = ret_conv_12_hu_conv;
87                 }
88                 return ret_conv_12_arr;
89         }
90
91         /**
92          * The hops composing the blinded path.
93          */
94         public void set_blinded_hops(BlindedHop[] val) {
95                 bindings.BlindedPath_set_blinded_hops(this.ptr, val != null ? Arrays.stream(val).mapToLong(val_conv_12 -> val_conv_12 == null ? 0 : val_conv_12.ptr).toArray() : null);
96                 Reference.reachabilityFence(this);
97                 Reference.reachabilityFence(val);
98                 for (BlindedHop val_conv_12: val) { if (this != null) { this.ptrs_to.add(val_conv_12); }; };
99         }
100
101         /**
102          * Constructs a new BlindedPath given each field
103          */
104         public static BlindedPath of(byte[] introduction_node_id_arg, byte[] blinding_point_arg, BlindedHop[] blinded_hops_arg) {
105                 long ret = bindings.BlindedPath_new(InternalUtils.check_arr_len(introduction_node_id_arg, 33), InternalUtils.check_arr_len(blinding_point_arg, 33), blinded_hops_arg != null ? Arrays.stream(blinded_hops_arg).mapToLong(blinded_hops_arg_conv_12 -> blinded_hops_arg_conv_12 == null ? 0 : blinded_hops_arg_conv_12.ptr).toArray() : null);
106                 Reference.reachabilityFence(introduction_node_id_arg);
107                 Reference.reachabilityFence(blinding_point_arg);
108                 Reference.reachabilityFence(blinded_hops_arg);
109                 if (ret >= 0 && ret <= 4096) { return null; }
110                 org.ldk.structs.BlindedPath ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BlindedPath(null, ret); }
111                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
112                 for (BlindedHop blinded_hops_arg_conv_12: blinded_hops_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(blinded_hops_arg_conv_12); }; };
113                 return ret_hu_conv;
114         }
115
116         long clone_ptr() {
117                 long ret = bindings.BlindedPath_clone_ptr(this.ptr);
118                 Reference.reachabilityFence(this);
119                 return ret;
120         }
121
122         /**
123          * Creates a copy of the BlindedPath
124          */
125         public BlindedPath clone() {
126                 long ret = bindings.BlindedPath_clone(this.ptr);
127                 Reference.reachabilityFence(this);
128                 if (ret >= 0 && ret <= 4096) { return null; }
129                 org.ldk.structs.BlindedPath ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BlindedPath(null, ret); }
130                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
131                 return ret_hu_conv;
132         }
133
134         /**
135          * Generates a non-cryptographic 64-bit hash of the BlindedPath.
136          */
137         public long hash() {
138                 long ret = bindings.BlindedPath_hash(this.ptr);
139                 Reference.reachabilityFence(this);
140                 return ret;
141         }
142
143         @Override public int hashCode() {
144                 return (int)this.hash();
145         }
146         /**
147          * Checks if two BlindedPaths contain equal inner contents.
148          * This ignores pointers and is_owned flags and looks at the values in fields.
149          * Two objects with NULL inner values will be considered "equal" here.
150          */
151         public boolean eq(org.ldk.structs.BlindedPath b) {
152                 boolean ret = bindings.BlindedPath_eq(this.ptr, b == null ? 0 : b.ptr);
153                 Reference.reachabilityFence(this);
154                 Reference.reachabilityFence(b);
155                 if (this != null) { this.ptrs_to.add(b); };
156                 return ret;
157         }
158
159         @Override public boolean equals(Object o) {
160                 if (!(o instanceof BlindedPath)) return false;
161                 return this.eq((BlindedPath)o);
162         }
163         /**
164          * Create a blinded path for an onion message, to be forwarded along `node_pks`. The last node
165          * pubkey in `node_pks` will be the destination node.
166          * 
167          * Errors if less than two hops are provided or if `node_pk`(s) are invalid.
168          */
169         public static Result_BlindedPathNoneZ new_for_message(byte[][] node_pks, org.ldk.structs.EntropySource entropy_source) {
170                 long ret = bindings.BlindedPath_new_for_message(node_pks != null ? Arrays.stream(node_pks).map(node_pks_conv_8 -> InternalUtils.check_arr_len(node_pks_conv_8, 33)).toArray(byte[][]::new) : null, entropy_source.ptr);
171                 Reference.reachabilityFence(node_pks);
172                 Reference.reachabilityFence(entropy_source);
173                 if (ret >= 0 && ret <= 4096) { return null; }
174                 Result_BlindedPathNoneZ ret_hu_conv = Result_BlindedPathNoneZ.constr_from_ptr(ret);
175                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
176                 return ret_hu_conv;
177         }
178
179         /**
180          * Serialize the BlindedPath object into a byte array which can be read by BlindedPath_read
181          */
182         public byte[] write() {
183                 byte[] ret = bindings.BlindedPath_write(this.ptr);
184                 Reference.reachabilityFence(this);
185                 return ret;
186         }
187
188         /**
189          * Read a BlindedPath from a byte array, created by BlindedPath_write
190          */
191         public static Result_BlindedPathDecodeErrorZ read(byte[] ser) {
192                 long ret = bindings.BlindedPath_read(ser);
193                 Reference.reachabilityFence(ser);
194                 if (ret >= 0 && ret <= 4096) { return null; }
195                 Result_BlindedPathDecodeErrorZ ret_hu_conv = Result_BlindedPathDecodeErrorZ.constr_from_ptr(ret);
196                 return ret_hu_conv;
197         }
198
199 }