[Java] Update auto-generated bindings to 0.0.105.0
[ldk-java] / src / main / java / org / ldk / structs / KeysManager.java
1 package org.ldk.structs;
2
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
5 import org.ldk.util.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
9
10
11 /**
12  * Simple KeysInterface implementor that takes a 32-byte seed for use as a BIP 32 extended key
13  * and derives keys from that.
14  * 
15  * Your node_id is seed/0'
16  * ChannelMonitor closes may use seed/1'
17  * Cooperative closes may use seed/2'
18  * The two close keys may be needed to claim on-chain funds!
19  * 
20  * This struct cannot be used for nodes that wish to support receiving phantom payments;
21  * [`PhantomKeysManager`] must be used instead.
22  * 
23  * Note that switching between this struct and [`PhantomKeysManager`] will invalidate any
24  * previously issued invoices and attempts to pay previous invoices will fail.
25  */
26 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
27 public class KeysManager extends CommonBase {
28         KeysManager(Object _dummy, long ptr) { super(ptr); }
29         @Override @SuppressWarnings("deprecation")
30         protected void finalize() throws Throwable {
31                 super.finalize();
32                 if (ptr != 0) { bindings.KeysManager_free(ptr); }
33         }
34
35         /**
36          * Constructs a KeysManager from a 32-byte seed. If the seed is in some way biased (eg your
37          * CSRNG is busted) this may panic (but more importantly, you will possibly lose funds).
38          * starting_time isn't strictly required to actually be a time, but it must absolutely,
39          * without a doubt, be unique to this instance. ie if you start multiple times with the same
40          * seed, starting_time must be unique to each run. Thus, the easiest way to achieve this is to
41          * simply use the current time (with very high precision).
42          * 
43          * The seed MUST be backed up safely prior to use so that the keys can be re-created, however,
44          * obviously, starting_time should be unique every time you reload the library - it is only
45          * used to generate new ephemeral key data (which will be stored by the individual channel if
46          * necessary).
47          * 
48          * Note that the seed is required to recover certain on-chain funds independent of
49          * ChannelMonitor data, though a current copy of ChannelMonitor data is also required for any
50          * channel, and some on-chain during-closing funds.
51          * 
52          * Note that until the 0.1 release there is no guarantee of backward compatibility between
53          * versions. Once the library is more fully supported, the docs will be updated to include a
54          * detailed description of the guarantee.
55          */
56         public static KeysManager of(byte[] seed, long starting_time_secs, int starting_time_nanos) {
57                 long ret = bindings.KeysManager_new(InternalUtils.check_arr_len(seed, 32), starting_time_secs, starting_time_nanos);
58                 Reference.reachabilityFence(seed);
59                 Reference.reachabilityFence(starting_time_secs);
60                 Reference.reachabilityFence(starting_time_nanos);
61                 if (ret >= 0 && ret <= 4096) { return null; }
62                 KeysManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new KeysManager(null, ret); }
63                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
64                 return ret_hu_conv;
65         }
66
67         /**
68          * Derive an old Sign containing per-channel secrets based on a key derivation parameters.
69          * 
70          * Key derivation parameters are accessible through a per-channel secrets
71          * Sign::channel_keys_id and is provided inside DynamicOuputP2WSH in case of
72          * onchain output detection for which a corresponding delayed_payment_key must be derived.
73          */
74         public InMemorySigner derive_channel_keys(long channel_value_satoshis, byte[] params) {
75                 long ret = bindings.KeysManager_derive_channel_keys(this.ptr, channel_value_satoshis, InternalUtils.check_arr_len(params, 32));
76                 Reference.reachabilityFence(this);
77                 Reference.reachabilityFence(channel_value_satoshis);
78                 Reference.reachabilityFence(params);
79                 if (ret >= 0 && ret <= 4096) { return null; }
80                 InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new InMemorySigner(null, ret); }
81                 ret_hu_conv.ptrs_to.add(this);
82                 return ret_hu_conv;
83         }
84
85         /**
86          * Creates a Transaction which spends the given descriptors to the given outputs, plus an
87          * output to the given change destination (if sufficient change value remains). The
88          * transaction will have a feerate, at least, of the given value.
89          * 
90          * Returns `Err(())` if the output value is greater than the input value minus required fee,
91          * if a descriptor was duplicated, or if an output descriptor `script_pubkey`
92          * does not match the one we can spend.
93          * 
94          * We do not enforce that outputs meet the dust limit or that any output scripts are standard.
95          * 
96          * May panic if the `SpendableOutputDescriptor`s were not generated by Channels which used
97          * this KeysManager or one of the `InMemorySigner` created by this KeysManager.
98          */
99         public Result_TransactionNoneZ spend_spendable_outputs(SpendableOutputDescriptor[] descriptors, TxOut[] outputs, byte[] change_destination_script, int feerate_sat_per_1000_weight) {
100                 long ret = bindings.KeysManager_spend_spendable_outputs(this.ptr, descriptors != null ? Arrays.stream(descriptors).mapToLong(descriptors_conv_27 -> descriptors_conv_27.ptr).toArray() : null, outputs != null ? Arrays.stream(outputs).mapToLong(outputs_conv_7 -> outputs_conv_7.ptr).toArray() : null, change_destination_script, feerate_sat_per_1000_weight);
101                 Reference.reachabilityFence(this);
102                 Reference.reachabilityFence(descriptors);
103                 Reference.reachabilityFence(outputs);
104                 Reference.reachabilityFence(change_destination_script);
105                 Reference.reachabilityFence(feerate_sat_per_1000_weight);
106                 if (ret >= 0 && ret <= 4096) { return null; }
107                 Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret);
108                 return ret_hu_conv;
109         }
110
111         /**
112          * Constructs a new KeysInterface which calls the relevant methods on this_arg.
113          * This copies the `inner` pointer in this_arg and thus the returned KeysInterface must be freed before this_arg is
114          */
115         public KeysInterface as_KeysInterface() {
116                 long ret = bindings.KeysManager_as_KeysInterface(this.ptr);
117                 Reference.reachabilityFence(this);
118                 if (ret >= 0 && ret <= 4096) { return null; }
119                 KeysInterface ret_hu_conv = new KeysInterface(null, ret);
120                 ret_hu_conv.ptrs_to.add(this);
121                 return ret_hu_conv;
122         }
123
124 }