bitcore-node
Version:
A blockchain indexing node with extended capabilities using bitcore
50 lines • 2.3 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseTransaction = void 0;
const storage_1 = require("../services/storage");
const base_1 = require("./base");
class BaseTransaction extends base_1.BaseModel {
constructor(storage) {
super('transactions', storage);
this.allowedPaging = [
{ key: 'blockHash', type: 'string' },
{ key: 'blockHeight', type: 'number' },
{ key: 'blockTimeNormalized', type: 'date' },
{ key: 'txid', type: 'string' }
];
}
onConnect() {
this.collection.createIndex({ txid: 1 }, { background: true });
this.collection.createIndex({ chain: 1, network: 1, blockHeight: 1 }, { background: true });
this.collection.createIndex({ blockHash: 1 }, { background: true });
this.collection.createIndex({ chain: 1, network: 1, blockTimeNormalized: 1 }, { background: true });
this.collection.createIndex({ wallets: 1, blockTimeNormalized: 1 }, { background: true, partialFilterExpression: { 'wallets.0': { $exists: true } } });
this.collection.createIndex({ wallets: 1, blockHeight: 1 }, { background: true, partialFilterExpression: { 'wallets.0': { $exists: true } } });
}
getTransactions(params) {
let originalQuery = params.query;
const { query, options } = storage_1.Storage.getFindOptions(this, params.options);
const finalQuery = Object.assign({}, originalQuery, query);
return this.collection.find(finalQuery, options).addCursorFlag('noCursorTimeout', true);
}
toMempoolSafeUpsert(mongoOp, height) {
if (height >= 0 /* SpentHeightIndicators.minimum */) {
return mongoOp;
}
else {
const update = mongoOp.updateOne.update;
return {
updateOne: {
filter: mongoOp.updateOne.filter,
update: {
$setOnInsert: { ...(update.$set && update.$set), ...(update.$setOnInsert && update.$setOnInsert) }
},
upsert: true,
forceServerObjectId: true
}
};
}
}
}
exports.BaseTransaction = BaseTransaction;
//# sourceMappingURL=baseTransaction.js.map