added Minig Pool Detection

This commit is contained in:
Mario Colque 2014-02-18 14:35:54 -03:00
parent 87fecad007
commit db064e9527
4 changed files with 37 additions and 22 deletions

View File

@ -17,8 +17,11 @@ exports.block = function(req, res, next, hash) {
if (err || !block) if (err || !block)
return common.handleErrors(err, res, next); return common.handleErrors(err, res, next);
else { else {
req.block = block.info; bdb.getPoolInfo(block.info.tx[0], function(info) {
return next(); block.info.poolInfo = info;
req.block = block.info;
return next();
});
} }
}); });
}; };

View File

@ -25,6 +25,9 @@ function spec(b) {
var Rpc = b.rpc || require('./Rpc').class(); var Rpc = b.rpc || require('./Rpc').class();
var PoolMatch = b.poolMatch || require('./PoolMatch').class(config); var PoolMatch = b.poolMatch || require('./PoolMatch').class(config);
var buffertools = require('buffertools');
var TransactionDb = require('./TransactionDb.js').class();
var BlockDb = function() { var BlockDb = function() {
BlockDb.super(this, arguments); BlockDb.super(this, arguments);
this.poolMatch = new PoolMatch(); this.poolMatch = new PoolMatch();
@ -57,7 +60,7 @@ function spec(b) {
return db.batch() return db.batch()
.put(time_key, b.hash) .put(time_key, b.hash)
.put(MAIN_PREFIX + b.hash, 1) .put(MAIN_PREFIX + b.hash, 1)
.put(PREV_PREFIX + b.hash, b.previousblockhash) .put(PREV_PREFIX + b.hash, b.previousblockhash)
.write(function(err){ .write(function(err){
if (!err) { if (!err) {
self.emit('new_block', {blockid: b.hash}); self.emit('new_block', {blockid: b.hash});
@ -164,6 +167,21 @@ function spec(b) {
}); });
}; };
BlockDb.prototype.getPoolInfo = function(tx, cb) {
var tr = new TransactionDb();
var self = this;
tr._getInfo(tx, function(e, a) {
if (e) return cb(false);
if (a.isCoinBase) {
var coinbaseHexBuffer = new Buffer(a.vin[0].coinbase, 'hex');
var a = self.poolMatch.match(coinbaseHexBuffer);
return cb(a);
}
});
};
BlockDb.prototype.fromHashWithInfo = function(hash, cb) { BlockDb.prototype.fromHashWithInfo = function(hash, cb) {
var self = this; var self = this;
@ -175,7 +193,6 @@ function spec(b) {
if (err) return cb(err); if (err) return cb(err);
info.isMainChain = val ? true : false; info.isMainChain = val ? true : false;
// info.poolInfo = self.poolMatch.match(info.hex);
return cb(null, { return cb(null, {
hash: hash, hash: hash,

View File

@ -11,36 +11,27 @@ function spec(b) {
var PoolMatch = function() { var PoolMatch = function() {
var self = this; var self = this;
self.strings={}; self.strings = {};
db.forEach(function(pool) { db.forEach(function(pool) {
pool.searchStrings.forEach(function(s) { pool.searchStrings.forEach(function(s) {
if (!self.strings[s]) self.strings[s] = []; self.strings[s] = {
self.strings[s].push(pool); poolName: pool.poolName,
url: pool.url
};
}); });
}); });
Object.keys( self.strings, function(s) {
delete self.strings[s].searchStrings;
});
self.stringsK = Object.keys(self.strings);
self.stringsKl = self.stringsK.length;
}; };
PoolMatch.prototype.match = function(buffer) { PoolMatch.prototype.match = function(buffer) {
var self = this; var self = this;
for(var k in self.strings) {
var match; if (buffertools.indexOf(buffer, k) >= 0) {
var i =0; return self.strings[k];
while (!match && i < self.stringsKl) {
var k = self.stringsK[i++];
if ( buffertools.indexOf(buffer,self.strings[k]) >= 0 ) {
match = self.strings[k];
} }
} };
return match;
}; };
return PoolMatch; return PoolMatch;
} }
module.defineClass(spec); module.defineClass(spec);

View File

@ -53,6 +53,10 @@
<td><strong>Timestamp</strong></td> <td><strong>Timestamp</strong></td>
<td class="text-right text-muted">{{block.time * 1000 | date:'medium'}}</td> <td class="text-right text-muted">{{block.time * 1000 | date:'medium'}}</td>
</tr> </tr>
<tr data-ng-show="block.poolInfo">
<td><strong>Relayed by</strong></td>
<td class="text-right text-muted"><a href="{{block.poolInfo.url}}" target="_blank" title="{{block.poolInfo.poolName}}">{{block.poolInfo.poolName}} <i class="glyphicon glyphicon-new-window"></i></a>
</tr>
<tr> <tr>
<td><strong>Merkle Root</strong></td> <td><strong>Merkle Root</strong></td>
<td class="text-right text-muted"> <td class="text-right text-muted">