aea1d41e32fa9b304a21e3f3df0fb951d6a064e8
[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 cloneable signer.
12  * 
13  * Although we require signers to be cloneable, it may be useful for developers to be able to use
14  * signers in an un-sized way, for example as `dyn BaseSign`. Therefore we separate the Clone trait,
15  * which implies Sized, into this derived trait.
16  */
17 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
18 public class Sign extends CommonBase {
19         final bindings.LDKSign bindings_instance;
20         Sign(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
21         private Sign(bindings.LDKSign arg, bindings.LDKBaseSign BaseSign, ChannelPublicKeys pubkeys) {
22                 super(bindings.LDKSign_new(arg, BaseSign, pubkeys == null ? 0 : pubkeys.clone_ptr()));
23                 this.ptrs_to.add(arg);
24                 this.ptrs_to.add(BaseSign);
25                 this.bindings_instance = arg;
26         }
27         @Override @SuppressWarnings("deprecation")
28         protected void finalize() throws Throwable {
29                 if (ptr != 0) { bindings.Sign_free(ptr); } super.finalize();
30         }
31
32         public static interface SignInterface {
33                 /**
34                  * Serialize the object into a byte array
35                  */
36                 byte[] write();
37         }
38         private static class LDKSignHolder { Sign held; }
39         public static Sign new_impl(SignInterface arg, BaseSign.BaseSignInterface BaseSign_impl, ChannelPublicKeys pubkeys) {
40                 final LDKSignHolder impl_holder = new LDKSignHolder();
41                 impl_holder.held = new Sign(new bindings.LDKSign() {
42                         @Override public byte[] write() {
43                                 byte[] ret = arg.write();
44                                 return ret;
45                         }
46                 }, BaseSign.new_impl(BaseSign_impl, pubkeys).bindings_instance, pubkeys);
47                 return impl_holder.held;
48         }
49
50         /**
51          * Gets the underlying BaseSign.
52          */
53         public BaseSign get_base_sign() {
54                 BaseSign res = new BaseSign(null, bindings.LDKSign_get_BaseSign(this.ptr));
55                 this.ptrs_to.add(res);
56                 return res;
57         }
58
59         /**
60          * Serialize the object into a byte array
61          */
62         public byte[] write() {
63                 byte[] ret = bindings.Sign_write(this.ptr);
64                 Reference.reachabilityFence(this);
65                 return ret;
66         }
67
68         long clone_ptr() {
69                 long ret = bindings.Sign_clone_ptr(this.ptr);
70                 Reference.reachabilityFence(this);
71                 return ret;
72         }
73
74         /**
75          * Creates a copy of a Sign
76          */
77         public Sign clone() {
78                 long ret = bindings.Sign_clone(this.ptr);
79                 Reference.reachabilityFence(this);
80                 if (ret >= 0 && ret <= 4096) { return null; }
81                 Sign ret_hu_conv = new Sign(null, ret);
82                 ret_hu_conv.ptrs_to.add(this);
83                 return ret_hu_conv;
84         }
85
86 }