]> git.bitcoin.ninja Git - ldk-java/blob - ts/structs/Fallback.ts
Merge pull request #47 from TheBlueMatt/main
[ldk-java] / ts / structs / Fallback.ts
1
2 import CommonBase from './CommonBase';
3 import * as bindings from '../bindings' // TODO: figure out location
4
5 export default class Fallback extends CommonBase {
6         protected constructor(_dummy: object, ptr: number) { super(ptr); }
7         protected finalize() {
8                 super.finalize();
9                 if (this.ptr != 0) { bindings.Fallback_free(this.ptr); }
10         }
11         static constr_from_ptr(ptr: number): Fallback {
12                 const raw_val: bindings.LDKFallback = bindings.LDKFallback_ref_from_ptr(ptr);
13                 if (raw_val instanceof bindings.LDKFallback.SegWitProgram) {
14                         return new SegWitProgram(this.ptr, raw_val);
15                 }
16                 if (raw_val instanceof bindings.LDKFallback.PubKeyHash) {
17                         return new PubKeyHash(this.ptr, raw_val);
18                 }
19                 if (raw_val instanceof bindings.LDKFallback.ScriptHash) {
20                         return new ScriptHash(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 SegWitProgram extends Fallback {
27         public version: UInt5;
28         public program: Uint8Array;
29         private constructor(ptr: number, obj: bindings.LDKFallback.SegWitProgram) {
30                 super(null, ptr);
31                 const version: number = obj.version;
32                 UInt5 version_conv = new UInt5(version);
33                 this.version = version_conv;
34                 this.program = obj.program;
35         }
36 }
37 export class PubKeyHash extends Fallback {
38         public pub_key_hash: Uint8Array;
39         private constructor(ptr: number, obj: bindings.LDKFallback.PubKeyHash) {
40                 super(null, ptr);
41                 this.pub_key_hash = obj.pub_key_hash;
42         }
43 }
44 export class ScriptHash extends Fallback {
45         public script_hash: Uint8Array;
46         private constructor(ptr: number, obj: bindings.LDKFallback.ScriptHash) {
47                 super(null, ptr);
48                 this.script_hash = obj.script_hash;
49         }
50 }
51         public Fallback clone() {
52                 number ret = bindings.Fallback_clone(this.ptr);
53                 Fallback ret_hu_conv = Fallback.constr_from_ptr(ret);
54                 ret_hu_conv.ptrs_to.add(this);
55                 return ret_hu_conv;
56         }
57
58         public static Fallback constructor_seg_wit_program(UInt5 version, Uint8Array program) {
59                 number ret = bindings.Fallback_seg_wit_program(version.getVal(), program);
60                 Fallback ret_hu_conv = Fallback.constr_from_ptr(ret);
61                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
62                 return ret_hu_conv;
63         }
64
65         public static Fallback constructor_pub_key_hash(Uint8Array a) {
66                 number ret = bindings.Fallback_pub_key_hash(a);
67                 Fallback ret_hu_conv = Fallback.constr_from_ptr(ret);
68                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
69                 return ret_hu_conv;
70         }
71
72         public static Fallback constructor_script_hash(Uint8Array a) {
73                 number ret = bindings.Fallback_script_hash(a);
74                 Fallback ret_hu_conv = Fallback.constr_from_ptr(ret);
75                 ret_hu_conv.ptrs_to.add(ret_hu_conv);
76                 return ret_hu_conv;
77         }
78
79         public number hash() {
80                 number ret = bindings.Fallback_hash(this.ptr);
81                 return ret;
82         }
83
84         public boolean eq(Fallback b) {
85                 boolean ret = bindings.Fallback_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
86                 return ret;
87         }
88
89 }