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

help me #31

Open
wants to merge 10 commits into
base: dependabot/npm_and_yarn/axios-0.21.1
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions MonitorClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}`;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down