Skip to content

Commit aaecccb

Browse files
committed
chore: fix eslint
Signed-off-by: nikolay <[email protected]>
1 parent 2e9648a commit aaecccb

File tree

26 files changed

+399
-392
lines changed

26 files changed

+399
-392
lines changed

packages/relay/src/lib/clients/cache/localLRUCache.ts

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,10 @@ export class LocalLRUCache implements ICacheClient {
121121
const cache = this.getCacheInstance(key);
122122
const value = cache.get(prefixedKey);
123123
if (value !== undefined) {
124-
const censoredKey = key.replace(Utils.IP_ADDRESS_REGEX, '<REDACTED>');
125-
const censoredValue = JSON.stringify(value).replace(/"ipAddress":"[^"]+"/, '"ipAddress":"<REDACTED>"');
126124
if (this.logger.isLevelEnabled('trace')) {
127-
this.logger.trace(`Returning cached value ${censoredKey}:${censoredValue} on ${callingMethod} call`);
125+
const censoredKey = key.replace(Utils.IP_ADDRESS_REGEX, '<REDACTED>');
126+
const censoredValue = JSON.stringify(value).replace(/"ipAddress":"[^"]+"/, '"ipAddress":"<REDACTED>"');
127+
this.logger.trace('Returning cached value %s:%s on %s call', censoredKey, censoredValue, callingMethod);
128128
}
129129
return value;
130130
}
@@ -142,9 +142,8 @@ export class LocalLRUCache implements ICacheClient {
142142
const prefixedKey = this.prefixKey(key);
143143
const cache = this.getCacheInstance(key);
144144
const remainingTtl = cache.getRemainingTTL(prefixedKey); // in milliseconds
145-
if (this.logger.isLevelEnabled('trace')) {
146-
this.logger.trace(`returning remaining TTL ${key}:${remainingTtl} on ${callingMethod} call`);
147-
}
145+
this.logger.trace(`returning remaining TTL %s:%s on %s call`, key, remainingTtl, callingMethod);
146+
148147
return remainingTtl;
149148
}
150149

@@ -171,7 +170,7 @@ export class LocalLRUCache implements ICacheClient {
171170
const message = `Caching ${censoredKey}:${censoredValue} on ${callingMethod} for ${
172171
resolvedTtl > 0 ? `${resolvedTtl} ms` : 'indefinite time'
173172
}`;
174-
this.logger.trace(`${message} (cache size: ${this.cache.size}, max: ${this.options.max})`);
173+
this.logger.trace(`%s (cache size: %s, max: %s)`, message, this.cache.size, this.options.max);
175174
}
176175
}
177176

