[C#] Check in initial auto-generated C# bindings
[ldk-java] / c_sharp / src / org / ldk / structs / KeysManager.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  * Simple [`KeysInterface`] implementation that takes a 32-byte seed for use as a BIP 32 extended
11  * key and derives keys from that.
12  * 
13  * Your `node_id` is seed/0'.
14  * Unilateral closes may use seed/1'.
15  * Cooperative closes may use seed/2'.
16  * The two close keys may be needed to claim on-chain funds!
17  * 
18  * This struct cannot be used for nodes that wish to support receiving phantom payments;
19  * [`PhantomKeysManager`] must be used instead.
20  * 
21  * Note that switching between this struct and [`PhantomKeysManager`] will invalidate any
22  * previously issued invoices and attempts to pay previous invoices will fail.
23  */
24 public class KeysManager : CommonBase {
25         internal KeysManager(object _dummy, long ptr) : base(ptr) { }
26         ~KeysManager() {
27                 if (ptr != 0) { bindings.KeysManager_free(ptr); }
28         }
29
30         /**
31          * Constructs a [`KeysManager`] from a 32-byte seed. If the seed is in some way biased (e.g.,
32          * your CSRNG is busted) this may panic (but more importantly, you will possibly lose funds).
33          * `starting_time` isn't strictly required to actually be a time, but it must absolutely,
34          * without a doubt, be unique to this instance. ie if you start multiple times with the same
35          * `seed`, `starting_time` must be unique to each run. Thus, the easiest way to achieve this
36          * is to simply use the current time (with very high precision).
37          * 
38          * The `seed` MUST be backed up safely prior to use so that the keys can be re-created, however,
39          * obviously, `starting_time` should be unique every time you reload the library - it is only
40          * used to generate new ephemeral key data (which will be stored by the individual channel if
41          * necessary).
42          * 
43          * Note that the seed is required to recover certain on-chain funds independent of
44          * [`ChannelMonitor`] data, though a current copy of [`ChannelMonitor`] data is also required
45          * for any channel, and some on-chain during-closing funds.
46          * 
47          * [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
48          */
49         public static KeysManager of(byte[] seed, long starting_time_secs, int starting_time_nanos) {
50                 long ret = bindings.KeysManager_new(InternalUtils.check_arr_len(seed, 32), starting_time_secs, starting_time_nanos);
51                 GC.KeepAlive(seed);
52                 GC.KeepAlive(starting_time_secs);
53                 GC.KeepAlive(starting_time_nanos);
54                 if (ret >= 0 && ret <= 4096) { return null; }
55                 org.ldk.structs.KeysManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.KeysManager(null, ret); }
56                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
57                 return ret_hu_conv;
58         }
59
60         /**
61          * Derive an old [`Sign`] containing per-channel secrets based on a key derivation parameters.
62          */
63         public InMemorySigner derive_channel_keys(long channel_value_satoshis, byte[] _params) {
64                 long ret = bindings.KeysManager_derive_channel_keys(this.ptr, channel_value_satoshis, InternalUtils.check_arr_len(_params, 32));
65                 GC.KeepAlive(this);
66                 GC.KeepAlive(channel_value_satoshis);
67                 GC.KeepAlive(_params);
68                 if (ret >= 0 && ret <= 4096) { return null; }
69                 org.ldk.structs.InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InMemorySigner(null, ret); }
70                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
71                 return ret_hu_conv;
72         }
73
74         /**
75          * Creates a [`Transaction`] which spends the given descriptors to the given outputs, plus an
76          * output to the given change destination (if sufficient change value remains). The
77          * transaction will have a feerate, at least, of the given value.
78          * 
79          * Returns `Err(())` if the output value is greater than the input value minus required fee,
80          * if a descriptor was duplicated, or if an output descriptor `script_pubkey`
81          * does not match the one we can spend.
82          * 
83          * We do not enforce that outputs meet the dust limit or that any output scripts are standard.
84          * 
85          * May panic if the [`SpendableOutputDescriptor`]s were not generated by channels which used
86          * this [`KeysManager`] or one of the [`InMemorySigner`] created by this [`KeysManager`].
87          */
88         public Result_TransactionNoneZ spend_spendable_outputs(SpendableOutputDescriptor[] descriptors, TxOut[] outputs, byte[] change_destination_script, int feerate_sat_per_1000_weight) {
89                 long ret = bindings.KeysManager_spend_spendable_outputs(this.ptr, descriptors != null ? InternalUtils.mapArray(descriptors, descriptors_conv_27 => descriptors_conv_27.ptr) : null, outputs != null ? InternalUtils.mapArray(outputs, outputs_conv_7 => outputs_conv_7.ptr) : null, change_destination_script, feerate_sat_per_1000_weight);
90                 GC.KeepAlive(this);
91                 GC.KeepAlive(descriptors);
92                 GC.KeepAlive(outputs);
93                 GC.KeepAlive(change_destination_script);
94                 GC.KeepAlive(feerate_sat_per_1000_weight);
95                 if (ret >= 0 && ret <= 4096) { return null; }
96                 Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret);
97                 return ret_hu_conv;
98         }
99
100         /**
101          * Constructs a new KeysInterface which calls the relevant methods on this_arg.
102          * This copies the `inner` pointer in this_arg and thus the returned KeysInterface must be freed before this_arg is
103          */
104         public KeysInterface as_KeysInterface() {
105                 long ret = bindings.KeysManager_as_KeysInterface(this.ptr);
106                 GC.KeepAlive(this);
107                 if (ret >= 0 && ret <= 4096) { return null; }
108                 KeysInterface ret_hu_conv = new KeysInterface(null, ret);
109                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
110                 return ret_hu_conv;
111         }
112
113 }
114 } } }