Merge pull request #124 from TheBlueMatt/main
[ldk-java] / c_sharp / src / org / ldk / structs / ChannelCounterparty.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  * Channel parameters which apply to our counterparty. These are split out from [`ChannelDetails`]
11  * to better separate parameters.
12  */
13 public class ChannelCounterparty : CommonBase {
14         internal ChannelCounterparty(object _dummy, long ptr) : base(ptr) { }
15         ~ChannelCounterparty() {
16                 if (ptr != 0) { bindings.ChannelCounterparty_free(ptr); }
17         }
18
19         /**
20          * The node_id of our counterparty
21          */
22         public byte[] get_node_id() {
23                 byte[] ret = bindings.ChannelCounterparty_get_node_id(this.ptr);
24                 GC.KeepAlive(this);
25                 return ret;
26         }
27
28         /**
29          * The node_id of our counterparty
30          */
31         public void set_node_id(byte[] val) {
32                 bindings.ChannelCounterparty_set_node_id(this.ptr, InternalUtils.check_arr_len(val, 33));
33                 GC.KeepAlive(this);
34                 GC.KeepAlive(val);
35         }
36
37         /**
38          * The Features the channel counterparty provided upon last connection.
39          * Useful for routing as it is the most up-to-date copy of the counterparty's features and
40          * many routing-relevant features are present in the init context.
41          */
42         public InitFeatures get_features() {
43                 long ret = bindings.ChannelCounterparty_get_features(this.ptr);
44                 GC.KeepAlive(this);
45                 if (ret >= 0 && ret <= 4096) { return null; }
46                 org.ldk.structs.InitFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InitFeatures(null, ret); }
47                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
48                 return ret_hu_conv;
49         }
50
51         /**
52          * The Features the channel counterparty provided upon last connection.
53          * Useful for routing as it is the most up-to-date copy of the counterparty's features and
54          * many routing-relevant features are present in the init context.
55          */
56         public void set_features(org.ldk.structs.InitFeatures val) {
57                 bindings.ChannelCounterparty_set_features(this.ptr, val == null ? 0 : val.ptr);
58                 GC.KeepAlive(this);
59                 GC.KeepAlive(val);
60                 if (this != null) { this.ptrs_to.AddLast(val); };
61         }
62
63         /**
64          * The value, in satoshis, that must always be held in the channel for our counterparty. This
65          * value ensures that if our counterparty broadcasts a revoked state, we can punish them by
66          * claiming at least this value on chain.
67          * 
68          * This value is not included in [`inbound_capacity_msat`] as it can never be spent.
69          * 
70          * [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
71          */
72         public long get_unspendable_punishment_reserve() {
73                 long ret = bindings.ChannelCounterparty_get_unspendable_punishment_reserve(this.ptr);
74                 GC.KeepAlive(this);
75                 return ret;
76         }
77
78         /**
79          * The value, in satoshis, that must always be held in the channel for our counterparty. This
80          * value ensures that if our counterparty broadcasts a revoked state, we can punish them by
81          * claiming at least this value on chain.
82          * 
83          * This value is not included in [`inbound_capacity_msat`] as it can never be spent.
84          * 
85          * [`inbound_capacity_msat`]: ChannelDetails::inbound_capacity_msat
86          */
87         public void set_unspendable_punishment_reserve(long val) {
88                 bindings.ChannelCounterparty_set_unspendable_punishment_reserve(this.ptr, val);
89                 GC.KeepAlive(this);
90                 GC.KeepAlive(val);
91         }
92
93         /**
94          * Information on the fees and requirements that the counterparty requires when forwarding
95          * payments to us through this channel.
96          * 
97          * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
98          */
99         public CounterpartyForwardingInfo get_forwarding_info() {
100                 long ret = bindings.ChannelCounterparty_get_forwarding_info(this.ptr);
101                 GC.KeepAlive(this);
102                 if (ret >= 0 && ret <= 4096) { return null; }
103                 org.ldk.structs.CounterpartyForwardingInfo ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CounterpartyForwardingInfo(null, ret); }
104                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
105                 return ret_hu_conv;
106         }
107
108         /**
109          * Information on the fees and requirements that the counterparty requires when forwarding
110          * payments to us through this channel.
111          * 
112          * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
113          */
114         public void set_forwarding_info(org.ldk.structs.CounterpartyForwardingInfo val) {
115                 bindings.ChannelCounterparty_set_forwarding_info(this.ptr, val == null ? 0 : val.ptr);
116                 GC.KeepAlive(this);
117                 GC.KeepAlive(val);
118                 if (this != null) { this.ptrs_to.AddLast(val); };
119         }
120
121         /**
122          * The smallest value HTLC (in msat) the remote peer will accept, for this channel. This field
123          * is only `None` before we have received either the `OpenChannel` or `AcceptChannel` message
124          * from the remote peer, or for `ChannelCounterparty` objects serialized prior to LDK 0.0.107.
125          */
126         public Option_u64Z get_outbound_htlc_minimum_msat() {
127                 long ret = bindings.ChannelCounterparty_get_outbound_htlc_minimum_msat(this.ptr);
128                 GC.KeepAlive(this);
129                 if (ret >= 0 && ret <= 4096) { return null; }
130                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
131                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
132                 return ret_hu_conv;
133         }
134
135         /**
136          * The smallest value HTLC (in msat) the remote peer will accept, for this channel. This field
137          * is only `None` before we have received either the `OpenChannel` or `AcceptChannel` message
138          * from the remote peer, or for `ChannelCounterparty` objects serialized prior to LDK 0.0.107.
139          */
140         public void set_outbound_htlc_minimum_msat(org.ldk.structs.Option_u64Z val) {
141                 bindings.ChannelCounterparty_set_outbound_htlc_minimum_msat(this.ptr, val.ptr);
142                 GC.KeepAlive(this);
143                 GC.KeepAlive(val);
144         }
145
146         /**
147          * The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
148          */
149         public Option_u64Z get_outbound_htlc_maximum_msat() {
150                 long ret = bindings.ChannelCounterparty_get_outbound_htlc_maximum_msat(this.ptr);
151                 GC.KeepAlive(this);
152                 if (ret >= 0 && ret <= 4096) { return null; }
153                 org.ldk.structs.Option_u64Z ret_hu_conv = org.ldk.structs.Option_u64Z.constr_from_ptr(ret);
154                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
155                 return ret_hu_conv;
156         }
157
158         /**
159          * The largest value HTLC (in msat) the remote peer currently will accept, for this channel.
160          */
161         public void set_outbound_htlc_maximum_msat(org.ldk.structs.Option_u64Z val) {
162                 bindings.ChannelCounterparty_set_outbound_htlc_maximum_msat(this.ptr, val.ptr);
163                 GC.KeepAlive(this);
164                 GC.KeepAlive(val);
165         }
166
167         /**
168          * Constructs a new ChannelCounterparty given each field
169          */
170         public static ChannelCounterparty of(byte[] node_id_arg, org.ldk.structs.InitFeatures features_arg, long unspendable_punishment_reserve_arg, org.ldk.structs.CounterpartyForwardingInfo forwarding_info_arg, org.ldk.structs.Option_u64Z outbound_htlc_minimum_msat_arg, org.ldk.structs.Option_u64Z outbound_htlc_maximum_msat_arg) {
171                 long ret = bindings.ChannelCounterparty_new(InternalUtils.check_arr_len(node_id_arg, 33), features_arg == null ? 0 : features_arg.ptr, unspendable_punishment_reserve_arg, forwarding_info_arg == null ? 0 : forwarding_info_arg.ptr, outbound_htlc_minimum_msat_arg.ptr, outbound_htlc_maximum_msat_arg.ptr);
172                 GC.KeepAlive(node_id_arg);
173                 GC.KeepAlive(features_arg);
174                 GC.KeepAlive(unspendable_punishment_reserve_arg);
175                 GC.KeepAlive(forwarding_info_arg);
176                 GC.KeepAlive(outbound_htlc_minimum_msat_arg);
177                 GC.KeepAlive(outbound_htlc_maximum_msat_arg);
178                 if (ret >= 0 && ret <= 4096) { return null; }
179                 org.ldk.structs.ChannelCounterparty ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelCounterparty(null, ret); }
180                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
181                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(features_arg); };
182                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(forwarding_info_arg); };
183                 return ret_hu_conv;
184         }
185
186         internal long clone_ptr() {
187                 long ret = bindings.ChannelCounterparty_clone_ptr(this.ptr);
188                 GC.KeepAlive(this);
189                 return ret;
190         }
191
192         /**
193          * Creates a copy of the ChannelCounterparty
194          */
195         public ChannelCounterparty clone() {
196                 long ret = bindings.ChannelCounterparty_clone(this.ptr);
197                 GC.KeepAlive(this);
198                 if (ret >= 0 && ret <= 4096) { return null; }
199                 org.ldk.structs.ChannelCounterparty ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelCounterparty(null, ret); }
200                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
201                 return ret_hu_conv;
202         }
203
204         /**
205          * Serialize the ChannelCounterparty object into a byte array which can be read by ChannelCounterparty_read
206          */
207         public byte[] write() {
208                 byte[] ret = bindings.ChannelCounterparty_write(this.ptr);
209                 GC.KeepAlive(this);
210                 return ret;
211         }
212
213         /**
214          * Read a ChannelCounterparty from a byte array, created by ChannelCounterparty_write
215          */
216         public static Result_ChannelCounterpartyDecodeErrorZ read(byte[] ser) {
217                 long ret = bindings.ChannelCounterparty_read(ser);
218                 GC.KeepAlive(ser);
219                 if (ret >= 0 && ret <= 4096) { return null; }
220                 Result_ChannelCounterpartyDecodeErrorZ ret_hu_conv = Result_ChannelCounterpartyDecodeErrorZ.constr_from_ptr(ret);
221                 return ret_hu_conv;
222         }
223
224 }
225 } } }