031932b150f72c3aeca232d8dfe606fa1ce42da0
[ldk-java] / c_sharp / src / org / ldk / structs / ChannelUpdate.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 channel_update message to be sent or received from a peer
11  */
12 public class ChannelUpdate : CommonBase {
13         internal ChannelUpdate(object _dummy, long ptr) : base(ptr) { }
14         ~ChannelUpdate() {
15                 if (ptr != 0) { bindings.ChannelUpdate_free(ptr); }
16         }
17
18         /**
19          * A signature of the channel update
20          */
21         public byte[] get_signature() {
22                 byte[] ret = bindings.ChannelUpdate_get_signature(this.ptr);
23                 GC.KeepAlive(this);
24                 return ret;
25         }
26
27         /**
28          * A signature of the channel update
29          */
30         public void set_signature(byte[] val) {
31                 bindings.ChannelUpdate_set_signature(this.ptr, InternalUtils.check_arr_len(val, 64));
32                 GC.KeepAlive(this);
33                 GC.KeepAlive(val);
34         }
35
36         /**
37          * The actual channel update
38          */
39         public UnsignedChannelUpdate get_contents() {
40                 long ret = bindings.ChannelUpdate_get_contents(this.ptr);
41                 GC.KeepAlive(this);
42                 if (ret >= 0 && ret <= 4096) { return null; }
43                 org.ldk.structs.UnsignedChannelUpdate ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.UnsignedChannelUpdate(null, ret); }
44                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
45                 return ret_hu_conv;
46         }
47
48         /**
49          * The actual channel update
50          */
51         public void set_contents(org.ldk.structs.UnsignedChannelUpdate val) {
52                 bindings.ChannelUpdate_set_contents(this.ptr, val == null ? 0 : val.ptr);
53                 GC.KeepAlive(this);
54                 GC.KeepAlive(val);
55                 if (this != null) { this.ptrs_to.AddLast(val); };
56         }
57
58         /**
59          * Constructs a new ChannelUpdate given each field
60          */
61         public static ChannelUpdate of(byte[] signature_arg, org.ldk.structs.UnsignedChannelUpdate contents_arg) {
62                 long ret = bindings.ChannelUpdate_new(InternalUtils.check_arr_len(signature_arg, 64), contents_arg == null ? 0 : contents_arg.ptr);
63                 GC.KeepAlive(signature_arg);
64                 GC.KeepAlive(contents_arg);
65                 if (ret >= 0 && ret <= 4096) { return null; }
66                 org.ldk.structs.ChannelUpdate ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelUpdate(null, ret); }
67                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
68                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(contents_arg); };
69                 return ret_hu_conv;
70         }
71
72         internal long clone_ptr() {
73                 long ret = bindings.ChannelUpdate_clone_ptr(this.ptr);
74                 GC.KeepAlive(this);
75                 return ret;
76         }
77
78         /**
79          * Creates a copy of the ChannelUpdate
80          */
81         public ChannelUpdate clone() {
82                 long ret = bindings.ChannelUpdate_clone(this.ptr);
83                 GC.KeepAlive(this);
84                 if (ret >= 0 && ret <= 4096) { return null; }
85                 org.ldk.structs.ChannelUpdate ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelUpdate(null, ret); }
86                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
87                 return ret_hu_conv;
88         }
89
90         /**
91          * Checks if two ChannelUpdates contain equal inner contents.
92          * This ignores pointers and is_owned flags and looks at the values in fields.
93          * Two objects with NULL inner values will be considered "equal" here.
94          */
95         public bool eq(org.ldk.structs.ChannelUpdate b) {
96                 bool ret = bindings.ChannelUpdate_eq(this.ptr, b == null ? 0 : b.ptr);
97                 GC.KeepAlive(this);
98                 GC.KeepAlive(b);
99                 if (this != null) { this.ptrs_to.AddLast(b); };
100                 return ret;
101         }
102
103         public override bool Equals(object o) {
104                 if (!(o is ChannelUpdate)) return false;
105                 return this.eq((ChannelUpdate)o);
106         }
107         /**
108          * Serialize the ChannelUpdate object into a byte array which can be read by ChannelUpdate_read
109          */
110         public byte[] write() {
111                 byte[] ret = bindings.ChannelUpdate_write(this.ptr);
112                 GC.KeepAlive(this);
113                 return ret;
114         }
115
116         /**
117          * Read a ChannelUpdate from a byte array, created by ChannelUpdate_write
118          */
119         public static Result_ChannelUpdateDecodeErrorZ read(byte[] ser) {
120                 long ret = bindings.ChannelUpdate_read(ser);
121                 GC.KeepAlive(ser);
122                 if (ret >= 0 && ret <= 4096) { return null; }
123                 Result_ChannelUpdateDecodeErrorZ ret_hu_conv = Result_ChannelUpdateDecodeErrorZ.constr_from_ptr(ret);
124                 return ret_hu_conv;
125         }
126
127 }
128 } } }