From 33c32d32c1b7dad6b34a957d86bc8a2653492850 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Tue, 8 Aug 2017 14:31:58 -0700 Subject: [PATCH] bip152: minor. add assertion. --- lib/net/bip152.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib/net/bip152.js b/lib/net/bip152.js index 28e42f28..1a33af0d 100644 --- a/lib/net/bip152.js +++ b/lib/net/bip152.js @@ -132,8 +132,11 @@ CompactBlock.prototype.fromRaw = function fromRaw(data) { this.totalTX += idCount; - for (let i = 0; i < idCount; i++) - this.ids.push(br.readU32() + br.readU16() * 0x100000000); + for (let i = 0; i < idCount; i++) { + const lo = br.readU32(); + const hi = br.readU16(); + this.ids.push(hi * 0x100000000 + lo); + } const txCount = br.readVarint(); @@ -259,8 +262,8 @@ CompactBlock.prototype.writeRaw = function writeRaw(bw, witness) { for (const id of this.ids) { const lo = id % 0x100000000; - let hi = (id - lo) / 0x100000000; - hi &= 0xffff; + const hi = (id - lo) / 0x100000000; + assert(hi <= 0xffff); bw.writeU32(lo); bw.writeU16(hi); }