import CommonBase from './CommonBase.mjs';
import * as bindings from '../bindings.mjs'
-import * as InternalUtils from '../InternalUtils.mjs'
+/**
+ * When on-chain outputs are created by rust-lightning (which our counterparty is not able to
+ * claim at any point in the future) an event is generated which you must track and be able to
+ * spend on-chain. The information needed to do this is provided in this enum, including the
+ * outpoint describing which txid and output index is available, the full output which exists at
+ * that txid/index, and any keys or other information required to sign.
+ */
export class SpendableOutputDescriptor extends CommonBase {
protected constructor(_dummy: object, ptr: number) { super(ptr, bindings.SpendableOutputDescriptor_free); }
/* @internal */
public static constr_from_ptr(ptr: number): SpendableOutputDescriptor {
- const raw_val: bindings.LDKSpendableOutputDescriptor = bindings.LDKSpendableOutputDescriptor_ref_from_ptr(ptr);
- if (raw_val instanceof bindings.LDKSpendableOutputDescriptor_StaticOutput) {
- return new SpendableOutputDescriptor_StaticOutput(ptr, raw_val);
+ const raw_ty: number = bindings.LDKSpendableOutputDescriptor_ty_from_ptr(ptr);
+ switch (raw_ty) {
+ case 0: return new SpendableOutputDescriptor_StaticOutput(ptr);
+ case 1: return new SpendableOutputDescriptor_DelayedPaymentOutput(ptr);
+ case 2: return new SpendableOutputDescriptor_StaticPaymentOutput(ptr);
+ default:
+ throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
}
- if (raw_val instanceof bindings.LDKSpendableOutputDescriptor_DelayedPaymentOutput) {
- return new SpendableOutputDescriptor_DelayedPaymentOutput(ptr, raw_val);
- }
- if (raw_val instanceof bindings.LDKSpendableOutputDescriptor_StaticPaymentOutput) {
- return new SpendableOutputDescriptor_StaticPaymentOutput(ptr, raw_val);
- }
- throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
}
public clone_ptr(): number {
return ret;
}
+ /**
+ * Creates a copy of the SpendableOutputDescriptor
+ */
public clone(): SpendableOutputDescriptor {
const ret: number = bindings.SpendableOutputDescriptor_clone(this.ptr);
const ret_hu_conv: SpendableOutputDescriptor = SpendableOutputDescriptor.constr_from_ptr(ret);
return ret_hu_conv;
}
+ /**
+ * Utility method to constructs a new StaticOutput-variant SpendableOutputDescriptor
+ */
public static constructor_static_output(outpoint: OutPoint, output: TxOut): SpendableOutputDescriptor {
const ret: number = bindings.SpendableOutputDescriptor_static_output(outpoint == null ? 0 : CommonBase.get_ptr_of(outpoint) & ~1, CommonBase.get_ptr_of(output));
const ret_hu_conv: SpendableOutputDescriptor = SpendableOutputDescriptor.constr_from_ptr(ret);
return ret_hu_conv;
}
+ /**
+ * Utility method to constructs a new DelayedPaymentOutput-variant SpendableOutputDescriptor
+ */
public static constructor_delayed_payment_output(a: DelayedPaymentOutputDescriptor): SpendableOutputDescriptor {
const ret: number = bindings.SpendableOutputDescriptor_delayed_payment_output(a == null ? 0 : CommonBase.get_ptr_of(a) & ~1);
const ret_hu_conv: SpendableOutputDescriptor = SpendableOutputDescriptor.constr_from_ptr(ret);
return ret_hu_conv;
}
+ /**
+ * Utility method to constructs a new StaticPaymentOutput-variant SpendableOutputDescriptor
+ */
public static constructor_static_payment_output(a: StaticPaymentOutputDescriptor): SpendableOutputDescriptor {
const ret: number = bindings.SpendableOutputDescriptor_static_payment_output(a == null ? 0 : CommonBase.get_ptr_of(a) & ~1);
const ret_hu_conv: SpendableOutputDescriptor = SpendableOutputDescriptor.constr_from_ptr(ret);
return ret_hu_conv;
}
+ /**
+ * Serialize the SpendableOutputDescriptor object into a byte array which can be read by SpendableOutputDescriptor_read
+ */
public write(): Uint8Array {
- const ret: Uint8Array = bindings.SpendableOutputDescriptor_write(this.ptr);
- return ret;
+ const ret: number = bindings.SpendableOutputDescriptor_write(this.ptr);
+ const ret_conv: Uint8Array = bindings.decodeUint8Array(ret);
+ return ret_conv;
}
+ /**
+ * Read a SpendableOutputDescriptor from a byte array, created by SpendableOutputDescriptor_write
+ */
public static constructor_read(ser: Uint8Array): Result_SpendableOutputDescriptorDecodeErrorZ {
- const ret: number = bindings.SpendableOutputDescriptor_read(ser);
+ const ret: number = bindings.SpendableOutputDescriptor_read(bindings.encodeUint8Array(ser));
const ret_hu_conv: Result_SpendableOutputDescriptorDecodeErrorZ = Result_SpendableOutputDescriptorDecodeErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}
}
+/** A SpendableOutputDescriptor of type StaticOutput */
export class SpendableOutputDescriptor_StaticOutput extends SpendableOutputDescriptor {
+ /**
+ * The outpoint which is spendable
+ */
public outpoint: OutPoint;
+ /**
+ * The output which is referenced by the given outpoint.
+ */
public output: TxOut;
/* @internal */
- public constructor(ptr: number, obj: bindings.LDKSpendableOutputDescriptor_StaticOutput) {
+ public constructor(ptr: number) {
super(null, ptr);
- const outpoint: number = obj.outpoint;
+ const outpoint: number = bindings.LDKSpendableOutputDescriptor_StaticOutput_get_outpoint(ptr);
const outpoint_hu_conv: OutPoint = new OutPoint(null, outpoint);
CommonBase.add_ref_from(outpoint_hu_conv, this);
this.outpoint = outpoint_hu_conv;
- const output: number = obj.output;
+ const output: number = bindings.LDKSpendableOutputDescriptor_StaticOutput_get_output(ptr);
const output_conv: TxOut = new TxOut(null, output);
this.output = output_conv;
}
}
+/** A SpendableOutputDescriptor of type DelayedPaymentOutput */
export class SpendableOutputDescriptor_DelayedPaymentOutput extends SpendableOutputDescriptor {
public delayed_payment_output: DelayedPaymentOutputDescriptor;
/* @internal */
- public constructor(ptr: number, obj: bindings.LDKSpendableOutputDescriptor_DelayedPaymentOutput) {
+ public constructor(ptr: number) {
super(null, ptr);
- const delayed_payment_output: number = obj.delayed_payment_output;
+ const delayed_payment_output: number = bindings.LDKSpendableOutputDescriptor_DelayedPaymentOutput_get_delayed_payment_output(ptr);
const delayed_payment_output_hu_conv: DelayedPaymentOutputDescriptor = new DelayedPaymentOutputDescriptor(null, delayed_payment_output);
CommonBase.add_ref_from(delayed_payment_output_hu_conv, this);
this.delayed_payment_output = delayed_payment_output_hu_conv;
}
}
+/** A SpendableOutputDescriptor of type StaticPaymentOutput */
export class SpendableOutputDescriptor_StaticPaymentOutput extends SpendableOutputDescriptor {
public static_payment_output: StaticPaymentOutputDescriptor;
/* @internal */
- public constructor(ptr: number, obj: bindings.LDKSpendableOutputDescriptor_StaticPaymentOutput) {
+ public constructor(ptr: number) {
super(null, ptr);
- const static_payment_output: number = obj.static_payment_output;
+ const static_payment_output: number = bindings.LDKSpendableOutputDescriptor_StaticPaymentOutput_get_static_payment_output(ptr);
const static_payment_output_hu_conv: StaticPaymentOutputDescriptor = new StaticPaymentOutputDescriptor(null, static_payment_output);
CommonBase.add_ref_from(static_payment_output_hu_conv, this);
this.static_payment_output = static_payment_output_hu_conv;