[Java] Update auto-generated Java bindings to LDK 0.0.121
[ldk-java] / src / main / java / org / ldk / structs / NodeId.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * Represents the compressed public key of a node
13  */
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 {
19                 super.finalize();
20                 if (ptr != 0) { bindings.NodeId_free(ptr); }
21         }
22
23         long clone_ptr() {
24                 long ret = bindings.NodeId_clone_ptr(this.ptr);
25                 Reference.reachabilityFence(this);
26                 return ret;
27         }
28
29         /**
30          * Creates a copy of the NodeId
31          */
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); };
38                 return ret_hu_conv;
39         }
40
41         /**
42          * Create a new NodeId from a public key
43          */
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); };
50                 return ret_hu_conv;
51         }
52
53         /**
54          * Get the public key slice from this NodeId
55          */
56         public byte[] as_slice() {
57                 byte[] ret = bindings.NodeId_as_slice(this.ptr);
58                 Reference.reachabilityFence(this);
59                 return ret;
60         }
61
62         /**
63          * Get the public key as an array from this NodeId
64          */
65         public byte[] as_array() {
66                 byte[] ret = bindings.NodeId_as_array(this.ptr);
67                 Reference.reachabilityFence(this);
68                 return ret;
69         }
70
71         /**
72          * Get the public key from this NodeId
73          */
74         public Result_PublicKeySecp256k1ErrorZ as_pubkey() {
75                 long ret = bindings.NodeId_as_pubkey(this.ptr);
76                 Reference.reachabilityFence(this);
77                 if (ret >= 0 && ret <= 4096) { return null; }
78                 Result_PublicKeySecp256k1ErrorZ ret_hu_conv = Result_PublicKeySecp256k1ErrorZ.constr_from_ptr(ret);
79                 return ret_hu_conv;
80         }
81
82         /**
83          * Generates a non-cryptographic 64-bit hash of the NodeId.
84          */
85         public long hash() {
86                 long ret = bindings.NodeId_hash(this.ptr);
87                 Reference.reachabilityFence(this);
88                 return ret;
89         }
90
91         @Override public int hashCode() {
92                 return (int)this.hash();
93         }
94         /**
95          * Serialize the NodeId object into a byte array which can be read by NodeId_read
96          */
97         public byte[] write() {
98                 byte[] ret = bindings.NodeId_write(this.ptr);
99                 Reference.reachabilityFence(this);
100                 return ret;
101         }
102
103         /**
104          * Read a NodeId from a byte array, created by NodeId_write
105          */
106         public static Result_NodeIdDecodeErrorZ read(byte[] ser) {
107                 long ret = bindings.NodeId_read(ser);
108                 Reference.reachabilityFence(ser);
109                 if (ret >= 0 && ret <= 4096) { return null; }
110                 Result_NodeIdDecodeErrorZ ret_hu_conv = Result_NodeIdDecodeErrorZ.constr_from_ptr(ret);
111                 return ret_hu_conv;
112         }
113
114 }