4177127e89f0bc0a38e60a77e5b34503b29bb650
[ldk-java] / c_sharp / src / org / ldk / structs / UpdateFulfillHTLC.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  * An [`update_fulfill_htlc`] message to be sent to or received from a peer.
11  * 
12  * [`update_fulfill_htlc`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#removing-an-htlc-update_fulfill_htlc-update_fail_htlc-and-update_fail_malformed_htlc
13  */
14 public class UpdateFulfillHTLC : CommonBase {
15         internal UpdateFulfillHTLC(object _dummy, long ptr) : base(ptr) { }
16         ~UpdateFulfillHTLC() {
17                 if (ptr != 0) { bindings.UpdateFulfillHTLC_free(ptr); }
18         }
19
20         /**
21          * The channel ID
22          */
23         public byte[] get_channel_id() {
24                 long ret = bindings.UpdateFulfillHTLC_get_channel_id(this.ptr);
25                 GC.KeepAlive(this);
26                 if (ret >= 0 && ret <= 4096) { return null; }
27                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
28                 return ret_conv;
29         }
30
31         /**
32          * The channel ID
33          */
34         public void set_channel_id(byte[] val) {
35                 bindings.UpdateFulfillHTLC_set_channel_id(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(val, 32)));
36                 GC.KeepAlive(this);
37                 GC.KeepAlive(val);
38         }
39
40         /**
41          * The HTLC ID
42          */
43         public long get_htlc_id() {
44                 long ret = bindings.UpdateFulfillHTLC_get_htlc_id(this.ptr);
45                 GC.KeepAlive(this);
46                 return ret;
47         }
48
49         /**
50          * The HTLC ID
51          */
52         public void set_htlc_id(long val) {
53                 bindings.UpdateFulfillHTLC_set_htlc_id(this.ptr, val);
54                 GC.KeepAlive(this);
55                 GC.KeepAlive(val);
56         }
57
58         /**
59          * The pre-image of the payment hash, allowing HTLC redemption
60          */
61         public byte[] get_payment_preimage() {
62                 long ret = bindings.UpdateFulfillHTLC_get_payment_preimage(this.ptr);
63                 GC.KeepAlive(this);
64                 if (ret >= 0 && ret <= 4096) { return null; }
65                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
66                 return ret_conv;
67         }
68
69         /**
70          * The pre-image of the payment hash, allowing HTLC redemption
71          */
72         public void set_payment_preimage(byte[] val) {
73                 bindings.UpdateFulfillHTLC_set_payment_preimage(this.ptr, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(val, 32)));
74                 GC.KeepAlive(this);
75                 GC.KeepAlive(val);
76         }
77
78         /**
79          * Constructs a new UpdateFulfillHTLC given each field
80          */
81         public static UpdateFulfillHTLC of(byte[] channel_id_arg, long htlc_id_arg, byte[] payment_preimage_arg) {
82                 long ret = bindings.UpdateFulfillHTLC_new(InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(channel_id_arg, 32)), htlc_id_arg, InternalUtils.encodeUint8Array(InternalUtils.check_arr_len(payment_preimage_arg, 32)));
83                 GC.KeepAlive(channel_id_arg);
84                 GC.KeepAlive(htlc_id_arg);
85                 GC.KeepAlive(payment_preimage_arg);
86                 if (ret >= 0 && ret <= 4096) { return null; }
87                 org.ldk.structs.UpdateFulfillHTLC ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UpdateFulfillHTLC(null, ret); }
88                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
89                 return ret_hu_conv;
90         }
91
92         internal long clone_ptr() {
93                 long ret = bindings.UpdateFulfillHTLC_clone_ptr(this.ptr);
94                 GC.KeepAlive(this);
95                 return ret;
96         }
97
98         /**
99          * Creates a copy of the UpdateFulfillHTLC
100          */
101         public UpdateFulfillHTLC clone() {
102                 long ret = bindings.UpdateFulfillHTLC_clone(this.ptr);
103                 GC.KeepAlive(this);
104                 if (ret >= 0 && ret <= 4096) { return null; }
105                 org.ldk.structs.UpdateFulfillHTLC ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UpdateFulfillHTLC(null, ret); }
106                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
107                 return ret_hu_conv;
108         }
109
110         /**
111          * Checks if two UpdateFulfillHTLCs contain equal inner contents.
112          * This ignores pointers and is_owned flags and looks at the values in fields.
113          * Two objects with NULL inner values will be considered "equal" here.
114          */
115         public bool eq(org.ldk.structs.UpdateFulfillHTLC b) {
116                 bool ret = bindings.UpdateFulfillHTLC_eq(this.ptr, b == null ? 0 : b.ptr);
117                 GC.KeepAlive(this);
118                 GC.KeepAlive(b);
119                 if (this != null) { this.ptrs_to.AddLast(b); };
120                 return ret;
121         }
122
123         public override bool Equals(object o) {
124                 if (!(o is UpdateFulfillHTLC)) return false;
125                 return this.eq((UpdateFulfillHTLC)o);
126         }
127         /**
128          * Serialize the UpdateFulfillHTLC object into a byte array which can be read by UpdateFulfillHTLC_read
129          */
130         public byte[] write() {
131                 long ret = bindings.UpdateFulfillHTLC_write(this.ptr);
132                 GC.KeepAlive(this);
133                 if (ret >= 0 && ret <= 4096) { return null; }
134                 byte[] ret_conv = InternalUtils.decodeUint8Array(ret);
135                 return ret_conv;
136         }
137
138         /**
139          * Read a UpdateFulfillHTLC from a byte array, created by UpdateFulfillHTLC_write
140          */
141         public static Result_UpdateFulfillHTLCDecodeErrorZ read(byte[] ser) {
142                 long ret = bindings.UpdateFulfillHTLC_read(InternalUtils.encodeUint8Array(ser));
143                 GC.KeepAlive(ser);
144                 if (ret >= 0 && ret <= 4096) { return null; }
145                 Result_UpdateFulfillHTLCDecodeErrorZ ret_hu_conv = Result_UpdateFulfillHTLCDecodeErrorZ.constr_from_ptr(ret);
146                 return ret_hu_conv;
147         }
148
149 }
150 } } }