[C#] Update auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / Route.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  * A route directs a payment from the sender (us) to the recipient. If the recipient supports MPP,
11  * it can take multiple paths. Each path is composed of one or more hops through the network.
12  */
13 public class Route : CommonBase {
14         internal Route(object _dummy, long ptr) : base(ptr) { }
15         ~Route() {
16                 if (ptr != 0) { bindings.Route_free(ptr); }
17         }
18
19         /**
20          * The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
21          * [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
22          * the same.
23          */
24         public Path[] get_paths() {
25                 long ret = bindings.Route_get_paths(this.ptr);
26                 GC.KeepAlive(this);
27                 if (ret >= 0 && ret <= 4096) { return null; }
28                 int ret_conv_6_len = InternalUtils.getArrayLength(ret);
29                 Path[] ret_conv_6_arr = new Path[ret_conv_6_len];
30                 for (int g = 0; g < ret_conv_6_len; g++) {
31                         long ret_conv_6 = InternalUtils.getU64ArrayElem(ret, g);
32                         org.ldk.structs.Path ret_conv_6_hu_conv = null; if (ret_conv_6 < 0 || ret_conv_6 > 4096) { ret_conv_6_hu_conv = new org.ldk.structs.Path(null, ret_conv_6); }
33                         if (ret_conv_6_hu_conv != null) { ret_conv_6_hu_conv.ptrs_to.AddLast(this); };
34                         ret_conv_6_arr[g] = ret_conv_6_hu_conv;
35                 }
36                 bindings.free_buffer(ret);
37                 return ret_conv_6_arr;
38         }
39
40         /**
41          * The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
42          * [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
43          * the same.
44          */
45         public void set_paths(Path[] val) {
46                 bindings.Route_set_paths(this.ptr, InternalUtils.encodeUint64Array(InternalUtils.mapArray(val, val_conv_6 => val_conv_6 == null ? 0 : val_conv_6.ptr)));
47                 GC.KeepAlive(this);
48                 GC.KeepAlive(val);
49                 foreach (Path val_conv_6 in val) { if (this != null) { this.ptrs_to.AddLast(val_conv_6); }; };
50         }
51
52         /**
53          * The `route_params` parameter passed to [`find_route`].
54          * 
55          * This is used by `ChannelManager` to track information which may be required for retries.
56          * 
57          * Will be `None` for objects serialized with LDK versions prior to 0.0.117.
58          * 
59          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
60          */
61         public RouteParameters get_route_params() {
62                 long ret = bindings.Route_get_route_params(this.ptr);
63                 GC.KeepAlive(this);
64                 if (ret >= 0 && ret <= 4096) { return null; }
65                 org.ldk.structs.RouteParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.RouteParameters(null, ret); }
66                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
67                 return ret_hu_conv;
68         }
69
70         /**
71          * The `route_params` parameter passed to [`find_route`].
72          * 
73          * This is used by `ChannelManager` to track information which may be required for retries.
74          * 
75          * Will be `None` for objects serialized with LDK versions prior to 0.0.117.
76          * 
77          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
78          */
79         public void set_route_params(org.ldk.structs.RouteParameters val) {
80                 bindings.Route_set_route_params(this.ptr, val == null ? 0 : val.ptr);
81                 GC.KeepAlive(this);
82                 GC.KeepAlive(val);
83                 if (this != null) { this.ptrs_to.AddLast(val); };
84         }
85
86         /**
87          * Constructs a new Route given each field
88          * 
89          * Note that route_params_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
90          */
91         public static Route of(Path[] paths_arg, org.ldk.structs.RouteParameters route_params_arg) {
92                 long ret = bindings.Route_new(InternalUtils.encodeUint64Array(InternalUtils.mapArray(paths_arg, paths_arg_conv_6 => paths_arg_conv_6 == null ? 0 : paths_arg_conv_6.ptr)), route_params_arg == null ? 0 : route_params_arg.ptr);
93                 GC.KeepAlive(paths_arg);
94                 GC.KeepAlive(route_params_arg);
95                 if (ret >= 0 && ret <= 4096) { return null; }
96                 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
97                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
98                 foreach (Path paths_arg_conv_6 in paths_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(paths_arg_conv_6); }; };
99                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(route_params_arg); };
100                 return ret_hu_conv;
101         }
102
103         internal long clone_ptr() {
104                 long ret = bindings.Route_clone_ptr(this.ptr);
105                 GC.KeepAlive(this);
106                 return ret;
107         }
108
109         /**
110          * Creates a copy of the Route
111          */
112         public Route clone() {
113                 long ret = bindings.Route_clone(this.ptr);
114                 GC.KeepAlive(this);
115                 if (ret >= 0 && ret <= 4096) { return null; }
116                 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
117                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
118                 return ret_hu_conv;
119         }
120
121         /**
122          * Generates a non-cryptographic 64-bit hash of the Route.
123          */
124         public long hash() {
125                 long ret = bindings.Route_hash(this.ptr);
126                 GC.KeepAlive(this);
127                 return ret;
128         }
129
130         public override int GetHashCode() {
131                 return (int)this.hash();
132         }
133         /**
134          * Checks if two Routes contain equal inner contents.
135          * This ignores pointers and is_owned flags and looks at the values in fields.
136          * Two objects with NULL inner values will be considered "equal" here.
137          */
138         public bool eq(org.ldk.structs.Route b) {
139                 bool ret = bindings.Route_eq(this.ptr, b == null ? 0 : b.ptr);
140                 GC.KeepAlive(this);
141                 GC.KeepAlive(b);
142                 if (this != null) { this.ptrs_to.AddLast(b); };
143                 return ret;
144         }
145
146         public override bool Equals(object o) {
147                 if (!(o is Route)) return false;
148                 return this.eq((Route)o);
149         }
150         /**
151          * Returns the total amount of fees paid on this [`Route`].
152          * 
153          * For objects serialized with LDK 0.0.117 and after, this includes any extra payment made to
154          * the recipient, which can happen in excess of the amount passed to [`find_route`] via
155          * [`RouteParameters::final_value_msat`], if we had to reach the [`htlc_minimum_msat`] limits.
156          * 
157          * [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
158          */
159         public long get_total_fees() {
160                 long ret = bindings.Route_get_total_fees(this.ptr);
161                 GC.KeepAlive(this);
162                 return ret;
163         }
164
165         /**
166          * Returns the total amount paid on this [`Route`], excluding the fees.
167          * 
168          * Might be more than requested as part of the given [`RouteParameters::final_value_msat`] if
169          * we had to reach the [`htlc_minimum_msat`] limits.
170          * 
171          * [`htlc_minimum_msat`]: https://github.com/lightning/bolts/blob/master/07-routing-gossip.md#the-channel_update-message
172          */
173         public long get_total_amount() {
174                 long ret = bindings.Route_get_total_amount(this.ptr);
175                 GC.KeepAlive(this);
176                 return ret;
177         }
178
179         /**
180          * Serialize the Route object into a byte array which can be read by Route_read
181          */
182         public byte[] write() {
183                 long ret = bindings.Route_write(this.ptr);
184                 GC.KeepAlive(this);
185                 if (ret >= 0 && ret <= 4096) { return null; }
186                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
187                 return ret_conv;
188         }
189
190         /**
191          * Read a Route from a byte array, created by Route_write
192          */
193         public static Result_RouteDecodeErrorZ read(byte[] ser) {
194                 long ret = bindings.Route_read(InternalUtils.encodeUint8Array(ser));
195                 GC.KeepAlive(ser);
196                 if (ret >= 0 && ret <= 4096) { return null; }
197                 Result_RouteDecodeErrorZ ret_hu_conv = Result_RouteDecodeErrorZ.constr_from_ptr(ret);
198                 return ret_hu_conv;
199         }
200
201 }
202 } } }