2 import CommonBase from './CommonBase';
3 import * as bindings from '../bindings' // TODO: figure out location
5 export default class ClosureReason extends CommonBase {
6 protected constructor(_dummy: object, ptr: number) { super(ptr); }
9 if (this.ptr != 0) { bindings.ClosureReason_free(this.ptr); }
11 static constr_from_ptr(ptr: number): ClosureReason {
12 const raw_val: bindings.LDKClosureReason = bindings.LDKClosureReason_ref_from_ptr(ptr);
13 if (raw_val instanceof bindings.LDKClosureReason.CounterpartyForceClosed) {
14 return new CounterpartyForceClosed(this.ptr, raw_val);
16 if (raw_val instanceof bindings.LDKClosureReason.HolderForceClosed) {
17 return new HolderForceClosed(this.ptr, raw_val);
19 if (raw_val instanceof bindings.LDKClosureReason.CooperativeClosure) {
20 return new CooperativeClosure(this.ptr, raw_val);
22 if (raw_val instanceof bindings.LDKClosureReason.CommitmentTxConfirmed) {
23 return new CommitmentTxConfirmed(this.ptr, raw_val);
25 if (raw_val instanceof bindings.LDKClosureReason.ProcessingError) {
26 return new ProcessingError(this.ptr, raw_val);
28 if (raw_val instanceof bindings.LDKClosureReason.DisconnectedPeer) {
29 return new DisconnectedPeer(this.ptr, raw_val);
31 if (raw_val instanceof bindings.LDKClosureReason.OutdatedChannelManager) {
32 return new OutdatedChannelManager(this.ptr, raw_val);
34 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
38 export class CounterpartyForceClosed extends ClosureReason {
39 public peer_msg: String;
40 private constructor(ptr: number, obj: bindings.LDKClosureReason.CounterpartyForceClosed) {
42 this.peer_msg = obj.peer_msg;
45 export class HolderForceClosed extends ClosureReason {
46 private constructor(ptr: number, obj: bindings.LDKClosureReason.HolderForceClosed) {
50 export class CooperativeClosure extends ClosureReason {
51 private constructor(ptr: number, obj: bindings.LDKClosureReason.CooperativeClosure) {
55 export class CommitmentTxConfirmed extends ClosureReason {
56 private constructor(ptr: number, obj: bindings.LDKClosureReason.CommitmentTxConfirmed) {
60 export class ProcessingError extends ClosureReason {
62 private constructor(ptr: number, obj: bindings.LDKClosureReason.ProcessingError) {
67 export class DisconnectedPeer extends ClosureReason {
68 private constructor(ptr: number, obj: bindings.LDKClosureReason.DisconnectedPeer) {
72 export class OutdatedChannelManager extends ClosureReason {
73 private constructor(ptr: number, obj: bindings.LDKClosureReason.OutdatedChannelManager) {
77 public ClosureReason clone() {
78 number ret = bindings.ClosureReason_clone(this.ptr);
79 ClosureReason ret_hu_conv = ClosureReason.constr_from_ptr(ret);
80 ret_hu_conv.ptrs_to.add(this);
84 public static ClosureReason constructor_counterparty_force_closed(String peer_msg) {
85 number ret = bindings.ClosureReason_counterparty_force_closed(peer_msg);
86 ClosureReason ret_hu_conv = ClosureReason.constr_from_ptr(ret);
87 ret_hu_conv.ptrs_to.add(ret_hu_conv);
91 public static ClosureReason constructor_holder_force_closed() {
92 number ret = bindings.ClosureReason_holder_force_closed();
93 ClosureReason ret_hu_conv = ClosureReason.constr_from_ptr(ret);
94 ret_hu_conv.ptrs_to.add(ret_hu_conv);
98 public static ClosureReason constructor_cooperative_closure() {
99 number ret = bindings.ClosureReason_cooperative_closure();
100 ClosureReason ret_hu_conv = ClosureReason.constr_from_ptr(ret);
101 ret_hu_conv.ptrs_to.add(ret_hu_conv);
105 public static ClosureReason constructor_commitment_tx_confirmed() {
106 number ret = bindings.ClosureReason_commitment_tx_confirmed();
107 ClosureReason ret_hu_conv = ClosureReason.constr_from_ptr(ret);
108 ret_hu_conv.ptrs_to.add(ret_hu_conv);
112 public static ClosureReason constructor_processing_error(String err) {
113 number ret = bindings.ClosureReason_processing_error(err);
114 ClosureReason ret_hu_conv = ClosureReason.constr_from_ptr(ret);
115 ret_hu_conv.ptrs_to.add(ret_hu_conv);
119 public static ClosureReason constructor_disconnected_peer() {
120 number ret = bindings.ClosureReason_disconnected_peer();
121 ClosureReason ret_hu_conv = ClosureReason.constr_from_ptr(ret);
122 ret_hu_conv.ptrs_to.add(ret_hu_conv);
126 public static ClosureReason constructor_outdated_channel_manager() {
127 number ret = bindings.ClosureReason_outdated_channel_manager();
128 ClosureReason ret_hu_conv = ClosureReason.constr_from_ptr(ret);
129 ret_hu_conv.ptrs_to.add(ret_hu_conv);
133 public Uint8Array write() {
134 Uint8Array ret = bindings.ClosureReason_write(this.ptr);