Skip to content

Commit

Permalink
bad entries in account info
Browse files Browse the repository at this point in the history
  • Loading branch information
mikecot committed Aug 26, 2024
1 parent 5963fc2 commit b98bf42
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/query/handlers/provider/providerAccountInfoHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import * as JsinfoSchema from '../../../schemas/jsinfoSchema/jsinfoSchema';
import { desc, eq, gte, and } from "drizzle-orm";
import { GetAndValidateProviderAddressFromRequest } from '../../utils/queryRequestArgParser';
import { RedisCache } from '../../classes/RedisCache';
import { JSONStringify, JSONStringifySpaced, logger } from '../../../utils/utils';
import { IsMeaningfulText, JSONStringify, JSONStringifySpaced, logger } from '../../../utils/utils';
import { WriteErrorToFastifyReply } from '../../utils/queryServerUtils';

type ReportEntry = {
Expand Down Expand Up @@ -103,7 +103,13 @@ async function fetchAllData(addr: string): Promise<ReportEntry[]> {
const uniqueConts = new Set<string>();

reportsRes.forEach((report: ReportEntry) => {
if (!report.data) return;
if (!report.data || !IsMeaningfulText(report.data)) return;

try {
let x = JSON.parse(report.data);
} catch (error) {
return;
}

const cont = removeKeyAndStringifyWithSortedKeys(report.data, 'block_report');
if (uniqueConts.has(cont)) return;
Expand Down
21 changes: 20 additions & 1 deletion src/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,4 +156,23 @@ export function JSONStringifySpaced(obj: any): string {
return JSON.stringify(obj, (key, value) =>
typeof value === 'bigint' ? value.toString() : value, 2
);
}
}

export const IsMeaningfulText = (text: string): boolean => {
if (!text) {
return false;
}

const trimmedText = text.trim();
if (trimmedText === '') {
return false;
}

const trimmedTextLower = trimmedText.toLowerCase();
const meaninglessValues = ['null', 'undefined', 'none', 'n/a', 'na', 'nil', 'false', '0'];
if (meaninglessValues.includes(trimmedTextLower)) {
return false
}

return true;
};

0 comments on commit b98bf42

Please sign in to comment.