Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(connector-sawtooth-socketio): fix strict flag warnings #2109

Merged
merged 1 commit into from
Jul 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ server.on("listening", onListening);
* Normalize a port into a number, string, or false.
*/

function normalizePort(val) {
function normalizePort(val: string) {
const port = parseInt(val, 10);

if (isNaN(port)) {
Expand All @@ -85,7 +85,7 @@ function normalizePort(val) {
* Event listener for HTTPS server "error" event.
*/

function onError(error) {
function onError(error: any) {
if (error.syscall !== "listen") {
throw error;
}
Expand Down Expand Up @@ -114,6 +114,12 @@ function onError(error) {

function onListening() {
const addr = server.address();

if (!addr) {
logger.error("Could not get running server address - exit.");
process.exit(1);
}

const bind = typeof addr === "string" ? "pipe " + addr : "port " + addr.port;
debug("Listening on " + bind);
}
Expand All @@ -125,8 +131,7 @@ io.on("connection", function (client) {
* startMonitor: starting block generation event monitoring
**/
client.on("startMonitor", function (data) {
// Callback to receive monitoring results
const cb = function (callbackData) {
Smonitor.startMonitor(client.id, data.filterKey, (callbackData) => {
let emitType = "";
if (callbackData.status == 200) {
emitType = "eventReceived";
Expand All @@ -135,8 +140,6 @@ io.on("connection", function (client) {
emitType = "monitor_error";
}
client.emit(emitType, callbackData);
};

Smonitor.startMonitor(client.id, data.filterKey, cb);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const cbor = require("cbor");
* 3.78*10^14
* 3.78e14
*/
exports.convNum = function (value, defaultValue) {
exports.convNum = function convNum(value: number | string, defaultValue: number | string) {
let retValue = 0;
let defValue = 0;

Expand Down Expand Up @@ -71,7 +71,7 @@ exports.convNum = function (value, defaultValue) {
return retValue;
};

exports.convertBlockNumber = function (value) {
exports.convertBlockNumber = function (value: number) {
return "0x" + ("0000000000000000" + value.toString(16)).substr(-16);
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ logger.level = config.read("logLevel", "info");
import { ValidatorAuthentication } from "./ValidatorAuthentication";
const XMLHttpRequest = require("xmlhttprequest").XMLHttpRequest;

export type MonitorCallback = (callback: {
status: number;
blockData: string;
}) => void;

/*
* ServerMonitorPlugin
* Class definitions of server monitoring
Expand All @@ -46,7 +51,7 @@ export class ServerMonitorPlugin {
* @param {string} filterKey: Key to filter blocks
* @param {function} cb: A callback function that receives monitoring results at any time.
*/
startMonitor(clientId, filterKey, cb) {
startMonitor(clientId: string, filterKey: string, cb: MonitorCallback) {
logger.info("*** START MONITOR ***");
logger.info("Client ID :" + clientId);
logger.debug(`filterKey = ${filterKey}`);
Expand Down Expand Up @@ -75,7 +80,7 @@ export class ServerMonitorPlugin {
* @param {string} filterKey: Key to filter blocks
* @param {function} cb: A callback function that receives monitoring results at any time.
*/
periodicMonitoring(clientId, filterKey, cb) {
periodicMonitoring(clientId: string, filterKey: string, cb: MonitorCallback) {
logger.info("*** START PERIODIC MONITORING ***");

const that = this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"tsBuildInfoFile": "../../.build-cache/cactus-plugin-ledger-connector-sawtooth-socketio.tsbuildinfo",
"strict": false // TODO - True, fix warnings
},
"include": [
"./src/main/typescript/common/core/*.ts",
Expand Down