UNPKG

lightningdevkit

Version:
109 lines 3.86 kB
import { TxOut } from '../structs/TxOut.mjs'; import { OutPoint } from '../structs/OutPoint.mjs'; import { CommonBase } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs'; /** * An unspent transaction output that is available to spend resulting from a successful * [`CoinSelection`] attempt. */ export class Utxo extends CommonBase { /* @internal */ constructor(_dummy, ptr) { super(ptr, bindings.Utxo_free); } /** * The unique identifier of the output. */ get_outpoint() { const ret = bindings.Utxo_get_outpoint(this.ptr); const ret_hu_conv = new OutPoint(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * The unique identifier of the output. */ set_outpoint(val) { bindings.Utxo_set_outpoint(this.ptr, CommonBase.get_ptr_of(val)); } /** * The output to spend. */ get_output() { const ret = bindings.Utxo_get_output(this.ptr); const ret_conv = new TxOut(null, ret); return ret_conv; } /** * The output to spend. */ set_output(val) { bindings.Utxo_set_output(this.ptr, CommonBase.get_ptr_of(val)); } /** * The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and [`TxIn::witness`], each * with their lengths included, required to satisfy the output's script. The weight consumed by * the input's `script_sig` must account for [`WITNESS_SCALE_FACTOR`]. */ get_satisfaction_weight() { const ret = bindings.Utxo_get_satisfaction_weight(this.ptr); return ret; } /** * The upper-bound weight consumed by the input's full [`TxIn::script_sig`] and [`TxIn::witness`], each * with their lengths included, required to satisfy the output's script. The weight consumed by * the input's `script_sig` must account for [`WITNESS_SCALE_FACTOR`]. */ set_satisfaction_weight(val) { bindings.Utxo_set_satisfaction_weight(this.ptr, val); } /** * Constructs a new Utxo given each field */ static constructor_new(outpoint_arg, output_arg, satisfaction_weight_arg) { const ret = bindings.Utxo_new(CommonBase.get_ptr_of(outpoint_arg), CommonBase.get_ptr_of(output_arg), satisfaction_weight_arg); const ret_hu_conv = new Utxo(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } clone_ptr() { const ret = bindings.Utxo_clone_ptr(this.ptr); return ret; } /** * Creates a copy of the Utxo */ clone() { const ret = bindings.Utxo_clone(this.ptr); const ret_hu_conv = new Utxo(null, ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Generates a non-cryptographic 64-bit hash of the Utxo. */ hash() { const ret = bindings.Utxo_hash(this.ptr); return ret; } /** * Checks if two Utxos 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. */ eq(b) { const ret = bindings.Utxo_eq(this.ptr, CommonBase.get_ptr_of(b)); CommonBase.add_ref_from(this, b); return ret; } /** * Returns a `Utxo` with the `satisfaction_weight` estimate for a legacy P2PKH output. */ static constructor_new_p2pkh(outpoint, value, pubkey_hash) { const ret = bindings.Utxo_new_p2pkh(CommonBase.get_ptr_of(outpoint), value, bindings.encodeUint8Array(pubkey_hash)); const ret_hu_conv = new Utxo(null, ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } } //# sourceMappingURL=Utxo.mjs.map