All files / lib/messages ReplyShortChannelIdsEndMessage.ts

100% Statements 16/16
50% Branches 1/2
100% Functions 3/3
100% Lines 16/16

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 361x 1x     1x   1x 1x     1x   1x 1x   1x     65x           1x       1x 1x 1x 1x 1x      
import { BufferReader, BufferWriter } from "@node-lightning/bufio";
import { MessageType } from "../MessageType";
import { IWireMessage } from "./IWireMessage";
 
export class ReplyShortChannelIdsEndMessage implements IWireMessage {
    public static deserialize(payload: Buffer): ReplyShortChannelIdsEndMessage {
        const instance = new ReplyShortChannelIdsEndMessage();
        const reader = new BufferReader(payload);
 
        // read type bytes
        reader.readUInt16BE();
 
        instance.chainHash = reader.readBytes(32);
        instance.complete = reader.readUInt8() === 1;
 
        return instance;
    }
 
    public type: MessageType = MessageType.ReplyShortChannelIdsEnd;
    public chainHash: Buffer;
    public complete: boolean;
 
    public serialize(): Buffer {
        const len =
            2 + // type
            32 + // chain_hash
            1; // complete
 
        const writer = new BufferWriter(Buffer.alloc(len));
        writer.writeUInt16BE(this.type);
        writer.writeBytes(this.chainHash);
        writer.writeUInt8(this.complete ? 1 : 0);
        return writer.toBuffer();
    }
}