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)
|
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();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
@ -63,7 +66,12 @@ var getBlock = function(blockhash, cb) {
|
|||||||
isOrphan: 1,
|
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,
|
hash: b.hash,
|
||||||
time: b.ts || info.time,
|
time: b.ts || info.time,
|
||||||
txlength: info.tx.length,
|
txlength: info.tx.length,
|
||||||
|
poolInfo: info.poolInfo
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}, function(err, allblocks) {
|
}, function(err, allblocks) {
|
||||||
|
|||||||
@ -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,
|
||||||
|
|||||||
@ -11,37 +11,28 @@ 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);
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -54,6 +54,12 @@
|
|||||||
<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}}</a>
|
||||||
|
</td>
|
||||||
|
</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">
|
||||||
|
|||||||
@ -35,6 +35,7 @@
|
|||||||
<th>Height</th>
|
<th>Height</th>
|
||||||
<th>Timestamp</th>
|
<th>Timestamp</th>
|
||||||
<th class="text-right">Transactions</th>
|
<th class="text-right">Transactions</th>
|
||||||
|
<th class="text-right">Relayed by</th>
|
||||||
<th class="text-right">Size</th>
|
<th class="text-right">Size</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -46,6 +47,7 @@
|
|||||||
<td><a href="/block/{{b.hash}}">{{b.height}}</a></td>
|
<td><a href="/block/{{b.hash}}">{{b.height}}</a></td>
|
||||||
<td>{{b.time * 1000 | date:'medium'}}</td>
|
<td>{{b.time * 1000 | date:'medium'}}</td>
|
||||||
<td class="text-right">{{b.txlength}}</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>
|
<td class="text-right">{{b.size}}</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@ -13,6 +13,7 @@
|
|||||||
<th>Height</th>
|
<th>Height</th>
|
||||||
<th>Age</th>
|
<th>Age</th>
|
||||||
<th class="text-right"><span class="ellipsis">Transactions</span></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>
|
<th class="text-right">Size</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -24,6 +25,7 @@
|
|||||||
</td>
|
</td>
|
||||||
<td><span class="ellipsis">{{humanSince(b.time)}}</span></td>
|
<td><span class="ellipsis">{{humanSince(b.time)}}</span></td>
|
||||||
<td class="text-right">{{b.txlength}}</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>
|
<td class="text-right">{{b.size}} bytes</td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user