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 * The destination of an onion message.
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class Destination extends CommonBase {
16 private Destination(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.Destination_free(ptr); }
22 static Destination constr_from_ptr(long ptr) {
23 bindings.LDKDestination raw_val = bindings.LDKDestination_ref_from_ptr(ptr);
24 if (raw_val.getClass() == bindings.LDKDestination.Node.class) {
25 return new Node(ptr, (bindings.LDKDestination.Node)raw_val);
27 if (raw_val.getClass() == bindings.LDKDestination.BlindedPath.class) {
28 return new BlindedPath(ptr, (bindings.LDKDestination.BlindedPath)raw_val);
30 assert false; return null; // Unreachable without extending the (internal) bindings interface
34 * We're sending this onion message to a node.
36 public final static class Node extends Destination {
37 public final byte[] node;
38 private Node(long ptr, bindings.LDKDestination.Node obj) {
44 * We're sending this onion message to a blinded path.
46 public final static class BlindedPath extends Destination {
47 public final org.ldk.structs.BlindedPath blinded_path;
48 private BlindedPath(long ptr, bindings.LDKDestination.BlindedPath obj) {
50 long blinded_path = obj.blinded_path;
51 org.ldk.structs.BlindedPath blinded_path_hu_conv = null; if (blinded_path < 0 || blinded_path > 4096) { blinded_path_hu_conv = new org.ldk.structs.BlindedPath(null, blinded_path); }
52 if (blinded_path_hu_conv != null) { blinded_path_hu_conv.ptrs_to.add(this); };
53 this.blinded_path = blinded_path_hu_conv;
57 long ret = bindings.Destination_clone_ptr(this.ptr);
58 Reference.reachabilityFence(this);
63 * Creates a copy of the Destination
65 public Destination clone() {
66 long ret = bindings.Destination_clone(this.ptr);
67 Reference.reachabilityFence(this);
68 if (ret >= 0 && ret <= 4096) { return null; }
69 org.ldk.structs.Destination ret_hu_conv = org.ldk.structs.Destination.constr_from_ptr(ret);
70 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
75 * Utility method to constructs a new Node-variant Destination
77 public static Destination node(byte[] a) {
78 long ret = bindings.Destination_node(InternalUtils.check_arr_len(a, 33));
79 Reference.reachabilityFence(a);
80 if (ret >= 0 && ret <= 4096) { return null; }
81 org.ldk.structs.Destination ret_hu_conv = org.ldk.structs.Destination.constr_from_ptr(ret);
82 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
87 * Utility method to constructs a new BlindedPath-variant Destination
89 public static Destination blinded_path(org.ldk.structs.BlindedPath a) {
90 long ret = bindings.Destination_blinded_path(a == null ? 0 : a.ptr);
91 Reference.reachabilityFence(a);
92 if (ret >= 0 && ret <= 4096) { return null; }
93 org.ldk.structs.Destination ret_hu_conv = org.ldk.structs.Destination.constr_from_ptr(ret);
94 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
95 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };