[TS] Update auto-generated bindings to LDK-C-Bindings 0.0.123.1
[ldk-java] / c_sharp / src / org / ldk / structs / BlindedPath.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 /**
10  * Onion messages and payments can be sent and received to blinded paths, which serve to hide the
11  * identity of the recipient.
12  */
13 public class BlindedPath : CommonBase {
14         internal BlindedPath(object _dummy, long ptr) : base(ptr) { }
15         ~BlindedPath() {
16                 if (ptr != 0) { bindings.BlindedPath_free(ptr); }
17         }
18
19         /**
20          * To send to a blinded path, the sender first finds a route to the unblinded
21          * `introduction_node`, which can unblind its [`encrypted_payload`] to find out the onion
22          * message or payment's next hop and forward it along.
23          * 
24          * [`encrypted_payload`]: BlindedHop::encrypted_payload
25          */
26         public IntroductionNode get_introduction_node() {
27                 long ret = bindings.BlindedPath_get_introduction_node(this.ptr);
28                 GC.KeepAlive(this);
29                 if (ret >= 0 && ret <= 4096) { return null; }
30                 org.ldk.structs.IntroductionNode ret_hu_conv = org.ldk.structs.IntroductionNode.constr_from_ptr(ret);
31                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
32                 return ret_hu_conv;
33         }
34
35         /**
36          * To send to a blinded path, the sender first finds a route to the unblinded
37          * `introduction_node`, which can unblind its [`encrypted_payload`] to find out the onion
38          * message or payment's next hop and forward it along.
39          * 
40          * [`encrypted_payload`]: BlindedHop::encrypted_payload
41          */
42         public void set_introduction_node(org.ldk.structs.IntroductionNode val) {
43                 bindings.BlindedPath_set_introduction_node(this.ptr, val.ptr);
44                 GC.KeepAlive(this);
45                 GC.KeepAlive(val);
46                 if (this != null) { this.ptrs_to.AddLast(val); };
47         }
48
49         /**
50          * Used by the introduction node to decrypt its [`encrypted_payload`] to forward the onion
51          * message or payment.
52          * 
53          * [`encrypted_payload`]: BlindedHop::encrypted_payload
54          */
55         public byte[] get_blinding_point() {
56                 long ret = bindings.BlindedPath_get_blinding_point(this.ptr);
57                 GC.KeepAlive(this);
58                 if (ret >= 0 && ret <= 4096) { return null; }
59                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
60                 return ret_conv;
61         }
62
63         /**
64          * Used by the introduction node to decrypt its [`encrypted_payload`] to forward the onion
65          * message or payment.
66          * 
67          * [`encrypted_payload`]: BlindedHop::encrypted_payload
68          */
69         public void set_blinding_point(byte[] val) {
70                 bindings.BlindedPath_set_blinding_point(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(val, 33)));
71                 GC.KeepAlive(this);
72                 GC.KeepAlive(val);
73         }
74
75         /**
76          * The hops composing the blinded path.
77          */
78         public BlindedHop[] get_blinded_hops() {
79                 long ret = bindings.BlindedPath_get_blinded_hops(this.ptr);
80                 GC.KeepAlive(this);
81                 if (ret >= 0 && ret <= 4096) { return null; }
82                 int ret_conv_12_len = InternalUtils.getArrayLength(ret);
83                 BlindedHop[] ret_conv_12_arr = new BlindedHop[ret_conv_12_len];
84                 for (int m = 0; m < ret_conv_12_len; m++) {
85                         long ret_conv_12 = InternalUtils.getU64ArrayElem(ret, m);
86                         org.ldk.structs.BlindedHop ret_conv_12_hu_conv = null; if (ret_conv_12 < 0 || ret_conv_12 > 4096) { ret_conv_12_hu_conv = new org.ldk.structs.BlindedHop(null, ret_conv_12); }
87                         if (ret_conv_12_hu_conv != null) { ret_conv_12_hu_conv.ptrs_to.AddLast(this); };
88                         ret_conv_12_arr[m] = ret_conv_12_hu_conv;
89                 }
90                 bindings.free_buffer(ret);
91                 return ret_conv_12_arr;
92         }
93
94         /**
95          * The hops composing the blinded path.
96          */
97         public void set_blinded_hops(BlindedHop[] val) {
98                 bindings.BlindedPath_set_blinded_hops(this.ptr, InternalUtils.encodeUint64Array(InternalUtils.mapArray(val, val_conv_12 => val_conv_12.ptr)));
99                 GC.KeepAlive(this);
100                 GC.KeepAlive(val);
101                 foreach (BlindedHop val_conv_12 in val) { if (this != null) { this.ptrs_to.AddLast(val_conv_12); }; };
102         }
103
104         /**
105          * Constructs a new BlindedPath given each field
106          */
107         public static BlindedPath of(org.ldk.structs.IntroductionNode introduction_node_arg, byte[] blinding_point_arg, BlindedHop[] blinded_hops_arg) {
108                 long ret = bindings.BlindedPath_new(introduction_node_arg.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(blinding_point_arg, 33)), InternalUtils.encodeUint64Array(InternalUtils.mapArray(blinded_hops_arg, blinded_hops_arg_conv_12 => blinded_hops_arg_conv_12.ptr)));
109                 GC.KeepAlive(introduction_node_arg);
110                 GC.KeepAlive(blinding_point_arg);
111                 GC.KeepAlive(blinded_hops_arg);
112                 if (ret >= 0 && ret <= 4096) { return null; }
113                 org.ldk.structs.BlindedPath ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BlindedPath(null, ret); }
114                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
115                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(introduction_node_arg); };
116                 foreach (BlindedHop blinded_hops_arg_conv_12 in blinded_hops_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(blinded_hops_arg_conv_12); }; };
117                 return ret_hu_conv;
118         }
119
120         internal long clone_ptr() {
121                 long ret = bindings.BlindedPath_clone_ptr(this.ptr);
122                 GC.KeepAlive(this);
123                 return ret;
124         }
125
126         /**
127          * Creates a copy of the BlindedPath
128          */
129         public BlindedPath clone() {
130                 long ret = bindings.BlindedPath_clone(this.ptr);
131                 GC.KeepAlive(this);
132                 if (ret >= 0 && ret <= 4096) { return null; }
133                 org.ldk.structs.BlindedPath ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.BlindedPath(null, ret); }
134                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
135                 return ret_hu_conv;
136         }
137
138         /**
139          * Generates a non-cryptographic 64-bit hash of the BlindedPath.
140          */
141         public long hash() {
142                 long ret = bindings.BlindedPath_hash(this.ptr);
143                 GC.KeepAlive(this);
144                 return ret;
145         }
146
147         public override int GetHashCode() {
148                 return (int)this.hash();
149         }
150         /**
151          * Checks if two BlindedPaths contain equal inner contents.
152          * This ignores pointers and is_owned flags and looks at the values in fields.
153          * Two objects with NULL inner values will be considered "equal" here.
154          */
155         public bool eq(org.ldk.structs.BlindedPath b) {
156                 bool ret = bindings.BlindedPath_eq(this.ptr, b.ptr);
157                 GC.KeepAlive(this);
158                 GC.KeepAlive(b);
159                 if (this != null) { this.ptrs_to.AddLast(b); };
160                 return ret;
161         }
162
163         public override bool Equals(object o) {
164                 if (!(o is BlindedPath)) return false;
165                 return this.eq((BlindedPath)o);
166         }
167         /**
168          * Create a one-hop blinded path for a message.
169          */
170         public static Result_BlindedPathNoneZ one_hop_for_message(byte[] recipient_node_id, org.ldk.structs.EntropySource entropy_source) {
171                 long ret = bindings.BlindedPath_one_hop_for_message(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(recipient_node_id, 33)), entropy_source.ptr);
172                 GC.KeepAlive(recipient_node_id);
173                 GC.KeepAlive(entropy_source);
174                 if (ret >= 0 && ret <= 4096) { return null; }
175                 Result_BlindedPathNoneZ ret_hu_conv = Result_BlindedPathNoneZ.constr_from_ptr(ret);
176                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(entropy_source); };
177                 return ret_hu_conv;
178         }
179
180         /**
181          * Create a blinded path for an onion message, to be forwarded along `node_pks`. The last node
182          * pubkey in `node_pks` will be the destination node.
183          * 
184          * Errors if no hops are provided or if `node_pk`(s) are invalid.
185          */
186         public static Result_BlindedPathNoneZ new_for_message(byte[][] node_pks, org.ldk.structs.EntropySource entropy_source) {
187                 long ret = bindings.BlindedPath_new_for_message(InternalUtils.encodeUint64Array(InternalUtils.mapArray(node_pks, node_pks_conv_8 => InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(node_pks_conv_8, 33)))), entropy_source.ptr);
188                 GC.KeepAlive(node_pks);
189                 GC.KeepAlive(entropy_source);
190                 if (ret >= 0 && ret <= 4096) { return null; }
191                 Result_BlindedPathNoneZ ret_hu_conv = Result_BlindedPathNoneZ.constr_from_ptr(ret);
192                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(entropy_source); };
193                 return ret_hu_conv;
194         }
195
196         /**
197          * Returns the introduction [`NodeId`] of the blinded path, if it is publicly reachable (i.e.,
198          * it is found in the network graph).
199          * 
200          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
201          */
202         public NodeId public_introduction_node_id(org.ldk.structs.ReadOnlyNetworkGraph network_graph) {
203                 long ret = bindings.BlindedPath_public_introduction_node_id(this.ptr, network_graph.ptr);
204                 GC.KeepAlive(this);
205                 GC.KeepAlive(network_graph);
206                 if (ret >= 0 && ret <= 4096) { return null; }
207                 org.ldk.structs.NodeId ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.NodeId(null, ret); }
208                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
209                 if (this != null) { this.ptrs_to.AddLast(network_graph); };
210                 return ret_hu_conv;
211         }
212
213         /**
214          * Serialize the BlindedPath object into a byte array which can be read by BlindedPath_read
215          */
216         public byte[] write() {
217                 long ret = bindings.BlindedPath_write(this.ptr);
218                 GC.KeepAlive(this);
219                 if (ret >= 0 && ret <= 4096) { return null; }
220                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
221                 return ret_conv;
222         }
223
224         /**
225          * Read a BlindedPath from a byte array, created by BlindedPath_write
226          */
227         public static Result_BlindedPathDecodeErrorZ read(byte[] ser) {
228                 long ret = bindings.BlindedPath_read(InternalUtils.encodeUint8Array(ser));
229                 GC.KeepAlive(ser);
230                 if (ret >= 0 && ret <= 4096) { return null; }
231                 Result_BlindedPathDecodeErrorZ ret_hu_conv = Result_BlindedPathDecodeErrorZ.constr_from_ptr(ret);
232                 return ret_hu_conv;
233         }
234
235 }
236 } } }