refactor: more moving around.
This commit is contained in:
parent
7f6849b6a6
commit
d350338c98
1
lib/bcoin/crypto/index.js
Normal file
1
lib/bcoin/crypto/index.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = require('./crypto');
|
||||||
@ -128,7 +128,7 @@ function Environment() {
|
|||||||
this.config = require('./config');
|
this.config = require('./config');
|
||||||
|
|
||||||
this.protocol = require('./protocol');
|
this.protocol = require('./protocol');
|
||||||
this.packets = this.protocol.packets;
|
this.packets = require('./net/packets');
|
||||||
this.network = require('./network');
|
this.network = require('./network');
|
||||||
this.errors = require('./errors');
|
this.errors = require('./errors');
|
||||||
this.ldb = require('./db/ldb');
|
this.ldb = require('./db/ldb');
|
||||||
|
|||||||
@ -8,7 +8,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var bcoin = require('../env');
|
var bcoin = require('../env');
|
||||||
var constants = require('./constants');
|
var constants = require('../protocol/constants');
|
||||||
var utils = require('../utils/utils');
|
var utils = require('../utils/utils');
|
||||||
var bn = require('bn.js');
|
var bn = require('bn.js');
|
||||||
var IP = require('../utils/ip');
|
var IP = require('../utils/ip');
|
||||||
@ -11,7 +11,7 @@ var bcoin = require('../env');
|
|||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var utils = require('../utils/utils');
|
var utils = require('../utils/utils');
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var constants = require('./constants');
|
var constants = require('../protocol/constants');
|
||||||
var BufferReader = require('../utils/reader');
|
var BufferReader = require('../utils/reader');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -11,6 +11,8 @@ var bcoin = require('../env');
|
|||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
var utils = require('../utils/utils');
|
var utils = require('../utils/utils');
|
||||||
var IP = require('../utils/ip');
|
var IP = require('../utils/ip');
|
||||||
|
var Parser = require('./parser');
|
||||||
|
var Framer = require('./framer');
|
||||||
var assert = utils.assert;
|
var assert = utils.assert;
|
||||||
var constants = bcoin.protocol.constants;
|
var constants = bcoin.protocol.constants;
|
||||||
var InvItem = bcoin.packets.InvItem;
|
var InvItem = bcoin.packets.InvItem;
|
||||||
@ -167,8 +169,8 @@ function Peer(pool, options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.parser = new bcoin.protocol.parser(this);
|
this.parser = new Parser(this);
|
||||||
this.framer = new bcoin.protocol.framer(this);
|
this.framer = new Framer(this);
|
||||||
|
|
||||||
this._init();
|
this._init();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,6 +9,3 @@
|
|||||||
|
|
||||||
exports.constants = require('./constants');
|
exports.constants = require('./constants');
|
||||||
exports.network = require('./network');
|
exports.network = require('./network');
|
||||||
exports.framer = require('./framer');
|
|
||||||
exports.parser = require('./parser');
|
|
||||||
exports.packets = require('./packets');
|
|
||||||
|
|||||||
1
lib/bcoin/utils/index.js
Normal file
1
lib/bcoin/utils/index.js
Normal file
@ -0,0 +1 @@
|
|||||||
|
module.exports = require('./utils');
|
||||||
@ -8,6 +8,8 @@ var utils = bcoin.utils;
|
|||||||
var fs = require('fs');
|
var fs = require('fs');
|
||||||
var alertData = fs.readFileSync(__dirname + '/data/alertTests.raw');
|
var alertData = fs.readFileSync(__dirname + '/data/alertTests.raw');
|
||||||
var NetworkAddress = bcoin.packets.NetworkAddress;
|
var NetworkAddress = bcoin.packets.NetworkAddress;
|
||||||
|
var Framer = require('../lib/bcoin/net/framer');
|
||||||
|
var Parser = require('../lib/bcoin/net/parser');
|
||||||
|
|
||||||
describe('Protocol', function() {
|
describe('Protocol', function() {
|
||||||
var version = require('../package.json').version;
|
var version = require('../package.json').version;
|
||||||
@ -16,8 +18,8 @@ describe('Protocol', function() {
|
|||||||
var parser;
|
var parser;
|
||||||
var framer;
|
var framer;
|
||||||
beforeEach(function() {
|
beforeEach(function() {
|
||||||
parser = bcoin.protocol.parser();
|
parser = new Parser();
|
||||||
framer = bcoin.protocol.framer();
|
framer = new Framer();
|
||||||
});
|
});
|
||||||
|
|
||||||
function packetTest(command, payload, test) {
|
function packetTest(command, payload, test) {
|
||||||
@ -197,21 +199,21 @@ describe('Protocol', function() {
|
|||||||
'c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599ffffffff01a029' +
|
'c9954c44b0ce168bc78efd5f1e1c7db9d6c21b3016599ffffffff01a029' +
|
||||||
'de5c0500000017a9141d9ca71efa36d814424ea6ca1437e67287aebe348' +
|
'de5c0500000017a9141d9ca71efa36d814424ea6ca1437e67287aebe348' +
|
||||||
'700000000', 'hex');
|
'700000000', 'hex');
|
||||||
var tx = bcoin.protocol.parser.parseTX(rawTwoTxs);
|
var tx = Parser.parseTX(rawTwoTxs);
|
||||||
delete tx._raw;
|
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() {
|
it('should parse, reserialize, and verify alert packets', function() {
|
||||||
var p = new bcoin.reader(alertData);
|
var p = new bcoin.reader(alertData);
|
||||||
p.start();
|
p.start();
|
||||||
while (p.left()) {
|
while (p.left()) {
|
||||||
var alert = bcoin.protocol.parser.parseAlert(p);
|
var alert = Parser.parseAlert(p);
|
||||||
assert(alert.verify(network.alertKey));
|
assert(alert.verify(network.alertKey));
|
||||||
alert._payload = null;
|
alert._payload = null;
|
||||||
alert._hash = null;
|
alert._hash = null;
|
||||||
var data = bcoin.protocol.framer.alert(alert);
|
var data = Framer.alert(alert);
|
||||||
alert = bcoin.protocol.parser.parseAlert(data);
|
alert = Parser.parseAlert(data);
|
||||||
assert(alert.verify(network.alertKey));
|
assert(alert.verify(network.alertKey));
|
||||||
}
|
}
|
||||||
p.end();
|
p.end();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user