removed mongoose. method: block list by date

This commit is contained in:
Gustavo Cortez 2014-02-05 10:16:40 -03:00
parent fe8bb95e28
commit df33366277
7 changed files with 18 additions and 62 deletions

View File

@ -3,17 +3,17 @@
/**
* Module dependencies.
*/
var mongoose = require('mongoose'),
Block = mongoose.model('Block'),
common = require('./common'),
async = require('async');
var common = require('./common'),
async = require('async'),
BlockDb = require('../../lib/BlockDb').class();
var bdb = new BlockDb();
/**
* Find block by hash ...
*/
exports.block = function(req, res, next, hash) {
Block.fromHashWithInfo(hash, function(err, block) {
bdb.fromHashWithInfo(hash, function(err, block) {
if (err || ! block)
return common.handleErrors(err, res, next);
else {
@ -37,7 +37,7 @@ exports.show = function(req, res) {
* Show block by Height
*/
exports.blockindex = function(req, res, next, height) {
Block.blockIndex(height, function(err, hashStr) {
bdb.blockIndex(height, function(err, hashStr) {
if (err) {
console.log(err);
res.status(400).send('Bad Request'); // TODO
@ -49,7 +49,7 @@ exports.blockindex = function(req, res, next, height) {
};
var getBlock = function(blockhash, cb) {
Block.fromHashWithInfo(blockhash, function(err, block) {
bdb.fromHashWithInfo(blockhash, function(err, block) {
if (err) {
console.log(err);
return cb(err);
@ -103,6 +103,7 @@ exports.list = function(req, res) {
var prev = formatTimestamp(new Date((gte - 86400) * 1000));
var next = formatTimestamp(new Date(lte * 1000));
/*
Block
.find({
time: {
@ -134,4 +135,5 @@ exports.list = function(req, res) {
});
}
});
*/
};

View File

@ -4,11 +4,14 @@
* Module dependencies.
*/
var Transaction = require('../models/Transaction').class();
var Block = require('../models/Block');
var Address = require('../models/Address');
var async = require('async');
var common = require('./common');
var BlockDb = require('../../lib/BlockDb').class();
var bdb = new BlockDb();
/**
* Find transaction by hash ...
@ -68,7 +71,7 @@ exports.list = function(req, res, next) {
var txs;
if (bId) {
Block.fromHashWithInfo(bId, function(err, block) {
bdb.fromHashWithInfo(bId, function(err, block) {
if (err) {
console.log(err);
return res.status(500).send('Internal Server Error');

View File

@ -7,7 +7,7 @@ function spec() {
var util = require('bitcore/util/util'),
TransactionRpc = require('../../lib/TransactionRpc').class(),
TransactionOut = require('./TransactionOut'),
TransactionOut = require('../../lib/TransactionDb'),
async = require('async');
var CONCURRENCY = 20;

View File

@ -23,7 +23,6 @@ module.exports = {
root: rootPath,
appName: 'Insight ' + env,
port: process.env.PORT || 3000,
db: 'mongodb://localhost/insight-' + env,
leveldb: './db',
bitcoind: {
protocol: process.env.BITCOIND_PROTO || 'http',

View File

@ -9,9 +9,7 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var express = require('express'),
fs = require('fs'),
PeerSync = require('./lib/PeerSync').class(),
HistoricSync = require('./lib/HistoricSync').class(),
mongoose = require('mongoose');
HistoricSync = require('./lib/HistoricSync').class();
//Initializing system variables
var config = require('./config/config');
@ -21,22 +19,6 @@ var config = require('./config/config');
*/
var expressApp = express();
/**
* Bootstrap db connection
*/
// If mongod is running
mongoose.connection.on('open', function() {
console.log('Connected to mongo server.');
});
// If mongod is not running
mongoose.connection.on('error', function(err) {
console.log('Could not connect to mongo server!');
console.log(err);
});
mongoose.connect(config.db);
/**
* Bootstrap models
*/

View File

@ -160,9 +160,7 @@ function spec() {
});
};
return BlockDb;
return BlockDb;
}
module.defineClass(spec);

View File

@ -4,7 +4,6 @@ require('classtool');
function spec() {
var mongoose = require('mongoose');
var config = require('../config/config');
var sockets = require('../app/controllers/socket.js');
var BlockDb = require('./BlockDb').class();
@ -22,34 +21,7 @@ function spec() {
self.opts = opts;
if (!(opts && opts.skipDbConnection)) {
if (mongoose.connection.readyState !== 1) {
mongoose.connect(config.db, function(err) {
if (err) {
console.log('CRITICAL ERROR: connecting to mongoDB:',err);
return (err);
}
});
}
self.db = mongoose.connection;
self.db.on('error', function(err) {
console.log('MongoDB ERROR:' + err);
return cb(err);
});
self.db.on('disconnect', function(err) {
console.log('MongoDB disconnect:' + err);
return cb(err);
});
return self.db.once('open', function(err) {
return cb(err);
});
}
else return cb();
return cb();
};
Sync.prototype.close = function() {