X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Forg%2Fldk%2Fstructs%2FOpenChannel.java;h=7040d9ea6b4ab2c874bd6c38fb8bf12def884218;hb=2bb592fb946e316dba9f4d1123f8ac72ff4e9bf8;hp=f0e80ebade5afa8d156c24dd50ec4acdac798f7b;hpb=b6cc0960eaee5a5bbc7fde79a56152d6dcd649d8;p=ldk-java diff --git a/src/main/java/org/ldk/structs/OpenChannel.java b/src/main/java/org/ldk/structs/OpenChannel.java index f0e80eba..7040d9ea 100644 --- a/src/main/java/org/ldk/structs/OpenChannel.java +++ b/src/main/java/org/ldk/structs/OpenChannel.java @@ -4,10 +4,16 @@ 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; /** - * An open_channel message to be sent or received from a peer + * An [`open_channel`] message to be sent to or received from a peer. + * + * Used in V1 channel establishment + * + * [`open_channel`]: https://github.com/lightning/bolts/blob/master/02-peer-protocol.md#the-open_channel-message */ @SuppressWarnings("unchecked") // We correctly assign various generic arrays public class OpenChannel extends CommonBase { @@ -23,6 +29,7 @@ public class OpenChannel extends CommonBase { */ public byte[] get_chain_hash() { byte[] ret = bindings.OpenChannel_get_chain_hash(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -30,7 +37,9 @@ public class OpenChannel extends CommonBase { * The genesis hash of the blockchain where the channel is to be opened */ public void set_chain_hash(byte[] val) { - bindings.OpenChannel_set_chain_hash(this.ptr, val); + bindings.OpenChannel_set_chain_hash(this.ptr, InternalUtils.check_arr_len(val, 32)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -38,6 +47,7 @@ public class OpenChannel extends CommonBase { */ public byte[] get_temporary_channel_id() { byte[] ret = bindings.OpenChannel_get_temporary_channel_id(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -45,7 +55,9 @@ public class OpenChannel extends CommonBase { * A temporary channel ID, until the funding outpoint is announced */ public void set_temporary_channel_id(byte[] val) { - bindings.OpenChannel_set_temporary_channel_id(this.ptr, val); + bindings.OpenChannel_set_temporary_channel_id(this.ptr, InternalUtils.check_arr_len(val, 32)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -53,6 +65,7 @@ public class OpenChannel extends CommonBase { */ public long get_funding_satoshis() { long ret = bindings.OpenChannel_get_funding_satoshis(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -61,6 +74,8 @@ public class OpenChannel extends CommonBase { */ public void set_funding_satoshis(long val) { bindings.OpenChannel_set_funding_satoshis(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -68,6 +83,7 @@ public class OpenChannel extends CommonBase { */ public long get_push_msat() { long ret = bindings.OpenChannel_get_push_msat(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -76,6 +92,8 @@ public class OpenChannel extends CommonBase { */ public void set_push_msat(long val) { bindings.OpenChannel_set_push_msat(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -83,6 +101,7 @@ public class OpenChannel extends CommonBase { */ public long get_dust_limit_satoshis() { long ret = bindings.OpenChannel_get_dust_limit_satoshis(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -91,6 +110,8 @@ public class OpenChannel extends CommonBase { */ public void set_dust_limit_satoshis(long val) { bindings.OpenChannel_set_dust_limit_satoshis(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -98,6 +119,7 @@ public class OpenChannel extends CommonBase { */ public long get_max_htlc_value_in_flight_msat() { long ret = bindings.OpenChannel_get_max_htlc_value_in_flight_msat(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -106,6 +128,8 @@ public class OpenChannel extends CommonBase { */ public void set_max_htlc_value_in_flight_msat(long val) { bindings.OpenChannel_set_max_htlc_value_in_flight_msat(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -113,6 +137,7 @@ public class OpenChannel extends CommonBase { */ public long get_channel_reserve_satoshis() { long ret = bindings.OpenChannel_get_channel_reserve_satoshis(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -121,6 +146,8 @@ public class OpenChannel extends CommonBase { */ public void set_channel_reserve_satoshis(long val) { bindings.OpenChannel_set_channel_reserve_satoshis(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -128,6 +155,7 @@ public class OpenChannel extends CommonBase { */ public long get_htlc_minimum_msat() { long ret = bindings.OpenChannel_get_htlc_minimum_msat(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -136,36 +164,48 @@ public class OpenChannel extends CommonBase { */ public void set_htlc_minimum_msat(long val) { bindings.OpenChannel_set_htlc_minimum_msat(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** - * The feerate per 1000-weight of sender generated transactions, until updated by update_fee + * The feerate per 1000-weight of sender generated transactions, until updated by + * [`UpdateFee`] */ public int get_feerate_per_kw() { int ret = bindings.OpenChannel_get_feerate_per_kw(this.ptr); + Reference.reachabilityFence(this); return ret; } /** - * The feerate per 1000-weight of sender generated transactions, until updated by update_fee + * The feerate per 1000-weight of sender generated transactions, until updated by + * [`UpdateFee`] */ public void set_feerate_per_kw(int val) { bindings.OpenChannel_set_feerate_per_kw(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** - * The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction + * The number of blocks which the counterparty will have to wait to claim on-chain funds if + * they broadcast a commitment transaction */ public short get_to_self_delay() { short ret = bindings.OpenChannel_get_to_self_delay(this.ptr); + Reference.reachabilityFence(this); return ret; } /** - * The number of blocks which the counterparty will have to wait to claim on-chain funds if they broadcast a commitment transaction + * The number of blocks which the counterparty will have to wait to claim on-chain funds if + * they broadcast a commitment transaction */ public void set_to_self_delay(short val) { bindings.OpenChannel_set_to_self_delay(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -173,6 +213,7 @@ public class OpenChannel extends CommonBase { */ public short get_max_accepted_htlcs() { short ret = bindings.OpenChannel_get_max_accepted_htlcs(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -181,6 +222,8 @@ public class OpenChannel extends CommonBase { */ public void set_max_accepted_htlcs(short val) { bindings.OpenChannel_set_max_accepted_htlcs(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -188,6 +231,7 @@ public class OpenChannel extends CommonBase { */ public byte[] get_funding_pubkey() { byte[] ret = bindings.OpenChannel_get_funding_pubkey(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -195,7 +239,9 @@ public class OpenChannel extends CommonBase { * The sender's key controlling the funding transaction */ public void set_funding_pubkey(byte[] val) { - bindings.OpenChannel_set_funding_pubkey(this.ptr, val); + bindings.OpenChannel_set_funding_pubkey(this.ptr, InternalUtils.check_arr_len(val, 33)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -203,6 +249,7 @@ public class OpenChannel extends CommonBase { */ public byte[] get_revocation_basepoint() { byte[] ret = bindings.OpenChannel_get_revocation_basepoint(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -210,7 +257,9 @@ public class OpenChannel extends CommonBase { * Used to derive a revocation key for transactions broadcast by counterparty */ public void set_revocation_basepoint(byte[] val) { - bindings.OpenChannel_set_revocation_basepoint(this.ptr, val); + bindings.OpenChannel_set_revocation_basepoint(this.ptr, InternalUtils.check_arr_len(val, 33)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -218,6 +267,7 @@ public class OpenChannel extends CommonBase { */ public byte[] get_payment_point() { byte[] ret = bindings.OpenChannel_get_payment_point(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -225,7 +275,9 @@ public class OpenChannel extends CommonBase { * A payment key to sender for transactions broadcast by counterparty */ public void set_payment_point(byte[] val) { - bindings.OpenChannel_set_payment_point(this.ptr, val); + bindings.OpenChannel_set_payment_point(this.ptr, InternalUtils.check_arr_len(val, 33)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -233,6 +285,7 @@ public class OpenChannel extends CommonBase { */ public byte[] get_delayed_payment_basepoint() { byte[] ret = bindings.OpenChannel_get_delayed_payment_basepoint(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -240,7 +293,9 @@ public class OpenChannel extends CommonBase { * Used to derive a payment key to sender for transactions broadcast by sender */ public void set_delayed_payment_basepoint(byte[] val) { - bindings.OpenChannel_set_delayed_payment_basepoint(this.ptr, val); + bindings.OpenChannel_set_delayed_payment_basepoint(this.ptr, InternalUtils.check_arr_len(val, 33)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -248,6 +303,7 @@ public class OpenChannel extends CommonBase { */ public byte[] get_htlc_basepoint() { byte[] ret = bindings.OpenChannel_get_htlc_basepoint(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -255,7 +311,9 @@ public class OpenChannel extends CommonBase { * Used to derive an HTLC payment key to sender */ public void set_htlc_basepoint(byte[] val) { - bindings.OpenChannel_set_htlc_basepoint(this.ptr, val); + bindings.OpenChannel_set_htlc_basepoint(this.ptr, InternalUtils.check_arr_len(val, 33)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** @@ -263,6 +321,7 @@ public class OpenChannel extends CommonBase { */ public byte[] get_first_per_commitment_point() { byte[] ret = bindings.OpenChannel_get_first_per_commitment_point(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -270,22 +329,123 @@ public class OpenChannel extends CommonBase { * The first to-be-broadcast-by-sender transaction's per commitment point */ public void set_first_per_commitment_point(byte[] val) { - bindings.OpenChannel_set_first_per_commitment_point(this.ptr, val); + bindings.OpenChannel_set_first_per_commitment_point(this.ptr, InternalUtils.check_arr_len(val, 33)); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); } /** - * Channel flags + * The channel flags to be used */ public byte get_channel_flags() { byte ret = bindings.OpenChannel_get_channel_flags(this.ptr); + Reference.reachabilityFence(this); return ret; } /** - * Channel flags + * The channel flags to be used */ public void set_channel_flags(byte val) { bindings.OpenChannel_set_channel_flags(this.ptr, val); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + } + + /** + * A request to pre-set the to-sender output's `scriptPubkey` for when we collaboratively close + */ + public Option_CVec_u8ZZ get_shutdown_scriptpubkey() { + long ret = bindings.OpenChannel_get_shutdown_scriptpubkey(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.Option_CVec_u8ZZ ret_hu_conv = org.ldk.structs.Option_CVec_u8ZZ.constr_from_ptr(ret); + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; + return ret_hu_conv; + } + + /** + * A request to pre-set the to-sender output's `scriptPubkey` for when we collaboratively close + */ + public void set_shutdown_scriptpubkey(org.ldk.structs.Option_CVec_u8ZZ val) { + bindings.OpenChannel_set_shutdown_scriptpubkey(this.ptr, val.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + if (this != null) { this.ptrs_to.add(val); }; + } + + /** + * The channel type that this channel will represent + * + * If this is `None`, we derive the channel type from the intersection of our + * feature bits with our counterparty's feature bits from the [`Init`] message. + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + @Nullable + public ChannelTypeFeatures get_channel_type() { + long ret = bindings.OpenChannel_get_channel_type(this.ptr); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.ChannelTypeFeatures ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.ChannelTypeFeatures(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; + return ret_hu_conv; + } + + /** + * The channel type that this channel will represent + * + * If this is `None`, we derive the channel type from the intersection of our + * feature bits with our counterparty's feature bits from the [`Init`] message. + * + * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + public void set_channel_type(@Nullable org.ldk.structs.ChannelTypeFeatures val) { + bindings.OpenChannel_set_channel_type(this.ptr, val == null ? 0 : val.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(val); + if (this != null) { this.ptrs_to.add(val); }; + } + + /** + * Constructs a new OpenChannel given each field + * + * Note that channel_type_arg (or a relevant inner pointer) may be NULL or all-0s to represent None + */ + public static OpenChannel of(byte[] chain_hash_arg, byte[] temporary_channel_id_arg, long funding_satoshis_arg, long push_msat_arg, long dust_limit_satoshis_arg, long max_htlc_value_in_flight_msat_arg, long channel_reserve_satoshis_arg, long htlc_minimum_msat_arg, int feerate_per_kw_arg, short to_self_delay_arg, short max_accepted_htlcs_arg, byte[] funding_pubkey_arg, byte[] revocation_basepoint_arg, byte[] payment_point_arg, byte[] delayed_payment_basepoint_arg, byte[] htlc_basepoint_arg, byte[] first_per_commitment_point_arg, byte channel_flags_arg, org.ldk.structs.Option_CVec_u8ZZ shutdown_scriptpubkey_arg, @Nullable org.ldk.structs.ChannelTypeFeatures channel_type_arg) { + long ret = bindings.OpenChannel_new(InternalUtils.check_arr_len(chain_hash_arg, 32), InternalUtils.check_arr_len(temporary_channel_id_arg, 32), funding_satoshis_arg, push_msat_arg, dust_limit_satoshis_arg, max_htlc_value_in_flight_msat_arg, channel_reserve_satoshis_arg, htlc_minimum_msat_arg, feerate_per_kw_arg, to_self_delay_arg, max_accepted_htlcs_arg, InternalUtils.check_arr_len(funding_pubkey_arg, 33), InternalUtils.check_arr_len(revocation_basepoint_arg, 33), InternalUtils.check_arr_len(payment_point_arg, 33), InternalUtils.check_arr_len(delayed_payment_basepoint_arg, 33), InternalUtils.check_arr_len(htlc_basepoint_arg, 33), InternalUtils.check_arr_len(first_per_commitment_point_arg, 33), channel_flags_arg, shutdown_scriptpubkey_arg.ptr, channel_type_arg == null ? 0 : channel_type_arg.ptr); + Reference.reachabilityFence(chain_hash_arg); + Reference.reachabilityFence(temporary_channel_id_arg); + Reference.reachabilityFence(funding_satoshis_arg); + Reference.reachabilityFence(push_msat_arg); + Reference.reachabilityFence(dust_limit_satoshis_arg); + Reference.reachabilityFence(max_htlc_value_in_flight_msat_arg); + Reference.reachabilityFence(channel_reserve_satoshis_arg); + Reference.reachabilityFence(htlc_minimum_msat_arg); + Reference.reachabilityFence(feerate_per_kw_arg); + Reference.reachabilityFence(to_self_delay_arg); + Reference.reachabilityFence(max_accepted_htlcs_arg); + Reference.reachabilityFence(funding_pubkey_arg); + Reference.reachabilityFence(revocation_basepoint_arg); + Reference.reachabilityFence(payment_point_arg); + Reference.reachabilityFence(delayed_payment_basepoint_arg); + Reference.reachabilityFence(htlc_basepoint_arg); + Reference.reachabilityFence(first_per_commitment_point_arg); + Reference.reachabilityFence(channel_flags_arg); + Reference.reachabilityFence(shutdown_scriptpubkey_arg); + Reference.reachabilityFence(channel_type_arg); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.OpenChannel ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OpenChannel(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(ret_hu_conv); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(shutdown_scriptpubkey_arg); }; + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(channel_type_arg); }; + return ret_hu_conv; + } + + long clone_ptr() { + long ret = bindings.OpenChannel_clone_ptr(this.ptr); + Reference.reachabilityFence(this); + return ret; } /** @@ -293,16 +453,48 @@ public class OpenChannel extends CommonBase { */ public OpenChannel clone() { long ret = bindings.OpenChannel_clone(this.ptr); - OpenChannel ret_hu_conv = new OpenChannel(null, ret); - ret_hu_conv.ptrs_to.add(this); + Reference.reachabilityFence(this); + if (ret >= 0 && ret <= 4096) { return null; } + org.ldk.structs.OpenChannel ret_hu_conv = null; if (ret < 0 || ret > 4096) { ret_hu_conv = new org.ldk.structs.OpenChannel(null, ret); } + if (ret_hu_conv != null) { ret_hu_conv.ptrs_to.add(this); }; return ret_hu_conv; } + /** + * Generates a non-cryptographic 64-bit hash of the OpenChannel. + */ + public long hash() { + long ret = bindings.OpenChannel_hash(this.ptr); + Reference.reachabilityFence(this); + return ret; + } + + @Override public int hashCode() { + return (int)this.hash(); + } + /** + * Checks if two OpenChannels contain equal inner contents. + * This ignores pointers and is_owned flags and looks at the values in fields. + * Two objects with NULL inner values will be considered "equal" here. + */ + public boolean eq(org.ldk.structs.OpenChannel b) { + boolean ret = bindings.OpenChannel_eq(this.ptr, b == null ? 0 : b.ptr); + Reference.reachabilityFence(this); + Reference.reachabilityFence(b); + if (this != null) { this.ptrs_to.add(b); }; + return ret; + } + + @Override public boolean equals(Object o) { + if (!(o instanceof OpenChannel)) return false; + return this.eq((OpenChannel)o); + } /** * Serialize the OpenChannel object into a byte array which can be read by OpenChannel_read */ public byte[] write() { byte[] ret = bindings.OpenChannel_write(this.ptr); + Reference.reachabilityFence(this); return ret; } @@ -311,6 +503,8 @@ public class OpenChannel extends CommonBase { */ public static Result_OpenChannelDecodeErrorZ read(byte[] ser) { long ret = bindings.OpenChannel_read(ser); + Reference.reachabilityFence(ser); + if (ret >= 0 && ret <= 4096) { return null; } Result_OpenChannelDecodeErrorZ ret_hu_conv = Result_OpenChannelDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; }