From cc91e3ea7b1d25c5384866f7e07f5e6c131df434 Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Thu, 26 Oct 2017 12:31:08 -0700 Subject: [PATCH] http: move to node module. --- lib/bcoin-browser.js | 10 ---------- lib/bcoin.js | 4 ---- lib/http/index.js | 15 --------------- lib/node/fullnode.js | 8 ++++---- lib/{http/server.js => node/http.js} | 8 ++++---- lib/node/index.js | 2 ++ lib/{http => node}/rpc.js | 0 lib/node/spvnode.js | 8 ++++---- lib/wallet/http.js | 10 +++++----- lib/wallet/plugin.js | 4 ++-- lib/wallet/server.js | 4 ++-- 11 files changed, 23 insertions(+), 50 deletions(-) delete mode 100644 lib/http/index.js rename lib/{http/server.js => node/http.js} (99%) rename lib/{http => node}/rpc.js (100%) diff --git a/lib/bcoin-browser.js b/lib/bcoin-browser.js index 2b4f15a7..1d965c11 100644 --- a/lib/bcoin-browser.js +++ b/lib/bcoin-browser.js @@ -174,10 +174,6 @@ bcoin.ldb = require('./db/ldb'); // HD bcoin.hd = require('./hd'); -// HTTP -bcoin.http = require('./http'); -bcoin.rpc = require('./http/rpc'); - // Mempool bcoin.txmempool = require('./mempool'); bcoin.fees = require('./mempool/fees'); @@ -268,9 +264,3 @@ bcoin.workerpool = require('./workers/workerpool'); // Package Info bcoin.pkg = require('./pkg'); - -/* - * Expose Globally - */ - -global.bcoin = bcoin; diff --git a/lib/bcoin.js b/lib/bcoin.js index 7b080d5e..96061c33 100644 --- a/lib/bcoin.js +++ b/lib/bcoin.js @@ -211,10 +211,6 @@ bcoin.define('ldb', './db/ldb'); // HD bcoin.define('hd', './hd'); -// HTTP -bcoin.define('http', './http'); -bcoin.define('rpc', './http/rpc'); - // Mempool bcoin.define('txmempool', './mempool'); bcoin.define('fees', './mempool/fees'); diff --git a/lib/http/index.js b/lib/http/index.js deleted file mode 100644 index 2bbaaedb..00000000 --- a/lib/http/index.js +++ /dev/null @@ -1,15 +0,0 @@ -/*! - * http/index.js - http 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'; - -/** - * @module http - */ - -exports.RPC = require('./rpc'); -exports.Server = require('./server'); diff --git a/lib/node/fullnode.js b/lib/node/fullnode.js index ce624b57..f674be86 100644 --- a/lib/node/fullnode.js +++ b/lib/node/fullnode.js @@ -12,9 +12,9 @@ const Fees = require('../mempool/fees'); const Mempool = require('../mempool/mempool'); const Pool = require('../net/pool'); const Miner = require('../mining/miner'); -const HTTPServer = require('../http/server'); -const RPC = require('../http/rpc'); const Node = require('./node'); +const HTTP = require('./http'); +const RPC = require('./rpc'); /** * Respresents a fullnode complete with a @@ -28,7 +28,7 @@ const Node = require('./node'); * @property {Mempool} mempool * @property {Pool} pool * @property {Miner} miner - * @property {HTTPServer} http + * @property {HTTP} http * @emits FullNode#block * @emits FullNode#tx * @emits FullNode#connect @@ -137,7 +137,7 @@ function FullNode(options) { this.rpc = new RPC(this); // HTTP needs access to the node. - this.http = new HTTPServer({ + this.http = new HTTP({ network: this.network, logger: this.logger, node: this, diff --git a/lib/http/server.js b/lib/node/http.js similarity index 99% rename from lib/http/server.js rename to lib/node/http.js index 37288d07..046fbd41 100644 --- a/lib/http/server.js +++ b/lib/node/http.js @@ -22,15 +22,15 @@ const Network = require('../protocol/network'); const Validator = require('../utils/validator'); const pkg = require('../pkg'); -class HTTPServer extends Server { +class HTTP extends Server { /** - * HTTPServer + * HTTP * @alias module:http.Server * @constructor * @param {Object} options * @param {Fullnode} options.node * @see HTTPBase - * @emits HTTPServer#socket + * @emits HTTP#socket */ constructor(options) { @@ -794,4 +794,4 @@ function enforce(value, msg) { * Expose */ -module.exports = HTTPServer; +module.exports = HTTP; diff --git a/lib/node/index.js b/lib/node/index.js index 5e156cb3..ee0edddb 100644 --- a/lib/node/index.js +++ b/lib/node/index.js @@ -12,6 +12,8 @@ exports.Config = require('./config'); exports.FullNode = require('./fullnode'); +exports.HTTP = require('./http'); exports.Logger = require('./logger'); exports.Node = require('./node'); +exports.RPC = require('./rpc'); exports.SPVNode = require('./spvnode'); diff --git a/lib/http/rpc.js b/lib/node/rpc.js similarity index 100% rename from lib/http/rpc.js rename to lib/node/rpc.js diff --git a/lib/node/spvnode.js b/lib/node/spvnode.js index 9e91677e..ad789b21 100644 --- a/lib/node/spvnode.js +++ b/lib/node/spvnode.js @@ -10,9 +10,9 @@ const Lock = require('../utils/lock'); const Chain = require('../blockchain/chain'); const Pool = require('../net/pool'); -const HTTPServer = require('../http/server'); -const RPC = require('../http/rpc'); const Node = require('./node'); +const HTTP = require('./http'); +const RPC = require('../rpc'); /** * Create an spv node which only maintains @@ -28,7 +28,7 @@ const Node = require('./node'); * @property {Boolean} loaded * @property {Chain} chain * @property {Pool} pool - * @property {HTTPServer} http + * @property {HTTP} http * @emits SPVNode#block * @emits SPVNode#tx * @emits SPVNode#error @@ -80,7 +80,7 @@ function SPVNode(options) { this.rpc = new RPC(this); - this.http = new HTTPServer({ + this.http = new HTTP({ network: this.network, logger: this.logger, node: this, diff --git a/lib/wallet/http.js b/lib/wallet/http.js index a71367fb..d5d3ce26 100644 --- a/lib/wallet/http.js +++ b/lib/wallet/http.js @@ -26,14 +26,14 @@ const HDPrivateKey = require('../hd/private'); const HDPublicKey = require('../hd/public'); const common = require('./common'); -class HTTPServer extends Server { +class HTTP extends Server { /** - * HTTPServer - * @alias module:wallet.HTTPServer + * HTTP + * @alias module:wallet.HTTP * @constructor * @param {Object} options * @see HTTPBase - * @emits HTTPServer#socket + * @emits HTTP#socket */ constructor(options) { @@ -1105,4 +1105,4 @@ function enforce(value, msg) { * Expose */ -module.exports = HTTPServer; +module.exports = HTTP; diff --git a/lib/wallet/plugin.js b/lib/wallet/plugin.js index ad28c7a6..847e9364 100644 --- a/lib/wallet/plugin.js +++ b/lib/wallet/plugin.js @@ -9,7 +9,7 @@ const EventEmitter = require('events'); const WalletDB = require('./walletdb'); const NodeClient = require('./nodeclient'); -const HTTPServer = require('./http'); +const HTTP = require('./http'); const RPC = require('./rpc'); /** @@ -54,7 +54,7 @@ function Plugin(node) { this.rpc = new RPC(this); - this.http = new HTTPServer({ + this.http = new HTTP({ network: node.network, logger: node.logger, node: this, diff --git a/lib/wallet/server.js b/lib/wallet/server.js index 4d44ef91..a998fa8a 100644 --- a/lib/wallet/server.js +++ b/lib/wallet/server.js @@ -8,7 +8,7 @@ const Node = require('../node/node'); const WalletDB = require('./walletdb'); -const HTTPServer = require('./http'); +const HTTP = require('./http'); const Client = require('./client'); const RPC = require('./rpc'); @@ -57,7 +57,7 @@ function WalletNode(options) { this.rpc = new RPC(this); - this.http = new HTTPServer({ + this.http = new HTTP({ network: this.network, logger: this.logger, node: this,