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 EventEmitter = require('events').EventEmitter;
|
||||||
var util = require('../utils/util');
|
var util = require('../utils/util');
|
||||||
var global = util.global;
|
|
||||||
var Network = require('../protocol/network');
|
var Network = require('../protocol/network');
|
||||||
var jobs = require('./jobs');
|
var jobs = require('./jobs');
|
||||||
var Parser = require('./parser-client');
|
var Parser = require('./parser-client');
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var util = require('../utils/util');
|
var util = require('../utils/util');
|
||||||
|
var packets = require('./packets');
|
||||||
var ServerParser = require('./parser');
|
var ServerParser = require('./parser');
|
||||||
var MTX = require('../primitives/mtx');
|
var MTX = require('../primitives/mtx');
|
||||||
var TX = require('../primitives/tx');
|
var TX = require('../primitives/tx');
|
||||||
@ -23,14 +24,39 @@ function Parser() {
|
|||||||
return new Parser();
|
return new Parser();
|
||||||
|
|
||||||
ServerParser.call(this);
|
ServerParser.call(this);
|
||||||
|
|
||||||
this.TX = TX;
|
|
||||||
this.MTX = MTX;
|
|
||||||
this.KeyRing = KeyRing;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
util.inherits(Parser, ServerParser);
|
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
|
* Expose
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -27,10 +27,6 @@ function Parser() {
|
|||||||
this.header = null;
|
this.header = null;
|
||||||
this.pending = [];
|
this.pending = [];
|
||||||
this.total = 0;
|
this.total = 0;
|
||||||
|
|
||||||
this.TX = null;
|
|
||||||
this.MTX = null;
|
|
||||||
this.KeyRing = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
util.inherits(Parser, EventEmitter);
|
util.inherits(Parser, EventEmitter);
|
||||||
@ -144,36 +140,22 @@ Parser.prototype.parsePacket = function parsePacket(header, data) {
|
|||||||
return packets.LogPacket.fromRaw(data);
|
return packets.LogPacket.fromRaw(data);
|
||||||
case packets.types.ERROR:
|
case packets.types.ERROR:
|
||||||
return packets.ErrorPacket.fromRaw(data);
|
return packets.ErrorPacket.fromRaw(data);
|
||||||
case packets.types.VERIFY:
|
case packets.types.ERRORRESULT:
|
||||||
return packets.VerifyPacket.fromRaw(this.TX, data);
|
return packets.ErrorResultPacket.fromRaw(data);
|
||||||
case packets.types.VERIFYRESULT:
|
case packets.types.VERIFYRESULT:
|
||||||
return packets.VerifyResultPacket.fromRaw(data);
|
return packets.VerifyResultPacket.fromRaw(data);
|
||||||
case packets.types.SIGN:
|
|
||||||
return packets.SignPacket.fromRaw(this.MTX, this.KeyRing, data);
|
|
||||||
case packets.types.SIGNRESULT:
|
case packets.types.SIGNRESULT:
|
||||||
return packets.SignResultPacket.fromRaw(data);
|
return packets.SignResultPacket.fromRaw(data);
|
||||||
case packets.types.VERIFYINPUT:
|
|
||||||
return packets.VerifyInputPacket.fromRaw(this.TX, data);
|
|
||||||
case packets.types.VERIFYINPUTRESULT:
|
case packets.types.VERIFYINPUTRESULT:
|
||||||
return packets.VerifyInputResultPacket.fromRaw(data);
|
return packets.VerifyInputResultPacket.fromRaw(data);
|
||||||
case packets.types.SIGNINPUT:
|
|
||||||
return packets.SignInputPacket.fromRaw(this.MTX, this.KeyRing, data);
|
|
||||||
case packets.types.SIGNINPUTRESULT:
|
case packets.types.SIGNINPUTRESULT:
|
||||||
return packets.SignInputResultPacket.fromRaw(data);
|
return packets.SignInputResultPacket.fromRaw(data);
|
||||||
case packets.types.ECVERIFY:
|
|
||||||
return packets.ECVerifyPacket.fromRaw(data);
|
|
||||||
case packets.types.ECVERIFYRESULT:
|
case packets.types.ECVERIFYRESULT:
|
||||||
return packets.ECVerifyResultPacket.fromRaw(data);
|
return packets.ECVerifyResultPacket.fromRaw(data);
|
||||||
case packets.types.ECSIGN:
|
|
||||||
return packets.ECSignPacket.fromRaw(data);
|
|
||||||
case packets.types.ECSIGNRESULT:
|
case packets.types.ECSIGNRESULT:
|
||||||
return packets.ECSignResultPacket.fromRaw(data);
|
return packets.ECSignResultPacket.fromRaw(data);
|
||||||
case packets.types.MINE:
|
|
||||||
return packets.MinePacket.fromRaw(data);
|
|
||||||
case packets.types.MINERESULT:
|
case packets.types.MINERESULT:
|
||||||
return packets.MineResultPacket.fromRaw(data);
|
return packets.MineResultPacket.fromRaw(data);
|
||||||
case packets.types.SCRYPT:
|
|
||||||
return packets.ScryptPacket.fromRaw(data);
|
|
||||||
case packets.types.SCRYPTRESULT:
|
case packets.types.SCRYPTRESULT:
|
||||||
return packets.ScryptResultPacket.fromRaw(data);
|
return packets.ScryptResultPacket.fromRaw(data);
|
||||||
default:
|
default:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user