pkg: update deps.

This commit is contained in:
Christopher Jeffrey 2018-03-12 14:53:53 -07:00
parent 319ec82997
commit c388498ab0
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
15 changed files with 45 additions and 1096 deletions

View File

@ -12,12 +12,12 @@ const path = require('path');
const AsyncEmitter = require('bevent');
const Logger = require('blgr');
const {Lock} = require('bmutex');
const LRU = require('blru');
const Network = require('../protocol/network');
const ChainDB = require('./chaindb');
const common = require('./common');
const consensus = require('../protocol/consensus');
const util = require('../utils/util');
const LRU = require('../utils/lru');
const ChainEntry = require('./chainentry');
const CoinView = require('../coins/coinview');
const Script = require('../script/script');

View File

@ -10,12 +10,12 @@
const assert = require('assert');
const bdb = require('bdb');
const bio = require('bufio');
const LRU = require('blru');
const Amount = require('../btc/amount');
const Network = require('../protocol/network');
const CoinView = require('../coins/coinview');
const UndoCoins = require('../coins/undocoins');
const layout = require('./layout');
const LRU = require('../utils/lru');
const util = require('../utils/util');
const consensus = require('../protocol/consensus');
const Block = require('../primitives/block');

View File

@ -7,7 +7,7 @@
'use strict';
const assert = require('assert');
const LRU = require('../utils/lru');
const LRU = require('blru');
const common = exports;
/**

View File

@ -11,6 +11,7 @@ const path = require('path');
const EventEmitter = require('events');
const bdb = require('bdb');
const {RollingFilter} = require('bfilter');
const Heap = require('bheep');
const common = require('../blockchain/common');
const consensus = require('../protocol/consensus');
const policy = require('../protocol/policy');
@ -28,7 +29,6 @@ const Network = require('../protocol/network');
const layout = require('./layout');
const Fees = require('./fees');
const CoinView = require('../coins/coinview');
const Heap = require('../utils/heap');
/**
* Mempool

View File

@ -9,7 +9,7 @@
const assert = require('assert');
const EventEmitter = require('events');
const Heap = require('../utils/heap');
const Heap = require('bheep');
const Amount = require('../btc/amount');
const Address = require('../primitives/address');
const BlockTemplate = require('./template');

View File

@ -99,7 +99,7 @@ class BIP151Stream {
this.publicKey = publicKey;
const secret = secp256k1.ecdh(this.publicKey, this.privateKey);
const secret = secp256k1.ecdh(this.publicKey, this.privateKey).slice(1);
const bw = bio.pool(33);

View File

@ -14,7 +14,7 @@ const assert = require('assert');
const bio = require('bufio');
const consensus = require('../protocol/consensus');
const sha256 = require('bcrypto/lib/sha256');
const {siphash} = require('bcrypto/lib/siphash');
const {siphash} = require('bsip');
const AbstractBlock = require('../primitives/abstractblock');
const TX = require('../primitives/tx');
const Headers = require('../primitives/headers');

View File

@ -12,11 +12,11 @@ const fs = require('bfile');
const IP = require('binet');
const dns = require('bdns');
const Logger = require('blgr');
const {murmur3} = require('bfilter');
const murmur3 = require('mrmr');
const List = require('blst');
const util = require('../utils/util');
const Network = require('../protocol/network');
const NetAddress = require('./netaddress');
const List = require('../utils/list');
const common = require('./common');
const seeds = require('./seeds');

View File

@ -100,7 +100,7 @@ class NetAddress {
* @returns {Boolean}
*/
static isIPv4() {
isIPv4() {
return IP.isIPv4(this.raw);
}
@ -109,7 +109,7 @@ class NetAddress {
* @returns {Boolean}
*/
static isIPv6() {
isIPv6() {
return IP.isIPv6(this.raw);
}

View File

@ -15,6 +15,7 @@ const dns = require('bdns');
const tcp = require('btcp');
const UPNP = require('bupnp');
const socks = require('bsocks');
const List = require('blst');
const {BloomFilter, RollingFilter} = require('bfilter');
const secp256k1 = require('bcrypto/lib/secp256k1');
const util = require('../utils/util');
@ -26,7 +27,6 @@ const BIP151 = require('./bip151');
const BIP152 = require('./bip152');
const Network = require('../protocol/network');
const Peer = require('./peer');
const List = require('../utils/list');
const HostList = require('./hostlist');
const InvItem = require('../primitives/invitem');
const packets = require('./packets');

View File

@ -1,244 +0,0 @@
/*!
* heap.js - heap object for bcoin
* Copyright (c) 2017, Christopher Jeffrey (MIT License).
* https://github.com/bcoin-org/bcoin
*/
'use strict';
const assert = require('assert');
/**
* Binary Heap
* @alias module:utils.Heap
*/
class Heap {
/**
* Create a binary heap.
* @constructor
* @param {Function?} compare
*/
constructor(compare) {
this.compare = comparator;
this.items = [];
if (compare)
this.set(compare);
}
/**
* Initialize and sort heap.
*/
init() {
const n = this.items.length;
if (n <= 1)
return;
for (let i = (n / 2 | 0) - 1; i >= 0; i--)
this.down(i, n);
}
/**
* Get heap size.
* @returns {Number}
*/
size() {
return this.items.length;
}
/**
* Set comparator.
* @param {Function} compare
*/
set(compare) {
assert(typeof compare === 'function',
'Comparator must be a function.');
this.compare = compare;
}
/**
* Push item onto heap.
* @param {Object} item
* @returns {Number}
*/
insert(item) {
this.items.push(item);
this.up(this.items.length - 1);
return this.items.length;
}
/**
* Pop next item off of heap.
* @param {Object} item
* @returns {Object}
*/
shift() {
if (this.items.length === 0)
return null;
const n = this.items.length - 1;
this.swap(0, n);
this.down(0, n);
return this.items.pop();
}
/**
* Remove item from heap.
* @param {Number} i
* @returns {Object}
*/
remove(i) {
if (this.items.length === 0)
return null;
const n = this.items.length - 1;
if (i < 0 || i > n)
return null;
if (n !== i) {
this.swap(i, n);
this.down(i, n);
this.up(i);
}
return this.items.pop();
}
/**
* Swap indicies.
* @private
* @param {Number} a
* @param {Number} b
*/
swap(a, b) {
const x = this.items[a];
const y = this.items[b];
this.items[a] = y;
this.items[b] = x;
}
/**
* Compare indicies.
* @private
* @param {Number} i
* @param {Number} j
* @returns {Boolean}
*/
less(i, j) {
return this.compare(this.items[i], this.items[j]) < 0;
}
/**
* Bubble item down.
* @private
* @param {Number} i
* @param {Number} n
*/
down(i, n) {
for (;;) {
const l = 2 * i + 1;
assert(l >= 0);
if (l < 0 || l >= n)
break;
let j = l;
const r = l + 1;
if (r < n && !this.less(l, r))
j = r;
if (!this.less(j, i))
break;
this.swap(i, j);
i = j;
}
}
/**
* Bubble item up.
* @private
* @param {Number} i
*/
up(i) {
for (;;) {
const j = (i - 1) / 2 | 0;
assert(j >= 0);
if (j < 0 || j === i)
break;
if (!this.less(i, j))
break;
this.swap(j, i);
i = j;
}
}
/**
* Convert heap to sorted array.
* @returns {Object[]}
*/
toArray() {
const heap = new Heap();
const result = [];
heap.compare = this.compare;
heap.items = this.items.slice();
while (heap.size() > 0)
result.push(heap.shift());
return result;
}
/**
* Instantiate heap from array and comparator.
* @param {Function} compare
* @param {Object[]} items
* @returns {Heap}
*/
static fromArray(compare, items) {
const heap = new Heap();
heap.set(compare);
heap.items = items;
heap.init();
return heap;
}
}
/*
* Helpers
*/
function comparator(a, b) {
throw new Error('No heap comparator set.');
}
/*
* Expose
*/
module.exports = Heap;

View File

@ -1,290 +0,0 @@
/*!
* list.js - double linked list for bcoin
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
* https://github.com/bcoin-org/bcoin
*/
'use strict';
const assert = require('assert');
/**
* Double Linked List
* @alias module:utils.List
*/
class List {
/**
* Create a list.
* @constructor
* @property {ListItem|null} head
* @property {ListItem|null} tail
* @property {Number} size
*/
constructor() {
this.head = null;
this.tail = null;
this.size = 0;
}
/**
* Reset the cache. Clear all items.
*/
reset() {
let item, next;
for (item = this.head; item; item = next) {
next = item.next;
item.prev = null;
item.next = null;
}
assert(!item);
this.head = null;
this.tail = null;
this.size = 0;
}
/**
* Remove the first item in the list.
* @returns {ListItem}
*/
shift() {
const item = this.head;
if (!item)
return null;
this.remove(item);
return item;
}
/**
* Prepend an item to the linked list (sets new head).
* @param {ListItem}
* @returns {Boolean}
*/
unshift(item) {
return this.insert(null, item);
}
/**
* Append an item to the linked list (sets new tail).
* @param {ListItem}
* @returns {Boolean}
*/
push(item) {
return this.insert(this.tail, item);
}
/**
* Remove the last item in the list.
* @returns {ListItem}
*/
pop() {
const item = this.tail;
if (!item)
return null;
this.remove(item);
return item;
}
/**
* Insert item into the linked list.
* @private
* @param {ListItem|null} ref
* @param {ListItem} item
* @returns {Boolean}
*/
insert(ref, item) {
if (item.prev || item.next || item === this.head)
return false;
assert(!item.prev);
assert(!item.next);
if (ref == null) {
if (!this.head) {
this.head = item;
this.tail = item;
} else {
this.head.prev = item;
item.next = this.head;
this.head = item;
}
this.size += 1;
return true;
}
item.next = ref.next;
item.prev = ref;
ref.next = item;
if (ref === this.tail)
this.tail = item;
this.size += 1;
return true;
}
/**
* Remove item from the linked list.
* @private
* @param {ListItem}
* @returns {Boolean}
*/
remove(item) {
if (!item.prev && !item.next && item !== this.head)
return false;
if (item.prev)
item.prev.next = item.next;
if (item.next)
item.next.prev = item.prev;
if (item === this.head)
this.head = item.next;
if (item === this.tail)
this.tail = item.prev || this.head;
if (!this.head)
assert(!this.tail);
if (!this.tail)
assert(!this.head);
item.prev = null;
item.next = null;
this.size -= 1;
return true;
}
/**
* Replace an item in-place.
* @param {ListItem} ref
* @param {ListItem} item
*/
replace(ref, item) {
if (ref.prev)
ref.prev.next = item;
if (ref.next)
ref.next.prev = item;
item.prev = ref.prev;
item.next = ref.next;
ref.next = null;
ref.prev = null;
if (this.head === ref)
this.head = item;
if (this.tail === ref)
this.tail = item;
}
/**
* Slice the list to an array of items.
* Will remove the items sliced.
* @param {Number?} total
* @returns {ListItem[]}
*/
slice(total) {
if (total == null)
total = -1;
const items = [];
let next = null;
for (let item = this.head; item; item = next) {
next = item.next;
item.prev = null;
item.next = null;
this.size -= 1;
items.push(item);
if (items.length === total)
break;
}
if (next) {
this.head = next;
next.prev = null;
} else {
this.head = null;
this.tail = null;
}
return items;
}
/**
* Convert the list to an array of items.
* @returns {ListItem[]}
*/
toArray() {
const items = [];
for (let item = this.head; item; item = item.next)
items.push(item);
return items;
}
}
/**
* List Item
* @alias module:utils.ListItem
*/
class ListItem {
/**
* Create a list item.
* @constructor
* @private
* @param {String} key
* @param {Object} value
*/
constructor(value) {
this.next = null;
this.prev = null;
this.value = value;
}
}
/*
* Expose
*/
exports = List;
exports.List = List;
exports.ListItem = ListItem;
exports.Item = ListItem;
module.exports = exports;

View File

@ -1,522 +0,0 @@
/*!
* lru.js - LRU cache for bcoin
* Copyright (c) 2014-2015, Fedor Indutny (MIT License)
* Copyright (c) 2014-2017, Christopher Jeffrey (MIT License).
* https://github.com/bcoin-org/bcoin
*/
'use strict';
const assert = require('assert');
/**
* LRU Cache
* @alias module:utils.LRU
*/
class LRU {
/**
* Create an LRU cache.
* @constructor
* @param {Number} capacity
* @param {Function?} getSize
*/
constructor(capacity, getSize) {
this.map = new Map();
this.size = 0;
this.items = 0;
this.head = null;
this.tail = null;
this.pending = null;
assert(typeof capacity === 'number', 'Capacity must be a number.');
assert(capacity >= 0, 'Capacity cannot be negative.');
assert(!getSize || typeof getSize === 'function', 'Bad size callback.');
this.capacity = capacity;
this.getSize = getSize;
}
/**
* Calculate size of an item.
* @private
* @param {LRUItem} item
* @returns {Number} Size.
*/
_getSize(item) {
if (this.getSize) {
const keySize = Math.floor(item.key.length * 1.375);
return 120 + keySize + this.getSize(item.value);
}
return 1;
}
/**
* Compact the LRU linked list.
* @private
*/
_compact() {
if (this.size <= this.capacity)
return;
let item = null;
let next = null;
for (item = this.head; item; item = next) {
if (this.size <= this.capacity)
break;
this.size -= this._getSize(item);
this.items -= 1;
this.map.delete(item.key);
next = item.next;
item.prev = null;
item.next = null;
}
if (!item) {
this.head = null;
this.tail = null;
return;
}
this.head = item;
item.prev = null;
}
/**
* Reset the cache. Clear all items.
*/
reset() {
let item, next;
for (item = this.head; item; item = next) {
this.map.delete(item.key);
this.items -= 1;
next = item.next;
item.prev = null;
item.next = null;
}
assert(!item);
this.size = 0;
this.head = null;
this.tail = null;
}
/**
* Add an item to the cache.
* @param {String|Number} key
* @param {Object} value
*/
set(key, value) {
if (this.capacity === 0)
return;
let item = this.map.get(key);
if (item) {
this.size -= this._getSize(item);
item.value = value;
this.size += this._getSize(item);
this._removeList(item);
this._appendList(item);
this._compact();
return;
}
item = new LRUItem(key, value);
this.map.set(key, item);
this._appendList(item);
this.size += this._getSize(item);
this.items += 1;
this._compact();
}
/**
* Retrieve an item from the cache.
* @param {String|Number} key
* @returns {Object} Item.
*/
get(key) {
if (this.capacity === 0)
return null;
const item = this.map.get(key);
if (!item)
return null;
this._removeList(item);
this._appendList(item);
return item.value;
}
/**
* Test whether the cache contains a key.
* @param {String|Number} key
* @returns {Boolean}
*/
has(key) {
if (this.capacity === 0)
return false;
return this.map.has(key);
}
/**
* Remove an item from the cache.
* @param {String|Number} key
* @returns {Boolean} Whether an item was removed.
*/
remove(key) {
if (this.capacity === 0)
return false;
const item = this.map.get(key);
if (!item)
return false;
this.size -= this._getSize(item);
this.items -= 1;
this.map.delete(key);
this._removeList(item);
return true;
}
/**
* Prepend an item to the linked list (sets new head).
* @private
* @param {LRUItem}
*/
_prependList(item) {
this._insertList(null, item);
}
/**
* Append an item to the linked list (sets new tail).
* @private
* @param {LRUItem}
*/
_appendList(item) {
this._insertList(this.tail, item);
}
/**
* Insert item into the linked list.
* @private
* @param {LRUItem|null} ref
* @param {LRUItem} item
*/
_insertList(ref, item) {
assert(!item.next);
assert(!item.prev);
if (ref == null) {
if (!this.head) {
this.head = item;
this.tail = item;
} else {
this.head.prev = item;
item.next = this.head;
this.head = item;
}
return;
}
item.next = ref.next;
item.prev = ref;
ref.next = item;
if (ref === this.tail)
this.tail = item;
}
/**
* Remove item from the linked list.
* @private
* @param {LRUItem}
*/
_removeList(item) {
if (item.prev)
item.prev.next = item.next;
if (item.next)
item.next.prev = item.prev;
if (item === this.head)
this.head = item.next;
if (item === this.tail)
this.tail = item.prev || this.head;
if (!this.head)
assert(!this.tail);
if (!this.tail)
assert(!this.head);
item.prev = null;
item.next = null;
}
/**
* Collect all keys in the cache, sorted by LRU.
* @returns {String[]}
*/
keys() {
const items = [];
for (let item = this.head; item; item = item.next) {
if (item === this.head)
assert(!item.prev);
if (!item.prev)
assert(item === this.head);
if (!item.next)
assert(item === this.tail);
items.push(item.key);
}
return items;
}
/**
* Collect all values in the cache, sorted by LRU.
* @returns {String[]}
*/
values() {
const items = [];
for (let item = this.head; item; item = item.next)
items.push(item.value);
return items;
}
/**
* Convert the LRU cache to an array of items.
* @returns {Object[]}
*/
toArray() {
const items = [];
for (let item = this.head; item; item = item.next)
items.push(item);
return items;
}
/**
* Create an atomic batch for the lru
* (used for caching database writes).
* @returns {LRUBatch}
*/
batch() {
return new LRUBatch(this);
}
/**
* Start the pending batch.
*/
start() {
assert(!this.pending);
this.pending = this.batch();
}
/**
* Clear the pending batch.
*/
clear() {
assert(this.pending);
this.pending.clear();
}
/**
* Drop the pending batch.
*/
drop() {
assert(this.pending);
this.pending = null;
}
/**
* Commit the pending batch.
*/
commit() {
assert(this.pending);
this.pending.commit();
this.pending = null;
}
/**
* Push an item onto the pending batch.
* @param {String} key
* @param {Object} value
*/
push(key, value) {
assert(this.pending);
if (this.capacity === 0)
return;
this.pending.set(key, value);
}
/**
* Push a removal onto the pending batch.
* @param {String} key
*/
unpush(key) {
assert(this.pending);
if (this.capacity === 0)
return;
this.pending.remove(key);
}
}
/**
* LRU Item
* @alias module:utils.LRUItem
*/
class LRUItem {
/**
* Create an LRU item.
* @constructor
* @private
* @param {String} key
* @param {Object} value
*/
constructor(key, value) {
this.key = key;
this.value = value;
this.next = null;
this.prev = null;
}
}
/**
* LRU Batch
* @alias module:utils.LRUBatch
*/
class LRUBatch {
/**
* Create an LRU batch.
* @constructor
* @param {LRU} lru
*/
constructor(lru) {
this.lru = lru;
this.ops = [];
}
/**
* Push an item onto the batch.
* @param {String} key
* @param {Object} value
*/
set(key, value) {
this.ops.push(new LRUOp(false, key, value));
}
/**
* Push a removal onto the batch.
* @param {String} key
*/
remove(key) {
this.ops.push(new LRUOp(true, key, null));
}
/**
* Clear the batch.
*/
clear() {
this.ops.length = 0;
}
/**
* Commit the batch.
*/
commit() {
for (const op of this.ops) {
if (op.remove) {
this.lru.remove(op.key);
continue;
}
this.lru.set(op.key, op.value);
}
this.ops.length = 0;
}
}
/**
* LRU Op
* @alias module:utils.LRUOp
* @private
*/
class LRUOp {
/**
* Create an LRU op.
* @constructor
* @param {Boolean} remove
* @param {String} key
* @param {Object} value
*/
constructor(remove, key, value) {
this.remove = remove;
this.key = key;
this.value = value;
}
}
/*
* Expose
*/
module.exports = LRU;

View File

@ -20,13 +20,13 @@ const bdb = require('bdb');
const hash256 = require('bcrypto/lib/hash256');
const BN = require('bn.js');
const bio = require('bufio');
const LRU = require('blru');
const util = require('../lib/utils/util');
const OldCoins = require('./coins/coins');
const OldUndoCoins = require('./coins/undocoins');
const CoinEntry = require('../lib/coins/coinentry');
const UndoCoins = require('../lib/coins/undocoins');
const Block = require('../lib/primitives/block');
const LRU = require('../lib/utils/lru');
const consensus = require('../lib/protocol/consensus');
const shouldPrune = process.argv.indexOf('--prune') !== -1;

View File

@ -23,41 +23,46 @@
"node": ">=7.6.0"
},
"dependencies": {
"bcfg": "~0.0.1",
"bclient": "~0.0.1",
"bcrypto": "~0.1.0",
"bdb": "~0.0.2",
"bdns": "~0.0.1",
"bevent": "~0.0.1",
"bfile": "~0.0.1",
"bfilter": "~0.0.1",
"binet": "~0.0.1",
"blgr": "~0.0.1",
"bmutex": "~0.0.1",
"bcfg": "~0.0.2",
"bclient": "~0.0.2",
"bcrypto": "~0.2.0",
"bdb": "~0.0.3",
"bdns": "~0.0.2",
"bevent": "~0.0.2",
"bfile": "~0.0.2",
"bfilter": "~0.1.0",
"bheep": "~0.0.1",
"binet": "~0.1.0",
"blgr": "~0.0.2",
"blru": "~0.0.1",
"blst": "~0.0.1",
"bmutex": "~0.0.2",
"bn.js": "~4.11.8",
"bsock": "~0.0.1",
"bsocks": "~0.0.1",
"bstring": "~0.0.1",
"btcp": "~0.0.1",
"bufio": "~0.0.1",
"bupnp": "~0.0.1",
"bval": "~0.0.1",
"bweb": "~0.0.1",
"n64": "~0.1.0"
"bsip": "~0.0.2",
"bsock": "~0.0.2",
"bsocks": "~0.0.2",
"bstring": "~0.0.2",
"btcp": "~0.0.2",
"bufio": "~0.0.3",
"bupnp": "~0.0.2",
"bval": "~0.0.2",
"bweb": "~0.0.2",
"mrmr": "~0.0.1",
"n64": "~0.1.1"
},
"devDependencies": {
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-loader": "^7.1.4",
"babel-plugin-transform-runtime": "^6.23.0",
"babel-preset-env": "^1.6.1",
"babelify": "^8.0.0",
"browserify": "^14.5.0",
"eslint": "^4.14.0",
"browserify": "^16.1.1",
"eslint": "^4.18.2",
"jsdoc": "^3.5.5",
"mocha": "^4.0.1",
"uglify-es": "^3.1.3",
"uglifyjs-webpack-plugin": "^1.1.5",
"webpack": "^3.10.0"
"mocha": "^5.0.4",
"uglify-es": "^3.3.9",
"uglifyjs-webpack-plugin": "^1.2.3",
"webpack": "^4.1.1"
},
"main": "./lib/bcoin.js",
"bin": {