Skip to content

Commit

Permalink
Allow multiple address reimport
Browse files Browse the repository at this point in the history
  • Loading branch information
prevostc committed Feb 6, 2024
1 parent f52a0bd commit 47c12e1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
27 changes: 19 additions & 8 deletions src/protocol/beefy/script/beefy.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { cloneDeep, isNumber } from "lodash";
import { cloneDeep, isArray, isNumber, isString } from "lodash";
import * as Rx from "rxjs";
import yargs from "yargs";
import { Chain, allChainIds } from "../../../types/chain";
Expand Down Expand Up @@ -48,7 +48,7 @@ interface CmdParams {
filterChains: Chain[];
includeEol: boolean;
forceConsideredBlockRange: Range<number> | null;
filterContractAddress: string | null;
filterContractAddress: string[] | null;
productRefreshInterval: SamplingPeriod | null;
loopEvery: SamplingPeriod | null;
loopEveryRandomizeRatio: number;
Expand Down Expand Up @@ -80,7 +80,7 @@ export function addBeefyCommands<TOptsBefore>(yargs: yargs.Argv<TOptsBefore>) {
alias: "t",
describe: "what to run",
},
contractAddress: { type: "string", demand: true, alias: "a", describe: "only import data for this contract address" },
contractAddress: { type: "string", array: true, demand: true, alias: "a", describe: "only import data for these contract addresses" },
forceRpcUrl: { type: "string", demand: false, alias: "f", describe: "force a specific RPC URL" },
rpcCount: { type: "number", demand: false, alias: "r", describe: "how many RPCs to use" },
fromBlock: { type: "number", demand: true, describe: "from block" },
Expand Down Expand Up @@ -141,7 +141,7 @@ export function addBeefyCommands<TOptsBefore>(yargs: yargs.Argv<TOptsBefore>) {
default: "all",
describe: "only re-import data for these chain",
},
contractAddress: { type: "string", demand: false, alias: "a", describe: "only reimport data for this contract address" },
contractAddress: { type: "string", array: true, demand: false, alias: "a", describe: "only reimport data for this contract address" },
includeEol: { type: "boolean", demand: false, default: false, alias: "e", describe: "Include EOL products for some chain" },
fromBlock: { type: "number", demand: true, describe: "from block" },
toBlock: { type: "number", demand: false, describe: "to block, defaults to latest" },
Expand All @@ -167,7 +167,7 @@ export function addBeefyCommands<TOptsBefore>(yargs: yargs.Argv<TOptsBefore>) {
task: "historical",
includeEol: argv.includeEol,
filterChains: argv.chain.includes("all") ? allChainIds : (argv.chain as Chain[]),
filterContractAddress: argv.contractAddress || null,
filterContractAddress: argv.contractAddress ?? null,
forceConsideredBlockRange: null,
forceRpcUrl: argv.forceRpcUrl ? addSecretsToRpcUrl(argv.forceRpcUrl) : null,
forceGetLogsBlockSpan: argv.forceGetLogsBlockSpan || null,
Expand All @@ -189,7 +189,7 @@ export function addBeefyCommands<TOptsBefore>(yargs: yargs.Argv<TOptsBefore>) {
getInputs: async () =>
cmdParams.filterChains.map((chain) => ({
chain,
onlyAddress: cmdParams.filterContractAddress ? [cmdParams.filterContractAddress] : null,
onlyAddress: cmdParams.filterContractAddress ?? null,
reimport: { from: fromBlock, to: toBlock },
})),
client: cmdParams.client,
Expand All @@ -214,7 +214,7 @@ export function addBeefyCommands<TOptsBefore>(yargs: yargs.Argv<TOptsBefore>) {
default: "all",
describe: "only import data for this chain",
},
contractAddress: { type: "string", demand: false, alias: "a", describe: "only import data for this contract address" },
contractAddress: { type: "string", array: true, demand: false, alias: "a", describe: "only import data for this contract address" },
fromBlock: { type: "number", demand: false, describe: "only from this block" },
toBlock: { type: "number", demand: false, describe: "to this block, defaults to latest" },
forceRpcUrl: { type: "string", demand: false, alias: "f", describe: "force a specific RPC URL" },
Expand Down Expand Up @@ -575,7 +575,18 @@ function productFilter$(chain: Chain | null, cmdParams: CmdParams) {
Rx.concatAll(),
Rx.filter((product) => {
const contractAddress = getProductContractAddress(product);
return cmdParams.filterContractAddress === null || contractAddress.toLocaleLowerCase() === cmdParams.filterContractAddress.toLocaleLowerCase();
let filter = cmdParams.filterContractAddress as string[] | null | string;
if (filter === null) {
return true;
}
if (isString(filter)) {
return contractAddress.toLocaleLowerCase() === filter.toLocaleLowerCase();
}
if (isArray(filter)) {
filter = filter.map((x) => x.toLocaleLowerCase());
return filter.includes(contractAddress.toLocaleLowerCase());
}
return true; // just in case
}),
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/script/show-used-rpc-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ async function main() {
default: "all",
describe: "only import data for this chain",
},
contractAddress: { type: "string", demand: false, alias: "a", describe: "only import data for this contract address" },
contractAddress: { type: "string", array: true, demand: false, alias: "a", describe: "only import data for this contract address" },
currentBlockNumber: { type: "number", demand: false, alias: "b", describe: "Force the current block number" },
forceRpcUrl: { type: "string", demand: false, alias: "f", describe: "force a specific RPC URL" },
forceGetLogsBlockSpan: { type: "number", demand: false, alias: "s", describe: "force a specific block span for getLogs" },
Expand Down

0 comments on commit 47c12e1

Please sign in to comment.