emit full blocks.
This commit is contained in:
parent
adf1932c8e
commit
89246d85e6
|
@ -14,10 +14,11 @@ bitcoind.start(function(err) {
|
|||
});
|
||||
bitcoind.on('open', function(status) {
|
||||
console.log('bitcoind: status="%s"', status);
|
||||
getBlocks(bitcoind);
|
||||
// bitcoind.on('block', function(block) {
|
||||
// console.log('Found block: %j', block);
|
||||
// });
|
||||
// getBlocks(bitcoind);
|
||||
bitcoind.on('block', function(block) {
|
||||
console.log('Found block:');
|
||||
console.log(block);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
|
|
@ -133,19 +133,24 @@ Bitcoin.prototype.start = function(callback) {
|
|||
this._emitted = {};
|
||||
|
||||
(function next() {
|
||||
bitcoindjs.pollBlocks(function(err, blocks) {
|
||||
return bitcoindjs.pollBlocks(function(err, blocks) {
|
||||
if (err) return setTimeout(next, self.pollInterval);
|
||||
utils.forEach(blocks, function(block, nextBlock) {
|
||||
var hash = block.hash || block;
|
||||
return utils.forEach(blocks, function(block, nextBlock) {
|
||||
// XXX Bad workaround
|
||||
if (self._emitted[hash]) return nextBlock();
|
||||
self._emitted[hash] = true;
|
||||
if (self._emitted[block.hash]) {
|
||||
return setImmediate(function() {
|
||||
return nextBlock();
|
||||
});
|
||||
}
|
||||
self._emitted[block.hash] = true;
|
||||
|
||||
self.emit('block', block);
|
||||
setImmediate(function() {
|
||||
|
||||
return setImmediate(function() {
|
||||
nextBlock();
|
||||
});
|
||||
}, function() {
|
||||
setTimeout(next, self.pollInterval);
|
||||
return setTimeout(next, self.pollInterval);
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
|
|
@ -983,7 +983,9 @@ async_poll_blocks_after(uv_work_t *req) {
|
|||
if (pindex != NULL) {
|
||||
CBlock block;
|
||||
if (ReadBlockFromDisk(block, pindex)) {
|
||||
blocks->Set(j, NanNew<String>(block.GetHash().GetHex().c_str()));
|
||||
Local<Object> obj = NanNew<Object>();
|
||||
cblock_to_js(block, pindex, obj);
|
||||
blocks->Set(j, obj);
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue