X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=ts%2Fstructs%2FRouteHint.mts;h=fb8079d7f04fec2a5c36941713e2754687fabfd2;hb=6700d1496b231c4b27d91a66be0d5efdb741662c;hp=150854497fb25f986d29878d86da8a3f42722190;hpb=2a65456aa0b540060dcf3ca707a54dc98cc3f38a;p=ldk-java diff --git a/ts/structs/RouteHint.mts b/ts/structs/RouteHint.mts index 15085449..fb8079d7 100644 --- a/ts/structs/RouteHint.mts +++ b/ts/structs/RouteHint.mts @@ -279,9 +279,11 @@ import { MultiThreadedLockableScore } from '../structs/MultiThreadedLockableScor import CommonBase from './CommonBase.mjs'; import * as bindings from '../bindings.mjs' -import * as InternalUtils from '../InternalUtils.mjs' +/** + * A list of hops along a payment path terminating with a channel to the recipient. + */ export class RouteHint extends CommonBase { /* @internal */ public constructor(_dummy: object, ptr: number) { @@ -289,23 +291,28 @@ export class RouteHint extends CommonBase { } public get_a(): RouteHintHop[] { - const ret: number[] = bindings.RouteHint_get_a(this.ptr); - const ret_conv_14_arr: RouteHintHop[] = new Array(ret.length).fill(null); - for (var o = 0; o < ret.length; o++) { - const ret_conv_14: number = ret[o]; + const ret: number = bindings.RouteHint_get_a(this.ptr); + const ret_conv_14_len: number = bindings.getArrayLength(ret); + const ret_conv_14_arr: RouteHintHop[] = new Array(ret_conv_14_len).fill(null); + for (var o = 0; o < ret_conv_14_len; o++) { + const ret_conv_14: number = bindings.getU32ArrayElem(ret, o); const ret_conv_14_hu_conv: RouteHintHop = new RouteHintHop(null, ret_conv_14); CommonBase.add_ref_from(ret_conv_14_hu_conv, this); ret_conv_14_arr[o] = ret_conv_14_hu_conv; } + bindings.freeWasmMemory(ret) return ret_conv_14_arr; } public set_a(val: RouteHintHop[]): void { - bindings.RouteHint_set_a(this.ptr, val != null ? val.map(val_conv_14 => val_conv_14 == null ? 0 : CommonBase.get_ptr_of(val_conv_14) & ~1) : null); + bindings.RouteHint_set_a(this.ptr, bindings.encodeUint32Array(val != null ? val.map(val_conv_14 => val_conv_14 == null ? 0 : CommonBase.get_ptr_of(val_conv_14) & ~1) : null)); } + /** + * Constructs a new RouteHint given each field + */ public static constructor_new(a_arg: RouteHintHop[]): RouteHint { - const ret: number = bindings.RouteHint_new(a_arg != null ? a_arg.map(a_arg_conv_14 => a_arg_conv_14 == null ? 0 : CommonBase.get_ptr_of(a_arg_conv_14) & ~1) : null); + const ret: number = bindings.RouteHint_new(bindings.encodeUint32Array(a_arg != null ? a_arg.map(a_arg_conv_14 => a_arg_conv_14 == null ? 0 : CommonBase.get_ptr_of(a_arg_conv_14) & ~1) : null)); const ret_hu_conv: RouteHint = new RouteHint(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; @@ -316,6 +323,9 @@ export class RouteHint extends CommonBase { return ret; } + /** + * Creates a copy of the RouteHint + */ public clone(): RouteHint { const ret: number = bindings.RouteHint_clone(this.ptr); const ret_hu_conv: RouteHint = new RouteHint(null, ret); @@ -323,24 +333,39 @@ export class RouteHint extends CommonBase { return ret_hu_conv; } - public hash(): number { - const ret: number = bindings.RouteHint_hash(this.ptr); + /** + * Checks if two RouteHints contain equal inner contents. + */ + public hash(): bigint { + const ret: bigint = bindings.RouteHint_hash(this.ptr); return ret; } + /** + * Checks if two RouteHints 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 eq(b: RouteHint): boolean { const ret: boolean = bindings.RouteHint_eq(this.ptr, b == null ? 0 : CommonBase.get_ptr_of(b) & ~1); CommonBase.add_ref_from(this, b); return ret; } + /** + * Serialize the RouteHint object into a byte array which can be read by RouteHint_read + */ public write(): Uint8Array { - const ret: Uint8Array = bindings.RouteHint_write(this.ptr); - return ret; + const ret: number = bindings.RouteHint_write(this.ptr); + const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); + return ret_conv; } + /** + * Read a RouteHint from a byte array, created by RouteHint_write + */ public static constructor_read(ser: Uint8Array): Result_RouteHintDecodeErrorZ { - const ret: number = bindings.RouteHint_read(ser); + const ret: number = bindings.RouteHint_read(bindings.encodeUint8Array(ser)); const ret_hu_conv: Result_RouteHintDecodeErrorZ = Result_RouteHintDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; }