b68379f982c2e6c7ea08471a4d52f08d8f97ddc9
[ldk-java] / src / main / java / org / ldk / structs / Sign.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  * A writeable signer.
12  * 
13  * There will always be two instances of a signer per channel, one occupied by the
14  * [`ChannelManager`] and another by the channel's [`ChannelMonitor`].
15  * 
16  * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
17  * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
18  */
19 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
20 public class Sign extends CommonBase {
21         final bindings.LDKSign bindings_instance;
22         Sign(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
23         private Sign(bindings.LDKSign arg, bindings.LDKBaseSign BaseSign, ChannelPublicKeys pubkeys) {
24                 super(bindings.LDKSign_new(arg, BaseSign, pubkeys == null ? 0 : pubkeys.clone_ptr()));
25                 this.ptrs_to.add(arg);
26                 this.ptrs_to.add(BaseSign);
27                 this.bindings_instance = arg;
28         }
29         @Override @SuppressWarnings("deprecation")
30         protected void finalize() throws Throwable {
31                 if (ptr != 0) { bindings.Sign_free(ptr); } super.finalize();
32         }
33
34         public static interface SignInterface {
35                 /**
36                  * Serialize the object into a byte array
37                  */
38                 byte[] write();
39         }
40         private static class LDKSignHolder { Sign held; }
41         public static Sign new_impl(SignInterface arg, BaseSign.BaseSignInterface BaseSign_impl, ChannelPublicKeys pubkeys) {
42                 final LDKSignHolder impl_holder = new LDKSignHolder();
43                 impl_holder.held = new Sign(new bindings.LDKSign() {
44                         @Override public byte[] write() {
45                                 byte[] ret = arg.write();
46                                 Reference.reachabilityFence(arg);
47                                 return ret;
48                         }
49                 }, BaseSign.new_impl(BaseSign_impl, pubkeys).bindings_instance, pubkeys);
50                 return impl_holder.held;
51         }
52
53         /**
54          * Gets the underlying BaseSign.
55          */
56         public BaseSign get_base_sign() {
57                 BaseSign res = new BaseSign(null, bindings.LDKSign_get_BaseSign(this.ptr));
58                 this.ptrs_to.add(res);
59                 return res;
60         }
61
62         /**
63          * Serialize the object into a byte array
64          */
65         public byte[] write() {
66                 byte[] ret = bindings.Sign_write(this.ptr);
67                 Reference.reachabilityFence(this);
68                 return ret;
69         }
70
71         long clone_ptr() {
72                 long ret = bindings.Sign_clone_ptr(this.ptr);
73                 Reference.reachabilityFence(this);
74                 return ret;
75         }
76
77         /**
78          * Creates a copy of a Sign
79          */
80         public Sign clone() {
81                 long ret = bindings.Sign_clone(this.ptr);
82                 Reference.reachabilityFence(this);
83                 if (ret >= 0 && ret <= 4096) { return null; }
84                 Sign ret_hu_conv = new Sign(null, ret);
85                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
86                 return ret_hu_conv;
87         }
88
89 }