246b5de48f7eaaff1d868f76180ddab2fdb7fd7d
[ldk-java] / c_sharp / src / org / ldk / structs / PhantomKeysManager.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  * Similar to [`KeysManager`], but allows the node using this struct to receive phantom node
11  * payments.
12  * 
13  * A phantom node payment is a payment made to a phantom invoice, which is an invoice that can be
14  * paid to one of multiple nodes. This works because we encode the invoice route hints such that
15  * LDK will recognize an incoming payment as destined for a phantom node, and collect the payment
16  * itself without ever needing to forward to this fake node.
17  * 
18  * Phantom node payments are useful for load balancing between multiple LDK nodes. They also
19  * provide some fault tolerance, because payers will automatically retry paying other provided
20  * nodes in the case that one node goes down.
21  * 
22  * Note that multi-path payments are not supported in phantom invoices for security reasons.
23  * Switching between this struct and [`KeysManager`] will invalidate any previously issued
24  * invoices and attempts to pay previous invoices will fail.
25  */
26 public class PhantomKeysManager : CommonBase {
27         internal PhantomKeysManager(object _dummy, long ptr) : base(ptr) { }
28         ~PhantomKeysManager() {
29                 if (ptr != 0) { bindings.PhantomKeysManager_free(ptr); }
30         }
31
32         /**
33          * Constructs a new KeysInterface which calls the relevant methods on this_arg.
34          * This copies the `inner` pointer in this_arg and thus the returned KeysInterface must be freed before this_arg is
35          */
36         public KeysInterface as_KeysInterface() {
37                 long ret = bindings.PhantomKeysManager_as_KeysInterface(this.ptr);
38                 GC.KeepAlive(this);
39                 if (ret >= 0 && ret <= 4096) { return null; }
40                 KeysInterface ret_hu_conv = new KeysInterface(null, ret);
41                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
42                 return ret_hu_conv;
43         }
44
45         /**
46          * Constructs a [`PhantomKeysManager`] given a 32-byte seed and an additional `cross_node_seed`
47          * that is shared across all nodes that intend to participate in [phantom node payments]
48          * together.
49          * 
50          * See [`KeysManager::new`] for more information on `seed`, `starting_time_secs`, and
51          * `starting_time_nanos`.
52          * 
53          * `cross_node_seed` must be the same across all phantom payment-receiving nodes and also the
54          * same across restarts, or else inbound payments may fail.
55          * 
56          * [phantom node payments]: PhantomKeysManager
57          */
58         public static PhantomKeysManager of(byte[] seed, long starting_time_secs, int starting_time_nanos, byte[] cross_node_seed) {
59                 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));
60                 GC.KeepAlive(seed);
61                 GC.KeepAlive(starting_time_secs);
62                 GC.KeepAlive(starting_time_nanos);
63                 GC.KeepAlive(cross_node_seed);
64                 if (ret >= 0 && ret <= 4096) { return null; }
65                 org.ldk.structs.PhantomKeysManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.PhantomKeysManager(null, ret); }
66                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(ret_hu_conv); };
67                 return ret_hu_conv;
68         }
69
70         /**
71          * See [`KeysManager::spend_spendable_outputs`] for documentation on this method.
72          */
73         public Result_TransactionNoneZ spend_spendable_outputs(SpendableOutputDescriptor[] descriptors, TxOut[] outputs, byte[] change_destination_script, int feerate_sat_per_1000_weight) {
74                 long ret = bindings.PhantomKeysManager_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);
75                 GC.KeepAlive(this);
76                 GC.KeepAlive(descriptors);
77                 GC.KeepAlive(outputs);
78                 GC.KeepAlive(change_destination_script);
79                 GC.KeepAlive(feerate_sat_per_1000_weight);
80                 if (ret >= 0 && ret <= 4096) { return null; }
81                 Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret);
82                 return ret_hu_conv;
83         }
84
85         /**
86          * See [`KeysManager::derive_channel_keys`] for documentation on this method.
87          */
88         public InMemorySigner derive_channel_keys(long channel_value_satoshis, byte[] _params) {
89                 long ret = bindings.PhantomKeysManager_derive_channel_keys(this.ptr, channel_value_satoshis, InternalUtils.check_arr_len(_params, 32));
90                 GC.KeepAlive(this);
91                 GC.KeepAlive(channel_value_satoshis);
92                 GC.KeepAlive(_params);
93                 if (ret >= 0 && ret <= 4096) { return null; }
94                 org.ldk.structs.InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InMemorySigner(null, ret); }
95                 if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.AddLast(this); };
96                 return ret_hu_conv;
97         }
98
99 }
100 } } }