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

View File

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

View File

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