2020-09-23 13:47:24 +00:00
|
|
|
import { BinanceAction } from "../blockchain/binance";
|
2021-01-29 06:45:43 +00:00
|
|
|
import { SmartchainAction } from "../blockchain/smartchain";
|
|
|
|
import { EthereumAction } from "../blockchain/ethereum";
|
2020-09-23 13:47:24 +00:00
|
|
|
import { CosmosAction } from "../blockchain/cosmos";
|
2020-10-19 22:51:47 +00:00
|
|
|
import { AssetInfos } from "../generic/asset-infos";
|
2020-09-23 13:47:24 +00:00
|
|
|
import { EthForks } from "../generic/eth-forks";
|
|
|
|
import { FoldersFiles } from "../generic/folders-and-files";
|
|
|
|
import { JsonAction } from "../generic/json-format";
|
|
|
|
import { KavaAction } from "../blockchain/kava";
|
|
|
|
import { LogoSize } from "../generic/logo-size";
|
|
|
|
import { TerraAction } from "../blockchain/terra";
|
|
|
|
import { TezosAction } from "../blockchain/tezos";
|
|
|
|
import { TronAction } from "../blockchain/tron";
|
|
|
|
import { Validators } from "../generic/validators";
|
|
|
|
import { WavesAction } from "../blockchain/waves";
|
2020-10-14 01:20:42 +00:00
|
|
|
import { Allowlists } from "../generic/allowlists";
|
2020-09-23 13:47:24 +00:00
|
|
|
import { ActionInterface, CheckStepInterface } from "../generic/interface";
|
2020-08-06 19:17:38 +00:00
|
|
|
import * as chalk from 'chalk';
|
|
|
|
import * as bluebird from "bluebird";
|
|
|
|
|
|
|
|
const actionList: ActionInterface[] = [
|
|
|
|
new FoldersFiles(),
|
2020-10-19 22:51:47 +00:00
|
|
|
new AssetInfos(),
|
2020-08-06 19:17:38 +00:00
|
|
|
new EthForks(),
|
|
|
|
new LogoSize(),
|
2020-10-14 01:20:42 +00:00
|
|
|
new Allowlists(),
|
2020-08-06 19:17:38 +00:00
|
|
|
new Validators(),
|
|
|
|
new JsonAction(),
|
|
|
|
// chains:
|
|
|
|
new BinanceAction(),
|
2021-01-29 06:45:43 +00:00
|
|
|
new SmartchainAction(),
|
|
|
|
new EthereumAction(),
|
2020-08-06 19:17:38 +00:00
|
|
|
new CosmosAction(),
|
|
|
|
new KavaAction(),
|
|
|
|
new TerraAction(),
|
|
|
|
new TezosAction(),
|
|
|
|
new TronAction(),
|
2020-08-31 16:25:21 +00:00
|
|
|
new WavesAction()
|
2020-08-06 19:17:38 +00:00
|
|
|
];
|
|
|
|
|
2020-09-16 12:52:10 +00:00
|
|
|
const maxErrosFromOneCheck = 5;
|
|
|
|
|
2021-02-22 11:55:52 +00:00
|
|
|
const markerError = chalk.red('XXX');
|
|
|
|
const markerWarning = chalk.yellow('!!');
|
|
|
|
const markerOK = chalk.green('✓');
|
|
|
|
|
2020-08-24 15:06:21 +00:00
|
|
|
async function checkStepList(steps: CheckStepInterface[]): Promise<[string[], string[]]> {
|
2020-09-18 14:39:31 +00:00
|
|
|
const errorsAll: string[] = [];
|
|
|
|
const warningsAll: string[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
await bluebird.each(steps, async (step) => {
|
|
|
|
try {
|
|
|
|
//console.log(` Running check step '${step.getName()}'...`);
|
2020-09-16 12:52:10 +00:00
|
|
|
const [errors, warnings] = await step.check();
|
|
|
|
if (errors && errors.length > 0) {
|
2021-02-22 11:55:52 +00:00
|
|
|
console.log(`- ${markerError} '${step.getName()}': ${errors.length} errors`);
|
2020-09-18 14:39:31 +00:00
|
|
|
let cnt = 0;
|
2020-09-16 12:52:10 +00:00
|
|
|
errors.forEach(err => {
|
|
|
|
if (cnt < maxErrosFromOneCheck) {
|
2021-02-22 11:55:52 +00:00
|
|
|
console.log(` ${markerError} '${err}'`);
|
2020-09-16 12:52:10 +00:00
|
|
|
errorsAll.push(err);
|
|
|
|
} else if (cnt == maxErrosFromOneCheck) {
|
2021-02-22 11:55:52 +00:00
|
|
|
console.log(` ${markerError} ${errors.length} errors in total, omitting rest ...`);
|
2020-09-16 12:52:10 +00:00
|
|
|
}
|
|
|
|
cnt++;
|
|
|
|
});
|
2020-08-24 15:06:21 +00:00
|
|
|
}
|
2020-09-16 12:52:10 +00:00
|
|
|
if (warnings && warnings.length > 0) {
|
2021-02-22 11:55:52 +00:00
|
|
|
console.log(`- ${markerWarning} '${step.getName()}': ${warnings.length} warnings`);
|
2020-09-18 14:39:31 +00:00
|
|
|
let cnt = 0;
|
2020-09-16 12:52:10 +00:00
|
|
|
warnings.forEach(warn => {
|
|
|
|
if (cnt < maxErrosFromOneCheck) {
|
2021-02-22 11:55:52 +00:00
|
|
|
console.log(` ${markerWarning} '${warn}'`);
|
2020-09-16 12:52:10 +00:00
|
|
|
warningsAll.push(warn);
|
|
|
|
} else if (cnt == maxErrosFromOneCheck) {
|
2021-02-22 11:55:52 +00:00
|
|
|
console.log(` ${markerWarning} ${warnings.length} warnings in total, omitting rest ...`);
|
2020-09-16 12:52:10 +00:00
|
|
|
}
|
|
|
|
cnt++;
|
|
|
|
});
|
2020-08-24 15:06:21 +00:00
|
|
|
}
|
2020-09-16 12:52:10 +00:00
|
|
|
if (errors.length == 0 && warnings.length == 0) {
|
2021-02-22 11:55:52 +00:00
|
|
|
console.log(`- ${markerOK} '${step.getName()}' OK`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
} catch (error) {
|
2021-02-22 11:55:52 +00:00
|
|
|
console.log(`- ${markerError} '${step.getName()}': Caught error: ${error.message}`);
|
2020-09-16 12:52:10 +00:00
|
|
|
errorsAll.push(`${step.getName()}: Exception: ${error.message}`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
});
|
2020-09-16 12:52:10 +00:00
|
|
|
return [errorsAll, warningsAll];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
2020-08-24 15:06:21 +00:00
|
|
|
async function sanityCheckByActionList(actions: ActionInterface[]): Promise<[string[], string[]]> {
|
2020-08-10 08:56:41 +00:00
|
|
|
console.log("Running sanity checks...");
|
2020-09-18 14:39:31 +00:00
|
|
|
const errors: string[] = [];
|
|
|
|
const warnings: string[] = [];
|
2020-08-06 19:17:38 +00:00
|
|
|
await bluebird.each(actions, async (action) => {
|
|
|
|
try {
|
2020-08-10 08:56:41 +00:00
|
|
|
if (action.getSanityChecks) {
|
|
|
|
const steps = action.getSanityChecks();
|
2020-08-06 19:17:38 +00:00
|
|
|
if (steps && steps.length > 0) {
|
|
|
|
console.log(` Action '${action.getName()}' has ${steps.length} check steps`);
|
2020-08-24 15:06:21 +00:00
|
|
|
const [errors1, warnings1] = await checkStepList(steps);
|
2020-08-12 08:03:28 +00:00
|
|
|
if (errors1.length > 0) {
|
|
|
|
errors1.forEach(e => errors.push(e));
|
2020-08-24 15:06:21 +00:00
|
|
|
}
|
|
|
|
if (warnings1.length > 0) {
|
|
|
|
warnings1.forEach(w => warnings.push(w));
|
|
|
|
}
|
|
|
|
if (errors1.length == 0 && warnings1.length == 0) {
|
2021-02-22 11:55:52 +00:00
|
|
|
console.log(`- ${markerOK} Action '${action.getName()}' OK, all ${steps.length} steps`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2021-02-22 11:55:52 +00:00
|
|
|
console.log(`- ${markerError} '${action.getName()}' Caught error: ${error.message}`);
|
2020-08-12 08:03:28 +00:00
|
|
|
errors.push(`${action.getName()}: Exception: ${error.message}`);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
});
|
2020-08-24 15:06:21 +00:00
|
|
|
console.log(`All sanity checks done, found ${errors.length} errors, ${warnings.length} warnings`);
|
|
|
|
return [errors, warnings];
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
2020-08-24 15:06:21 +00:00
|
|
|
async function consistencyCheckByActionList(actions: ActionInterface[]): Promise<[string[], string[]]> {
|
2020-08-10 08:56:41 +00:00
|
|
|
console.log("Running consistency checks...");
|
2020-09-18 14:39:31 +00:00
|
|
|
const errors: string[] = [];
|
|
|
|
const warnings: string[] = [];
|
2020-08-10 08:56:41 +00:00
|
|
|
await bluebird.each(actions, async (action) => {
|
|
|
|
try {
|
|
|
|
if (action.getConsistencyChecks) {
|
|
|
|
const steps = action.getConsistencyChecks();
|
|
|
|
if (steps && steps.length > 0) {
|
|
|
|
console.log(` Action '${action.getName()}' has ${steps.length} check steps`);
|
2020-08-24 15:06:21 +00:00
|
|
|
const [errors1, warnings1] = await checkStepList(steps);
|
2020-08-12 08:03:28 +00:00
|
|
|
if (errors1.length > 0) {
|
|
|
|
errors1.forEach(e => errors.push(e));
|
2020-08-24 15:06:21 +00:00
|
|
|
}
|
|
|
|
if (warnings1.length > 0) {
|
|
|
|
warnings1.forEach(w => warnings.push(w));
|
|
|
|
}
|
|
|
|
if (errors1.length == 0 && warnings1.length == 0) {
|
2021-02-22 11:55:52 +00:00
|
|
|
console.log(`- ${markerOK} Action '${action.getName()}' OK, all ${steps.length} steps`);
|
2020-08-10 08:56:41 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (error) {
|
2021-02-22 11:55:52 +00:00
|
|
|
console.log(`- ${markerError} '${action.getName()}' Caught error: ${error.message}`);
|
2020-08-12 08:03:28 +00:00
|
|
|
errors.push(`${action.getName()}: Exception: ${error.message}`);
|
2020-08-10 08:56:41 +00:00
|
|
|
}
|
|
|
|
});
|
2020-08-24 15:06:21 +00:00
|
|
|
console.log(`All consistency checks done, found ${errors.length} errors, ${warnings.length} warnings`);
|
|
|
|
return [errors, warnings];
|
2020-08-10 08:56:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async function sanityFixByList(actions: ActionInterface[]) {
|
|
|
|
console.log("Running sanity fixes...");
|
2020-08-06 19:17:38 +00:00
|
|
|
await bluebird.each(actions, async (action) => {
|
|
|
|
try {
|
2020-08-10 08:56:41 +00:00
|
|
|
if (action.sanityFix) {
|
|
|
|
console.log(`Sanity fix '${action.getName()}':`);
|
|
|
|
await action.sanityFix();
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log(`Caught error: ${error.message}`);
|
|
|
|
}
|
|
|
|
});
|
2020-08-10 08:56:41 +00:00
|
|
|
console.log("All sanity fixes done.");
|
|
|
|
}
|
|
|
|
|
|
|
|
async function consistencyFixByList(actions: ActionInterface[]) {
|
|
|
|
console.log("Running consistency fixes...");
|
|
|
|
await bluebird.each(actions, async (action) => {
|
|
|
|
try {
|
|
|
|
if (action.consistencyFix) {
|
2021-03-01 14:46:10 +00:00
|
|
|
console.log(`Consistency fix '${action.getName()}':`);
|
2020-08-10 08:56:41 +00:00
|
|
|
await action.consistencyFix();
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log(`Caught error: ${error.message}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
console.log("All consistency fixes done.");
|
2020-07-29 13:42:51 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 15:45:55 +00:00
|
|
|
async function updateAutoByList(actions: ActionInterface[]) {
|
|
|
|
console.log("Running auto updates (using external data sources) ...");
|
2020-08-06 19:17:38 +00:00
|
|
|
await bluebird.each(actions, async (action) => {
|
|
|
|
try {
|
2021-02-01 15:45:55 +00:00
|
|
|
if (action.updateAuto) {
|
|
|
|
console.log(`Auto update '${action.getName()}':`);
|
|
|
|
await action.updateAuto();
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log(`Caught error: ${error.message}`);
|
|
|
|
}
|
|
|
|
});
|
2021-02-01 15:45:55 +00:00
|
|
|
console.log("All auto updates done.");
|
|
|
|
}
|
|
|
|
|
|
|
|
async function updateManualByList(actions: ActionInterface[]) {
|
|
|
|
console.log("Running manual updates (using external data sources) ...");
|
|
|
|
await bluebird.each(actions, async (action) => {
|
|
|
|
try {
|
|
|
|
if (action.updateManual) {
|
|
|
|
console.log(`Manual update '${action.getName()}':`);
|
|
|
|
await action.updateManual();
|
|
|
|
}
|
|
|
|
} catch (error) {
|
|
|
|
console.log(`Caught error: ${error.message}`);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
console.log("All manual updates done.");
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
2020-08-24 15:06:21 +00:00
|
|
|
export async function sanityCheckAll(): Promise<[string[], string[]]> {
|
2020-08-10 08:56:41 +00:00
|
|
|
return await sanityCheckByActionList(actionList);
|
|
|
|
}
|
|
|
|
|
2020-08-24 15:06:21 +00:00
|
|
|
export async function consistencyCheckAll(): Promise<[string[], string[]]> {
|
2020-08-10 08:56:41 +00:00
|
|
|
return await consistencyCheckByActionList(actionList);
|
|
|
|
}
|
|
|
|
|
2020-09-18 14:39:31 +00:00
|
|
|
export async function sanityFixAll(): Promise<void> {
|
2020-08-10 08:56:41 +00:00
|
|
|
await sanityFixByList(actionList);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
2020-09-18 14:39:31 +00:00
|
|
|
export async function consistencyFixAll(): Promise<void> {
|
2020-08-10 08:56:41 +00:00
|
|
|
await consistencyFixByList(actionList);
|
2020-08-06 19:17:38 +00:00
|
|
|
}
|
|
|
|
|
2021-02-01 15:45:55 +00:00
|
|
|
export async function updateAutoAll(): Promise<void> {
|
|
|
|
await updateAutoByList(actionList);
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function updateManualAll(): Promise<void> {
|
|
|
|
await updateManualByList(actionList);
|
2020-07-29 13:42:51 +00:00
|
|
|
}
|