2 import CommonBase from './CommonBase';
3 import * as bindings from '../bindings' // TODO: figure out location
5 export default class SpendableOutputDescriptor extends CommonBase {
6 protected constructor(_dummy: object, ptr: number) { super(ptr); }
9 if (this.ptr != 0) { bindings.SpendableOutputDescriptor_free(this.ptr); }
11 static constr_from_ptr(ptr: number): SpendableOutputDescriptor {
12 const raw_val: bindings.LDKSpendableOutputDescriptor = bindings.LDKSpendableOutputDescriptor_ref_from_ptr(ptr);
13 if (raw_val instanceof bindings.LDKSpendableOutputDescriptor.StaticOutput) {
14 return new StaticOutput(this.ptr, raw_val);
16 if (raw_val instanceof bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput) {
17 return new DelayedPaymentOutput(this.ptr, raw_val);
19 if (raw_val instanceof bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput) {
20 return new StaticPaymentOutput(this.ptr, raw_val);
22 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
26 export class StaticOutput extends SpendableOutputDescriptor {
27 public outpoint: OutPoint;
29 private constructor(ptr: number, obj: bindings.LDKSpendableOutputDescriptor.StaticOutput) {
31 const outpoint: number = obj.outpoint;
32 const outpoint_hu_conv: OutPoint = new OutPoint(null, outpoint);
33 outpoint_hu_conv.ptrs_to.add(this);
34 this.outpoint = outpoint_hu_conv;
35 const output: number = obj.output;
36 TxOut output_conv = new TxOut(null, output);
37 this.output = output_conv;
40 export class DelayedPaymentOutput extends SpendableOutputDescriptor {
41 public delayed_payment_output: DelayedPaymentOutputDescriptor;
42 private constructor(ptr: number, obj: bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput) {
44 const delayed_payment_output: number = obj.delayed_payment_output;
45 const delayed_payment_output_hu_conv: DelayedPaymentOutputDescriptor = new DelayedPaymentOutputDescriptor(null, delayed_payment_output);
46 delayed_payment_output_hu_conv.ptrs_to.add(this);
47 this.delayed_payment_output = delayed_payment_output_hu_conv;
50 export class StaticPaymentOutput extends SpendableOutputDescriptor {
51 public static_payment_output: StaticPaymentOutputDescriptor;
52 private constructor(ptr: number, obj: bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput) {
54 const static_payment_output: number = obj.static_payment_output;
55 const static_payment_output_hu_conv: StaticPaymentOutputDescriptor = new StaticPaymentOutputDescriptor(null, static_payment_output);
56 static_payment_output_hu_conv.ptrs_to.add(this);
57 this.static_payment_output = static_payment_output_hu_conv;
60 public SpendableOutputDescriptor clone() {
61 number ret = bindings.SpendableOutputDescriptor_clone(this.ptr);
62 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
63 ret_hu_conv.ptrs_to.add(this);
67 public Uint8Array write() {
68 Uint8Array ret = bindings.SpendableOutputDescriptor_write(this.ptr);
72 public static Result_SpendableOutputDescriptorDecodeErrorZ constructor_read(Uint8Array ser) {
73 number ret = bindings.SpendableOutputDescriptor_read(ser);
74 Result_SpendableOutputDescriptorDecodeErrorZ ret_hu_conv = Result_SpendableOutputDescriptorDecodeErrorZ.constr_from_ptr(ret);