CSharp: fix LDKStr array decoding
[ldk-java] / c_sharp / src / org / ldk / structs / Input.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  * An input that must be included in a transaction when performing coin selection through
11  * [`CoinSelectionSource::select_confirmed_utxos`]. It is guaranteed to be a SegWit input, so it
12  * must have an empty [`TxIn::script_sig`] when spent.
13  */
14 public class Input : CommonBase {
15         internal Input(object _dummy, long ptr) : base(ptr) { }
16         ~Input() {
17                 if (ptr != 0) { bindings.Input_free(ptr); }
18         }
19
20         /**
21          * The unique identifier of the input.
22          */
23         public OutPoint get_outpoint() {
24                 long ret = bindings.Input_get_outpoint(this.ptr);
25                 GC.KeepAlive(this);
26                 if (ret >= 0 && ret <= 4096) { return null; }
27                 org.ldk.structs.OutPoint ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OutPoint(null, ret); }
28                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
29                 return ret_hu_conv;
30         }
31
32         /**
33          * The unique identifier of the input.
34          */
35         public void set_outpoint(org.ldk.structs.OutPoint val) {
36                 bindings.Input_set_outpoint(this.ptr, val == null ? 0 : val.ptr);
37                 GC.KeepAlive(this);
38                 GC.KeepAlive(val);
39                 if (this != null) { this.ptrs_to.AddLast(val); };
40         }
41
42         /**
43          * The UTXO being spent by the input.
44          */
45         public TxOut get_previous_utxo() {
46                 long ret = bindings.Input_get_previous_utxo(this.ptr);
47                 GC.KeepAlive(this);
48                 if (ret >= 0 && ret <= 4096) { return null; }
49                 TxOut ret_conv = new TxOut(null, ret);
50                 return ret_conv;
51         }
52
53         /**
54          * The UTXO being spent by the input.
55          */
56         public void set_previous_utxo(org.ldk.structs.TxOut val) {
57                 bindings.Input_set_previous_utxo(this.ptr, val.ptr);
58                 GC.KeepAlive(this);
59                 GC.KeepAlive(val);
60         }
61
62         /**
63          * The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and
64          * [`TxIn::witness`], each with their lengths included, required to satisfy the output's
65          * script.
66          */
67         public long get_satisfaction_weight() {
68                 long ret = bindings.Input_get_satisfaction_weight(this.ptr);
69                 GC.KeepAlive(this);
70                 return ret;
71         }
72
73         /**
74          * The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and
75          * [`TxIn::witness`], each with their lengths included, required to satisfy the output's
76          * script.
77          */
78         public void set_satisfaction_weight(long val) {
79                 bindings.Input_set_satisfaction_weight(this.ptr, val);
80                 GC.KeepAlive(this);
81                 GC.KeepAlive(val);
82         }
83
84         /**
85          * Constructs a new Input given each field
86          */
87         public static Input of(org.ldk.structs.OutPoint outpoint_arg, org.ldk.structs.TxOut previous_utxo_arg, long satisfaction_weight_arg) {
88                 long ret = bindings.Input_new(outpoint_arg == null ? 0 : outpoint_arg.ptr, previous_utxo_arg.ptr, satisfaction_weight_arg);
89                 GC.KeepAlive(outpoint_arg);
90                 GC.KeepAlive(previous_utxo_arg);
91                 GC.KeepAlive(satisfaction_weight_arg);
92                 if (ret >= 0 && ret <= 4096) { return null; }
93                 org.ldk.structs.Input ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Input(null, ret); }
94                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
95                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(outpoint_arg); };
96                 return ret_hu_conv;
97         }
98
99         internal long clone_ptr() {
100                 long ret = bindings.Input_clone_ptr(this.ptr);
101                 GC.KeepAlive(this);
102                 return ret;
103         }
104
105         /**
106          * Creates a copy of the Input
107          */
108         public Input clone() {
109                 long ret = bindings.Input_clone(this.ptr);
110                 GC.KeepAlive(this);
111                 if (ret >= 0 && ret <= 4096) { return null; }
112                 org.ldk.structs.Input ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.Input(null, ret); }
113                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
114                 return ret_hu_conv;
115         }
116
117         /**
118          * Generates a non-cryptographic 64-bit hash of the Input.
119          */
120         public long hash() {
121                 long ret = bindings.Input_hash(this.ptr);
122                 GC.KeepAlive(this);
123                 return ret;
124         }
125
126         public override int GetHashCode() {
127                 return (int)this.hash();
128         }
129         /**
130          * Checks if two Inputs contain equal inner contents.
131          * This ignores pointers and is_owned flags and looks at the values in fields.
132          * Two objects with NULL inner values will be considered "equal" here.
133          */
134         public bool eq(org.ldk.structs.Input b) {
135                 bool ret = bindings.Input_eq(this.ptr, b == null ? 0 : b.ptr);
136                 GC.KeepAlive(this);
137                 GC.KeepAlive(b);
138                 if (this != null) { this.ptrs_to.AddLast(b); };
139                 return ret;
140         }
141
142         public override bool Equals(object o) {
143                 if (!(o is Input)) return false;
144                 return this.eq((Input)o);
145         }
146 }
147 } } }