UNPKG

@node-lightning/wire

Version:
72 lines 3.79 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GossipQueriesSyncTask = exports.GossipQueriesSyncState = void 0; const ChannelAnnouncementMessage_1 = require("../messages/ChannelAnnouncementMessage"); const ChannelUpdateMessage_1 = require("../messages/ChannelUpdateMessage"); const NodeAnnouncementMessage_1 = require("../messages/NodeAnnouncementMessage"); const ReplyChannelRangeMessage_1 = require("../messages/ReplyChannelRangeMessage"); const ReplyShortChannelIdsEndMessage_1 = require("../messages/ReplyShortChannelIdsEndMessage"); const ChannelRangeQuery_1 = require("../gossip/ChannelRangeQuery"); const ChannelsQuery_1 = require("../gossip/ChannelsQuery"); const GossipSyncWatcher_1 = require("../gossip/GossipSyncWatcher"); var GossipQueriesSyncState; (function (GossipQueriesSyncState) { GossipQueriesSyncState[GossipQueriesSyncState["Idle"] = 0] = "Idle"; GossipQueriesSyncState[GossipQueriesSyncState["AwaitingChannelRange"] = 1] = "AwaitingChannelRange"; GossipQueriesSyncState[GossipQueriesSyncState["AwaitingChannels"] = 2] = "AwaitingChannels"; GossipQueriesSyncState[GossipQueriesSyncState["AwaitingMessages"] = 3] = "AwaitingMessages"; GossipQueriesSyncState[GossipQueriesSyncState["Complete"] = 4] = "Complete"; GossipQueriesSyncState[GossipQueriesSyncState["Failed"] = 5] = "Failed"; })(GossipQueriesSyncState = exports.GossipQueriesSyncState || (exports.GossipQueriesSyncState = {})); class GossipQueriesSyncTask { constructor(chainHash, messageSender, logger) { this.chainHash = chainHash; this.messageSender = messageSender; this.logger = logger; this._state = GossipQueriesSyncState.Idle; this._rangeQuery = new ChannelRangeQuery_1.ChannelRangeQuery(this.chainHash, messageSender, this.logger); this._channelsQuery = new ChannelsQuery_1.ChannelsQuery(this.chainHash, messageSender, this.logger); this._syncWatcher = new GossipSyncWatcher_1.GossipSyncWatcher(this.logger); } get state() { return this._state; } get error() { return this._error; } async queryRange(firstBlock, numBlocks) { try { this.logger.info("synchronization starting"); this._state = GossipQueriesSyncState.AwaitingChannelRange; const scids = await this._rangeQuery.queryRange(firstBlock, numBlocks); this._state = GossipQueriesSyncState.AwaitingChannels; await this._channelsQuery.query(...scids); this._state = GossipQueriesSyncState.AwaitingMessages; await this._syncWatcher.watch(); this.logger.info("synchronization complete!"); this._state = GossipQueriesSyncState.Complete; } catch (ex) { this.logger.error("synchronization failed with error", ex.message); this._state = GossipQueriesSyncState.Failed; this._error = ex; throw ex; } } handleWireMessage(msg) { if (msg instanceof ReplyChannelRangeMessage_1.ReplyChannelRangeMessage) { this._rangeQuery.handleReplyChannelRange(msg); return; } else if (msg instanceof ReplyShortChannelIdsEndMessage_1.ReplyShortChannelIdsEndMessage) { this._channelsQuery.handleReplyShortChannelIdsEnd(msg); } else if (msg instanceof ChannelAnnouncementMessage_1.ChannelAnnouncementMessage || msg instanceof ChannelUpdateMessage_1.ChannelUpdateMessage || msg instanceof NodeAnnouncementMessage_1.NodeAnnouncementMessage) { this._syncWatcher.onGossipMessage(msg); } } } exports.GossipQueriesSyncTask = GossipQueriesSyncTask; //# sourceMappingURL=GossipQueriesSyncTask.js.map