7a7999d038944f0ac29350a81f7193db4b2ec2dc
[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         long clone_ptr() {
25                 long ret = bindings.BlindedPath_clone_ptr(this.ptr);
26                 Reference.reachabilityFence(this);
27                 return ret;
28         }
29
30         /**
31          * Creates a copy of the BlindedPath
32          */
33         public BlindedPath clone() {
34                 long ret = bindings.BlindedPath_clone(this.ptr);
35                 Reference.reachabilityFence(this);
36                 if (ret >= 0 && ret <= 4096) { return null; }
37                 org.ldk.structs.BlindedPath ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BlindedPath(null, ret); }
38                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
39                 return ret_hu_conv;
40         }
41
42         /**
43          * Generates a non-cryptographic 64-bit hash of the BlindedPath.
44          */
45         public long hash() {
46                 long ret = bindings.BlindedPath_hash(this.ptr);
47                 Reference.reachabilityFence(this);
48                 return ret;
49         }
50
51         @Override public int hashCode() {
52                 return (int)this.hash();
53         }
54         /**
55          * Checks if two BlindedPaths contain equal inner contents.
56          * This ignores pointers and is_owned flags and looks at the values in fields.
57          * Two objects with NULL inner values will be considered "equal" here.
58          */
59         public boolean eq(org.ldk.structs.BlindedPath b) {
60                 boolean ret = bindings.BlindedPath_eq(this.ptr, b == null ? 0 : b.ptr);
61                 Reference.reachabilityFence(this);
62                 Reference.reachabilityFence(b);
63                 if (this != null) { this.ptrs_to.add(b); };
64                 return ret;
65         }
66
67         @Override public boolean equals(Object o) {
68                 if (!(o instanceof BlindedPath)) return false;
69                 return this.eq((BlindedPath)o);
70         }
71         /**
72          * Create a blinded path for an onion message, to be forwarded along `node_pks`. The last node
73          * pubkey in `node_pks` will be the destination node.
74          * 
75          * Errors if less than two hops are provided or if `node_pk`(s) are invalid.
76          */
77         public static Result_BlindedPathNoneZ new_for_message(byte[][] node_pks, org.ldk.structs.EntropySource entropy_source) {
78                 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 == null ? 0 : entropy_source.ptr);
79                 Reference.reachabilityFence(node_pks);
80                 Reference.reachabilityFence(entropy_source);
81                 if (ret >= 0 && ret <= 4096) { return null; }
82                 Result_BlindedPathNoneZ ret_hu_conv = Result_BlindedPathNoneZ.constr_from_ptr(ret);
83                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(entropy_source); };
84                 return ret_hu_conv;
85         }
86
87         /**
88          * Serialize the BlindedPath object into a byte array which can be read by BlindedPath_read
89          */
90         public byte[] write() {
91                 byte[] ret = bindings.BlindedPath_write(this.ptr);
92                 Reference.reachabilityFence(this);
93                 return ret;
94         }
95
96         /**
97          * Read a BlindedPath from a byte array, created by BlindedPath_write
98          */
99         public static Result_BlindedPathDecodeErrorZ read(byte[] ser) {
100                 long ret = bindings.BlindedPath_read(ser);
101                 Reference.reachabilityFence(ser);
102                 if (ret >= 0 && ret <= 4096) { return null; }
103                 Result_BlindedPathDecodeErrorZ ret_hu_conv = Result_BlindedPathDecodeErrorZ.constr_from_ptr(ret);
104                 return ret_hu_conv;
105         }
106
107 }