2014-01-15 12:15:14 -08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
require('classtool');
|
|
|
|
|
|
|
|
function spec() {
|
|
|
|
var async = require('async');
|
|
|
|
var RpcClient = require('bitcore/RpcClient').class();
|
|
|
|
var config = require('../../config/config');
|
|
|
|
var rpc = new RpcClient(config.bitcoind);
|
|
|
|
|
|
|
|
function Status() {
|
|
|
|
}
|
|
|
|
|
|
|
|
Status.prototype.getInfo = function(next) {
|
|
|
|
var that = this;
|
|
|
|
async.series([
|
|
|
|
function (cb) {
|
2014-01-15 12:39:11 -08:00
|
|
|
rpc.getInfo(function(err, info){
|
2014-01-15 12:15:14 -08:00
|
|
|
if (err) return cb(err);
|
|
|
|
|
2014-01-15 12:39:11 -08:00
|
|
|
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;
|
2014-01-15 12:15:14 -08:00
|
|
|
return cb();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
], function (err) {
|
|
|
|
return next(err);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-01-15 13:05:02 -08:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-01-15 13:27:06 -08:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-01-16 10:33:33 -08:00
|
|
|
Status.prototype.getLastBlockHash = function(next) {
|
|
|
|
var that = this;
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
}
|
2014-01-16 18:23:10 -08:00
|
|
|
],
|
2014-01-16 10:33:33 -08:00
|
|
|
function (err, result) {
|
|
|
|
that.lastblockhash = result;
|
|
|
|
return next();
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
2014-01-15 12:15:14 -08:00
|
|
|
return Status;
|
|
|
|
|
|
|
|
}
|
|
|
|
module.defineClass(spec);
|
|
|
|
|