UNPKG

lightningdevkit

Version:
58 lines 2.67 kB
import { CommonBase } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs'; class LDKBroadcasterInterfaceHolder { constructor() { this.held = null; } } /** * An interface to send a transaction to the Bitcoin network. */ export class BroadcasterInterface extends CommonBase { /* @internal */ constructor(_dummy, ptr) { super(ptr, bindings.BroadcasterInterface_free); this.bindings_instance = null; } /** Creates a new instance of BroadcasterInterface from a given implementation */ static new_impl(arg) { const impl_holder = new LDKBroadcasterInterfaceHolder(); let structImplementation = { broadcast_transactions(txs) { const txs_conv_12_len = bindings.getArrayLength(txs); const txs_conv_12_arr = new Array(txs_conv_12_len).fill(null); for (var m = 0; m < txs_conv_12_len; m++) { const txs_conv_12 = bindings.getU32ArrayElem(txs, m); const txs_conv_12_conv = bindings.decodeUint8Array(txs_conv_12); txs_conv_12_arr[m] = txs_conv_12_conv; } bindings.freeWasmMemory(txs); arg.broadcast_transactions(txs_conv_12_arr); }, }; const ptr_idx = bindings.LDKBroadcasterInterface_new(structImplementation); impl_holder.held = new BroadcasterInterface(null, ptr_idx[0]); impl_holder.held.instance_idx = ptr_idx[1]; impl_holder.held.bindings_instance = structImplementation; return impl_holder.held; } /** * Sends a list of transactions out to (hopefully) be mined. * This only needs to handle the actual broadcasting of transactions, LDK will automatically * rebroadcast transactions that haven't made it into a block. * * In some cases LDK may attempt to broadcast a transaction which double-spends another * and this isn't a bug and can be safely ignored. * * If more than one transaction is given, these transactions should be considered to be a * package and broadcast together. Some of the transactions may or may not depend on each other, * be sure to manage both cases correctly. * * Bitcoin transaction packages are defined in BIP 331 and here: * <https://github.com/bitcoin/bitcoin/blob/master/doc/policy/packages.md> */ broadcast_transactions(txs) { bindings.BroadcasterInterface_broadcast_transactions(this.ptr, bindings.encodeUint32Array(txs.map(txs_conv_12 => bindings.encodeUint8Array(txs_conv_12)))); } } //# sourceMappingURL=BroadcasterInterface.mjs.map