emit full blocks.

This commit is contained in:
Christopher Jeffrey 2014-09-23 10:21:44 -07:00
parent adf1932c8e
commit 89246d85e6
3 changed files with 20 additions and 12 deletions

View File

@ -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);
});
});
});

View File

@ -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);
});
});
})();

View File

@ -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++;
}
}