Skip to content

Commit

Permalink
Handle in getTez.js if challenges are disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
harryttd committed Aug 24, 2023
1 parent 8bc3dd9 commit a64187a
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions scripts/getTez.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ const displayHelp = () => {
log(`Usage: getTez.js [options] <address>
Options:
-h, --help Display help information.
-p, --profile <value> Set the profile ('user' for 1 Tez or 'baker' for 6000 Tez).
-n, --network <value> Set the network name. See available networks at https://teztnets.xyz.
-p, --profile <value> Set the profile ('user' or 'baker').
-n, --network <value> Set the faucet's network name. See available networks at https://teztnets.xyz.
Ignored if --faucet-url is set.
-f, --faucet-url <value> Set the custom faucet URL. Ignores --network.
-v, --verbose Enable verbose logging.`)
Expand Down Expand Up @@ -120,6 +120,22 @@ const requestHeaders = {
"Content-Type": "application/x-www-form-urlencoded",
}

const getInfo = async () => {
verboseLog("Requesting faucet info...")

const response = await fetch(`${faucetUrl}/info`, {
headers: requestHeaders,
})

const body = await response.json()

if (!response.ok) {
handleError(`ERROR: ${body.message}`)
}

return body
}

const getChallenge = async () => {
verboseLog("Requesting PoW challenge...")

Expand Down Expand Up @@ -190,6 +206,13 @@ const verifySolution = async (solution, nonce) => {
const getTez = async (args) => {
await parseArgs(args)

const faucetInfo = await getInfo()

if (faucetInfo.challengesDisabled) {
const txHash = (await verifySolution("", 0)).txHash
return txHash
}

let { challenge, difficulty, challengeCounter } = await getChallenge()

while (challenge && difficulty && challengeCounter) {
Expand Down

0 comments on commit a64187a

Please sign in to comment.