Merge pull request #33 from TheBlueMatt/main
[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 javax.annotation.Nullable;
8
9 /**
10  * A cloneable signer.
11  * 
12  * Although we require signers to be cloneable, it may be useful for developers to be able to use
13  * signers in an un-sized way, for example as `dyn BaseSign`. Therefore we separate the Clone trait,
14  * which implies Sized, into this derived trait.
15  */
16 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
17 public class Sign extends CommonBase {
18         final bindings.LDKSign bindings_instance;
19         Sign(Object _dummy, long ptr) { super(ptr); bindings_instance = null; }
20         private Sign(bindings.LDKSign arg, bindings.LDKBaseSign BaseSign, ChannelPublicKeys pubkeys) {
21                 super(bindings.LDKSign_new(arg, BaseSign, pubkeys == null ? 0 : pubkeys.ptr & ~1));
22                 this.ptrs_to.add(arg);
23                 this.ptrs_to.add(BaseSign);
24                 this.ptrs_to.add(pubkeys);
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                 return ret;
65         }
66
67         /**
68          * Creates a copy of a Sign
69          */
70         public Sign clone() {
71                 long ret = bindings.Sign_clone(this.ptr);
72                 if (ret < 1024) { return null; }
73                 Sign ret_hu_conv = new Sign(null, ret);
74                 ret_hu_conv.ptrs_to.add(this);
75                 return ret_hu_conv;
76         }
77
78 }