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 * Get the public key from this NodeId
65 public Result_PublicKeySecp256k1ErrorZ as_pubkey() {
66 long ret = bindings.NodeId_as_pubkey(this.ptr);
67 Reference.reachabilityFence(this);
68 if (ret >= 0 && ret <= 4096) { return null; }
69 Result_PublicKeySecp256k1ErrorZ ret_hu_conv = Result_PublicKeySecp256k1ErrorZ.constr_from_ptr(ret);
74 * Generates a non-cryptographic 64-bit hash of the NodeId.
77 long ret = bindings.NodeId_hash(this.ptr);
78 Reference.reachabilityFence(this);
82 @Override public int hashCode() {
83 return (int)this.hash();
86 * Serialize the NodeId object into a byte array which can be read by NodeId_read
88 public byte[] write() {
89 byte[] ret = bindings.NodeId_write(this.ptr);
90 Reference.reachabilityFence(this);
95 * Read a NodeId from a byte array, created by NodeId_write
97 public static Result_NodeIdDecodeErrorZ read(byte[] ser) {
98 long ret = bindings.NodeId_read(ser);
99 Reference.reachabilityFence(ser);
100 if (ret >= 0 && ret <= 4096) { return null; }
101 Result_NodeIdDecodeErrorZ ret_hu_conv = Result_NodeIdDecodeErrorZ.constr_from_ptr(ret);