workers: remove parser-client.

This commit is contained in:
Christopher Jeffrey 2017-07-05 12:05:58 -07:00
parent 972d98e0db
commit 90f783fd05
No known key found for this signature in database
GPG Key ID: 8962AB9DE6666BBD
6 changed files with 25 additions and 79 deletions

View File

@ -7,7 +7,6 @@
'use strict';
const EventEmitter = require('events');
const util = require('../utils/util');
const StaticWriter = require('../utils/staticwriter');
@ -20,12 +19,8 @@ const StaticWriter = require('../utils/staticwriter');
function Framer() {
if (!(this instanceof Framer))
return new Framer();
EventEmitter.call(this);
}
util.inherits(Framer, EventEmitter);
Framer.prototype.packet = function _packet(packet) {
let size = 10 + packet.getSize();
let bw = new StaticWriter(size);

View File

@ -12,9 +12,6 @@
exports.Framer = require('./framer');
exports.jobs = require('./jobs');
// exports.Master = require('./master');
exports.packets = require('./packets');
exports.ParserClient = require('./parser-client');
exports.Parser = require('./parser');
// exports.worker = require('./worker');
exports.WorkerPool = require('./workerpool');

View File

@ -12,7 +12,7 @@ const EventEmitter = require('events');
const util = require('../utils/util');
const Network = require('../protocol/network');
const jobs = require('./jobs');
const Parser = require('./parser-client');
const Parser = require('./parser');
const Framer = require('./framer');
const packets = require('./packets');
const HAS_WORKERS = typeof global.postMessage === 'function';

View File

@ -17,6 +17,10 @@ const encoding = require('../utils/encoding');
const Script = require('../script/script');
const Witness = require('../script/witness');
const Output = require('../primitives/output');
const MTX = require('../primitives/mtx');
const TX = require('../primitives/tx');
const KeyRing = require('../primitives/keyring');
const CoinView = require('../coins/coinview');
/*
* Constants
@ -221,7 +225,7 @@ VerifyPacket.prototype.toWriter = function toWriter(bw) {
bw.write32(this.flags != null ? this.flags : -1);
};
VerifyPacket.fromRaw = function fromRaw(TX, CoinView, data) {
VerifyPacket.fromRaw = function fromRaw(data) {
let br = new BufferReader(data, true);
let packet = new VerifyPacket();
@ -311,7 +315,7 @@ SignPacket.prototype.toWriter = function toWriter(bw) {
bw.writeU8(this.type);
};
SignPacket.fromRaw = function fromRaw(MTX, KeyRing, data) {
SignPacket.fromRaw = function fromRaw(data) {
let br = new BufferReader(data, true);
let packet = new SignPacket();
let count;
@ -449,7 +453,7 @@ VerifyInputPacket.prototype.toWriter = function toWriter(bw) {
bw.write32(this.flags != null ? this.flags : -1);
};
VerifyInputPacket.fromRaw = function fromRaw(TX, data) {
VerifyInputPacket.fromRaw = function fromRaw(data) {
let br = new BufferReader(data, true);
let packet = new VerifyInputPacket();
@ -535,7 +539,7 @@ SignInputPacket.prototype.toWriter = function toWriter(bw) {
bw.writeU8(this.type);
};
SignInputPacket.fromRaw = function fromRaw(MTX, KeyRing, data) {
SignInputPacket.fromRaw = function fromRaw(data) {
let br = new BufferReader(data, true);
let packet = new SignInputPacket();

View File

@ -1,66 +0,0 @@
/*!
* workers.js - worker processes 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 util = require('../utils/util');
const packets = require('./packets');
const ServerParser = require('./parser');
const MTX = require('../primitives/mtx');
const TX = require('../primitives/tx');
const KeyRing = require('../primitives/keyring');
const CoinView = require('../coins/coinview');
/**
* Parser
* @alias module:workers.ParserClient
* @constructor
*/
function Parser() {
if (!(this instanceof Parser))
return new Parser();
ServerParser.call(this);
}
util.inherits(Parser, ServerParser);
Parser.prototype.parsePacket = function parsePacket(header, data) {
switch (header.cmd) {
case packets.types.EVENT:
return packets.EventPacket.fromRaw(data);
case packets.types.LOG:
return packets.LogPacket.fromRaw(data);
case packets.types.ERROR:
return packets.ErrorPacket.fromRaw(data);
case packets.types.VERIFY:
return packets.VerifyPacket.fromRaw(TX, CoinView, data);
case packets.types.SIGN:
return packets.SignPacket.fromRaw(MTX, KeyRing, data);
case packets.types.VERIFYINPUT:
return packets.VerifyInputPacket.fromRaw(TX, data);
case packets.types.SIGNINPUT:
return packets.SignInputPacket.fromRaw(MTX, KeyRing, data);
case packets.types.ECVERIFY:
return packets.ECVerifyPacket.fromRaw(data);
case packets.types.ECSIGN:
return packets.ECSignPacket.fromRaw(data);
case packets.types.MINE:
return packets.MinePacket.fromRaw(data);
case packets.types.SCRYPT:
return packets.ScryptPacket.fromRaw(data);
default:
throw new Error('Unknown packet.');
}
};
/*
* Expose
*/
module.exports = Parser;

View File

@ -141,20 +141,36 @@ Parser.prototype.parsePacket = function parsePacket(header, data) {
return packets.ErrorPacket.fromRaw(data);
case packets.types.ERRORRESULT:
return packets.ErrorResultPacket.fromRaw(data);
case packets.types.VERIFY:
return packets.VerifyPacket.fromRaw(data);
case packets.types.VERIFYRESULT:
return packets.VerifyResultPacket.fromRaw(data);
case packets.types.SIGN:
return packets.SignPacket.fromRaw(data);
case packets.types.SIGNRESULT:
return packets.SignResultPacket.fromRaw(data);
case packets.types.VERIFYINPUT:
return packets.VerifyInputPacket.fromRaw(data);
case packets.types.VERIFYINPUTRESULT:
return packets.VerifyInputResultPacket.fromRaw(data);
case packets.types.SIGNINPUT:
return packets.SignInputPacket.fromRaw(data);
case packets.types.SIGNINPUTRESULT:
return packets.SignInputResultPacket.fromRaw(data);
case packets.types.ECVERIFY:
return packets.ECVerifyPacket.fromRaw(data);
case packets.types.ECVERIFYRESULT:
return packets.ECVerifyResultPacket.fromRaw(data);
case packets.types.ECSIGN:
return packets.ECSignPacket.fromRaw(data);
case packets.types.ECSIGNRESULT:
return packets.ECSignResultPacket.fromRaw(data);
case packets.types.MINE:
return packets.MinePacket.fromRaw(data);
case packets.types.MINERESULT:
return packets.MineResultPacket.fromRaw(data);
case packets.types.SCRYPT:
return packets.ScryptPacket.fromRaw(data);
case packets.types.SCRYPTRESULT:
return packets.ScryptResultPacket.fromRaw(data);
default: