]> git.bitcoin.ninja Git - ldk-java/blob - ts/structs/Fallback.ts
Merge pull request #20 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 boolean eq(Fallback b) {
59                 boolean ret = bindings.Fallback_eq(this.ptr, b == null ? 0 : b.ptr & ~1);
60                 this.ptrs_to.add(b);
61                 return ret;
62         }
63
64 }