1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Onion messages and payments can be sent and received to blinded paths, which serve to hide the
13 * identity of the recipient.
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 {
21 if (ptr != 0) { bindings.BlindedPath_free(ptr); }
25 long ret = bindings.BlindedPath_clone_ptr(this.ptr);
26 Reference.reachabilityFence(this);
31 * Creates a copy of the BlindedPath
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); };
43 * Generates a non-cryptographic 64-bit hash of the BlindedPath.
46 long ret = bindings.BlindedPath_hash(this.ptr);
47 Reference.reachabilityFence(this);
51 @Override public int hashCode() {
52 return (int)this.hash();
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.
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); };
67 @Override public boolean equals(Object o) {
68 if (!(o instanceof BlindedPath)) return false;
69 return this.eq((BlindedPath)o);
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.
75 * Errors if less than two hops are provided or if `node_pk`(s) are invalid.
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); };
88 * Serialize the BlindedPath object into a byte array which can be read by BlindedPath_read
90 public byte[] write() {
91 byte[] ret = bindings.BlindedPath_write(this.ptr);
92 Reference.reachabilityFence(this);
97 * Read a BlindedPath from a byte array, created by BlindedPath_write
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);