Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Commit

Permalink
🚀 Fixed linting issues and updated Readme
Browse files Browse the repository at this point in the history
  • Loading branch information
vardan10 committed Jul 25, 2023
1 parent 195d0ac commit 004b84d
Show file tree
Hide file tree
Showing 9 changed files with 14 additions and 12 deletions.
6 changes: 3 additions & 3 deletions services/blockchain-indexer/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ A list of the most commonly used environment variables is presented below:
- `ENABLE_DATA_RETRIEVAL_MODE`: Boolean flag to enable the Data Service mode.
- `ENABLE_INDEXING_MODE`: Boolean flag to enable the Data Indexing mode.
- `ENABLE_PERSIST_EVENTS`: Boolean flag to permanently maintain the events in the MySQL database.
- `ENABLE_APPLY_SNAPSHOT`: Boolean flag to enable initializing database with a snapshot.
- `INDEX_SNAPSHOT_URL`: URL from where the database snapshot will be downloaded.
- `ENABLE_SNAPSHOT_ALLOW_INSECURE_HTTP`: Boolean flag to enable downloading snapshot from a (unsecured) HTTP URL.
- `ENABLE_APPLY_SNAPSHOT`: Boolean flag to enable initialization of the index with the Lisk Service DB snapshot.
- `INDEX_SNAPSHOT_URL`: URL from where the Lisk Service DB snapshot will be downloaded.
- `ENABLE_SNAPSHOT_ALLOW_INSECURE_HTTP`: Boolean flag to enable downloading snapshot from an (unsecured) HTTP URL.
- `LISK_STATIC`: URL of Lisk static assets.
- `SERVICE_INDEXER_CACHE_REDIS`: URL of the cache storage (Redis).
- `JOB_INTERVAL_DELETE_SERIALIZED_EVENTS`: Job run interval to delete serialized events. By default, it is set to 0.
Expand Down
2 changes: 1 addition & 1 deletion services/blockchain-indexer/shared/utils/requestAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,4 @@ const requestAll = async (fn, method, params, limit) => {
return totalResponse;
};

module.exports = requestAll;
module.exports = requestAll;
6 changes: 4 additions & 2 deletions services/blockchain-indexer/shared/utils/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ const logger = Logger();

let snapshotFilePath = './data/service-snapshot.sql';
const MYSQL_ENDPOINT = config.endpoints.mysql;
const PRIVATE_IP_REGEX = /^(10(\.\d{1,3}){3})|((172\.(1[6-9]|2\d|3[0-1])|192\.168)(\.\d{1,3}){2})$/;

const getHTTPProtocolByURL = (url) => url.startsWith('https') ? https : http;

Expand All @@ -55,7 +56,7 @@ const calculateSHA256 = async (file) => new Promise((resolve, reject) => {
});

// Check if the IP address is local/private
const isLocalIP = (ip) => ip === '127.0.0.1' || ip.startsWith('10.') || ip.startsWith('192.168.');
const isLocalIP = (ip) => ip === '127.0.0.1' || PRIVATE_IP_REGEX.test(ip);

const validateSnapshotURL = async (snapshotURL) => {
const { hostname } = new URL(snapshotURL);
Expand Down Expand Up @@ -86,6 +87,8 @@ const validateSnapshotURL = async (snapshotURL) => {
};

const downloadUnzipAndVerifyChecksum = async (fileUrl, filePath) => {
await validateSnapshotURL(fileUrl);

const checksumUrl = fileUrl.replace('.gz', '.SHA256');

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -209,7 +212,6 @@ const initSnapshot = async () => {
throw new Error(`Please consider using a secured source (HTTPS). To continue to download snapshot from ${snapshotUrl}, set 'ENABLE_SNAPSHOT_ALLOW_INSECURE_HTTP' env variable.`);
}

await validateSnapshotURL(snapshotUrl);
await downloadSnapshot(snapshotUrl);
await applySnapshot();
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ xdescribe('Test requestAll method', () => {
it('should throw error -> null method', async () => {
expect(() => requestAll(request.requestConnector, null, {})).rejects.toThrow();
});
});
});
2 changes: 1 addition & 1 deletion services/export/shared/helpers/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ const list = (dirPath, count = 100, page = 0) => new Promise((resolve, reject) =
});

const purge = async (dirPath, days) => {
if (days === undefined) throw new ValidationException('days cannot be undefined');
if (days === undefined) throw new ValidationException('days cannot be undefined.');

try {
// Get the list of files in the directory using getFiles method
Expand Down
2 changes: 1 addition & 1 deletion services/export/shared/requestAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ const requestAll = async (fn, params, limit) => {
return data;
};

module.exports = requestAll;
module.exports = requestAll;
2 changes: 1 addition & 1 deletion services/export/tests/unit/shared/requestAll.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,4 @@ describe('Test requestAll method', () => {
it('should throw error if passed function is undefined', async () => {
expect(async () => requestAll(undefined, { limit: 50, extra_param: 'extra_value' }, 20)).rejects.toThrow();
});
});
});
2 changes: 1 addition & 1 deletion services/transaction-statistics/shared/utils/requestAll.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@ const requestAll = async (fn, method, params, limit) => {
return data;
};

module.exports = requestAll;
module.exports = requestAll;
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@ xdescribe('Test requestAll method', () => {
it('should throw error -> null method', async () => {
expect(requestAll(request.requestIndexer, null, {})).rejects.toThrow();
});
});
});

0 comments on commit 004b84d

Please sign in to comment.