refactor: env.

This commit is contained in:
Christopher Jeffrey 2016-08-24 02:20:27 -07:00
parent 3b17b8e775
commit 177272a2c5
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
3 changed files with 62 additions and 31 deletions

View File

@ -92,7 +92,6 @@ var global = utils.global;
* @property {Function} address - {@link Address} constructor.
* @property {Function} wallet - {@link Wallet} constructor.
* @property {Function} walletdb - {@link WalletDB} constructor.
* @property {Function} provider - {@link Provider} constructor.
* @property {Function} peer - {@link Peer} constructor.
* @property {Function} pool - {@link Pool} constructor.
* @property {Function} miner - {@link Miner} constructor.
@ -100,7 +99,6 @@ var global = utils.global;
* @property {Object} http
* @property {Function} http.client - {@link HTTPClient} constructor.
* @property {Function} http.http - {@link HTTPBase} constructor.
* @property {Function} http.provider - {@link HTTPProvider} constructor.
* @property {Function} http.request - See {@link request}.
* @property {Function} http.server - {@link HTTPServer} constructor.
* @property {Object} workers - See {@link module:workers}.
@ -111,26 +109,35 @@ var global = utils.global;
function Environment() {
this.env = Environment;
this.bn = require('bn.js');
// Protocol
this.constants = require('./protocol/constants');
this.networks = require('./protocol/networks');
this.network = require('./protocol/network');
// Utils
this.utils = require('./utils/utils');
this.locker = require('./utils/locker');
this.reader = require('./utils/reader');
this.writer = require('./utils/writer');
this.ec = require('./crypto/ec');
this.lru = require('./utils/lru');
this.bloom = require('./primitives/bloom');
this.rbt = require('./db/rbt');
this.lowlevelup = require('./db/lowlevelup');
this.uri = require('./utils/uri');
this.logger = require('./node/logger');
this.config = require('./node/config');
this.constants = require('./protocol/constants');
this.networks = require('./protocol/networks');
this.packets = require('./net/packets');
this.network = require('./protocol/network');
this.errors = require('./utils/errors');
// Crypto
this.ec = require('./crypto/ec');
this.crypto = require('./crypto/crypto');
this.chachapoly = require('./crypto/chachapoly');
this.scrypt = require('./crypto/scrypt');
this.siphash = require('./crypto/siphash');
// DB
this.lowlevelup = require('./db/lowlevelup');
this.ldb = require('./db/ldb');
this.timedata = require('./net/timedata');
this.rbt = require('./db/rbt');
// Primitives
this.bloom = require('./primitives/bloom');
this.script = require('./primitives/script');
this.opcode = this.script.Opcode;
this.stack = this.script.Stack;
@ -140,50 +147,76 @@ function Environment() {
this.outpoint = this.input.Outpoint;
this.output = require('./primitives/output');
this.coin = require('./primitives/coin');
this.coins = require('./chain/coins');
this.coinview = require('./chain/coinview');
this.tx = require('./primitives/tx');
this.mtx = require('./primitives/mtx');
this.txdb = require('./wallet/txdb');
this.abstractblock = require('./primitives/abstractblock');
this.bip151 = require('./net/bip151');
this.bip150 = require('./net/bip150');
this.bip152 = require('./net/bip152');
this.memblock = require('./primitives/memblock');
this.block = require('./primitives/block');
this.merkleblock = require('./primitives/merkleblock');
this.headers = require('./primitives/headers');
this.fees = require('./mempool/fees');
this.keyring = require('./primitives/keyring');
this.hd = require('./primitives/hd');
// Node
this.logger = require('./node/logger');
this.config = require('./node/config');
this.node = require('./node/node');
this.spvnode = require('./node/spvnode');
this.fullnode = require('./node/fullnode');
// Net
this.timedata = require('./net/timedata');
this.packets = require('./net/packets');
this.invitem = this.packets.InvItem;
this.bip150 = require('./net/bip150');
this.bip151 = require('./net/bip151');
this.bip152 = require('./net/bip152');
this.peer = require('./net/peer');
this.pool = require('./net/pool');
// Chain
this.coins = require('./chain/coins');
this.coinview = require('./chain/coinview');
this.chainentry = require('./chain/chainentry');
this.chaindb = require('./chain/chaindb');
this.chain = require('./chain/chain');
// Mempool
this.fees = require('./mempool/fees');
this.mempool = require('./mempool/mempool');
this.mempoolentry = this.mempool.MempoolEntry;
this.keyring = require('./primitives/keyring');
this.hd = require('./primitives/hd');
// Miner
this.miner = require('./miner/miner');
this.minerblock = require('./miner/minerblock');
// Wallet
this.txdb = require('./wallet/txdb');
this.wallet = require('./wallet/wallet');
this.account = this.wallet.Account;
this.walletdb = require('./wallet/walletdb');
this.path = this.walletdb.Path;
this.peer = require('./net/peer');
this.pool = require('./net/pool');
this.miner = require('./miner/miner');
this.minerblock = this.miner.MinerBlock;
// HTTP
this.http = require('./http');
// Workers
this.workers = require('./workers/workers');
// Sigcache
this.sc = require('./sigcache');
// Global Instances
this.sigcache = new this.sc(0);
this.time = new this.timedata();
this.defaultLogger = new this.logger('none');
this.workerPool = new this.workers();
// Global Worker Properties
this.useWorkers = false;
this.master = null;
// Initialize the environment.
this.set({
network: process.env.BCOIN_NETWORK || 'main',
useWorkers: +process.env.BCOIN_USE_WORKERS === 1,

View File

@ -11,7 +11,6 @@ var bcoin = require('../env');
var constants = bcoin.constants;
var utils = bcoin.utils;
var assert = utils.assert;
var InvItem = bcoin.packets.InvItem;
/**
* The class which all block-like objects inherit from.
@ -241,7 +240,7 @@ AbstractBlock.prototype.__defineGetter__('rhash', function() {
*/
AbstractBlock.prototype.toInv = function toInv() {
return new InvItem(constants.inv.BLOCK, this.hash('hex'));
return new bcoin.invitem(constants.inv.BLOCK, this.hash('hex'));
};
/**

View File

@ -14,7 +14,6 @@ var constants = bcoin.constants;
var Script = bcoin.script;
var Stack = bcoin.stack;
var BufferWriter = require('../utils/writer');
var InvItem = bcoin.packets.InvItem;
/**
* A static transaction object.
@ -1757,7 +1756,7 @@ TX.prototype.__defineGetter__('wtxid', function() {
*/
TX.prototype.toInv = function toInv() {
return new InvItem(constants.inv.TX, this.hash('hex'));
return new bcoin.invitem(constants.inv.TX, this.hash('hex'));
};
/**