e7c85b52bf0658d2045af2cf2fea3218e4d53e86
[ldk-java] / src / main / java / org / ldk / structs / TransactionU16LenLimited.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 wrapper for a `Transaction` which can only be constructed with [`TransactionU16LenLimited::new`]
13  * if the `Transaction`'s consensus-serialized length is <= u16::MAX.
14  * 
15  * Use [`TransactionU16LenLimited::into_transaction`] to convert into the contained `Transaction`.
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class TransactionU16LenLimited extends CommonBase {
19         TransactionU16LenLimited(Object _dummy, long ptr) { super(ptr); }
20         @Override @SuppressWarnings("deprecation")
21         protected void finalize() throws Throwable {
22                 super.finalize();
23                 if (ptr != 0) { bindings.TransactionU16LenLimited_free(ptr); }
24         }
25
26         long clone_ptr() {
27                 long ret = bindings.TransactionU16LenLimited_clone_ptr(this.ptr);
28                 Reference.reachabilityFence(this);
29                 return ret;
30         }
31
32         /**
33          * Creates a copy of the TransactionU16LenLimited
34          */
35         public TransactionU16LenLimited clone() {
36                 long ret = bindings.TransactionU16LenLimited_clone(this.ptr);
37                 Reference.reachabilityFence(this);
38                 if (ret >= 0 && ret <= 4096) { return null; }
39                 org.ldk.structs.TransactionU16LenLimited ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.TransactionU16LenLimited(null, ret); }
40                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
41                 return ret_hu_conv;
42         }
43
44         /**
45          * Checks if two TransactionU16LenLimiteds contain equal inner contents.
46          * This ignores pointers and is_owned flags and looks at the values in fields.
47          * Two objects with NULL inner values will be considered "equal" here.
48          */
49         public boolean eq(org.ldk.structs.TransactionU16LenLimited b) {
50                 boolean ret = bindings.TransactionU16LenLimited_eq(this.ptr, b == null ? 0 : b.ptr);
51                 Reference.reachabilityFence(this);
52                 Reference.reachabilityFence(b);
53                 if (this != null) { this.ptrs_to.add(b); };
54                 return ret;
55         }
56
57         @Override public boolean equals(Object o) {
58                 if (!(o instanceof TransactionU16LenLimited)) return false;
59                 return this.eq((TransactionU16LenLimited)o);
60         }
61         /**
62          * Constructs a new `TransactionU16LenLimited` from a `Transaction` only if it's consensus-
63          * serialized length is <= u16::MAX.
64          */
65         public static Result_TransactionU16LenLimitedNoneZ of(byte[] transaction) {
66                 long ret = bindings.TransactionU16LenLimited_new(transaction);
67                 Reference.reachabilityFence(transaction);
68                 if (ret >= 0 && ret <= 4096) { return null; }
69                 Result_TransactionU16LenLimitedNoneZ ret_hu_conv = Result_TransactionU16LenLimitedNoneZ.constr_from_ptr(ret);
70                 return ret_hu_conv;
71         }
72
73         /**
74          * Consumes this `TransactionU16LenLimited` and returns its contained `Transaction`.
75          */
76         public byte[] into_transaction() {
77                 byte[] ret = bindings.TransactionU16LenLimited_into_transaction(this.ptr);
78                 Reference.reachabilityFence(this);
79                 if (this != null) { this.ptrs_to.add(this); };
80                 return ret;
81         }
82
83         /**
84          * Serialize the TransactionU16LenLimited object into a byte array which can be read by TransactionU16LenLimited_read
85          */
86         public byte[] write() {
87                 byte[] ret = bindings.TransactionU16LenLimited_write(this.ptr);
88                 Reference.reachabilityFence(this);
89                 return ret;
90         }
91
92         /**
93          * Read a TransactionU16LenLimited from a byte array, created by TransactionU16LenLimited_write
94          */
95         public static Result_TransactionU16LenLimitedDecodeErrorZ read(byte[] ser) {
96                 long ret = bindings.TransactionU16LenLimited_read(ser);
97                 Reference.reachabilityFence(ser);
98                 if (ret >= 0 && ret <= 4096) { return null; }
99                 Result_TransactionU16LenLimitedDecodeErrorZ ret_hu_conv = Result_TransactionU16LenLimitedDecodeErrorZ.constr_from_ptr(ret);
100                 return ret_hu_conv;
101         }
102
103 }