UNPKG

lightningdevkit

Version:
102 lines 4.17 kB
import { Bolt12OfferContext } from '../structs/Bolt12OfferContext.mjs'; import { Bolt12RefundContext } from '../structs/Bolt12RefundContext.mjs'; import { Result_PaymentContextDecodeErrorZ } from '../structs/Result_PaymentContextDecodeErrorZ.mjs'; import { CommonBase } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs'; /** * The context of an inbound payment, which is included in a [`BlindedPaymentPath`] via * [`ReceiveTlvs`] and surfaced in [`PaymentPurpose`]. * * [`PaymentPurpose`]: crate::events::PaymentPurpose */ export class PaymentContext extends CommonBase { constructor(_dummy, ptr) { super(ptr, bindings.PaymentContext_free); } /* @internal */ static constr_from_ptr(ptr) { const raw_ty = bindings.LDKPaymentContext_ty_from_ptr(ptr); switch (raw_ty) { case 0: return new PaymentContext_Bolt12Offer(ptr); case 1: return new PaymentContext_Bolt12Refund(ptr); default: throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface } } clone_ptr() { const ret = bindings.PaymentContext_clone_ptr(this.ptr); return ret; } /** * Creates a copy of the PaymentContext */ clone() { const ret = bindings.PaymentContext_clone(this.ptr); const ret_hu_conv = PaymentContext.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Utility method to constructs a new Bolt12Offer-variant PaymentContext */ static constructor_bolt12_offer(a) { const ret = bindings.PaymentContext_bolt12_offer(CommonBase.get_ptr_of(a)); const ret_hu_conv = PaymentContext.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } /** * Utility method to constructs a new Bolt12Refund-variant PaymentContext */ static constructor_bolt12_refund(a) { const ret = bindings.PaymentContext_bolt12_refund(CommonBase.get_ptr_of(a)); const ret_hu_conv = PaymentContext.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } /** * Checks if two PaymentContexts contain equal inner contents. * This ignores pointers and is_owned flags and looks at the values in fields. */ eq(b) { const ret = bindings.PaymentContext_eq(this.ptr, CommonBase.get_ptr_of(b)); return ret; } /** * Serialize the PaymentContext object into a byte array which can be read by PaymentContext_read */ write() { const ret = bindings.PaymentContext_write(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * Read a PaymentContext from a byte array, created by PaymentContext_write */ static constructor_read(ser) { const ret = bindings.PaymentContext_read(bindings.encodeUint8Array(ser)); const ret_hu_conv = Result_PaymentContextDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } } /** A PaymentContext of type Bolt12Offer */ export class PaymentContext_Bolt12Offer extends PaymentContext { /* @internal */ constructor(ptr) { super(null, ptr); const bolt12_offer = bindings.LDKPaymentContext_Bolt12Offer_get_bolt12_offer(ptr); const bolt12_offer_hu_conv = new Bolt12OfferContext(null, bolt12_offer); CommonBase.add_ref_from(bolt12_offer_hu_conv, this); this.bolt12_offer = bolt12_offer_hu_conv; } } /** A PaymentContext of type Bolt12Refund */ export class PaymentContext_Bolt12Refund extends PaymentContext { /* @internal */ constructor(ptr) { super(null, ptr); const bolt12_refund = bindings.LDKPaymentContext_Bolt12Refund_get_bolt12_refund(ptr); const bolt12_refund_hu_conv = new Bolt12RefundContext(null, bolt12_refund); CommonBase.add_ref_from(bolt12_refund_hu_conv, this); this.bolt12_refund = bolt12_refund_hu_conv; } } //# sourceMappingURL=PaymentContext.mjs.map