Include mining pool information.
This commit is contained in:
parent
4a850e2758
commit
c7054051e3
@ -4,10 +4,22 @@ var common = require('./common');
|
||||
var async = require('async');
|
||||
var bitcore = require('bitcore');
|
||||
var BufferUtil = bitcore.util.buffer;
|
||||
var pools = require('../pools.json');
|
||||
var BN = bitcore.crypto.BN;
|
||||
|
||||
function BlockController(node) {
|
||||
var self = this;
|
||||
this.node = node;
|
||||
|
||||
this.poolStrings = {};
|
||||
pools.forEach(function(pool) {
|
||||
pool.searchStrings.forEach(function(s) {
|
||||
self.poolStrings[s] = {
|
||||
poolName: pool.poolName,
|
||||
url: pool.url
|
||||
};
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
var BLOCK_LIMIT = 200;
|
||||
@ -55,7 +67,8 @@ BlockController.prototype.transformBlock = function(block, info) {
|
||||
previousblockhash: blockObj.header.prevHash,
|
||||
nextblockhash: this.node.services.bitcoind.getNextBlockHash(block.hash),
|
||||
reward: this.getBlockReward(info.height) / 1e8,
|
||||
isMainChain: info.isMainChain
|
||||
isMainChain: info.isMainChain,
|
||||
poolInfo: this.getPoolInfo(block)
|
||||
};
|
||||
};
|
||||
|
||||
@ -155,7 +168,7 @@ BlockController.prototype.list = function(req, res) {
|
||||
hash: block.hash,
|
||||
time: block.header.time,
|
||||
txlength: block.transactions.length,
|
||||
poolInfo: {}
|
||||
poolInfo: self.getPoolInfo(block)
|
||||
};
|
||||
}),
|
||||
length: blocks.length,
|
||||
@ -179,6 +192,18 @@ BlockController.prototype.list = function(req, res) {
|
||||
});
|
||||
};
|
||||
|
||||
BlockController.prototype.getPoolInfo = function(block) {
|
||||
var coinbaseBuffer = block.transactions[0].inputs[0]._scriptBuffer;
|
||||
|
||||
for(var k in this.poolStrings) {
|
||||
if (coinbaseBuffer.toString('utf-8').match(k)) {
|
||||
return this.poolStrings[k];
|
||||
}
|
||||
}
|
||||
|
||||
return {};
|
||||
};
|
||||
|
||||
//helper to convert timestamps to yyyy-mm-dd format
|
||||
BlockController.prototype.formatTimestamp = function(date) {
|
||||
var yyyy = date.getUTCFullYear().toString();
|
||||
@ -198,7 +223,7 @@ BlockController.prototype.getBlockReward = function(height) {
|
||||
// Subsidy is cut in half every 210,000 blocks which will occur approximately every 4 years.
|
||||
var subsidy = new BN(50 * 1e8);
|
||||
subsidy = subsidy.shrn(halvings);
|
||||
|
||||
|
||||
return parseInt(subsidy.toString(10));
|
||||
};
|
||||
|
||||
|
||||
235
pools.json
Normal file
235
pools.json
Normal file
@ -0,0 +1,235 @@
|
||||
[
|
||||
{
|
||||
"poolName": "50BTC",
|
||||
"url": "https://50btc.com/",
|
||||
"searchStrings": [
|
||||
"50BTC.com",
|
||||
"50btc.com"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "175btc",
|
||||
"url": "http://www.175btc.com/",
|
||||
"searchStrings": [
|
||||
"Mined By 175btc.com"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "ASICminer",
|
||||
"url": "https://bitcointalk.org/index.php?topic=99497.0",
|
||||
"searchStrings": [
|
||||
"Mined By ASICMiner"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "AntMiner",
|
||||
"url": "https://bitmaintech.com/",
|
||||
"searchStrings": [
|
||||
"AntPool"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "agentD",
|
||||
"url": "http://",
|
||||
"searchStrings": [
|
||||
"agentD"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "Bitfury",
|
||||
"url": "http://bitfury.org/",
|
||||
"searchStrings": [
|
||||
"2av0id51pct"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "BitMinter",
|
||||
"url": "https://bitminter.com/",
|
||||
"searchStrings": [
|
||||
"BitMinter"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "Bitparking",
|
||||
"url": "http://bitparking.com/",
|
||||
"searchStrings": [
|
||||
"bitparking"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "BTC Guild",
|
||||
"url": "https://www.btcguild.com/",
|
||||
"searchStrings": [
|
||||
"Mined by BTC Guild",
|
||||
"BTC Guild"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "bcpool.io",
|
||||
"url": "https://bcpool.io/",
|
||||
"searchStrings": [
|
||||
"bcpool"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "Discus Fish",
|
||||
"url": "http://f2pool.com/",
|
||||
"searchStrings": [
|
||||
"七彩神仙鱼",
|
||||
"Made in China",
|
||||
"Mined by user"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "Discus Fish Solo",
|
||||
"url": "http://f2pool.com/",
|
||||
"searchStrings": [
|
||||
"For Pierce and Paul"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "Cointerra",
|
||||
"url": "http://cointerra.com/",
|
||||
"searchStrings": [
|
||||
"cointerra"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "Eligius",
|
||||
"url": "http://eligius.st/",
|
||||
"searchStrings": [
|
||||
"Eligius"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "EclipseMC",
|
||||
"url": "https://eclipsemc.com/",
|
||||
"searchStrings": [
|
||||
"Josh Zerlan was here!",
|
||||
"EclipseMC",
|
||||
"Aluminum Falcon"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "GIVE-ME-COINS",
|
||||
"url": "https://give-me-coins.com/",
|
||||
"searchStrings": [
|
||||
"Mined at GIVE-ME-COINS.com"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "ghash.io",
|
||||
"url": "https://ghash.io/",
|
||||
"searchStrings": [
|
||||
"ghash.io",
|
||||
"GHash.IO"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "HHTT",
|
||||
"url": "http://hhtt.1209k.com/",
|
||||
"searchStrings": [
|
||||
"HHTT"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "KNCminer",
|
||||
"url": "https://www.kncminer.com/",
|
||||
"searchStrings": [
|
||||
"KnCMiner"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "Megabigpower",
|
||||
"url": "http://megabigpower.com/",
|
||||
"searchStrings": [
|
||||
"megabigpower.com"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "MultiCoin",
|
||||
"url": "https://multicoin.co/",
|
||||
"searchStrings": [
|
||||
"MultiCoin.co"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "Mt Red",
|
||||
"url": "https://mtred.com/",
|
||||
"searchStrings": [
|
||||
"/mtred/"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "MaxBTC",
|
||||
"url": "https://www.maxbtc.com",
|
||||
"searchStrings": [
|
||||
"MaxBTC"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "NMCbit",
|
||||
"url": "http://nmcbit.com/",
|
||||
"searchStrings": [
|
||||
"nmcbit.com"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "ozcoin",
|
||||
"url": "https://ozco.in/",
|
||||
"searchStrings": [
|
||||
"ozco.in",
|
||||
"ozcoin"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "Polmine.pl",
|
||||
"url": "https://polmine.pl/",
|
||||
"searchStrings": [
|
||||
"by polmine.pl"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "simplecoin",
|
||||
"url": "http://simplecoin.us/",
|
||||
"searchStrings": [
|
||||
"simplecoin.us ftw"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "Slush",
|
||||
"url": "https://mining.bitcoin.cz/",
|
||||
"searchStrings": [
|
||||
"slush"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "TripleMining",
|
||||
"url": "https://www.triplemining.com/",
|
||||
"searchStrings": [
|
||||
"Triplemining.com"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "wizkid057",
|
||||
"url": "http://wizkid057.com/btc",
|
||||
"searchStrings": [
|
||||
"wizkid057"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "Yourbtc.net",
|
||||
"url": "http://yourbtc.net/",
|
||||
"searchStrings": [
|
||||
"yourbtc.net"
|
||||
]
|
||||
},
|
||||
{
|
||||
"poolName": "BTCChina Pool",
|
||||
"url": "https://pool.btcchina.com/",
|
||||
"searchStrings": [
|
||||
"BTCChina Pool",
|
||||
"btcchina.com"
|
||||
]
|
||||
}
|
||||
]
|
||||
@ -6,36 +6,37 @@ var BlockController = require('../lib/blocks');
|
||||
var bitcore = require('bitcore');
|
||||
var _ = require('lodash');
|
||||
|
||||
var blocks = {
|
||||
'0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7': '07000020a491892cca9f143f7f00b8d65bbce0204bb32e17e914325fa5010000000000003e28f0519ecf01f7f01ea8da61084b2e4741a18ce1f3738117b84458353764b06fb9e35567f20c1a78eb626f0301000000010000000000000000000000000000000000000000000000000000000000000000ffffffff2303d6250800feb0aae355fe263600000963676d696e6572343208ae5800000000000000ffffffff01c018824a000000001976a91468bedce8982d25c3b6b03f6238cbad00378b8ead88ac000000000100000002ad5a14ae9d0f3221b790c4fc590fddceea1456e5692d8c4bf1ff7175f2b0c987000000008b4830450221008e5df62719cd92d7b137d00bbd27f153f2909bcad3a300960bc1020ec6d5e961022039df51600ff4fb5da5a794d1648c6b47c1f7d277fd5877fb5e52a730a3595f8c014104eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307ffffffff9621ac65bc22ea593ca9a61a8d63e461bf3d3f277989df5d3bd33ddfae0aa1d8000000008a4730440220761464d7bab9515d92260762a97af82a9b25d202d8f7197b1aaec81b6fed541f022059f99606de6b06e17b2cd102dceb3807ebdd9e777a5b77c9a0b3672f5eabcb31014104eb1e0ccd9afcac42229348dd776e991c69551ae3474340fada12e787e51758397e1d3afdba360d6374261125ea3b6ea079a5f202c150dfd729e1062d9176a307ffffffff02dc374401000000001976a9144b7b335f978f130269fe661423258ae9642df8a188ac72b3d000000000001976a9146efcf883b4b6f9997be9a0600f6c095fe2bd2d9288ac000000000100000002060d3cb6dfb7ffe85e2908010fea63190c9707e96fc7448128eb895b5e222771030000006b483045022100f67cffc0ae23adb236ff3edb4a9736e277605db30cc7708dfab8cf1e1483bbce022052396aa5d664ec1cb65992c423fd9a17e94dc7af328d2d559e90746dd195ca5901210346134da14907581d8190d3980caaf46d95e4eb9c1ca8e70f1fc6007fefb1909dfeffffff7b2d8a8263cffbdb722e2a5c74166e6f2258634e277c0b08f51b578b667e2fba000000006a473044022077222a91cda23af69179377c62d84a176fb12caff6c5cbf6ae9e5957ff3b1afe0220768edead76819228dcba18cca3c9a5a5d4c32919720f21df21a297ba375bbe5c012103371ea5a4dfe356b3ea4042a537d7ab7ee0faabd43e21b6cc076fda2240629eeefeffffff02209a1d00000000001976a9148e451eec7ca0a1764b4ab119274efdd2727b3c8588ac40420f00000000001976a914d0fce8f064cd1059a6a11501dd66fe42368572b088accb250800',
|
||||
'000000000008fbb2e358e382a6f6948b2da24563bba183af447e6e2542e8efc7': '0300000041c49521c6106debe1221077ca9e71850e3c328037e5e98fbd0600000000000082b3a56da828618b1b7b103763e3c21c38c9536ce185ddd4aebdcd627645a878fb96e355ffff001d192907730101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff2803bf25081b4d696e656420627920416e74506f6f6c202bde53072055e396fb010300000099050000ffffffff01807c814a000000001976a9144c5220c58749e5474ec4e5bbb0c2cc0342c6f44488ac00000000',
|
||||
'00000000000006bd8fe9e53780323c0e85719eca771022e1eb6d10c62195c441': '030000004705096ec15ee742e9c14aee22f5f30cb568a0817b4a6c1ec4b9010000000000afb4442dbd55dcc8c86c94dc84ca0d130aeade144623fc0e47849343087067204792e35567f20c1a4b773d0f0101000000010000000000000000000000000000000000000000000000000000000000000000ffffffff2803be25081b4d696e656420627920416e74506f6f6c202bde53072055e392470100000000aba10000ffffffff01807c814a000000001976a9144c5220c58749e5474ec4e5bbb0c2cc0342c6f44488ac00000000'
|
||||
};
|
||||
var blocks = require('./data/blocks.json');
|
||||
|
||||
var blockIndexes = {
|
||||
'0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7': {
|
||||
'0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7': {
|
||||
hash: '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7',
|
||||
chainWork: '0000000000000000000000000000000000000000000000054626b1839ade284a',
|
||||
prevHash: '00000000000001a55f3214e9172eb34b20e0bc5bd6b8007f3f149fca2c8991a4',
|
||||
height: 533974
|
||||
height: 533974
|
||||
},
|
||||
'000000000008fbb2e358e382a6f6948b2da24563bba183af447e6e2542e8efc7': {
|
||||
'000000000008fbb2e358e382a6f6948b2da24563bba183af447e6e2542e8efc7': {
|
||||
hash: '000000000008fbb2e358e382a6f6948b2da24563bba183af447e6e2542e8efc7',
|
||||
chainWork: '00000000000000000000000000000000000000000000000544ea52e1575ca753',
|
||||
prevHash: '00000000000006bd8fe9e53780323c0e85719eca771022e1eb6d10c62195c441',
|
||||
height: 533951
|
||||
height: 533951
|
||||
},
|
||||
'00000000000006bd8fe9e53780323c0e85719eca771022e1eb6d10c62195c441': {
|
||||
hash: '00000000000006bd8fe9e53780323c0e85719eca771022e1eb6d10c62195c441',
|
||||
chainWork: '00000000000000000000000000000000000000000000000544ea52e0575ba752',
|
||||
prevHash: '000000000001b9c41e6c4a7b81a068b50cf3f522ee4ac1e942e75ec16e090547',
|
||||
height: 533950
|
||||
height: 533950
|
||||
},
|
||||
533974: {
|
||||
'000000000000000004a118407a4e3556ae2d5e882017e7ce526659d8073f13a4': {
|
||||
hash: '000000000000000004a118407a4e3556ae2d5e882017e7ce526659d8073f13a4',
|
||||
prevHash: '00000000000000000a9d74a7b527f7b995fc21ceae5aa21087b443469351a362',
|
||||
height: 375493
|
||||
},
|
||||
533974: {
|
||||
hash: '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7',
|
||||
chainWork: '0000000000000000000000000000000000000000000000054626b1839ade284a',
|
||||
prevHash: '00000000000001a55f3214e9172eb34b20e0bc5bd6b8007f3f149fca2c8991a4',
|
||||
height: 533974
|
||||
height: 533974
|
||||
}
|
||||
};
|
||||
|
||||
@ -61,7 +62,8 @@ describe('Blocks', function() {
|
||||
'previousblockhash': '00000000000001a55f3214e9172eb34b20e0bc5bd6b8007f3f149fca2c8991a4',
|
||||
'nextblockhash': '000000000001e866a8057cde0c650796cb8a59e0e6038dc31c69d7ca6649627d',
|
||||
'reward': 12.5,
|
||||
'isMainChain': true
|
||||
'isMainChain': true,
|
||||
'poolInfo': {}
|
||||
};
|
||||
|
||||
var bitcoreBlock = bitcore.Block.fromBuffer(new Buffer(blocks['0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7'], 'hex'));
|
||||
@ -81,9 +83,9 @@ describe('Blocks', function() {
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
it('block data should be correct', function(done) {
|
||||
var blocks = new BlockController(node);
|
||||
var controller = new BlockController(node);
|
||||
var req = {};
|
||||
var res = {};
|
||||
var next = function() {
|
||||
@ -95,8 +97,42 @@ describe('Blocks', function() {
|
||||
|
||||
var hash = '0000000000000afa0c3c0afd450c793a1e300ec84cbe9555166e06132f19a8f7';
|
||||
|
||||
blocks.block(req, res, next, hash);
|
||||
controller.block(req, res, next, hash);
|
||||
});
|
||||
|
||||
it('block pool info should be correct', function(done) {
|
||||
var block = bitcore.Block.fromString(blocks['000000000000000004a118407a4e3556ae2d5e882017e7ce526659d8073f13a4']);
|
||||
var node = {
|
||||
getBlock: sinon.stub().callsArgWith(1, null, block),
|
||||
services: {
|
||||
bitcoind: {
|
||||
getNextBlockHash: sinon.stub().returns('000000000001e866a8057cde0c650796cb8a59e0e6038dc31c69d7ca6649627d'),
|
||||
getBlockIndex: sinon.stub().returns(blockIndexes['000000000000000004a118407a4e3556ae2d5e882017e7ce526659d8073f13a4']),
|
||||
isMainChain: sinon.stub().returns(true)
|
||||
},
|
||||
db: {
|
||||
tip: {
|
||||
__height: 534092
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
var controller = new BlockController(node);
|
||||
var req = {};
|
||||
var res = {};
|
||||
var next = function() {
|
||||
should.exist(req.block);
|
||||
var block = req.block;
|
||||
req.block.poolInfo.poolName.should.equal('Discus Fish');
|
||||
req.block.poolInfo.url.should.equal('http://f2pool.com/');
|
||||
done();
|
||||
};
|
||||
|
||||
var hash = '000000000000000004a118407a4e3556ae2d5e882017e7ce526659d8073f13a4';
|
||||
|
||||
controller.block(req, res, next, hash);
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('/blocks route', function() {
|
||||
@ -109,7 +145,10 @@ describe('Blocks', function() {
|
||||
"hash": "000000000008fbb2e358e382a6f6948b2da24563bba183af447e6e2542e8efc7",
|
||||
"time": 1440978683,
|
||||
"txlength": 1,
|
||||
"poolInfo": {}
|
||||
"poolInfo": {
|
||||
"poolName": "AntMiner",
|
||||
"url": "https://bitmaintech.com/"
|
||||
}
|
||||
},
|
||||
{
|
||||
"height": 533950,
|
||||
@ -117,7 +156,10 @@ describe('Blocks', function() {
|
||||
"hash": "00000000000006bd8fe9e53780323c0e85719eca771022e1eb6d10c62195c441",
|
||||
"time": 1440977479,
|
||||
"txlength": 1,
|
||||
"poolInfo": {}
|
||||
"poolInfo": {
|
||||
"poolName": "AntMiner",
|
||||
"url": "https://bitmaintech.com/"
|
||||
}
|
||||
}
|
||||
],
|
||||
"length": 2,
|
||||
|
||||
6
test/data/blocks.json
Normal file
6
test/data/blocks.json
Normal file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user