All files / lib/deserialize channel-from-message.ts

100% Statements 11/11
100% Branches 2/2
100% Functions 1/1
100% Lines 11/11

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    1x             1x     8x 8x 8x 8x 8x 8x 2x 2x   8x    
import { ChannelAnnouncementMessage } from "@node-lightning/wire";
import { ExtendedChannelAnnouncementMessage } from "@node-lightning/wire";
import { Channel } from "../channel";
 
/**
 * Constructs an incomplete channel from a node announcement message. The channel does
 * not include outpoint, capacity, or per node settings found in channel_update
 * messages. These values need to be set elsewhere.
 */
export function channelFromMessage(
    msg: ChannelAnnouncementMessage | ExtendedChannelAnnouncementMessage,
): Channel {
    const c = new Channel();
    c.shortChannelId = msg.shortChannelId;
    c.features = msg.features;
    c.nodeId1 = msg.nodeId1;
    c.nodeId2 = msg.nodeId2;
    if ("outpoint" in msg) {
        c.channelPoint = msg.outpoint;
        c.capacity = msg.capacity;
    }
    return c;
}