Skip to content

Commit

Permalink
feat(scripts): Add reservations in batches
Browse files Browse the repository at this point in the history
  • Loading branch information
wottpal committed Aug 15, 2023
1 parent 6e8bdd9 commit 485e80b
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions scripts/reservations/addReservation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ export const addReservations = async (
const { api, account } = initParams
const { abi } = await getDeploymentData('azns_registry')
const contract = new ContractPromise(api, abi, registryAddress)

try {
await contractTx(api, account, contract, 'add_reserved_names', {}, [validatedReservations])
console.log(`\nSuccessfully added ${validatedReservations.length} reserved names to registry.`)
// Add reservations to registry contract in batches
const amountBatches = Math.ceil(validatedReservations.length / 100)
for (let i = 0; i < amountBatches; i++) {
const batch = validatedReservations.slice(i * 100, (i + 1) * 100)
await contractTx(api, account, contract, 'add_reserved_names', {}, [batch])
console.log(
`Successfully added ${batch.length} reserved names to registry (batch ${
i + 1
}/${amountBatches}).`,
)
}
} catch (error) {
throw new Error('Error while adding reserved names to registry.')
}
Expand Down

0 comments on commit 485e80b

Please sign in to comment.