619bd6df7320ffc9269f4a03f93a64b75de2aad2
[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 routes taken for a single (potentially-)multi-part payment. The pubkey of the
21          * last RouteHop in each path must be the same. Each entry represents a list of hops, NOT
22          * INCLUDING our own, where the last hop is the destination. Thus, this must always be at
23          * least length one. While the maximum length of any given path is variable, keeping the length
24          * of any path less or equal to 19 should currently ensure it is viable.
25          */
26         public RouteHop[][] get_paths() {
27                 long[][] ret = bindings.Route_get_paths(this.ptr);
28                 GC.KeepAlive(this);
29                 int ret_conv_12_len = ret.Length;
30                 RouteHop[][] ret_conv_12_arr = new RouteHop[ret_conv_12_len][];
31                 for (int m = 0; m < ret_conv_12_len; m++) {
32                         long[] ret_conv_12 = ret[m];
33                         int ret_conv_12_conv_10_len = ret_conv_12.Length;
34                         RouteHop[] ret_conv_12_conv_10_arr = new RouteHop[ret_conv_12_conv_10_len];
35                         for (int k = 0; k < ret_conv_12_conv_10_len; k++) {
36                                 long ret_conv_12_conv_10 = ret_conv_12[k];
37                                 org.ldk.structs.RouteHop ret_conv_12_conv_10_hu_conv = null; if (ret_conv_12_conv_10 < 0 || ret_conv_12_conv_10 > 4096) { ret_conv_12_conv_10_hu_conv = new org.ldk.structs.RouteHop(null, ret_conv_12_conv_10); }
38                                 if (ret_conv_12_conv_10_hu_conv != null) { ret_conv_12_conv_10_hu_conv.ptrs_to.AddLast(this); };
39                                 ret_conv_12_conv_10_arr[k] = ret_conv_12_conv_10_hu_conv;
40                         }
41                         ret_conv_12_arr[m] = ret_conv_12_conv_10_arr;
42                 }
43                 return ret_conv_12_arr;
44         }
45
46         /**
47          * The list of routes taken for a single (potentially-)multi-part payment. The pubkey of the
48          * last RouteHop in each path must be the same. Each entry represents a list of hops, NOT
49          * INCLUDING our own, where the last hop is the destination. Thus, this must always be at
50          * least length one. While the maximum length of any given path is variable, keeping the length
51          * of any path less or equal to 19 should currently ensure it is viable.
52          */
53         public void set_paths(RouteHop[][] val) {
54                 bindings.Route_set_paths(this.ptr, val != null ? InternalUtils.mapArray(val, val_conv_12 => val_conv_12 != null ? InternalUtils.mapArray(val_conv_12, val_conv_12_conv_10 => val_conv_12_conv_10 == null ? 0 : val_conv_12_conv_10.ptr) : null) : null);
55                 GC.KeepAlive(this);
56                 GC.KeepAlive(val);
57                 foreach (RouteHop[] val_conv_12 in val) { foreach (RouteHop val_conv_12_conv_10 in val_conv_12) { if (this != null) { this.ptrs_to.AddLast(val_conv_12_conv_10); }; }; };
58         }
59
60         /**
61          * The `payment_params` parameter passed to [`find_route`].
62          * This is used by `ChannelManager` to track information which may be required for retries,
63          * provided back to you via [`Event::PaymentPathFailed`].
64          * 
65          * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
66          * 
67          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
68          */
69         public PaymentParameters get_payment_params() {
70                 long ret = bindings.Route_get_payment_params(this.ptr);
71                 GC.KeepAlive(this);
72                 if (ret >= 0 && ret <= 4096) { return null; }
73                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
74                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
75                 return ret_hu_conv;
76         }
77
78         /**
79          * The `payment_params` parameter passed to [`find_route`].
80          * This is used by `ChannelManager` to track information which may be required for retries,
81          * provided back to you via [`Event::PaymentPathFailed`].
82          * 
83          * [`Event::PaymentPathFailed`]: crate::util::events::Event::PaymentPathFailed
84          * 
85          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
86          */
87         public void set_payment_params(org.ldk.structs.PaymentParameters val) {
88                 bindings.Route_set_payment_params(this.ptr, val == null ? 0 : val.ptr);
89                 GC.KeepAlive(this);
90                 GC.KeepAlive(val);
91                 if (this != null) { this.ptrs_to.AddLast(val); };
92         }
93
94         /**
95          * Constructs a new Route given each field
96          */
97         public static Route of(RouteHop[][] paths_arg, org.ldk.structs.PaymentParameters payment_params_arg) {
98                 long ret = bindings.Route_new(paths_arg != null ? InternalUtils.mapArray(paths_arg, paths_arg_conv_12 => paths_arg_conv_12 != null ? InternalUtils.mapArray(paths_arg_conv_12, paths_arg_conv_12_conv_10 => paths_arg_conv_12_conv_10 == null ? 0 : paths_arg_conv_12_conv_10.ptr) : null) : null, payment_params_arg == null ? 0 : payment_params_arg.ptr);
99                 GC.KeepAlive(paths_arg);
100                 GC.KeepAlive(payment_params_arg);
101                 if (ret >= 0 && ret <= 4096) { return null; }
102                 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
103                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
104                 foreach (RouteHop[] paths_arg_conv_12 in paths_arg) { foreach (RouteHop paths_arg_conv_12_conv_10 in paths_arg_conv_12) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(paths_arg_conv_12_conv_10); }; }; };
105                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_params_arg); };
106                 return ret_hu_conv;
107         }
108
109         internal long clone_ptr() {
110                 long ret = bindings.Route_clone_ptr(this.ptr);
111                 GC.KeepAlive(this);
112                 return ret;
113         }
114
115         /**
116          * Creates a copy of the Route
117          */
118         public Route clone() {
119                 long ret = bindings.Route_clone(this.ptr);
120                 GC.KeepAlive(this);
121                 if (ret >= 0 && ret <= 4096) { return null; }
122                 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
123                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
124                 return ret_hu_conv;
125         }
126
127         /**
128          * Checks if two Routes contain equal inner contents.
129          */
130         public long hash() {
131                 long ret = bindings.Route_hash(this.ptr);
132                 GC.KeepAlive(this);
133                 return ret;
134         }
135
136         public override int GetHashCode() {
137                 return (int)this.hash();
138         }
139         /**
140          * Checks if two Routes contain equal inner contents.
141          * This ignores pointers and is_owned flags and looks at the values in fields.
142          * Two objects with NULL inner values will be considered "equal" here.
143          */
144         public bool eq(org.ldk.structs.Route b) {
145                 bool ret = bindings.Route_eq(this.ptr, b == null ? 0 : b.ptr);
146                 GC.KeepAlive(this);
147                 GC.KeepAlive(b);
148                 if (this != null) { this.ptrs_to.AddLast(b); };
149                 return ret;
150         }
151
152         public override bool Equals(object o) {
153                 if (!(o is Route)) return false;
154                 return this.eq((Route)o);
155         }
156         /**
157          * Returns the total amount of fees paid on this [`Route`].
158          * 
159          * This doesn't include any extra payment made to the recipient, which can happen in excess of
160          * the amount passed to [`find_route`]'s `params.final_value_msat`.
161          */
162         public long get_total_fees() {
163                 long ret = bindings.Route_get_total_fees(this.ptr);
164                 GC.KeepAlive(this);
165                 return ret;
166         }
167
168         /**
169          * Returns the total amount paid on this [`Route`], excluding the fees.
170          */
171         public long get_total_amount() {
172                 long ret = bindings.Route_get_total_amount(this.ptr);
173                 GC.KeepAlive(this);
174                 return ret;
175         }
176
177         /**
178          * Serialize the Route object into a byte array which can be read by Route_read
179          */
180         public byte[] write() {
181                 byte[] ret = bindings.Route_write(this.ptr);
182                 GC.KeepAlive(this);
183                 return ret;
184         }
185
186         /**
187          * Read a Route from a byte array, created by Route_write
188          */
189         public static Result_RouteDecodeErrorZ read(byte[] ser) {
190                 long ret = bindings.Route_read(ser);
191                 GC.KeepAlive(ser);
192                 if (ret >= 0 && ret <= 4096) { return null; }
193                 Result_RouteDecodeErrorZ ret_hu_conv = Result_RouteDecodeErrorZ.constr_from_ptr(ret);
194                 return ret_hu_conv;
195         }
196
197 }
198 } } }