Skip to content

Commit

Permalink
Add 'try catch' statements to writing disk
Browse files Browse the repository at this point in the history
'try catch' statement will handle errors like "Directory already
exists". Also, the check of mkdir is located now at the beggining of the
script, reducing the probability of not being able to save the data
queried to subgraph.
  • Loading branch information
manumonti committed Sep 30, 2022
1 parent 6c677f9 commit 9751f27
Showing 1 changed file with 28 additions and 21 deletions.
49 changes: 28 additions & 21 deletions scripts/gen_merkle_dist.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ const endTimeDate = new Date(endTime * 1000).toISOString().slice(0, 10)
const distribution_path = "distributions/" + endTimeDate

async function main() {
try {
fs.mkdirSync(distribution_path)
} catch (err) {
console.error(err)
return
}

const ongoingRewards = await stakingRewards.getOngoingMekleInput(
graphqlApi,
startTime,
Expand All @@ -23,27 +30,27 @@ async function main() {
)
const merkleDist = stakingRewards.genMerkleDist(merkleInput)

fs.mkdir(distribution_path, (err) => {
if (err) {
return console.error(err)
}
})
fs.writeFileSync(
distribution_path + "/MerkleInputOngoingRewards.json",
JSON.stringify(ongoingRewards, null, 4)
)
fs.writeFileSync(
distribution_path + "/MerkleInputBonusRewards.json",
JSON.stringify(bonusRewards, null, 4)
)
fs.writeFileSync(
distribution_path + "/MerkleInputTotalRewards.json",
JSON.stringify(merkleInput, null, 4)
)
fs.writeFileSync(
distribution_path + "/MerkleDist.json",
JSON.stringify(merkleDist, null, 4)
)
try{
fs.writeFileSync(
distribution_path + "/MerkleInputOngoingRewards.json",
JSON.stringify(ongoingRewards, null, 4)
)
fs.writeFileSync(
distribution_path + "/MerkleInputBonusRewards.json",
JSON.stringify(bonusRewards, null, 4)
)
fs.writeFileSync(
distribution_path + "/MerkleInputTotalRewards.json",
JSON.stringify(merkleInput, null, 4)
)
fs.writeFileSync(
distribution_path + "/MerkleDist.json",
JSON.stringify(merkleDist, null, 4)
)
} catch (err) {
console.error(err)
return
}

console.log("Total amount of rewards: ", merkleDist.totalAmount)
}
Expand Down

0 comments on commit 9751f27

Please sign in to comment.