Skip to content

Commit

Permalink
add additional CLI option to add-contract.ts command "runBackfiller" …
Browse files Browse the repository at this point in the history
…to be able not populate historical data on contract creating (#55)
  • Loading branch information
ramilexe authored May 14, 2021
1 parent 9f544b0 commit 8059e93
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
9 changes: 7 additions & 2 deletions src/cli/add-contract.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,18 @@ const argv = yargs.parserConfiguration({
type: 'string',
default: '',
describe: 'Solidity compiler version'
},
runBackfiller: {
type: 'boolean',
default: false,
describe: 'Run backfiller'
}
}).argv;

(async (): Promise<void> => {
const connectionOptions = await getConnectionOptions();
createConnection(connectionOptions).then(async () => {
const { name, address, sourcePath, artifactPath, startingBlock, compilerVersion } = argv;
const { name, address, sourcePath, artifactPath, startingBlock, compilerVersion, runBackfiller } = argv;

const contracts = [];

Expand All @@ -67,7 +72,7 @@ const argv = yargs.parserConfiguration({
contracts.push(contract);

const contractService = new ContractService();
const data = await contractService.addContracts(null, contracts);
const data = await contractService.addContracts(null, contracts, runBackfiller);
console.log(data);
});
})();
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/defaultController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default class DefaultController {
const contracts = req.body.contracts;
const apikey = req.body.apikey;

const data = await contractService.addContracts(apikey, contracts);
const data = await contractService.addContracts(apikey, contracts, true);

res.status(HttpStatusCodes.OK).json({
message: 'OK',
Expand Down
4 changes: 2 additions & 2 deletions src/services/contractService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export default class ContractService {
}


public async addContracts (apiKey: string, contracts: ContractParam[]): Promise<{ success; fail }> {
public async addContracts (apiKey: string, contracts: ContractParam[], runBackfiller: boolean): Promise<{ success; fail }> {
const eventRepository: EventRepository = getConnection().getCustomRepository(EventRepository);
const stateRepository: StateRepository = getConnection().getCustomRepository(StateRepository);
const contractRepository: ContractRepository = getConnection().getCustomRepository(ContractRepository);
Expand Down Expand Up @@ -121,7 +121,7 @@ export default class ContractService {
}
}

if (contractIds && contractIds.length) {
if (contractIds && contractIds.length && runBackfiller) {
this.runBackfillService(contractIds); // async
}

Expand Down

0 comments on commit 8059e93

Please sign in to comment.