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 static SpendableOutputDescriptor constructor_static_output(OutPoint outpoint, TxOut output) {
68 number ret = bindings.SpendableOutputDescriptor_static_output(outpoint == null ? 0 : outpoint.ptr & ~1, output.ptr);
69 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
70 ret_hu_conv.ptrs_to.add(ret_hu_conv);
74 public static SpendableOutputDescriptor constructor_delayed_payment_output(DelayedPaymentOutputDescriptor a) {
75 number ret = bindings.SpendableOutputDescriptor_delayed_payment_output(a == null ? 0 : a.ptr & ~1);
76 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
77 ret_hu_conv.ptrs_to.add(ret_hu_conv);
81 public static SpendableOutputDescriptor constructor_static_payment_output(StaticPaymentOutputDescriptor a) {
82 number ret = bindings.SpendableOutputDescriptor_static_payment_output(a == null ? 0 : a.ptr & ~1);
83 SpendableOutputDescriptor ret_hu_conv = SpendableOutputDescriptor.constr_from_ptr(ret);
84 ret_hu_conv.ptrs_to.add(ret_hu_conv);
88 public Uint8Array write() {
89 Uint8Array ret = bindings.SpendableOutputDescriptor_write(this.ptr);
93 public static Result_SpendableOutputDescriptorDecodeErrorZ constructor_read(Uint8Array ser) {
94 number ret = bindings.SpendableOutputDescriptor_read(ser);
95 Result_SpendableOutputDescriptorDecodeErrorZ ret_hu_conv = Result_SpendableOutputDescriptorDecodeErrorZ.constr_from_ptr(ret);