Skip to content

Commit

Permalink
Return the max challenges if min and max tez are equal
Browse files Browse the repository at this point in the history
  • Loading branch information
harryttd committed Oct 4, 2023
1 parent 4799551 commit 75f7559
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/pow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ const determineDifficulty = () => {
const determineChallengesNeeded = (amount: number, usedCaptcha: boolean) => {
const { MIN_TEZ, MAX_TEZ, MIN_CHALLENGES, MAX_CHALLENGES, MAX_CHALLENGES_WITH_CAPTCHA } = env

// Calculate the proportion of the requested Tez to the maximum Tez
const tezProportion = (amount - MIN_TEZ) / (MAX_TEZ - MIN_TEZ)

// Calculate the base number of challenges based on the Tez proportion and whether a captcha was used
const maxChallenges = usedCaptcha ? MAX_CHALLENGES_WITH_CAPTCHA : MAX_CHALLENGES

if (MIN_TEZ === MAX_TEZ) return maxChallenges

// Calculate the proportion of the requested Tez to the maximum Tez
const tezProportion = (amount - MIN_TEZ) / (MAX_TEZ - MIN_TEZ)
const challengesNeeded = Math.ceil(tezProportion * (maxChallenges - MIN_CHALLENGES) + MIN_CHALLENGES)

return challengesNeeded
Expand Down

0 comments on commit 75f7559

Please sign in to comment.