minor: more style concerns.

This commit is contained in:
Christopher Jeffrey 2014-06-24 00:57:46 -05:00
parent 6072fe7afd
commit 5e3e72ba4c
2 changed files with 20 additions and 24 deletions

View File

@ -80,9 +80,8 @@ Block.prototype.hasTX = function hasTX(hash) {
Block.prototype._verifyMerkle = function verifyMerkle() { Block.prototype._verifyMerkle = function verifyMerkle() {
var height = 0; var height = 0;
if (this.subtype === 'block') { if (this.subtype === 'block')
return; return;
}
// Count leafs // Count leafs
for (var i = this.totalTX; i > 0; i >>= 1) for (var i = this.totalTX; i > 0; i >>= 1)
@ -180,32 +179,28 @@ Block.prototype._buildMerkle = function buildMerkle() {
// and CheckBlock() in bitcoin/src/main.cpp. // and CheckBlock() in bitcoin/src/main.cpp.
Block.prototype._checkBlock = function checkBlock() { Block.prototype._checkBlock = function checkBlock() {
// Check proof of work matches claimed amount // Check proof of work matches claimed amount
if (!utils.testTarget(this.bits, this.hash())) { if (!utils.testTarget(this.bits, this.hash()))
return false; return false;
}
// Check timestamp // Check timestamp
if (this.ts > (Date.now() / 1000) + 2 * 60 * 60) { if (this.ts > (Date.now() / 1000) + 2 * 60 * 60)
return false; return false;
}
// Size of all txs cant be bigger than MAX_BLOCK_SIZE // Size of all txs cant be bigger than MAX_BLOCK_SIZE
if (this.txs.length > bcoin.protocol.constants.block.maxSize) { if (this.txs.length > bcoin.protocol.constants.block.maxSize)
return false; return false;
}
// First TX must be a coinbase // First TX must be a coinbase
if (!this.txs.length || if (!this.txs.length ||
this.txs[0].inputs.length !== 1 || this.txs[0].inputs.length !== 1 ||
+this.txs[0].inputs[0].out.hash !== 0) { +this.txs[0].inputs[0].out.hash !== 0)
return false; return false;
}
// The rest of the txs must not be coinbases // The rest of the txs must not be coinbases
for (var i = 1; i < this.txs.length; i++) { for (var i = 1; i < this.txs.length; i++) {
if (this.txs[i].inputs.length === 1 && +this.txs[i].inputs[0].out.hash === 0) { if (this.txs[i].inputs.length === 1 &&
+this.txs[i].inputs[0].out.hash === 0)
return false; return false;
}
} }
// Build MerkleTree // Build MerkleTree
@ -215,10 +210,11 @@ Block.prototype._checkBlock = function checkBlock() {
var unique = {}; var unique = {};
for (var i = 0; i < this.txs.length; i++) { for (var i = 0; i < this.txs.length; i++) {
var hash = this.txs[i].hash('hex'); var hash = this.txs[i].hash('hex');
if (unique[hash]) return false; if (unique[hash])
return false;
unique[hash] = true; unique[hash] = true;
} }
// Check merkle root // Check merkle root
return this.merkleTree[this.merkleTree.length-1] === this.merkleRoot; return this.merkleTree[this.merkleTree.length - 1] === this.merkleRoot;
}; };

View File

@ -383,34 +383,34 @@ Parser.prototype.parseAddr = function parseAddr(p) {
return this._error('Invalid addr size'); return this._error('Invalid addr size');
var addrs = []; var addrs = [];
var len, off, count, ts, service, ipv4, ipv6, port, i;
// count // count
len = readIntv(p, 0); var len = readIntv(p, 0);
off = len.off; var off = len.off;
count = len.r; var count = len.r;
p = p.slice(off); p = p.slice(off);
for (i = 0; i < count; i++) { for (var i = 0; i < count; i++) {
// timestamp - LE // timestamp - LE
ts = utils.readU32(p, 0); var ts = utils.readU32(p, 0);
// NODE_NETWORK service - LE // NODE_NETWORK service - LE
service = utils.readU64(p, 4); var service = utils.readU64(p, 4);
// ipv6 - BE // ipv6 - BE
ipv6 = utils.toHex(p.slice(12, 24)); var ipv6 = utils.toHex(p.slice(12, 24));
ipv6 = '::' + ipv6.replace(/(.{4})/g, '$1:').slice(0, -1); ipv6 = '::' + ipv6.replace(/(.{4})/g, '$1:').slice(0, -1);
// ipv4 - BE // ipv4 - BE
ipv4 = utils.readU32BE(p, 24); var ipv4 = utils.readU32BE(p, 24);
ipv4 = ((ipv4 >> 24) & 0xff) + '.' + ipv4 = ((ipv4 >> 24) & 0xff) + '.' +
((ipv4 >> 16) & 0xff) + '.' + ((ipv4 >> 16) & 0xff) + '.' +
((ipv4 >> 8) & 0xff) + '.' + ((ipv4 >> 8) & 0xff) + '.' +
((ipv4 >> 0) & 0xff); ((ipv4 >> 0) & 0xff);
// port - BE // port - BE
port = utils.readU16BE(p, 28); var port = utils.readU16BE(p, 28);
addrs.push({ addrs.push({
ts: ts, ts: ts,