Merge pull request #47 from TheBlueMatt/main
[ldk-java] / src / main / java / org / ldk / structs / ChannelInfo.java
index 8206d572a63b52e1d1d4ff2d81e8f49350c34fa0..7bec5b21952a45cc3a8a8f01c4ae53ca6b143960 100644 (file)
@@ -4,6 +4,7 @@ import org.ldk.impl.bindings;
 import org.ldk.enums.*;
 import org.ldk.util.*;
 import java.util.Arrays;
+import javax.annotation.Nullable;
 
 
 /**
@@ -24,6 +25,7 @@ public class ChannelInfo extends CommonBase {
         */
        public ChannelFeatures get_features() {
                long ret = bindings.ChannelInfo_get_features(this.ptr);
+               if (ret < 1024) { return null; }
                ChannelFeatures ret_hu_conv = new ChannelFeatures(null, ret);
                ret_hu_conv.ptrs_to.add(this);
                return ret_hu_conv;
@@ -34,7 +36,6 @@ public class ChannelInfo extends CommonBase {
         */
        public void set_features(ChannelFeatures val) {
                bindings.ChannelInfo_set_features(this.ptr, val == null ? 0 : val.ptr & ~1);
-               this.ptrs_to.add(val);
        }
 
        /**
@@ -54,9 +55,13 @@ public class ChannelInfo extends CommonBase {
 
        /**
         * Details about the first direction of a channel
+        * 
+        * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
         */
+       @Nullable
        public DirectionalChannelInfo get_one_to_two() {
                long ret = bindings.ChannelInfo_get_one_to_two(this.ptr);
+               if (ret < 1024) { return null; }
                DirectionalChannelInfo ret_hu_conv = new DirectionalChannelInfo(null, ret);
                ret_hu_conv.ptrs_to.add(this);
                return ret_hu_conv;
@@ -64,10 +69,11 @@ public class ChannelInfo extends CommonBase {
 
        /**
         * Details about the first direction of a channel
+        * 
+        * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
         */
-       public void set_one_to_two(DirectionalChannelInfo val) {
+       public void set_one_to_two(@Nullable DirectionalChannelInfo val) {
                bindings.ChannelInfo_set_one_to_two(this.ptr, val == null ? 0 : val.ptr & ~1);
-               this.ptrs_to.add(val);
        }
 
        /**
@@ -87,9 +93,13 @@ public class ChannelInfo extends CommonBase {
 
        /**
         * Details about the second direction of a channel
+        * 
+        * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
         */
+       @Nullable
        public DirectionalChannelInfo get_two_to_one() {
                long ret = bindings.ChannelInfo_get_two_to_one(this.ptr);
+               if (ret < 1024) { return null; }
                DirectionalChannelInfo ret_hu_conv = new DirectionalChannelInfo(null, ret);
                ret_hu_conv.ptrs_to.add(this);
                return ret_hu_conv;
@@ -97,10 +107,29 @@ public class ChannelInfo extends CommonBase {
 
        /**
         * Details about the second direction of a channel
+        * 
+        * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
         */
-       public void set_two_to_one(DirectionalChannelInfo val) {
+       public void set_two_to_one(@Nullable DirectionalChannelInfo val) {
                bindings.ChannelInfo_set_two_to_one(this.ptr, val == null ? 0 : val.ptr & ~1);
-               this.ptrs_to.add(val);
+       }
+
+       /**
+        * The channel capacity as seen on-chain, if chain lookup is available.
+        */
+       public Option_u64Z get_capacity_sats() {
+               long ret = bindings.ChannelInfo_get_capacity_sats(this.ptr);
+               if (ret < 1024) { return null; }
+               Option_u64Z ret_hu_conv = Option_u64Z.constr_from_ptr(ret);
+               ret_hu_conv.ptrs_to.add(this);
+               return ret_hu_conv;
+       }
+
+       /**
+        * The channel capacity as seen on-chain, if chain lookup is available.
+        */
+       public void set_capacity_sats(Option_u64Z val) {
+               bindings.ChannelInfo_set_capacity_sats(this.ptr, val.ptr);
        }
 
        /**
@@ -108,9 +137,13 @@ public class ChannelInfo extends CommonBase {
         * Mostly redundant with the data we store in fields explicitly.
         * Everything else is useful only for sending out for initial routing sync.
         * Not stored if contains excess data to prevent DoS.
+        * 
+        * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
         */
+       @Nullable
        public ChannelAnnouncement get_announcement_message() {
                long ret = bindings.ChannelInfo_get_announcement_message(this.ptr);
+               if (ret < 1024) { return null; }
                ChannelAnnouncement ret_hu_conv = new ChannelAnnouncement(null, ret);
                ret_hu_conv.ptrs_to.add(this);
                return ret_hu_conv;
@@ -121,10 +154,22 @@ public class ChannelInfo extends CommonBase {
         * Mostly redundant with the data we store in fields explicitly.
         * Everything else is useful only for sending out for initial routing sync.
         * Not stored if contains excess data to prevent DoS.
+        * 
+        * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
         */
-       public void set_announcement_message(ChannelAnnouncement val) {
+       public void set_announcement_message(@Nullable ChannelAnnouncement val) {
                bindings.ChannelInfo_set_announcement_message(this.ptr, val == null ? 0 : val.ptr & ~1);
-               this.ptrs_to.add(val);
+       }
+
+       /**
+        * Constructs a new ChannelInfo given each field
+        */
+       public static ChannelInfo of(ChannelFeatures features_arg, byte[] node_one_arg, DirectionalChannelInfo one_to_two_arg, byte[] node_two_arg, DirectionalChannelInfo two_to_one_arg, Option_u64Z capacity_sats_arg, ChannelAnnouncement announcement_message_arg) {
+               long ret = bindings.ChannelInfo_new(features_arg == null ? 0 : features_arg.ptr & ~1, node_one_arg, one_to_two_arg == null ? 0 : one_to_two_arg.ptr & ~1, node_two_arg, two_to_one_arg == null ? 0 : two_to_one_arg.ptr & ~1, capacity_sats_arg.ptr, announcement_message_arg == null ? 0 : announcement_message_arg.ptr & ~1);
+               if (ret < 1024) { return null; }
+               ChannelInfo ret_hu_conv = new ChannelInfo(null, ret);
+               ret_hu_conv.ptrs_to.add(ret_hu_conv);
+               return ret_hu_conv;
        }
 
        /**
@@ -132,6 +177,7 @@ public class ChannelInfo extends CommonBase {
         */
        public ChannelInfo clone() {
                long ret = bindings.ChannelInfo_clone(this.ptr);
+               if (ret < 1024) { return null; }
                ChannelInfo ret_hu_conv = new ChannelInfo(null, ret);
                ret_hu_conv.ptrs_to.add(this);
                return ret_hu_conv;
@@ -148,8 +194,9 @@ public class ChannelInfo extends CommonBase {
        /**
         * Read a ChannelInfo from a byte array, created by ChannelInfo_write
         */
-       public static Result_ChannelInfoDecodeErrorZ constructor_read(byte[] ser) {
+       public static Result_ChannelInfoDecodeErrorZ read(byte[] ser) {
                long ret = bindings.ChannelInfo_read(ser);
+               if (ret < 1024) { return null; }
                Result_ChannelInfoDecodeErrorZ ret_hu_conv = Result_ChannelInfoDecodeErrorZ.constr_from_ptr(ret);
                return ret_hu_conv;
        }