1 package org.ldk.structs;
3 import org.ldk.impl.bindings;
4 import org.ldk.enums.*;
6 import java.util.Arrays;
7 import java.lang.ref.Reference;
8 import javax.annotation.Nullable;
12 * Similar to [`KeysManager`], but allows the node using this struct to receive phantom node
15 * A phantom node payment is a payment made to a phantom invoice, which is an invoice that can be
16 * paid to one of multiple nodes. This works because we encode the invoice route hints such that
17 * LDK will recognize an incoming payment as destined for a phantom node, and collect the payment
18 * itself without ever needing to forward to this fake node.
20 * Phantom node payments are useful for load balancing between multiple LDK nodes. They also
21 * provide some fault tolerance, because payers will automatically retry paying other provided
22 * nodes in the case that one node goes down.
24 * Note that multi-path payments are not supported in phantom invoices for security reasons.
25 * Switching between this struct and [`KeysManager`] will invalidate any previously issued
26 * invoices and attempts to pay previous invoices will fail.
28 @SuppressWarnings("unchecked") // We correctly assign various generic arrays
29 public class PhantomKeysManager extends CommonBase {
30 PhantomKeysManager(Object _dummy, long ptr) { super(ptr); }
31 @Override @SuppressWarnings("deprecation")
32 protected void finalize() throws Throwable {
34 if (ptr != 0) { bindings.PhantomKeysManager_free(ptr); }
38 * Constructs a new EntropySource which calls the relevant methods on this_arg.
39 * This copies the `inner` pointer in this_arg and thus the returned EntropySource must be freed before this_arg is
41 public EntropySource as_EntropySource() {
42 long ret = bindings.PhantomKeysManager_as_EntropySource(this.ptr);
43 Reference.reachabilityFence(this);
44 if (ret >= 0 && ret <= 4096) { return null; }
45 EntropySource ret_hu_conv = new EntropySource(null, ret);
46 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
51 * Constructs a new NodeSigner which calls the relevant methods on this_arg.
52 * This copies the `inner` pointer in this_arg and thus the returned NodeSigner must be freed before this_arg is
54 public NodeSigner as_NodeSigner() {
55 long ret = bindings.PhantomKeysManager_as_NodeSigner(this.ptr);
56 Reference.reachabilityFence(this);
57 if (ret >= 0 && ret <= 4096) { return null; }
58 NodeSigner ret_hu_conv = new NodeSigner(null, ret);
59 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
64 * Constructs a new SignerProvider which calls the relevant methods on this_arg.
65 * This copies the `inner` pointer in this_arg and thus the returned SignerProvider must be freed before this_arg is
67 public SignerProvider as_SignerProvider() {
68 long ret = bindings.PhantomKeysManager_as_SignerProvider(this.ptr);
69 Reference.reachabilityFence(this);
70 if (ret >= 0 && ret <= 4096) { return null; }
71 SignerProvider ret_hu_conv = new SignerProvider(null, ret);
72 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
77 * Constructs a [`PhantomKeysManager`] given a 32-byte seed and an additional `cross_node_seed`
78 * that is shared across all nodes that intend to participate in [phantom node payments]
81 * See [`KeysManager::new`] for more information on `seed`, `starting_time_secs`, and
82 * `starting_time_nanos`.
84 * `cross_node_seed` must be the same across all phantom payment-receiving nodes and also the
85 * same across restarts, or else inbound payments may fail.
87 * [phantom node payments]: PhantomKeysManager
89 public static PhantomKeysManager of(byte[] seed, long starting_time_secs, int starting_time_nanos, byte[] cross_node_seed) {
90 long ret = bindings.PhantomKeysManager_new(InternalUtils.check_arr_len(seed, 32), starting_time_secs, starting_time_nanos, InternalUtils.check_arr_len(cross_node_seed, 32));
91 Reference.reachabilityFence(seed);
92 Reference.reachabilityFence(starting_time_secs);
93 Reference.reachabilityFence(starting_time_nanos);
94 Reference.reachabilityFence(cross_node_seed);
95 if (ret >= 0 && ret <= 4096) { return null; }
96 org.ldk.structs.PhantomKeysManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PhantomKeysManager(null, ret); }
97 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); };
102 * See [`KeysManager::spend_spendable_outputs`] for documentation on this method.
104 public Result_TransactionNoneZ spend_spendable_outputs(SpendableOutputDescriptor[] descriptors, TxOut[] outputs, byte[] change_destination_script, int feerate_sat_per_1000_weight, org.ldk.structs.Option_PackedLockTimeZ locktime) {
105 long ret = bindings.PhantomKeysManager_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, locktime.ptr);
106 Reference.reachabilityFence(this);
107 Reference.reachabilityFence(descriptors);
108 Reference.reachabilityFence(outputs);
109 Reference.reachabilityFence(change_destination_script);
110 Reference.reachabilityFence(feerate_sat_per_1000_weight);
111 Reference.reachabilityFence(locktime);
112 if (ret >= 0 && ret <= 4096) { return null; }
113 Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret);
114 for (SpendableOutputDescriptor descriptors_conv_27: descriptors) { if (this != null) { this.ptrs_to.add(descriptors_conv_27); }; };
115 if (this != null) { this.ptrs_to.add(locktime); };
120 * See [`KeysManager::derive_channel_keys`] for documentation on this method.
122 public InMemorySigner derive_channel_keys(long channel_value_satoshis, byte[] params) {
123 long ret = bindings.PhantomKeysManager_derive_channel_keys(this.ptr, channel_value_satoshis, InternalUtils.check_arr_len(params, 32));
124 Reference.reachabilityFence(this);
125 Reference.reachabilityFence(channel_value_satoshis);
126 Reference.reachabilityFence(params);
127 if (ret >= 0 && ret <= 4096) { return null; }
128 org.ldk.structs.InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InMemorySigner(null, ret); }
129 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); };
134 * Gets the \"node_id\" secret key used to sign gossip announcements, decode onion data, etc.
136 public byte[] get_node_secret_key() {
137 byte[] ret = bindings.PhantomKeysManager_get_node_secret_key(this.ptr);
138 Reference.reachabilityFence(this);
143 * Gets the \"node_id\" secret key of the phantom node used to sign invoices, decode the
144 * last-hop onion data, etc.
146 public byte[] get_phantom_node_secret_key() {
147 byte[] ret = bindings.PhantomKeysManager_get_phantom_node_secret_key(this.ptr);
148 Reference.reachabilityFence(this);