X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FKeysManager.java;h=d92016a7adc00ffedda263a53974efb7fd1d9bd6;hb=5e9de82b3a7712a41189756d9d16d946142b2ac5;hp=047ef055167644be5b4595610ade39b7a93a4756;hpb=b0c50b891cbca28d3bd1d86276c132ff5221d8e4;p=ldk-java diff --git a/src/main/java/org/ldk/structs/KeysManager.java b/src/main/java/org/ldk/structs/KeysManager.java index 047ef055..d92016a7 100644 --- a/src/main/java/org/ldk/structs/KeysManager.java +++ b/src/main/java/org/ldk/structs/KeysManager.java @@ -4,6 +4,8 @@ import org.ldk.impl.bindings; import org.ldk.enums.*; import org.ldk.util.*; import java.util.Arrays; +import java.lang.ref.Reference; +import javax.annotation.Nullable; /** @@ -14,6 +16,12 @@ import java.util.Arrays; * ChannelMonitor closes may use seed/1' * Cooperative closes may use seed/2' * The two close keys may be needed to claim on-chain funds! + * + * This struct cannot be used for nodes that wish to support receiving phantom payments; + * [`PhantomKeysManager`] must be used instead. + * + * Note that switching between this struct and [`PhantomKeysManager`] will invalidate any + * previously issued invoices and attempts to pay previous invoices will fail. */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class KeysManager extends CommonBase { @@ -46,9 +54,13 @@ public class KeysManager extends CommonBase { * detailed description of the guarantee. */ public static KeysManager of(byte[] seed, long starting_time_secs, int starting_time_nanos) { - long ret = bindings.KeysManager_new(seed, starting_time_secs, starting_time_nanos); - KeysManager ret_hu_conv = new KeysManager(null, ret); - ret_hu_conv.ptrs_to.add(ret_hu_conv); + long ret = bindings.KeysManager_new(InternalUtils.check_arr_len(seed, 32), starting_time_secs, starting_time_nanos); + Reference.reachabilityFence(seed); + Reference.reachabilityFence(starting_time_secs); + Reference.reachabilityFence(starting_time_nanos); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.KeysManager ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.KeysManager(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; return ret_hu_conv; } @@ -60,9 +72,13 @@ public class KeysManager extends CommonBase { * onchain output detection for which a corresponding delayed_payment_key must be derived. */ public InMemorySigner derive_channel_keys(long channel_value_satoshis, byte[] params) { - long ret = bindings.KeysManager_derive_channel_keys(this.ptr, channel_value_satoshis, params); - InMemorySigner ret_hu_conv = new InMemorySigner(null, ret); - ret_hu_conv.ptrs_to.add(this); + long ret = bindings.KeysManager_derive_channel_keys(this.ptr, channel_value_satoshis, InternalUtils.check_arr_len(params, 32)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(channel_value_satoshis); + Reference.reachabilityFence(params); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.InMemorySigner ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.InMemorySigner(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } @@ -71,8 +87,9 @@ public class KeysManager extends CommonBase { * output to the given change destination (if sufficient change value remains). The * transaction will have a feerate, at least, of the given value. * - * Returns `Err(())` if the output value is greater than the input value minus required fee or - * if a descriptor was duplicated. + * Returns `Err(())` if the output value is greater than the input value minus required fee, + * if a descriptor was duplicated, or if an output descriptor `script_pubkey` + * does not match the one we can spend. * * We do not enforce that outputs meet the dust limit or that any output scripts are standard. * @@ -80,10 +97,14 @@ public class KeysManager extends CommonBase { * this KeysManager or one of the `InMemorySigner` created by this KeysManager. */ public Result_TransactionNoneZ spend_spendable_outputs(SpendableOutputDescriptor[] descriptors, TxOut[] outputs, byte[] change_destination_script, int feerate_sat_per_1000_weight) { - 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); + 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); + Reference.reachabilityFence(this); + Reference.reachabilityFence(descriptors); + Reference.reachabilityFence(outputs); + Reference.reachabilityFence(change_destination_script); + Reference.reachabilityFence(feerate_sat_per_1000_weight); + if (ret >= 0 && ret <= 4096) { return null; } Result_TransactionNoneZ ret_hu_conv = Result_TransactionNoneZ.constr_from_ptr(ret); - /* TODO 2 SpendableOutputDescriptor */; - /* TODO 2 TxOut */; return ret_hu_conv; } @@ -93,8 +114,10 @@ public class KeysManager extends CommonBase { */ public KeysInterface as_KeysInterface() { long ret = bindings.KeysManager_as_KeysInterface(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } KeysInterface ret_hu_conv = new KeysInterface(null, ret); - ret_hu_conv.ptrs_to.add(this); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; }