getTxById added to model
This commit is contained in:
parent
801fbf62e8
commit
efe19444d5
@ -2,6 +2,8 @@ const Transactions = require('../../models/transaction.js');
|
||||
const logger = require('../logger');
|
||||
const config = require('../../config');
|
||||
|
||||
const txs = new Transactions();
|
||||
|
||||
// For now, blocks handles these calls.
|
||||
// These will be replaced with more advanced mongo
|
||||
// No optimization yet.
|
||||
@ -84,11 +86,7 @@ function getTopTransactions(cb) {
|
||||
}
|
||||
|
||||
function getTxById(txid, cb) {
|
||||
getTransaction(
|
||||
{ hash: txid },
|
||||
{ },
|
||||
1,
|
||||
0,
|
||||
txs.byId(txid,
|
||||
(err, transaction) => {
|
||||
if (err) {
|
||||
logger.log('error',
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
const mongoose = require('mongoose');
|
||||
const Input = require('./input');
|
||||
const Output = require('./output');
|
||||
const logger = require('../lib/logger');
|
||||
|
||||
const Schema = mongoose.Schema;
|
||||
|
||||
@ -24,6 +25,18 @@ const TransactionSchema = new Schema({
|
||||
|
||||
TransactionSchema.index({ hash: 1 });
|
||||
|
||||
const Transaction = mongoose.model('Transaction', TransactionSchema);
|
||||
TransactionSchema.methods.byId = function txById(txid, cb) {
|
||||
return this.model('Transaction').findOne(
|
||||
{ hash: txid },
|
||||
(err, tx) => {
|
||||
if (err) {
|
||||
logger.log('error',
|
||||
`TransactionSchema.methods.byId: ${err}`);
|
||||
return cb(err);
|
||||
}
|
||||
return cb(null, tx);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = Transaction;
|
||||
|
||||
module.exports = mongoose.model('Transaction', TransactionSchema);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user