workers: client and server parser refactor.
This commit is contained in:
parent
a4d30f00a8
commit
1f47d5ead5
@ -9,7 +9,6 @@
|
||||
|
||||
var EventEmitter = require('events').EventEmitter;
|
||||
var util = require('../utils/util');
|
||||
var global = util.global;
|
||||
var Network = require('../protocol/network');
|
||||
var jobs = require('./jobs');
|
||||
var Parser = require('./parser-client');
|
||||
|
||||
@ -8,6 +8,7 @@
|
||||
'use strict';
|
||||
|
||||
var util = require('../utils/util');
|
||||
var packets = require('./packets');
|
||||
var ServerParser = require('./parser');
|
||||
var MTX = require('../primitives/mtx');
|
||||
var TX = require('../primitives/tx');
|
||||
@ -23,14 +24,39 @@ function Parser() {
|
||||
return new Parser();
|
||||
|
||||
ServerParser.call(this);
|
||||
|
||||
this.TX = TX;
|
||||
this.MTX = MTX;
|
||||
this.KeyRing = KeyRing;
|
||||
}
|
||||
|
||||
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, 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
|
||||
*/
|
||||
|
||||
@ -27,10 +27,6 @@ function Parser() {
|
||||
this.header = null;
|
||||
this.pending = [];
|
||||
this.total = 0;
|
||||
|
||||
this.TX = null;
|
||||
this.MTX = null;
|
||||
this.KeyRing = null;
|
||||
}
|
||||
|
||||
util.inherits(Parser, EventEmitter);
|
||||
@ -144,36 +140,22 @@ Parser.prototype.parsePacket = function parsePacket(header, data) {
|
||||
return packets.LogPacket.fromRaw(data);
|
||||
case packets.types.ERROR:
|
||||
return packets.ErrorPacket.fromRaw(data);
|
||||
case packets.types.VERIFY:
|
||||
return packets.VerifyPacket.fromRaw(this.TX, data);
|
||||
case packets.types.ERRORRESULT:
|
||||
return packets.ErrorResultPacket.fromRaw(data);
|
||||
case packets.types.VERIFYRESULT:
|
||||
return packets.VerifyResultPacket.fromRaw(data);
|
||||
case packets.types.SIGN:
|
||||
return packets.SignPacket.fromRaw(this.MTX, this.KeyRing, data);
|
||||
case packets.types.SIGNRESULT:
|
||||
return packets.SignResultPacket.fromRaw(data);
|
||||
case packets.types.VERIFYINPUT:
|
||||
return packets.VerifyInputPacket.fromRaw(this.TX, data);
|
||||
case packets.types.VERIFYINPUTRESULT:
|
||||
return packets.VerifyInputResultPacket.fromRaw(data);
|
||||
case packets.types.SIGNINPUT:
|
||||
return packets.SignInputPacket.fromRaw(this.MTX, this.KeyRing, 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:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user