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)
return common.handleErrors(err, res, next);
else {
bdb.getPoolInfo(block.info.tx[0], function(info) {
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 PoolMatch = b.poolMatch || require('./PoolMatch').class(config);
var buffertools = require('buffertools');
var TransactionDb = require('./TransactionDb.js').class();
var BlockDb = function() {
BlockDb.super(this, arguments);
this.poolMatch = new PoolMatch();
@ -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) {
var self = this;
@ -175,7 +193,6 @@ function spec(b) {
if (err) return cb(err);
info.isMainChain = val ? true : false;
// info.poolInfo = self.poolMatch.match(info.hex);
return cb(null, {
hash: hash,

View File

@ -14,33 +14,24 @@ function spec(b) {
self.strings = {};
db.forEach(function(pool) {
pool.searchStrings.forEach(function(s) {
if (!self.strings[s]) self.strings[s] = [];
self.strings[s].push(pool);
self.strings[s] = {
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) {
var self = this;
var match;
var i =0;
while (!match && i < self.stringsKl) {
var k = self.stringsK[i++];
if ( buffertools.indexOf(buffer,self.strings[k]) >= 0 ) {
match = self.strings[k];
for(var k in self.strings) {
if (buffertools.indexOf(buffer, k) >= 0) {
return self.strings[k];
}
}
return match;
};
};
return PoolMatch;
}
module.defineClass(spec);

View File

@ -53,6 +53,10 @@
<td><strong>Timestamp</strong></td>
<td class="text-right text-muted">{{block.time * 1000 | date:'medium'}}</td>
</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>
<td><strong>Merkle Root</strong></td>
<td class="text-right text-muted">