bitcore-node-zcash/app/models/Status.js

106 lines
2.3 KiB
JavaScript
Raw Normal View History

2014-01-15 12:15:14 -08:00
'use strict';
2014-03-05 18:03:56 -08:00
//var imports = require('soop').imports();
2014-01-15 12:15:14 -08:00
2014-03-05 18:03:56 -08:00
var async = require('async');
2014-05-07 05:45:44 -07:00
var bitcore = require('bitcore');
var RpcClient = bitcore.RpcClient;
2014-03-05 18:03:56 -08:00
var config = require('../../config/config');
var rpc = new RpcClient(config.bitcoind);
var bDb = require('../../lib/BlockDb').default();
2014-01-15 12:15:14 -08:00
function Status() {}
2014-01-15 12:15:14 -08:00
2014-03-05 18:03:56 -08:00
Status.prototype.getInfo = function(next) {
var that = this;
async.series([
function (cb) {
rpc.getInfo(function(err, info){
if (err) return cb(err);
that.info = info.result;
return cb();
});
},
], function (err) {
return next(err);
});
};
Status.prototype.getDifficulty = function(next) {
var that = this;
async.series([
function (cb) {
rpc.getDifficulty(function(err, df){
if (err) return cb(err);
that.difficulty = df.result;
return cb();
});
}
], function (err) {
return next(err);
});
};
Status.prototype.getTxOutSetInfo = function(next) {
var that = this;
async.series([
function (cb) {
rpc.getTxOutSetInfo(function(err, txout){
if (err) return cb(err);
that.txoutsetinfo = txout.result;
return cb();
});
}
], function (err) {
return next(err);
});
};
Status.prototype.getBestBlockHash = function(next) {
var that = this;
async.series([
function (cb) {
rpc.getBestBlockHash(function(err, bbh){
if (err) return cb(err);
that.bestblockhash = bbh.result;
return cb();
});
},
], function (err) {
return next(err);
});
};
Status.prototype.getLastBlockHash = function(next) {
var that = this;
bDb.getTip(function(err,tip) {
2014-03-05 18:03:56 -08:00
that.syncTipHash = tip;
async.waterfall(
[
function(callback){
rpc.getBlockCount(function(err, bc){
if (err) return callback(err);
callback(null, bc.result);
});
},
function(bc, callback){
rpc.getBlockHash(bc, function(err, bh){
if (err) return callback(err);
callback(null, bh.result);
});
}
],
function (err, result) {
that.lastblockhash = result;
return next();
}
);
});
};
module.exports = require('soop')(Status);