lightningdevkit
Version:
Lightning Development Kit
115 lines • 4.4 kB
JavaScript
import { UntrustedString } from '../structs/UntrustedString.mjs';
import { Result_InvoiceErrorDecodeErrorZ } from '../structs/Result_InvoiceErrorDecodeErrorZ.mjs';
import { ErroneousField } from '../structs/ErroneousField.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* An error in response to an [`InvoiceRequest`] or an [`Bolt12Invoice`].
*
* [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
* [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
*/
export class InvoiceError extends CommonBase {
/* @internal */
constructor(_dummy, ptr) {
super(ptr, bindings.InvoiceError_free);
}
/**
* The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error.
*
* [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
* [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
*
* Note that the return value (or a relevant inner pointer) may be NULL or all-0s to represent None
*/
get_erroneous_field() {
const ret = bindings.InvoiceError_get_erroneous_field(this.ptr);
const ret_hu_conv = new ErroneousField(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* The field in the [`InvoiceRequest`] or the [`Bolt12Invoice`] that contained an error.
*
* [`InvoiceRequest`]: crate::offers::invoice_request::InvoiceRequest
* [`Bolt12Invoice`]: crate::offers::invoice::Bolt12Invoice
*
* Note that val (or a relevant inner pointer) may be NULL or all-0s to represent None
*/
set_erroneous_field(val) {
bindings.InvoiceError_set_erroneous_field(this.ptr, val == null ? 0n : CommonBase.get_ptr_of(val));
}
/**
* An explanation of the error.
*/
get_message() {
const ret = bindings.InvoiceError_get_message(this.ptr);
const ret_hu_conv = new UntrustedString(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* An explanation of the error.
*/
set_message(val) {
bindings.InvoiceError_set_message(this.ptr, CommonBase.get_ptr_of(val));
}
/**
* Constructs a new InvoiceError given each field
*
* Note that erroneous_field_arg (or a relevant inner pointer) may be NULL or all-0s to represent None
*/
static constructor_new(erroneous_field_arg, message_arg) {
const ret = bindings.InvoiceError_new(erroneous_field_arg == null ? 0n : CommonBase.get_ptr_of(erroneous_field_arg), CommonBase.get_ptr_of(message_arg));
const ret_hu_conv = new InvoiceError(null, ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
clone_ptr() {
const ret = bindings.InvoiceError_clone_ptr(this.ptr);
return ret;
}
/**
* Creates a copy of the InvoiceError
*/
clone() {
const ret = bindings.InvoiceError_clone(this.ptr);
const ret_hu_conv = new InvoiceError(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Creates an [`InvoiceError`] with the given message.
*/
static constructor_from_string(s) {
const ret = bindings.InvoiceError_from_string(bindings.encodeString(s));
const ret_hu_conv = new InvoiceError(null, ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Get the string representation of a InvoiceError object
*/
to_str() {
const ret = bindings.InvoiceError_to_str(this.ptr);
const ret_conv = bindings.decodeString(ret);
return ret_conv;
}
/**
* Serialize the InvoiceError object into a byte array which can be read by InvoiceError_read
*/
write() {
const ret = bindings.InvoiceError_write(this.ptr);
const ret_conv = bindings.decodeUint8Array(ret);
return ret_conv;
}
/**
* Read a InvoiceError from a byte array, created by InvoiceError_write
*/
static constructor_read(ser) {
const ret = bindings.InvoiceError_read(bindings.encodeUint8Array(ser));
const ret_hu_conv = Result_InvoiceErrorDecodeErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}
}
//# sourceMappingURL=InvoiceError.mjs.map