UNPKG

@node-lightning/wire

Version:
90 lines 3.97 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.AcceptChannelMessage = void 0; const bufio_1 = require("@node-lightning/bufio"); const MessageType_1 = require("../MessageType"); const readTlvs_1 = require("../serialize/readTlvs"); const core_1 = require("@node-lightning/core"); /** * AcceptChannelMessage represents the accept_channel message defined in * BOLT #2 of the Lightning Specification. This message is sent by the * receiving node in reply to an open_channel message. This message * signals agreement to open a channel with the using the values both * message. After this message is received by the initiating peer, the * initiating peer will create a funding transaction and send the * funding_created message. */ class AcceptChannelMessage { constructor() { /** * The type for accept_channel message. accept_channel = 33 */ this.type = AcceptChannelMessage.type; } /** * Deserializes an accept_channel message * @param buf */ static deserialize(buf) { const instance = new AcceptChannelMessage(); const reader = new bufio_1.BufferReader(buf); reader.readUInt16BE(); // read type instance.temporaryChannelId = reader.readBytes(32); instance.dustLimitSatoshis = core_1.Value.fromSats(reader.readUInt64BE()); instance.maxHtlcValueInFlightMsat = core_1.Value.fromMilliSats(reader.readUInt64BE()); instance.channelReserveSatoshis = core_1.Value.fromSats(reader.readUInt64BE()); instance.htlcMinimumMsat = core_1.Value.fromMilliSats(reader.readUInt64BE()); instance.minimumDepth = reader.readUInt32BE(); instance.toSelfDelay = reader.readUInt16BE(); instance.maxAcceptedHtlcs = reader.readUInt16BE(); instance.fundingPubKey = reader.readBytes(33); instance.revocationBasePoint = reader.readBytes(33); instance.paymentBasePoint = reader.readBytes(33); instance.delayedPaymentBasePoint = reader.readBytes(33); instance.htlcBasePoint = reader.readBytes(33); instance.firstPerCommitmentPoint = reader.readBytes(33); // Parse the TLVs readTlvs_1.readTlvs(reader, (type, valueReader) => { switch (type) { case BigInt(0): { instance.upfrontShutdownScript = valueReader.readBytes(); return true; } default: return false; } }); return instance; } /** * Serializes the accept_channel message into a Buffer */ serialize() { const writer = new bufio_1.BufferWriter(); writer.writeUInt16BE(this.type); writer.writeBytes(this.temporaryChannelId); writer.writeUInt64BE(this.dustLimitSatoshis.sats); writer.writeUInt64BE(this.maxHtlcValueInFlightMsat.msats); writer.writeUInt64BE(this.channelReserveSatoshis.sats); writer.writeUInt64BE(this.htlcMinimumMsat.msats); writer.writeUInt32BE(this.minimumDepth); writer.writeUInt16BE(this.toSelfDelay); writer.writeUInt16BE(this.maxAcceptedHtlcs); writer.writeBytes(this.fundingPubKey); writer.writeBytes(this.revocationBasePoint); writer.writeBytes(this.paymentBasePoint); writer.writeBytes(this.delayedPaymentBasePoint); writer.writeBytes(this.htlcBasePoint); writer.writeBytes(this.firstPerCommitmentPoint); // upfront_shutdown_script TLV if (this.upfrontShutdownScript) { writer.writeBigSize(0); writer.writeBigSize(this.upfrontShutdownScript.length); writer.writeBytes(this.upfrontShutdownScript); } return writer.toBuffer(); } } exports.AcceptChannelMessage = AcceptChannelMessage; AcceptChannelMessage.type = MessageType_1.MessageType.AcceptChannel; //# sourceMappingURL=AcceptChannelMessage.js.map