1
2
@@ -204,105 +204,105 @@
-18x
+19x
-18x
-18x
-18x
-18x
-18x
-18x
-18x
+19x
+19x
+19x
+19x
+19x
+19x
+19x
-18x
+19x
-20x
-20x
+22x
+22x
-36x
-36x
+46x
+46x
-36x
-
-
+46x
+1x
+1x
-
+1x
-
+1x
-36x
-36x
-36x
+46x
+46x
+45x
-
+1x
-36x
+46x
-36x
+46x
-30x
-30x
+46x
+46x
-36x
+46x
-36x
+46x
-36x
-36x
+46x
+46x
-30x
-30x
-30x
+46x
+46x
+46x
-10x
-10x
+2x
+2x
-36x
+46x
-36x
-36x
+46x
+46x
-36x
+45x
-36x
+46x
-30x
-30x
+46x
+46x
@@ -314,12 +314,12 @@
-36x
-36x
+45x
+45x
-10x
+3x
@@ -367,27 +367,27 @@
for (let i = 0; i < this.attempts; i++) {
const stat = await this.stat();
- Iif (stat) {
- const now = Date.now();
- const mtime = Math.round(stat.mtimeMs);
+ if (stat) {
+ const now = Date.now();
+ const mtime = Math.round(stat.mtimeMs);
// Somebody changed their system clock.
- if (mtime >= now + 10 * 1000) {
+ Iif (mtime >= now + 10 * 1000) {
await this.unlink();
continue;
}
- if (now < mtime + this.stale) {
+ Iif (now < mtime + this.stale) {
await this.wait();
continue;
}
}
try {
- Eif (!stat)
+ if (!stat)
await this.touch();
else
- await this.update();
+ await this.update();
} catch (e) {
continue;
}
@@ -475,7 +475,7 @@
diff --git a/coverage/urkel/lib/mfs.js.html b/coverage/urkel/lib/mfs.js.html
index 78cb095..81db911 100644
--- a/coverage/urkel/lib/mfs.js.html
+++ b/coverage/urkel/lib/mfs.js.html
@@ -20,24 +20,24 @@
- 68.48%
+ 66.76%
Statements
- 239/349
+ 233/349
- 52.45%
+ 51.75%
Branches
- 75/143
+ 74/143
- 68.12%
+ 65.22%
Functions
- 47/69
+ 45/69
- 68.48%
+ 66.76%
Lines
- 239/349
+ 233/349
@@ -962,13 +962,13 @@
-18x
-18x
-18x
-18x
-18x
-18x
-18x
+19x
+19x
+19x
+19x
+19x
+19x
+19x
@@ -977,121 +977,121 @@
-273x
+360x
-273x
+360x
-273x
+360x
-273x
+360x
-273x
-226x
+360x
+297x
-226x
+297x
-226x
+297x
-273x
+360x
-273x
+360x
-123x
+162x
-123x
-123x
+162x
+162x
-123x
+162x
-123x
+162x
-35x
+45x
-35x
+45x
-18x
+27x
-18x
+27x
-123x
-69x
+162x
+81x
-69x
-69x
+81x
+81x
-69x
+81x
-123x
+162x
-123x
+162x
-35x
-35x
-35x
-35x
+45x
+45x
+45x
+45x
-123x
+162x
-123x
-123x
+162x
+162x
-123x
+162x
-123x
+162x
-118x
+162x
-118x
+162x
-118x
+162x
-118x
+162x
-41x
+54x
-41x
+54x
-41x
+54x
-41x
+54x
-41x
+54x
@@ -1117,20 +1117,20 @@
-35x
-35x
+45x
+45x
-35x
+45x
-35x
+45x
-35x
+45x
-35x
-35x
+45x
+45x
-35x
+45x
@@ -1144,89 +1144,89 @@
-35x
+45x
-35x
-18x
+45x
+27x
-18x
+27x
-17x
-17x
+18x
+18x
-17x
+18x
-35x
+45x
-2x
+3x
-2x
+3x
-2x
+3x
-2x
+3x
-2x
+3x
-2x
+3x
-2x
+3x
-2x
+3x
-2x
+3x
-2x
+3x
-2x
+3x
-2x
+3x
-2x
+3x
-2x
-2x
+3x
+3x
-2x
+3x
-59x
+81x
-59x
-35x
+81x
+45x
-24x
+36x
-35x
+45x
@@ -1234,7 +1234,7 @@
-24x
+36x
@@ -1271,19 +1271,19 @@
-36x
+54x
-36x
-2x
+54x
+3x
-34x
+51x
-34x
+51x
-36x
+54x
@@ -1305,19 +1305,19 @@
-8x
+
-8x
+
-8x
-8x
+
+
-8x
+
-8x
+
@@ -1342,20 +1342,20 @@
-88x
+117x
-88x
+117x
-88x
+117x
-88x
+117x
-88x
+117x
-88x
+117x
@@ -1382,19 +1382,19 @@
-57x
+78x
-57x
+78x
-57x
+78x
-57x
+78x
-57x
+78x
@@ -1406,49 +1406,49 @@
-1738515x
+2625477x
-1738515x
+2625477x
-1738515x
+2625477x
-1738515x
+2625477x
-1738515x
+2625477x
-1738515x
-1738515x
+2625477x
+2625477x
-1738515x
+2625477x
-1738515x
+2625477x
-57x
+78x
-57x
+78x
-57x
+78x
-57x
+78x
-57x
+78x
-57x
-57x
+78x
+78x
-57x
+78x
-57x
+78x
@@ -1458,27 +1458,27 @@
-104x
-104x
+118x
+118x
-104x
+118x
-104x
+118x
-104x
-104x
-104x
+118x
+118x
+118x
-104x
-104x
-104x
-104x
+118x
+118x
+118x
+118x
-104x
+118x
-112x
+153x
@@ -1486,7 +1486,7 @@
-157x
+213x
@@ -1496,48 +1496,48 @@
-69x
-69x
+81x
+81x
-112x
+153x
-43x
-43x
+45x
+45x
-57x
-29x
+78x
+36x
-57x
-68x
-68x
-68x
+78x
+102x
+102x
+102x
-1738515x
-1738515x
-1738515x
+2625477x
+2625477x
+2625477x
-57x
+78x
-57x
+78x
-57x
+78x
-57x
+78x
-57x
+78x
@@ -1547,20 +1547,20 @@
-35x
-35x
-35x
+37x
+37x
+37x
-287x
+381x
-41x
-41x
-67x
-41x
+54x
+54x
+93x
+54x
@@ -1570,30 +1570,30 @@
-112x
+153x
-112x
+153x
-112x
-112x
-112x
-112x
-112x
-112x
-112x
-112x
-112x
-112x
-112x
-112x
-112x
-112x
-112x
-112x
-112x
-112x
+153x
+153x
+153x
+153x
+153x
+153x
+153x
+153x
+153x
+153x
+153x
+153x
+153x
+153x
+153x
+153x
+153x
+153x
-112x
+153x
@@ -1613,7 +1613,7 @@
-24x
+36x
@@ -1631,40 +1631,40 @@
-123x
-123x
-123x
+162x
+162x
+162x
-123x
-123x
-123x
-123x
-123x
+162x
+162x
+162x
+162x
+162x
-123x
+162x
-35x
-35x
+45x
+45x
-70x
-70x
-70x
+90x
+90x
+90x
-18x
-18x
-18x
+27x
+27x
+27x
@@ -1676,43 +1676,43 @@
-308x
+405x
-308x
-308x
-308x
+405x
+405x
+405x
-308x
+405x
-308x
+405x
-308x
+405x
-308x
+405x
-308x
+405x
-308x
+405x
-37x
+48x
-37x
-37x
-37x
-37x
+48x
+48x
+48x
+48x
-37x
-37x
+48x
+48x
-37x
-37x
+48x
+48x
-37x
+48x
@@ -2141,20 +2141,20 @@
return this.utimesSync(path, atime, mtime);
}
- truncateSync(path, size) {
- const [file] = this._find(path);
+ truncateSync(path, size) {
+ const [file] = this._find(path);
- Iif (!file)
+ if (!file)
throw makeError('truncate', 'ENOENT', path);
- file.mtime = Date.now();
- file.ctime = file.mtime;
+ file.mtime = Date.now();
+ file.ctime = file.mtime;
- file.truncate(size);
+ file.truncate(size);
}
- async truncate(path, size) {
- return this.truncateSync(path, size);
+ async truncate(path, size) {
+ return this.truncateSync(path, size);
}
futimesSync(fd, atime, mtime) {
@@ -2563,7 +2563,7 @@
diff --git a/coverage/urkel/lib/optimized/index.html b/coverage/urkel/lib/optimized/index.html
index eec9b62..3c27c57 100644
--- a/coverage/urkel/lib/optimized/index.html
+++ b/coverage/urkel/lib/optimized/index.html
@@ -20,31 +20,31 @@
- 11.56%
+ 77.84%
Statements
- 92/796
+ 871/1119
- 4.76%
+ 59.44%
Branches
- 14/294
+ 211/355
- 7.19%
+ 73.3%
Functions
- 10/139
+ 140/191
- 11.6%
+ 78.01%
Lines
- 92/793
+ 869/1114
Press n or j to go to the next uncovered block, b, p or k for the previous block.
-
+
@@ -62,42 +62,42 @@
- nodes.js |
- |
- 15.38% |
- 22/143 |
- 0% |
- 0/18 |
- 4% |
- 2/50 |
- 15.38% |
- 22/143 |
+ nodes.js |
+ |
+ 84.62% |
+ 121/143 |
+ 88.89% |
+ 16/18 |
+ 68% |
+ 34/50 |
+ 84.62% |
+ 121/143 |
- proof.js |
- |
- 9.96% |
- 26/261 |
- 0% |
- 0/132 |
- 0% |
- 0/25 |
- 10.08% |
- 26/258 |
+ store.js |
+ |
+ 69.52% |
+ 406/584 |
+ 45.6% |
+ 88/193 |
+ 71.43% |
+ 55/77 |
+ 69.78% |
+ 404/579 |
- tree.js |
- |
- 9.84% |
- 38/386 |
- 9.72% |
- 14/144 |
- 12.5% |
- 8/64 |
- 9.84% |
- 38/386 |
+ tree.js |
+ |
+ 87.56% |
+ 338/386 |
+ 74.31% |
+ 107/144 |
+ 79.69% |
+ 51/64 |
+ 87.56% |
+ 338/386 |
@@ -119,7 +119,7 @@
diff --git a/coverage/urkel/lib/optimized/nodes.js.html b/coverage/urkel/lib/optimized/nodes.js.html
index d75bc1b..bde44ea 100644
--- a/coverage/urkel/lib/optimized/nodes.js.html
+++ b/coverage/urkel/lib/optimized/nodes.js.html
@@ -20,31 +20,31 @@
- 15.38%
+ 84.62%
Statements
- 22/143
+ 121/143
- 0%
+ 88.89%
Branches
- 0/18
+ 16/18
- 4%
+ 68%
Functions
- 2/50
+ 34/50
- 15.38%
+ 84.62%
Lines
- 22/143
+ 121/143
Press n or j to go to the next uncovered block, b, p or k for the previous block.
-
+
1
2
@@ -495,21 +495,21 @@
-1x
-1x
-1x
+36658024x
+36658024x
+36658024x
-
+986947x
-
+999100x
-
+1736063x
@@ -522,15 +522,15 @@
-
+7298x
-
+45089x
-
+110700x
@@ -538,12 +538,12 @@
-
+50597x
-
-
+140456x
+140456x
@@ -584,11 +584,11 @@
-
+140409x
-
+7052x
@@ -606,28 +606,28 @@
-
-
-
+34709184x
+34709184x
+34709184x
-
+34212225x
-
+89184x
-
-
-
+108340x
+86924x
+86924x
-
+86924x
-
+108340x
@@ -635,61 +635,61 @@
-
+89184x
-
-
-
+89184x
+89184x
+89184x
-
-
-
+89184x
+89184x
+89184x
-
+89184x
-
+776958x
-
-
+776958x
+776958x
-
+776958x
-
+776958x
-
-
-
+776958x
+746373x
+746373x
-
-
+746373x
+746373x
-
+746373x
-
+30585x
-
-
+776958x
+776958x
-
-
-
+776958x
+746216x
+746216x
-
-
+746216x
+746216x
-
+746216x
-
+30742x
-
+776958x
@@ -700,16 +700,16 @@
-
-
-
-
+7x
+7x
+7x
+7x
-
-
-
+776958x
+776958x
+776958x
@@ -719,29 +719,29 @@
-
-
-
-
-
-
+315794x
+315794x
+315794x
+315794x
+315794x
+315794x
-
+125794x
-
+244651x
-
+176095x
-
-
+63307x
+63307x
@@ -749,36 +749,36 @@
-
-
-
-
-
+45089x
+45089x
+45089x
+45089x
+45089x
-
+75705x
-
-
+75705x
+75705x
-
+75705x
-
+75705x
-
-
+75705x
+75705x
-
-
+75705x
+75705x
-
-
+75705x
+75705x
-
+75705x
@@ -786,15 +786,15 @@
-
-
-
-
+7x
+7x
+7x
+7x
-
-
+75705x
+75705x
@@ -804,25 +804,25 @@
-
+1633045x
-
+877251x
-
+852654x
-
-
+283131x
+283131x
-
-
+20x
+20x
@@ -898,16 +898,16 @@
this.data = data;
}
- get pos() {
- return this.flags >>> 1;
+ get pos() {
+ return this.flags >>> 1;
}
- set pos(pos) {
- this.flags = pos * 2 + this.leaf;
+ set pos(pos) {
+ this.flags = pos * 2 + this.leaf;
}
- get leaf() {
- return this.flags & 1;
+ get leaf() {
+ return this.flags & 1;
}
set leaf(bit) {
@@ -919,29 +919,29 @@
throw new AssertionError('Unimplemented.');
}
- isNull() {
- return false;
+ isNull() {
+ return false;
}
- isInternal() {
- return false;
+ isInternal() {
+ return false;
}
- isLeaf() {
- return false;
+ isLeaf() {
+ return false;
}
isHash() {
return false;
}
- hash(hash) {
- return hash.zero;
+ hash(hash) {
+ return hash.zero;
}
- toHash(hash) {
- assert(this.index !== 0);
- return new Hash(this.hash(hash), this.index, this.flags);
+ toHash(hash) {
+ assert(this.index !== 0);
+ return new Hash(this.hash(hash), this.index, this.flags);
}
getSize(hash, bits) {
@@ -981,12 +981,12 @@
super(0, 0, null);
}
- type() {
- return NULL;
+ type() {
+ return NULL;
}
- isNull() {
- return true;
+ isNull() {
+ return true;
}
toHash(hash) {
@@ -1003,91 +1003,91 @@
*/
class Internal extends Node {
- constructor(left, right) {
- super(0, 0, null);
- this.left = left;
- this.right = right;
+ constructor(left, right) {
+ super(0, 0, null);
+ this.left = left;
+ this.right = right;
}
- type() {
- return INTERNAL;
+ type() {
+ return INTERNAL;
}
- isInternal() {
- return true;
+ isInternal() {
+ return true;
}
- hash(hash) {
- if (!this.data) {
- const left = this.left.hash(hash);
- const right = this.right.hash(hash);
+ hash(hash) {
+ if (!this.data) {
+ const left = this.left.hash(hash);
+ const right = this.right.hash(hash);
- this.data = hashInternal(hash, left, right);
+ this.data = hashInternal(hash, left, right);
}
- return this.data;
+ return this.data;
}
getSize(hash, bits) {
return Internal.getSize(hash, bits);
}
- write(data, off, hash, bits) {
- const {left, right} = this;
+ write(data, off, hash, bits) {
+ const {left, right} = this;
- off = writeU16(data, left.index * 2, off);
- off = writeU32(data, left.flags, off);
- off += left.hash(hash).copy(data, off);
+ off = writeU16(data, left.index * 2, off);
+ off = writeU32(data, left.flags, off);
+ off += left.hash(hash).copy(data, off);
- off = writeU16(data, right.index, off);
- off = writeU32(data, right.flags, off);
- off += right.hash(hash).copy(data, off);
+ off = writeU16(data, right.index, off);
+ off = writeU32(data, right.flags, off);
+ off += right.hash(hash).copy(data, off);
- return off;
+ return off;
}
- decode(data, hash, bits) {
- let off = 0;
+ decode(data, hash, bits) {
+ let off = 0;
let index;
- index = readU16(data, off);
- off += 2;
+ index = readU16(data, off);
+ off += 2;
// Sanity check.
- if ((index & 1) !== 0)
+ Iif ((index & 1) !== 0)
throw new AssertionError('Database corruption.');
- index >>>= 1;
+ index >>>= 1;
- if (index !== 0) {
- const flags = readU32(data, off);
- off += 4;
+ if (index !== 0) {
+ const flags = readU32(data, off);
+ off += 4;
- const lhash = data.slice(off, off + hash.size);
- off += hash.size;
+ const lhash = data.slice(off, off + hash.size);
+ off += hash.size;
- this.left = new Hash(lhash, index, flags);
+ this.left = new Hash(lhash, index, flags);
} else {
- off += 4 + hash.size;
+ off += 4 + hash.size;
}
// Unused bit here.
- index = readU16(data, off);
- off += 2;
+ index = readU16(data, off);
+ off += 2;
- if (index !== 0) {
- const flags = readU32(data, off);
- off += 4;
+ if (index !== 0) {
+ const flags = readU32(data, off);
+ off += 4;
- const rhash = data.slice(off, off + hash.size);
- off += hash.size;
+ const rhash = data.slice(off, off + hash.size);
+ off += hash.size;
- this.right = new Hash(rhash, index, flags);
+ this.right = new Hash(rhash, index, flags);
} else {
- off += 4 + hash.size;
+ off += 4 + hash.size;
}
- return this;
+ return this;
}
inspect() {
@@ -1097,17 +1097,17 @@
};
}
- static getSize(hash, bits) {
- assert(hash && typeof hash.digest === 'function');
- assert((bits >>> 0) === bits);
- assert(bits > 0 && (bits & 7) === 0);
- return (2 + 4 + hash.size) * 2;
+ static getSize(hash, bits) {
+ assert(hash && typeof hash.digest === 'function');
+ assert((bits >>> 0) === bits);
+ assert(bits > 0 && (bits & 7) === 0);
+ return (2 + 4 + hash.size) * 2;
}
- static decode(data, hash, bits) {
- const NIL = exports.NIL;
- const node = new this(NIL, NIL);
- return node.decode(data, hash, bits);
+ static decode(data, hash, bits) {
+ const NIL = exports.NIL;
+ const node = new this(NIL, NIL);
+ return node.decode(data, hash, bits);
}
}
@@ -1116,83 +1116,83 @@
*/
class Leaf extends Node {
- constructor(data, key, value) {
- super(0, 0, data);
- this.key = key;
- this.value = value;
- this.vindex = 0;
- this.vpos = 0;
- this.vsize = 0;
+ constructor(data, key, value) {
+ super(0, 0, data);
+ this.key = key;
+ this.value = value;
+ this.vindex = 0;
+ this.vpos = 0;
+ this.vsize = 0;
}
- get leaf() {
- return 1;
+ get leaf() {
+ return 1;
}
- type() {
- return LEAF;
+ type() {
+ return LEAF;
}
- isLeaf() {
- return true;
+ isLeaf() {
+ return true;
}
- hash(hash) {
- assert(this.data);
- return this.data;
+ hash(hash) {
+ assert(this.data);
+ return this.data;
}
getSize(hash, bits) {
return Leaf.getSize(hash, bits);
}
- write(data, off, hash, bits) {
- off = writeU16(data, this.vindex * 2 + 1, off);
- off = writeU32(data, this.vpos, off);
- off = writeU16(data, this.vsize, off);
- off += this.key.copy(data, off);
- return off;
+ write(data, off, hash, bits) {
+ off = writeU16(data, this.vindex * 2 + 1, off);
+ off = writeU32(data, this.vpos, off);
+ off = writeU16(data, this.vsize, off);
+ off += this.key.copy(data, off);
+ return off;
}
- decode(data, hash, bits) {
- let off = 0;
+ decode(data, hash, bits) {
+ let off = 0;
- this.vindex = readU16(data, off);
- off += 2;
+ this.vindex = readU16(data, off);
+ off += 2;
// Sanity check.
- if ((this.vindex & 1) !== 1)
+ Iif ((this.vindex & 1) !== 1)
throw new AssertionError('Database corruption.');
- this.vindex >>>= 1;
+ this.vindex >>>= 1;
// Unused bit here.
- this.vpos = readU32(data, off);
- off += 4;
+ this.vpos = readU32(data, off);
+ off += 4;
- this.vsize = readU16(data, off);
- off += 2;
+ this.vsize = readU16(data, off);
+ off += 2;
- this.key = data.slice(off, off + (bits >>> 3));
- off += bits >>> 3;
+ this.key = data.slice(off, off + (bits >>> 3));
+ off += bits >>> 3;
- return this;
+ return this;
}
inspect() {
return `<Leaf: ${this.key.toString('hex')}>`;
}
- static getSize(hash, bits) {
- assert(hash && typeof hash.digest === 'function');
- assert((bits >>> 0) === bits);
- assert(bits > 0 && (bits & 7) === 0);
- return 2 + 4 + 2 + (bits >>> 3);
+ static getSize(hash, bits) {
+ assert(hash && typeof hash.digest === 'function');
+ assert((bits >>> 0) === bits);
+ assert(bits > 0 && (bits & 7) === 0);
+ return 2 + 4 + 2 + (bits >>> 3);
}
- static decode(data, hash, bits) {
- const node = new this(null, null, null);
- return node.decode(data, hash, bits);
+ static decode(data, hash, bits) {
+ const node = new this(null, null, null);
+ return node.decode(data, hash, bits);
}
}
@@ -1201,26 +1201,26 @@
*/
class Hash extends Node {
- constructor(data, index, flags) {
- super(index, flags, data);
+ constructor(data, index, flags) {
+ super(index, flags, data);
}
- type() {
- return HASH;
+ type() {
+ return HASH;
}
- isHash() {
- return true;
+ isHash() {
+ return true;
}
- hash(hash) {
- assert(this.data);
- return this.data;
+ hash(hash) {
+ assert(this.data);
+ return this.data;
}
- toHash(hash) {
- assert(this.data);
- return this;
+ toHash(hash) {
+ assert(this.data);
+ return this;
}
inspect() {
@@ -1246,7 +1246,7 @@
diff --git a/coverage/urkel/lib/optimized/store.js.html b/coverage/urkel/lib/optimized/store.js.html
index d01b42a..305c468 100644
--- a/coverage/urkel/lib/optimized/store.js.html
+++ b/coverage/urkel/lib/optimized/store.js.html
@@ -1325,10 +1325,10 @@
19x
19x
-33x
+34x
-33x
-20x
+34x
+21x
13x
@@ -1504,19 +1504,19 @@
-890695x
-890695x
+888501x
+888501x
-890695x
+888501x
-890695x
+888501x
-890695x
+888501x
-890695x
-890679x
+888501x
+888485x
16x
@@ -1677,12 +1677,12 @@
-890679x
+888485x
-890679x
+888485x
-890679x
+888485x
@@ -1716,19 +1716,19 @@
-854891x
-854891x
+852663x
+852663x
-854891x
-854891x
+852663x
+852663x
-854891x
+852663x
-854891x
-854891x
-854891x
+852663x
+852663x
+852663x
@@ -1746,46 +1746,46 @@
-134924x
-134924x
+134273x
+134273x
-134924x
+134273x
-134924x
+134273x
-134924x
+134273x
-134924x
+134273x
-134924x
+134273x
-134924x
+134273x
-134924x
-134924x
+134273x
+134273x
-134924x
+134273x
-44994x
-44994x
-44994x
-44994x
-44994x
-44994x
-44994x
+45089x
+45089x
+45089x
+45089x
+45089x
+45089x
+45089x
-12185x
+12164x
@@ -2040,21 +2040,21 @@
-854882x
+852654x
-854882x
-854882x
-854882x
+852654x
+852654x
+852654x
-35788x
+35822x
-35788x
+35822x
-35788x
+35822x
@@ -2208,20 +2208,20 @@
-359896x
+358784x
-179938x
+179382x
11x
-179938x
+179382x
45x
45x
45x
-179938x
+179382x
@@ -2230,12 +2230,12 @@
-44994x
+45089x
-44994x
-44994x
+45089x
+45089x
-44994x
+45089x
@@ -2275,17 +2275,17 @@
-890727x
+888533x
-890727x
+888533x
48x
-890679x
+888485x
-890679x
+888485x
-890679x
+888485x
@@ -3553,7 +3553,7 @@
diff --git a/coverage/urkel/lib/optimized/tree.js.html b/coverage/urkel/lib/optimized/tree.js.html
index 2166297..7208e47 100644
--- a/coverage/urkel/lib/optimized/tree.js.html
+++ b/coverage/urkel/lib/optimized/tree.js.html
@@ -20,31 +20,31 @@
- 9.84%
+ 87.56%
Statements
- 38/386
+ 338/386
- 9.72%
+ 74.31%
Branches
- 14/144
+ 107/144
- 12.5%
+ 79.69%
Functions
- 8/64
+ 51/64
- 9.84%
+ 87.56%
Lines
- 38/386
+ 338/386
Press n or j to go to the next uncovered block, b, p or k for the previous block.
-
+
1
2
@@ -1092,29 +1092,29 @@
+301100x
-
-
+301100x
+240089x
-
-
+240089x
-5x
+38x
-5x
+38x
-
+240089x
-5x
+942x
@@ -1122,15 +1122,15 @@
-6x
+14x
-6x
+14x
-
-
+14x
+14x
@@ -1138,31 +1138,31 @@
-
-
+10x
+10x
-
+852654x
-
+35822x
-
-
+50014x
+50014x
-
-
+50014x
+1522504x
-
+1378x
-
+711927x
@@ -1171,27 +1171,27 @@
-
-
+711927x
+356090x
-
+355837x
-
+711927x
-
+711927x
-
-
+48636x
+23626x
-
+25010x
-
-
+760563x
+760563x
@@ -1202,29 +1202,29 @@
-
-
+50010x
+50010x
-
-
+240089x
+240089x
-
-
+240089x
+240089x
-
-
-
+240089x
+240089x
+33496425x
-
+111232x
-
+33235375x
@@ -1233,22 +1233,22 @@
-
-
-
+33235375x
+4851146x
+4851146x
-
-
+28384229x
+28384229x
-
+33235375x
-
+33235375x
-
+128857x
@@ -1258,26 +1258,26 @@
-
+128857x
-
+128857x
-
-
+439819x
+439819x
-
-
+128857x
+128857x
-
+128857x
-
-
+20961x
+20961x
@@ -1287,40 +1287,40 @@
-
+240089x
-
-
+240089x
+33804051x
-
+33804051x
-
-
+33804051x
+5024317x
-
+28779734x
-
+240089x
-
+10083x
-
-
+10083x
+10083x
-
-
-
+10083x
+10083x
+186844x
-
+142505x
@@ -1329,57 +1329,57 @@
-
-
-
+142505x
+71253x
+71253x
-
-
+71252x
+71252x
-
+142505x
-
+142505x
-
+10083x
-
+10083x
-
+10083x
-
-
-
+10083x
+7278x
+7278x
-
-
+7278x
+14330x
-
-
+14330x
+7278x
-
-
+7052x
+7052x
-
+2805x
-
+10083x
-
-
+34256x
+34256x
@@ -1389,72 +1389,72 @@
-
-
+10083x
+128175x
-
+128175x
-
-
+128175x
+64081x
-
+64094x
-
+10083x
-
+19x
-
+19x
-
+19x
-
+19x
-
+164059x
-
-
+23353x
+23353x
-
-
+82020x
+82020x
-
-
+82020x
+82020x
-
+82020x
-
+82020x
-
-
+46263x
+40089x
-
-
+40089x
+40089x
-
+46263x
-
+46263x
-
-
+12423x
+12423x
@@ -1462,27 +1462,27 @@
-
-
+914x
+914x
-
+922x
-
-
+922x
+922x
-
-
-
+922x
+922x
+25188x
-
+116x
-
+11730x
@@ -1491,39 +1491,39 @@
-
-
-
-
+11730x
+5885x
+5885x
+5885x
-
-
-
+5845x
+5845x
+5845x
-
+11730x
-
+11730x
-
+806x
-
-
-
+806x
+459x
+459x
-
-
-
+347x
+347x
+347x
-
+806x
-
-
+12536x
+12536x
@@ -1532,68 +1532,68 @@
-
+922x
-
-
+1x
+1x
-
+1x
-
+1x
-
-
+1x
+1x
-
-
+1x
+1x
-
-
+1x
+1x
-
-
+1x
+1x
-
+26493x
-
+2165x
-
-
+7164x
+7164x
-
-
+7164x
+7164x
-
+7164x
-
+7164x
-
+7164x
-
-
-
+5000x
+5000x
+5000x
-
-
+5000x
+5000x
-
+5000x
-
+5000x
-
-
+12164x
+12164x
@@ -1601,28 +1601,28 @@
-
+18x
-
-
-
+18x
+8x
+8x
-
+18x
-5x
+10x
-
-
-
+1x
+1x
+1x
-
+1x
@@ -1636,12 +1636,12 @@
-
-
+1x
+1x
-4x
+9x
@@ -1655,23 +1655,23 @@
-5x
-5x
-5x
+28x
+28x
+28x
-
-
-
+28x
+28x
+28x
-
+2x
-
-
-
+10x
+10x
+10x
@@ -1680,29 +1680,29 @@
-
+4x
-
-
+4x
+4x
-
+4x
-
-
+8x
+6x
-
+8x
-
-
-
+2x
+2x
+2x
-
+2x
@@ -1716,8 +1716,8 @@
-
-
+2x
+2x
@@ -1727,12 +1727,12 @@
-5x
-5x
+10x
+10x
-
+21x
@@ -1740,20 +1740,20 @@
-
-
-
+240089x
+240089x
+240089x
-
-
+10083x
+10083x
-
-
-
+19x
+19x
+19x
@@ -1768,22 +1768,22 @@
-
-
-
+3x
+3x
+3x
-
-
-
-
-
-
-
-
-
-
+3x
+3x
+3x
+3x
+3x
+3x
+3x
+3x
+3x
+3x
-
+3x
@@ -1801,88 +1801,88 @@
-
+3x
-
-
+26513x
+26513x
-
-
+26513x
+26513x
-
-
+53023x
+53023x
-
+53029x
-
+26516x
-
+26516x
-
+26516x
-
-
+26516x
+3x
-
+26513x
-
-
-
+26513x
+3x
+3x
-
-
-
-
+26513x
+26513x
+53023x
+53023x
-
+53023x
-
-
+2165x
+2165x
-
-
+21504x
+7168x
-
+14336x
-
-
+14336x
+7168x
-
+7168x
-
+14336x
-
-
+5006x
+5006x
-
-
+24348x
+12174x
-
+12174x
-
-
-
+12174x
+12174x
+12174x
@@ -1891,30 +1891,30 @@
-
+26513x
-
-
-
+5009x
+26516x
+3x
-
-
+26513x
+21507x
-
-
+5006x
+5006x
-
-
+5006x
+5006x
-
+5006x
-
-
+3x
+3x
-
+3x
@@ -1924,9 +1924,9 @@
-
-
-
+26513x
+26513x
+26513x
@@ -1936,25 +1936,25 @@
-
-
-
+3x
+3x
+3x
-
-
+3x
+3x
-
-
+5009x
+3x
-
+5006x
-
+5006x
@@ -1978,8 +1978,8 @@
const common = require('../common');
const errors = require('../errors');
const nodes = require('./nodes');
-const Proof = require('./proof');
-const store = require('../trie/store');
+const Proof = require('../proof');
+const store = require('./store');
const {
hasBit,
@@ -2051,16 +2051,16 @@
this.root = NIL;
}
- isKey(key) {
- if (!Buffer.isBuffer(key))
+ isKey(key) {
+ Iif (!Buffer.isBuffer(key))
return false;
- return key.length === (this.bits >>> 3);
+ return key.length === (this.bits >>> 3);
}
- isValue(value) {
- if (!Buffer.isBuffer(value))
+ isValue(value) {
+ Iif (!Buffer.isBuffer(value))
return false;
- return value.length <= 0xffff;
+ return value.length <= 0xffff;
}
isHash(hash) {
@@ -2069,8 +2069,8 @@
return hash.length === this.hash.size;
}
- hashValue(key, value) {
- return hashValue(this.hash, key, value);
+ hashValue(key, value) {
+ return hashValue(this.hash, key, value);
}
rootHash() {
@@ -2088,41 +2088,41 @@
await this.inject(root);
}
- async close() {
- this.root = NIL;
- return this.store.close();
+ async close() {
+ this.root = NIL;
+ return this.store.close();
}
async inject(root) {
this.root = await this.getHistory(root);
}
- async getHistory(root) {
- assert(this.isHash(root));
- return this.store.getHistory(root);
+ async getHistory(root) {
+ assert(this.isHash(root));
+ return this.store.getHistory(root);
}
- async resolve(node) {
- return this.store.resolve(node);
+ async resolve(node) {
+ return this.store.resolve(node);
}
- async retrieve(node) {
- return this.store.retrieve(node);
+ async retrieve(node) {
+ return this.store.retrieve(node);
}
- async _get(root, key) {
- let node = root;
- let depth = 0;
+ async _get(root, key) {
+ let node = root;
+ let depth = 0;
- for (;;) {
- switch (node.type()) {
+ for (;;) {
+ switch (node.type()) {
case NULL: {
// Empty (sub)tree.
- return null;
+ return null;
}
case INTERNAL: {
- if (depth === this.bits) {
+ Iif (depth === this.bits) {
throw new MissingNodeError({
rootHash: root.hash(this.hash),
key,
@@ -2131,60 +2131,60 @@
}
// Internal node.
- if (hasBit(key, depth))
- node = node.right;
+ if (hasBit(key, depth))
+ node = node.right;
else
- node = node.left;
+ node = node.left;
- depth += 1;
+ depth += 1;
- break;
+ break;
}
case LEAF: {
// Prefix collision.
- if (!key.equals(node.key))
- return null;
+ if (!key.equals(node.key))
+ return null;
- return this.retrieve(node);
+ return this.retrieve(node);
}
case HASH: {
- node = await this.resolve(node);
- break;
+ node = await this.resolve(node);
+ break;
}
- default: {
+ default: {
throw new AssertionError('Unknown node type.');
}
}
}
}
- async get(key) {
- assert(this.isKey(key));
- return this._get(this.root, key);
+ async get(key) {
+ assert(this.isKey(key));
+ return this._get(this.root, key);
}
- async _insert(root, key, value) {
- const leaf = this.hashValue(key, value);
- const nodes = [];
+ async _insert(root, key, value) {
+ const leaf = this.hashValue(key, value);
+ const nodes = [];
- let node = root;
- let depth = 0;
+ let node = root;
+ let depth = 0;
// Traverse bits left to right.
-outer:
- for (;;) {
- switch (node.type()) {
+outer:
+ for (;;) {
+ switch (node.type()) {
case NULL: {
// Empty (sub)tree.
// Replace the empty node.
- break outer;
+ break outer;
}
case INTERNAL: {
- if (depth === this.bits) {
+ Iif (depth === this.bits) {
throw new MissingNodeError({
rootHash: root.hash(this.hash),
key,
@@ -2193,22 +2193,22 @@
}
// Internal node.
- if (hasBit(key, depth)) {
- nodes.push(node.left);
- node = node.right;
+ if (hasBit(key, depth)) {
+ nodes.push(node.left);
+ node = node.right;
} else {
- nodes.push(node.right);
- node = node.left;
+ nodes.push(node.right);
+ node = node.left;
}
- depth += 1;
+ depth += 1;
- break;
+ break;
}
case LEAF: {
// Current key.
- if (key.equals(node.key)) {
+ Iif (key.equals(node.key)) {
// Exact leaf already exists.
if (leaf.equals(node.data))
return root;
@@ -2218,69 +2218,69 @@
break outer;
}
- assert(depth !== this.bits);
+ assert(depth !== this.bits);
// Insert placeholder leaves to grow
// the branch if we have bit collisions.
- while (hasBit(key, depth) === hasBit(node.key, depth)) {
+ while (hasBit(key, depth) === hasBit(node.key, depth)) {
// Child-less sibling.
- nodes.push(NIL);
- depth += 1;
+ nodes.push(NIL);
+ depth += 1;
}
// Leaf is our sibling.
- nodes.push(node);
- depth += 1;
+ nodes.push(node);
+ depth += 1;
- break outer;
+ break outer;
}
case HASH: {
- node = await this.resolve(node);
- break;
+ node = await this.resolve(node);
+ break;
}
- default: {
+ default: {
throw new AssertionError('Unknown node type.');
}
}
}
// Start at the leaf.
- root = new Leaf(leaf, key, value);
+ root = new Leaf(leaf, key, value);
// Traverse bits right to left.
- while (nodes.length > 0) {
- const node = nodes.pop();
+ while (nodes.length > 0) {
+ const node = nodes.pop();
- depth -= 1;
+ depth -= 1;
- if (hasBit(key, depth))
- root = new Internal(node, root);
+ if (hasBit(key, depth))
+ root = new Internal(node, root);
else
- root = new Internal(root, node);
+ root = new Internal(root, node);
}
- return root;
+ return root;
}
- async _remove(root, key) {
- const nodes = [];
+ async _remove(root, key) {
+ const nodes = [];
- let node = root;
- let depth = 0;
+ let node = root;
+ let depth = 0;
// Traverse bits left to right.
-outer:
- for (;;) {
- switch (node.type()) {
- case NULL: {
+outer:
+ for (;;) {
+ switch (node.type()) {
+ case NULL: {
// Empty (sub)tree.
return root;
}
case INTERNAL: {
- if (depth === this.bits) {
+ Iif (depth === this.bits) {
throw new MissingNodeError({
rootHash: root.hash(this.hash),
key,
@@ -2289,160 +2289,160 @@
}
// Internal node.
- if (hasBit(key, depth)) {
- nodes.push(node.left);
- node = node.right;
+ if (hasBit(key, depth)) {
+ nodes.push(node.left);
+ node = node.right;
} else {
- nodes.push(node.right);
- node = node.left;
+ nodes.push(node.right);
+ node = node.left;
}
- depth += 1;
+ depth += 1;
- break;
+ break;
}
case LEAF: {
// Not our key.
- if (!key.equals(node.key))
+ Iif (!key.equals(node.key))
return root;
// Root can be a leaf.
- if (depth === 0) {
+ Iif (depth === 0) {
// Remove the root.
return NIL;
}
// Sibling.
- root = nodes[depth - 1];
+ root = nodes[depth - 1];
// Shrink the subtree if we're a leaf.
- if (root.leaf) {
- nodes.pop();
- depth -= 1;
+ if (root.leaf) {
+ nodes.pop();
+ depth -= 1;
- while (depth > 0) {
- const side = nodes[depth - 1];
+ while (depth > 0) {
+ const side = nodes[depth - 1];
- if (!side.isNull())
- break;
+ if (!side.isNull())
+ break;
- nodes.pop();
- depth -= 1;
+ nodes.pop();
+ depth -= 1;
}
} else {
- root = NIL;
+ root = NIL;
}
- break outer;
+ break outer;
}
case HASH: {
- node = await this.resolve(node);
- break;
+ node = await this.resolve(node);
+ break;
}
- default: {
+ default: {
throw new AssertionError('Unknown node type.');
}
}
}
// Traverse bits right to left.
- while (nodes.length > 0) {
- const node = nodes.pop();
+ while (nodes.length > 0) {
+ const node = nodes.pop();
- depth -= 1;
+ depth -= 1;
- if (hasBit(key, depth))
- root = new Internal(node, root);
+ if (hasBit(key, depth))
+ root = new Internal(node, root);
else
- root = new Internal(root, node);
+ root = new Internal(root, node);
}
- return root;
+ return root;
}
- async _commit(node) {
- const root = this._write(node);
+ async _commit(node) {
+ const root = this._write(node);
- await this.store.commit(root);
+ await this.store.commit(root);
- this.root = root;
+ this.root = root;
- return root;
+ return root;
}
- _write(node) {
- switch (node.type()) {
+ _write(node) {
+ switch (node.type()) {
case NULL: {
- assert(node.index === 0);
- return node;
+ assert(node.index === 0);
+ return node;
}
case INTERNAL: {
- node.left = this._write(node.left);
- node.right = this._write(node.right);
+ node.left = this._write(node.left);
+ node.right = this._write(node.right);
- if (node.index === 0) {
- this.store.writeNode(node);
+ Eif (node.index === 0) {
+ this.store.writeNode(node);
// if (this.store.needsFlush())
// await this.store.flush();
}
- assert(node.index !== 0);
+ assert(node.index !== 0);
- return node.toHash(this.hash);
+ return node.toHash(this.hash);
}
case LEAF: {
- if (node.index === 0) {
- assert(node.value);
+ if (node.index === 0) {
+ assert(node.value);
- this.store.writeValue(node);
- this.store.writeNode(node);
+ this.store.writeValue(node);
+ this.store.writeNode(node);
// if (this.store.needsFlush())
// await this.store.flush();
}
- assert(node.index !== 0);
+ assert(node.index !== 0);
- return node.toHash(this.hash);
+ return node.toHash(this.hash);
}
case HASH: {
- assert(node.index !== 0);
- return node;
+ assert(node.index !== 0);
+ return node;
}
}
throw new AssertionError('Unknown node.');
}
- async prove(key) {
- assert(this.isKey(key));
- return this._prove(this.root, key);
+ async prove(key) {
+ assert(this.isKey(key));
+ return this._prove(this.root, key);
}
- async _prove(root, key) {
- const proof = new Proof();
+ async _prove(root, key) {
+ const proof = new Proof();
- let node = root;
- let depth = 0;
+ let node = root;
+ let depth = 0;
// Traverse bits left to right.
-outer:
- for (;;) {
- switch (node.type()) {
+outer:
+ for (;;) {
+ switch (node.type()) {
case NULL: {
// Empty (sub)tree.
- break outer;
+ break outer;
}
case INTERNAL: {
- if (depth === this.bits) {
+ Iif (depth === this.bits) {
throw new MissingNodeError({
rootHash: root.hash(this.hash),
key,
@@ -2451,138 +2451,138 @@
}
// Internal node.
- if (hasBit(key, depth)) {
- const hash = node.left.hash(this.hash);
- proof.push(hash);
- node = node.right;
+ if (hasBit(key, depth)) {
+ const hash = node.left.hash(this.hash);
+ proof.push(hash);
+ node = node.right;
} else {
- const hash = node.right.hash(this.hash);
- proof.push(hash);
- node = node.left;
+ const hash = node.right.hash(this.hash);
+ proof.push(hash);
+ node = node.left;
}
- depth += 1;
+ depth += 1;
- break;
+ break;
}
case LEAF: {
- const value = await this.retrieve(node);
+ const value = await this.retrieve(node);
- if (node.key.equals(key)) {
- proof.type = Proof.TYPE_EXISTS;
- proof.value = value;
+ if (node.key.equals(key)) {
+ proof.type = Proof.TYPE_EXISTS;
+ proof.value = value;
} else {
- proof.type = Proof.TYPE_COLLISION;
- proof.key = Buffer.from(node.key);
- proof.hash = this.hash.digest(value);
+ proof.type = Proof.TYPE_COLLISION;
+ proof.key = Buffer.from(node.key);
+ proof.hash = this.hash.digest(value);
}
- break outer;
+ break outer;
}
case HASH: {
- node = await this.resolve(node);
- break;
+ node = await this.resolve(node);
+ break;
}
- default: {
+ default: {
throw new AssertionError('Unknown node type.');
}
}
}
- return proof;
+ return proof;
}
- async compact() {
- const prefix = randomPath(this.prefix);
- const store = this.store.clone(prefix);
+ async compact() {
+ const prefix = randomPath(this.prefix);
+ const store = this.store.clone(prefix);
- await store.open();
+ await store.open();
- const root = await this._compact(this.root, store);
+ const root = await this._compact(this.root, store);
- await store.commit(root);
- await store.close();
+ await store.commit(root);
+ await store.close();
- await this.store.close();
- await this.store.destroy();
+ await this.store.close();
+ await this.store.destroy();
- await store.rename(this.prefix);
- await store.open();
+ await store.rename(this.prefix);
+ await store.open();
- this.store = store;
- this.root = root;
+ this.store = store;
+ this.root = root;
}
- async _compact(node, store) {
- switch (node.type()) {
+ async _compact(node, store) {
+ switch (node.type()) {
case NULL: {
- return node;
+ return node;
}
case INTERNAL: {
- node.left = await this._compact(node.left, store);
- node.right = await this._compact(node.right, store);
+ node.left = await this._compact(node.left, store);
+ node.right = await this._compact(node.right, store);
- node.index = 0;
- node.pos = 0;
+ node.index = 0;
+ node.pos = 0;
- store.writeNode(node);
+ store.writeNode(node);
- if (store.needsFlush())
+ Iif (store.needsFlush())
await store.flush();
- return node.toHash(this.hash);
+ return node.toHash(this.hash);
}
case LEAF: {
- node.index = 0;
- node.pos = 0;
- node.value = await this.retrieve(node);
+ node.index = 0;
+ node.pos = 0;
+ node.value = await this.retrieve(node);
- store.writeValue(node);
- store.writeNode(node);
+ store.writeValue(node);
+ store.writeNode(node);
- if (store.needsFlush())
+ Iif (store.needsFlush())
await store.flush();
- return node.toHash(this.hash);
+ return node.toHash(this.hash);
}
case HASH: {
- const rn = await this.resolve(node);
- return this._compact(rn, store);
+ const rn = await this.resolve(node);
+ return this._compact(rn, store);
}
}
throw new AssertionError('Unknown node.');
}
- snapshot(hash) {
- let root = null;
+ snapshot(hash) {
+ let root = null;
- if (hash == null) {
- hash = this.rootHash();
- root = this.root;
+ if (hash == null) {
+ hash = this.rootHash();
+ root = this.root;
}
- return new Snapshot(this, hash, root);
+ return new Snapshot(this, hash, root);
}
transaction() {
return new Transaction(this);
}
- iterator(read = true, descending = false) {
- const iter = new Iterator(this, this, read, descending);
- iter.root = this.root;
- return iter;
+ iterator(read = true, descending = false) {
+ const iter = new Iterator(this, this, read, descending);
+ iter.root = this.root;
+ return iter;
}
- [asyncIterator]() {
- return this.entries();
+ [asyncIterator]() {
+ return this.entries();
}
keys() {
@@ -2595,9 +2595,9 @@
return iter.values();
}
- entries() {
- const iter = this.iterator(true, false);
- return iter.entries();
+ entries() {
+ const iter = this.iterator(true, false);
+ return iter.entries();
}
batch() {
@@ -2619,19 +2619,19 @@
assert(tree.isHash(hash));
assert(root === null || (root instanceof Node));
- this.tree = tree;
- this.hash = hash;
- this.root = root;
+ this.tree = tree;
+ this.hash = hash;
+ this.root = root;
}
- rootHash() {
- return this.hash;
+ rootHash() {
+ return this.hash;
}
- async getRoot() {
- if (!this.root)
- this.root = await this.tree.getHistory(this.hash);
- return this.root;
+ async getRoot() {
+ Eif (!this.root)
+ this.root = await this.tree.getHistory(this.hash);
+ return this.root;
}
async inject(root) {
@@ -2639,30 +2639,30 @@
this.hash = root;
}
- async get(key) {
- assert(this.tree.isKey(key));
+ async get(key) {
+ assert(this.tree.isKey(key));
- if (!this.root)
- this.root = await this.getRoot();
+ Eif (!this.root)
+ this.root = await this.getRoot();
- return this.tree._get(this.root, key);
+ return this.tree._get(this.root, key);
}
- async prove(key) {
- if (!this.root)
- this.root = await this.getRoot();
+ async prove(key) {
+ if (!this.root)
+ this.root = await this.getRoot();
- return this.tree._prove(this.root, key);
+ return this.tree._prove(this.root, key);
}
- iterator(read = true, descending = false) {
- const iter = new Iterator(this.tree, this, read, descending);
- iter.root = this.root;
- return iter;
+ iterator(read = true, descending = false) {
+ const iter = new Iterator(this.tree, this, read, descending);
+ iter.root = this.root;
+ return iter;
}
- [asyncIterator]() {
- return this.entries();
+ [asyncIterator]() {
+ return this.entries();
}
keys() {
@@ -2675,9 +2675,9 @@
return iter.values();
}
- entries() {
- const iter = this.iterator(true);
- return iter.entries();
+ entries() {
+ const iter = this.iterator(true);
+ return iter.entries();
}
}
@@ -2691,29 +2691,29 @@
super(tree, tree.rootHash(), tree.root);
}
- rootHash() {
- return this.root.hash(this.tree.hash);
+ rootHash() {
+ return this.root.hash(this.tree.hash);
}
async getRoot() {
return this.root;
}
- async insert(key, value) {
- assert(this.tree.isKey(key));
- assert(this.tree.isValue(value));
- this.root = await this.tree._insert(this.root, key, value);
+ async insert(key, value) {
+ assert(this.tree.isKey(key));
+ assert(this.tree.isValue(value));
+ this.root = await this.tree._insert(this.root, key, value);
}
- async remove(key) {
- assert(this.tree.isKey(key));
- this.root = await this.tree._remove(this.root, key);
+ async remove(key) {
+ assert(this.tree.isKey(key));
+ this.root = await this.tree._remove(this.root, key);
}
- async commit() {
- this.root = await this.tree._commit(this.root);
- this.hash = this.rootHash();
- return this.hash;
+ async commit() {
+ this.root = await this.tree._commit(this.root);
+ this.hash = this.rootHash();
+ return this.hash;
}
clear() {
@@ -2727,23 +2727,23 @@
*/
class Iterator {
- constructor(tree, parent, read, descending = false) {
- assert(tree instanceof Tree);
- assert(parent && typeof parent.getRoot === 'function');
- assert(typeof read === 'boolean');
-
- this.tree = tree;
- this.parent = parent;
- this.descending = 1;
- this.read = read;
- this.root = null;
- this.stack = [];
- this.done = false;
- this.node = NIL;
- this.key = null;
- this.value = null;
-
- if (descending) {
+ constructor(tree, parent, read, descending = false) {
+ assert(tree instanceof Tree);
+ assert(parent && typeof parent.getRoot === 'function');
+ assert(typeof read === 'boolean');
+
+ this.tree = tree;
+ this.parent = parent;
+ this.descending = 1;
+ this.read = read;
+ this.root = null;
+ this.stack = [];
+ this.done = false;
+ this.node = NIL;
+ this.key = null;
+ this.value = null;
+
+ Iif (descending) {
this.descending = 0
}
}
@@ -2760,121 +2760,121 @@
return new AsyncIterator(this, 1);
}
- entries() {
- return new AsyncIterator(this, 2);
+ entries() {
+ return new AsyncIterator(this, 2);
}
- push(node, depth) {
- const state = new IteratorState(node, depth);
- return this.stack.push(state);
+ push(node, depth) {
+ const state = new IteratorState(node, depth);
+ return this.stack.push(state);
}
- pop() {
- assert(this.stack.length > 0);
- return this.stack.pop();
+ pop() {
+ assert(this.stack.length > 0);
+ return this.stack.pop();
}
- top() {
- assert(this.stack.length > 0);
- return this.stack[this.stack.length - 1];
+ top() {
+ assert(this.stack.length > 0);
+ return this.stack[this.stack.length - 1];
}
- length() {
- return this.stack.length;
+ length() {
+ return this.stack.length;
}
- async seek() {
- if (!this.root)
+ async seek() {
+ Iif (!this.root)
this.root = await this.parent.getRoot();
- this.node = NIL;
+ this.node = NIL;
- if (this.done)
+ Iif (this.done)
return false;
- if (this.length() === 0) {
- this.push(this.root, 0);
+ if (this.length() === 0) {
+ this.push(this.root, 0);
} else {
- this.pop();
+ this.pop();
- if (this.length() === 0) {
- this.done = true;
- return false;
+ if (this.length() === 0) {
+ this.done = true;
+ return false;
}
}
-outer:
- for (;;) {
- const parent = this.top();
- const {node, depth} = parent;
+outer:
+ for (;;) {
+ const parent = this.top();
+ const {node, depth} = parent;
- switch (node.type()) {
+ switch (node.type()) {
case NULL: {
- this.node = node;
- break outer;
+ this.node = node;
+ break outer;
}
case INTERNAL: {
- if (parent.child >= 1)
- break outer;
+ if (parent.child >= 1)
+ break outer;
- parent.child += 1;
+ parent.child += 1;
- if (parent.child === this.descending)
- this.push(node.right, depth + 1);
+ if (parent.child === this.descending)
+ this.push(node.right, depth + 1);
else
- this.push(node.left, depth + 1);
+ this.push(node.left, depth + 1);
- break;
+ break;
}
case LEAF: {
- this.node = node;
- break outer;
+ this.node = node;
+ break outer;
}
case HASH: {
- if (parent.child >= 0)
- break outer;
+ if (parent.child >= 0)
+ break outer;
- parent.child += 1;
+ parent.child += 1;
- const rn = await this.tree.resolve(node);
- this.push(rn, depth);
- break;
+ const rn = await this.tree.resolve(node);
+ this.push(rn, depth);
+ break;
}
- default: {
+ default: {
throw new AssertionError('Unknown node.');
}
}
}
- return true;
+ return true;
}
- async next() {
- for (;;) {
- if (!await this.seek())
- break;
+ async next() {
+ for (;;) {
+ if (!await this.seek())
+ break;
- if (!this.node.isLeaf())
- continue;
+ if (!this.node.isLeaf())
+ continue;
- this.key = this.node.key;
- this.value = this.node.value;
+ this.key = this.node.key;
+ this.value = this.node.value;
- if (this.read && !this.value)
- this.value = await this.tree.retrieve(this.node);
+ Eif (this.read && !this.value)
+ this.value = await this.tree.retrieve(this.node);
- return true;
+ return true;
}
- this.key = null;
- this.value = null;
+ this.key = null;
+ this.value = null;
- return false;
+ return false;
}
}
@@ -2883,10 +2883,10 @@
*/
class IteratorState {
- constructor(node, depth) {
- this.node = node;
- this.depth = depth;
- this.child = -1;
+ constructor(node, depth) {
+ this.node = node;
+ this.depth = depth;
+ this.child = -1;
}
}
@@ -2895,27 +2895,27 @@
*/
class AsyncIterator {
- constructor(iter, type) {
- assert(iter instanceof Iterator);
- assert((type & 3) === type);
- assert(type < 3);
+ constructor(iter, type) {
+ assert(iter instanceof Iterator);
+ assert((type & 3) === type);
+ assert(type < 3);
- this.iter = iter;
- this.type = type;
+ this.iter = iter;
+ this.type = type;
}
- async next() {
- if (!await this.iter.next())
- return { value: undefined, done: true };
+ async next() {
+ if (!await this.iter.next())
+ return { value: undefined, done: true };
- switch (this.type) {
- case 0:
+ switch (this.type) {
+ case 0:
return { value: this.iter.key, done: false };
- case 1:
+ case 1:
return { value: this.iter.value, done: false };
case 2:
- return { value: [this.iter.key, this.iter.value], done: false };
- default:
+ return { value: [this.iter.key, this.iter.value], done: false };
+ default:
throw new AssertionError('Bad value mode.');
}
}
@@ -2932,7 +2932,7 @@
diff --git a/coverage/urkel/lib/optimized/urkel.js.html b/coverage/urkel/lib/optimized/urkel.js.html
index 383a148..7716d04 100644
--- a/coverage/urkel/lib/optimized/urkel.js.html
+++ b/coverage/urkel/lib/optimized/urkel.js.html
@@ -97,9 +97,9 @@
*/
exports.common = require('../common');
- exports.store = require('../trie/store');
+ exports.store = require('./store');
exports.nodes = require('./nodes');
- exports.Proof = require('./proof');
+ exports.Proof = require('../proof');
exports.Tree = require('./tree');
exports.errors = require('../errors');
@@ -109,7 +109,7 @@
diff --git a/coverage/urkel/lib/proof.js.html b/coverage/urkel/lib/proof.js.html
new file mode 100644
index 0000000..ea0c865
--- /dev/null
+++ b/coverage/urkel/lib/proof.js.html
@@ -0,0 +1,1737 @@
+
+
+
+ Code coverage report for urkel/lib/proof.js
+
+
+
+
+
+
+
+
+
+
+
+
+ 77.78%
+ Statements
+ 203/261
+
+
+ 60.61%
+ Branches
+ 80/132
+
+
+ 72%
+ Functions
+ 18/25
+
+
+ 77.52%
+ Lines
+ 200/258
+
+
+
+ Press n or j to go to the next uncovered block, b, p or k for the previous block.
+
+
+
+
+1
+2
+3
+4
+5
+6
+7
+8
+9
+10
+11
+12
+13
+14
+15
+16
+17
+18
+19
+20
+21
+22
+23
+24
+25
+26
+27
+28
+29
+30
+31
+32
+33
+34
+35
+36
+37
+38
+39
+40
+41
+42
+43
+44
+45
+46
+47
+48
+49
+50
+51
+52
+53
+54
+55
+56
+57
+58
+59
+60
+61
+62
+63
+64
+65
+66
+67
+68
+69
+70
+71
+72
+73
+74
+75
+76
+77
+78
+79
+80
+81
+82
+83
+84
+85
+86
+87
+88
+89
+90
+91
+92
+93
+94
+95
+96
+97
+98
+99
+100
+101
+102
+103
+104
+105
+106
+107
+108
+109
+110
+111
+112
+113
+114
+115
+116
+117
+118
+119
+120
+121
+122
+123
+124
+125
+126
+127
+128
+129
+130
+131
+132
+133
+134
+135
+136
+137
+138
+139
+140
+141
+142
+143
+144
+145
+146
+147
+148
+149
+150
+151
+152
+153
+154
+155
+156
+157
+158
+159
+160
+161
+162
+163
+164
+165
+166
+167
+168
+169
+170
+171
+172
+173
+174
+175
+176
+177
+178
+179
+180
+181
+182
+183
+184
+185
+186
+187
+188
+189
+190
+191
+192
+193
+194
+195
+196
+197
+198
+199
+200
+201
+202
+203
+204
+205
+206
+207
+208
+209
+210
+211
+212
+213
+214
+215
+216
+217
+218
+219
+220
+221
+222
+223
+224
+225
+226
+227
+228
+229
+230
+231
+232
+233
+234
+235
+236
+237
+238
+239
+240
+241
+242
+243
+244
+245
+246
+247
+248
+249
+250
+251
+252
+253
+254
+255
+256
+257
+258
+259
+260
+261
+262
+263
+264
+265
+266
+267
+268
+269
+270
+271
+272
+273
+274
+275
+276
+277
+278
+279
+280
+281
+282
+283
+284
+285
+286
+287
+288
+289
+290
+291
+292
+293
+294
+295
+296
+297
+298
+299
+300
+301
+302
+303
+304
+305
+306
+307
+308
+309
+310
+311
+312
+313
+314
+315
+316
+317
+318
+319
+320
+321
+322
+323
+324
+325
+326
+327
+328
+329
+330
+331
+332
+333
+334
+335
+336
+337
+338
+339
+340
+341
+342
+343
+344
+345
+346
+347
+348
+349
+350
+351
+352
+353
+354
+355
+356
+357
+358
+359
+360
+361
+362
+363
+364
+365
+366
+367
+368
+369
+370
+371
+372
+373
+374
+375
+376
+377
+378
+379
+380
+381
+382
+383
+384
+385
+386
+387
+388
+389
+390
+391
+392
+393
+394
+395
+396
+397
+398
+399
+400
+401
+402
+403
+404
+405
+406
+407
+408
+409
+410
+411
+412
+413
+414
+415
+416
+417
+418
+419
+420
+421
+422
+423
+424
+425
+426
+427
+428
+429
+430
+431
+432
+433
+434
+435
+436
+437
+438
+439
+440
+441
+442
+443
+444
+445
+446
+447
+448
+449
+450
+451
+452
+453
+454
+455
+456
+457
+458
+459
+460
+461
+462
+463
+464
+465
+466
+467
+468
+469
+470
+471
+472
+473
+474
+475
+476
+477
+478
+479
+480
+481
+482
+483
+484
+485
+486
+487
+488
+489
+490
+491
+492
+493
+494
+495
+496
+497
+498
+499
+500
+501
+502
+503
+504
+505
+506
+507
+508
+509
+510
+511
+512
+513
+514
+515
+516
+517
+518
+519
+520
+521
+522
+523
+524
+525
+526
+527
+528
+529
+530
+531
+532
+533
+534
+535
+536
+537
+538
+539
+540
+541
+542
+543
+544
+545
+546
+547
+548
+549
+550
+551
+552
+553
+554
+555
+556
+557 |
+
+
+
+
+
+
+
+1x
+1x
+1x
+
+
+
+
+
+
+
+
+
+1x
+
+
+
+
+1x
+
+
+
+
+
+1x
+1x
+1x
+1x
+
+1x
+1x
+1x
+1x
+
+
+
+
+
+
+1x
+
+
+
+
+
+
+
+
+
+
+
+
+1x
+
+
+
+
+
+
+
+
+
+
+
+1x
+
+
+
+
+
+
+
+
+
+
+
+
+1x
+
+
+
+
+
+
+
+
+
+
+
+
+1892x
+1892x
+1892x
+1892x
+1892x
+
+
+
+
+
+
+
+1892x
+1892x
+1892x
+
+1892x
+
+
+1892x
+
+259x
+
+
+259x
+
+
+259x
+
+
+259x
+
+699x
+
+
+699x
+
+
+699x
+
+
+699x
+
+
+699x
+
+
+699x
+
+934x
+
+
+934x
+
+
+934x
+
+
+934x
+
+
+934x
+
+
+
+
+1892x
+
+
+
+23474x
+23474x
+23474x
+
+
+
+1844x
+1844x
+1844x
+1844x
+1844x
+1844x
+1844x
+
+1844x
+
+
+1844x
+
+
+1844x
+
+259x
+259x
+
+667x
+
+667x
+667x
+
+918x
+918x
+
+
+1844x
+
+1844x
+
+
+1844x
+23474x
+
+23474x
+11776x
+
+11698x
+
+
+1844x
+
+
+1844x
+
+
+
+48x
+48x
+48x
+48x
+48x
+
+48x
+
+48x
+48x
+
+48x
+80x
+80x
+
+
+48x
+
+
+
+32x
+32x
+32x
+
+16x
+16x
+16x
+
+
+48x
+
+
+
+24x
+24x
+
+24x
+24x
+24x
+24x
+
+24x
+
+24x
+
+24x
+
+24x
+24x
+
+24x
+40x
+
+40x
+
+
+
+
+40x
+
+
+24x
+
+
+
+16x
+16x
+16x
+
+8x
+8x
+8x
+
+
+24x
+
+24x
+
+
+
+
+
+
+
+
+
+
+
+
+24x
+24x
+24x
+24x
+24x
+24x
+
+24x
+
+24x
+
+24x
+24x
+
+24x
+
+24x
+
+24x
+
+
+24x
+
+24x
+24x
+
+24x
+40x
+
+
+
+
+40x
+40x
+
+40x
+
+
+24x
+
+
+
+
+
+16x
+16x
+
+16x
+16x
+
+16x
+
+
+
+8x
+
+8x
+8x
+
+8x
+8x
+
+8x
+
+
+
+
+
+
+
+24x
+
+
+
+
+
+
+
+
+
+24x
+24x
+24x
+24x
+
+
+
+24x
+24x
+
+
+
+24x
+
+40x
+
+
+
+
+
+
+
+24x
+24x
+24x
+24x
+
+24x
+
+
+24x
+
+
+24x
+
+24x
+
+
+24x
+
+
+24x
+
+24x
+40x
+
+24x
+
+
+
+16x
+16x
+16x
+
+8x
+8x
+
+
+
+
+
+
+24x
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+24x
+
+
+
+24x
+
+
+
+1x
+1x
+1x
+1x
+
+1x
+1x
+1x
+1x
+
+
+
+
+
+
+80x
+
+80x
+
+80x
+
+80x
+
+
+
+48x
+
+
+
+
+
+
+
+136x
+
+
+
+
+
+
+
+80x
+
+80x
+
+
+80x
+
+
+80x
+
+
+80x
+
+80x
+
+
+80x
+
+
+
+
+
+
+1x
+ | /*!
+ * proof.js - tree proofs
+ * Copyright (c) 2018, Christopher Jeffrey (MIT License).
+ * https://github.com/handshake-org/urkel
+ */
+
+'use strict';
+
+const assert = require('bsert');
+const common = require('./common');
+const errors = require('./errors');
+
+const {
+ hasBit,
+ setBit,
+ hashInternal,
+ hashLeaf,
+ hashValue,
+ readU16,
+ writeU16
+} = common;
+
+const {
+ AssertionError,
+ EncodingError
+} = errors;
+
+/*
+ * Constants
+ */
+
+const TYPE_DEADEND = 0;
+const TYPE_COLLISION = 1;
+const TYPE_EXISTS = 2;
+const TYPE_UNKNOWN = 3;
+
+const PROOF_OK = 0;
+const PROOF_HASH_MISMATCH = 1;
+const PROOF_SAME_KEY = 2;
+const PROOF_UNKNOWN_ERROR = 3;
+
+/**
+ * Proof types.
+ * @enum {Number}
+ */
+
+const types = {
+ TYPE_DEADEND,
+ TYPE_COLLISION,
+ TYPE_EXISTS,
+ TYPE_UNKNOWN
+};
+
+/**
+ * Proof types (strings).
+ * @const {String[]}
+ * @default
+ */
+
+const typesByVal = [
+ 'TYPE_DEADEND',
+ 'TYPE_COLLISION',
+ 'TYPE_EXISTS',
+ 'TYPE_UNKNOWN'
+];
+
+/**
+ * Verification error codes.
+ * @enum {Number}
+ */
+
+const codes = {
+ PROOF_OK,
+ PROOF_HASH_MISMATCH,
+ PROOF_SAME_KEY,
+ PROOF_UNKNOWN_ERROR
+};
+
+/**
+ * Verification error codes (strings).
+ * @const {String[]}
+ * @default
+ */
+
+const codesByVal = [
+ 'PROOF_OK',
+ 'PROOF_HASH_MISMATCH',
+ 'PROOF_SAME_KEY',
+ 'PROOF_UNKNOWN_ERROR'
+];
+
+/**
+ * Proof
+ */
+
+class Proof {
+ constructor() {
+ this.type = TYPE_DEADEND;
+ this.nodes = [];
+ this.key = null;
+ this.hash = null;
+ this.value = null;
+ }
+
+ get depth() {
+ return this.nodes.length;
+ }
+
+ isSane(hash, bits) {
+ assert(hash && typeof hash.digest === 'function');
+ assert((bits >>> 0) === bits);
+ assert(bits > 0 && (bits & 7) === 0);
+
+ Iif (this.nodes.length > bits)
+ return false;
+
+ switch (this.type) {
+ case TYPE_DEADEND:
+ Iif (this.key)
+ return false;
+
+ Iif (this.hash)
+ return false;
+
+ Iif (this.value)
+ return false;
+
+ break;
+ case TYPE_COLLISION:
+ Iif (!this.key)
+ return false;
+
+ Iif (!this.hash)
+ return false;
+
+ Iif (this.value)
+ return false;
+
+ Iif (this.key.length !== (bits >>> 3))
+ return false;
+
+ Iif (this.hash.length !== hash.size)
+ return false;
+
+ break;
+ case TYPE_EXISTS:
+ Iif (this.key)
+ return false;
+
+ Iif (this.hash)
+ return false;
+
+ Iif (!this.value)
+ return false;
+
+ Iif (this.value.length > 0xffff)
+ return false;
+
+ break;
+ default:
+ return false;
+ }
+
+ return true;
+ }
+
+ push(node) {
+ assert(Buffer.isBuffer(node));
+ this.nodes.push(Buffer.from(node));
+ return this;
+ }
+
+ verify(root, key, hash, bits) {
+ assert(Buffer.isBuffer(root));
+ assert(Buffer.isBuffer(key));
+ assert(hash && typeof hash.digest === 'function');
+ assert((bits >>> 0) === bits);
+ assert(bits > 0 && (bits & 7) === 0);
+ assert(root.length === hash.size);
+ assert(key.length === (bits >>> 3));
+
+ Iif (!this.isSane(hash, bits))
+ return [PROOF_UNKNOWN_ERROR, null];
+
+ let leaf = null;
+
+ // Re-create the leaf.
+ switch (this.type) {
+ case TYPE_DEADEND:
+ leaf = hash.zero;
+ break;
+ case TYPE_COLLISION:
+ Iif (this.key.equals(key))
+ return [PROOF_SAME_KEY, null];
+ leaf = hashLeaf(hash, this.key, this.hash);
+ break;
+ case TYPE_EXISTS:
+ leaf = hashValue(hash, key, this.value);
+ break;
+ }
+
+ assert(leaf);
+
+ let next = leaf;
+
+ // Traverse bits right to left.
+ for (let i = this.nodes.length - 1; i >= 0; i--) {
+ const node = this.nodes[i];
+
+ if (hasBit(key, i))
+ next = hashInternal(hash, node, next);
+ else
+ next = hashInternal(hash, next, node);
+ }
+
+ Iif (!next.equals(root))
+ return [PROOF_HASH_MISMATCH, null];
+
+ return [PROOF_OK, this.value];
+ }
+
+ getSize(hash, bits) {
+ assert(hash && typeof hash.digest === 'function');
+ assert((bits >>> 0) === bits);
+ assert(bits > 0 && (bits & 7) === 0);
+ assert(bits < (1 << 14));
+ assert(this.isSane(hash, bits));
+
+ let size = 0;
+
+ size += 2;
+ size += (this.nodes.length + 7) >>> 3;
+
+ for (const node of this.nodes) {
+ Eif (!node.equals(hash.zero))
+ size += node.length;
+ }
+
+ switch (this.type) {
+ case TYPE_DEADEND:
+ break;
+ case TYPE_COLLISION:
+ size += bits >>> 3;
+ size += hash.size;
+ break;
+ case TYPE_EXISTS:
+ size += 2;
+ size += this.value.length;
+ break;
+ }
+
+ return size;
+ }
+
+ write(data, off, hash, bits) {
+ assert(Buffer.isBuffer(data));
+ assert((off >>> 0) === off);
+
+ const size = this.getSize(hash, bits);
+ const count = this.nodes.length;
+ const bsize = (count + 7) >>> 3;
+ const field = (this.type << 14) | count;
+
+ let pos = off;
+
+ checkWrite(pos + size <= data.length, pos);
+
+ pos = writeU16(data, field, pos);
+
+ data.fill(0x00, pos, pos + bsize);
+ pos += bsize;
+
+ for (let i = 0; i < this.nodes.length; i++) {
+ const node = this.nodes[i];
+
+ Iif (node.equals(hash.zero)) {
+ setBit(data, (off + 2) * 8 + i, 1);
+ continue;
+ }
+
+ pos += node.copy(data, pos);
+ }
+
+ switch (this.type) {
+ case TYPE_DEADEND:
+ break;
+ case TYPE_COLLISION:
+ pos += this.key.copy(data, pos);
+ pos += this.hash.copy(data, pos);
+ break;
+ case TYPE_EXISTS:
+ pos = writeU16(data, this.value.length, pos);
+ pos += this.value.copy(data, pos);
+ break;
+ }
+
+ checkWrite((pos - off) === size, pos);
+
+ return pos;
+ }
+
+ writeBW(bw, hash, bits) {
+ assert(bw && typeof bw.writeU8 === 'function');
+ if (bw.data)
+ bw.offset = this.write(bw.data, bw.offset, hash, bits);
+ else
+ bw.writeBytes(this.encode(hash, bits));
+ return bw;
+ }
+
+ read(data, off, hash, bits) {
+ assert(Buffer.isBuffer(data));
+ assert((off >>> 0) === off);
+ assert(hash && typeof hash.digest === 'function');
+ assert((bits >>> 0) === bits);
+ assert(bits > 0 && (bits & 7) === 0);
+ assert(bits < (1 << 14));
+
+ let pos = off;
+
+ checkRead(pos + 2 <= data.length, pos);
+
+ const field = readU16(data, pos);
+ pos += 2;
+
+ this.type = field >>> 14;
+
+ const count = field & ~(3 << 14);
+
+ Iif (count > bits)
+ throw new EncodingError(pos, 'Proof too large');
+
+ const bsize = (count + 7) >>> 3;
+
+ checkRead(pos + bsize <= data.length, pos);
+ pos += bsize;
+
+ for (let i = 0; i < count; i++) {
+ Iif (hasBit(data, (off + 2) * 8 + i)) {
+ this.nodes.push(hash.zero);
+ continue;
+ }
+
+ const node = copy(data, pos, hash.size);
+ pos += hash.size;
+
+ this.nodes.push(node);
+ }
+
+ switch (this.type) {
+ case TYPE_DEADEND: {
+ break;
+ }
+
+ case TYPE_COLLISION: {
+ this.key = copy(data, pos, bits >>> 3);
+ pos += bits >>> 3;
+
+ this.hash = copy(data, pos, hash.size);
+ pos += hash.size;
+
+ break;
+ }
+
+ case TYPE_EXISTS: {
+ checkRead(pos + 2 <= data.length, pos);
+
+ const size = readU16(data, pos);
+ pos += 2;
+
+ this.value = copy(data, pos, size);
+ pos += size;
+
+ break;
+ }
+
+ default: {
+ throw new EncodingError(pos, 'Invalid type.');
+ }
+ }
+
+ return pos;
+ }
+
+ readBR(br, hash, bits) {
+ assert(br && typeof br.readU8 === 'function');
+ br.offset = this.read(br.data, br.offset, hash, bits);
+ return this;
+ }
+
+ encode(hash, bits) {
+ const size = this.getSize(hash, bits);
+ const data = Buffer.allocUnsafe(size);
+ this.write(data, 0, hash, bits);
+ return data;
+ }
+
+ decode(data, hash, bits) {
+ this.read(data, 0, hash, bits);
+ return this;
+ }
+
+ toJSON() {
+ return {
+ type: typesByVal[this.type],
+ nodes: this.nodes.map(node => node.toString('hex')),
+ key: this.key ? this.key.toString('hex') : undefined,
+ hash: this.hash ? this.hash.toString('hex') : undefined,
+ value: this.value ? this.value.toString('hex') : undefined
+ };
+ }
+
+ fromJSON(json, hash, bits) {
+ assert(hash && typeof hash.digest === 'function');
+ assert((bits >>> 0) === bits);
+ assert(bits > 0 && (bits & 7) === 0);
+ assert(bits < (1 << 14));
+
+ Iif (!json || typeof json !== 'object')
+ throw new EncodingError(0, 'Invalid JSON object');
+
+ Iif (typeof json.type !== 'string' || !types.hasOwnProperty(json.type))
+ throw new EncodingError(0, 'Type field must be a string');
+
+ const type = types[json.type];
+
+ Iif (!Array.isArray(json.nodes))
+ throw new EncodingError(0, 'Nodes field must be an array');
+
+ Iif (json.nodes.length > bits)
+ throw new EncodingError(0, 'Proof too large');
+
+ this.type = type;
+
+ for (const item of json.nodes)
+ this.nodes.push(parseHex(item, hash.size));
+
+ switch (type) {
+ case TYPE_DEADEND:
+ break;
+ case TYPE_COLLISION:
+ this.key = parseHex(json.key, bits >>> 3);
+ this.hash = parseHex(json.hash, hash.size);
+ break;
+ case TYPE_EXISTS:
+ this.value = parseHex(json.value, -1);
+ break;
+ case TYPE_UNKNOWN:
+ throw new EncodingError(0, 'Invalid type');
+ default:
+ throw new AssertionError('Invalid type.');
+ }
+
+ return this;
+ }
+
+ static type(value) {
+ assert((value & 0xff) === value);
+
+ if (value >= typesByVal.length)
+ value = TYPE_UNKNOWN;
+
+ return typesByVal[value];
+ }
+
+ static code(value) {
+ assert((value & 0xff) === value);
+
+ if (value >= codesByVal.length)
+ value = PROOF_UNKNOWN_ERROR;
+
+ return codesByVal[value];
+ }
+
+ static read(data, off, hash, bits) {
+ return new this().read(data, off, hash, bits);
+ }
+
+ static readBR(br, hash, bits) {
+ return new this().readBR(br, hash, bits);
+ }
+
+ static decode(data, hash, bits) {
+ return new this().decode(data, hash, bits);
+ }
+
+ static fromJSON(json, hash, bits) {
+ return new this().fromJSON(json, hash, bits);
+ }
+}
+
+Proof.types = types;
+Proof.typesByVal = typesByVal;
+Proof.codes = codes;
+Proof.codesByVal = codesByVal;
+
+Proof.TYPE_DEADEND = TYPE_DEADEND;
+Proof.TYPE_EXISTS = TYPE_EXISTS;
+Proof.TYPE_COLLISION = TYPE_COLLISION;
+Proof.TYPE_UNKNOWN = TYPE_UNKNOWN;
+
+/*
+ * Helpers
+ */
+
+function copy(data, pos, size) {
+ checkRead(pos + size <= data.length, pos, copy);
+
+ const buf = Buffer.allocUnsafe(size);
+
+ data.copy(buf, 0, pos, pos + size);
+
+ return buf;
+}
+
+function checkWrite(ok, offset, start) {
+ Iif (!ok) {
+ throw new EncodingError(offset,
+ 'Out of bounds write',
+ start || checkWrite);
+ }
+}
+
+function checkRead(ok, offset, start) {
+ Iif (!ok) {
+ throw new EncodingError(offset,
+ 'Out of bounds read',
+ start || checkRead);
+ }
+}
+
+function parseHex(str, size) {
+ assert(size === -1 || (size >>> 0) === size);
+
+ Iif (typeof str !== 'string')
+ throw new EncodingError(0, 'Field must be a string');
+
+ Iif ((str.length >>> 1) > 0xffff)
+ throw new EncodingError(0, 'Hex string too large');
+
+ Iif (size !== -1 && (str.length >>> 1) !== size)
+ throw new EncodingError(0, 'Unexpected hex string size');
+
+ const data = Buffer.from(str, 'hex');
+
+ Iif (data.length !== (str.length >>> 1))
+ throw new EncodingError(0, 'Invalid hex string');
+
+ return data;
+}
+
+/*
+ * Expose
+ */
+
+module.exports = Proof;
+ |
+
+
+
+
+
+
+
+
+
+
+
diff --git a/coverage/urkel/lib/radix/common.js.html b/coverage/urkel/lib/radix/common.js.html
index 692c214..015dbd1 100644
--- a/coverage/urkel/lib/radix/common.js.html
+++ b/coverage/urkel/lib/radix/common.js.html
@@ -301,9 +301,9 @@
-1321379x
-1321379x
-1321379x
+1318587x
+1318587x
+1318587x
@@ -316,33 +316,33 @@
-75989x
-60606x
+76133x
+60663x
-15383x
+15470x
-15383x
+15470x
-15383x
-15383x
-15383x
-15383x
-15383x
-15383x
+15470x
+15470x
+15470x
+15470x
+15470x
+15470x
-15383x
+15470x
-40967x
+40811x
-40619x
-40619x
+40484x
+40484x
@@ -403,7 +403,7 @@
-1519309x
+1519858x
@@ -413,16 +413,16 @@
-1519299x
+1519848x
-191861x
-191861x
-191861x
+192157x
+192157x
+192157x
@@ -435,14 +435,14 @@
-176470x
-176470x
-176470x
-176470x
-176470x
-176470x
-176470x
-176470x
+176679x
+176679x
+176679x
+176679x
+176679x
+176679x
+176679x
+176679x
@@ -742,7 +742,7 @@
diff --git a/coverage/urkel/lib/radix/index.html b/coverage/urkel/lib/radix/index.html
index 5904652..bd2da86 100644
--- a/coverage/urkel/lib/radix/index.html
+++ b/coverage/urkel/lib/radix/index.html
@@ -145,7 +145,7 @@
diff --git a/coverage/urkel/lib/radix/nodes.js.html b/coverage/urkel/lib/radix/nodes.js.html
index bd194a5..c4b710c 100644
--- a/coverage/urkel/lib/radix/nodes.js.html
+++ b/coverage/urkel/lib/radix/nodes.js.html
@@ -676,24 +676,24 @@
-1675469x
-1675469x
+1675920x
+1675920x
-1675255x
+1675706x
-2687248x
+2688032x
-1675226x
+1675677x
-2687247x
+2688031x
@@ -713,31 +713,31 @@
-176450x
-176450x
-176450x
-176450x
+176659x
+176659x
+176659x
+176659x
-176450x
-176450x
-176450x
-176450x
+176659x
+176659x
+176659x
+176659x
-176450x
+176659x
-1519281x
-1519281x
-1519281x
-1519281x
-1519281x
+1519830x
+1519830x
+1519830x
+1519830x
+1519830x
-1519281x
-1519281x
-1519281x
+1519830x
+1519830x
+1519830x
-1519281x
+1519830x
@@ -764,7 +764,7 @@
-1519281x
+1519830x
@@ -772,11 +772,11 @@
-155945x
-155945x
-155945x
-155945x
-155945x
+155847x
+155847x
+155847x
+155847x
+155847x
@@ -786,8 +786,8 @@
-3036880x
-3036880x
+3034702x
+3034702x
@@ -795,11 +795,11 @@
-123563x
+122024x
-52547x
+52277x
@@ -807,7 +807,7 @@
-2046x
+1942x
@@ -815,13 +815,13 @@
-110785x
-110785x
+110822x
+110822x
-121313x
-121313x
+121250x
+121250x
@@ -880,166 +880,166 @@
-1356143x
-1356143x
-1356143x
-1356143x
+1353614x
+1353614x
+1353614x
+1353614x
-1363373x
+1360844x
-68392x
+68564x
-1873850x
+1868385x
-938391x
+933729x
-935459x
+934656x
-1245294x
+1239678x
-622647x
-622647x
+619839x
+619839x
-622647x
-622647x
+619839x
+619839x
-79782x
-64784x
-64784x
-64784x
+79962x
+64964x
+64964x
+64964x
-64784x
+64964x
-79782x
+79962x
-65625x
+65797x
-65625x
-15250x
+65797x
+15312x
-65625x
+65797x
-65625x
+65797x
-65625x
+65797x
-65625x
+65797x
-65625x
-15250x
-15250x
+65797x
+15312x
+15312x
-65625x
-65625x
+65797x
+65797x
-65625x
-65625x
+65797x
+65797x
-65625x
+65797x
-65625x
-65625x
+65797x
+65797x
-65625x
+65797x
-65625x
-15250x
-15250x
-15250x
+65797x
+15312x
+15312x
+15312x
-65625x
+65797x
-65625x
-65625x
+65797x
+65797x
-65625x
+65797x
-65625x
-65625x
+65797x
+65797x
-65625x
+65797x
-719544x
+719948x
-719544x
-719544x
-719544x
+719948x
+719948x
+719948x
-719544x
+719948x
-719544x
-37850x
+719948x
+37920x
-37850x
+37920x
-37850x
-37850x
+37920x
+37920x
-37850x
+37920x
-37850x
-37850x
-37850x
+37920x
+37920x
+37920x
-37850x
+37920x
-37850x
+37920x
-719544x
-719544x
+719948x
+719948x
-719544x
-719544x
+719948x
+719948x
-719544x
+719948x
-719544x
-719544x
+719948x
+719948x
-719544x
-719544x
+719948x
+719948x
-719544x
+719948x
-719544x
+719948x
@@ -1051,17 +1051,17 @@
-719544x
-719544x
-719544x
+719948x
+719948x
+719948x
-622647x
-622647x
-622647x
-622647x
-622647x
+619839x
+619839x
+619839x
+619839x
+619839x
@@ -1071,60 +1071,60 @@
-120335x
-120335x
-120335x
-120335x
+119941x
+119941x
+119941x
+119941x
-149305x
+148901x
-131149x
+130858x
-67764x
-67764x
+67518x
+67518x
-28970x
+28960x
-45160x
-45160x
+45025x
+45025x
-45160x
+45025x
-45160x
-45160x
-45160x
-45160x
-45160x
-45160x
+45025x
+45025x
+45025x
+45025x
+45025x
+45025x
-80175x
+79916x
-80175x
-80175x
+79916x
+79916x
-80175x
-80175x
+79916x
+79916x
-80175x
-80175x
+79916x
+79916x
-80175x
+79916x
@@ -1132,8 +1132,8 @@
-80175x
-80175x
+79916x
+79916x
@@ -1143,20 +1143,20 @@
-1560401x
+1561146x
-811577x
+812160x
-799710x
+799855x
-246872x
-246872x
+247564x
+247564x
@@ -1174,11 +1174,11 @@
-799719x
+799864x
-719544x
+719948x
-80175x
+79916x
@@ -1780,7 +1780,7 @@
diff --git a/coverage/urkel/lib/radix/proof.js.html b/coverage/urkel/lib/radix/proof.js.html
index 9c8e5a7..fc01c01 100644
--- a/coverage/urkel/lib/radix/proof.js.html
+++ b/coverage/urkel/lib/radix/proof.js.html
@@ -967,7 +967,7 @@
946x
-11130x
+11073x
@@ -993,63 +993,63 @@
-115x
+136x
-115x
+136x
-115x
+136x
-115x
+136x
-115x
+136x
-115x
+136x
-115x
+136x
-115x
+136x
-115x
+136x
-115x
+136x
-115x
+136x
-364x
+343x
-364x
+343x
-364x
+343x
-364x
+343x
-364x
+343x
-364x
+343x
-364x
+343x
-364x
+343x
-364x
+343x
467x
@@ -1081,8 +1081,8 @@
-11110x
-11110x
+11053x
+11053x
@@ -1105,15 +1105,15 @@
-115x
+136x
-115x
-115x
+136x
+136x
-348x
+327x
-348x
-348x
+327x
+327x
459x
459x
@@ -1126,21 +1126,21 @@
922x
-11090x
+11033x
-11090x
+11033x
-11090x
+11033x
-11090x
-5551x
+11033x
+5457x
-5539x
+5576x
-11090x
+11033x
-11090x
+11033x
@@ -1505,16 +1505,16 @@
-11130x
-11130x
+11073x
+11073x
-11110x
-11110x
-11110x
-11110x
-11110x
+11053x
+11053x
+11053x
+11053x
+11053x
@@ -1551,7 +1551,7 @@
-11110x
+11053x
@@ -2404,7 +2404,7 @@
diff --git a/coverage/urkel/lib/radix/store.js.html b/coverage/urkel/lib/radix/store.js.html
index d73f91a..af3547c 100644
--- a/coverage/urkel/lib/radix/store.js.html
+++ b/coverage/urkel/lib/radix/store.js.html
@@ -1499,19 +1499,19 @@
-835557x
-835557x
+835681x
+835681x
-835557x
+835681x
-835557x
+835681x
-835557x
+835681x
-835557x
-835542x
+835681x
+835666x
15x
@@ -1672,12 +1672,12 @@
-835542x
+835666x
-835542x
+835666x
-835542x
+835666x
@@ -1711,14 +1711,14 @@
-799719x
-799719x
-799719x
+799864x
+799864x
+799864x
-799719x
-799719x
+799864x
+799864x
@@ -1735,43 +1735,43 @@
-110785x
-110785x
+110822x
+110822x
-110785x
+110822x
-110785x
+110822x
-110785x
+110822x
-110785x
+110822x
-110785x
+110822x
-110785x
+110822x
-110785x
-110785x
+110822x
+110822x
-110785x
+110822x
-110785x
+110822x
-45160x
-45160x
-45160x
-45160x
-45160x
-45160x
-45160x
-45160x
+45025x
+45025x
+45025x
+45025x
+45025x
+45025x
+45025x
+45025x
@@ -2028,23 +2028,23 @@
-801756x
-2046x
+801797x
+1942x
-799710x
-799710x
-799710x
-799710x
+799855x
+799855x
+799855x
+799855x
-35823x
+35802x
-35823x
+35802x
-35823x
-35823x
+35802x
+35802x
@@ -2204,20 +2204,20 @@
-311950x
+311754x
-155965x
+155867x
11x
-155965x
+155867x
45x
45x
45x
-155965x
+155867x
@@ -2226,12 +2226,12 @@
-45160x
+45025x
-45160x
-45160x
+45025x
+45025x
-45160x
+45025x
@@ -2271,17 +2271,17 @@
-835587x
+835711x
-835587x
+835711x
45x
-835542x
+835666x
-835542x
+835666x
-835542x
+835666x
@@ -3547,7 +3547,7 @@
diff --git a/coverage/urkel/lib/radix/tree.js.html b/coverage/urkel/lib/radix/tree.js.html
index 2dbb413..be43898 100644
--- a/coverage/urkel/lib/radix/tree.js.html
+++ b/coverage/urkel/lib/radix/tree.js.html
@@ -1051,15 +1051,15 @@
-101242x
+100972x
-101242x
+100972x
-40160x
+40025x
-40160x
+40025x
@@ -1069,8 +1069,8 @@
-40160x
-40160x
+40025x
+40025x
@@ -1103,11 +1103,11 @@
-801756x
+801797x
-35823x
+35802x
@@ -1115,14 +1115,14 @@
50014x
50014x
-1432784x
+1433314x
-667703x
+667971x
@@ -1130,30 +1130,30 @@
-667703x
-1325x
+667971x
+1328x
-666378x
+666643x
-666378x
+666643x
-666378x
-666378x
+666643x
+666643x
-666378x
+666643x
-48689x
-23679x
+48686x
+23676x
25010x
-716392x
-716392x
+716657x
+716657x
@@ -1172,14 +1172,14 @@
-517689x
+516559x
5x
-470134x
+468875x
@@ -1187,32 +1187,32 @@
-470134x
+468875x
-470134x
+468875x
-470134x
+468875x
-470134x
-11185x
-11185x
-11185x
-11185x
+468875x
+11060x
+11060x
+11060x
+11060x
-458949x
-458949x
-458949x
+457815x
+457815x
+457815x
-458949x
+457815x
-458949x
+457815x
-28970x
+28960x
@@ -1222,21 +1222,21 @@
-28970x
+28960x
-28970x
+28960x
-28970x
+28960x
-28970x
-28970x
+28960x
+28960x
-28970x
+28960x
-18580x
-18580x
+18719x
+18719x
@@ -1246,14 +1246,14 @@
-168461x
+166481x
-133697x
+132023x
@@ -1261,46 +1261,46 @@
-133697x
+132023x
-133697x
+132023x
-133697x
-133697x
-133697x
+132023x
+132023x
+132023x
-133697x
+132023x
-133697x
+132023x
-133697x
-10154x
+132023x
+10019x
2767x
2767x
-7387x
+7252x
-123543x
+122004x
-123543x
+122004x
-10154x
+10019x
-10154x
+10019x
-24610x
-24610x
+24439x
+24439x
@@ -1320,46 +1320,46 @@
-121271x
+121615x
-60626x
-60626x
+60798x
+60798x
-60626x
-60626x
+60798x
+60798x
-60626x
+60798x
-60626x
+60798x
-50679x
-40160x
+50444x
+40025x
-40160x
-40160x
+40025x
+40025x
-50679x
+50444x
-50679x
+50444x
-9966x
-9966x
+10373x
+10373x
@@ -1380,14 +1380,14 @@
922x
922x
-24024x
+23910x
-11205x
+11169x
@@ -1395,53 +1395,53 @@
-11205x
-115x
-115x
+11169x
+136x
+136x
-115x
-115x
-115x
-115x
-115x
+136x
+136x
+136x
+136x
+136x
-115x
+136x
-11090x
+11033x
-11090x
-11090x
-11090x
+11033x
+11033x
+11033x
-11090x
+11033x
-11090x
-11090x
+11033x
+11033x
-11090x
+11033x
-807x
+786x
-807x
+786x
459x
459x
459x
-348x
-348x
-348x
-348x
+327x
+327x
+327x
+327x
-807x
+786x
-12012x
-12012x
+11955x
+11955x
@@ -1656,22 +1656,22 @@
-40160x
-40160x
+40025x
+40025x
-40160x
+40025x
-40160x
-40160x
+40025x
+40025x
-10154x
+10019x
-10154x
+10019x
-10154x
-10154x
+10019x
+10019x
@@ -2809,7 +2809,7 @@
diff --git a/coverage/urkel/lib/radix/urkel.js.html b/coverage/urkel/lib/radix/urkel.js.html
index 851d4b4..35d0fef 100644
--- a/coverage/urkel/lib/radix/urkel.js.html
+++ b/coverage/urkel/lib/radix/urkel.js.html
@@ -106,7 +106,7 @@
diff --git a/coverage/urkel/lib/trie/index.html b/coverage/urkel/lib/trie/index.html
index 22b05e5..68c757e 100644
--- a/coverage/urkel/lib/trie/index.html
+++ b/coverage/urkel/lib/trie/index.html
@@ -20,24 +20,24 @@
- 79.78%
+ 79.8%
Statements
- 1097/1375
+ 889/1114
- 61.88%
+ 62.1%
Branches
- 276/446
+ 195/314
- 75.74%
+ 75.71%
Functions
- 178/235
+ 159/210
- 79.87%
+ 79.96%
Lines
- 1091/1366
+ 886/1108
@@ -74,30 +74,17 @@
181/205 |
|
-
- proof.js |
- |
- 77.78% |
- 203/261 |
- 60.61% |
- 80/132 |
- 72% |
- 18/25 |
- 77.52% |
- 200/258 |
-
-
store.js |
- |
- 72.94% |
- 399/547 |
- 48.67% |
- 73/150 |
- 72.15% |
- 57/79 |
- 73.25% |
- 397/542 |
+ |
+ 72.03% |
+ 394/547 |
+ 48% |
+ 72/150 |
+ 70.89% |
+ 56/79 |
+ 72.32% |
+ 392/542 |
@@ -132,7 +119,7 @@
diff --git a/coverage/urkel/lib/trie/nodes.js.html b/coverage/urkel/lib/trie/nodes.js.html
index 087af23..fdcb181 100644
--- a/coverage/urkel/lib/trie/nodes.js.html
+++ b/coverage/urkel/lib/trie/nodes.js.html
@@ -666,24 +666,24 @@
-1764840x
-1764840x
+1763244x
+1763244x
-1764578x
+1763030x
-2866514x
+2863120x
-1764549x
+1763001x
-2866501x
+2863119x
@@ -703,17 +703,17 @@
-198986x
-198986x
-198986x
-198986x
+198817x
+198817x
+198817x
+198817x
-198986x
-198986x
-198986x
-198986x
+198817x
+198817x
+198817x
+198817x
-198986x
+198817x
@@ -721,17 +721,17 @@
-1584469x
-1584469x
-1584469x
-1584469x
-1584469x
+1583042x
+1583042x
+1583042x
+1583042x
+1583042x
-1584469x
-1584469x
-1584469x
+1583042x
+1583042x
+1583042x
-1584469x
+1583042x
@@ -758,7 +758,7 @@
-1584469x
+1583042x
@@ -766,11 +766,11 @@
-180080x
-180080x
-180080x
-180080x
-180080x
+179959x
+179959x
+179959x
+179959x
+179959x
@@ -780,8 +780,8 @@
-3214548x
-3214548x
+3211652x
+3211652x
@@ -791,33 +791,33 @@
-469069x
+468470x
-44988x
+45030x
-24755x
+24592x
-886x
+897x
-25832x
+25659x
-135092x
-135092x
+134929x
+134929x
-141233x
-141233x
+141173x
+141173x
@@ -856,11 +856,11 @@
-41344x
+40982x
-85911x
+85319x
@@ -881,27 +881,27 @@
-1448875x
-1448875x
-1448875x
+1447424x
+1447424x
+1447424x
-1461569x
+1460007x
-90104x
+89899x
-1982579x
+1981723x
-992163x
+991875x
-990416x
+989848x
@@ -910,13 +910,13 @@
-1328936x
+1329722x
-664468x
-664468x
+664861x
+664861x
-664468x
-664468x
+664861x
+664861x
@@ -925,98 +925,98 @@
-109784x
-87837x
-87837x
+109391x
+87665x
+87665x
-87837x
+87665x
-109784x
+109391x
-90104x
+89899x
-90104x
-76999x
+89899x
+77025x
-90104x
-76959x
+89899x
+76722x
-90104x
+89899x
-90104x
+89899x
-90104x
-76999x
-76999x
+89899x
+77025x
+77025x
-90104x
-76959x
-76959x
+89899x
+76722x
+76722x
-90104x
+89899x
-90104x
-90104x
+89899x
+89899x
-90104x
-76999x
-76999x
-76999x
+89899x
+77025x
+77025x
+77025x
-90104x
-76959x
-76959x
-76959x
+89899x
+76722x
+76722x
+76722x
-90104x
+89899x
-784407x
+782563x
-784407x
-784407x
-784407x
+782563x
+782563x
+782563x
-784407x
+782563x
-784407x
-750970x
-750970x
+782563x
+749985x
+749985x
-750970x
-750970x
+749985x
+749985x
-750970x
+749985x
-784407x
-750756x
-750756x
+782563x
+750125x
+750125x
-750756x
-750756x
+750125x
+750125x
-750756x
+750125x
-784407x
+782563x
@@ -1027,17 +1027,17 @@
-784407x
-784407x
-784407x
+782563x
+782563x
+782563x
-664468x
-664468x
-664468x
-664468x
-664468x
+664861x
+664861x
+664861x
+664861x
+664861x
@@ -1048,60 +1048,60 @@
-122713x
-122713x
-122713x
-122713x
+122944x
+122944x
+122944x
+122944x
-144247x
+144582x
-137962x
+138070x
-63208x
-63208x
+63344x
+63344x
-28709x
+28847x
-44988x
-44988x
+45030x
+45030x
-44988x
+45030x
-44988x
-44988x
-44988x
-44988x
-44988x
-44988x
+45030x
+45030x
+45030x
+45030x
+45030x
+45030x
-82725x
+82914x
-82725x
-82725x
+82914x
+82914x
-82725x
-82725x
+82914x
+82914x
-82725x
-82725x
+82914x
+82914x
-82725x
+82914x
@@ -1109,8 +1109,8 @@
-82725x
-82725x
+82914x
+82914x
@@ -1123,20 +1123,20 @@
-1642959x
+1641283x
-883099x
+881205x
-867123x
+865468x
-284835x
-284835x
+284572x
+284572x
@@ -1154,11 +1154,11 @@
-867132x
+865477x
-784407x
+782563x
-82725x
+82914x
@@ -1750,7 +1750,7 @@
diff --git a/coverage/urkel/lib/trie/store.js.html b/coverage/urkel/lib/trie/store.js.html
index 96e0380..8e67a96 100644
--- a/coverage/urkel/lib/trie/store.js.html
+++ b/coverage/urkel/lib/trie/store.js.html
@@ -20,24 +20,24 @@
- 72.94%
+ 72.03%
Statements
- 399/547
+ 394/547
- 48.67%
+ 48%
Branches
- 73/150
+ 72/150
- 72.15%
+ 70.89%
Functions
- 57/79
+ 56/79
- 73.25%
+ 72.32%
Lines
- 397/542
+ 392/542
@@ -1260,28 +1260,28 @@
-12x
-12x
-12x
-12x
-12x
+6x
+6x
+6x
+6x
+6x
-12x
-12x
-12x
-12x
+6x
+6x
+6x
+6x
-12x
-12x
-12x
-12x
-12x
-12x
-12x
-12x
-12x
-12x
-12x
+6x
+6x
+6x
+6x
+6x
+6x
+6x
+6x
+6x
+6x
+6x
@@ -1295,28 +1295,28 @@
-31x
-31x
+24x
+24x
-24x
-24x
+18x
+18x
-24x
-38x
-38x
-25x
-13x
-13x
+18x
+31x
+31x
+19x
+12x
+12x
-13x
+12x
-13x
+12x
@@ -1324,16 +1324,16 @@
-24x
+18x
-24x
-13x
+18x
+12x
-13x
+12x
-24x
+18x
@@ -1351,54 +1351,54 @@
-21x
-21x
+15x
+15x
-21x
+15x
-21x
-21x
+15x
+15x
-21x
-11x
-11x
-11x
-11x
+15x
+6x
+6x
+6x
+6x
-10x
+9x
-21x
+15x
-21x
-21x
-21x
-21x
+15x
+15x
+15x
+15x
-21x
-11x
+15x
+6x
-10x
+9x
-21x
+15x
-21x
-21x
-21x
-21x
-21x
-21x
-21x
-21x
-21x
+15x
+15x
+15x
+15x
+15x
+15x
+15x
+15x
+15x
-21x
+15x
@@ -1474,52 +1474,52 @@
-902958x
-902958x
+901287x
+901287x
-902958x
+901287x
-902958x
+901287x
-902958x
+901287x
-902958x
-902937x
+901287x
+901272x
-21x
+15x
-21x
-21x
-21x
+15x
+15x
+15x
-21x
+15x
-21x
-21x
+15x
+15x
-21x
+15x
-21x
-21x
+15x
+15x
-21x
+15x
-21x
+15x
-21x
+15x
-21x
+15x
-21x
+15x
@@ -1627,9 +1627,9 @@
-902937x
-902937x
-902937x
+901272x
+901272x
+901272x
@@ -1656,14 +1656,14 @@
-867132x
-867132x
-867132x
+865477x
+865477x
+865477x
-867132x
-867132x
+865477x
+865477x
@@ -1672,55 +1672,55 @@
-41x
-41x
-41x
-41x
-41x
+35x
+35x
+35x
+35x
+35x
-135092x
-135092x
+134929x
+134929x
-135092x
+134929x
-135092x
+134929x
-135092x
+134929x
-135092x
+134929x
-135092x
+134929x
-135092x
+134929x
-135092x
-135092x
+134929x
+134929x
-135092x
+134929x
-135092x
+134929x
-44988x
-44988x
-44988x
-44988x
-44988x
-44988x
-44988x
-44988x
+45030x
+45030x
+45030x
+45030x
+45030x
+45030x
+45030x
+45030x
-12308x
+12251x
@@ -1783,12 +1783,12 @@
-10x
-10x
+9x
+9x
-10x
+9x
-10x
+9x
9x
9x
@@ -1815,45 +1815,45 @@
-1x
+
-21x
-21x
+15x
+15x
-21x
-11x
+15x
+6x
-10x
+9x
-10x
-10x
-10x
+9x
+9x
+9x
-10x
-10x
+9x
+9x
-10x
+9x
-10x
-10x
+9x
+9x
-10x
+9x
-10x
+9x
9x
9x
9x
9x
-1x
-1x
+
+
-1x
+
@@ -1864,19 +1864,19 @@
-21x
+15x
-21x
+15x
-21x
+15x
-21x
+15x
-21x
-12x
+15x
+6x
9x
@@ -1967,36 +1967,36 @@
-868009x
-886x
+866365x
+897x
-867123x
-867123x
-867123x
-867123x
+865468x
+865468x
+865468x
+865468x
-35805x
+35795x
-35805x
+35795x
-35805x
+35795x
-35805x
+35795x
-65x
+47x
-1806002x
+1802654x
@@ -2007,9 +2007,9 @@
-116x
-116x
-116x
+92x
+92x
+92x
@@ -2121,13 +2121,13 @@
-27x
-27x
-27x
-27x
+21x
+21x
+21x
+21x
-27x
-27x
+21x
+21x
@@ -2143,20 +2143,20 @@
-360220x
+359978x
-180100x
+179979x
11x
-180100x
+179979x
45x
45x
45x
-180100x
+179979x
@@ -2165,10 +2165,10 @@
-44988x
-44988x
-44988x
-44988x
+45030x
+45030x
+45030x
+45030x
@@ -2202,40 +2202,40 @@
-27x
-27x
+21x
+21x
-21x
+15x
-903000x
+901317x
-903000x
-63x
+901317x
+45x
-902937x
+901272x
-902937x
+901272x
-902937x
+901272x
-21x
+15x
-21x
-42x
+15x
+30x
-21x
-21x
+15x
+15x
-21x
+15x
-21x
+15x
@@ -2296,7 +2296,7 @@
-1x
+
@@ -2306,7 +2306,7 @@
-11x
+6x
@@ -2950,7 +2950,7 @@
}
}
- return [-1, null];
+ return [-1, null];
}
async recoverState(index) {
@@ -2977,18 +2977,18 @@
await file.close();
}
- if (meta) {
+ Eif (meta) {
const state = meta.clone();
state.metaPtr.index = index;
state.metaPtr.pos = off;
return [state, meta];
}
- await this.fs.unlink(path);
- index -= 1;
+ await this.fs.unlink(path);
+ index -= 1;
}
- return [new Meta(), new Meta()];
+ return [new Meta(), new Meta()];
}
@@ -3430,8 +3430,8 @@
*/
class FileStore extends Store {
- constructor(prefix, hash, bits) {
- super(fs, prefix, hash, bits);
+ constructor(prefix, hash, bits) {
+ super(fs, prefix, hash, bits);
}
}
@@ -3457,7 +3457,7 @@
diff --git a/coverage/urkel/lib/trie/tree.js.html b/coverage/urkel/lib/trie/tree.js.html
index 91e043c..62ff44f 100644
--- a/coverage/urkel/lib/trie/tree.js.html
+++ b/coverage/urkel/lib/trie/tree.js.html
@@ -936,7 +936,8 @@
888
889
890
-891
+891
+892 |
@@ -947,9 +948,10 @@
1x
1x
1x
+
+
1x
1x
-
1x
@@ -1023,15 +1025,15 @@
-100898x
+100982x
-100898x
+100982x
-39988x
+40030x
-39988x
+40030x
@@ -1041,8 +1043,8 @@
-39988x
-39988x
+40030x
+40030x
@@ -1075,11 +1077,11 @@
-868009x
+866365x
-35805x
+35795x
@@ -1087,14 +1089,14 @@
50014x
50014x
-1531613x
+1528601x
-1373x
+1353x
-716479x
+714963x
@@ -1102,25 +1104,25 @@
-716479x
+714963x
-716479x
-716479x
+714963x
+714963x
-716479x
+714963x
-48641x
-23631x
+48661x
+23651x
25010x
-765120x
-765120x
+763624x
+763624x
@@ -1136,14 +1138,14 @@
-540841x
+540917x
-11279x
+11183x
-479583x
+479624x
@@ -1151,20 +1153,20 @@
-479583x
-479583x
-479583x
-479583x
+479624x
+479624x
+479624x
+479624x
-479583x
+479624x
-479583x
+479624x
-28709x
+28847x
@@ -1174,31 +1176,31 @@
-28709x
+28847x
-28709x
+28847x
-28709x
+28847x
-28709x
+28847x
-28709x
-28709x
+28847x
+28847x
-28709x
-28862x
-28862x
-28862x
+28847x
+28753x
+28753x
+28753x
-28709x
+28847x
-21270x
-21270x
+21263x
+21263x
@@ -1208,14 +1210,14 @@
-186037x
+186455x
-141650x
+142012x
@@ -1223,43 +1225,43 @@
-141650x
-141650x
-141650x
+142012x
+142012x
+142012x
-141650x
+142012x
-141650x
+142012x
-141650x
-21511x
-7175x
+142012x
+21584x
+7209x
-14336x
-7161x
+14375x
+7166x
-127314x
+127637x
-9982x
+10024x
-9982x
+10024x
-9982x
-7175x
+10024x
+7209x
-2807x
+2815x
-34405x
-34405x
+34419x
+34419x
@@ -1279,46 +1281,46 @@
-165611x
+165315x
-23941x
+23799x
-82796x
-82796x
+82648x
+82648x
-82796x
-82796x
+82648x
+82648x
-82796x
+82648x
-82796x
+82648x
-46120x
-39988x
+46265x
+40030x
-39988x
-39988x
+40030x
+40030x
-46120x
+46265x
-46120x
+46265x
-12754x
-12754x
+12603x
+12603x
@@ -1339,14 +1341,14 @@
922x
922x
-25345x
+25189x
-133x
+143x
-11817x
+11744x
@@ -1354,36 +1356,36 @@
-11817x
-11817x
-11817x
+11744x
+11744x
+11744x
-11817x
+11744x
-11817x
-11817x
+11744x
+11744x
-11817x
+11744x
-789x
+779x
-789x
+779x
459x
459x
-330x
-330x
-330x
+320x
+320x
+320x
-789x
+779x
-12606x
-12606x
+12523x
+12523x
@@ -1417,23 +1419,23 @@
-26925x
+26754x
-2309x
+2252x
-7308x
-7308x
+7251x
+7251x
-7308x
+7251x
-7308x
+7251x
-7308x
+7251x
-7308x
+7251x
@@ -1450,8 +1452,8 @@
-12308x
-12308x
+12251x
+12251x
@@ -1598,22 +1600,22 @@
-39988x
-39988x
+40030x
+40030x
-39988x
+40030x
-39988x
-39988x
+40030x
+40030x
-9982x
+10024x
-9982x
+10024x
-9982x
-9982x
+10024x
+10024x
@@ -1666,67 +1668,67 @@
-26945x
-26945x
+26774x
+26774x
-26945x
-26945x
+26774x
+26774x
-53887x
-53887x
+53545x
+53545x
-53893x
+53551x
-26948x
+26777x
-26948x
+26777x
-26948x
+26777x
-26948x
+26777x
3x
-26945x
+26774x
-26945x
+26774x
3x
3x
-26945x
-26945x
-53887x
-53887x
+26774x
+26774x
+53545x
+53545x
-53887x
+53545x
-2309x
-2309x
+2252x
+2252x
-21936x
-7312x
+21765x
+7255x
-14624x
+14510x
-14624x
-7312x
+14510x
+7255x
-7312x
+7255x
-14624x
+14510x
@@ -1735,14 +1737,14 @@
-24636x
-12318x
+24522x
+12261x
-12318x
+12261x
-12318x
-12318x
-12318x
+12261x
+12261x
+12261x
@@ -1751,16 +1753,16 @@
-26945x
+26774x
5009x
-26948x
+26777x
3x
-26945x
-21939x
+26774x
+21768x
5006x
5006x
@@ -1784,9 +1786,9 @@
-26945x
-26945x
-26945x
+26774x
+26774x
+26774x
@@ -1836,10 +1838,11 @@
const assert = require('bsert');
const common = require('../common');
+const Proof = require('../proof');
+
+
const nodes = require('./nodes');
-const Proof = require('./proof');
const store = require('./store');
-
const errors = require('../errors');
const {
@@ -2722,7 +2725,7 @@
diff --git a/coverage/urkel/lib/trie/urkel.js.html b/coverage/urkel/lib/trie/urkel.js.html
index dcce791..ed6ddab 100644
--- a/coverage/urkel/lib/trie/urkel.js.html
+++ b/coverage/urkel/lib/trie/urkel.js.html
@@ -99,7 +99,7 @@
exports.common = require('../common');
exports.store = require('./store');
exports.nodes = require('./nodes');
-exports.Proof = require('./proof');
+exports.Proof = require('../proof');
exports.Tree = require('./tree');
exports.errors = require('../errors');
@@ -109,7 +109,7 @@
diff --git a/coverage/urkel/optimized.js.html b/coverage/urkel/optimized.js.html
index ccc0493..12a0c2c 100644
--- a/coverage/urkel/optimized.js.html
+++ b/coverage/urkel/optimized.js.html
@@ -91,7 +91,7 @@
diff --git a/coverage/urkel/radix.js.html b/coverage/urkel/radix.js.html
index 8187dc2..1f25e03 100644
--- a/coverage/urkel/radix.js.html
+++ b/coverage/urkel/radix.js.html
@@ -91,7 +91,7 @@
diff --git a/coverage/urkel/trie.js.html b/coverage/urkel/trie.js.html
index 58b0aaf..6c3256d 100644
--- a/coverage/urkel/trie.js.html
+++ b/coverage/urkel/trie.js.html
@@ -91,7 +91,7 @@
diff --git a/lib/.DS_Store b/lib/.DS_Store
deleted file mode 100644
index bf990e5..0000000
Binary files a/lib/.DS_Store and /dev/null differ
diff --git a/lib/proof.js b/lib/proof.js
index 06131ad..88e60cc 100644
--- a/lib/proof.js
+++ b/lib/proof.js
@@ -7,8 +7,8 @@
'use strict';
const assert = require('bsert');
-const common = require('../common');
-const errors = require('../errors');
+const common = require('./common');
+const errors = require('./errors');
const {
hasBit,
diff --git a/lib/trie/urkel.js b/lib/trie/urkel.js
index e35377e..0be29fa 100644
--- a/lib/trie/urkel.js
+++ b/lib/trie/urkel.js
@@ -13,7 +13,7 @@
exports.common = require('../common');
exports.store = require('./store');
exports.nodes = require('./nodes');
-exports.Proof = require('./proof');
+exports.Proof = require('../proof');
exports.Tree = require('./tree');
exports.errors = require('../errors');
| | |