1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import javax.annotation.Nullable;
11 * Represents the compressed public key of a node
13 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
14 public class NodeId extends CommonBase {
15 NodeId(Object _dummy, long ptr) { super(ptr); }
16 @Override @SuppressWarnings("deprecation")
17 protected void finalize() throws Throwable {
19 if (ptr != 0) { bindings.NodeId_free(ptr); }
23 long ret = bindings.NodeId_clone_ptr(this.ptr);
28 * Creates a copy of the NodeId
30 public NodeId clone() {
31 long ret = bindings.NodeId_clone(this.ptr);
32 if (ret >= 0 && ret <= 4096) { return null; }
33 NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new NodeId(null, ret); }
34 ret_hu_conv.ptrs_to.add(this);
39 * Create a new NodeId from a public key
41 public static NodeId from_pubkey(byte[] pubkey) {
42 long ret = bindings.NodeId_from_pubkey(InternalUtils.check_arr_len(pubkey, 33));
43 if (ret >= 0 && ret <= 4096) { return null; }
44 NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new NodeId(null, ret); }
45 ret_hu_conv.ptrs_to.add(ret_hu_conv);
50 * Get the public key slice from this NodeId
52 public byte[] as_slice() {
53 byte[] ret = bindings.NodeId_as_slice(this.ptr);
58 * Checks if two NodeIds contain equal inner contents.
61 long ret = bindings.NodeId_hash(this.ptr);
66 * Serialize the NodeId object into a byte array which can be read by NodeId_read
68 public byte[] write() {
69 byte[] ret = bindings.NodeId_write(this.ptr);
74 * Read a NodeId from a byte array, created by NodeId_write
76 public static Result_NodeIdDecodeErrorZ read(byte[] ser) {
77 long ret = bindings.NodeId_read(ser);
78 if (ret >= 0 && ret <= 4096) { return null; }
79 Result_NodeIdDecodeErrorZ ret_hu_conv = Result_NodeIdDecodeErrorZ.constr_from_ptr(ret);