Merge pull request #369 from colkito/feature/mining-pool-detection
added Minig Pool Detection
This commit is contained in:
commit
d23648befc
@ -17,8 +17,11 @@ exports.block = function(req, res, next, hash) {
|
||||
if (err || !block)
|
||||
return common.handleErrors(err, res, next);
|
||||
else {
|
||||
req.block = block.info;
|
||||
return next();
|
||||
bdb.getPoolInfo(block.info.tx[0], function(info) {
|
||||
block.info.poolInfo = info;
|
||||
req.block = block.info;
|
||||
return next();
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
||||
@ -63,7 +66,12 @@ var getBlock = function(blockhash, cb) {
|
||||
isOrphan: 1,
|
||||
};
|
||||
}
|
||||
return cb(err, block.info);
|
||||
|
||||
bdb.getPoolInfo(block.info.tx[0], function(info) {
|
||||
block.info.poolInfo = info;
|
||||
return cb(err, block.info);
|
||||
});
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
@ -127,6 +135,7 @@ exports.list = function(req, res) {
|
||||
hash: b.hash,
|
||||
time: b.ts || info.time,
|
||||
txlength: info.tx.length,
|
||||
poolInfo: info.poolInfo
|
||||
});
|
||||
});
|
||||
}, function(err, allblocks) {
|
||||
|
||||
@ -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();
|
||||
@ -57,7 +60,7 @@ function spec(b) {
|
||||
return db.batch()
|
||||
.put(time_key, b.hash)
|
||||
.put(MAIN_PREFIX + b.hash, 1)
|
||||
.put(PREV_PREFIX + b.hash, b.previousblockhash)
|
||||
.put(PREV_PREFIX + b.hash, b.previousblockhash)
|
||||
.write(function(err){
|
||||
if (!err) {
|
||||
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) {
|
||||
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,
|
||||
|
||||
@ -11,37 +11,28 @@ function spec(b) {
|
||||
var PoolMatch = function() {
|
||||
var self = this;
|
||||
|
||||
self.strings={};
|
||||
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);
|
||||
|
||||
|
||||
|
||||
@ -54,6 +54,12 @@
|
||||
<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}}</a>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td><strong>Merkle Root</strong></td>
|
||||
<td class="text-right text-muted">
|
||||
|
||||
@ -35,6 +35,7 @@
|
||||
<th>Height</th>
|
||||
<th>Timestamp</th>
|
||||
<th class="text-right">Transactions</th>
|
||||
<th class="text-right">Relayed by</th>
|
||||
<th class="text-right">Size</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -46,6 +47,7 @@
|
||||
<td><a href="/block/{{b.hash}}">{{b.height}}</a></td>
|
||||
<td>{{b.time * 1000 | date:'medium'}}</td>
|
||||
<td class="text-right">{{b.txlength}}</td>
|
||||
<td class="text-right"><a href="{{b.poolInfo.url}}" title="{{b.poolInfo.poolName}}" target="_blank" data-ng-show="b.poolInfo">{{b.poolInfo.poolName}}</a></td>
|
||||
<td class="text-right">{{b.size}}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
@ -13,6 +13,7 @@
|
||||
<th>Height</th>
|
||||
<th>Age</th>
|
||||
<th class="text-right"><span class="ellipsis">Transactions</span></th>
|
||||
<th class="text-right"><span class="ellipsis">Relayed by</span></th>
|
||||
<th class="text-right">Size</th>
|
||||
</tr>
|
||||
</thead>
|
||||
@ -24,6 +25,7 @@
|
||||
</td>
|
||||
<td><span class="ellipsis">{{humanSince(b.time)}}</span></td>
|
||||
<td class="text-right">{{b.txlength}}</td>
|
||||
<td class="text-right"><a href="{{b.poolInfo.url}}" title="{{b.poolInfo.poolName}}" target="_blank" data-ng-show="b.poolInfo">{{b.poolInfo.poolName}}</a></td>
|
||||
<td class="text-right">{{b.size}} bytes</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user