X-Git-Url: http://git.bitcoin.ninja/index.cgi?p=ldk-java;a=blobdiff_plain;f=ts%2Fstructs%2FOutPoint.mts;h=2a649854ea3890ab63b6958c3e3fe0d5ab2ace5c;hp=2274b645dc851eb05876983c92e7642b42ad49a9;hb=c629a01650402c8e2f9b9db8ced9ed63ce687727;hpb=d1d0121c000b713c10fd0bedd249eb8dda2e4db7 diff --git a/ts/structs/OutPoint.mts b/ts/structs/OutPoint.mts index 2274b645..2a649854 100644 --- a/ts/structs/OutPoint.mts +++ b/ts/structs/OutPoint.mts @@ -281,31 +281,52 @@ import CommonBase from './CommonBase.mjs'; import * as bindings from '../bindings.mjs' +/** + * A reference to a transaction output. + * + * Differs from bitcoin::blockdata::transaction::OutPoint as the index is a u16 instead of u32 + * due to LN's restrictions on index values. Should reduce (possibly) unsafe conversions this way. + */ export class OutPoint extends CommonBase { /* @internal */ public constructor(_dummy: object, ptr: number) { super(ptr, bindings.OutPoint_free); } + /** + * The referenced transaction's txid. + */ public get_txid(): Uint8Array { const ret: number = bindings.OutPoint_get_txid(this.ptr); const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); return ret_conv; } + /** + * The referenced transaction's txid. + */ public set_txid(val: Uint8Array): void { bindings.OutPoint_set_txid(this.ptr, bindings.encodeUint8Array(bindings.check_arr_len(val, 32))); } + /** + * The index of the referenced output in its transaction's vout. + */ public get_index(): number { const ret: number = bindings.OutPoint_get_index(this.ptr); return ret; } + /** + * The index of the referenced output in its transaction's vout. + */ public set_index(val: number): void { bindings.OutPoint_set_index(this.ptr, val); } + /** + * Constructs a new OutPoint given each field + */ public static constructor_new(txid_arg: Uint8Array, index_arg: number): OutPoint { const ret: number = bindings.OutPoint_new(bindings.encodeUint8Array(bindings.check_arr_len(txid_arg, 32)), index_arg); const ret_hu_conv: OutPoint = new OutPoint(null, ret); @@ -318,6 +339,9 @@ export class OutPoint extends CommonBase { return ret; } + /** + * Creates a copy of the OutPoint + */ public clone(): OutPoint { const ret: number = bindings.OutPoint_clone(this.ptr); const ret_hu_conv: OutPoint = new OutPoint(null, ret); @@ -325,29 +349,46 @@ export class OutPoint extends CommonBase { return ret_hu_conv; } + /** + * Checks if two OutPoints 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: OutPoint): boolean { const ret: boolean = bindings.OutPoint_eq(this.ptr, b == null ? 0 : CommonBase.get_ptr_of(b) & ~1); CommonBase.add_ref_from(this, b); return ret; } + /** + * Checks if two OutPoints contain equal inner contents. + */ public hash(): bigint { const ret: bigint = bindings.OutPoint_hash(this.ptr); return ret; } + /** + * Convert an `OutPoint` to a lightning channel id. + */ public to_channel_id(): Uint8Array { const ret: number = bindings.OutPoint_to_channel_id(this.ptr); const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); return ret_conv; } + /** + * Serialize the OutPoint object into a byte array which can be read by OutPoint_read + */ public write(): Uint8Array { const ret: number = bindings.OutPoint_write(this.ptr); const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); return ret_conv; } + /** + * Read a OutPoint from a byte array, created by OutPoint_write + */ public static constructor_read(ser: Uint8Array): Result_OutPointDecodeErrorZ { const ret: number = bindings.OutPoint_read(bindings.encodeUint8Array(ser)); const ret_hu_conv: Result_OutPointDecodeErrorZ = Result_OutPointDecodeErrorZ.constr_from_ptr(ret);