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