2 import CommonBase from './CommonBase';
3 import * as bindings from '../bindings' // TODO: figure out location
5 export default class Fallback extends CommonBase {
6 protected constructor(_dummy: object, ptr: number) { super(ptr); }
9 if (this.ptr != 0) { bindings.Fallback_free(this.ptr); }
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);
16 if (raw_val instanceof bindings.LDKFallback.PubKeyHash) {
17 return new PubKeyHash(this.ptr, raw_val);
19 if (raw_val instanceof bindings.LDKFallback.ScriptHash) {
20 return new ScriptHash(this.ptr, raw_val);
22 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
26 export class SegWitProgram extends Fallback {
27 public version: UInt5;
28 public program: Uint8Array;
29 private constructor(ptr: number, obj: bindings.LDKFallback.SegWitProgram) {
31 const version: number = obj.version;
32 UInt5 version_conv = new UInt5(version);
33 this.version = version_conv;
34 this.program = obj.program;
37 export class PubKeyHash extends Fallback {
38 public pub_key_hash: Uint8Array;
39 private constructor(ptr: number, obj: bindings.LDKFallback.PubKeyHash) {
41 this.pub_key_hash = obj.pub_key_hash;
44 export class ScriptHash extends Fallback {
45 public script_hash: Uint8Array;
46 private constructor(ptr: number, obj: bindings.LDKFallback.ScriptHash) {
48 this.script_hash = obj.script_hash;
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);
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);
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);
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);
79 public number hash() {
80 number ret = bindings.Fallback_hash(this.ptr);
84 public boolean eq(Fallback b) {
85 boolean ret = bindings.Fallback_eq(this.ptr, b == null ? 0 : b.ptr & ~1);