X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=blobdiff_plain;f=ts%2Fstructs%2FCommitmentUpdate.mts;h=8eff640134b96cfbd8eb35dc460c2fa30542a087;hp=b292015e6d0ad4e293a5b1183c8c84c5287a80ca;hb=c629a01650402c8e2f9b9db8ced9ed63ce687727;hpb=2a65456aa0b540060dcf3ca707a54dc98cc3f38a diff --git a/ts/structs/CommitmentUpdate.mts b/ts/structs/CommitmentUpdate.mts index b292015e..8eff6401 100644 --- a/ts/structs/CommitmentUpdate.mts +++ b/ts/structs/CommitmentUpdate.mts @@ -279,79 +279,119 @@ import { MultiThreadedLockableScore } from '../structs/MultiThreadedLockableScor import CommonBase from './CommonBase.mjs'; import * as bindings from '../bindings.mjs' -import * as InternalUtils from '../InternalUtils.mjs' +/** + * Struct used to return values from revoke_and_ack messages, containing a bunch of commitment + * transaction updates if they were pending. + */ export class CommitmentUpdate extends CommonBase { /* @internal */ public constructor(_dummy: object, ptr: number) { super(ptr, bindings.CommitmentUpdate_free); } + /** + * update_add_htlc messages which should be sent + */ public get_update_add_htlcs(): UpdateAddHTLC[] { - const ret: number[] = bindings.CommitmentUpdate_get_update_add_htlcs(this.ptr); - const ret_conv_15_arr: UpdateAddHTLC[] = new Array(ret.length).fill(null); - for (var p = 0; p < ret.length; p++) { - const ret_conv_15: number = ret[p]; + const ret: number = bindings.CommitmentUpdate_get_update_add_htlcs(this.ptr); + const ret_conv_15_len: number = bindings.getArrayLength(ret); + const ret_conv_15_arr: UpdateAddHTLC[] = new Array(ret_conv_15_len).fill(null); + for (var p = 0; p < ret_conv_15_len; p++) { + const ret_conv_15: number = bindings.getU32ArrayElem(ret, p); const ret_conv_15_hu_conv: UpdateAddHTLC = new UpdateAddHTLC(null, ret_conv_15); CommonBase.add_ref_from(ret_conv_15_hu_conv, this); ret_conv_15_arr[p] = ret_conv_15_hu_conv; } + bindings.freeWasmMemory(ret) return ret_conv_15_arr; } + /** + * update_add_htlc messages which should be sent + */ public set_update_add_htlcs(val: UpdateAddHTLC[]): void { - bindings.CommitmentUpdate_set_update_add_htlcs(this.ptr, val != null ? val.map(val_conv_15 => val_conv_15 == null ? 0 : CommonBase.get_ptr_of(val_conv_15) & ~1) : null); + bindings.CommitmentUpdate_set_update_add_htlcs(this.ptr, bindings.encodeUint32Array(val != null ? val.map(val_conv_15 => val_conv_15 == null ? 0 : CommonBase.get_ptr_of(val_conv_15) & ~1) : null)); } + /** + * update_fulfill_htlc messages which should be sent + */ public get_update_fulfill_htlcs(): UpdateFulfillHTLC[] { - const ret: number[] = bindings.CommitmentUpdate_get_update_fulfill_htlcs(this.ptr); - const ret_conv_19_arr: UpdateFulfillHTLC[] = new Array(ret.length).fill(null); - for (var t = 0; t < ret.length; t++) { - const ret_conv_19: number = ret[t]; + const ret: number = bindings.CommitmentUpdate_get_update_fulfill_htlcs(this.ptr); + const ret_conv_19_len: number = bindings.getArrayLength(ret); + const ret_conv_19_arr: UpdateFulfillHTLC[] = new Array(ret_conv_19_len).fill(null); + for (var t = 0; t < ret_conv_19_len; t++) { + const ret_conv_19: number = bindings.getU32ArrayElem(ret, t); const ret_conv_19_hu_conv: UpdateFulfillHTLC = new UpdateFulfillHTLC(null, ret_conv_19); CommonBase.add_ref_from(ret_conv_19_hu_conv, this); ret_conv_19_arr[t] = ret_conv_19_hu_conv; } + bindings.freeWasmMemory(ret) return ret_conv_19_arr; } + /** + * update_fulfill_htlc messages which should be sent + */ public set_update_fulfill_htlcs(val: UpdateFulfillHTLC[]): void { - bindings.CommitmentUpdate_set_update_fulfill_htlcs(this.ptr, val != null ? val.map(val_conv_19 => val_conv_19 == null ? 0 : CommonBase.get_ptr_of(val_conv_19) & ~1) : null); + bindings.CommitmentUpdate_set_update_fulfill_htlcs(this.ptr, bindings.encodeUint32Array(val != null ? val.map(val_conv_19 => val_conv_19 == null ? 0 : CommonBase.get_ptr_of(val_conv_19) & ~1) : null)); } + /** + * update_fail_htlc messages which should be sent + */ public get_update_fail_htlcs(): UpdateFailHTLC[] { - const ret: number[] = bindings.CommitmentUpdate_get_update_fail_htlcs(this.ptr); - const ret_conv_16_arr: UpdateFailHTLC[] = new Array(ret.length).fill(null); - for (var q = 0; q < ret.length; q++) { - const ret_conv_16: number = ret[q]; + const ret: number = bindings.CommitmentUpdate_get_update_fail_htlcs(this.ptr); + const ret_conv_16_len: number = bindings.getArrayLength(ret); + const ret_conv_16_arr: UpdateFailHTLC[] = new Array(ret_conv_16_len).fill(null); + for (var q = 0; q < ret_conv_16_len; q++) { + const ret_conv_16: number = bindings.getU32ArrayElem(ret, q); const ret_conv_16_hu_conv: UpdateFailHTLC = new UpdateFailHTLC(null, ret_conv_16); CommonBase.add_ref_from(ret_conv_16_hu_conv, this); ret_conv_16_arr[q] = ret_conv_16_hu_conv; } + bindings.freeWasmMemory(ret) return ret_conv_16_arr; } + /** + * update_fail_htlc messages which should be sent + */ public set_update_fail_htlcs(val: UpdateFailHTLC[]): void { - bindings.CommitmentUpdate_set_update_fail_htlcs(this.ptr, val != null ? val.map(val_conv_16 => val_conv_16 == null ? 0 : CommonBase.get_ptr_of(val_conv_16) & ~1) : null); + bindings.CommitmentUpdate_set_update_fail_htlcs(this.ptr, bindings.encodeUint32Array(val != null ? val.map(val_conv_16 => val_conv_16 == null ? 0 : CommonBase.get_ptr_of(val_conv_16) & ~1) : null)); } + /** + * update_fail_malformed_htlc messages which should be sent + */ public get_update_fail_malformed_htlcs(): UpdateFailMalformedHTLC[] { - const ret: number[] = bindings.CommitmentUpdate_get_update_fail_malformed_htlcs(this.ptr); - const ret_conv_25_arr: UpdateFailMalformedHTLC[] = new Array(ret.length).fill(null); - for (var z = 0; z < ret.length; z++) { - const ret_conv_25: number = ret[z]; + const ret: number = bindings.CommitmentUpdate_get_update_fail_malformed_htlcs(this.ptr); + const ret_conv_25_len: number = bindings.getArrayLength(ret); + const ret_conv_25_arr: UpdateFailMalformedHTLC[] = new Array(ret_conv_25_len).fill(null); + for (var z = 0; z < ret_conv_25_len; z++) { + const ret_conv_25: number = bindings.getU32ArrayElem(ret, z); const ret_conv_25_hu_conv: UpdateFailMalformedHTLC = new UpdateFailMalformedHTLC(null, ret_conv_25); CommonBase.add_ref_from(ret_conv_25_hu_conv, this); ret_conv_25_arr[z] = ret_conv_25_hu_conv; } + bindings.freeWasmMemory(ret) return ret_conv_25_arr; } + /** + * update_fail_malformed_htlc messages which should be sent + */ public set_update_fail_malformed_htlcs(val: UpdateFailMalformedHTLC[]): void { - bindings.CommitmentUpdate_set_update_fail_malformed_htlcs(this.ptr, val != null ? val.map(val_conv_25 => val_conv_25 == null ? 0 : CommonBase.get_ptr_of(val_conv_25) & ~1) : null); + bindings.CommitmentUpdate_set_update_fail_malformed_htlcs(this.ptr, bindings.encodeUint32Array(val != null ? val.map(val_conv_25 => val_conv_25 == null ? 0 : CommonBase.get_ptr_of(val_conv_25) & ~1) : null)); } + /** + * An update_fee message which should be sent + * + * Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None + */ public get_update_fee(): UpdateFee { const ret: number = bindings.CommitmentUpdate_get_update_fee(this.ptr); const ret_hu_conv: UpdateFee = new UpdateFee(null, ret); @@ -359,10 +399,18 @@ export class CommitmentUpdate extends CommonBase { return ret_hu_conv; } + /** + * An update_fee message which should be sent + * + * Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None + */ public set_update_fee(val: UpdateFee): void { bindings.CommitmentUpdate_set_update_fee(this.ptr, val == null ? 0 : CommonBase.get_ptr_of(val) & ~1); } + /** + * Finally, the commitment_signed message which should be sent + */ public get_commitment_signed(): CommitmentSigned { const ret: number = bindings.CommitmentUpdate_get_commitment_signed(this.ptr); const ret_hu_conv: CommitmentSigned = new CommitmentSigned(null, ret); @@ -370,12 +418,18 @@ export class CommitmentUpdate extends CommonBase { return ret_hu_conv; } + /** + * Finally, the commitment_signed message which should be sent + */ public set_commitment_signed(val: CommitmentSigned): void { bindings.CommitmentUpdate_set_commitment_signed(this.ptr, val == null ? 0 : CommonBase.get_ptr_of(val) & ~1); } + /** + * Constructs a new CommitmentUpdate given each field + */ public static constructor_new(update_add_htlcs_arg: UpdateAddHTLC[], update_fulfill_htlcs_arg: UpdateFulfillHTLC[], update_fail_htlcs_arg: UpdateFailHTLC[], update_fail_malformed_htlcs_arg: UpdateFailMalformedHTLC[], update_fee_arg: UpdateFee, commitment_signed_arg: CommitmentSigned): CommitmentUpdate { - const ret: number = bindings.CommitmentUpdate_new(update_add_htlcs_arg != null ? update_add_htlcs_arg.map(update_add_htlcs_arg_conv_15 => update_add_htlcs_arg_conv_15 == null ? 0 : CommonBase.get_ptr_of(update_add_htlcs_arg_conv_15) & ~1) : null, update_fulfill_htlcs_arg != null ? update_fulfill_htlcs_arg.map(update_fulfill_htlcs_arg_conv_19 => update_fulfill_htlcs_arg_conv_19 == null ? 0 : CommonBase.get_ptr_of(update_fulfill_htlcs_arg_conv_19) & ~1) : null, update_fail_htlcs_arg != null ? update_fail_htlcs_arg.map(update_fail_htlcs_arg_conv_16 => update_fail_htlcs_arg_conv_16 == null ? 0 : CommonBase.get_ptr_of(update_fail_htlcs_arg_conv_16) & ~1) : null, update_fail_malformed_htlcs_arg != null ? update_fail_malformed_htlcs_arg.map(update_fail_malformed_htlcs_arg_conv_25 => update_fail_malformed_htlcs_arg_conv_25 == null ? 0 : CommonBase.get_ptr_of(update_fail_malformed_htlcs_arg_conv_25) & ~1) : null, update_fee_arg == null ? 0 : CommonBase.get_ptr_of(update_fee_arg) & ~1, commitment_signed_arg == null ? 0 : CommonBase.get_ptr_of(commitment_signed_arg) & ~1); + const ret: number = bindings.CommitmentUpdate_new(bindings.encodeUint32Array(update_add_htlcs_arg != null ? update_add_htlcs_arg.map(update_add_htlcs_arg_conv_15 => update_add_htlcs_arg_conv_15 == null ? 0 : CommonBase.get_ptr_of(update_add_htlcs_arg_conv_15) & ~1) : null), bindings.encodeUint32Array(update_fulfill_htlcs_arg != null ? update_fulfill_htlcs_arg.map(update_fulfill_htlcs_arg_conv_19 => update_fulfill_htlcs_arg_conv_19 == null ? 0 : CommonBase.get_ptr_of(update_fulfill_htlcs_arg_conv_19) & ~1) : null), bindings.encodeUint32Array(update_fail_htlcs_arg != null ? update_fail_htlcs_arg.map(update_fail_htlcs_arg_conv_16 => update_fail_htlcs_arg_conv_16 == null ? 0 : CommonBase.get_ptr_of(update_fail_htlcs_arg_conv_16) & ~1) : null), bindings.encodeUint32Array(update_fail_malformed_htlcs_arg != null ? update_fail_malformed_htlcs_arg.map(update_fail_malformed_htlcs_arg_conv_25 => update_fail_malformed_htlcs_arg_conv_25 == null ? 0 : CommonBase.get_ptr_of(update_fail_malformed_htlcs_arg_conv_25) & ~1) : null), update_fee_arg == null ? 0 : CommonBase.get_ptr_of(update_fee_arg) & ~1, commitment_signed_arg == null ? 0 : CommonBase.get_ptr_of(commitment_signed_arg) & ~1); const ret_hu_conv: CommitmentUpdate = new CommitmentUpdate(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; @@ -386,6 +440,9 @@ export class CommitmentUpdate extends CommonBase { return ret; } + /** + * Creates a copy of the CommitmentUpdate + */ public clone(): CommitmentUpdate { const ret: number = bindings.CommitmentUpdate_clone(this.ptr); const ret_hu_conv: CommitmentUpdate = new CommitmentUpdate(null, ret);