Skip to content

Commit

Permalink
move checking observedBlock existence in db to controller
Browse files Browse the repository at this point in the history
  • Loading branch information
Intizar-T committed May 28, 2024
1 parent 9738603 commit b9f8488
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 5 deletions.
3 changes: 3 additions & 0 deletions api/blocks/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ func getObservedBlock(c *fiber.Ctx) error {
if err != nil {
return err
}
if result.Service == "" {
return c.JSON(nil)
}

return c.JSON(result)
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/listener/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ export async function getListener({
* @return {Promise<IBlock>}
* @exception {FailedToGetObservedBlock}
*/
export async function getObservedBlock({ service }: { service: string }): Promise<IBlock> {
export async function getObservedBlock({ service }: { service: string }): Promise<IBlock | null> {
try {
const endpoint = buildUrl(ORAKL_NETWORK_API_URL, `blocks/observed?service=${service}`)
return (await axios.get(endpoint))?.data
Expand Down
2 changes: 1 addition & 1 deletion core/src/listener/listener.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ function latestJob({

try {
// We assume that observedBlock has been initialized in the db in state.add()
observedBlock = (await getObservedBlock({ service })).blockNumber
observedBlock = (await getObservedBlock({ service }))?.blockNumber as number
} catch (e) {
// Similarly to the failure during fetching the latest block
// number, this error doesn't require job resubmission. The next
Expand Down
4 changes: 1 addition & 3 deletions core/src/listener/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,7 @@ export class State {
await this.addBlockToHistoryQueue(contractAddress, block.blockNumber)
}

// if there is no observedBlock record in the db,
// use the listenerInitType to determine how to initialize the listener
if (observedBlock.service === '') {
if (observedBlock == null) {
switch (this.listenerInitType) {
case 'clear':
case 'latest':
Expand Down

0 comments on commit b9f8488

Please sign in to comment.