lightningdevkit
Version:
Lightning Development Kit
131 lines • 5.25 kB
JavaScript
import { Result_NoneBolt12SemanticErrorZ } from '../structs/Result_NoneBolt12SemanticErrorZ.mjs';
import { Result_OfferBolt12SemanticErrorZ } from '../structs/Result_OfferBolt12SemanticErrorZ.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* Builds an [`Offer`] for the \"offer to be paid\" flow.
*
* See [module-level documentation] for usage.
*
* [module-level documentation]: self
*/
export class OfferWithExplicitMetadataBuilder extends CommonBase {
/* @internal */
constructor(_dummy, ptr) {
super(ptr, bindings.OfferWithExplicitMetadataBuilder_free);
}
clone_ptr() {
const ret = bindings.OfferWithExplicitMetadataBuilder_clone_ptr(this.ptr);
return ret;
}
/**
* Creates a copy of the OfferWithExplicitMetadataBuilder
*/
clone() {
const ret = bindings.OfferWithExplicitMetadataBuilder_clone(this.ptr);
const ret_hu_conv = new OfferWithExplicitMetadataBuilder(null, ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Creates a new builder for an offer using the `signing_pubkey` for signing invoices. The
* associated secret key must be remembered while the offer is valid.
*
* Use a different pubkey per offer to avoid correlating offers.
*
* # Note
*
* If constructing an [`Offer`] for use with a [`ChannelManager`], use
* [`ChannelManager::create_offer_builder`] instead of [`OfferBuilder::new`].
*
* [`ChannelManager`]: crate::ln::channelmanager::ChannelManager
* [`ChannelManager::create_offer_builder`]: crate::ln::channelmanager::ChannelManager::create_offer_builder
*/
static constructor_new(signing_pubkey) {
const ret = bindings.OfferWithExplicitMetadataBuilder_new(bindings.encodeUint8Array(signing_pubkey));
const ret_hu_conv = new OfferWithExplicitMetadataBuilder(null, ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Sets the [`Offer::metadata`] to the given bytes.
*
* Successive calls to this method will override the previous setting.
*/
metadata(metadata) {
const ret = bindings.OfferWithExplicitMetadataBuilder_metadata(this.ptr, bindings.encodeUint8Array(metadata));
const ret_hu_conv = Result_NoneBolt12SemanticErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}
/**
* Adds the chain hash of the given [`Network`] to [`Offer::chains`]. If not called,
* the chain hash of [`Network::Bitcoin`] is assumed to be the only one supported.
*
* See [`Offer::chains`] on how this relates to the payment currency.
*
* Successive calls to this method will add another chain hash.
*/
chain(network) {
bindings.OfferWithExplicitMetadataBuilder_chain(this.ptr, network);
}
/**
* Sets the [`Offer::amount`] as an [`Amount::Bitcoin`].
*
* Successive calls to this method will override the previous setting.
*/
amount_msats(amount_msats) {
bindings.OfferWithExplicitMetadataBuilder_amount_msats(this.ptr, amount_msats);
}
/**
* Sets the [`Offer::absolute_expiry`] as seconds since the Unix epoch.
*
* Successive calls to this method will override the previous setting.
*/
absolute_expiry(absolute_expiry) {
bindings.OfferWithExplicitMetadataBuilder_absolute_expiry(this.ptr, absolute_expiry);
}
/**
* Sets the [`Offer::description`].
*
* Successive calls to this method will override the previous setting.
*/
description(description) {
bindings.OfferWithExplicitMetadataBuilder_description(this.ptr, bindings.encodeString(description));
}
/**
* Sets the [`Offer::issuer`].
*
* Successive calls to this method will override the previous setting.
*/
issuer(issuer) {
bindings.OfferWithExplicitMetadataBuilder_issuer(this.ptr, bindings.encodeString(issuer));
}
/**
* Adds a blinded path to [`Offer::paths`]. Must include at least one path if only connected by
* private channels or if [`Offer::issuer_signing_pubkey`] is not a public node id.
*
* Successive calls to this method will add another blinded path. Caller is responsible for not
* adding duplicate paths.
*/
path(path) {
bindings.OfferWithExplicitMetadataBuilder_path(this.ptr, CommonBase.get_ptr_of(path));
}
/**
* Sets the quantity of items for [`Offer::supported_quantity`]. If not called, defaults to
* [`Quantity::One`].
*
* Successive calls to this method will override the previous setting.
*/
supported_quantity(quantity) {
bindings.OfferWithExplicitMetadataBuilder_supported_quantity(this.ptr, CommonBase.get_ptr_of(quantity));
}
/**
* Builds an [`Offer`] from the builder's settings.
*/
build() {
const ret = bindings.OfferWithExplicitMetadataBuilder_build(this.ptr);
const ret_hu_conv = Result_OfferBolt12SemanticErrorZ.constr_from_ptr(ret);
return ret_hu_conv;
}
}
//# sourceMappingURL=OfferWithExplicitMetadataBuilder.mjs.map