[TS] Update auto-generated TypeScript Bindings
[ldk-java] / ts / structs / NetworkUpdate.mts
index 7f5afe8a34c5550fdcb2835037e56d3df62e0789..e4a839248f90b115a85ba204fca8a2ea8510e4d2 100644 (file)
@@ -279,23 +279,25 @@ import { MultiThreadedLockableScore } from '../structs/MultiThreadedLockableScor
 
 import CommonBase from './CommonBase.mjs';
 import * as bindings from '../bindings.mjs'
-import * as InternalUtils from '../InternalUtils.mjs'
 
+/**
+ * Update to the [`NetworkGraph`] based on payment failure information conveyed via the Onion
+ * return packet by a node along the route. See [BOLT #4] for details.
+ * 
+ * [BOLT #4]: https://github.com/lightningnetwork/lightning-rfc/blob/master/04-onion-routing.md
+ */
 export class NetworkUpdate extends CommonBase {
        protected constructor(_dummy: object, ptr: number) { super(ptr, bindings.NetworkUpdate_free); }
        /* @internal */
        public static constr_from_ptr(ptr: number): NetworkUpdate {
-               const raw_val: bindings.LDKNetworkUpdate = bindings.LDKNetworkUpdate_ref_from_ptr(ptr);
-               if (raw_val instanceof bindings.LDKNetworkUpdate_ChannelUpdateMessage) {
-                       return new NetworkUpdate_ChannelUpdateMessage(ptr, raw_val);
+               const raw_ty: number = bindings.LDKNetworkUpdate_ty_from_ptr(ptr);
+               switch (raw_ty) {
+                       case 0: return new NetworkUpdate_ChannelUpdateMessage(ptr);
+                       case 1: return new NetworkUpdate_ChannelClosed(ptr);
+                       case 2: return new NetworkUpdate_NodeFailure(ptr);
+                       default:
+                               throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
                }
-               if (raw_val instanceof bindings.LDKNetworkUpdate_ChannelClosed) {
-                       return new NetworkUpdate_ChannelClosed(ptr, raw_val);
-               }
-               if (raw_val instanceof bindings.LDKNetworkUpdate_NodeFailure) {
-                       return new NetworkUpdate_NodeFailure(ptr, raw_val);
-               }
-               throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
        }
 
        public clone_ptr(): number {
@@ -303,6 +305,9 @@ export class NetworkUpdate extends CommonBase {
                return ret;
        }
 
+       /**
+        * Creates a copy of the NetworkUpdate
+        */
        public clone(): NetworkUpdate {
                const ret: number = bindings.NetworkUpdate_clone(this.ptr);
                const ret_hu_conv: NetworkUpdate = NetworkUpdate.constr_from_ptr(ret);
@@ -310,6 +315,9 @@ export class NetworkUpdate extends CommonBase {
                return ret_hu_conv;
        }
 
+       /**
+        * Utility method to constructs a new ChannelUpdateMessage-variant NetworkUpdate
+        */
        public static constructor_channel_update_message(msg: ChannelUpdate): NetworkUpdate {
                const ret: number = bindings.NetworkUpdate_channel_update_message(msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1);
                const ret_hu_conv: NetworkUpdate = NetworkUpdate.constr_from_ptr(ret);
@@ -317,54 +325,86 @@ export class NetworkUpdate extends CommonBase {
                return ret_hu_conv;
        }
 
-       public static constructor_channel_closed(short_channel_id: number, is_permanent: boolean): NetworkUpdate {
+       /**
+        * Utility method to constructs a new ChannelClosed-variant NetworkUpdate
+        */
+       public static constructor_channel_closed(short_channel_id: bigint, is_permanent: boolean): NetworkUpdate {
                const ret: number = bindings.NetworkUpdate_channel_closed(short_channel_id, is_permanent);
                const ret_hu_conv: NetworkUpdate = NetworkUpdate.constr_from_ptr(ret);
                CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
                return ret_hu_conv;
        }
 
+       /**
+        * Utility method to constructs a new NodeFailure-variant NetworkUpdate
+        */
        public static constructor_node_failure(node_id: Uint8Array, is_permanent: boolean): NetworkUpdate {
-               const ret: number = bindings.NetworkUpdate_node_failure(InternalUtils.check_arr_len(node_id, 33), is_permanent);
+               const ret: number = bindings.NetworkUpdate_node_failure(bindings.encodeUint8Array(bindings.check_arr_len(node_id, 33)), is_permanent);
                const ret_hu_conv: NetworkUpdate = NetworkUpdate.constr_from_ptr(ret);
                CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
                return ret_hu_conv;
        }
 
+       /**
+        * Serialize the NetworkUpdate object into a byte array which can be read by NetworkUpdate_read
+        */
        public write(): Uint8Array {
-               const ret: Uint8Array = bindings.NetworkUpdate_write(this.ptr);
-               return ret;
+               const ret: number = bindings.NetworkUpdate_write(this.ptr);
+               const ret_conv: Uint8Array = bindings.decodeUint8Array(ret);
+               return ret_conv;
        }
 
 }
+/** A NetworkUpdate of type ChannelUpdateMessage */
 export class NetworkUpdate_ChannelUpdateMessage extends NetworkUpdate {
+       /**
+        * The update to apply via [`NetworkGraph::update_channel`].
+        */
        public msg: ChannelUpdate;
        /* @internal */
-       public constructor(ptr: number, obj: bindings.LDKNetworkUpdate_ChannelUpdateMessage) {
+       public constructor(ptr: number) {
                super(null, ptr);
-               const msg: number = obj.msg;
+               const msg: number = bindings.LDKNetworkUpdate_ChannelUpdateMessage_get_msg(ptr);
                const msg_hu_conv: ChannelUpdate = new ChannelUpdate(null, msg);
                        CommonBase.add_ref_from(msg_hu_conv, this);
                this.msg = msg_hu_conv;
        }
 }
+/** A NetworkUpdate of type ChannelClosed */
 export class NetworkUpdate_ChannelClosed extends NetworkUpdate {
-       public short_channel_id: number;
+       /**
+        * The short channel id of the closed channel.
+        */
+       public short_channel_id: bigint;
+       /**
+        * Whether the channel should be permanently removed or temporarily disabled until a new
+        * `channel_update` message is received.
+        */
        public is_permanent: boolean;
        /* @internal */
-       public constructor(ptr: number, obj: bindings.LDKNetworkUpdate_ChannelClosed) {
+       public constructor(ptr: number) {
                super(null, ptr);
-               this.short_channel_id = obj.short_channel_id;
-               this.is_permanent = obj.is_permanent;
+               this.short_channel_id = bindings.LDKNetworkUpdate_ChannelClosed_get_short_channel_id(ptr);
+               this.is_permanent = bindings.LDKNetworkUpdate_ChannelClosed_get_is_permanent(ptr);
        }
 }
+/** A NetworkUpdate of type NodeFailure */
 export class NetworkUpdate_NodeFailure extends NetworkUpdate {
+       /**
+        * The node id of the failed node.
+        */
        public node_id: Uint8Array;
+       /**
+        * Whether the node should be permanently removed from consideration or can be restored
+        * when a new `channel_update` message is received.
+        */
        public is_permanent: boolean;
        /* @internal */
-       public constructor(ptr: number, obj: bindings.LDKNetworkUpdate_NodeFailure) {
+       public constructor(ptr: number) {
                super(null, ptr);
-               this.node_id = obj.node_id;
-               this.is_permanent = obj.is_permanent;
+               const node_id: number = bindings.LDKNetworkUpdate_NodeFailure_get_node_id(ptr);
+               const node_id_conv: Uint8Array = bindings.decodeUint8Array(node_id);
+               this.node_id = node_id_conv;
+               this.is_permanent = bindings.LDKNetworkUpdate_NodeFailure_get_is_permanent(ptr);
        }
 }