lightningdevkit
Version:
Lightning Development Kit
126 lines • 6.11 kB
JavaScript
import { BlindedMessagePath } from '../structs/BlindedMessagePath.mjs';
import { ResponseInstruction } from '../structs/ResponseInstruction.mjs';
import { Destination } from '../structs/Destination.mjs';
import { MessageContext } from '../structs/MessageContext.mjs';
import { CommonBase } from './CommonBase.mjs';
import * as bindings from '../bindings.mjs';
/**
* Instructions for how and where to send a message.
*/
export class MessageSendInstructions extends CommonBase {
constructor(_dummy, ptr) { super(ptr, bindings.MessageSendInstructions_free); }
/* @internal */
static constr_from_ptr(ptr) {
const raw_ty = bindings.LDKMessageSendInstructions_ty_from_ptr(ptr);
switch (raw_ty) {
case 0: return new MessageSendInstructions_WithSpecifiedReplyPath(ptr);
case 1: return new MessageSendInstructions_WithReplyPath(ptr);
case 2: return new MessageSendInstructions_WithoutReplyPath(ptr);
case 3: return new MessageSendInstructions_ForReply(ptr);
default:
throw new Error('oops, this should be unreachable'); // Unreachable without extending the (internal) bindings interface
}
}
clone_ptr() {
const ret = bindings.MessageSendInstructions_clone_ptr(this.ptr);
return ret;
}
/**
* Creates a copy of the MessageSendInstructions
*/
clone() {
const ret = bindings.MessageSendInstructions_clone(this.ptr);
const ret_hu_conv = MessageSendInstructions.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, this);
return ret_hu_conv;
}
/**
* Utility method to constructs a new WithSpecifiedReplyPath-variant MessageSendInstructions
*/
static constructor_with_specified_reply_path(destination, reply_path) {
const ret = bindings.MessageSendInstructions_with_specified_reply_path(CommonBase.get_ptr_of(destination), CommonBase.get_ptr_of(reply_path));
const ret_hu_conv = MessageSendInstructions.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Utility method to constructs a new WithReplyPath-variant MessageSendInstructions
*/
static constructor_with_reply_path(destination, context) {
const ret = bindings.MessageSendInstructions_with_reply_path(CommonBase.get_ptr_of(destination), CommonBase.get_ptr_of(context));
const ret_hu_conv = MessageSendInstructions.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Utility method to constructs a new WithoutReplyPath-variant MessageSendInstructions
*/
static constructor_without_reply_path(destination) {
const ret = bindings.MessageSendInstructions_without_reply_path(CommonBase.get_ptr_of(destination));
const ret_hu_conv = MessageSendInstructions.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
/**
* Utility method to constructs a new ForReply-variant MessageSendInstructions
*/
static constructor_for_reply(instructions) {
const ret = bindings.MessageSendInstructions_for_reply(CommonBase.get_ptr_of(instructions));
const ret_hu_conv = MessageSendInstructions.constr_from_ptr(ret);
CommonBase.add_ref_from(ret_hu_conv, ret_hu_conv);
return ret_hu_conv;
}
}
/** A MessageSendInstructions of type WithSpecifiedReplyPath */
export class MessageSendInstructions_WithSpecifiedReplyPath extends MessageSendInstructions {
/* @internal */
constructor(ptr) {
super(null, ptr);
const destination = bindings.LDKMessageSendInstructions_WithSpecifiedReplyPath_get_destination(ptr);
const destination_hu_conv = Destination.constr_from_ptr(destination);
CommonBase.add_ref_from(destination_hu_conv, this);
this.destination = destination_hu_conv;
const reply_path = bindings.LDKMessageSendInstructions_WithSpecifiedReplyPath_get_reply_path(ptr);
const reply_path_hu_conv = new BlindedMessagePath(null, reply_path);
CommonBase.add_ref_from(reply_path_hu_conv, this);
this.reply_path = reply_path_hu_conv;
}
}
/** A MessageSendInstructions of type WithReplyPath */
export class MessageSendInstructions_WithReplyPath extends MessageSendInstructions {
/* @internal */
constructor(ptr) {
super(null, ptr);
const destination = bindings.LDKMessageSendInstructions_WithReplyPath_get_destination(ptr);
const destination_hu_conv = Destination.constr_from_ptr(destination);
CommonBase.add_ref_from(destination_hu_conv, this);
this.destination = destination_hu_conv;
const context = bindings.LDKMessageSendInstructions_WithReplyPath_get_context(ptr);
const context_hu_conv = MessageContext.constr_from_ptr(context);
CommonBase.add_ref_from(context_hu_conv, this);
this.context = context_hu_conv;
}
}
/** A MessageSendInstructions of type WithoutReplyPath */
export class MessageSendInstructions_WithoutReplyPath extends MessageSendInstructions {
/* @internal */
constructor(ptr) {
super(null, ptr);
const destination = bindings.LDKMessageSendInstructions_WithoutReplyPath_get_destination(ptr);
const destination_hu_conv = Destination.constr_from_ptr(destination);
CommonBase.add_ref_from(destination_hu_conv, this);
this.destination = destination_hu_conv;
}
}
/** A MessageSendInstructions of type ForReply */
export class MessageSendInstructions_ForReply extends MessageSendInstructions {
/* @internal */
constructor(ptr) {
super(null, ptr);
const instructions = bindings.LDKMessageSendInstructions_ForReply_get_instructions(ptr);
const instructions_hu_conv = new ResponseInstruction(null, instructions);
CommonBase.add_ref_from(instructions_hu_conv, this);
this.instructions = instructions_hu_conv;
}
}
//# sourceMappingURL=MessageSendInstructions.mjs.map