2 import CommonBase from './CommonBase';
3 import * as bindings from '../bindings' // TODO: figure out location
5 export default class APIError extends CommonBase {
6 protected constructor(_dummy: object, ptr: number) { super(ptr); }
9 if (this.ptr != 0) { bindings.APIError_free(this.ptr); }
11 static constr_from_ptr(ptr: number): APIError {
12 const raw_val: bindings.LDKAPIError = bindings.LDKAPIError_ref_from_ptr(ptr);
13 if (raw_val instanceof bindings.LDKAPIError.APIMisuseError) {
14 return new APIMisuseError(this.ptr, raw_val);
16 if (raw_val instanceof bindings.LDKAPIError.FeeRateTooHigh) {
17 return new FeeRateTooHigh(this.ptr, raw_val);
19 if (raw_val instanceof bindings.LDKAPIError.RouteError) {
20 return new RouteError(this.ptr, raw_val);
22 if (raw_val instanceof bindings.LDKAPIError.ChannelUnavailable) {
23 return new ChannelUnavailable(this.ptr, raw_val);
25 if (raw_val instanceof bindings.LDKAPIError.MonitorUpdateFailed) {
26 return new MonitorUpdateFailed(this.ptr, raw_val);
28 throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
32 export class APIMisuseError extends APIError {
34 private constructor(ptr: number, obj: bindings.LDKAPIError.APIMisuseError) {
39 export class FeeRateTooHigh extends APIError {
41 public feerate: number;
42 private constructor(ptr: number, obj: bindings.LDKAPIError.FeeRateTooHigh) {
45 this.feerate = obj.feerate;
48 export class RouteError extends APIError {
50 private constructor(ptr: number, obj: bindings.LDKAPIError.RouteError) {
55 export class ChannelUnavailable extends APIError {
57 private constructor(ptr: number, obj: bindings.LDKAPIError.ChannelUnavailable) {
62 export class MonitorUpdateFailed extends APIError {
63 private constructor(ptr: number, obj: bindings.LDKAPIError.MonitorUpdateFailed) {
67 public APIError clone() {
68 number ret = bindings.APIError_clone(this.ptr);
69 APIError ret_hu_conv = APIError.constr_from_ptr(ret);
70 ret_hu_conv.ptrs_to.add(this);