[Java] Update auto-generated Java bindings to LDK 0.0.121
[ldk-java] / src / main / java / org / ldk / structs / DelayedPaymentKey.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 derived key built from a [`DelayedPaymentBasepoint`] and `per_commitment_point`.
13  * 
14  * The delayed payment key is used to pay the commitment state broadcaster their
15  * non-HTLC-encumbered funds after a delay. This delay gives their counterparty a chance to
16  * punish and claim all the channel funds if the state broadcasted was previously revoked.
17  * 
18  * [See the BOLT specs]
19  * (https://github.com/lightning/bolts/blob/master/03-transactions.md#localpubkey-local_htlcpubkey-remote_htlcpubkey-local_delayedpubkey-and-remote_delayedpubkey-derivation)
20  * for more information on key derivation details.
21  */
22 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
23 public class DelayedPaymentKey extends CommonBase {
24         DelayedPaymentKey(Object _dummy, long ptr) { super(ptr); }
25         @Override @SuppressWarnings("deprecation")
26         protected void finalize() throws Throwable {
27                 super.finalize();
28                 if (ptr != 0) { bindings.DelayedPaymentKey_free(ptr); }
29         }
30
31         public byte[] get_a() {
32                 byte[] ret = bindings.DelayedPaymentKey_get_a(this.ptr);
33                 Reference.reachabilityFence(this);
34                 return ret;
35         }
36
37         public void set_a(byte[] val) {
38                 bindings.DelayedPaymentKey_set_a(this.ptr, InternalUtils.check_arr_len(val, 33));
39                 Reference.reachabilityFence(this);
40                 Reference.reachabilityFence(val);
41         }
42
43         /**
44          * Constructs a new DelayedPaymentKey given each field
45          */
46         public static DelayedPaymentKey of(byte[] a_arg) {
47                 long ret = bindings.DelayedPaymentKey_new(InternalUtils.check_arr_len(a_arg, 33));
48                 Reference.reachabilityFence(a_arg);
49                 if (ret >= 0 && ret <= 4096) { return null; }
50                 org.ldk.structs.DelayedPaymentKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.DelayedPaymentKey(null, ret); }
51                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
52                 return ret_hu_conv;
53         }
54
55         /**
56          * Checks if two DelayedPaymentKeys contain equal inner contents.
57          * This ignores pointers and is_owned flags and looks at the values in fields.
58          * Two objects with NULL inner values will be considered "equal" here.
59          */
60         public boolean eq(org.ldk.structs.DelayedPaymentKey b) {
61                 boolean ret = bindings.DelayedPaymentKey_eq(this.ptr, b == null ? 0 : b.ptr);
62                 Reference.reachabilityFence(this);
63                 Reference.reachabilityFence(b);
64                 if (this != null) { this.ptrs_to.add(b); };
65                 return ret;
66         }
67
68         @Override public boolean equals(Object o) {
69                 if (!(o instanceof DelayedPaymentKey)) return false;
70                 return this.eq((DelayedPaymentKey)o);
71         }
72         long clone_ptr() {
73                 long ret = bindings.DelayedPaymentKey_clone_ptr(this.ptr);
74                 Reference.reachabilityFence(this);
75                 return ret;
76         }
77
78         /**
79          * Creates a copy of the DelayedPaymentKey
80          */
81         public DelayedPaymentKey clone() {
82                 long ret = bindings.DelayedPaymentKey_clone(this.ptr);
83                 Reference.reachabilityFence(this);
84                 if (ret >= 0 && ret <= 4096) { return null; }
85                 org.ldk.structs.DelayedPaymentKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.DelayedPaymentKey(null, ret); }
86                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
87                 return ret_hu_conv;
88         }
89
90         /**
91          * Derive a public delayedpubkey using one node\'s `per_commitment_point` and its countersignatory\'s `basepoint`
92          */
93         public static DelayedPaymentKey from_basepoint(org.ldk.structs.DelayedPaymentBasepoint countersignatory_basepoint, byte[] per_commitment_point) {
94                 long ret = bindings.DelayedPaymentKey_from_basepoint(countersignatory_basepoint == null ? 0 : countersignatory_basepoint.ptr, InternalUtils.check_arr_len(per_commitment_point, 33));
95                 Reference.reachabilityFence(countersignatory_basepoint);
96                 Reference.reachabilityFence(per_commitment_point);
97                 if (ret >= 0 && ret <= 4096) { return null; }
98                 org.ldk.structs.DelayedPaymentKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.DelayedPaymentKey(null, ret); }
99                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
100                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(countersignatory_basepoint); };
101                 return ret_hu_conv;
102         }
103
104         /**
105          * Build a delayedpubkey directly from an already-derived private key
106          */
107         public static DelayedPaymentKey from_secret_key(byte[] sk) {
108                 long ret = bindings.DelayedPaymentKey_from_secret_key(InternalUtils.check_arr_len(sk, 32));
109                 Reference.reachabilityFence(sk);
110                 if (ret >= 0 && ret <= 4096) { return null; }
111                 org.ldk.structs.DelayedPaymentKey ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.DelayedPaymentKey(null, ret); }
112                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
113                 return ret_hu_conv;
114         }
115
116         /**
117          * Get inner Public Key
118          */
119         public byte[] to_public_key() {
120                 byte[] ret = bindings.DelayedPaymentKey_to_public_key(this.ptr);
121                 Reference.reachabilityFence(this);
122                 return ret;
123         }
124
125         /**
126          * Serialize the DelayedPaymentKey object into a byte array which can be read by DelayedPaymentKey_read
127          */
128         public byte[] write() {
129                 byte[] ret = bindings.DelayedPaymentKey_write(this.ptr);
130                 Reference.reachabilityFence(this);
131                 return ret;
132         }
133
134         /**
135          * Read a DelayedPaymentKey from a byte array, created by DelayedPaymentKey_write
136          */
137         public static Result_DelayedPaymentKeyDecodeErrorZ read(byte[] ser) {
138                 long ret = bindings.DelayedPaymentKey_read(ser);
139                 Reference.reachabilityFence(ser);
140                 if (ret >= 0 && ret <= 4096) { return null; }
141                 Result_DelayedPaymentKeyDecodeErrorZ ret_hu_conv = Result_DelayedPaymentKeyDecodeErrorZ.constr_from_ptr(ret);
142                 return ret_hu_conv;
143         }
144
145 }