c34c454317eecb39c5b95662090539f6b582953a
[ldk-java] / c_sharp / src / org / ldk / structs / CommitmentTransaction.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 /**
10  * This class tracks the per-transaction information needed to build a commitment transaction and will
11  * actually build it and sign.  It is used for holder transactions that we sign only when needed
12  * and for transactions we sign for the counterparty.
13  * 
14  * This class can be used inside a signer implementation to generate a signature given the relevant
15  * secret key.
16  */
17 public class CommitmentTransaction : CommonBase {
18         internal CommitmentTransaction(object _dummy, long ptr) : base(ptr) { }
19         ~CommitmentTransaction() {
20                 if (ptr != 0) { bindings.CommitmentTransaction_free(ptr); }
21         }
22
23         internal long clone_ptr() {
24                 long ret = bindings.CommitmentTransaction_clone_ptr(this.ptr);
25                 GC.KeepAlive(this);
26                 return ret;
27         }
28
29         /**
30          * Creates a copy of the CommitmentTransaction
31          */
32         public CommitmentTransaction clone() {
33                 long ret = bindings.CommitmentTransaction_clone(this.ptr);
34                 GC.KeepAlive(this);
35                 if (ret >= 0 && ret <= 4096) { return null; }
36                 org.ldk.structs.CommitmentTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.CommitmentTransaction(null, ret); }
37                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
38                 return ret_hu_conv;
39         }
40
41         /**
42          * Serialize the CommitmentTransaction object into a byte array which can be read by CommitmentTransaction_read
43          */
44         public byte[] write() {
45                 byte[] ret = bindings.CommitmentTransaction_write(this.ptr);
46                 GC.KeepAlive(this);
47                 return ret;
48         }
49
50         /**
51          * Read a CommitmentTransaction from a byte array, created by CommitmentTransaction_write
52          */
53         public static Result_CommitmentTransactionDecodeErrorZ read(byte[] ser) {
54                 long ret = bindings.CommitmentTransaction_read(ser);
55                 GC.KeepAlive(ser);
56                 if (ret >= 0 && ret <= 4096) { return null; }
57                 Result_CommitmentTransactionDecodeErrorZ ret_hu_conv = Result_CommitmentTransactionDecodeErrorZ.constr_from_ptr(ret);
58                 return ret_hu_conv;
59         }
60
61         /**
62          * The backwards-counting commitment number
63          */
64         public long commitment_number() {
65                 long ret = bindings.CommitmentTransaction_commitment_number(this.ptr);
66                 GC.KeepAlive(this);
67                 return ret;
68         }
69
70         /**
71          * The value to be sent to the broadcaster
72          */
73         public long to_broadcaster_value_sat() {
74                 long ret = bindings.CommitmentTransaction_to_broadcaster_value_sat(this.ptr);
75                 GC.KeepAlive(this);
76                 return ret;
77         }
78
79         /**
80          * The value to be sent to the counterparty
81          */
82         public long to_countersignatory_value_sat() {
83                 long ret = bindings.CommitmentTransaction_to_countersignatory_value_sat(this.ptr);
84                 GC.KeepAlive(this);
85                 return ret;
86         }
87
88         /**
89          * The feerate paid per 1000-weight-unit in this commitment transaction.
90          */
91         public int feerate_per_kw() {
92                 int ret = bindings.CommitmentTransaction_feerate_per_kw(this.ptr);
93                 GC.KeepAlive(this);
94                 return ret;
95         }
96
97         /**
98          * Trust our pre-built transaction and derived transaction creation public keys.
99          * 
100          * Applies a wrapper which allows access to these fields.
101          * 
102          * This should only be used if you fully trust the builder of this object.  It should not
103          * be used by an external signer - instead use the verify function.
104          */
105         public TrustedCommitmentTransaction trust() {
106                 long ret = bindings.CommitmentTransaction_trust(this.ptr);
107                 GC.KeepAlive(this);
108                 if (ret >= 0 && ret <= 4096) { return null; }
109                 org.ldk.structs.TrustedCommitmentTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.TrustedCommitmentTransaction(null, ret); }
110                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
111                 return ret_hu_conv;
112         }
113
114         /**
115          * Verify our pre-built transaction and derived transaction creation public keys.
116          * 
117          * Applies a wrapper which allows access to these fields.
118          * 
119          * An external validating signer must call this method before signing
120          * or using the built transaction.
121          */
122         public Result_TrustedCommitmentTransactionNoneZ verify(org.ldk.structs.DirectedChannelTransactionParameters channel_parameters, org.ldk.structs.ChannelPublicKeys broadcaster_keys, org.ldk.structs.ChannelPublicKeys countersignatory_keys) {
123                 long ret = bindings.CommitmentTransaction_verify(this.ptr, channel_parameters == null ? 0 : channel_parameters.ptr, broadcaster_keys == null ? 0 : broadcaster_keys.ptr, countersignatory_keys == null ? 0 : countersignatory_keys.ptr);
124                 GC.KeepAlive(this);
125                 GC.KeepAlive(channel_parameters);
126                 GC.KeepAlive(broadcaster_keys);
127                 GC.KeepAlive(countersignatory_keys);
128                 if (ret >= 0 && ret <= 4096) { return null; }
129                 Result_TrustedCommitmentTransactionNoneZ ret_hu_conv = Result_TrustedCommitmentTransactionNoneZ.constr_from_ptr(ret);
130                 if (this != null) { this.ptrs_to.AddLast(channel_parameters); };
131                 if (this != null) { this.ptrs_to.AddLast(broadcaster_keys); };
132                 if (this != null) { this.ptrs_to.AddLast(countersignatory_keys); };
133                 return ret_hu_conv;
134         }
135
136 }
137 } } }