2 import CommonBase from './CommonBase';
3 import * as bindings from '../bindings' // TODO: figure out location
5 export default class ErrorAction extends CommonBase {
6 protected constructor(_dummy: object, ptr: number) { super(ptr); }
9 if (this.ptr != 0) { bindings.ErrorAction_free(this.ptr); }
11 static constr_from_ptr(ptr: number): ErrorAction {
12 const raw_val: bindings.LDKErrorAction = bindings.LDKErrorAction_ref_from_ptr(ptr);
13 if (raw_val instanceof bindings.LDKErrorAction.DisconnectPeer) {
14 return new DisconnectPeer(this.ptr, raw_val);
16 if (raw_val instanceof bindings.LDKErrorAction.IgnoreError) {
17 return new IgnoreError(this.ptr, raw_val);
19 if (raw_val instanceof bindings.LDKErrorAction.IgnoreAndLog) {
20 return new IgnoreAndLog(this.ptr, raw_val);
22 if (raw_val instanceof bindings.LDKErrorAction.SendErrorMessage) {
23 return new SendErrorMessage(this.ptr, raw_val);
25 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
29 export class DisconnectPeer extends ErrorAction {
30 public msg: ErrorMessage;
31 private constructor(ptr: number, obj: bindings.LDKErrorAction.DisconnectPeer) {
33 const msg: number = obj.msg;
34 const msg_hu_conv: ErrorMessage = new ErrorMessage(null, msg);
35 msg_hu_conv.ptrs_to.add(this);
36 this.msg = msg_hu_conv;
39 export class IgnoreError extends ErrorAction {
40 private constructor(ptr: number, obj: bindings.LDKErrorAction.IgnoreError) {
44 export class IgnoreAndLog extends ErrorAction {
45 public ignore_and_log: Level;
46 private constructor(ptr: number, obj: bindings.LDKErrorAction.IgnoreAndLog) {
48 this.ignore_and_log = obj.ignore_and_log;
51 export class SendErrorMessage extends ErrorAction {
52 public msg: ErrorMessage;
53 private constructor(ptr: number, obj: bindings.LDKErrorAction.SendErrorMessage) {
55 const msg: number = obj.msg;
56 const msg_hu_conv: ErrorMessage = new ErrorMessage(null, msg);
57 msg_hu_conv.ptrs_to.add(this);
58 this.msg = msg_hu_conv;
61 public ErrorAction clone() {
62 number ret = bindings.ErrorAction_clone(this.ptr);
63 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
64 ret_hu_conv.ptrs_to.add(this);
68 public static ErrorAction constructor_disconnect_peer(ErrorMessage msg) {
69 number ret = bindings.ErrorAction_disconnect_peer(msg == null ? 0 : msg.ptr & ~1);
70 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
71 ret_hu_conv.ptrs_to.add(ret_hu_conv);
75 public static ErrorAction constructor_ignore_error() {
76 number ret = bindings.ErrorAction_ignore_error();
77 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
78 ret_hu_conv.ptrs_to.add(ret_hu_conv);
82 public static ErrorAction constructor_ignore_and_log(Level a) {
83 number ret = bindings.ErrorAction_ignore_and_log(a);
84 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
85 ret_hu_conv.ptrs_to.add(ret_hu_conv);
89 public static ErrorAction constructor_send_error_message(ErrorMessage msg) {
90 number ret = bindings.ErrorAction_send_error_message(msg == null ? 0 : msg.ptr & ~1);
91 ErrorAction ret_hu_conv = ErrorAction.constr_from_ptr(ret);
92 ret_hu_conv.ptrs_to.add(ret_hu_conv);