[C#] Add marshaling logic for array C# -> C conversion
[ldk-java] / c_sharp / src / org / ldk / structs / Sign.cs
1 using org.ldk.impl;
2 using org.ldk.enums;
3 using org.ldk.util;
4 using System;
5
6 namespace org { namespace ldk { namespace structs {
7
8 /**
9  * A writeable signer.
10  * 
11  * There will always be two instances of a signer per channel, one occupied by the
12  * [`ChannelManager`] and another by the channel's [`ChannelMonitor`].
13  * 
14  * [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
15  * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
16  */
17 public class Sign : CommonBase {
18         internal readonly bindings.LDKSign bindings_instance;
19         internal Sign(object _dummy, long ptr) : base(ptr) { bindings_instance = null; }
20         private Sign(bindings.LDKSign arg, bindings.LDKBaseSign BaseSign, ChannelPublicKeys pubkeys) : base(bindings.LDKSign_new(arg, BaseSign, pubkeys == null ? 0 : pubkeys.clone_ptr())) {
21                 this.ptrs_to.AddLast(arg);
22                 this.ptrs_to.AddLast(BaseSign);
23                 this.bindings_instance = arg;
24         }
25         ~Sign() {
26                 if (ptr != 0) { bindings.Sign_free(ptr); }
27         }
28
29         public interface SignInterface {
30                 /**
31                  * Serialize the object into a byte array
32                  */
33                 byte[] write();
34         }
35         private class LDKSignHolder { internal Sign held; }
36         private class LDKSignImpl : bindings.LDKSign {
37                 internal LDKSignImpl(SignInterface arg, LDKSignHolder impl_holder) { this.arg = arg; this.impl_holder = impl_holder; }
38                 private SignInterface arg;
39                 private LDKSignHolder impl_holder;
40                 public byte[] write() {
41                         byte[] ret = arg.write();
42                                 GC.KeepAlive(arg);
43                         return ret;
44                 }
45         }
46         public static Sign new_impl(SignInterface arg, BaseSign.BaseSignInterface BaseSign_impl, ChannelPublicKeys pubkeys) {
47                 LDKSignHolder impl_holder = new LDKSignHolder();
48                 impl_holder.held = new Sign(new LDKSignImpl(arg, impl_holder), BaseSign.new_impl(BaseSign_impl, pubkeys).bindings_instance, pubkeys);
49                 return impl_holder.held;
50         }
51
52         /**
53          * Gets the underlying BaseSign.
54          */
55         public BaseSign get_base_sign() {
56                 BaseSign res = new BaseSign(null, bindings.LDKSign_get_BaseSign(this.ptr));
57                 this.ptrs_to.AddLast(res);
58                 return res;
59         }
60
61         /**
62          * Serialize the object into a byte array
63          */
64         public byte[] write() {
65                 byte[] ret = bindings.Sign_write(this.ptr);
66                 GC.KeepAlive(this);
67                 return ret;
68         }
69
70         internal long clone_ptr() {
71                 long ret = bindings.Sign_clone_ptr(this.ptr);
72                 GC.KeepAlive(this);
73                 return ret;
74         }
75
76         /**
77          * Creates a copy of a Sign
78          */
79         public Sign clone() {
80                 long ret = bindings.Sign_clone(this.ptr);
81                 GC.KeepAlive(this);
82                 if (ret >= 0 && ret <= 4096) { return null; }
83                 Sign ret_hu_conv = new Sign(null, ret);
84                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
85                 return ret_hu_conv;
86         }
87
88 }
89 } } }