bitcore-node
Version:
A blockchain indexing node with extended capabilities using bitcore
41 lines • 1.79 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.EventStorage = exports.EventModel = void 0;
const base_1 = require("./base");
class EventModel extends base_1.BaseModel {
constructor(storage) {
super('events', storage);
this.allowedPaging = [];
}
async onConnect() {
await this.collection.createIndex({ type: 1, emitTime: 1 }, { background: true });
await this.collection.createIndex({ emitTime: 1 }, { background: true, expireAfterSeconds: 60 * 5 });
}
signalBlock(block) {
return this.collection.insertOne({ payload: block, emitTime: new Date(), type: 'block' });
}
signalTx(tx) {
return this.collection.insertOne({ payload: tx, emitTime: new Date(), type: 'tx' });
}
signalTxs(txs) {
this.collection.insertMany(txs.map(tx => ({ payload: tx, emitTime: new Date(), type: 'tx' })));
}
signalAddressCoin(payload) {
return this.collection.insertOne({ payload, emitTime: new Date(), type: 'coin' });
}
signalAddressCoins(coins) {
return this.collection.insertMany(coins.map(coin => ({ payload: coin, emitTime: new Date(), type: 'coin' })));
}
getBlockTail(lastSeen) {
return this.collection.find({ type: 'block', emitTime: { $gte: lastSeen } }).addCursorFlag('noCursorTimeout', true);
}
getTxTail(lastSeen) {
return this.collection.find({ type: 'tx', emitTime: { $gte: lastSeen } }).addCursorFlag('noCursorTimeout', true);
}
getCoinTail(lastSeen) {
return this.collection.find({ type: 'coin', emitTime: { $gte: lastSeen } }).addCursorFlag('noCursorTimeout', true);
}
}
exports.EventModel = EventModel;
exports.EventStorage = new EventModel();
//# sourceMappingURL=events.js.map