lightningdevkit
Version:
Lightning Development Kit
91 lines • 3.66 kB
JavaScript
import { Description } from '../structs/Description.mjs';
import { Sha256 } from '../structs/Sha256.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* Represents the description of an invoice which has to be either a directly included string or
* a hash of a description provided out of band.
*/
export class Bolt11InvoiceDescription extends CommonBase {
constructor(_dummy, ptr) { super(ptr, bindings.Bolt11InvoiceDescription_free); }
/* @internal */
static constr_from_ptr(ptr) {
const raw_ty = bindings.LDKBolt11InvoiceDescription_ty_from_ptr(ptr);
switch (raw_ty) {
case 0: return new Bolt11InvoiceDescription_Direct(ptr);
case 1: return new Bolt11InvoiceDescription_Hash(ptr);
default:
throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
}
}
clone_ptr() {
const ret = bindings.Bolt11InvoiceDescription_clone_ptr(this.ptr);
return ret;
}
/**
* Creates a copy of the Bolt11InvoiceDescription
*/
clone() {
const ret = bindings.Bolt11InvoiceDescription_clone(this.ptr);
const ret_hu_conv = Bolt11InvoiceDescription.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Utility method to constructs a new Direct-variant Bolt11InvoiceDescription
*/
static constructor_direct(a) {
const ret = bindings.Bolt11InvoiceDescription_direct(CommonBase.get_ptr_of(a));
const ret_hu_conv = Bolt11InvoiceDescription.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Utility method to constructs a new Hash-variant Bolt11InvoiceDescription
*/
static constructor_hash(a) {
const ret = bindings.Bolt11InvoiceDescription_hash(CommonBase.get_ptr_of(a));
const ret_hu_conv = Bolt11InvoiceDescription.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Checks if two Bolt11InvoiceDescriptions contain equal inner contents.
* This ignores pointers and is_owned flags and looks at the values in fields.
*/
eq(b) {
const ret = bindings.Bolt11InvoiceDescription_eq(this.ptr, CommonBase.get_ptr_of(b));
return ret;
}
/**
* Get the string representation of a Bolt11InvoiceDescription object
*/
to_str() {
const ret = bindings.Bolt11InvoiceDescription_to_str(this.ptr);
const ret_conv = bindings.decodeString(ret);
return ret_conv;
}
}
/** A Bolt11InvoiceDescription of type Direct */
export class Bolt11InvoiceDescription_Direct extends Bolt11InvoiceDescription {
/* @internal */
constructor(ptr) {
super(null, ptr);
const direct = bindings.LDKBolt11InvoiceDescription_Direct_get_direct(ptr);
const direct_hu_conv = new Description(null, direct);
CommonBase.add_ref_from(direct_hu_conv, this);
this.direct = direct_hu_conv;
}
}
/** A Bolt11InvoiceDescription of type Hash */
export class Bolt11InvoiceDescription_Hash extends Bolt11InvoiceDescription {
/* @internal */
constructor(ptr) {
super(null, ptr);
const hash = bindings.LDKBolt11InvoiceDescription_Hash_get_hash(ptr);
const hash_hu_conv = new Sha256(null, hash);
CommonBase.add_ref_from(hash_hu_conv, this);
this.hash = hash_hu_conv;
}
}
//# sourceMappingURL=Bolt11InvoiceDescription.mjs.map