@@ -212,9 +211,9 @@ export class LocalLRUCache implements ICacheClient {
212211
*/
213212
public async delete(key: string, callingMethod: string): Promise<void> {
214213
const prefixedKey = this.prefixKey(key);
215-
if (this.logger.isLevelEnabled('trace')) {
216-
this.logger.trace(`delete cache for ${key} on ${callingMethod} call`);
217-
}
214+
215+
this.logger.trace(`delete cache for %s on %s call`, key, callingMethod);
216+
218217
const cache = this.getCacheInstance(key);
219218
cache.delete(prefixedKey);
220219
}
@@ -273,9 +272,8 @@ export class LocalLRUCache implements ICacheClient {
273272

274273
const matchingKeys = keys.filter((key) => regex.test(key));
275274

276-
if (this.logger.isLevelEnabled('trace')) {
277-
this.logger.trace(`retrieving keys matching ${pattern} on ${callingMethod} call`);
278-
}
275+
this.logger.trace(`retrieving keys matching %s on %s call`, pattern, callingMethod);
276+
279277
// Remove the prefix from the returned keys
280278
return matchingKeys.map((key) => key.substring(LocalLRUCache.CACHE_KEY_PREFIX.length));
281279
}

packages/relay/src/lib/clients/cache/redisCache.ts

Lines changed: 24 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export class RedisCache implements IRedisCacheClient {
8686
if (this.logger.isLevelEnabled('trace')) {
8787
const censoredKey = key.replace(Utils.IP_ADDRESS_REGEX, '<REDACTED>');
8888
const censoredValue = result.replace(/"ipAddress":"[^"]+"/, '"ipAddress":"<REDACTED>"');
89-
this.logger.trace(`Returning cached value ${censoredKey}:${censoredValue} on ${callingMethod} call`);
89+
this.logger.trace(`Returning cached value %s:%s on %s call`, censoredKey, censoredValue, callingMethod);
9090
}
9191
// TODO: add metrics
9292
return JSON.parse(result);
@@ -113,13 +113,13 @@ export class RedisCache implements IRedisCacheClient {
113113
await this.client.set(prefixedKey, serializedValue);
114114
}
115115

116-
const censoredKey = key.replace(Utils.IP_ADDRESS_REGEX, '<REDACTED>');
117-
const censoredValue = serializedValue.replace(/"ipAddress":"[^"]+"/, '"ipAddress":"<REDACTED>"');
118-
const message = `Caching ${censoredKey}:${censoredValue} on ${callingMethod} for ${
119-
resolvedTtl > 0 ? `${resolvedTtl} ms` : 'indefinite time'
120-
}`;
121116
if (this.logger.isLevelEnabled('trace')) {
122-
this.logger.trace(`${message}`);
117+
const censoredKey = key.replace(Utils.IP_ADDRESS_REGEX, '<REDACTED>');
118+
const censoredValue = serializedValue.replace(/"ipAddress":"[^"]+"/, '"ipAddress":"<REDACTED>"');
119+
const message = `Caching ${censoredKey}:${censoredValue} on ${callingMethod} for ${
120+
resolvedTtl > 0 ? `${resolvedTtl} ms` : 'indefinite time'
121+
}`;
122+
this.logger.trace(`%s`, message);
123123
}
124124
// TODO: add metrics
125125
}
@@ -143,9 +143,12 @@ export class RedisCache implements IRedisCacheClient {
143143
await this.client.mSet(serializedKeyValuePairs);
144144

145145
// Log the operation
146-
const entriesLength = Object.keys(keyValuePairs).length;
147146
if (this.logger.isLevelEnabled('trace')) {
148-
this.logger.trace(`caching multiple keys via ${callingMethod}, total keys: ${entriesLength}`);
147+
this.logger.trace(
148+
`caching multiple keys via %s, total keys: %s`,
149+
callingMethod,
150+
Object.keys(keyValuePairs).length,
151+
);
149152
}
150153
}
151154

@@ -171,10 +174,13 @@ export class RedisCache implements IRedisCacheClient {
171174
// Execute pipeline operation
172175
await pipeline.execAsPipeline();
173176

177+
// Log the operation
174178
if (this.logger.isLevelEnabled('trace')) {
175-
// Log the operation
176-
const entriesLength = Object.keys(keyValuePairs).length;
177-
this.logger.trace(`caching multiple keys via ${callingMethod}, total keys: ${entriesLength}`);
179+
this.logger.trace(
180+
`caching multiple keys via %s, total keys: %s`,
181+
callingMethod,
182+
Object.keys(keyValuePairs).length,
183+
);
178184
}
179185
}
180186

@@ -188,9 +194,7 @@ export class RedisCache implements IRedisCacheClient {
188194
async delete(key: string, callingMethod: string): Promise<void> {
189195
const prefixedKey = this.prefixKey(key);
190196
await this.client.del(prefixedKey);
191-
if (this.logger.isLevelEnabled('trace')) {
192-
this.logger.trace(`delete cache for ${key} on ${callingMethod} call`);
193-
}
197+
this.logger.trace(`delete cache for %s on %s call`, key, callingMethod);
194198
// TODO: add metrics
195199
}
196200

@@ -205,9 +209,7 @@ export class RedisCache implements IRedisCacheClient {
205209
async incrBy(key: string, amount: number, callingMethod: string): Promise<number> {
206210
const prefixedKey = this.prefixKey(key);
207211
const result = await this.client.incrBy(prefixedKey, amount);
208-
if (this.logger.isLevelEnabled('trace')) {
209-
this.logger.trace(`incrementing ${key} by ${amount} on ${callingMethod} call`);
210-
}
212+
this.logger.trace(`incrementing %s by %s on %s call`, key, amount, callingMethod);
211213
return result;
212214
}
213215

@@ -223,9 +225,7 @@ export class RedisCache implements IRedisCacheClient {
223225
async lRange(key: string, start: number, end: number, callingMethod: string): Promise<any[]> {
224226
const prefixedKey = this.prefixKey(key);
225227
const result = await this.client.lRange(prefixedKey, start, end);
226-
if (this.logger.isLevelEnabled('trace')) {
227-
this.logger.trace(`retrieving range [${start}:${end}] from ${key} on ${callingMethod} call`);
228-
}
228+
this.logger.trace(`retrieving range [%s:%s] from %s on %s call`, start, end, key, callingMethod);
229229
return result.map((item) => JSON.parse(item));
230230
}
231231

@@ -242,7 +242,7 @@ export class RedisCache implements IRedisCacheClient {
242242
const serializedValue = JSON.stringify(value);
243243
const result = await this.client.rPush(prefixedKey, serializedValue);
244244
if (this.logger.isLevelEnabled('trace')) {
245-
this.logger.trace(`pushing ${serializedValue} to ${key} on ${callingMethod} call`);
245+
this.logger.trace(`pushing %s to %s on %s call`, serializedValue, key, callingMethod);
246246
}
247247
return result;
248248
}
@@ -256,9 +256,7 @@ export class RedisCache implements IRedisCacheClient {
256256
async keys(pattern: string, callingMethod: string): Promise<string[]> {
257257
const prefixedPattern = this.prefixKey(pattern);
258258
const result = await this.client.keys(prefixedPattern);
259-
if (this.logger.isLevelEnabled('trace')) {
260-
this.logger.trace(`retrieving keys matching ${pattern} on ${callingMethod} call`);
261-
}
259+
this.logger.trace(`retrieving keys matching %s on %s call`, pattern, callingMethod);
262260
// Remove the prefix from the returned keys
263261
return result.map((key) => key.substring(RedisCache.CACHE_KEY_PREFIX.length));
264262
}
@@ -283,7 +281,7 @@ export class RedisCache implements IRedisCacheClient {
283281
await pipeline.exec();
284282

285283
if (this.logger.isLevelEnabled('trace')) {
286-
this.logger.trace(`Cleared ${keysToDelete.length} cache keys`);
284+
this.logger.trace(`Cleared %s cache keys`, keysToDelete.length);
287285
}
288286
}
289287
}

packages/relay/src/lib/clients/mirrorNodeClient.ts

Lines changed: 51 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ export class MirrorNodeClient {
225225
retryDelay: (retryCount, error) => {
226226
const delay = mirrorNodeRetryDelay * retryCount;
227227
if (this.logger.isLevelEnabled('trace')) {
228-
this.logger.trace(`Retry delay ${delay} ms on '${error?.request?.path}'`);
228+
this.logger.trace(`Retry delay %s ms on '%s'`, delay, error?.request?.path);
229229
}
230230
return delay;
231231
},
@@ -290,7 +290,9 @@ export class MirrorNodeClient {
290290
});
291291

292292
this.logger.info(
293-
`Mirror Node client successfully configured to REST url: ${this.restUrl} and Web3 url: ${this.web3Url} `,
293+
`Mirror Node client successfully configured to REST url: %s and Web3 url: %s `,
294+
this.restUrl,
295+
this.web3Url,
294296
);
295297
this.cacheService = cacheService;
296298

@@ -377,7 +379,7 @@ export class MirrorNodeClient {
377379
try {
378380
return JSONBigInt.parse(data);
379381
} catch (error) {
380-
this.logger.warn(`Failed to parse response data from Mirror Node: ${error}`);
382+
this.logger.warn(`Failed to parse response data from Mirror Node: %s`, error);
381383
}
382384
}
383385

@@ -394,9 +396,12 @@ export class MirrorNodeClient {
394396
const ms = Date.now() - start;
395397
if (this.logger.isLevelEnabled('debug')) {
396398
this.logger.debug(
397-
`Successfully received response from mirror node server: method=${method}, path=${path}, status=${
398-
response.status
399-
}, duration:${ms}ms, data:${JSON.stringify(response.data)}`,
399+
`Successfully received response from mirror node server: method=%s, path=%s, status=%s, duration:%sms, data:%s`,
400+
method,
401+
path,
402+
response.status,
403+
ms,
404+
JSON.stringify(response.data),
400405
);
401406
}
402407
this.mirrorResponseHistogram.labels(pathLabel, response.status?.toString()).observe(ms);
@@ -451,27 +456,35 @@ export class MirrorNodeClient {
451456
const acceptedErrorResponses = MirrorNodeClient.acceptedErrorStatusesResponsePerRequestPathMap.get(pathLabel);
452457

453458
if (error.response && acceptedErrorResponses?.includes(effectiveStatusCode)) {
454-
if (this.logger.isLevelEnabled('debug')) {
455-
this.logger.debug(
456-
`An accepted error occurred while communicating with the mirror node server: method=${method}, path=${path}, status=${effectiveStatusCode}`,
457-
);
458-
}
459+
this.logger.debug(
460+
`An accepted error occurred while communicating with the mirror node server: method=%s, path=%s, status=%s}`,
461+
method,
462+
path,
463+
effectiveStatusCode,
464+
);
459465
return null;
460466
}
461467

462468
// Contract Call returns 400 for a CONTRACT_REVERT but is a valid response, expected and should not be logged as error:
463469
if (pathLabel === MirrorNodeClient.CONTRACT_CALL_ENDPOINT && effectiveStatusCode === 400) {
464470
if (this.logger.isLevelEnabled('debug')) {
465471
this.logger.debug(
466-
`[${method}] ${path} Contract Revert: ( StatusCode: '${effectiveStatusCode}', StatusText: '${
467-
error.response.statusText
468-
}', Detail: '${JSON.stringify(error.response.detail)}',Data: '${JSON.stringify(error.response.data)}')`,
472+
`[%s] %s Contract Revert: ( StatusCode: '%s', StatusText: '%s', Detail: '%s',Data: '%s')`,
473+
method,
474+
path,
475+
effectiveStatusCode,
476+
error.response.statusText,
477+
JSON.stringify(error.response.detail),
478+
JSON.stringify(error.response.data),
469479
);
470480
}
471481
} else {
472482
this.logger.error(
473483
new Error(error.message),
474-
`Error encountered while communicating with the mirror node server: method=${method}, path=${path}, status=${effectiveStatusCode}`,
484+
`Error encountered while communicating with the mirror node server: method=%s, path=%s, status=%s`,
485+
method,
486+
path,
487+
effectiveStatusCode,
475488
);
476489
}
477490

@@ -497,7 +510,7 @@ export class MirrorNodeClient {
497510
if (page === pageMax) {
498511
// max page reached
499512
if (this.logger.isLevelEnabled('trace')) {
500-
this.logger.trace(`Max page reached ${pageMax} with ${results.length} results`);
513+
this.logger.trace(`Max page reached %s with %s results`, pageMax, results.length);
501514
}
502515
throw predefined.PAGINATION_MAX(pageMax);
503516
}
@@ -575,15 +588,15 @@ export class MirrorNodeClient {
575588
const match = url.match(regex);
576589
const accountId = match ? match[1] : null;
577590
if (!accountId) {
578-
this.logger.error(`Unable to extract evm address from url ${url}`);
591+
this.logger.error(`Unable to extract evm address from url %s`, url);
579592
}
580593
return String(accountId);
581594
} else {
582595
// account id
583596
const match = url.match(MirrorNodeClient.EVM_ADDRESS_REGEX);
584597
const accountId = match ? match[1] : null;
585598
if (!accountId) {
586-
this.logger.error(`Unable to extract account ID from url ${url}`);
599+
this.logger.error(`Unable to extract account ID from url %s`, url);
587600
}
588601
return String(accountId);
589602
}
@@ -802,9 +815,9 @@ export class MirrorNodeClient {
802815
// Found immature record, log the info, set flag and exit record traversal
803816
if (this.logger.isLevelEnabled('debug')) {
804817
this.logger.debug(
805-
`Contract result contains nullable transaction_index or block_number, or block_hash is an empty hex (0x): contract_result=${JSON.stringify(
806-
contractObject,
807-
)}. ${!isLastAttempt ? `Retrying after a delay of ${mirrorNodeRetryDelay} ms.` : ``}`,
818+
`Contract result contains nullable transaction_index or block_number, or block_hash is an empty hex (0x): contract_result=%s. %s}`,
819+
JSON.stringify(contractObject),
820+
!isLastAttempt ? `Retrying after a delay of ${mirrorNodeRetryDelay} ms.` : ``,
808821
);
809822
}
810823

@@ -991,9 +1004,9 @@ export class MirrorNodeClient {
9911004
// Found immature record, log the info, set flag and exit record traversal
9921005
if (this.logger.isLevelEnabled('debug')) {
9931006
this.logger.debug(
994-
`Contract result log contains nullable transaction_index, block_number, index, or block_hash is an empty hex (0x): log=${JSON.stringify(
995-
log,
996-
)}. ${!isLastAttempt ? `Retrying after a delay of ${mirrorNodeRetryDelay} ms.` : ``}`,
1007+
`Contract result log contains nullable transaction_index, block_number, index, or block_hash is an empty hex (0x): log=%s. %s`,
1008+
JSON.stringify(log),
1009+
!isLastAttempt ? `Retrying after a delay of ${mirrorNodeRetryDelay} ms.` : ``,
9971010
);
9981011
}
9991012

@@ -1484,7 +1497,9 @@ export class MirrorNodeClient {
14841497
} else {
14851498
this.logger.warn(
14861499
e,
1487-
`Error raised during polling mirror node for updated records: method=${methodName}, args=${args}`,
1500+
`Error raised during polling mirror node for updated records: method=%s, args=%s`,
1501+
methodName,
1502+
args,
14881503
);
14891504
}
14901505
}
@@ -1495,9 +1510,12 @@ export class MirrorNodeClient {
14951510

14961511
if (this.logger.isLevelEnabled('debug')) {
14971512
this.logger.debug(
1498-
`Repeating request ${methodName} with args ${JSON.stringify(
1499-
args,
1500-
)} retry count ${i} of ${repeatCount}. Waiting ${this.MIRROR_NODE_RETRY_DELAY} ms before repeating request`,
1513+
`Repeating request %s with args %s retry count %s of %s. Waiting %s ms before repeating request`,
1514+
methodName,
1515+
JSON.stringify(args),
1516+
i,
1517+
repeatCount,
1518+
this.MIRROR_NODE_RETRY_DELAY,
15011519
);
15021520
}
15031521

@@ -1523,12 +1541,11 @@ export class MirrorNodeClient {
15231541
operatorAccountId: string,
15241542
requestDetails: RequestDetails,
15251543
): Promise<ITransactionRecordMetric> {
1526-
if (this.logger.isLevelEnabled('debug')) {
1527-
this.logger.debug(
1528-
`Get transaction record via mirror node: transactionId=${transactionId}, txConstructorName=${txConstructorName}`,
1529-
);
1530-
}
1531-
1544+
this.logger.debug(
1545+
`Get transaction record via mirror node: transactionId=%s, txConstructorName=%s`,
1546+
transactionId,
1547+
txConstructorName,
1548+
);
15321549
// Create a modified copy of requestDetails
15331550
const modifiedRequestDetails = new RequestDetails({
15341551
requestId: requestDetails.requestId,

0 commit comments

Comments
 (0)