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