X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FChannelConfig.java;h=7f5f6d2e63bd1e8e469b6d850fa2c0d927bdf3ac;hb=f8c25e52ce878136043ddc4dbfac6c6640f1d4f6;hp=7676cae3051952892f79503781f7c101a6818565;hpb=2ed9081562d00a8645604b07629e963231d49e0f;p=ldk-java diff --git a/src/main/java/org/ldk/structs/ChannelConfig.java b/src/main/java/org/ldk/structs/ChannelConfig.java index 7676cae3..7f5f6d2e 100644 --- a/src/main/java/org/ldk/structs/ChannelConfig.java +++ b/src/main/java/org/ldk/structs/ChannelConfig.java @@ -2,63 +2,212 @@ package org.ldk.structs; import org.ldk.impl.bindings; import org.ldk.enums.*; +import org.ldk.util.*; +import java.util.Arrays; + +/** + * Options which apply on a per-channel basis and may change at runtime or based on negotiation + * with our counterparty. + */ +@SuppressWarnings("unchecked") // We correctly assign various generic arrays public class ChannelConfig extends CommonBase { ChannelConfig(Object _dummy, long ptr) { super(ptr); } @Override @SuppressWarnings("deprecation") protected void finalize() throws Throwable { - bindings.ChannelConfig_free(ptr); super.finalize(); + super.finalize(); + if (ptr != 0) { bindings.ChannelConfig_free(ptr); } } - public ChannelConfig(ChannelConfig orig) { - super(bindings.ChannelConfig_clone(orig == null ? 0 : orig.ptr & ~1)); - this.ptrs_to.add(orig); + /** + * Amount (in millionths of a satoshi) the channel will charge per transferred satoshi. + * This may be allowed to change at runtime in a later update, however doing so must result in + * update messages sent to notify all nodes of our updated relay fee. + * + * Default value: 0. + */ + public int get_fee_proportional_millionths() { + int ret = bindings.ChannelConfig_get_fee_proportional_millionths(this.ptr); + return ret; } - public int get_fee_proportional_millionths(ChannelConfig this_ptr) { - int ret = bindings.ChannelConfig_get_fee_proportional_millionths(this_ptr == null ? 0 : this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); + /** + * Amount (in millionths of a satoshi) the channel will charge per transferred satoshi. + * This may be allowed to change at runtime in a later update, however doing so must result in + * update messages sent to notify all nodes of our updated relay fee. + * + * Default value: 0. + */ + public void set_fee_proportional_millionths(int val) { + bindings.ChannelConfig_set_fee_proportional_millionths(this.ptr, val); + } + + /** + * The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over + * the channel this config applies to. + * + * This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight + * HTLC balance when a channel appears on-chain whereas + * [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining + * (non-HTLC-encumbered) balance. + * + * Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed, + * we (or one of our watchtowers) MUST be online to check for broadcast of the current + * commitment transaction at least once per this many blocks (minus some margin to allow us + * enough time to broadcast and confirm a transaction, possibly with time in between to RBF + * the spending transaction). + * + * Default value: 72 (12 hours at an average of 6 blocks/hour). + * Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as + * [`MIN_CLTV_EXPIRY_DELTA`] instead. + * + * [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA + */ + public short get_cltv_expiry_delta() { + short ret = bindings.ChannelConfig_get_cltv_expiry_delta(this.ptr); return ret; } - public void set_fee_proportional_millionths(ChannelConfig this_ptr, int val) { - bindings.ChannelConfig_set_fee_proportional_millionths(this_ptr == null ? 0 : this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + /** + * The difference in the CLTV value between incoming HTLCs and an outbound HTLC forwarded over + * the channel this config applies to. + * + * This is analogous to [`ChannelHandshakeConfig::our_to_self_delay`] but applies to in-flight + * HTLC balance when a channel appears on-chain whereas + * [`ChannelHandshakeConfig::our_to_self_delay`] applies to the remaining + * (non-HTLC-encumbered) balance. + * + * Thus, for HTLC-encumbered balances to be enforced on-chain when a channel is force-closed, + * we (or one of our watchtowers) MUST be online to check for broadcast of the current + * commitment transaction at least once per this many blocks (minus some margin to allow us + * enough time to broadcast and confirm a transaction, possibly with time in between to RBF + * the spending transaction). + * + * Default value: 72 (12 hours at an average of 6 blocks/hour). + * Minimum value: [`MIN_CLTV_EXPIRY_DELTA`], any values less than this will be treated as + * [`MIN_CLTV_EXPIRY_DELTA`] instead. + * + * [`MIN_CLTV_EXPIRY_DELTA`]: crate::ln::channelmanager::MIN_CLTV_EXPIRY_DELTA + */ + public void set_cltv_expiry_delta(short val) { + bindings.ChannelConfig_set_cltv_expiry_delta(this.ptr, val); } - public boolean get_announced_channel(ChannelConfig this_ptr) { - boolean ret = bindings.ChannelConfig_get_announced_channel(this_ptr == null ? 0 : this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); + /** + * Set to announce the channel publicly and notify all nodes that they can route via this + * channel. + * + * This should only be set to true for nodes which expect to be online reliably. + * + * As the node which funds a channel picks this value this will only apply for new outbound + * channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set. + * + * This cannot be changed after the initial channel handshake. + * + * Default value: false. + */ + public boolean get_announced_channel() { + boolean ret = bindings.ChannelConfig_get_announced_channel(this.ptr); return ret; } - public void set_announced_channel(ChannelConfig this_ptr, boolean val) { - bindings.ChannelConfig_set_announced_channel(this_ptr == null ? 0 : this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + /** + * Set to announce the channel publicly and notify all nodes that they can route via this + * channel. + * + * This should only be set to true for nodes which expect to be online reliably. + * + * As the node which funds a channel picks this value this will only apply for new outbound + * channels unless ChannelHandshakeLimits::force_announced_channel_preferences is set. + * + * This cannot be changed after the initial channel handshake. + * + * Default value: false. + */ + public void set_announced_channel(boolean val) { + bindings.ChannelConfig_set_announced_channel(this.ptr, val); } - public boolean get_commit_upfront_shutdown_pubkey(ChannelConfig this_ptr) { - boolean ret = bindings.ChannelConfig_get_commit_upfront_shutdown_pubkey(this_ptr == null ? 0 : this_ptr.ptr & ~1); - this.ptrs_to.add(this_ptr); + /** + * When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty + * supports it, they will then enforce the mutual-close output to us matches what we provided + * at intialization, preventing us from closing to an alternate pubkey. + * + * This is set to true by default to provide a slight increase in security, though ultimately + * any attacker who is able to take control of a channel can just as easily send the funds via + * lightning payments, so we never require that our counterparties support this option. + * + * This cannot be changed after a channel has been initialized. + * + * Default value: true. + */ + public boolean get_commit_upfront_shutdown_pubkey() { + boolean ret = bindings.ChannelConfig_get_commit_upfront_shutdown_pubkey(this.ptr); return ret; } - public void set_commit_upfront_shutdown_pubkey(ChannelConfig this_ptr, boolean val) { - bindings.ChannelConfig_set_commit_upfront_shutdown_pubkey(this_ptr == null ? 0 : this_ptr.ptr & ~1, val); - this.ptrs_to.add(this_ptr); + /** + * When set, we commit to an upfront shutdown_pubkey at channel open. If our counterparty + * supports it, they will then enforce the mutual-close output to us matches what we provided + * at intialization, preventing us from closing to an alternate pubkey. + * + * This is set to true by default to provide a slight increase in security, though ultimately + * any attacker who is able to take control of a channel can just as easily send the funds via + * lightning payments, so we never require that our counterparties support this option. + * + * This cannot be changed after a channel has been initialized. + * + * Default value: true. + */ + public void set_commit_upfront_shutdown_pubkey(boolean val) { + bindings.ChannelConfig_set_commit_upfront_shutdown_pubkey(this.ptr, val); } - public ChannelConfig(int fee_proportional_millionths_arg, boolean announced_channel_arg, boolean commit_upfront_shutdown_pubkey_arg) { - super(bindings.ChannelConfig_new(fee_proportional_millionths_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg)); + /** + * Constructs a new ChannelConfig given each field + */ + public static ChannelConfig constructor_new(int fee_proportional_millionths_arg, short cltv_expiry_delta_arg, boolean announced_channel_arg, boolean commit_upfront_shutdown_pubkey_arg) { + long ret = bindings.ChannelConfig_new(fee_proportional_millionths_arg, cltv_expiry_delta_arg, announced_channel_arg, commit_upfront_shutdown_pubkey_arg); + ChannelConfig ret_hu_conv = new ChannelConfig(null, ret); + ret_hu_conv.ptrs_to.add(ret_hu_conv); + return ret_hu_conv; } - public ChannelConfig() { - super(bindings.ChannelConfig_default()); + /** + * Creates a copy of the ChannelConfig + */ + public ChannelConfig clone() { + long ret = bindings.ChannelConfig_clone(this.ptr); + ChannelConfig ret_hu_conv = new ChannelConfig(null, ret); + ret_hu_conv.ptrs_to.add(this); + return ret_hu_conv; + } + + /** + * Creates a "default" ChannelConfig. See struct and individual field documentaiton for details on which values are used. + */ + public static ChannelConfig constructor_default() { + long ret = bindings.ChannelConfig_default(); + ChannelConfig ret_hu_conv = new ChannelConfig(null, ret); + ret_hu_conv.ptrs_to.add(ret_hu_conv); + return ret_hu_conv; + } + + /** + * Serialize the ChannelConfig object into a byte array which can be read by ChannelConfig_read + */ + public byte[] write() { + byte[] ret = bindings.ChannelConfig_write(this.ptr); + return ret; } - // Skipped ChannelConfig_write - public ChannelConfig(byte[] ser) { - super(bindings.ChannelConfig_read(ser)); + /** + * Read a ChannelConfig from a byte array, created by ChannelConfig_write + */ + public static Result_ChannelConfigDecodeErrorZ constructor_read(byte[] ser) { + long ret = bindings.ChannelConfig_read(ser); + Result_ChannelConfigDecodeErrorZ ret_hu_conv = Result_ChannelConfigDecodeErrorZ.constr_from_ptr(ret); + return ret_hu_conv; } }