import CommonBase from './CommonBase.mjs';
import * as bindings from '../bindings.mjs'
-import * as InternalUtils from '../InternalUtils.mjs'
+/**
+ * Used to put an error message in a LightningError
+ */
export class ErrorAction extends CommonBase {
protected constructor(_dummy: object, ptr: number) { super(ptr, bindings.ErrorAction_free); }
/* @internal */
public static constr_from_ptr(ptr: number): ErrorAction {
- const raw_val: bindings.LDKErrorAction = bindings.LDKErrorAction_ref_from_ptr(ptr);
- if (raw_val instanceof bindings.LDKErrorAction_DisconnectPeer) {
- return new ErrorAction_DisconnectPeer(ptr, raw_val);
+ const raw_ty: number = bindings.LDKErrorAction_ty_from_ptr(ptr);
+ switch (raw_ty) {
+ case 0: return new ErrorAction_DisconnectPeer(ptr);
+ case 1: return new ErrorAction_IgnoreError(ptr);
+ case 2: return new ErrorAction_IgnoreAndLog(ptr);
+ case 3: return new ErrorAction_IgnoreDuplicateGossip(ptr);
+ case 4: return new ErrorAction_SendErrorMessage(ptr);
+ default:
+ throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
}
- if (raw_val instanceof bindings.LDKErrorAction_IgnoreError) {
- return new ErrorAction_IgnoreError(ptr, raw_val);
- }
- if (raw_val instanceof bindings.LDKErrorAction_IgnoreAndLog) {
- return new ErrorAction_IgnoreAndLog(ptr, raw_val);
- }
- if (raw_val instanceof bindings.LDKErrorAction_IgnoreDuplicateGossip) {
- return new ErrorAction_IgnoreDuplicateGossip(ptr, raw_val);
- }
- if (raw_val instanceof bindings.LDKErrorAction_SendErrorMessage) {
- return new ErrorAction_SendErrorMessage(ptr, raw_val);
- }
- throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
}
public clone_ptr(): number {
return ret;
}
+ /**
+ * Creates a copy of the ErrorAction
+ */
public clone(): ErrorAction {
const ret: number = bindings.ErrorAction_clone(this.ptr);
const ret_hu_conv: ErrorAction = ErrorAction.constr_from_ptr(ret);
return ret_hu_conv;
}
+ /**
+ * Utility method to constructs a new DisconnectPeer-variant ErrorAction
+ */
public static constructor_disconnect_peer(msg: ErrorMessage): ErrorAction {
const ret: number = bindings.ErrorAction_disconnect_peer(msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1);
const ret_hu_conv: ErrorAction = ErrorAction.constr_from_ptr(ret);
return ret_hu_conv;
}
+ /**
+ * Utility method to constructs a new IgnoreError-variant ErrorAction
+ */
public static constructor_ignore_error(): ErrorAction {
const ret: number = bindings.ErrorAction_ignore_error();
const ret_hu_conv: ErrorAction = ErrorAction.constr_from_ptr(ret);
return ret_hu_conv;
}
+ /**
+ * Utility method to constructs a new IgnoreAndLog-variant ErrorAction
+ */
public static constructor_ignore_and_log(a: Level): ErrorAction {
const ret: number = bindings.ErrorAction_ignore_and_log(a);
const ret_hu_conv: ErrorAction = ErrorAction.constr_from_ptr(ret);
return ret_hu_conv;
}
+ /**
+ * Utility method to constructs a new IgnoreDuplicateGossip-variant ErrorAction
+ */
public static constructor_ignore_duplicate_gossip(): ErrorAction {
const ret: number = bindings.ErrorAction_ignore_duplicate_gossip();
const ret_hu_conv: ErrorAction = ErrorAction.constr_from_ptr(ret);
return ret_hu_conv;
}
+ /**
+ * Utility method to constructs a new SendErrorMessage-variant ErrorAction
+ */
public static constructor_send_error_message(msg: ErrorMessage): ErrorAction {
const ret: number = bindings.ErrorAction_send_error_message(msg == null ? 0 : CommonBase.get_ptr_of(msg) & ~1);
const ret_hu_conv: ErrorAction = ErrorAction.constr_from_ptr(ret);
}
}
+/** A ErrorAction of type DisconnectPeer */
export class ErrorAction_DisconnectPeer extends ErrorAction {
+ /**
+ * An error message which we should make an effort to send before we disconnect.
+ *
+ * Note that this (or a relevant inner pointer) may be NULL or all-0s to represent None
+ */
public msg: ErrorMessage;
/* @internal */
- public constructor(ptr: number, obj: bindings.LDKErrorAction_DisconnectPeer) {
+ public constructor(ptr: number) {
super(null, ptr);
- const msg: number = obj.msg;
+ const msg: number = bindings.LDKErrorAction_DisconnectPeer_get_msg(ptr);
const msg_hu_conv: ErrorMessage = new ErrorMessage(null, msg);
CommonBase.add_ref_from(msg_hu_conv, this);
this.msg = msg_hu_conv;
}
}
+/** A ErrorAction of type IgnoreError */
export class ErrorAction_IgnoreError extends ErrorAction {
/* @internal */
- public constructor(ptr: number, obj: bindings.LDKErrorAction_IgnoreError) {
+ public constructor(ptr: number) {
super(null, ptr);
}
}
+/** A ErrorAction of type IgnoreAndLog */
export class ErrorAction_IgnoreAndLog extends ErrorAction {
public ignore_and_log: Level;
/* @internal */
- public constructor(ptr: number, obj: bindings.LDKErrorAction_IgnoreAndLog) {
+ public constructor(ptr: number) {
super(null, ptr);
- this.ignore_and_log = obj.ignore_and_log;
+ this.ignore_and_log = bindings.LDKErrorAction_IgnoreAndLog_get_ignore_and_log(ptr);
}
}
+/** A ErrorAction of type IgnoreDuplicateGossip */
export class ErrorAction_IgnoreDuplicateGossip extends ErrorAction {
/* @internal */
- public constructor(ptr: number, obj: bindings.LDKErrorAction_IgnoreDuplicateGossip) {
+ public constructor(ptr: number) {
super(null, ptr);
}
}
+/** A ErrorAction of type SendErrorMessage */
export class ErrorAction_SendErrorMessage extends ErrorAction {
+ /**
+ * The message to send.
+ */
public msg: ErrorMessage;
/* @internal */
- public constructor(ptr: number, obj: bindings.LDKErrorAction_SendErrorMessage) {
+ public constructor(ptr: number) {
super(null, ptr);
- const msg: number = obj.msg;
+ const msg: number = bindings.LDKErrorAction_SendErrorMessage_get_msg(ptr);
const msg_hu_conv: ErrorMessage = new ErrorMessage(null, msg);
CommonBase.add_ref_from(msg_hu_conv, this);
this.msg = msg_hu_conv;