UNPKG

lightningdevkit

Version:
104 lines 4.08 kB
import { OutPoint } from '../structs/OutPoint.mjs'; import { Result_FundingInfoDecodeErrorZ } from '../structs/Result_FundingInfoDecodeErrorZ.mjs'; import { CommonBase } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs'; /** * `FundingInfo` holds information about a channel's funding transaction. * * When LDK is set to manual propagation of the funding transaction * (via [`ChannelManager::unsafe_manual_funding_transaction_generated`), * LDK does not have the full transaction data. Instead, the `OutPoint` * for the funding is provided here. * * [`ChannelManager::unsafe_manual_funding_transaction_generated`]: crate::ln::channelmanager::ChannelManager::unsafe_manual_funding_transaction_generated */ export class FundingInfo extends CommonBase { constructor(_dummy, ptr) { super(ptr, bindings.FundingInfo_free); } /* @internal */ static constr_from_ptr(ptr) { const raw_ty = bindings.LDKFundingInfo_ty_from_ptr(ptr); switch (raw_ty) { case 0: return new FundingInfo_Tx(ptr); case 1: return new FundingInfo_OutPoint(ptr); default: throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface } } clone_ptr() { const ret = bindings.FundingInfo_clone_ptr(this.ptr); return ret; } /** * Creates a copy of the FundingInfo */ clone() { const ret = bindings.FundingInfo_clone(this.ptr); const ret_hu_conv = FundingInfo.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Utility method to constructs a new Tx-variant FundingInfo */ static constructor_tx(transaction) { const ret = bindings.FundingInfo_tx(bindings.encodeUint8Array(transaction)); const ret_hu_conv = FundingInfo.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } /** * Utility method to constructs a new OutPoint-variant FundingInfo */ static constructor_out_point(outpoint) { const ret = bindings.FundingInfo_out_point(CommonBase.get_ptr_of(outpoint)); const ret_hu_conv = FundingInfo.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } /** * Checks if two FundingInfos contain equal inner contents. * This ignores pointers and is_owned flags and looks at the values in fields. */ eq(b) { const ret = bindings.FundingInfo_eq(this.ptr, CommonBase.get_ptr_of(b)); return ret; } /** * Serialize the FundingInfo object into a byte array which can be read by FundingInfo_read */ write() { const ret = bindings.FundingInfo_write(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * Read a FundingInfo from a byte array, created by FundingInfo_write */ static constructor_read(ser) { const ret = bindings.FundingInfo_read(bindings.encodeUint8Array(ser)); const ret_hu_conv = Result_FundingInfoDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } } /** A FundingInfo of type Tx */ export class FundingInfo_Tx extends FundingInfo { /* @internal */ constructor(ptr) { super(null, ptr); const transaction = bindings.LDKFundingInfo_Tx_get_transaction(ptr); const transaction_conv = bindings.decodeUint8Array(transaction); this.transaction = transaction_conv; } } /** A FundingInfo of type OutPoint */ export class FundingInfo_OutPoint extends FundingInfo { /* @internal */ constructor(ptr) { super(null, ptr); const outpoint = bindings.LDKFundingInfo_OutPoint_get_outpoint(ptr); const outpoint_hu_conv = new OutPoint(null, outpoint); CommonBase.add_ref_from(outpoint_hu_conv, this); this.outpoint = outpoint_hu_conv; } } //# sourceMappingURL=FundingInfo.mjs.map