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 * Represents the compressed public key of a node
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class NodeId extends CommonBase {
16 NodeId(Object _dummy, long ptr) { super(ptr); }
17 @Override @SuppressWarnings("deprecation")
18 protected void finalize() throws Throwable {
20 if (ptr != 0) { bindings.NodeId_free(ptr); }
24 long ret = bindings.NodeId_clone_ptr(this.ptr);
25 Reference.reachabilityFence(this);
30 * Creates a copy of the NodeId
32 public NodeId clone() {
33 long ret = bindings.NodeId_clone(this.ptr);
34 Reference.reachabilityFence(this);
35 if (ret >= 0 && ret <= 4096) { return null; }
36 org.ldk.structs.NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeId(null, ret); }
37 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
42 * Create a new NodeId from a public key
44 public static NodeId from_pubkey(byte[] pubkey) {
45 long ret = bindings.NodeId_from_pubkey(InternalUtils.check_arr_len(pubkey, 33));
46 Reference.reachabilityFence(pubkey);
47 if (ret >= 0 && ret <= 4096) { return null; }
48 org.ldk.structs.NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeId(null, ret); }
49 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
54 * Get the public key slice from this NodeId
56 public byte[] as_slice() {
57 byte[] ret = bindings.NodeId_as_slice(this.ptr);
58 Reference.reachabilityFence(this);
63 * Checks if two NodeIds contain equal inner contents.
66 long ret = bindings.NodeId_hash(this.ptr);
67 Reference.reachabilityFence(this);
71 @Override public int hashCode() {
72 return (int)this.hash();
75 * Serialize the NodeId object into a byte array which can be read by NodeId_read
77 public byte[] write() {
78 byte[] ret = bindings.NodeId_write(this.ptr);
79 Reference.reachabilityFence(this);
84 * Read a NodeId from a byte array, created by NodeId_write
86 public static Result_NodeIdDecodeErrorZ read(byte[] ser) {
87 long ret = bindings.NodeId_read(ser);
88 Reference.reachabilityFence(ser);
89 if (ret >= 0 && ret <= 4096) { return null; }
90 Result_NodeIdDecodeErrorZ ret_hu_conv = Result_NodeIdDecodeErrorZ.constr_from_ptr(ret);