[Java] Update auto-generated bindings to LDK 0.0.123
[ldk-java] / src / main / java / org / ldk / structs / PeeledOnion.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  * A processed incoming onion message, containing either a Forward (another onion message)
13  * or a Receive payload with decrypted contents.
14  */
15 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
16 public class PeeledOnion extends CommonBase {
17         private PeeledOnion(Object _dummy, long ptr) { super(ptr); }
18         @Override @SuppressWarnings("deprecation")
19         protected void finalize() throws Throwable {
20                 super.finalize();
21                 if (ptr != 0) { bindings.PeeledOnion_free(ptr); }
22         }
23         static PeeledOnion constr_from_ptr(long ptr) {
24                 bindings.LDKPeeledOnion raw_val = bindings.LDKPeeledOnion_ref_from_ptr(ptr);
25                 if (raw_val.getClass() == bindings.LDKPeeledOnion.Forward.class) {
26                         return new Forward(ptr, (bindings.LDKPeeledOnion.Forward)raw_val);
27                 }
28                 if (raw_val.getClass() == bindings.LDKPeeledOnion.Receive.class) {
29                         return new Receive(ptr, (bindings.LDKPeeledOnion.Receive)raw_val);
30                 }
31                 assert false; return null; // Unreachable without extending the (internal) bindings interface
32         }
33
34         /**
35          * Forwarded onion, with the next node id and a new onion
36          */
37         public final static class Forward extends PeeledOnion {
38                 public final org.ldk.structs.NextMessageHop _0;
39                 public final org.ldk.structs.OnionMessage _1;
40                 private Forward(long ptr, bindings.LDKPeeledOnion.Forward obj) {
41                         super(null, ptr);
42                         long _0 = obj._0;
43                         org.ldk.structs.NextMessageHop _0_hu_conv = org.ldk.structs.NextMessageHop.constr_from_ptr(_0);
44                         if (_0_hu_conv != null) { _0_hu_conv.ptrs_to.add(this); };
45                         this._0 = _0_hu_conv;
46                         long _1 = obj._1;
47                         org.ldk.structs.OnionMessage _1_hu_conv = null; if (_1 < 0 || _1 > 4096) { _1_hu_conv = new org.ldk.structs.OnionMessage(null, _1); }
48                         if (_1_hu_conv != null) { _1_hu_conv.ptrs_to.add(this); };
49                         this._1 = _1_hu_conv;
50                 }
51         }
52         /**
53          * Received onion message, with decrypted contents, path_id, and reply path
54          */
55         public final static class Receive extends PeeledOnion {
56                 public final org.ldk.structs.ParsedOnionMessageContents _0;
57                 /**
58                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
59                 */
60                 @Nullable public final byte[] _1;
61                 /**
62                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
63                 */
64                 @Nullable public final org.ldk.structs.BlindedPath _2;
65                 private Receive(long ptr, bindings.LDKPeeledOnion.Receive obj) {
66                         super(null, ptr);
67                         long _0 = obj._0;
68                         org.ldk.structs.ParsedOnionMessageContents _0_hu_conv = org.ldk.structs.ParsedOnionMessageContents.constr_from_ptr(_0);
69                         if (_0_hu_conv != null) { _0_hu_conv.ptrs_to.add(this); };
70                         this._0 = _0_hu_conv;
71                         this._1 = obj._1;
72                         long _2 = obj._2;
73                         org.ldk.structs.BlindedPath _2_hu_conv = null; if (_2 < 0 || _2 > 4096) { _2_hu_conv = new org.ldk.structs.BlindedPath(null, _2); }
74                         if (_2_hu_conv != null) { _2_hu_conv.ptrs_to.add(this); };
75                         this._2 = _2_hu_conv;
76                 }
77         }
78         long clone_ptr() {
79                 long ret = bindings.PeeledOnion_clone_ptr(this.ptr);
80                 Reference.reachabilityFence(this);
81                 return ret;
82         }
83
84         /**
85          * Creates a copy of the PeeledOnion
86          */
87         public PeeledOnion clone() {
88                 long ret = bindings.PeeledOnion_clone(this.ptr);
89                 Reference.reachabilityFence(this);
90                 if (ret >= 0 && ret <= 4096) { return null; }
91                 org.ldk.structs.PeeledOnion ret_hu_conv = org.ldk.structs.PeeledOnion.constr_from_ptr(ret);
92                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
93                 return ret_hu_conv;
94         }
95
96         /**
97          * Utility method to constructs a new Forward-variant PeeledOnion
98          */
99         public static PeeledOnion forward(org.ldk.structs.NextMessageHop a, org.ldk.structs.OnionMessage b) {
100                 long ret = bindings.PeeledOnion_forward(a.ptr, b.ptr);
101                 Reference.reachabilityFence(a);
102                 Reference.reachabilityFence(b);
103                 if (ret >= 0 && ret <= 4096) { return null; }
104                 org.ldk.structs.PeeledOnion ret_hu_conv = org.ldk.structs.PeeledOnion.constr_from_ptr(ret);
105                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
106                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
107                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(b); };
108                 return ret_hu_conv;
109         }
110
111         /**
112          * Utility method to constructs a new Receive-variant PeeledOnion
113          */
114         public static PeeledOnion receive(org.ldk.structs.ParsedOnionMessageContents a, byte[] b, org.ldk.structs.BlindedPath c) {
115                 long ret = bindings.PeeledOnion_receive(a.ptr, InternalUtils.check_arr_len(b, 32), c.ptr);
116                 Reference.reachabilityFence(a);
117                 Reference.reachabilityFence(b);
118                 Reference.reachabilityFence(c);
119                 if (ret >= 0 && ret <= 4096) { return null; }
120                 org.ldk.structs.PeeledOnion ret_hu_conv = org.ldk.structs.PeeledOnion.constr_from_ptr(ret);
121                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
122                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(a); };
123                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(c); };
124                 return ret_hu_conv;
125         }
126
127 }