wallet: fix layout style.

This commit is contained in:
Christopher Jeffrey 2017-07-31 18:59:25 -07:00
parent f58feb0035
commit 1f38f36077
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD

View File

@ -29,8 +29,8 @@ const layouts = exports;
layouts.walletdb = {
binary: true,
p: function p(hash) {
const key = Buffer.allocUnsafe(1 + (hash.length / 2));
assert(typeof hash === 'string');
const key = Buffer.allocUnsafe(1 + (hash.length / 2));
key[0] = 0x70;
key.write(hash, 1, 'hex');
return key;
@ -41,9 +41,9 @@ layouts.walletdb = {
return key.toString('hex', 1);
},
P: function P(wid, hash) {
const key = Buffer.allocUnsafe(1 + 4 + (hash.length / 2));
assert(typeof wid === 'number');
assert(typeof hash === 'string');
const key = Buffer.allocUnsafe(1 + 4 + (hash.length / 2));
key[0] = 0x50;
key.writeUInt32BE(wid, 1, true);
key.write(hash, 5, 'hex');
@ -55,10 +55,10 @@ layouts.walletdb = {
return key.toString('hex', 5);
},
r: function r(wid, index, hash) {
const key = Buffer.allocUnsafe(1 + 4 + 4 + (hash.length / 2));
assert(typeof wid === 'number');
assert(typeof index === 'number');
assert(typeof hash === 'string');
const key = Buffer.allocUnsafe(1 + 4 + 4 + (hash.length / 2));
key[0] = 0x72;
key.writeUInt32BE(wid, 1, true);
key.writeUInt32BE(index, 5, true);
@ -71,8 +71,8 @@ layouts.walletdb = {
return key.toString('hex', 9);
},
w: function w(wid) {
const key = Buffer.allocUnsafe(5);
assert(typeof wid === 'number');
const key = Buffer.allocUnsafe(5);
key[0] = 0x77;
key.writeUInt32BE(wid, 1, true);
return key;
@ -83,9 +83,9 @@ layouts.walletdb = {
return key.readUInt32BE(1, true);
},
l: function l(id) {
assert(typeof id === 'string');
const len = Buffer.byteLength(id, 'ascii');
const key = Buffer.allocUnsafe(1 + len);
assert(typeof id === 'string');
key[0] = 0x6c;
if (len > 0)
key.write(id, 1, 'ascii');
@ -97,19 +97,19 @@ layouts.walletdb = {
return key.toString('ascii', 1);
},
a: function a(wid, index) {
const key = Buffer.allocUnsafe(9);
assert(typeof wid === 'number');
assert(typeof index === 'number');
const key = Buffer.allocUnsafe(9);
key[0] = 0x61;
key.writeUInt32BE(wid, 1, true);
key.writeUInt32BE(index, 5, true);
return key;
},
i: function i(wid, name) {
const len = Buffer.byteLength(name, 'ascii');
const key = Buffer.allocUnsafe(5 + len);
assert(typeof wid === 'number');
assert(typeof name === 'string');
const len = Buffer.byteLength(name, 'ascii');
const key = Buffer.allocUnsafe(5 + len);
key[0] = 0x69;
key.writeUInt32BE(wid, 1, true);
if (len > 0)
@ -122,9 +122,9 @@ layouts.walletdb = {
return [key.readUInt32BE(1, true), key.toString('ascii', 5)];
},
n: function n(wid, index) {
const key = Buffer.allocUnsafe(9);
assert(typeof wid === 'number');
assert(typeof index === 'number');
const key = Buffer.allocUnsafe(9);
key[0] = 0x6e;
key.writeUInt32BE(wid, 1, true);
key.writeUInt32BE(index, 5, true);
@ -132,15 +132,15 @@ layouts.walletdb = {
},
R: Buffer.from([0x52]),
h: function h(height) {
const key = Buffer.allocUnsafe(5);
assert(typeof height === 'number');
const key = Buffer.allocUnsafe(5);
key[0] = 0x68;
key.writeUInt32BE(height, 1, true);
return key;
},
b: function b(height) {
const key = Buffer.allocUnsafe(5);
assert(typeof height === 'number');
const key = Buffer.allocUnsafe(5);
key[0] = 0x62;
key.writeUInt32BE(height, 1, true);
return key;
@ -151,9 +151,9 @@ layouts.walletdb = {
return key.readUInt32BE(1, true);
},
o: function o(hash, index) {
const key = Buffer.allocUnsafe(37);
assert(typeof hash === 'string');
assert(typeof index === 'number');
const key = Buffer.allocUnsafe(37);
key[0] = 0x6f;
key.write(hash, 1, 'hex');
key.writeUInt32BE(index, 33, true);
@ -187,9 +187,9 @@ layouts.walletdb = {
layouts.txdb = {
binary: true,
prefix: function prefix(wid, key) {
const out = Buffer.allocUnsafe(5 + key.length);
assert(typeof wid === 'number');
assert(Buffer.isBuffer(key));
const out = Buffer.allocUnsafe(5 + key.length);
out[0] = 0x74;
out.writeUInt32BE(wid, 1);
key.copy(out, 5);
@ -202,9 +202,9 @@ layouts.txdb = {
},
R: Buffer.from([0x52]),
hi: function hi(ch, hash, index) {
const key = Buffer.allocUnsafe(37);
assert(typeof hash === 'string');
assert(typeof index === 'number');
const key = Buffer.allocUnsafe(37);
key[0] = ch;
key.write(hash, 1, 'hex');
key.writeUInt32BE(index, 33, true);
@ -217,9 +217,9 @@ layouts.txdb = {
return [key.toString('hex', 0, 32), key.readUInt32BE(32, true)];
},
ih: function ih(ch, index, hash) {
const key = Buffer.allocUnsafe(37);
assert(typeof index === 'number');
assert(typeof hash === 'string');
const key = Buffer.allocUnsafe(37);
key[0] = ch;
key.writeUInt32BE(index, 1, true);
key.write(hash, 5, 'hex');
@ -232,10 +232,10 @@ layouts.txdb = {
return [key.readUInt32BE(0, true), key.toString('hex', 4, 36)];
},
iih: function iih(ch, index, num, hash) {
const key = Buffer.allocUnsafe(41);
assert(typeof index === 'number');
assert(typeof num === 'number');
assert(typeof hash === 'string');
const key = Buffer.allocUnsafe(41);
key[0] = ch;
key.writeUInt32BE(index, 1, true);
key.writeUInt32BE(num, 5, true);
@ -253,10 +253,10 @@ layouts.txdb = {
];
},
ihi: function ihi(ch, index, hash, num) {
const key = Buffer.allocUnsafe(41);
assert(typeof index === 'number');
assert(typeof hash === 'string');
assert(typeof num === 'number');
const key = Buffer.allocUnsafe(41);
key[0] = ch;
key.writeUInt32BE(index, 1, true);
key.write(hash, 5, 'hex');
@ -274,8 +274,8 @@ layouts.txdb = {
];
},
ha: function ha(ch, hash) {
const key = Buffer.allocUnsafe(33);
assert(typeof hash === 'string');
const key = Buffer.allocUnsafe(33);
key[0] = ch;
key.write(hash, 1, 'hex');
return key;
@ -362,8 +362,8 @@ layouts.txdb = {
return this.ha(0x72, hash);
},
b: function b(height) {
const key = Buffer.allocUnsafe(5);
assert(typeof height === 'number');
const key = Buffer.allocUnsafe(5);
key[0] = 0x62;
key.writeUInt32BE(height, 1, true);
return key;