fix validateAddress. cleanup.
This commit is contained in:
parent
46a5ca7500
commit
c96a12bf2e
@ -461,42 +461,6 @@ Chain.prototype.locatorHashes = function(index) {
|
||||
return hashes;
|
||||
};
|
||||
|
||||
Chain.prototype.locatorHashes = function(index) {
|
||||
var chain = this.index.hashes;
|
||||
var hashes = [];
|
||||
var top = chain.length - 1;
|
||||
var step = 1, start = 0;
|
||||
|
||||
if (typeof index === 'string') {
|
||||
for (i = top; i >= 0; i--) {
|
||||
if (chain[i] === index) {
|
||||
top = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else if (typeof index === 'number') {
|
||||
top = index;
|
||||
}
|
||||
|
||||
for (var i = top; i > 0; i -= step, ++start) {
|
||||
if (start >= 10) step *= 2;
|
||||
hashes.push(chain[i]);
|
||||
}
|
||||
|
||||
hashes.push(chain[0]);
|
||||
|
||||
return hashes;
|
||||
};
|
||||
|
||||
Chain.prototype.__defineGetter__('orphan_bmap', function() {
|
||||
var self = this;
|
||||
return Object.keys(this.orphan.map).reduce(function(out, prev) {
|
||||
var orphan = self.orphan.map[prev];
|
||||
out[orphan.hash('hex')] = orphan;
|
||||
return out;
|
||||
}, {});
|
||||
});
|
||||
|
||||
Chain.prototype.getOrphanRoot = function getOrphanRoot(hash) {
|
||||
var self = this;
|
||||
|
||||
@ -504,31 +468,13 @@ Chain.prototype.getOrphanRoot = function getOrphanRoot(hash) {
|
||||
hash = hash.hash('hex');
|
||||
}
|
||||
|
||||
var orphans = this.orphan_bmap;
|
||||
var orphans = this.orphan.bmap;
|
||||
|
||||
/*
|
||||
var orphanRoot = hash;
|
||||
var last = orphanRoot;
|
||||
while (orphans[last]) {
|
||||
orphanRoot = last;
|
||||
last = orphans[last].prevBlock;
|
||||
}
|
||||
*/
|
||||
|
||||
// accurate:
|
||||
var orphanRoot = hash;
|
||||
while (orphans[orphanRoot.prevBlock]) {
|
||||
orphanRoot = orphans[orphanRoot.prevBlock];
|
||||
}
|
||||
|
||||
/*
|
||||
if hash stop gets last desired block, it should be:
|
||||
var orphanRoot = hash;
|
||||
while (orphans[orphanRoot]) {
|
||||
orphanRoot = orphans[orphanRoot].prevBlock;
|
||||
}
|
||||
*/
|
||||
|
||||
return orphanRoot;
|
||||
};
|
||||
|
||||
|
||||
@ -92,7 +92,10 @@ Peer.prototype._init = function init() {
|
||||
if (this.pool.options.fullNode) {
|
||||
this.once('version', function() {
|
||||
var ip = self.socket && self.socket.remoteAddress || '0.0.0.0';
|
||||
self.pool.emit('debug', 'version (%s): loading locator hashes for getblocks', ip);
|
||||
self.pool.emit('debug',
|
||||
'Sent version (%s): height=%s',
|
||||
ip, this.pool.chain.getStartHeight());
|
||||
self.pool.emit('debug', 'version (%s): sending locator hashes', ip);
|
||||
self.chain.on('load', function() {
|
||||
self.loadHeaders(self.chain.locatorHashes(), 0);
|
||||
});
|
||||
@ -460,7 +463,7 @@ Peer.prototype._handleHeaders = function handleHeaders(headers) {
|
||||
for (var i = 0; i < headers.length; i++) {
|
||||
var header = headers[i];
|
||||
var hash = header.hash;
|
||||
// if (this.chain.orphan_bmap[hash]) {
|
||||
// if (this.chain.orphan.bmap[hash]) {
|
||||
if (this.chain.orphan.map[header.prevBlock]) {
|
||||
this.loadHeaders(this.chain.locatorHashes(), this.chain.getOrphanRoot(hash));
|
||||
continue;
|
||||
|
||||
@ -200,6 +200,8 @@ Wallet.addr2hash = function addr2hash(addr, version) {
|
||||
};
|
||||
|
||||
Wallet.prototype.validateAddress = function validateAddress(addr, version) {
|
||||
if (!addr)
|
||||
return false;
|
||||
var p = Wallet.addr2hash(addr, version);
|
||||
return p.length !== 0;
|
||||
};
|
||||
|
||||
Loading…
Reference in New Issue
Block a user