fix work bug
This commit is contained in:
parent
0bd69fa74f
commit
b3ad83b9ee
@ -40,7 +40,7 @@ BlockChain.prototype.addData = function(block) {
|
||||
|
||||
var prevHash = bitcore.util.buffer.reverse(block.header.prevHash).toString('hex');
|
||||
|
||||
this.work[block.hash] = this.work[prevHash].work + getWork(block.header.bits);
|
||||
this.work[block.hash] = this.work[prevHash] + getWork(block.header.bits);
|
||||
this.prev[block.hash] = prevHash;
|
||||
};
|
||||
|
||||
|
||||
28
lib/node.js
28
lib/node.js
@ -39,6 +39,7 @@ var BitcoreNode = function(bus, networkMonitor, blockService, transactionService
|
||||
|
||||
this.bus.register(bitcore.Block, function(block) {
|
||||
|
||||
console.log('Block', block.id);
|
||||
var prevHash = bitcore.util.buffer.reverse(block.header.prevHash).toString('hex');
|
||||
self.blockCache[block.hash] = block;
|
||||
|
||||
@ -48,15 +49,21 @@ var BitcoreNode = function(bus, networkMonitor, blockService, transactionService
|
||||
}
|
||||
|
||||
var blockchainChanges = self.blockchain.proposeNewBlock(block);
|
||||
console.log('changes', blockchainChanges);
|
||||
Promise.each(blockchainChanges.unconfirmed, function(hash) {
|
||||
return self.blockService.unconfirm(self.blockCache[hash]);
|
||||
})
|
||||
.then(Promise.each(blockchainChanges.confirmed, function(hash) {
|
||||
return self.blockService.confirm(self.blockCache[hash]);
|
||||
}))
|
||||
.then(function() {
|
||||
self.networkMonitor.requestBlocks(self.blockchain.getBlockLocator());
|
||||
});
|
||||
return self.blockService.unconfirm(self.blockCache[hash]);
|
||||
})
|
||||
.then(function() {
|
||||
return Promise.all(blockchainChanges.confirmed.map(function(hash) {
|
||||
return self.blockService.confirm(self.blockCache[hash]);
|
||||
}));
|
||||
})
|
||||
.then(function() {
|
||||
self.networkMonitor.requestBlocks(self.blockchain.getBlockLocator());
|
||||
})
|
||||
.catch(function(error) {
|
||||
self.stop(error);
|
||||
});
|
||||
});
|
||||
|
||||
this.bus.onAny(function(value) {
|
||||
@ -79,7 +86,6 @@ BitcoreNode.create = function(opts) {
|
||||
|
||||
var networkMonitor = NetworkMonitor.create(bus, opts.NetworkMonitor);
|
||||
|
||||
console.log(opts.LevelUp);
|
||||
var database = Promise.promisifyAll(
|
||||
new LevelUp(opts.LevelUp || config.get('LevelUp'))
|
||||
);
|
||||
@ -119,8 +125,8 @@ BitcoreNode.prototype.start = function() {
|
||||
});
|
||||
};
|
||||
|
||||
BitcoreNode.prototype.stop = function() {
|
||||
this.networkMonitor.stop();
|
||||
BitcoreNode.prototype.stop = function(reason) {
|
||||
this.networkMonitor.stop(reason);
|
||||
};
|
||||
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user