refactor.
This commit is contained in:
parent
a019e9cfc7
commit
6136434959
@ -24,10 +24,10 @@ module.exports = function ldb(name, options) {
|
|||||||
if (bcoin.isBrowser) {
|
if (bcoin.isBrowser) {
|
||||||
backend = require('level-js');
|
backend = require('level-js');
|
||||||
} else {
|
} else {
|
||||||
if (!backend || backend === 'rocksdb')
|
if (!backend || backend === 'leveldb')
|
||||||
backend = 'rocksdown';
|
|
||||||
else if (backend === 'leveldb')
|
|
||||||
backend = 'leveldown';
|
backend = 'leveldown';
|
||||||
|
else if (backend === 'rocksdb')
|
||||||
|
backend = 'rocksdown';
|
||||||
else if (backend === 'lmdb')
|
else if (backend === 'lmdb')
|
||||||
backend = 'lmdb';
|
backend = 'lmdb';
|
||||||
|
|
||||||
@ -52,7 +52,8 @@ module.exports = function ldb(name, options) {
|
|||||||
writeMap: options.writeMap || false,
|
writeMap: options.writeMap || false,
|
||||||
|
|
||||||
// For RocksDB
|
// For RocksDB
|
||||||
memtableBudget: 512 << 20,
|
// optimizeCompaction: 'level',
|
||||||
|
// memtableBudget: 512 << 20,
|
||||||
|
|
||||||
db: backend
|
db: backend
|
||||||
});
|
});
|
||||||
|
|||||||
@ -18,6 +18,7 @@ var constants = bcoin.protocol.constants;
|
|||||||
|
|
||||||
function Pool(node, options) {
|
function Pool(node, options) {
|
||||||
var self = this;
|
var self = this;
|
||||||
|
var seeds;
|
||||||
|
|
||||||
if (!(this instanceof Pool))
|
if (!(this instanceof Pool))
|
||||||
return new Pool(node, options);
|
return new Pool(node, options);
|
||||||
@ -28,6 +29,7 @@ function Pool(node, options) {
|
|||||||
options = {};
|
options = {};
|
||||||
|
|
||||||
this.options = options;
|
this.options = options;
|
||||||
|
this.network = node.network;
|
||||||
|
|
||||||
options.spv = options.spv !== false;
|
options.spv = options.spv !== false;
|
||||||
|
|
||||||
@ -41,8 +43,12 @@ function Pool(node, options) {
|
|||||||
? (!options.spv ? true : false)
|
? (!options.spv ? true : false)
|
||||||
: options.relay;
|
: options.relay;
|
||||||
|
|
||||||
this.network = node.network;
|
seeds = (options.seeds || network.seeds).slice();
|
||||||
this.originalSeeds = (options.seeds || network.seeds).map(utils.parseHost);
|
|
||||||
|
if (process.env.BCOIN_SEED)
|
||||||
|
seeds.unshift(process.env.BCOIN_SEED);
|
||||||
|
|
||||||
|
this.originalSeeds = seeds.map(utils.parseHost);
|
||||||
this.setSeeds([]);
|
this.setSeeds([]);
|
||||||
|
|
||||||
this.server = null;
|
this.server = null;
|
||||||
|
|||||||
@ -111,11 +111,7 @@ main.genesis = {
|
|||||||
hash: utils.revHex(
|
hash: utils.revHex(
|
||||||
'000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'
|
'000000000019d6689c085ae165831e934ff763ae46a2a6c172b3f1b60a8ce26f'
|
||||||
),
|
),
|
||||||
prevBlock: utils.toHex(
|
prevBlock: '0000000000000000000000000000000000000000000000000000000000000000',
|
||||||
[ 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0 ]),
|
|
||||||
merkleRoot: utils.revHex(
|
merkleRoot: utils.revHex(
|
||||||
'4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'
|
'4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'
|
||||||
),
|
),
|
||||||
@ -234,11 +230,7 @@ testnet.genesis = {
|
|||||||
hash: utils.revHex(
|
hash: utils.revHex(
|
||||||
'000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943'
|
'000000000933ea01ad0ee984209779baaec3ced90fa3f408719526f8d77f4943'
|
||||||
),
|
),
|
||||||
prevBlock: utils.toHex(
|
prevBlock: '0000000000000000000000000000000000000000000000000000000000000000',
|
||||||
[ 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0 ]),
|
|
||||||
merkleRoot: utils.revHex(
|
merkleRoot: utils.revHex(
|
||||||
'4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'
|
'4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'
|
||||||
),
|
),
|
||||||
@ -339,11 +331,7 @@ regtest.genesis = {
|
|||||||
hash: utils.revHex(
|
hash: utils.revHex(
|
||||||
'0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206'
|
'0f9188f13cb7b2c71f2a335e3a4fc328bf5beb436012afca590b1a11466e2206'
|
||||||
),
|
),
|
||||||
prevBlock: utils.toHex(
|
prevBlock: '0000000000000000000000000000000000000000000000000000000000000000',
|
||||||
[ 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0 ]),
|
|
||||||
merkleRoot: utils.revHex(
|
merkleRoot: utils.revHex(
|
||||||
'4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'
|
'4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'
|
||||||
),
|
),
|
||||||
@ -457,11 +445,7 @@ segnet.genesis = {
|
|||||||
hash: utils.revHex(
|
hash: utils.revHex(
|
||||||
'0d5b9c518ddf053fcac71730830df4526a9949c08f34acf6a1d30464d22f02aa'
|
'0d5b9c518ddf053fcac71730830df4526a9949c08f34acf6a1d30464d22f02aa'
|
||||||
),
|
),
|
||||||
prevBlock: utils.toHex(
|
prevBlock: '0000000000000000000000000000000000000000000000000000000000000000',
|
||||||
[ 0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
|
||||||
0, 0, 0, 0, 0, 0, 0, 0 ]),
|
|
||||||
merkleRoot: utils.revHex(
|
merkleRoot: utils.revHex(
|
||||||
'4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'
|
'4a5e1e4baab89f3a32518a88c31bc87f618f76673e2cc77ab2127b7afdeda33b'
|
||||||
),
|
),
|
||||||
|
|||||||
@ -2473,6 +2473,8 @@ Script.decode = function decode(buf) {
|
|||||||
// script parsing was originally non-strict/ridiculous.
|
// script parsing was originally non-strict/ridiculous.
|
||||||
// Something could do a direct push of 30 bytes with
|
// Something could do a direct push of 30 bytes with
|
||||||
// only 20 bytes after it.
|
// only 20 bytes after it.
|
||||||
|
// NOTE 2: We use reference Buffer slices here. Larger
|
||||||
|
// buffer slices should _never_ be passed in here.
|
||||||
while (off < buf.length) {
|
while (off < buf.length) {
|
||||||
b = buf[off++];
|
b = buf[off++];
|
||||||
|
|
||||||
@ -2485,7 +2487,7 @@ Script.decode = function decode(buf) {
|
|||||||
// Direct Push
|
// Direct Push
|
||||||
// Next `b` bytes should be pushed to stack
|
// Next `b` bytes should be pushed to stack
|
||||||
if (b >= 0x01 && b <= 0x4b) {
|
if (b >= 0x01 && b <= 0x4b) {
|
||||||
code.push(utils.slice(buf, off, off + b));
|
code.push(buf.slice(off, off + b));
|
||||||
off += b;
|
off += b;
|
||||||
utils.hidden(code[code.length - 1], 'pushdata', {
|
utils.hidden(code[code.length - 1], 'pushdata', {
|
||||||
opcode: null,
|
opcode: null,
|
||||||
@ -2512,7 +2514,7 @@ Script.decode = function decode(buf) {
|
|||||||
if (opcode === 'pushdata1') {
|
if (opcode === 'pushdata1') {
|
||||||
len = buf[off];
|
len = buf[off];
|
||||||
off += 1;
|
off += 1;
|
||||||
code.push(utils.slice(buf, off, off + len));
|
code.push(buf.slice(off, off + len));
|
||||||
off += len;
|
off += len;
|
||||||
utils.hidden(code[code.length - 1], 'pushdata', {
|
utils.hidden(code[code.length - 1], 'pushdata', {
|
||||||
opcode: opcode,
|
opcode: opcode,
|
||||||
@ -2521,7 +2523,7 @@ Script.decode = function decode(buf) {
|
|||||||
} else if (opcode === 'pushdata2') {
|
} else if (opcode === 'pushdata2') {
|
||||||
len = utils.readU16(buf, off);
|
len = utils.readU16(buf, off);
|
||||||
off += 2;
|
off += 2;
|
||||||
code.push(utils.slice(buf, off, off + len));
|
code.push(buf.slice(off, off + len));
|
||||||
off += len;
|
off += len;
|
||||||
utils.hidden(code[code.length - 1], 'pushdata', {
|
utils.hidden(code[code.length - 1], 'pushdata', {
|
||||||
opcode: opcode,
|
opcode: opcode,
|
||||||
@ -2530,7 +2532,7 @@ Script.decode = function decode(buf) {
|
|||||||
} else if (opcode === 'pushdata4') {
|
} else if (opcode === 'pushdata4') {
|
||||||
len = utils.readU32(buf, off);
|
len = utils.readU32(buf, off);
|
||||||
off += 4;
|
off += 4;
|
||||||
code.push(utils.slice(buf, off, off + len));
|
code.push(buf.slice(off, off + len));
|
||||||
off += len;
|
off += len;
|
||||||
utils.hidden(code[code.length - 1], 'pushdata', {
|
utils.hidden(code[code.length - 1], 'pushdata', {
|
||||||
opcode: opcode,
|
opcode: opcode,
|
||||||
|
|||||||
@ -28,7 +28,8 @@ utils.nop = function() {};
|
|||||||
utils.slice = function slice(buf, start, end) {
|
utils.slice = function slice(buf, start, end) {
|
||||||
var clone;
|
var clone;
|
||||||
|
|
||||||
buf = buf.slice(start || 0, end || buf.length);
|
if (start != null)
|
||||||
|
buf = buf.slice(start, end);
|
||||||
|
|
||||||
clone = new Buffer(buf.length);
|
clone = new Buffer(buf.length);
|
||||||
|
|
||||||
@ -61,18 +62,18 @@ utils.toBuffer = function toBuffer(msg, enc) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
utils.toArray = function toArray(msg, enc) {
|
utils.toArray = function toArray(msg, enc) {
|
||||||
|
var res = [];
|
||||||
|
var i, c, hi, lo, slice, num;
|
||||||
|
|
||||||
|
if (!msg)
|
||||||
|
return res;
|
||||||
|
|
||||||
if (Buffer.isBuffer(msg))
|
if (Buffer.isBuffer(msg))
|
||||||
return Array.prototype.slice.call(msg);
|
return Array.prototype.slice.call(msg);
|
||||||
|
|
||||||
if (Array.isArray(msg))
|
if (Array.isArray(msg))
|
||||||
return msg.slice();
|
return msg.slice();
|
||||||
|
|
||||||
if (!msg)
|
|
||||||
return [];
|
|
||||||
|
|
||||||
var res = [];
|
|
||||||
var i, c, hi, lo, slice, num;
|
|
||||||
|
|
||||||
if (typeof msg === 'string') {
|
if (typeof msg === 'string') {
|
||||||
if (!enc) {
|
if (!enc) {
|
||||||
for (i = 0; i < msg.length; i++) {
|
for (i = 0; i < msg.length; i++) {
|
||||||
@ -165,6 +166,7 @@ utils.fromBase58 = function fromBase58(str) {
|
|||||||
for (i = 0; i < str.length; i++)
|
for (i = 0; i < str.length; i++)
|
||||||
if (str[i] !== '1')
|
if (str[i] !== '1')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
zeroes = i;
|
zeroes = i;
|
||||||
|
|
||||||
// Read 4-char words and add them to bignum
|
// Read 4-char words and add them to bignum
|
||||||
@ -374,7 +376,7 @@ utils.toHex = function toHex(msg) {
|
|||||||
if (typeof msg === 'string')
|
if (typeof msg === 'string')
|
||||||
return msg;
|
return msg;
|
||||||
|
|
||||||
return new Buffer(msg).toString('hex');
|
return msg.toString('hex');
|
||||||
};
|
};
|
||||||
|
|
||||||
utils.isHex = function isHex(msg) {
|
utils.isHex = function isHex(msg) {
|
||||||
@ -611,22 +613,14 @@ utils.isSatoshi = function isSatoshi(val) {
|
|||||||
return val;
|
return val;
|
||||||
if (utils.isInt(val))
|
if (utils.isInt(val))
|
||||||
return new bn(val, 10);
|
return new bn(val, 10);
|
||||||
if (utils.isHex(val))
|
|
||||||
return new bn(val, 'hex');
|
|
||||||
if (Buffer.isBuffer(val))
|
if (Buffer.isBuffer(val))
|
||||||
return new bn(val);
|
return new bn(val);
|
||||||
if (Array.isArray(val))
|
|
||||||
return new bn(val);
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
utils.isBTC = function isBTC(val) {
|
utils.isBTC = function isBTC(val) {
|
||||||
if (utils.isFloat(val))
|
if (utils.isFloat(val))
|
||||||
return val;
|
return val;
|
||||||
// For user input strings. Might cause overlap
|
|
||||||
// with isSatoshi if not used carefully.
|
|
||||||
// if (utils.isInt(val))
|
|
||||||
// return val;
|
|
||||||
return false;
|
return false;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -680,12 +674,13 @@ utils.ip2version = function ip2version(ip, version) {
|
|||||||
// Check to see if this an
|
// Check to see if this an
|
||||||
// ipv4-mapped ipv6 address.
|
// ipv4-mapped ipv6 address.
|
||||||
if (ip.length > 4) {
|
if (ip.length > 4) {
|
||||||
while (ip[0] === 0)
|
i = 0;
|
||||||
ip = ip.slice(1);
|
while (ip[i] === 0)
|
||||||
|
i++;
|
||||||
|
|
||||||
// Found an ipv4 address
|
// Found an ipv4 address
|
||||||
if (ip.length === 6 && ip[0] === 0xff && ip[1] === 0xff)
|
if (ip.length - i === 6 && ip[i] === 0xff && ip[i + 1] === 0xff)
|
||||||
return ip.slice(-4);
|
return utils.slice(ip, -4);
|
||||||
|
|
||||||
// No ipv4 address
|
// No ipv4 address
|
||||||
return new Buffer([0, 0, 0, 0]);
|
return new Buffer([0, 0, 0, 0]);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user