1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * A reference to a transaction output.
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.
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 {
23 if (ptr != 0) { bindings.OutPoint_free(ptr); }
27 * The referenced transaction's txid.
29 public byte[] get_txid() {
30 byte[] ret = bindings.OutPoint_get_txid(this.ptr);
31 Reference.reachabilityFence(this);
36 * The referenced transaction's txid.
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);
45 * The index of the referenced output in its transaction's vout.
47 public short get_index() {
48 short ret = bindings.OutPoint_get_index(this.ptr);
49 Reference.reachabilityFence(this);
54 * The index of the referenced output in its transaction's vout.
56 public void set_index(short val) {
57 bindings.OutPoint_set_index(this.ptr, val);
58 Reference.reachabilityFence(this);
59 Reference.reachabilityFence(val);
63 * Constructs a new OutPoint given each field
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);
76 long ret = bindings.OutPoint_clone_ptr(this.ptr);
77 Reference.reachabilityFence(this);
82 * Creates a copy of the OutPoint
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);
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.
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);
106 @Override public boolean equals(Object o) {
107 if (!(o instanceof OutPoint)) return false;
108 return this.eq((OutPoint)o);
111 * Checks if two OutPoints contain equal inner contents.
114 long ret = bindings.OutPoint_hash(this.ptr);
115 Reference.reachabilityFence(this);
119 @Override public int hashCode() {
120 return (int)this.hash();
123 * Convert an `OutPoint` to a lightning channel id.
125 public byte[] to_channel_id() {
126 byte[] ret = bindings.OutPoint_to_channel_id(this.ptr);
127 Reference.reachabilityFence(this);
132 * Serialize the OutPoint object into a byte array which can be read by OutPoint_read
134 public byte[] write() {
135 byte[] ret = bindings.OutPoint_write(this.ptr);
136 Reference.reachabilityFence(this);
141 * Read a OutPoint from a byte array, created by OutPoint_write
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);