[C#] Drop reference to `assert` which makes building on Win hard
[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                 int ret_conv_6_len = ret.Length;
28                 Path[] ret_conv_6_arr = new Path[ret_conv_6_len];
29                 for (int g = 0; g < ret_conv_6_len; g++) {
30                         long ret_conv_6 = ret[g];
31                         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); }
32                         if (ret_conv_6_hu_conv != null) { ret_conv_6_hu_conv.ptrs_to.AddLast(this); };
33                         ret_conv_6_arr[g] = ret_conv_6_hu_conv;
34                 }
35                 return ret_conv_6_arr;
36         }
37
38         /**
39          * The list of [`Path`]s taken for a single (potentially-)multi-part payment. If no
40          * [`BlindedTail`]s are present, then the pubkey of the last [`RouteHop`] in each path must be
41          * the same.
42          */
43         public void set_paths(Path[] val) {
44                 bindings.Route_set_paths(this.ptr, val != null ? InternalUtils.mapArray(val, val_conv_6 => val_conv_6 == null ? 0 : val_conv_6.ptr) : null);
45                 GC.KeepAlive(this);
46                 GC.KeepAlive(val);
47                 foreach (Path val_conv_6 in val) { if (this != null) { this.ptrs_to.AddLast(val_conv_6); }; };
48         }
49
50         /**
51          * The `payment_params` parameter passed via [`RouteParameters`] to [`find_route`].
52          * 
53          * This is used by `ChannelManager` to track information which may be required for retries.
54          * 
55          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
56          */
57         public PaymentParameters get_payment_params() {
58                 long ret = bindings.Route_get_payment_params(this.ptr);
59                 GC.KeepAlive(this);
60                 if (ret >= 0 && ret <= 4096) { return null; }
61                 org.ldk.structs.PaymentParameters ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PaymentParameters(null, ret); }
62                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
63                 return ret_hu_conv;
64         }
65
66         /**
67          * The `payment_params` parameter passed via [`RouteParameters`] to [`find_route`].
68          * 
69          * This is used by `ChannelManager` to track information which may be required for retries.
70          * 
71          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
72          */
73         public void set_payment_params(org.ldk.structs.PaymentParameters val) {
74                 bindings.Route_set_payment_params(this.ptr, val == null ? 0 : val.ptr);
75                 GC.KeepAlive(this);
76                 GC.KeepAlive(val);
77                 if (this != null) { this.ptrs_to.AddLast(val); };
78         }
79
80         /**
81          * Constructs a new Route given each field
82          */
83         public static Route of(Path[] paths_arg, org.ldk.structs.PaymentParameters payment_params_arg) {
84                 long ret = bindings.Route_new(paths_arg != null ? InternalUtils.mapArray(paths_arg, paths_arg_conv_6 => paths_arg_conv_6 == null ? 0 : paths_arg_conv_6.ptr) : null, payment_params_arg == null ? 0 : payment_params_arg.ptr);
85                 GC.KeepAlive(paths_arg);
86                 GC.KeepAlive(payment_params_arg);
87                 if (ret >= 0 && ret <= 4096) { return null; }
88                 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
89                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
90                 foreach (Path paths_arg_conv_6 in paths_arg) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(paths_arg_conv_6); }; };
91                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(payment_params_arg); };
92                 return ret_hu_conv;
93         }
94
95         internal long clone_ptr() {
96                 long ret = bindings.Route_clone_ptr(this.ptr);
97                 GC.KeepAlive(this);
98                 return ret;
99         }
100
101         /**
102          * Creates a copy of the Route
103          */
104         public Route clone() {
105                 long ret = bindings.Route_clone(this.ptr);
106                 GC.KeepAlive(this);
107                 if (ret >= 0 && ret <= 4096) { return null; }
108                 org.ldk.structs.Route ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Route(null, ret); }
109                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
110                 return ret_hu_conv;
111         }
112
113         /**
114          * Generates a non-cryptographic 64-bit hash of the Route.
115          */
116         public long hash() {
117                 long ret = bindings.Route_hash(this.ptr);
118                 GC.KeepAlive(this);
119                 return ret;
120         }
121
122         public override int GetHashCode() {
123                 return (int)this.hash();
124         }
125         /**
126          * Checks if two Routes contain equal inner contents.
127          * This ignores pointers and is_owned flags and looks at the values in fields.
128          * Two objects with NULL inner values will be considered "equal" here.
129          */
130         public bool eq(org.ldk.structs.Route b) {
131                 bool ret = bindings.Route_eq(this.ptr, b == null ? 0 : b.ptr);
132                 GC.KeepAlive(this);
133                 GC.KeepAlive(b);
134                 if (this != null) { this.ptrs_to.AddLast(b); };
135                 return ret;
136         }
137
138         public override bool Equals(object o) {
139                 if (!(o is Route)) return false;
140                 return this.eq((Route)o);
141         }
142         /**
143          * Returns the total amount of fees paid on this [`Route`].
144          * 
145          * This doesn't include any extra payment made to the recipient, which can happen in excess of
146          * the amount passed to [`find_route`]'s `route_params.final_value_msat`.
147          */
148         public long get_total_fees() {
149                 long ret = bindings.Route_get_total_fees(this.ptr);
150                 GC.KeepAlive(this);
151                 return ret;
152         }
153
154         /**
155          * Returns the total amount paid on this [`Route`], excluding the fees. Might be more than
156          * requested if we had to reach htlc_minimum_msat.
157          */
158         public long get_total_amount() {
159                 long ret = bindings.Route_get_total_amount(this.ptr);
160                 GC.KeepAlive(this);
161                 return ret;
162         }
163
164         /**
165          * Serialize the Route object into a byte array which can be read by Route_read
166          */
167         public byte[] write() {
168                 byte[] ret = bindings.Route_write(this.ptr);
169                 GC.KeepAlive(this);
170                 return ret;
171         }
172
173         /**
174          * Read a Route from a byte array, created by Route_write
175          */
176         public static Result_RouteDecodeErrorZ read(byte[] ser) {
177                 long ret = bindings.Route_read(ser);
178                 GC.KeepAlive(ser);
179                 if (ret >= 0 && ret <= 4096) { return null; }
180                 Result_RouteDecodeErrorZ ret_hu_conv = Result_RouteDecodeErrorZ.constr_from_ptr(ret);
181                 return ret_hu_conv;
182         }
183
184 }
185 } } }