From 90f783fd05a799b1468d64eac95f114410a81edc Mon Sep 17 00:00:00 2001 From: Christopher Jeffrey Date: Wed, 5 Jul 2017 12:05:58 -0700 Subject: [PATCH] workers: remove parser-client. --- lib/workers/framer.js | 5 --- lib/workers/index.js | 3 -- lib/workers/master.js | 2 +- lib/workers/packets.js | 12 ++++--- lib/workers/parser-client.js | 66 ------------------------------------ lib/workers/parser.js | 16 +++++++++ 6 files changed, 25 insertions(+), 79 deletions(-) delete mode 100644 lib/workers/parser-client.js diff --git a/lib/workers/framer.js b/lib/workers/framer.js index 9afda782..e64b3134 100644 --- a/lib/workers/framer.js +++ b/lib/workers/framer.js @@ -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); diff --git a/lib/workers/index.js b/lib/workers/index.js index 21edc482..2ea36abd 100644 --- a/lib/workers/index.js +++ b/lib/workers/index.js @@ -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'); diff --git a/lib/workers/master.js b/lib/workers/master.js index 179fac25..28e35d3f 100644 --- a/lib/workers/master.js +++ b/lib/workers/master.js @@ -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'; diff --git a/lib/workers/packets.js b/lib/workers/packets.js index 2464be0a..1d801789 100644 --- a/lib/workers/packets.js +++ b/lib/workers/packets.js @@ -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(); diff --git a/lib/workers/parser-client.js b/lib/workers/parser-client.js deleted file mode 100644 index 69517fb7..00000000 --- a/lib/workers/parser-client.js +++ /dev/null @@ -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; diff --git a/lib/workers/parser.js b/lib/workers/parser.js index 829e1b5c..fa844ae8 100644 --- a/lib/workers/parser.js +++ b/lib/workers/parser.js @@ -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: