X-Git-Url: http://git.bitcoin.ninja/index.cgi?a=blobdiff_plain;f=ts%2Fstructs%2FClosingTransaction.mts;h=cd5ff8462655763703e5dd2217922664422a80ff;hb=eab69282af298d16b07eaf3b7bdda07e184033cd;hp=cf75b7fdffbb240244efa5e3d573469e4f3ed466;hpb=2a65456aa0b540060dcf3ca707a54dc98cc3f38a;p=ldk-java diff --git a/ts/structs/ClosingTransaction.mts b/ts/structs/ClosingTransaction.mts index cf75b7fd..cd5ff846 100644 --- a/ts/structs/ClosingTransaction.mts +++ b/ts/structs/ClosingTransaction.mts @@ -279,9 +279,15 @@ import { MultiThreadedLockableScore } from '../structs/MultiThreadedLockableScor import CommonBase from './CommonBase.mjs'; import * as bindings from '../bindings.mjs' -import * as InternalUtils from '../InternalUtils.mjs' +/** + * This class tracks the per-transaction information needed to build a closing transaction and will + * actually build it and sign. + * + * This class can be used inside a signer implementation to generate a signature given the relevant + * secret key. + */ export class ClosingTransaction extends CommonBase { /* @internal */ public constructor(_dummy: object, ptr: number) { @@ -293,6 +299,9 @@ export class ClosingTransaction extends CommonBase { return ret; } + /** + * Creates a copy of the ClosingTransaction + */ public clone(): ClosingTransaction { const ret: number = bindings.ClosingTransaction_clone(this.ptr); const ret_hu_conv: ClosingTransaction = new ClosingTransaction(null, ret); @@ -300,18 +309,32 @@ export class ClosingTransaction extends CommonBase { return ret_hu_conv; } - public hash(): number { - const ret: number = bindings.ClosingTransaction_hash(this.ptr); + /** + * Checks if two ClosingTransactions contain equal inner contents. + */ + public hash(): bigint { + const ret: bigint = bindings.ClosingTransaction_hash(this.ptr); return ret; } - public static constructor_new(to_holder_value_sat: number, to_counterparty_value_sat: number, to_holder_script: Uint8Array, to_counterparty_script: Uint8Array, funding_outpoint: OutPoint): ClosingTransaction { - const ret: number = bindings.ClosingTransaction_new(to_holder_value_sat, to_counterparty_value_sat, to_holder_script, to_counterparty_script, funding_outpoint == null ? 0 : CommonBase.get_ptr_of(funding_outpoint) & ~1); + /** + * Construct an object of the class + */ + public static constructor_new(to_holder_value_sat: bigint, to_counterparty_value_sat: bigint, to_holder_script: Uint8Array, to_counterparty_script: Uint8Array, funding_outpoint: OutPoint): ClosingTransaction { + const ret: number = bindings.ClosingTransaction_new(to_holder_value_sat, to_counterparty_value_sat, bindings.encodeUint8Array(to_holder_script), bindings.encodeUint8Array(to_counterparty_script), funding_outpoint == null ? 0 : CommonBase.get_ptr_of(funding_outpoint) & ~1); const ret_hu_conv: ClosingTransaction = new ClosingTransaction(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } + /** + * Trust our pre-built transaction. + * + * Applies a wrapper which allows access to the transaction. + * + * This should only be used if you fully trust the builder of this object. It should not + * be used by an external signer - instead use the verify function. + */ public trust(): TrustedClosingTransaction { const ret: number = bindings.ClosingTransaction_trust(this.ptr); const ret_hu_conv: TrustedClosingTransaction = new TrustedClosingTransaction(null, ret); @@ -319,30 +342,52 @@ export class ClosingTransaction extends CommonBase { return ret_hu_conv; } + /** + * Verify our pre-built transaction. + * + * Applies a wrapper which allows access to the transaction. + * + * An external validating signer must call this method before signing + * or using the built transaction. + */ public verify(funding_outpoint: OutPoint): Result_TrustedClosingTransactionNoneZ { const ret: number = bindings.ClosingTransaction_verify(this.ptr, funding_outpoint == null ? 0 : CommonBase.get_ptr_of(funding_outpoint) & ~1); const ret_hu_conv: Result_TrustedClosingTransactionNoneZ = Result_TrustedClosingTransactionNoneZ.constr_from_ptr(ret); return ret_hu_conv; } - public to_holder_value_sat(): number { - const ret: number = bindings.ClosingTransaction_to_holder_value_sat(this.ptr); + /** + * The value to be sent to the holder, or zero if the output will be omitted + */ + public to_holder_value_sat(): bigint { + const ret: bigint = bindings.ClosingTransaction_to_holder_value_sat(this.ptr); return ret; } - public to_counterparty_value_sat(): number { - const ret: number = bindings.ClosingTransaction_to_counterparty_value_sat(this.ptr); + /** + * The value to be sent to the counterparty, or zero if the output will be omitted + */ + public to_counterparty_value_sat(): bigint { + const ret: bigint = bindings.ClosingTransaction_to_counterparty_value_sat(this.ptr); return ret; } + /** + * The destination of the holder's output + */ public to_holder_script(): Uint8Array { - const ret: Uint8Array = bindings.ClosingTransaction_to_holder_script(this.ptr); - return ret; + const ret: number = bindings.ClosingTransaction_to_holder_script(this.ptr); + const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); + return ret_conv; } + /** + * The destination of the counterparty's output + */ public to_counterparty_script(): Uint8Array { - const ret: Uint8Array = bindings.ClosingTransaction_to_counterparty_script(this.ptr); - return ret; + const ret: number = bindings.ClosingTransaction_to_counterparty_script(this.ptr); + const ret_conv: Uint8Array = bindings.decodeUint8Array(ret); + return ret_conv; } }