layout: aggressive asserts.
This commit is contained in:
parent
b5fef64aa1
commit
fbb2500281
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
const util = require('../utils/util');
|
const util = require('../utils/util');
|
||||||
const pad8 = util.pad8;
|
const pad8 = util.pad8;
|
||||||
const pad32 = util.pad32;
|
const pad32 = util.pad32;
|
||||||
@ -46,44 +47,58 @@ const layout = {
|
|||||||
return 'v' + pad8(bit) + hex(hash);
|
return 'v' + pad8(bit) + hex(hash);
|
||||||
},
|
},
|
||||||
vv: function vv(key) {
|
vv: function vv(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
|
assert(key.length === 36);
|
||||||
return [+key.slice(1, 4), key.slice(4, 36)];
|
return [+key.slice(1, 4), key.slice(4, 36)];
|
||||||
},
|
},
|
||||||
T: function T(address, hash) {
|
T: function T(addr, hash) {
|
||||||
address = hex(address);
|
addr = hex(addr);
|
||||||
|
|
||||||
if (address.length === 64)
|
if (addr.length === 64)
|
||||||
return 'W' + address + hex(hash);
|
return 'W' + addr + hex(hash);
|
||||||
|
|
||||||
return 'T' + address + hex(hash);
|
assert(addr.length === 40);
|
||||||
|
return 'T' + addr + hex(hash);
|
||||||
},
|
},
|
||||||
C: function C(address, hash, index) {
|
C: function C(addr, hash, index) {
|
||||||
address = hex(address);
|
addr = hex(addr);
|
||||||
|
|
||||||
if (address.length === 64)
|
if (addr.length === 64)
|
||||||
return 'X' + address + hex(hash) + pad32(index);
|
return 'X' + addr + hex(hash) + pad32(index);
|
||||||
|
|
||||||
return 'C' + address + hex(hash) + pad32(index);
|
assert(addr.length === 40);
|
||||||
|
return 'C' + addr + hex(hash) + pad32(index);
|
||||||
},
|
},
|
||||||
pp: function aa(key) {
|
pp: function aa(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
|
assert(key.length === 65);
|
||||||
return key.slice(1, 65);
|
return key.slice(1, 65);
|
||||||
},
|
},
|
||||||
Cc: function Cc(key) {
|
Cc: function Cc(key) {
|
||||||
let hash, index;
|
let hash, index;
|
||||||
|
|
||||||
|
assert(typeof key === 'string');
|
||||||
|
|
||||||
if (key.length === 139) {
|
if (key.length === 139) {
|
||||||
hash = key.slice(65, 129);
|
hash = key.slice(65, 129);
|
||||||
index = +key.slice(129);
|
index = +key.slice(129);
|
||||||
} else {
|
} else if (key.length === 115) {
|
||||||
hash = key.slice(41, 105);
|
hash = key.slice(41, 105);
|
||||||
index = +key.slice(105);
|
index = +key.slice(105);
|
||||||
|
} else {
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [hash, index];
|
return [hash, index];
|
||||||
},
|
},
|
||||||
Tt: function Tt(key) {
|
Tt: function Tt(key) {
|
||||||
return key.length === 129
|
assert(typeof key === 'string');
|
||||||
? key.slice(64)
|
|
||||||
: key.slice(41);
|
if (key.length === 129)
|
||||||
|
return key.slice(64);
|
||||||
|
|
||||||
|
assert(key.length === 105);
|
||||||
|
return key.slice(41);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -92,8 +107,9 @@ const layout = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function hex(hash) {
|
function hex(hash) {
|
||||||
if (typeof hash !== 'string')
|
if (Buffer.isBuffer(hash))
|
||||||
hash = hash.toString('hex');
|
hash = hash.toString('hex');
|
||||||
|
assert(typeof hash === 'string');
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Database Layout:
|
* Database Layout:
|
||||||
* R -> tip hash
|
* R -> tip hash
|
||||||
@ -61,78 +63,97 @@ const layout = {
|
|||||||
},
|
},
|
||||||
v: function v(bit, hash) {
|
v: function v(bit, hash) {
|
||||||
let key = Buffer.allocUnsafe(1 + 1 + 32);
|
let key = Buffer.allocUnsafe(1 + 1 + 32);
|
||||||
|
assert(typeof bit === 'number');
|
||||||
key[0] = 0x76;
|
key[0] = 0x76;
|
||||||
key[1] = bit;
|
key[1] = bit;
|
||||||
write(key, hash, 2);
|
write(key, hash, 2);
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
vv: function vv(key) {
|
vv: function vv(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length === 34);
|
||||||
return [key[1], key.toString('hex', 2, 34)];
|
return [key[1], key.toString('hex', 2, 34)];
|
||||||
},
|
},
|
||||||
T: function T(address, hash) {
|
T: function T(addr, hash) {
|
||||||
let len = address.length;
|
let len = addr.length;
|
||||||
let key;
|
let key;
|
||||||
|
|
||||||
if (typeof address === 'string')
|
if (typeof addr === 'string')
|
||||||
len /= 2;
|
len /= 2;
|
||||||
|
|
||||||
if (len === 32) {
|
if (len === 32) {
|
||||||
key = Buffer.allocUnsafe(65);
|
key = Buffer.allocUnsafe(65);
|
||||||
key[0] = 0xab; // W + T
|
key[0] = 0xab; // W + T
|
||||||
write(key, address, 1);
|
write(key, addr, 1);
|
||||||
write(key, hash, 33);
|
write(key, hash, 33);
|
||||||
} else {
|
} else if (len === 20) {
|
||||||
key = Buffer.allocUnsafe(53);
|
key = Buffer.allocUnsafe(53);
|
||||||
key[0] = 0x54; // T
|
key[0] = 0x54; // T
|
||||||
write(key, address, 1);
|
write(key, addr, 1);
|
||||||
write(key, hash, 21);
|
write(key, hash, 21);
|
||||||
|
} else {
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
C: function C(address, hash, index) {
|
C: function C(addr, hash, index) {
|
||||||
let len = address.length;
|
let len = addr.length;
|
||||||
let key;
|
let key;
|
||||||
|
|
||||||
if (typeof address === 'string')
|
assert(typeof index === 'number');
|
||||||
|
|
||||||
|
if (typeof addr === 'string')
|
||||||
len /= 2;
|
len /= 2;
|
||||||
|
|
||||||
if (len === 32) {
|
if (len === 32) {
|
||||||
key = Buffer.allocUnsafe(69);
|
key = Buffer.allocUnsafe(69);
|
||||||
key[0] = 0x9a; // W + C
|
key[0] = 0x9a; // W + C
|
||||||
write(key, address, 1);
|
write(key, addr, 1);
|
||||||
write(key, hash, 33);
|
write(key, hash, 33);
|
||||||
key.writeUInt32BE(index, 65, true);
|
key.writeUInt32BE(index, 65, true);
|
||||||
} else {
|
} else if (len === 20) {
|
||||||
key = Buffer.allocUnsafe(57);
|
key = Buffer.allocUnsafe(57);
|
||||||
key[0] = 0x43; // C
|
key[0] = 0x43; // C
|
||||||
write(key, address, 1);
|
write(key, addr, 1);
|
||||||
write(key, hash, 21);
|
write(key, hash, 21);
|
||||||
key.writeUInt32BE(index, 53, true);
|
key.writeUInt32BE(index, 53, true);
|
||||||
|
} else {
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
pp: function aa(key) {
|
pp: function aa(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length === 33);
|
||||||
return key.toString('hex', 1, 33);
|
return key.toString('hex', 1, 33);
|
||||||
},
|
},
|
||||||
Cc: function Cc(key) {
|
Cc: function Cc(key) {
|
||||||
let hash, index;
|
let hash, index;
|
||||||
|
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
|
||||||
if (key.length === 69) {
|
if (key.length === 69) {
|
||||||
hash = key.toString('hex', 33, 65);
|
hash = key.toString('hex', 33, 65);
|
||||||
index = key.readUInt32BE(65, 0);
|
index = key.readUInt32BE(65, 0);
|
||||||
} else {
|
} else if (key.length === 57) {
|
||||||
hash = key.toString('hex', 21, 53);
|
hash = key.toString('hex', 21, 53);
|
||||||
index = key.readUInt32BE(53, 0);
|
index = key.readUInt32BE(53, 0);
|
||||||
|
} else {
|
||||||
|
assert(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
return [hash, index];
|
return [hash, index];
|
||||||
},
|
},
|
||||||
Tt: function Tt(key) {
|
Tt: function Tt(key) {
|
||||||
return key.length === 65
|
assert(Buffer.isBuffer(key));
|
||||||
? key.toString('hex', 33, 65)
|
|
||||||
: key.toString('hex', 21, 53);
|
if (key.length === 65)
|
||||||
|
return key.toString('hex', 33, 65);
|
||||||
|
|
||||||
|
assert(key.length === 53);
|
||||||
|
return key.toString('hex', 21, 53);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -143,6 +164,7 @@ const layout = {
|
|||||||
function write(data, str, off) {
|
function write(data, str, off) {
|
||||||
if (Buffer.isBuffer(str))
|
if (Buffer.isBuffer(str))
|
||||||
return str.copy(data, off);
|
return str.copy(data, off);
|
||||||
|
assert(typeof str === 'string');
|
||||||
data.write(str, off, 'hex');
|
data.write(str, off, 'hex');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +177,7 @@ function pair(prefix, hash) {
|
|||||||
|
|
||||||
function ipair(prefix, num) {
|
function ipair(prefix, num) {
|
||||||
let key = Buffer.allocUnsafe(5);
|
let key = Buffer.allocUnsafe(5);
|
||||||
|
assert(typeof num === 'number');
|
||||||
key[0] = prefix;
|
key[0] = prefix;
|
||||||
key.writeUInt32BE(num, 1, true);
|
key.writeUInt32BE(num, 1, true);
|
||||||
return key;
|
return key;
|
||||||
@ -162,6 +185,7 @@ function ipair(prefix, num) {
|
|||||||
|
|
||||||
function bpair(prefix, hash, index) {
|
function bpair(prefix, hash, index) {
|
||||||
let key = Buffer.allocUnsafe(37);
|
let key = Buffer.allocUnsafe(37);
|
||||||
|
assert(typeof index === 'number');
|
||||||
key[0] = prefix;
|
key[0] = prefix;
|
||||||
write(key, hash, 1);
|
write(key, hash, 1);
|
||||||
key.writeUInt32BE(index, 33, true);
|
key.writeUInt32BE(index, 33, true);
|
||||||
|
|||||||
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
const layout = {
|
const layout = {
|
||||||
binary: false,
|
binary: false,
|
||||||
R: 'R',
|
R: 'R',
|
||||||
@ -15,6 +17,8 @@ const layout = {
|
|||||||
return 'e' + hex(hash);
|
return 'e' + hex(hash);
|
||||||
},
|
},
|
||||||
ee: function ee(key) {
|
ee: function ee(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
|
assert(key.length === 65);
|
||||||
return key.slice(1, 65);
|
return key.slice(1, 65);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -24,8 +28,9 @@ const layout = {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
function hex(hash) {
|
function hex(hash) {
|
||||||
if (typeof hash !== 'string')
|
if (Buffer.isBuffer(hash))
|
||||||
hash = hash.toString('hex');
|
hash = hash.toString('hex');
|
||||||
|
assert(typeof hash === 'string');
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Database Layout:
|
* Database Layout:
|
||||||
* R -> tip hash
|
* R -> tip hash
|
||||||
@ -25,6 +27,8 @@ const layout = {
|
|||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
ee: function ee(key) {
|
ee: function ee(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length === 33);
|
||||||
return key.toString('hex', 1, 33);
|
return key.toString('hex', 1, 33);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -36,6 +40,7 @@ const layout = {
|
|||||||
function write(data, str, off) {
|
function write(data, str, off) {
|
||||||
if (Buffer.isBuffer(str))
|
if (Buffer.isBuffer(str))
|
||||||
return str.copy(data, off);
|
return str.copy(data, off);
|
||||||
|
assert(typeof str === 'string');
|
||||||
data.write(str, off, 'hex');
|
data.write(str, off, 'hex');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -540,6 +540,7 @@ util.indexOf = function indexOf(items, data) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
util.pad8 = function pad8(num) {
|
util.pad8 = function pad8(num) {
|
||||||
|
assert(typeof num === 'number');
|
||||||
assert(num >= 0);
|
assert(num >= 0);
|
||||||
num = num + '';
|
num = num + '';
|
||||||
switch (num.length) {
|
switch (num.length) {
|
||||||
@ -561,6 +562,7 @@ util.pad8 = function pad8(num) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
util.pad32 = function pad32(num) {
|
util.pad32 = function pad32(num) {
|
||||||
|
assert(typeof num === 'number');
|
||||||
assert(num >= 0);
|
assert(num >= 0);
|
||||||
num = num + '';
|
num = num + '';
|
||||||
switch (num.length) {
|
switch (num.length) {
|
||||||
@ -597,6 +599,7 @@ util.pad32 = function pad32(num) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
util.hex8 = function hex8(num) {
|
util.hex8 = function hex8(num) {
|
||||||
|
assert(typeof num === 'number');
|
||||||
assert(num >= 0);
|
assert(num >= 0);
|
||||||
num = num.toString(16);
|
num = num.toString(16);
|
||||||
switch (num.length) {
|
switch (num.length) {
|
||||||
@ -617,6 +620,7 @@ util.hex8 = function hex8(num) {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
util.hex32 = function hex32(num) {
|
util.hex32 = function hex32(num) {
|
||||||
|
assert(typeof num === 'number');
|
||||||
assert(num >= 0);
|
assert(num >= 0);
|
||||||
num = num.toString(16);
|
num = num.toString(16);
|
||||||
switch (num.length) {
|
switch (num.length) {
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
const util = require('../utils/util');
|
const util = require('../utils/util');
|
||||||
const pad32 = util.pad32;
|
const pad32 = util.pad32;
|
||||||
const layouts = exports;
|
const layouts = exports;
|
||||||
@ -13,42 +14,53 @@ const layouts = exports;
|
|||||||
layouts.walletdb = {
|
layouts.walletdb = {
|
||||||
binary: false,
|
binary: false,
|
||||||
p: function p(hash) {
|
p: function p(hash) {
|
||||||
|
assert(typeof hash === 'string');
|
||||||
return 'p' + hash;
|
return 'p' + hash;
|
||||||
},
|
},
|
||||||
pp: function pp(key) {
|
pp: function pp(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
return key.slice(1);
|
return key.slice(1);
|
||||||
},
|
},
|
||||||
P: function P(wid, hash) {
|
P: function P(wid, hash) {
|
||||||
|
assert(typeof hash === 'string');
|
||||||
return 'p' + pad32(wid) + hash;
|
return 'p' + pad32(wid) + hash;
|
||||||
},
|
},
|
||||||
Pp: function Pp(key) {
|
Pp: function Pp(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
return key.slice(11);
|
return key.slice(11);
|
||||||
},
|
},
|
||||||
r: function r(wid, index, hash) {
|
r: function r(wid, index, hash) {
|
||||||
|
assert(typeof hash === 'string');
|
||||||
return 'r' + pad32(wid) + pad32(index) + hash;
|
return 'r' + pad32(wid) + pad32(index) + hash;
|
||||||
},
|
},
|
||||||
rr: function rr(key) {
|
rr: function rr(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
return key.slice(21);
|
return key.slice(21);
|
||||||
},
|
},
|
||||||
w: function w(wid) {
|
w: function w(wid) {
|
||||||
return 'w' + pad32(wid);
|
return 'w' + pad32(wid);
|
||||||
},
|
},
|
||||||
ww: function ww(key) {
|
ww: function ww(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
return +key.slice(1);
|
return +key.slice(1);
|
||||||
},
|
},
|
||||||
l: function l(id) {
|
l: function l(id) {
|
||||||
|
assert(typeof id === 'string');
|
||||||
return 'l' + id;
|
return 'l' + id;
|
||||||
},
|
},
|
||||||
ll: function ll(key) {
|
ll: function ll(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
return key.slice(1);
|
return key.slice(1);
|
||||||
},
|
},
|
||||||
a: function a(wid, index) {
|
a: function a(wid, index) {
|
||||||
return 'a' + pad32(wid) + pad32(index);
|
return 'a' + pad32(wid) + pad32(index);
|
||||||
},
|
},
|
||||||
i: function i(wid, name) {
|
i: function i(wid, name) {
|
||||||
|
assert(typeof name === 'string');
|
||||||
return 'i' + pad32(wid) + name;
|
return 'i' + pad32(wid) + name;
|
||||||
},
|
},
|
||||||
ii: function ii(key) {
|
ii: function ii(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
return [+key.slice(1, 11), key.slice(11)];
|
return [+key.slice(1, 11), key.slice(11)];
|
||||||
},
|
},
|
||||||
n: function n(wid, index) {
|
n: function n(wid, index) {
|
||||||
@ -62,9 +74,11 @@ layouts.walletdb = {
|
|||||||
return 'b' + pad32(height);
|
return 'b' + pad32(height);
|
||||||
},
|
},
|
||||||
bb: function bb(key) {
|
bb: function bb(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
return +key.slice(1);
|
return +key.slice(1);
|
||||||
},
|
},
|
||||||
o: function o(hash, index) {
|
o: function o(hash, index) {
|
||||||
|
assert(typeof hash === 'string');
|
||||||
return 'o' + hash + pad32(index);
|
return 'o' + hash + pad32(index);
|
||||||
},
|
},
|
||||||
oo: function oo(key) {
|
oo: function oo(key) {
|
||||||
@ -75,44 +89,56 @@ layouts.walletdb = {
|
|||||||
layouts.txdb = {
|
layouts.txdb = {
|
||||||
binary: false,
|
binary: false,
|
||||||
prefix: function prefix(wid, key) {
|
prefix: function prefix(wid, key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
return 't' + pad32(wid) + key;
|
return 't' + pad32(wid) + key;
|
||||||
},
|
},
|
||||||
pre: function prefix(key) {
|
pre: function prefix(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
return +key.slice(1, 11);
|
return +key.slice(1, 11);
|
||||||
},
|
},
|
||||||
R: 'R',
|
R: 'R',
|
||||||
hi: function hi(ch, hash, index) {
|
hi: function hi(ch, hash, index) {
|
||||||
|
assert(typeof hash === 'string');
|
||||||
return ch + hash + pad32(index);
|
return ch + hash + pad32(index);
|
||||||
},
|
},
|
||||||
hii: function hii(key) {
|
hii: function hii(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
key = key.slice(12);
|
key = key.slice(12);
|
||||||
return [key.slice(0, 64), +key.slice(64)];
|
return [key.slice(0, 64), +key.slice(64)];
|
||||||
},
|
},
|
||||||
ih: function ih(ch, index, hash) {
|
ih: function ih(ch, index, hash) {
|
||||||
|
assert(typeof hash === 'string');
|
||||||
return ch + pad32(index) + hash;
|
return ch + pad32(index) + hash;
|
||||||
},
|
},
|
||||||
ihh: function ihh(key) {
|
ihh: function ihh(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
key = key.slice(12);
|
key = key.slice(12);
|
||||||
return [+key.slice(0, 10), key.slice(10)];
|
return [+key.slice(0, 10), key.slice(10)];
|
||||||
},
|
},
|
||||||
iih: function iih(ch, index, num, hash) {
|
iih: function iih(ch, index, num, hash) {
|
||||||
|
assert(typeof hash === 'string');
|
||||||
return ch + pad32(index) + pad32(num) + hash;
|
return ch + pad32(index) + pad32(num) + hash;
|
||||||
},
|
},
|
||||||
iihh: function iihh(key) {
|
iihh: function iihh(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
key = key.slice(12);
|
key = key.slice(12);
|
||||||
return [+key.slice(0, 10), +key.slice(10, 20), key.slice(20)];
|
return [+key.slice(0, 10), +key.slice(10, 20), key.slice(20)];
|
||||||
},
|
},
|
||||||
ihi: function ihi(ch, index, hash, num) {
|
ihi: function ihi(ch, index, hash, num) {
|
||||||
|
assert(typeof hash === 'string');
|
||||||
return ch + pad32(index) + hash + pad32(num);
|
return ch + pad32(index) + hash + pad32(num);
|
||||||
},
|
},
|
||||||
ihii: function ihii(key) {
|
ihii: function ihii(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
key = key.slice(12);
|
key = key.slice(12);
|
||||||
return [+key.slice(0, 10), key.slice(10, 74), +key.slice(74)];
|
return [+key.slice(0, 10), key.slice(10, 74), +key.slice(74)];
|
||||||
},
|
},
|
||||||
ha: function ha(ch, hash) {
|
ha: function ha(ch, hash) {
|
||||||
|
assert(typeof hash === 'string');
|
||||||
return ch + hash;
|
return ch + hash;
|
||||||
},
|
},
|
||||||
haa: function haa(key) {
|
haa: function haa(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
key = key.slice(12);
|
key = key.slice(12);
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
@ -201,6 +227,7 @@ layouts.txdb = {
|
|||||||
return 'b' + pad32(height);
|
return 'b' + pad32(height);
|
||||||
},
|
},
|
||||||
bb: function bb(key) {
|
bb: function bb(key) {
|
||||||
|
assert(typeof key === 'string');
|
||||||
key = key.slice(12);
|
key = key.slice(12);
|
||||||
return +key.slice(0);
|
return +key.slice(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
const assert = require('assert');
|
||||||
const layouts = exports;
|
const layouts = exports;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -29,25 +30,35 @@ layouts.walletdb = {
|
|||||||
binary: true,
|
binary: true,
|
||||||
p: function p(hash) {
|
p: function p(hash) {
|
||||||
let key = Buffer.allocUnsafe(1 + (hash.length / 2));
|
let key = Buffer.allocUnsafe(1 + (hash.length / 2));
|
||||||
|
assert(typeof hash === 'string');
|
||||||
key[0] = 0x70;
|
key[0] = 0x70;
|
||||||
key.write(hash, 1, 'hex');
|
key.write(hash, 1, 'hex');
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
pp: function pp(key) {
|
pp: function pp(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length >= 21);
|
||||||
return key.toString('hex', 1);
|
return key.toString('hex', 1);
|
||||||
},
|
},
|
||||||
P: function P(wid, hash) {
|
P: function P(wid, hash) {
|
||||||
let key = Buffer.allocUnsafe(1 + 4 + (hash.length / 2));
|
let key = Buffer.allocUnsafe(1 + 4 + (hash.length / 2));
|
||||||
|
assert(typeof wid === 'number');
|
||||||
|
assert(typeof hash === 'string');
|
||||||
key[0] = 0x50;
|
key[0] = 0x50;
|
||||||
key.writeUInt32BE(wid, 1, true);
|
key.writeUInt32BE(wid, 1, true);
|
||||||
key.write(hash, 5, 'hex');
|
key.write(hash, 5, 'hex');
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
Pp: function Pp(key) {
|
Pp: function Pp(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length >= 25);
|
||||||
return key.toString('hex', 5);
|
return key.toString('hex', 5);
|
||||||
},
|
},
|
||||||
r: function r(wid, index, hash) {
|
r: function r(wid, index, hash) {
|
||||||
let key = Buffer.allocUnsafe(1 + 4 + 4 + (hash.length / 2));
|
let key = Buffer.allocUnsafe(1 + 4 + 4 + (hash.length / 2));
|
||||||
|
assert(typeof wid === 'number');
|
||||||
|
assert(typeof index === 'number');
|
||||||
|
assert(typeof hash === 'string');
|
||||||
key[0] = 0x72;
|
key[0] = 0x72;
|
||||||
key.writeUInt32BE(wid, 1, true);
|
key.writeUInt32BE(wid, 1, true);
|
||||||
key.writeUInt32BE(index, 5, true);
|
key.writeUInt32BE(index, 5, true);
|
||||||
@ -55,30 +66,40 @@ layouts.walletdb = {
|
|||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
rr: function rr(key) {
|
rr: function rr(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length >= 29);
|
||||||
return key.toString('hex', 9);
|
return key.toString('hex', 9);
|
||||||
},
|
},
|
||||||
w: function w(wid) {
|
w: function w(wid) {
|
||||||
let key = Buffer.allocUnsafe(5);
|
let key = Buffer.allocUnsafe(5);
|
||||||
|
assert(typeof wid === 'number');
|
||||||
key[0] = 0x77;
|
key[0] = 0x77;
|
||||||
key.writeUInt32BE(wid, 1, true);
|
key.writeUInt32BE(wid, 1, true);
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
ww: function ww(key) {
|
ww: function ww(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length === 5);
|
||||||
return key.readUInt32BE(1, true);
|
return key.readUInt32BE(1, true);
|
||||||
},
|
},
|
||||||
l: function l(id) {
|
l: function l(id) {
|
||||||
let len = Buffer.byteLength(id, 'ascii');
|
let len = Buffer.byteLength(id, 'ascii');
|
||||||
let key = Buffer.allocUnsafe(1 + len);
|
let key = Buffer.allocUnsafe(1 + len);
|
||||||
|
assert(typeof id === 'string');
|
||||||
key[0] = 0x6c;
|
key[0] = 0x6c;
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
key.write(id, 1, 'ascii');
|
key.write(id, 1, 'ascii');
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
ll: function ll(key) {
|
ll: function ll(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length >= 1);
|
||||||
return key.toString('ascii', 1);
|
return key.toString('ascii', 1);
|
||||||
},
|
},
|
||||||
a: function a(wid, index) {
|
a: function a(wid, index) {
|
||||||
let key = Buffer.allocUnsafe(9);
|
let key = Buffer.allocUnsafe(9);
|
||||||
|
assert(typeof wid === 'number');
|
||||||
|
assert(typeof index === 'number');
|
||||||
key[0] = 0x61;
|
key[0] = 0x61;
|
||||||
key.writeUInt32BE(wid, 1, true);
|
key.writeUInt32BE(wid, 1, true);
|
||||||
key.writeUInt32BE(index, 5, true);
|
key.writeUInt32BE(index, 5, true);
|
||||||
@ -87,6 +108,8 @@ layouts.walletdb = {
|
|||||||
i: function i(wid, name) {
|
i: function i(wid, name) {
|
||||||
let len = Buffer.byteLength(name, 'ascii');
|
let len = Buffer.byteLength(name, 'ascii');
|
||||||
let key = Buffer.allocUnsafe(5 + len);
|
let key = Buffer.allocUnsafe(5 + len);
|
||||||
|
assert(typeof wid === 'number');
|
||||||
|
assert(typeof name === 'string');
|
||||||
key[0] = 0x69;
|
key[0] = 0x69;
|
||||||
key.writeUInt32BE(wid, 1, true);
|
key.writeUInt32BE(wid, 1, true);
|
||||||
if (len > 0)
|
if (len > 0)
|
||||||
@ -94,10 +117,14 @@ layouts.walletdb = {
|
|||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
ii: function ii(key) {
|
ii: function ii(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length >= 5);
|
||||||
return [key.readUInt32BE(1, true), key.toString('ascii', 5)];
|
return [key.readUInt32BE(1, true), key.toString('ascii', 5)];
|
||||||
},
|
},
|
||||||
n: function n(wid, index) {
|
n: function n(wid, index) {
|
||||||
let key = Buffer.allocUnsafe(9);
|
let key = Buffer.allocUnsafe(9);
|
||||||
|
assert(typeof wid === 'number');
|
||||||
|
assert(typeof index === 'number');
|
||||||
key[0] = 0x6e;
|
key[0] = 0x6e;
|
||||||
key.writeUInt32BE(wid, 1, true);
|
key.writeUInt32BE(wid, 1, true);
|
||||||
key.writeUInt32BE(index, 5, true);
|
key.writeUInt32BE(index, 5, true);
|
||||||
@ -106,27 +133,35 @@ layouts.walletdb = {
|
|||||||
R: Buffer.from([0x52]),
|
R: Buffer.from([0x52]),
|
||||||
h: function h(height) {
|
h: function h(height) {
|
||||||
let key = Buffer.allocUnsafe(5);
|
let key = Buffer.allocUnsafe(5);
|
||||||
|
assert(typeof height === 'number');
|
||||||
key[0] = 0x68;
|
key[0] = 0x68;
|
||||||
key.writeUInt32BE(height, 1, true);
|
key.writeUInt32BE(height, 1, true);
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
b: function b(height) {
|
b: function b(height) {
|
||||||
let key = Buffer.allocUnsafe(5);
|
let key = Buffer.allocUnsafe(5);
|
||||||
|
assert(typeof height === 'number');
|
||||||
key[0] = 0x62;
|
key[0] = 0x62;
|
||||||
key.writeUInt32BE(height, 1, true);
|
key.writeUInt32BE(height, 1, true);
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
bb: function bb(key) {
|
bb: function bb(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length === 5);
|
||||||
return key.readUInt32BE(1, true);
|
return key.readUInt32BE(1, true);
|
||||||
},
|
},
|
||||||
o: function o(hash, index) {
|
o: function o(hash, index) {
|
||||||
let key = Buffer.allocUnsafe(37);
|
let key = Buffer.allocUnsafe(37);
|
||||||
|
assert(typeof hash === 'string');
|
||||||
|
assert(typeof index === 'number');
|
||||||
key[0] = 0x6f;
|
key[0] = 0x6f;
|
||||||
key.write(hash, 1, 'hex');
|
key.write(hash, 1, 'hex');
|
||||||
key.writeUInt32BE(index, 33, true);
|
key.writeUInt32BE(index, 33, true);
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
oo: function oo(key) {
|
oo: function oo(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length === 37);
|
||||||
return [key.toString('hex', 1, 33), key.readUInt32BE(33, true)];
|
return [key.toString('hex', 1, 33), key.readUInt32BE(33, true)];
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -153,39 +188,54 @@ layouts.txdb = {
|
|||||||
binary: true,
|
binary: true,
|
||||||
prefix: function prefix(wid, key) {
|
prefix: function prefix(wid, key) {
|
||||||
let out = Buffer.allocUnsafe(5 + key.length);
|
let out = Buffer.allocUnsafe(5 + key.length);
|
||||||
|
assert(typeof wid === 'number');
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
out[0] = 0x74;
|
out[0] = 0x74;
|
||||||
out.writeUInt32BE(wid, 1);
|
out.writeUInt32BE(wid, 1);
|
||||||
key.copy(out, 5);
|
key.copy(out, 5);
|
||||||
return out;
|
return out;
|
||||||
},
|
},
|
||||||
pre: function prefix(key) {
|
pre: function prefix(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length >= 5);
|
||||||
return key.readUInt32BE(1, true);
|
return key.readUInt32BE(1, true);
|
||||||
},
|
},
|
||||||
R: Buffer.from([0x52]),
|
R: Buffer.from([0x52]),
|
||||||
hi: function hi(ch, hash, index) {
|
hi: function hi(ch, hash, index) {
|
||||||
let key = Buffer.allocUnsafe(37);
|
let key = Buffer.allocUnsafe(37);
|
||||||
|
assert(typeof hash === 'string');
|
||||||
|
assert(typeof index === 'number');
|
||||||
key[0] = ch;
|
key[0] = ch;
|
||||||
key.write(hash, 1, 'hex');
|
key.write(hash, 1, 'hex');
|
||||||
key.writeUInt32BE(index, 33, true);
|
key.writeUInt32BE(index, 33, true);
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
hii: function hii(key) {
|
hii: function hii(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length - 5 === 37);
|
||||||
key = key.slice(6);
|
key = key.slice(6);
|
||||||
return [key.toString('hex', 0, 32), key.readUInt32BE(32, true)];
|
return [key.toString('hex', 0, 32), key.readUInt32BE(32, true)];
|
||||||
},
|
},
|
||||||
ih: function ih(ch, index, hash) {
|
ih: function ih(ch, index, hash) {
|
||||||
let key = Buffer.allocUnsafe(37);
|
let key = Buffer.allocUnsafe(37);
|
||||||
|
assert(typeof index === 'number');
|
||||||
|
assert(typeof hash === 'string');
|
||||||
key[0] = ch;
|
key[0] = ch;
|
||||||
key.writeUInt32BE(index, 1, true);
|
key.writeUInt32BE(index, 1, true);
|
||||||
key.write(hash, 5, 'hex');
|
key.write(hash, 5, 'hex');
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
ihh: function ihh(key) {
|
ihh: function ihh(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length - 5 === 37);
|
||||||
key = key.slice(6);
|
key = key.slice(6);
|
||||||
return [key.readUInt32BE(0, true), key.toString('hex', 4, 36)];
|
return [key.readUInt32BE(0, true), key.toString('hex', 4, 36)];
|
||||||
},
|
},
|
||||||
iih: function iih(ch, index, num, hash) {
|
iih: function iih(ch, index, num, hash) {
|
||||||
let key = Buffer.allocUnsafe(41);
|
let key = Buffer.allocUnsafe(41);
|
||||||
|
assert(typeof index === 'number');
|
||||||
|
assert(typeof num === 'number');
|
||||||
|
assert(typeof hash === 'string');
|
||||||
key[0] = ch;
|
key[0] = ch;
|
||||||
key.writeUInt32BE(index, 1, true);
|
key.writeUInt32BE(index, 1, true);
|
||||||
key.writeUInt32BE(num, 5, true);
|
key.writeUInt32BE(num, 5, true);
|
||||||
@ -193,6 +243,8 @@ layouts.txdb = {
|
|||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
iihh: function iihh(key) {
|
iihh: function iihh(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length - 5 === 41);
|
||||||
key = key.slice(6);
|
key = key.slice(6);
|
||||||
return [
|
return [
|
||||||
key.readUInt32BE(0, true),
|
key.readUInt32BE(0, true),
|
||||||
@ -202,6 +254,9 @@ layouts.txdb = {
|
|||||||
},
|
},
|
||||||
ihi: function ihi(ch, index, hash, num) {
|
ihi: function ihi(ch, index, hash, num) {
|
||||||
let key = Buffer.allocUnsafe(41);
|
let key = Buffer.allocUnsafe(41);
|
||||||
|
assert(typeof index === 'number');
|
||||||
|
assert(typeof hash === 'string');
|
||||||
|
assert(typeof num === 'number');
|
||||||
key[0] = ch;
|
key[0] = ch;
|
||||||
key.writeUInt32BE(index, 1, true);
|
key.writeUInt32BE(index, 1, true);
|
||||||
key.write(hash, 5, 'hex');
|
key.write(hash, 5, 'hex');
|
||||||
@ -209,6 +264,8 @@ layouts.txdb = {
|
|||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
ihii: function ihii(key) {
|
ihii: function ihii(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length - 5 === 41);
|
||||||
key = key.slice(6);
|
key = key.slice(6);
|
||||||
return [
|
return [
|
||||||
key.readUInt32BE(0, true),
|
key.readUInt32BE(0, true),
|
||||||
@ -218,11 +275,14 @@ layouts.txdb = {
|
|||||||
},
|
},
|
||||||
ha: function ha(ch, hash) {
|
ha: function ha(ch, hash) {
|
||||||
let key = Buffer.allocUnsafe(33);
|
let key = Buffer.allocUnsafe(33);
|
||||||
|
assert(typeof hash === 'string');
|
||||||
key[0] = ch;
|
key[0] = ch;
|
||||||
key.write(hash, 1, 'hex');
|
key.write(hash, 1, 'hex');
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
haa: function haa(key) {
|
haa: function haa(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length - 5 === 33);
|
||||||
key = key.slice(6);
|
key = key.slice(6);
|
||||||
return key.toString('hex', 0);
|
return key.toString('hex', 0);
|
||||||
},
|
},
|
||||||
@ -303,11 +363,14 @@ layouts.txdb = {
|
|||||||
},
|
},
|
||||||
b: function b(height) {
|
b: function b(height) {
|
||||||
let key = Buffer.allocUnsafe(5);
|
let key = Buffer.allocUnsafe(5);
|
||||||
|
assert(typeof height === 'number');
|
||||||
key[0] = 0x62;
|
key[0] = 0x62;
|
||||||
key.writeUInt32BE(height, 1, true);
|
key.writeUInt32BE(height, 1, true);
|
||||||
return key;
|
return key;
|
||||||
},
|
},
|
||||||
bb: function bb(key) {
|
bb: function bb(key) {
|
||||||
|
assert(Buffer.isBuffer(key));
|
||||||
|
assert(key.length - 5 === 5);
|
||||||
key = key.slice(6);
|
key = key.slice(6);
|
||||||
return key.readUInt32BE(0, true);
|
return key.readUInt32BE(0, true);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user