removed mongoose. method: block list by date
This commit is contained in:
parent
fe8bb95e28
commit
df33366277
@ -3,17 +3,17 @@
|
|||||||
/**
|
/**
|
||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
var mongoose = require('mongoose'),
|
var common = require('./common'),
|
||||||
Block = mongoose.model('Block'),
|
async = require('async'),
|
||||||
common = require('./common'),
|
BlockDb = require('../../lib/BlockDb').class();
|
||||||
async = require('async');
|
|
||||||
|
|
||||||
|
var bdb = new BlockDb();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find block by hash ...
|
* Find block by hash ...
|
||||||
*/
|
*/
|
||||||
exports.block = function(req, res, next, hash) {
|
exports.block = function(req, res, next, hash) {
|
||||||
Block.fromHashWithInfo(hash, function(err, block) {
|
bdb.fromHashWithInfo(hash, function(err, block) {
|
||||||
if (err || ! block)
|
if (err || ! block)
|
||||||
return common.handleErrors(err, res, next);
|
return common.handleErrors(err, res, next);
|
||||||
else {
|
else {
|
||||||
@ -37,7 +37,7 @@ exports.show = function(req, res) {
|
|||||||
* Show block by Height
|
* Show block by Height
|
||||||
*/
|
*/
|
||||||
exports.blockindex = function(req, res, next, height) {
|
exports.blockindex = function(req, res, next, height) {
|
||||||
Block.blockIndex(height, function(err, hashStr) {
|
bdb.blockIndex(height, function(err, hashStr) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
res.status(400).send('Bad Request'); // TODO
|
res.status(400).send('Bad Request'); // TODO
|
||||||
@ -49,7 +49,7 @@ exports.blockindex = function(req, res, next, height) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
var getBlock = function(blockhash, cb) {
|
var getBlock = function(blockhash, cb) {
|
||||||
Block.fromHashWithInfo(blockhash, function(err, block) {
|
bdb.fromHashWithInfo(blockhash, function(err, block) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return cb(err);
|
return cb(err);
|
||||||
@ -103,6 +103,7 @@ exports.list = function(req, res) {
|
|||||||
var prev = formatTimestamp(new Date((gte - 86400) * 1000));
|
var prev = formatTimestamp(new Date((gte - 86400) * 1000));
|
||||||
var next = formatTimestamp(new Date(lte * 1000));
|
var next = formatTimestamp(new Date(lte * 1000));
|
||||||
|
|
||||||
|
/*
|
||||||
Block
|
Block
|
||||||
.find({
|
.find({
|
||||||
time: {
|
time: {
|
||||||
@ -134,4 +135,5 @@ exports.list = function(req, res) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
*/
|
||||||
};
|
};
|
||||||
|
|||||||
@ -4,11 +4,14 @@
|
|||||||
* Module dependencies.
|
* Module dependencies.
|
||||||
*/
|
*/
|
||||||
var Transaction = require('../models/Transaction').class();
|
var Transaction = require('../models/Transaction').class();
|
||||||
var Block = require('../models/Block');
|
|
||||||
var Address = require('../models/Address');
|
var Address = require('../models/Address');
|
||||||
var async = require('async');
|
var async = require('async');
|
||||||
var common = require('./common');
|
var common = require('./common');
|
||||||
|
|
||||||
|
var BlockDb = require('../../lib/BlockDb').class();
|
||||||
|
|
||||||
|
var bdb = new BlockDb();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Find transaction by hash ...
|
* Find transaction by hash ...
|
||||||
@ -68,7 +71,7 @@ exports.list = function(req, res, next) {
|
|||||||
var txs;
|
var txs;
|
||||||
|
|
||||||
if (bId) {
|
if (bId) {
|
||||||
Block.fromHashWithInfo(bId, function(err, block) {
|
bdb.fromHashWithInfo(bId, function(err, block) {
|
||||||
if (err) {
|
if (err) {
|
||||||
console.log(err);
|
console.log(err);
|
||||||
return res.status(500).send('Internal Server Error');
|
return res.status(500).send('Internal Server Error');
|
||||||
|
|||||||
@ -7,7 +7,7 @@ function spec() {
|
|||||||
|
|
||||||
var util = require('bitcore/util/util'),
|
var util = require('bitcore/util/util'),
|
||||||
TransactionRpc = require('../../lib/TransactionRpc').class(),
|
TransactionRpc = require('../../lib/TransactionRpc').class(),
|
||||||
TransactionOut = require('./TransactionOut'),
|
TransactionOut = require('../../lib/TransactionDb'),
|
||||||
async = require('async');
|
async = require('async');
|
||||||
|
|
||||||
var CONCURRENCY = 20;
|
var CONCURRENCY = 20;
|
||||||
|
|||||||
@ -23,7 +23,6 @@ module.exports = {
|
|||||||
root: rootPath,
|
root: rootPath,
|
||||||
appName: 'Insight ' + env,
|
appName: 'Insight ' + env,
|
||||||
port: process.env.PORT || 3000,
|
port: process.env.PORT || 3000,
|
||||||
db: 'mongodb://localhost/insight-' + env,
|
|
||||||
leveldb: './db',
|
leveldb: './db',
|
||||||
bitcoind: {
|
bitcoind: {
|
||||||
protocol: process.env.BITCOIND_PROTO || 'http',
|
protocol: process.env.BITCOIND_PROTO || 'http',
|
||||||
|
|||||||
20
insight.js
20
insight.js
@ -9,9 +9,7 @@ process.env.NODE_ENV = process.env.NODE_ENV || 'development';
|
|||||||
var express = require('express'),
|
var express = require('express'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
PeerSync = require('./lib/PeerSync').class(),
|
PeerSync = require('./lib/PeerSync').class(),
|
||||||
HistoricSync = require('./lib/HistoricSync').class(),
|
HistoricSync = require('./lib/HistoricSync').class();
|
||||||
mongoose = require('mongoose');
|
|
||||||
|
|
||||||
|
|
||||||
//Initializing system variables
|
//Initializing system variables
|
||||||
var config = require('./config/config');
|
var config = require('./config/config');
|
||||||
@ -21,22 +19,6 @@ var config = require('./config/config');
|
|||||||
*/
|
*/
|
||||||
var expressApp = express();
|
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
|
* Bootstrap models
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -160,9 +160,7 @@ function spec() {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
return BlockDb;
|
||||||
|
|
||||||
return BlockDb;
|
|
||||||
}
|
}
|
||||||
module.defineClass(spec);
|
module.defineClass(spec);
|
||||||
|
|
||||||
|
|||||||
30
lib/Sync.js
30
lib/Sync.js
@ -4,7 +4,6 @@ require('classtool');
|
|||||||
|
|
||||||
|
|
||||||
function spec() {
|
function spec() {
|
||||||
var mongoose = require('mongoose');
|
|
||||||
var config = require('../config/config');
|
var config = require('../config/config');
|
||||||
var sockets = require('../app/controllers/socket.js');
|
var sockets = require('../app/controllers/socket.js');
|
||||||
var BlockDb = require('./BlockDb').class();
|
var BlockDb = require('./BlockDb').class();
|
||||||
@ -22,34 +21,7 @@ function spec() {
|
|||||||
|
|
||||||
self.opts = opts;
|
self.opts = opts;
|
||||||
|
|
||||||
if (!(opts && opts.skipDbConnection)) {
|
return cb();
|
||||||
|
|
||||||
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();
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Sync.prototype.close = function() {
|
Sync.prototype.close = function() {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user