Merge pull request #124 from TheBlueMatt/main
[ldk-java] / c_sharp / src / org / ldk / structs / HolderCommitmentTransaction.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  * Information needed to build and sign a holder's commitment transaction.
11  * 
12  * The transaction is only signed once we are ready to broadcast.
13  */
14 public class HolderCommitmentTransaction : CommonBase {
15         internal HolderCommitmentTransaction(object _dummy, long ptr) : base(ptr) { }
16         ~HolderCommitmentTransaction() {
17                 if (ptr != 0) { bindings.HolderCommitmentTransaction_free(ptr); }
18         }
19
20         /**
21          * Our counterparty's signature for the transaction
22          */
23         public byte[] get_counterparty_sig() {
24                 byte[] ret = bindings.HolderCommitmentTransaction_get_counterparty_sig(this.ptr);
25                 GC.KeepAlive(this);
26                 return ret;
27         }
28
29         /**
30          * Our counterparty's signature for the transaction
31          */
32         public void set_counterparty_sig(byte[] val) {
33                 bindings.HolderCommitmentTransaction_set_counterparty_sig(this.ptr, InternalUtils.check_arr_len(val, 64));
34                 GC.KeepAlive(this);
35                 GC.KeepAlive(val);
36         }
37
38         /**
39          * All non-dust counterparty HTLC signatures, in the order they appear in the transaction
40          * 
41          * Returns a copy of the field.
42          */
43         public byte[][] get_counterparty_htlc_sigs() {
44                 byte[][] ret = bindings.HolderCommitmentTransaction_get_counterparty_htlc_sigs(this.ptr);
45                 GC.KeepAlive(this);
46                 return ret;
47         }
48
49         /**
50          * All non-dust counterparty HTLC signatures, in the order they appear in the transaction
51          */
52         public void set_counterparty_htlc_sigs(byte[][] val) {
53                 bindings.HolderCommitmentTransaction_set_counterparty_htlc_sigs(this.ptr, val != null ? InternalUtils.mapArray(val, val_conv_8 => InternalUtils.check_arr_len(val_conv_8, 64)) : null);
54                 GC.KeepAlive(this);
55                 GC.KeepAlive(val);
56         }
57
58         internal long clone_ptr() {
59                 long ret = bindings.HolderCommitmentTransaction_clone_ptr(this.ptr);
60                 GC.KeepAlive(this);
61                 return ret;
62         }
63
64         /**
65          * Creates a copy of the HolderCommitmentTransaction
66          */
67         public HolderCommitmentTransaction clone() {
68                 long ret = bindings.HolderCommitmentTransaction_clone(this.ptr);
69                 GC.KeepAlive(this);
70                 if (ret >= 0 && ret <= 4096) { return null; }
71                 org.ldk.structs.HolderCommitmentTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.HolderCommitmentTransaction(null, ret); }
72                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
73                 return ret_hu_conv;
74         }
75
76         /**
77          * Serialize the HolderCommitmentTransaction object into a byte array which can be read by HolderCommitmentTransaction_read
78          */
79         public byte[] write() {
80                 byte[] ret = bindings.HolderCommitmentTransaction_write(this.ptr);
81                 GC.KeepAlive(this);
82                 return ret;
83         }
84
85         /**
86          * Read a HolderCommitmentTransaction from a byte array, created by HolderCommitmentTransaction_write
87          */
88         public static Result_HolderCommitmentTransactionDecodeErrorZ read(byte[] ser) {
89                 long ret = bindings.HolderCommitmentTransaction_read(ser);
90                 GC.KeepAlive(ser);
91                 if (ret >= 0 && ret <= 4096) { return null; }
92                 Result_HolderCommitmentTransactionDecodeErrorZ ret_hu_conv = Result_HolderCommitmentTransactionDecodeErrorZ.constr_from_ptr(ret);
93                 return ret_hu_conv;
94         }
95
96         /**
97          * Create a new holder transaction with the given counterparty signatures.
98          * The funding keys are used to figure out which signature should go first when building the transaction for broadcast.
99          */
100         public static HolderCommitmentTransaction of(org.ldk.structs.CommitmentTransaction commitment_tx, byte[] counterparty_sig, byte[][] counterparty_htlc_sigs, byte[] holder_funding_key, byte[] counterparty_funding_key) {
101                 long ret = bindings.HolderCommitmentTransaction_new(commitment_tx == null ? 0 : commitment_tx.ptr, InternalUtils.check_arr_len(counterparty_sig, 64), counterparty_htlc_sigs != null ? InternalUtils.mapArray(counterparty_htlc_sigs, counterparty_htlc_sigs_conv_8 => InternalUtils.check_arr_len(counterparty_htlc_sigs_conv_8, 64)) : null, InternalUtils.check_arr_len(holder_funding_key, 33), InternalUtils.check_arr_len(counterparty_funding_key, 33));
102                 GC.KeepAlive(commitment_tx);
103                 GC.KeepAlive(counterparty_sig);
104                 GC.KeepAlive(counterparty_htlc_sigs);
105                 GC.KeepAlive(holder_funding_key);
106                 GC.KeepAlive(counterparty_funding_key);
107                 if (ret >= 0 && ret <= 4096) { return null; }
108                 org.ldk.structs.HolderCommitmentTransaction ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.HolderCommitmentTransaction(null, ret); }
109                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
110                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(commitment_tx); };
111                 return ret_hu_conv;
112         }
113
114 }
115 } } }