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) {
|
bitcoind.on('open', function(status) {
|
||||||
console.log('bitcoind: status="%s"', status);
|
console.log('bitcoind: status="%s"', status);
|
||||||
getBlocks(bitcoind);
|
// getBlocks(bitcoind);
|
||||||
// bitcoind.on('block', function(block) {
|
bitcoind.on('block', function(block) {
|
||||||
// console.log('Found block: %j', block);
|
console.log('Found block:');
|
||||||
// });
|
console.log(block);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -133,19 +133,24 @@ Bitcoin.prototype.start = function(callback) {
|
|||||||
this._emitted = {};
|
this._emitted = {};
|
||||||
|
|
||||||
(function next() {
|
(function next() {
|
||||||
bitcoindjs.pollBlocks(function(err, blocks) {
|
return bitcoindjs.pollBlocks(function(err, blocks) {
|
||||||
if (err) return setTimeout(next, self.pollInterval);
|
if (err) return setTimeout(next, self.pollInterval);
|
||||||
utils.forEach(blocks, function(block, nextBlock) {
|
return utils.forEach(blocks, function(block, nextBlock) {
|
||||||
var hash = block.hash || block;
|
|
||||||
// XXX Bad workaround
|
// XXX Bad workaround
|
||||||
if (self._emitted[hash]) return nextBlock();
|
if (self._emitted[block.hash]) {
|
||||||
self._emitted[hash] = true;
|
return setImmediate(function() {
|
||||||
|
return nextBlock();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
self._emitted[block.hash] = true;
|
||||||
|
|
||||||
self.emit('block', block);
|
self.emit('block', block);
|
||||||
setImmediate(function() {
|
|
||||||
|
return setImmediate(function() {
|
||||||
nextBlock();
|
nextBlock();
|
||||||
});
|
});
|
||||||
}, function() {
|
}, 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) {
|
if (pindex != NULL) {
|
||||||
CBlock block;
|
CBlock block;
|
||||||
if (ReadBlockFromDisk(block, pindex)) {
|
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++;
|
j++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user