@bsv/wallet-toolbox-mobile
Version:
Client only Wallet Storage
60 lines • 2.78 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BulkIngestorWhatsOnChainCdn = void 0;
const utilityHelpers_1 = require("../../../../utility/utilityHelpers");
const BulkIngestorBase_1 = require("./BulkIngestorBase");
const blockHeaderUtilities_1 = require("../util/blockHeaderUtilities");
const ChaintracksFetch_1 = require("../util/ChaintracksFetch");
const WhatsOnChainServices_1 = require("./WhatsOnChainServices");
class BulkIngestorWhatsOnChainCdn 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);
this.fetch = options.fetch || new ChaintracksFetch_1.ChaintracksFetch();
}
async getPresentHeight() {
const presentHeight = await this.woc.getChainTipHeight();
(0, utilityHelpers_1.logger)(`presentHeight=${presentHeight}`);
return presentHeight;
}
async fetchHeaders(before, fetchRange, bulkRange, priorLiveHeaders) {
const oldHeaders = [];
try {
const ranges = await this.woc.getHeaderByteFileLinks(fetchRange, this.fetch);
const headers = [];
for (const range of ranges) {
for (let height = range.range.minHeight; height <= range.range.maxHeight; height++) {
if (fetchRange.contains(height)) {
if (!range.data)
range.data = await this.fetch.download(this.fetch.pathJoin(range.sourceUrl, range.fileName));
const h = (0, blockHeaderUtilities_1.deserializeBlockHeader)(range.data, (height - range.range.minHeight) * 80, height);
oldHeaders.push(h);
}
}
}
}
catch (e) {
(0, utilityHelpers_1.logger)(`Errors during WhatsOnChain ingestion:\n${e}`);
}
const liveHeaders = await this.storage().addBulkHeaders(oldHeaders, bulkRange, priorLiveHeaders);
return liveHeaders;
}
}
exports.BulkIngestorWhatsOnChainCdn = BulkIngestorWhatsOnChainCdn;
//# sourceMappingURL=BulkIngestorWhatsOnChainCdn.js.map