Skip to content
This repository was archived by the owner on Apr 27, 2021. It is now read-only.

Commit 280400e

Browse files
authored
Merge pull request #8 from Alethio/v1.4.1
V1.4.1
2 parents 7c4e4a5 + 69b346e commit 280400e

7 files changed

Lines changed: 694 additions & 633 deletions

File tree

.env.sample

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,9 @@ KOHERA_DB_REQUEST_TIMEOUT=100
9191
KOHERA_API_REQUEST_TIMEOUT=100
9292
KOHERA_QUEUE_REQUEST_TIMEOUT=50
9393

94-
INFURA_API_URL=https://api.infura.io/v1/jsonrpc
95-
INFURA_API_KEY=
94+
INFURA_URL=infura.io/v3
95+
INFURA_PROJECT_ID=
96+
INFURA_PROJECT_SECRET=
9697

9798
ETHSTATS_BLOB_API_URL=https://blob-api.ethstats.io/v1
9899
ETHSTATS_BLOB_API_KEY=

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
# Changelog
22
All notable changes to this project will be documented in this file.
33

4+
## [1.4.1] - 2019-04-01
5+
- Remove "sprintf" npm package due to memory leaks
6+
- Update Infura library to use latest v3 API
7+
- Update npm dependent packages to latest versions
8+
49
## [1.4.0] - 2019-03-14
510
- Add support for PostgreSQL
611
- Add docker compose example for cluster mode with PostgreSQL persistence

app/bootstrap.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import dotenv from 'dotenv';
66
import lodash from 'lodash';
77
import meow from 'meow';
88
import chalk from 'chalk';
9-
import sprintfJS from 'sprintf-js';
109
import Cassandra from 'cassandra-driver';
1110
import Postgres from 'pg';
1211
import Redis from 'ioredis';
@@ -48,7 +47,6 @@ const diContainer = {
4847
lodash,
4948
meow,
5049
chalk,
51-
sprintfJS,
5250
geoIp,
5351
d3,
5452
bigNumberUtils

app/lib/Infura.js

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,25 +9,27 @@ export default class Infura {
99
this.bigNumberUtils = diContainer.bigNumberUtils;
1010

1111
this.network = this.appConfig.NETWORK;
12-
this.apiUrl = this.appConfig.INFURA_API_URL;
13-
this.apiKey = this.appConfig.INFURA_API_KEY;
12+
this.url = this.appConfig.INFURA_URL;
13+
this.projectId = this.appConfig.INFURA_PROJECT_ID;
14+
this.projectSecret = this.appConfig.INFURA_PROJECT_SECRET;
1415
}
1516

16-
get(params) {
17+
request(jsonRpcObject) {
1718
let requestOptions = {
18-
method: 'GET',
19-
uri: `${this.apiUrl}/${this.network}/${params.method}?token=${this.apiKey}`,
20-
json: true
19+
method: 'POST',
20+
headers: {
21+
Authorization: `Basic ${Buffer.from(':' + this.projectSecret).toString('base64')}`
22+
},
23+
uri: `https://${this.network}.${this.url}/${this.projectId}`,
24+
json: false,
25+
body: JSON.stringify(jsonRpcObject)
2126
};
2227

23-
if (params.params) {
24-
requestOptions.uri += `&params=${params.params}`;
25-
}
26-
2728
this.log.debug(`Infura request: ${JSON.stringify(requestOptions)}`);
2829

2930
return this.requestPromise(requestOptions).then(requestResult => {
3031
let result = null;
32+
requestResult = JSON.parse(requestResult);
3133

3234
if (requestResult.error) {
3335
this.log.error(`Infura => ${requestResult.error.message}`);
@@ -37,25 +39,29 @@ export default class Infura {
3739

3840
return result;
3941
}).catch(error => {
40-
let errorMessage = this.lodash.isObject(error.error) ? ((error.error.body === undefined) ? error.error : error.error.body.errors[0]) : error.message;
41-
this.log.error(`Infura => ${errorMessage}`);
42+
this.log.error(`Infura => ${JSON.stringify(error)}`);
4243
});
4344
}
4445

4546
getBlockByNumber(number) {
46-
let requestParams = {
47+
let jsonRpcObject = {
48+
jsonrpc: '2.0',
4749
method: 'eth_getBlockByNumber',
48-
params: `["${this.bigNumberUtils.getHex(number, true)}",true]`
50+
params: [this.bigNumberUtils.getHex(number, true), false],
51+
id: 1
4952
};
5053

51-
return this.get(requestParams);
54+
return this.request(jsonRpcObject);
5255
}
5356

5457
getLastBlockNumber() {
55-
let requestParams = {
56-
method: 'eth_blockNumber'
58+
let jsonRpcObject = {
59+
jsonrpc: '2.0',
60+
method: 'eth_blockNumber',
61+
params: [],
62+
id: 1
5763
};
5864

59-
return this.get(requestParams);
65+
return this.request(jsonRpcObject);
6066
}
6167
}

app/lib/Logger.js

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ export default class Logger {
22
constructor(diContainer) {
33
this.appConfig = diContainer.appConfig;
44
this.chalk = diContainer.chalk;
5-
this.sprintf = diContainer.sprintfJS.sprintf;
65
this.prometheusMetrics = null;
76

87
this.showDateTime = this.appConfig.LOG_SHOW_DATETIME;
@@ -15,7 +14,7 @@ export default class Logger {
1514

1615
_log(type, string) {
1716
let dateTime = new Date().toISOString().replace('T', ' ').replace('Z', '');
18-
let resultString = `${(this.showDateTime) ? dateTime + ' - ' : ''}%s: ${string}`;
17+
let resultString = `${(this.showDateTime) ? dateTime + ' - ' : ''}%LOG-TYPE%: ${string}`;
1918

2019
if (this.showAsJson) {
2120
let output = {
@@ -30,16 +29,16 @@ export default class Logger {
3029
console.log(string);
3130
break;
3231
case 'info':
33-
console.log(this.chalk.white(this.sprintf(resultString, 'INFO')));
32+
console.log(this.chalk.white(resultString.replace('%LOG-TYPE%', 'INFO')));
3433
break;
3534
case 'debug':
36-
console.log(this.chalk.cyan(this.sprintf(resultString, 'DEBUG')));
35+
console.log(this.chalk.cyan(resultString.replace('%LOG-TYPE%', 'DEBUG')));
3736
break;
3837
case 'warning':
39-
console.log(this.chalk.yellow(this.sprintf(resultString, 'WARNING')));
38+
console.log(this.chalk.yellow(resultString.replace('%LOG-TYPE%', 'WARNING')));
4039
break;
4140
case 'error':
42-
console.log(this.chalk.red(this.sprintf(resultString, 'ERROR')));
41+
console.log(this.chalk.red(resultString.replace('%LOG-TYPE%', 'ERROR')));
4342
break;
4443
default:
4544
console.log('Logger: Unknown type');

0 commit comments

Comments
 (0)