@bsv/wallet-toolbox-mobile
Version:
Client only Wallet Storage
53 lines • 2.24 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.LiveIngestorWhatsOnChainWs = void 0;
const LiveIngestorBase_1 = require("./LiveIngestorBase");
const WhatsOnChainIngestorWs_1 = require("./WhatsOnChainIngestorWs");
const WhatsOnChainServices_1 = require("./WhatsOnChainServices");
class LiveIngestorWhatsOnChainWs extends LiveIngestorBase_1.LiveIngestorBase {
static createLiveIngestorWhatsOnChainOptions(chain) {
const options = {
...WhatsOnChainServices_1.WhatsOnChainServices.createWhatsOnChainServicesOptions(chain),
...LiveIngestorBase_1.LiveIngestorBase.createLiveIngestorBaseOptions(chain),
idleWait: 100000
};
return options;
}
constructor(options) {
super(options);
this.stopNewListenersToken = { stop: undefined };
this.idleWait = options.idleWait || 100000;
this.woc = new WhatsOnChainServices_1.WhatsOnChainServices(options);
}
async getHeaderByHash(hash) {
const header = await this.woc.getHeaderByHash(hash);
return header;
}
async startListening(liveHeaders) {
const errors = [];
const enqueue = header => {
liveHeaders.push(header);
};
const error = (code, message) => {
errors.push({ code, message, count: errors.length });
return false;
};
for (;;) {
const ok = await (0, WhatsOnChainIngestorWs_1.WocHeadersLiveListener)(enqueue, error, this.stopNewListenersToken, this.chain, this.idleWait);
if (!ok || errors.length > 0) {
console.log(`WhatsOnChain live ingestor ok=${ok} error count=${errors.length}`);
for (const e of errors)
console.log(`WhatsOnChain error code=${e.code} count=${e.count} message=${e.message}`);
}
if (ok)
break;
errors.length = 0;
}
}
stopListening() {
var _a, _b;
(_b = (_a = this.stopNewListenersToken).stop) === null || _b === void 0 ? void 0 : _b.call(_a);
}
}
exports.LiveIngestorWhatsOnChainWs = LiveIngestorWhatsOnChainWs;
//# sourceMappingURL=LiveIngestorWhatsOnChainWs.js.map