Skip to content

Commit

Permalink
fixed a timing issue where round emission during /latest call could f…
Browse files Browse the repository at this point in the history
…ail (#76)

verification
  • Loading branch information
CluEleSsUK committed Jan 27, 2024
1 parent ea66db9 commit 0cae10f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 6 additions & 9 deletions lib/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,19 +67,16 @@ export interface ChainClient {

// fetch a beacon for a given `roundNumber` or get the latest beacon by omitting the `roundNumber`
export async function fetchBeacon(client: ChainClient, roundNumber?: number): Promise<RandomnessBeacon> {
let beacon = null

if (!roundNumber) {
beacon = await client.latest()
} else if (roundNumber < 1) {
throw Error('Cannot request lower than round number 1')
} else {
beacon = await client.get(roundNumber)
roundNumber = roundAt(Date.now(), await client.chain().info())
}

const expectedRound = roundNumber || roundAt(Date.now(), await client.chain().info())
if (roundNumber < 1) {
throw Error('Cannot request lower than round number 1')
}
const beacon = await client.get(roundNumber)

return validatedBeacon(client, beacon, expectedRound)
return validatedBeacon(client, beacon, roundNumber)
}

// fetch the most recent beacon to have been emitted at a given `time` in epoch ms
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "drand-client",
"version": "1.2.2",
"version": "1.2.3",
"description": "A client to the drand randomness beacon network.",
"main": "index.js",
"types": "index.d.ts",
Expand Down

0 comments on commit 0cae10f

Please sign in to comment.