Skip to content

Commit 97a5642

Browse files
committed
Create initial competitionId=1
1 parent 4d34a9e commit 97a5642

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/indexer/indexer.service.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,34 @@ export class IndexerService {
110110
} else {
111111
this.logger.log(`Bootstrap: existed tokenFactory=${indexerState.name}, blockNumber=${indexerState.blockNumber}`)
112112
}
113+
114+
try {
115+
// create initial competition id = 1
116+
const contract = new this.web3.eth.Contract(TokenFactoryABI, address);
117+
const currentCompetitionId = await contract.methods
118+
.currentCompetitionId()
119+
.call() as bigint
120+
if(currentCompetitionId === 1n) {
121+
const [initialCompetition] = await this.appService
122+
.getCompetitions({ competitionId: Number(currentCompetitionId) })
123+
if(!initialCompetition) {
124+
const block = await this.web3.eth.getBlock(blockNumber)
125+
await this.dataSource.manager.insert(CompetitionEntity, {
126+
txnHash: '',
127+
blockNumber: blockNumber,
128+
tokenFactoryAddress: address,
129+
competitionId: Number(currentCompetitionId),
130+
timestampStart: Number(block.timestamp),
131+
timestampEnd: null,
132+
isCompleted: false,
133+
winnerToken: null,
134+
});
135+
this.logger.log(`INITIAL NewCompetitionStarted: competitionId=${1}, timestamp=${Number(block.timestamp)}`);
136+
}
137+
}
138+
} catch (e) {
139+
140+
}
113141
}
114142

115143
return tokenFactories

0 commit comments

Comments
 (0)