8ddb6965153ac185f9c26fd06171c988ee605897
[ldk-java] / c_sharp / src / org / ldk / structs / ErrorMessage.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 [`error`] message to be sent to or received from a peer.
11  * 
12  * [`error`]: https://github.com/lightning/bolts/blob/master/01-messaging.md#the-error-and-warning-messages
13  */
14 public class ErrorMessage : CommonBase {
15         internal ErrorMessage(object _dummy, long ptr) : base(ptr) { }
16         ~ErrorMessage() {
17                 if (ptr != 0) { bindings.ErrorMessage_free(ptr); }
18         }
19
20         /**
21          * The channel ID involved in the error.
22          * 
23          * All-0s indicates a general error unrelated to a specific channel, after which all channels
24          * with the sending peer should be closed.
25          */
26         public byte[] get_channel_id() {
27                 byte[] ret = bindings.ErrorMessage_get_channel_id(this.ptr);
28                 GC.KeepAlive(this);
29                 return ret;
30         }
31
32         /**
33          * The channel ID involved in the error.
34          * 
35          * All-0s indicates a general error unrelated to a specific channel, after which all channels
36          * with the sending peer should be closed.
37          */
38         public void set_channel_id(byte[] val) {
39                 bindings.ErrorMessage_set_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32));
40                 GC.KeepAlive(this);
41                 GC.KeepAlive(val);
42         }
43
44         /**
45          * A possibly human-readable error description.
46          * 
47          * The string should be sanitized before it is used (e.g., emitted to logs or printed to
48          * `stdout`). Otherwise, a well crafted error message may trigger a security vulnerability in
49          * the terminal emulator or the logging subsystem.
50          */
51         public string get_data() {
52                 string ret = bindings.ErrorMessage_get_data(this.ptr);
53                 GC.KeepAlive(this);
54                 return ret;
55         }
56
57         /**
58          * A possibly human-readable error description.
59          * 
60          * The string should be sanitized before it is used (e.g., emitted to logs or printed to
61          * `stdout`). Otherwise, a well crafted error message may trigger a security vulnerability in
62          * the terminal emulator or the logging subsystem.
63          */
64         public void set_data(string val) {
65                 bindings.ErrorMessage_set_data(this.ptr, val);
66                 GC.KeepAlive(this);
67                 GC.KeepAlive(val);
68         }
69
70         /**
71          * Constructs a new ErrorMessage given each field
72          */
73         public static ErrorMessage of(byte[] channel_id_arg, string data_arg) {
74                 long ret = bindings.ErrorMessage_new(InternalUtils.check_arr_len(channel_id_arg, 32), data_arg);
75                 GC.KeepAlive(channel_id_arg);
76                 GC.KeepAlive(data_arg);
77                 if (ret >= 0 && ret <= 4096) { return null; }
78                 org.ldk.structs.ErrorMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ErrorMessage(null, ret); }
79                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
80                 return ret_hu_conv;
81         }
82
83         internal long clone_ptr() {
84                 long ret = bindings.ErrorMessage_clone_ptr(this.ptr);
85                 GC.KeepAlive(this);
86                 return ret;
87         }
88
89         /**
90          * Creates a copy of the ErrorMessage
91          */
92         public ErrorMessage clone() {
93                 long ret = bindings.ErrorMessage_clone(this.ptr);
94                 GC.KeepAlive(this);
95                 if (ret >= 0 && ret <= 4096) { return null; }
96                 org.ldk.structs.ErrorMessage ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ErrorMessage(null, ret); }
97                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
98                 return ret_hu_conv;
99         }
100
101         /**
102          * Checks if two ErrorMessages contain equal inner contents.
103          * This ignores pointers and is_owned flags and looks at the values in fields.
104          * Two objects with NULL inner values will be considered "equal" here.
105          */
106         public bool eq(org.ldk.structs.ErrorMessage b) {
107                 bool ret = bindings.ErrorMessage_eq(this.ptr, b == null ? 0 : b.ptr);
108                 GC.KeepAlive(this);
109                 GC.KeepAlive(b);
110                 if (this != null) { this.ptrs_to.AddLast(b); };
111                 return ret;
112         }
113
114         public override bool Equals(object o) {
115                 if (!(o is ErrorMessage)) return false;
116                 return this.eq((ErrorMessage)o);
117         }
118         /**
119          * Serialize the ErrorMessage object into a byte array which can be read by ErrorMessage_read
120          */
121         public byte[] write() {
122                 byte[] ret = bindings.ErrorMessage_write(this.ptr);
123                 GC.KeepAlive(this);
124                 return ret;
125         }
126
127         /**
128          * Read a ErrorMessage from a byte array, created by ErrorMessage_write
129          */
130         public static Result_ErrorMessageDecodeErrorZ read(byte[] ser) {
131                 long ret = bindings.ErrorMessage_read(ser);
132                 GC.KeepAlive(ser);
133                 if (ret >= 0 && ret <= 4096) { return null; }
134                 Result_ErrorMessageDecodeErrorZ ret_hu_conv = Result_ErrorMessageDecodeErrorZ.constr_from_ptr(ret);
135                 return ret_hu_conv;
136         }
137
138 }
139 } } }