d35db03016f808ed75107cfb9d63ec092d15eca8
[ldk-java] / src / main / java / org / ldk / structs / BlindedRoute.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 can be sent and received to blinded routes, which serve to hide the identity of
13  * the recipient.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class BlindedRoute extends CommonBase {
17         BlindedRoute(Object _dummy, long ptr) { super(ptr); }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 super.finalize();
21                 if (ptr != 0) { bindings.BlindedRoute_free(ptr); }
22         }
23
24         /**
25          * Create a blinded route to be forwarded along `node_pks`. The last node pubkey in `node_pks`
26          * will be the destination node.
27          * 
28          * Errors if less than two hops are provided or if `node_pk`(s) are invalid.
29          */
30         public static Result_BlindedRouteNoneZ of(byte[][] node_pks, KeysInterface keys_manager) {
31                 long ret = bindings.BlindedRoute_new(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, keys_manager == null ? 0 : keys_manager.ptr);
32                 Reference.reachabilityFence(node_pks);
33                 Reference.reachabilityFence(keys_manager);
34                 if (ret >= 0 && ret <= 4096) { return null; }
35                 Result_BlindedRouteNoneZ ret_hu_conv = Result_BlindedRouteNoneZ.constr_from_ptr(ret);
36                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(keys_manager); };
37                 return ret_hu_conv;
38         }
39
40         /**
41          * Serialize the BlindedRoute object into a byte array which can be read by BlindedRoute_read
42          */
43         public byte[] write() {
44                 byte[] ret = bindings.BlindedRoute_write(this.ptr);
45                 Reference.reachabilityFence(this);
46                 return ret;
47         }
48
49         /**
50          * Read a BlindedRoute from a byte array, created by BlindedRoute_write
51          */
52         public static Result_BlindedRouteDecodeErrorZ read(byte[] ser) {
53                 long ret = bindings.BlindedRoute_read(ser);
54                 Reference.reachabilityFence(ser);
55                 if (ret >= 0 && ret <= 4096) { return null; }
56                 Result_BlindedRouteDecodeErrorZ ret_hu_conv = Result_BlindedRouteDecodeErrorZ.constr_from_ptr(ret);
57                 return ret_hu_conv;
58         }
59
60 }