Merge pull request #139 from TheBlueMatt/main
[ldk-java] / c_sharp / src / org / ldk / structs / Payee.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  * The recipient of a payment, differing based on whether they've hidden their identity with route
10  * blinding.
11  */
12 public class Payee : CommonBase {
13         protected Payee(object _dummy, long ptr) : base(ptr) { }
14         ~Payee() {
15                 if (ptr != 0) { bindings.Payee_free(ptr); }
16         }
17
18         internal static Payee constr_from_ptr(long ptr) {
19                 long raw_ty = bindings.LDKPayee_ty_from_ptr(ptr);
20                 switch (raw_ty) {
21                         case 0: return new Payee_Blinded(ptr);
22                         case 1: return new Payee_Clear(ptr);
23                         default:
24                                 throw new ArgumentException("Impossible enum variant");
25                 }
26         }
27
28         /** A Payee of type Blinded */
29         public class Payee_Blinded : Payee {
30                 /**
31                  * Aggregated routing info and blinded paths, for routing to the payee without knowing their
32                  * node id.
33                  */
34                 public TwoTuple_BlindedPayInfoBlindedPathZ[] route_hints;
35                 /**
36                  * Features supported by the payee.
37                  * 
38                  * May be set from the payee's invoice. May be `None` if the invoice does not contain any
39                  * features.
40                  * 
41                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
42                  */
43                 public Bolt12InvoiceFeatures features;
44                 internal Payee_Blinded(long ptr) : base(null, ptr) {
45                         long[] route_hints = bindings.LDKPayee_Blinded_get_route_hints(ptr);
46                         int route_hints_conv_37_len = route_hints.Length;
47                         TwoTuple_BlindedPayInfoBlindedPathZ[] route_hints_conv_37_arr = new TwoTuple_BlindedPayInfoBlindedPathZ[route_hints_conv_37_len];
48                         for (int l = 0; l < route_hints_conv_37_len; l++) {
49                                 long route_hints_conv_37 = route_hints[l];
50                                 TwoTuple_BlindedPayInfoBlindedPathZ route_hints_conv_37_hu_conv = new TwoTuple_BlindedPayInfoBlindedPathZ(null, route_hints_conv_37);
51                                 if (route_hints_conv_37_hu_conv != null) { route_hints_conv_37_hu_conv.ptrs_to.AddLast(this); };
52                                 route_hints_conv_37_arr[l] = route_hints_conv_37_hu_conv;
53                         }
54                         this.route_hints = route_hints_conv_37_arr;
55                         long features = bindings.LDKPayee_Blinded_get_features(ptr);
56                         org.ldk.structs.Bolt12InvoiceFeatures features_hu_conv = null; if (features < 0 || features > 4096) { features_hu_conv = new org.ldk.structs.Bolt12InvoiceFeatures(null, features); }
57                         if (features_hu_conv != null) { features_hu_conv.ptrs_to.AddLast(this); };
58                         this.features = features_hu_conv;
59                 }
60         }
61         /** A Payee of type Clear */
62         public class Payee_Clear : Payee {
63                 /**
64                  * The node id of the payee.
65                  */
66                 public byte[] node_id;
67                 /**
68                  * Hints for routing to the payee, containing channels connecting the payee to public nodes.
69                  */
70                 public RouteHint[] route_hints;
71                 /**
72                  * Features supported by the payee.
73                  * 
74                  * May be set from the payee's invoice or via [`for_keysend`]. May be `None` if the invoice
75                  * does not contain any features.
76                  * 
77                  * [`for_keysend`]: PaymentParameters::for_keysend
78                  * 
79                  * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
80                  */
81                 public Bolt11InvoiceFeatures features;
82                 /**
83                  * The minimum CLTV delta at the end of the route. This value must not be zero.
84                  */
85                 public int final_cltv_expiry_delta;
86                 internal Payee_Clear(long ptr) : base(null, ptr) {
87                         this.node_id = bindings.LDKPayee_Clear_get_node_id(ptr);
88                         long[] route_hints = bindings.LDKPayee_Clear_get_route_hints(ptr);
89                         int route_hints_conv_11_len = route_hints.Length;
90                         RouteHint[] route_hints_conv_11_arr = new RouteHint[route_hints_conv_11_len];
91                         for (int l = 0; l < route_hints_conv_11_len; l++) {
92                                 long route_hints_conv_11 = route_hints[l];
93                                 org.ldk.structs.RouteHint route_hints_conv_11_hu_conv = null; if (route_hints_conv_11 < 0 || route_hints_conv_11 > 4096) { route_hints_conv_11_hu_conv = new org.ldk.structs.RouteHint(null, route_hints_conv_11); }
94                                 if (route_hints_conv_11_hu_conv != null) { route_hints_conv_11_hu_conv.ptrs_to.AddLast(this); };
95                                 route_hints_conv_11_arr[l] = route_hints_conv_11_hu_conv;
96                         }
97                         this.route_hints = route_hints_conv_11_arr;
98                         long features = bindings.LDKPayee_Clear_get_features(ptr);
99                         org.ldk.structs.Bolt11InvoiceFeatures features_hu_conv = null; if (features < 0 || features > 4096) { features_hu_conv = new org.ldk.structs.Bolt11InvoiceFeatures(null, features); }
100                         if (features_hu_conv != null) { features_hu_conv.ptrs_to.AddLast(this); };
101                         this.features = features_hu_conv;
102                         this.final_cltv_expiry_delta = bindings.LDKPayee_Clear_get_final_cltv_expiry_delta(ptr);
103                 }
104         }
105         internal long clone_ptr() {
106                 long ret = bindings.Payee_clone_ptr(this.ptr);
107                 GC.KeepAlive(this);
108                 return ret;
109         }
110
111         /**
112          * Creates a copy of the Payee
113          */
114         public Payee clone() {
115                 long ret = bindings.Payee_clone(this.ptr);
116                 GC.KeepAlive(this);
117                 if (ret >= 0 && ret <= 4096) { return null; }
118                 org.ldk.structs.Payee ret_hu_conv = org.ldk.structs.Payee.constr_from_ptr(ret);
119                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
120                 return ret_hu_conv;
121         }
122
123         /**
124          * Utility method to constructs a new Blinded-variant Payee
125          */
126         public static Payee blinded(TwoTuple_BlindedPayInfoBlindedPathZ[] route_hints, org.ldk.structs.Bolt12InvoiceFeatures features) {
127                 long ret = bindings.Payee_blinded(route_hints != null ? InternalUtils.mapArray(route_hints, route_hints_conv_37 => route_hints_conv_37 != null ? route_hints_conv_37.ptr : 0) : null, features == null ? 0 : features.ptr);
128                 GC.KeepAlive(route_hints);
129                 GC.KeepAlive(features);
130                 if (ret >= 0 && ret <= 4096) { return null; }
131                 org.ldk.structs.Payee ret_hu_conv = org.ldk.structs.Payee.constr_from_ptr(ret);
132                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
133                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(features); };
134                 return ret_hu_conv;
135         }
136
137         /**
138          * Utility method to constructs a new Clear-variant Payee
139          */
140         public static Payee clear(byte[] node_id, RouteHint[] route_hints, org.ldk.structs.Bolt11InvoiceFeatures features, int final_cltv_expiry_delta) {
141                 long ret = bindings.Payee_clear(InternalUtils.check_arr_len(node_id, 33), route_hints != null ? InternalUtils.mapArray(route_hints, route_hints_conv_11 => route_hints_conv_11 == null ? 0 : route_hints_conv_11.ptr) : null, features == null ? 0 : features.ptr, final_cltv_expiry_delta);
142                 GC.KeepAlive(node_id);
143                 GC.KeepAlive(route_hints);
144                 GC.KeepAlive(features);
145                 GC.KeepAlive(final_cltv_expiry_delta);
146                 if (ret >= 0 && ret <= 4096) { return null; }
147                 org.ldk.structs.Payee ret_hu_conv = org.ldk.structs.Payee.constr_from_ptr(ret);
148                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
149                 foreach (RouteHint route_hints_conv_11 in route_hints) { if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(route_hints_conv_11); }; };
150                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(features); };
151                 return ret_hu_conv;
152         }
153
154         /**
155          * Generates a non-cryptographic 64-bit hash of the Payee.
156          */
157         public long hash() {
158                 long ret = bindings.Payee_hash(this.ptr);
159                 GC.KeepAlive(this);
160                 return ret;
161         }
162
163         public override int GetHashCode() {
164                 return (int)this.hash();
165         }
166         /**
167          * Checks if two Payees contain equal inner contents.
168          * This ignores pointers and is_owned flags and looks at the values in fields.
169          */
170         public bool eq(org.ldk.structs.Payee b) {
171                 bool ret = bindings.Payee_eq(this.ptr, b == null ? 0 : b.ptr);
172                 GC.KeepAlive(this);
173                 GC.KeepAlive(b);
174                 return ret;
175         }
176
177         public override bool Equals(object o) {
178                 if (!(o is Payee)) return false;
179                 return this.eq((Payee)o);
180         }
181 }
182 } } }