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.BlindedRoute.class) {
28 return new BlindedRoute(ptr, (bindings.LDKDestination.BlindedRoute)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 route.
46 public final static class BlindedRoute extends Destination {
47 public final org.ldk.structs.BlindedRoute blinded_route;
48 private BlindedRoute(long ptr, bindings.LDKDestination.BlindedRoute obj) {
50 long blinded_route = obj.blinded_route;
51 org.ldk.structs.BlindedRoute blinded_route_hu_conv = null; if (blinded_route < 0 || blinded_route > 4096) { blinded_route_hu_conv = new org.ldk.structs.BlindedRoute(null, blinded_route); }
52 if (blinded_route_hu_conv != null) { blinded_route_hu_conv.ptrs_to.add(this); };
53 this.blinded_route = blinded_route_hu_conv;
57 * Utility method to constructs a new Node-variant Destination
59 public static Destination node(byte[] a) {
60 long ret = bindings.Destination_node(InternalUtils.check_arr_len(a, 33));
61 Reference.reachabilityFence(a);
62 if (ret >= 0 && ret <= 4096) { return null; }
63 org.ldk.structs.Destination ret_hu_conv = org.ldk.structs.Destination.constr_from_ptr(ret);
64 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
69 * Utility method to constructs a new BlindedRoute-variant Destination
71 public static Destination blinded_route(BlindedRoute a) {
72 long ret = bindings.Destination_blinded_route(a == null ? 0 : a.ptr);
73 Reference.reachabilityFence(a);
74 if (ret >= 0 && ret <= 4096) { return null; }
75 org.ldk.structs.Destination ret_hu_conv = org.ldk.structs.Destination.constr_from_ptr(ret);
76 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
77 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
78 // Due to rust's strict-ownership memory model, in some cases we need to "move"
79 // an object to pass exclusive ownership to the function being called.
80 // In most cases, we avoid ret_hu_conv being visible in GC'd languages by cloning the object
81 // at the FFI layer, creating a new object which Rust can claim ownership of
82 // However, in some cases (eg here), there is no way to clone an object, and thus
83 // we actually have to pass full ownership to Rust.
84 // Thus, after ret_hu_conv call, a is reset to null and is now a dummy object.