Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix add on-contract-event #304

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ie-contract.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { IE_CONTRACT_ABI, IE_CONTRACT_ADDRESS, RPC_URL, GLIF_TOKEN } from '../sp

const fetchRequest = new ethers.FetchRequest(RPC_URL)
fetchRequest.setHeader('Authorization', `Bearer ${GLIF_TOKEN}`)
const provider = new ethers.JsonRpcProvider(fetchRequest)
export const provider = new ethers.JsonRpcProvider(fetchRequest)

// Uncomment for troubleshooting
// provider.on('debug', d => console.log('[ethers:debug] %s\npayload: %o', d.action, d.payload))
Expand Down
24 changes: 17 additions & 7 deletions lib/round-tracker.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import assert from 'node:assert'
import * as Sentry from '@sentry/node'
import { createMeridianContract } from './ie-contract.js'
import { createMeridianContract, provider } from './ie-contract.js'
import { onContractEvent } from 'on-contract-event'
import { RPC_URL, GLIF_TOKEN } from '../spark-publish/ie-contract-config.js'
Comment on lines +3 to +5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to keep only one place where we are importing from spark-publish.

Would you mind re-exporting these constants in ./ie-contract.js?

Suggested change
import { createMeridianContract, provider } from './ie-contract.js'
import { onContractEvent } from 'on-contract-event'
import { RPC_URL, GLIF_TOKEN } from '../spark-publish/ie-contract-config.js'
import { RPC_URL, GLIF_TOKEN, createMeridianContract, provider } from './ie-contract.js'
import { onContractEvent } from 'on-contract-event'


// The number of tasks per round is proportionate to the SPARK round length - longer rounds require
// more tasks per round.
Expand Down Expand Up @@ -65,12 +67,20 @@ export async function startRoundTracker ({ pgPool, signal }) {
Sentry.captureException(err)
})
}
contract.on('RoundStart', onRoundStart)
if (signal) {
signal.addEventListener('abort', () => {
contract.removeListener('RoundStart', onRoundStart)
})
}
const it = onContractEvent({
contract,
provider,
rpcUrl: RPC_URL,
rpcHeaders: {
Authorization: `Bearer ${GLIF_TOKEN}`
},
signal
})
;(async () => {
for await (const event of it) {
onRoundStart(event.args[0])
}
})().catch(console.error)

const currentRound = await updateSparkRound(await contract.currentRoundIndex())
return currentRound
Expand Down
9 changes: 9 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"http-assert": "^1.5.0",
"http-responders": "^2.0.2",
"multiformats": "^13.1.0",
"on-contract-event": "^1.1.0",
"pg": "^8.11.5",
"postgrator": "^7.2.0",
"raw-body": "^2.5.2"
Expand Down