Skip to content

Commit

Permalink
Merge pull request #31 from manumonti/gen-merkle-dist-mkdir
Browse files Browse the repository at this point in the history
Add 'try catch' statements to writing disk commands
  • Loading branch information
manumonti authored Oct 5, 2022
2 parents 6c677f9 + 9751f27 commit 24d6eb5
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 24d6eb5

Please sign in to comment.