UNPKG

@bsv/wallet-toolbox-mobile

Version:
57 lines 2.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.BulkIngestorWhatsOnChainWs = void 0; const utilityHelpers_1 = require("../../../../utility/utilityHelpers"); const BulkIngestorBase_1 = require("./BulkIngestorBase"); const WhatsOnChainIngestorWs_1 = require("./WhatsOnChainIngestorWs"); const WhatsOnChainServices_1 = require("./WhatsOnChainServices"); class BulkIngestorWhatsOnChainWs extends BulkIngestorBase_1.BulkIngestorBase { /** * * @param chain * @param localCachePath defaults to './data/ingest_whatsonchain_headers' * @returns */ static createBulkIngestorWhatsOnChainOptions(chain) { const options = { ...WhatsOnChainServices_1.WhatsOnChainServices.createWhatsOnChainServicesOptions(chain), ...BulkIngestorBase_1.BulkIngestorBase.createBulkIngestorBaseOptions(chain), idleWait: 5000 }; return options; } constructor(options) { super(options); this.stopOldListenersToken = { stop: undefined }; this.idleWait = options.idleWait || 5000; this.woc = new WhatsOnChainServices_1.WhatsOnChainServices(options); } async getPresentHeight() { const presentHeight = await this.woc.getChainTipHeight(); (0, utilityHelpers_1.logger)(`presentHeight=${presentHeight}`); return presentHeight; } async fetchHeaders(before, fetchRange, bulkRange, priorLiveHeaders) { const oldHeaders = []; const errors = []; const enqueue = header => { oldHeaders.push(header); }; const error = (code, message) => { errors.push({ code, message, count: errors.length }); return false; }; const ok = await (0, WhatsOnChainIngestorWs_1.WocHeadersBulkListener)(fetchRange.minHeight, fetchRange.maxHeight, enqueue, error, this.stopOldListenersToken, this.chain, this.idleWait); let liveHeaders = []; if (ok) { liveHeaders = await this.storage().addBulkHeaders(oldHeaders, bulkRange, priorLiveHeaders); } if (errors.length > 0) { const errorMessages = errors.map(e => `(${e.code}) ${e.message} (${e.count})`).join('\n'); (0, utilityHelpers_1.logger)(`Errors during WhatsOnChain ingestion:\n${errorMessages}`); } return liveHeaders; } } exports.BulkIngestorWhatsOnChainWs = BulkIngestorWhatsOnChainWs; //# sourceMappingURL=BulkIngestorWhatsOnChainWs.js.map