lightningdevkit
Version:
Lightning Development Kit
94 lines • 3.67 kB
JavaScript
import { APIError } from '../structs/APIError.mjs';
import { Option_NetworkUpdateZ } from '../structs/Option_NetworkUpdateZ.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* When the payment path failure took place and extra details about it. [`PathFailure::OnPath`] may
* contain a [`NetworkUpdate`] that needs to be applied to the [`NetworkGraph`].
*
* [`NetworkUpdate`]: crate::routing::gossip::NetworkUpdate
* [`NetworkGraph`]: crate::routing::gossip::NetworkGraph
*/
export class PathFailure extends CommonBase {
constructor(_dummy, ptr) { super(ptr, bindings.PathFailure_free); }
/* @internal */
static constr_from_ptr(ptr) {
const raw_ty = bindings.LDKPathFailure_ty_from_ptr(ptr);
switch (raw_ty) {
case 0: return new PathFailure_InitialSend(ptr);
case 1: return new PathFailure_OnPath(ptr);
default:
throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
}
}
clone_ptr() {
const ret = bindings.PathFailure_clone_ptr(this.ptr);
return ret;
}
/**
* Creates a copy of the PathFailure
*/
clone() {
const ret = bindings.PathFailure_clone(this.ptr);
const ret_hu_conv = PathFailure.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Utility method to constructs a new InitialSend-variant PathFailure
*/
static constructor_initial_send(err) {
const ret = bindings.PathFailure_initial_send(CommonBase.get_ptr_of(err));
const ret_hu_conv = PathFailure.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Utility method to constructs a new OnPath-variant PathFailure
*/
static constructor_on_path(network_update) {
const ret = bindings.PathFailure_on_path(CommonBase.get_ptr_of(network_update));
const ret_hu_conv = PathFailure.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Checks if two PathFailures contain equal inner contents.
* This ignores pointers and is_owned flags and looks at the values in fields.
*/
eq(b) {
const ret = bindings.PathFailure_eq(this.ptr, CommonBase.get_ptr_of(b));
return ret;
}
/**
* Serialize the PathFailure object into a byte array which can be read by PathFailure_read
*/
write() {
const ret = bindings.PathFailure_write(this.ptr);
const ret_conv = bindings.decodeUint8Array(ret);
return ret_conv;
}
}
/** A PathFailure of type InitialSend */
export class PathFailure_InitialSend extends PathFailure {
/* @internal */
constructor(ptr) {
super(null, ptr);
const err = bindings.LDKPathFailure_InitialSend_get_err(ptr);
const err_hu_conv = APIError.constr_from_ptr(err);
CommonBase.add_ref_from(err_hu_conv, this);
this.err = err_hu_conv;
}
}
/** A PathFailure of type OnPath */
export class PathFailure_OnPath extends PathFailure {
/* @internal */
constructor(ptr) {
super(null, ptr);
const network_update = bindings.LDKPathFailure_OnPath_get_network_update(ptr);
const network_update_hu_conv = Option_NetworkUpdateZ.constr_from_ptr(network_update);
CommonBase.add_ref_from(network_update_hu_conv, this);
this.network_update = network_update_hu_conv;
}
}
//# sourceMappingURL=PathFailure.mjs.map