[Java] Update auto-generated Java bindings to LDK 0.0.121
[ldk-java] / src / main / java / org / ldk / structs / OnionPacket.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  * BOLT 4 onion packet including hop data for the next peer.
13  */
14 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
15 public class OnionPacket extends CommonBase {
16         OnionPacket(Object _dummy, long ptr) { super(ptr); }
17         @Override @SuppressWarnings("deprecation")
18         protected void finalize() throws Throwable {
19                 super.finalize();
20                 if (ptr != 0) { bindings.OnionPacket_free(ptr); }
21         }
22
23         /**
24          * BOLT 4 version number.
25          */
26         public byte get_version() {
27                 byte ret = bindings.OnionPacket_get_version(this.ptr);
28                 Reference.reachabilityFence(this);
29                 return ret;
30         }
31
32         /**
33          * BOLT 4 version number.
34          */
35         public void set_version(byte val) {
36                 bindings.OnionPacket_set_version(this.ptr, val);
37                 Reference.reachabilityFence(this);
38                 Reference.reachabilityFence(val);
39         }
40
41         /**
42          * In order to ensure we always return an error on onion decode in compliance with [BOLT
43          * #4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md), we have to
44          * deserialize `OnionPacket`s contained in [`UpdateAddHTLC`] messages even if the ephemeral
45          * public key (here) is bogus, so we hold a [`Result`] instead of a [`PublicKey`] as we'd
46          * like.
47          * 
48          * Returns a copy of the field.
49          */
50         public Result_PublicKeySecp256k1ErrorZ get_public_key() {
51                 long ret = bindings.OnionPacket_get_public_key(this.ptr);
52                 Reference.reachabilityFence(this);
53                 if (ret >= 0 && ret <= 4096) { return null; }
54                 Result_PublicKeySecp256k1ErrorZ ret_hu_conv = Result_PublicKeySecp256k1ErrorZ.constr_from_ptr(ret);
55                 return ret_hu_conv;
56         }
57
58         /**
59          * In order to ensure we always return an error on onion decode in compliance with [BOLT
60          * #4](https://github.com/lightning/bolts/blob/master/04-onion-routing.md), we have to
61          * deserialize `OnionPacket`s contained in [`UpdateAddHTLC`] messages even if the ephemeral
62          * public key (here) is bogus, so we hold a [`Result`] instead of a [`PublicKey`] as we'd
63          * like.
64          */
65         public void set_public_key(org.ldk.structs.Result_PublicKeySecp256k1ErrorZ val) {
66                 bindings.OnionPacket_set_public_key(this.ptr, val != null ? val.ptr : 0);
67                 Reference.reachabilityFence(this);
68                 Reference.reachabilityFence(val);
69         }
70
71         /**
72          * HMAC to verify the integrity of hop_data.
73          */
74         public byte[] get_hmac() {
75                 byte[] ret = bindings.OnionPacket_get_hmac(this.ptr);
76                 Reference.reachabilityFence(this);
77                 return ret;
78         }
79
80         /**
81          * HMAC to verify the integrity of hop_data.
82          */
83         public void set_hmac(byte[] val) {
84                 bindings.OnionPacket_set_hmac(this.ptr, InternalUtils.check_arr_len(val, 32));
85                 Reference.reachabilityFence(this);
86                 Reference.reachabilityFence(val);
87         }
88
89         long clone_ptr() {
90                 long ret = bindings.OnionPacket_clone_ptr(this.ptr);
91                 Reference.reachabilityFence(this);
92                 return ret;
93         }
94
95         /**
96          * Creates a copy of the OnionPacket
97          */
98         public OnionPacket clone() {
99                 long ret = bindings.OnionPacket_clone(this.ptr);
100                 Reference.reachabilityFence(this);
101                 if (ret >= 0 && ret <= 4096) { return null; }
102                 org.ldk.structs.OnionPacket ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OnionPacket(null, ret); }
103                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
104                 return ret_hu_conv;
105         }
106
107         /**
108          * Generates a non-cryptographic 64-bit hash of the OnionPacket.
109          */
110         public long hash() {
111                 long ret = bindings.OnionPacket_hash(this.ptr);
112                 Reference.reachabilityFence(this);
113                 return ret;
114         }
115
116         @Override public int hashCode() {
117                 return (int)this.hash();
118         }
119         /**
120          * Checks if two OnionPackets contain equal inner contents.
121          * This ignores pointers and is_owned flags and looks at the values in fields.
122          * Two objects with NULL inner values will be considered "equal" here.
123          */
124         public boolean eq(org.ldk.structs.OnionPacket b) {
125                 boolean ret = bindings.OnionPacket_eq(this.ptr, b == null ? 0 : b.ptr);
126                 Reference.reachabilityFence(this);
127                 Reference.reachabilityFence(b);
128                 if (this != null) { this.ptrs_to.add(b); };
129                 return ret;
130         }
131
132         @Override public boolean equals(Object o) {
133                 if (!(o instanceof OnionPacket)) return false;
134                 return this.eq((OnionPacket)o);
135         }
136         /**
137          * Serialize the OnionPacket object into a byte array which can be read by OnionPacket_read
138          */
139         public byte[] write() {
140                 byte[] ret = bindings.OnionPacket_write(this.ptr);
141                 Reference.reachabilityFence(this);
142                 return ret;
143         }
144
145         /**
146          * Read a OnionPacket from a byte array, created by OnionPacket_write
147          */
148         public static Result_OnionPacketDecodeErrorZ read(byte[] ser) {
149                 long ret = bindings.OnionPacket_read(ser);
150                 Reference.reachabilityFence(ser);
151                 if (ret >= 0 && ret <= 4096) { return null; }
152                 Result_OnionPacketDecodeErrorZ ret_hu_conv = Result_OnionPacketDecodeErrorZ.constr_from_ptr(ret);
153                 return ret_hu_conv;
154         }
155
156 }