02521101d63f985739c5d2a9e4d7efcaef3777d4
[ldk-java] / c_sharp / src / org / ldk / structs / OutPoint.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 reference to a transaction output.
11  * 
12  * Differs from bitcoin::blockdata::transaction::OutPoint as the index is a u16 instead of u32
13  * due to LN's restrictions on index values. Should reduce (possibly) unsafe conversions this way.
14  */
15 public class OutPoint : CommonBase {
16         internal OutPoint(object _dummy, long ptr) : base(ptr) { }
17         ~OutPoint() {
18                 if (ptr != 0) { bindings.OutPoint_free(ptr); }
19         }
20
21         /**
22          * The referenced transaction's txid.
23          */
24         public byte[] get_txid() {
25                 byte[] ret = bindings.OutPoint_get_txid(this.ptr);
26                 GC.KeepAlive(this);
27                 return ret;
28         }
29
30         /**
31          * The referenced transaction's txid.
32          */
33         public void set_txid(byte[] val) {
34                 bindings.OutPoint_set_txid(this.ptr, InternalUtils.check_arr_len(val, 32));
35                 GC.KeepAlive(this);
36                 GC.KeepAlive(val);
37         }
38
39         /**
40          * The index of the referenced output in its transaction's vout.
41          */
42         public short get_index() {
43                 short ret = bindings.OutPoint_get_index(this.ptr);
44                 GC.KeepAlive(this);
45                 return ret;
46         }
47
48         /**
49          * The index of the referenced output in its transaction's vout.
50          */
51         public void set_index(short val) {
52                 bindings.OutPoint_set_index(this.ptr, val);
53                 GC.KeepAlive(this);
54                 GC.KeepAlive(val);
55         }
56
57         /**
58          * Constructs a new OutPoint given each field
59          */
60         public static OutPoint of(byte[] txid_arg, short index_arg) {
61                 long ret = bindings.OutPoint_new(InternalUtils.check_arr_len(txid_arg, 32), index_arg);
62                 GC.KeepAlive(txid_arg);
63                 GC.KeepAlive(index_arg);
64                 if (ret >= 0 && ret <= 4096) { return null; }
65                 org.ldk.structs.OutPoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OutPoint(null, ret); }
66                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
67                 return ret_hu_conv;
68         }
69
70         internal long clone_ptr() {
71                 long ret = bindings.OutPoint_clone_ptr(this.ptr);
72                 GC.KeepAlive(this);
73                 return ret;
74         }
75
76         /**
77          * Creates a copy of the OutPoint
78          */
79         public OutPoint clone() {
80                 long ret = bindings.OutPoint_clone(this.ptr);
81                 GC.KeepAlive(this);
82                 if (ret >= 0 && ret <= 4096) { return null; }
83                 org.ldk.structs.OutPoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OutPoint(null, ret); }
84                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
85                 return ret_hu_conv;
86         }
87
88         /**
89          * Checks if two OutPoints contain equal inner contents.
90          * This ignores pointers and is_owned flags and looks at the values in fields.
91          * Two objects with NULL inner values will be considered "equal" here.
92          */
93         public bool eq(org.ldk.structs.OutPoint b) {
94                 bool ret = bindings.OutPoint_eq(this.ptr, b == null ? 0 : b.ptr);
95                 GC.KeepAlive(this);
96                 GC.KeepAlive(b);
97                 if (this != null) { this.ptrs_to.AddLast(b); };
98                 return ret;
99         }
100
101         public override bool Equals(object o) {
102                 if (!(o is OutPoint)) return false;
103                 return this.eq((OutPoint)o);
104         }
105         /**
106          * Checks if two OutPoints contain equal inner contents.
107          */
108         public long hash() {
109                 long ret = bindings.OutPoint_hash(this.ptr);
110                 GC.KeepAlive(this);
111                 return ret;
112         }
113
114         public override int GetHashCode() {
115                 return (int)this.hash();
116         }
117         /**
118          * Convert an `OutPoint` to a lightning channel id.
119          */
120         public byte[] to_channel_id() {
121                 byte[] ret = bindings.OutPoint_to_channel_id(this.ptr);
122                 GC.KeepAlive(this);
123                 return ret;
124         }
125
126         /**
127          * Serialize the OutPoint object into a byte array which can be read by OutPoint_read
128          */
129         public byte[] write() {
130                 byte[] ret = bindings.OutPoint_write(this.ptr);
131                 GC.KeepAlive(this);
132                 return ret;
133         }
134
135         /**
136          * Read a OutPoint from a byte array, created by OutPoint_write
137          */
138         public static Result_OutPointDecodeErrorZ read(byte[] ser) {
139                 long ret = bindings.OutPoint_read(ser);
140                 GC.KeepAlive(ser);
141                 if (ret >= 0 && ret <= 4096) { return null; }
142                 Result_OutPointDecodeErrorZ ret_hu_conv = Result_OutPointDecodeErrorZ.constr_from_ptr(ret);
143                 return ret_hu_conv;
144         }
145
146 }
147 } } }