resolve conflict in api and saga
This commit is contained in:
parent
e9ec0c019d
commit
324e148fa6
|
@ -62,45 +62,45 @@ class ConsoleListener {
|
||||||
_listenForLogRequests() {
|
_listenForLogRequests() {
|
||||||
if (this.ipc.ipcRole !== 'server') return;
|
if (this.ipc.ipcRole !== 'server') return;
|
||||||
this.ipc.on('log', (request) => {
|
this.ipc.on('log', (request) => {
|
||||||
if (request.type === 'contract-log') {
|
if (request.type !== 'contract-log') {
|
||||||
if (!this.contractsDeployed) return;
|
return this.logger.info(JSON.stringify(request));
|
||||||
|
|
||||||
let {address, data, transactionHash, blockNumber, gasUsed, status} = request;
|
|
||||||
const contract = this.addressToContract[address];
|
|
||||||
|
|
||||||
if (!contract) {
|
|
||||||
this._updateContractList();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const {name, silent} = contract;
|
|
||||||
if (silent && !this.outputDone) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const func = contract.functions[data.substring(0, 10)];
|
|
||||||
const functionName = func.functionName;
|
|
||||||
|
|
||||||
const decodedParameters = utils.decodeParams(func.abi.inputs, data.substring(10));
|
|
||||||
let paramString = "";
|
|
||||||
if (func.abi.inputs) {
|
|
||||||
func.abi.inputs.forEach((input) => {
|
|
||||||
let quote = input.type.indexOf("int") === -1 ? '"' : '';
|
|
||||||
paramString += quote + decodedParameters[input.name] + quote + ", ";
|
|
||||||
});
|
|
||||||
paramString = paramString.substring(0, paramString.length - 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
gasUsed = utils.hexToNumber(gasUsed);
|
|
||||||
blockNumber = utils.hexToNumber(blockNumber);
|
|
||||||
|
|
||||||
this.logs.push(Object.assign({}, request, {name, functionName, paramString, gasUsed, blockNumber}));
|
|
||||||
this.events.emit('contracts:log', this.logs[this.logs.length - 1]);
|
|
||||||
|
|
||||||
this.logger.info(`Blockchain>`.underline + ` ${name}.${functionName}(${paramString})`.bold + ` | ${transactionHash} | gas:${gasUsed} | blk:${blockNumber} | status:${status}`);
|
|
||||||
} else {
|
|
||||||
this.logger.info(JSON.stringify(request));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!this.contractsDeployed) return;
|
||||||
|
|
||||||
|
let {address, data, transactionHash, blockNumber, gasUsed, status} = request;
|
||||||
|
const contract = this.addressToContract[address];
|
||||||
|
|
||||||
|
if (!contract) {
|
||||||
|
this._updateContractList();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const {name, silent} = contract;
|
||||||
|
if (silent && !this.outputDone) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const func = contract.functions[data.substring(0, 10)];
|
||||||
|
const functionName = func.functionName;
|
||||||
|
|
||||||
|
const decodedParameters = utils.decodeParams(func.abi.inputs, data.substring(10));
|
||||||
|
let paramString = "";
|
||||||
|
if (func.abi.inputs) {
|
||||||
|
func.abi.inputs.forEach((input) => {
|
||||||
|
let quote = input.type.indexOf("int") === -1 ? '"' : '';
|
||||||
|
paramString += quote + decodedParameters[input.name] + quote + ", ";
|
||||||
|
});
|
||||||
|
paramString = paramString.substring(0, paramString.length - 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
gasUsed = utils.hexToNumber(gasUsed);
|
||||||
|
blockNumber = utils.hexToNumber(blockNumber);
|
||||||
|
|
||||||
|
this.logs.push(Object.assign({}, request, {name, functionName, paramString, gasUsed, blockNumber}));
|
||||||
|
this.events.emit('contracts:log', this.logs[this.logs.length - 1]);
|
||||||
|
|
||||||
|
this.logger.info(`Blockchain>`.underline + ` ${name}.${functionName}(${paramString})`.bold + ` | ${transactionHash} | gas:${gasUsed} | blk:${blockNumber} | status:${status}`);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,6 +55,7 @@ class Server {
|
||||||
const main = serveStatic(this.buildDir, {'index': ['index.html', 'index.htm']});
|
const main = serveStatic(this.buildDir, {'index': ['index.html', 'index.htm']});
|
||||||
|
|
||||||
this.app = express();
|
this.app = express();
|
||||||
|
const expressWs = expressWebSocket(this.app);
|
||||||
// Assign Logging Function
|
// Assign Logging Function
|
||||||
this.app.use(function(req, res, next) {
|
this.app.use(function(req, res, next) {
|
||||||
if (self.logging) {
|
if (self.logging) {
|
||||||
|
@ -64,7 +65,6 @@ class Server {
|
||||||
}
|
}
|
||||||
next();
|
next();
|
||||||
});
|
});
|
||||||
expressWebSocket(this.app);
|
|
||||||
|
|
||||||
this.app.use(helmet.noCache());
|
this.app.use(helmet.noCache());
|
||||||
this.app.use(cors());
|
this.app.use(cors());
|
||||||
|
@ -97,16 +97,15 @@ class Server {
|
||||||
this.app[apiCall.method].apply(this.app, [apiCall.endpoint, this.applyAPIFunction.bind(this, apiCall.cb)]);
|
this.app[apiCall.method].apply(this.app, [apiCall.endpoint, this.applyAPIFunction.bind(this, apiCall.cb)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
const wss = expressWs.getWss('/');
|
||||||
|
|
||||||
this.app.ws('/', function(ws, _req) {
|
self.events.on('outputDone', () => {
|
||||||
self.events.on('outputDone', () => {
|
wss.clients.forEach(function (client) {
|
||||||
if (ws.readyState === WEB_SOCKET_STATE_OPEN) {
|
client.send('outputDone');
|
||||||
return ws.send('outputDone');
|
});
|
||||||
}
|
self.events.on('outputError', () => {
|
||||||
// if the socket wasn't yet opened, listen for the 'open' event,
|
wss.clients.forEach(function (client) {
|
||||||
// then send the 'outputDone' data
|
client.send('outputError');
|
||||||
ws.addEventListener('open', _event => {
|
|
||||||
ws.send('outputDone');
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -164,7 +163,13 @@ class Server {
|
||||||
}
|
}
|
||||||
|
|
||||||
applyAPIFunction (cb, req, res) {
|
applyAPIFunction (cb, req, res) {
|
||||||
this.events.request('authenticator:authorize', req.headers.authorization, (err) => {
|
// FIXME Need to not authenticate WS request as they do not pass the toekn in the header yet
|
||||||
|
const authToken = (!res.send) ? req.protocol : req.headers.authorization;
|
||||||
|
if (!res.send) {
|
||||||
|
// console.dir(arguments);
|
||||||
|
return cb(req, res);
|
||||||
|
}
|
||||||
|
this.events.request('authenticator:authorize', authToken, (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
const send = res.send ? res.send.bind(res) : req.send.bind(req); // WS only has the first params
|
const send = res.send ? res.send.bind(res) : req.send.bind(req); // WS only has the first params
|
||||||
return send(err);
|
return send(err);
|
||||||
|
|
Loading…
Reference in New Issue