UNPKG

lightningdevkit

Version:
77 lines 3.4 kB
import { Nonce } from '../structs/Nonce.mjs'; import { Result_AsyncPaymentsContextDecodeErrorZ } from '../structs/Result_AsyncPaymentsContextDecodeErrorZ.mjs'; import { CommonBase } from './CommonBase.mjs'; import * as bindings from '../bindings.mjs'; /** * Contains data specific to an [`AsyncPaymentsMessage`]. * * [`AsyncPaymentsMessage`]: crate::onion_message::async_payments::AsyncPaymentsMessage */ export class AsyncPaymentsContext extends CommonBase { constructor(_dummy, ptr) { super(ptr, bindings.AsyncPaymentsContext_free); } /* @internal */ static constr_from_ptr(ptr) { const raw_ty = bindings.LDKAsyncPaymentsContext_ty_from_ptr(ptr); switch (raw_ty) { case 0: return new AsyncPaymentsContext_OutboundPayment(ptr); default: throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface } } clone_ptr() { const ret = bindings.AsyncPaymentsContext_clone_ptr(this.ptr); return ret; } /** * Creates a copy of the AsyncPaymentsContext */ clone() { const ret = bindings.AsyncPaymentsContext_clone(this.ptr); const ret_hu_conv = AsyncPaymentsContext.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, this); return ret_hu_conv; } /** * Utility method to constructs a new OutboundPayment-variant AsyncPaymentsContext */ static constructor_outbound_payment(payment_id, nonce, hmac) { const ret = bindings.AsyncPaymentsContext_outbound_payment(bindings.encodeUint8Array(payment_id), CommonBase.get_ptr_of(nonce), bindings.encodeUint8Array(hmac)); const ret_hu_conv = AsyncPaymentsContext.constr_from_ptr(ret); CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv); return ret_hu_conv; } /** * Serialize the AsyncPaymentsContext object into a byte array which can be read by AsyncPaymentsContext_read */ write() { const ret = bindings.AsyncPaymentsContext_write(this.ptr); const ret_conv = bindings.decodeUint8Array(ret); return ret_conv; } /** * Read a AsyncPaymentsContext from a byte array, created by AsyncPaymentsContext_write */ static constructor_read(ser) { const ret = bindings.AsyncPaymentsContext_read(bindings.encodeUint8Array(ser)); const ret_hu_conv = Result_AsyncPaymentsContextDecodeErrorZ.constr_from_ptr(ret); return ret_hu_conv; } } /** A AsyncPaymentsContext of type OutboundPayment */ export class AsyncPaymentsContext_OutboundPayment extends AsyncPaymentsContext { /* @internal */ constructor(ptr) { super(null, ptr); const payment_id = bindings.LDKAsyncPaymentsContext_OutboundPayment_get_payment_id(ptr); const payment_id_conv = bindings.decodeUint8Array(payment_id); this.payment_id = payment_id_conv; const nonce = bindings.LDKAsyncPaymentsContext_OutboundPayment_get_nonce(ptr); const nonce_hu_conv = new Nonce(null, nonce); CommonBase.add_ref_from(nonce_hu_conv, this); this.nonce = nonce_hu_conv; const hmac = bindings.LDKAsyncPaymentsContext_OutboundPayment_get_hmac(ptr); const hmac_conv = bindings.decodeUint8Array(hmac); this.hmac = hmac_conv; } } //# sourceMappingURL=AsyncPaymentsContext.mjs.map