]> git.bitcoin.ninja Git - ldk-java/blob - ts/structs/SpendableOutputDescriptor.ts
Merge pull request #50 from TheBlueMatt/main
[ldk-java] / ts / structs / SpendableOutputDescriptor.ts
1
2 import CommonBase from './CommonBase';
3 import * as bindings from '../bindings' // TODO: figure out location
4
5 export default class SpendableOutputDescriptor extends CommonBase {
6         protected constructor(_dummy: object, ptr: number) { super(ptr); }
7         protected finalize() {
8                 super.finalize();
9                 if (this.ptr != 0) { bindings.SpendableOutputDescriptor_free(this.ptr); }
10         }
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);
15                 }
16                 if (raw_val instanceof bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput) {
17                         return new DelayedPaymentOutput(this.ptr, raw_val);
18                 }
19                 if (raw_val instanceof bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput) {
20                         return new StaticPaymentOutput(this.ptr, raw_val);
21                 }
22                 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
23         }
24
25 }
26 export class StaticOutput extends SpendableOutputDescriptor {
27         public outpoint: OutPoint;
28         public output: TxOut;
29         private constructor(ptr: number, obj: bindings.LDKSpendableOutputDescriptor.StaticOutput) {
30                 super(null, ptr);
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;
38         }
39 }
40 export class DelayedPaymentOutput extends SpendableOutputDescriptor {
41         public delayed_payment_output: DelayedPaymentOutputDescriptor;
42         private constructor(ptr: number, obj: bindings.LDKSpendableOutputDescriptor.DelayedPaymentOutput) {
43                 super(null, ptr);
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;
48         }
49 }
50 export class StaticPaymentOutput extends SpendableOutputDescriptor {
51         public static_payment_output: StaticPaymentOutputDescriptor;
52         private constructor(ptr: number, obj: bindings.LDKSpendableOutputDescriptor.StaticPaymentOutput) {
53                 super(null, ptr);
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;
58         }
59 }
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);
64                 return ret_hu_conv;
65         }
66
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);
71                 return ret_hu_conv;
72         }
73
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);
78                 return ret_hu_conv;
79         }
80
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);
85                 return ret_hu_conv;
86         }
87
88         public Uint8Array write() {
89                 Uint8Array ret = bindings.SpendableOutputDescriptor_write(this.ptr);
90                 return ret;
91         }
92
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);
96                 return ret_hu_conv;
97         }
98
99 }