[TS] Update auto-generated bindings to LDK-C-Bindings 0.0.123.1
[ldk-java] / c_sharp / src / org / ldk / structs / HTLCDestination.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
9  * Intended destination of a failed HTLC as indicated in [`Event::HTLCHandlingFailed`].
10  */
11 public class HTLCDestination : CommonBase {
12         protected HTLCDestination(object _dummy, long ptr) : base(ptr) { }
13         ~HTLCDestination() {
14                 if (ptr != 0) { bindings.HTLCDestination_free(ptr); }
15         }
16
17         internal static HTLCDestination constr_from_ptr(long ptr) {
18                 long raw_ty = bindings.LDKHTLCDestination_ty_from_ptr(ptr);
19                 switch (raw_ty) {
20                         case 0: return new HTLCDestination_NextHopChannel(ptr);
21                         case 1: return new HTLCDestination_UnknownNextHop(ptr);
22                         case 2: return new HTLCDestination_InvalidForward(ptr);
23                         case 3: return new HTLCDestination_InvalidOnion(ptr);
24                         case 4: return new HTLCDestination_FailedPayment(ptr);
25                         default:
26                                 throw new ArgumentException("Impossible enum variant");
27                 }
28         }
29
30         /** A HTLCDestination of type NextHopChannel */
31         public class HTLCDestination_NextHopChannel : HTLCDestination {
32                 /**
33                  * The `node_id` of the next node. For backwards compatibility, this field is
34                  * marked as optional, versions prior to 0.0.110 may not always be able to provide
35                  * counterparty node information.
36                  * 
37                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
38                  */
39                 public byte[] node_id;
40                 /**
41                  * The outgoing `channel_id` between us and the next node.
42                  */
43                 public ChannelId channel_id;
44                 internal HTLCDestination_NextHopChannel(long ptr) : base(null, ptr) {
45                         long node_id = bindings.LDKHTLCDestination_NextHopChannel_get_node_id(ptr);
46                         byte[] node_id_conv = InternalUtils.decodeUint8Array(node_id);
47                         this.node_id = node_id_conv;
48                         long channel_id = bindings.LDKHTLCDestination_NextHopChannel_get_channel_id(ptr);
49                         org.ldk.structs.ChannelId channel_id_hu_conv = null; if (channel_id < 0 || channel_id > 4096) { channel_id_hu_conv = new org.ldk.structs.ChannelId(null, channel_id); }
50                         if (channel_id_hu_conv != null) { channel_id_hu_conv.ptrs_to.AddLast(this); };
51                         this.channel_id = channel_id_hu_conv;
52                 }
53         }
54         /** A HTLCDestination of type UnknownNextHop */
55         public class HTLCDestination_UnknownNextHop : HTLCDestination {
56                 /**
57                  * Short channel id we are requesting to forward an HTLC to.
58                  */
59                 public long requested_forward_scid;
60                 internal HTLCDestination_UnknownNextHop(long ptr) : base(null, ptr) {
61                         this.requested_forward_scid = bindings.LDKHTLCDestination_UnknownNextHop_get_requested_forward_scid(ptr);
62                 }
63         }
64         /** A HTLCDestination of type InvalidForward */
65         public class HTLCDestination_InvalidForward : HTLCDestination {
66                 /**
67                  * Short channel id we are requesting to forward an HTLC to.
68                  */
69                 public long requested_forward_scid;
70                 internal HTLCDestination_InvalidForward(long ptr) : base(null, ptr) {
71                         this.requested_forward_scid = bindings.LDKHTLCDestination_InvalidForward_get_requested_forward_scid(ptr);
72                 }
73         }
74         /** A HTLCDestination of type InvalidOnion */
75         public class HTLCDestination_InvalidOnion : HTLCDestination {
76                 internal HTLCDestination_InvalidOnion(long ptr) : base(null, ptr) {
77                 }
78         }
79         /** A HTLCDestination of type FailedPayment */
80         public class HTLCDestination_FailedPayment : HTLCDestination {
81                 /**
82                  * The payment hash of the payment we attempted to process.
83                  */
84                 public byte[] payment_hash;
85                 internal HTLCDestination_FailedPayment(long ptr) : base(null, ptr) {
86                         long payment_hash = bindings.LDKHTLCDestination_FailedPayment_get_payment_hash(ptr);
87                         byte[] payment_hash_conv = InternalUtils.decodeUint8Array(payment_hash);
88                         this.payment_hash = payment_hash_conv;
89                 }
90         }
91         internal long clone_ptr() {
92                 long ret = bindings.HTLCDestination_clone_ptr(this.ptr);
93                 GC.KeepAlive(this);
94                 return ret;
95         }
96
97         /**
98          * Creates a copy of the HTLCDestination
99          */
100         public HTLCDestination clone() {
101                 long ret = bindings.HTLCDestination_clone(this.ptr);
102                 GC.KeepAlive(this);
103                 if (ret >= 0 && ret <= 4096) { return null; }
104                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
105                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
106                 return ret_hu_conv;
107         }
108
109         /**
110          * Utility method to constructs a new NextHopChannel-variant HTLCDestination
111          */
112         public static HTLCDestination next_hop_channel(byte[] node_id, org.ldk.structs.ChannelId channel_id) {
113                 long ret = bindings.HTLCDestination_next_hop_channel(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(node_id, 33)), channel_id.ptr);
114                 GC.KeepAlive(node_id);
115                 GC.KeepAlive(channel_id);
116                 if (ret >= 0 && ret <= 4096) { return null; }
117                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
118                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
119                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(channel_id); };
120                 return ret_hu_conv;
121         }
122
123         /**
124          * Utility method to constructs a new UnknownNextHop-variant HTLCDestination
125          */
126         public static HTLCDestination unknown_next_hop(long requested_forward_scid) {
127                 long ret = bindings.HTLCDestination_unknown_next_hop(requested_forward_scid);
128                 GC.KeepAlive(requested_forward_scid);
129                 if (ret >= 0 && ret <= 4096) { return null; }
130                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
131                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
132                 return ret_hu_conv;
133         }
134
135         /**
136          * Utility method to constructs a new InvalidForward-variant HTLCDestination
137          */
138         public static HTLCDestination invalid_forward(long requested_forward_scid) {
139                 long ret = bindings.HTLCDestination_invalid_forward(requested_forward_scid);
140                 GC.KeepAlive(requested_forward_scid);
141                 if (ret >= 0 && ret <= 4096) { return null; }
142                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
143                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
144                 return ret_hu_conv;
145         }
146
147         /**
148          * Utility method to constructs a new InvalidOnion-variant HTLCDestination
149          */
150         public static HTLCDestination invalid_onion() {
151                 long ret = bindings.HTLCDestination_invalid_onion();
152                 if (ret >= 0 && ret <= 4096) { return null; }
153                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
154                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
155                 return ret_hu_conv;
156         }
157
158         /**
159          * Utility method to constructs a new FailedPayment-variant HTLCDestination
160          */
161         public static HTLCDestination failed_payment(byte[] payment_hash) {
162                 long ret = bindings.HTLCDestination_failed_payment(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_hash, 32)));
163                 GC.KeepAlive(payment_hash);
164                 if (ret >= 0 && ret <= 4096) { return null; }
165                 org.ldk.structs.HTLCDestination ret_hu_conv = org.ldk.structs.HTLCDestination.constr_from_ptr(ret);
166                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
167                 return ret_hu_conv;
168         }
169
170         /**
171          * Checks if two HTLCDestinations contain equal inner contents.
172          * This ignores pointers and is_owned flags and looks at the values in fields.
173          */
174         public bool eq(org.ldk.structs.HTLCDestination b) {
175                 bool ret = bindings.HTLCDestination_eq(this.ptr, b.ptr);
176                 GC.KeepAlive(this);
177                 GC.KeepAlive(b);
178                 return ret;
179         }
180
181         public override bool Equals(object o) {
182                 if (!(o is HTLCDestination)) return false;
183                 return this.eq((HTLCDestination)o);
184         }
185         /**
186          * Serialize the HTLCDestination object into a byte array which can be read by HTLCDestination_read
187          */
188         public byte[] write() {
189                 long ret = bindings.HTLCDestination_write(this.ptr);
190                 GC.KeepAlive(this);
191                 if (ret >= 0 && ret <= 4096) { return null; }
192                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
193                 return ret_conv;
194         }
195
196 }
197 } } }