refactor: more moving around.

This commit is contained in:
Christopher Jeffrey 2016-08-23 22:55:50 -07:00
parent 7f6849b6a6
commit d350338c98
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
9 changed files with 18 additions and 15 deletions

View File

@ -0,0 +1 @@
module.exports = require('./crypto');

View File

@ -128,7 +128,7 @@ function Environment() {
this.config = require('./config');
this.protocol = require('./protocol');
this.packets = this.protocol.packets;
this.packets = require('./net/packets');
this.network = require('./network');
this.errors = require('./errors');
this.ldb = require('./db/ldb');

View File

@ -8,7 +8,7 @@
'use strict';
var bcoin = require('../env');
var constants = require('./constants');
var constants = require('../protocol/constants');
var utils = require('../utils/utils');
var bn = require('bn.js');
var IP = require('../utils/ip');

View File

@ -11,7 +11,7 @@ var bcoin = require('../env');
var EventEmitter = require('events').EventEmitter;
var utils = require('../utils/utils');
var assert = utils.assert;
var constants = require('./constants');
var constants = require('../protocol/constants');
var BufferReader = require('../utils/reader');
/**

View File

@ -11,6 +11,8 @@ var bcoin = require('../env');
var EventEmitter = require('events').EventEmitter;
var utils = require('../utils/utils');
var IP = require('../utils/ip');
var Parser = require('./parser');
var Framer = require('./framer');
var assert = utils.assert;
var constants = bcoin.protocol.constants;
var InvItem = bcoin.packets.InvItem;
@ -167,8 +169,8 @@ function Peer(pool, options) {
}
}
this.parser = new bcoin.protocol.parser(this);
this.framer = new bcoin.protocol.framer(this);
this.parser = new Parser(this);
this.framer = new Framer(this);
this._init();
}

View File

@ -9,6 +9,3 @@
exports.constants = require('./constants');
exports.network = require('./network');
exports.framer = require('./framer');
exports.parser = require('./parser');
exports.packets = require('./packets');

1
lib/bcoin/utils/index.js Normal file
View File

@ -0,0 +1 @@
module.exports = require('./utils');

View File

@ -8,6 +8,8 @@ var utils = bcoin.utils;
var fs = require('fs');
var alertData = fs.readFileSync(__dirname + '/data/alertTests.raw');
var NetworkAddress = bcoin.packets.NetworkAddress;
var Framer = require('../lib/bcoin/net/framer');
var Parser = require('../lib/bcoin/net/parser');
describe('Protocol', function() {
var version = require('../package.json').version;
@ -16,8 +18,8 @@ describe('Protocol', function() {
var parser;
var framer;
beforeEach(function() {
parser = bcoin.protocol.parser();
framer = bcoin.protocol.framer();
parser = new Parser();
framer = new Framer();
});
function packetTest(command, payload, test) {
@ -197,21 +199,21 @@ describe('Protocol', function() {
'c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599ffffffff01a029' +
'de5c0500000017a9141d9ca71efa36d814424ea6ca1437e67287aebe348' +
'700000000', 'hex');
var tx = bcoin.protocol.parser.parseTX(rawTwoTxs);
var tx = Parser.parseTX(rawTwoTxs);
delete tx._raw;
assert.deepEqual(bcoin.protocol.framer.tx(tx), rawFirstTx);
assert.deepEqual(Framer.tx(tx), rawFirstTx);
});
it('should parse, reserialize, and verify alert packets', function() {
var p = new bcoin.reader(alertData);
p.start();
while (p.left()) {
var alert = bcoin.protocol.parser.parseAlert(p);
var alert = Parser.parseAlert(p);
assert(alert.verify(network.alertKey));
alert._payload = null;
alert._hash = null;
var data = bcoin.protocol.framer.alert(alert);
alert = bcoin.protocol.parser.parseAlert(data);
var data = Framer.alert(alert);
alert = Parser.parseAlert(data);
assert(alert.verify(network.alertKey));
}
p.end();