diff --git a/MonitorClient.js b/MonitorClient.js index 80c1682..e0087bd 100644 --- a/MonitorClient.js +++ b/MonitorClient.js @@ -526,8 +526,10 @@ class MonitorClient extends EventEmitter { throw new Error(errorMessages.no_pool_id); } let result = null; - const startTs = startTime ? Math.floor((Date.now() - startTime) / 1000) : 0; - const lastTs = state.lastTs ? Math.floor((Date.now() / 1000 - state.lastTs)) : 0; + if (startTime > 10000000000) startTime /= 1000; // JS ts protection; + const now = Date.now() / 1000; + const startTs = startTime ? Math.floor(now - startTime) : 0; + const lastTs = state.lastTs ? Math.floor(now - state.lastTs) : 0; const period = Math.min(Math.max(this.options.period, startTs, lastTs), 360000); const { apiKey, poolId } = this.credentials; const url = `${this.options.monitor}/${method}/${poolId}?apiKey=${apiKey}&period=${period}`; @@ -590,12 +592,13 @@ class MonitorClient extends EventEmitter { try { json = e.response.data ? e.response.data : JSON.parse(e.response.body); } catch (jsonException) { - // do nothing + this.log(`Impossible to parse JSON body: ${e.response.body}`); } if (json && json.error) { this.log(`Monitor API Error [code ${json.error.code}]: ${json.error.message}`); } } + this.log(e); throw new Error(`${url} POST ${errorMessages.request_failed} ${e.message}`); } return result; @@ -665,6 +668,7 @@ class MonitorClient extends EventEmitter { throw new Error(`${errorMessages.rq_unkonwn_method} ${method}`); } if (data && data.body) { + this.log(data.timings); result = JSON.parse(data.body); } break; diff --git a/README.md b/README.md index a195f49..5cb2064 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ monitorApp.init([ '0x0000000000000000000000000000000000000001', '0x0000000000000000000000000000000000000002', '0x0000000000000000000000000000000000000003' -]).then(() => monitorApp.watch((data) => console.log(data)); +]).then(() => monitorApp.watch((data) => console.log(data))); ``` Voila, now we can get and process all the new transactions and ERC-20 operations for the specified addresses using just a single npm library and Node.js. diff --git a/package-lock.json b/package-lock.json index b2876b0..602aa2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "eth-bulk-monitor-client-nodejs", - "version": "0.0.34", + "version": "0.0.38", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index db5c9eb..fdef283 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eth-bulk-monitor-client-nodejs", - "version": "0.0.34", + "version": "0.0.38", "description": "Ethplorer bulk Monitor API nodejs client", "main": "index.js", "devDependencies": {