From 485e80be6990b97f562a73cdcc4c4494dfb6493e Mon Sep 17 00:00:00 2001 From: Dennis Zoma Date: Tue, 15 Aug 2023 14:26:38 +0200 Subject: [PATCH] feat(scripts): Add reservations in batches --- scripts/reservations/addReservation.ts | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/scripts/reservations/addReservation.ts b/scripts/reservations/addReservation.ts index 79b2cf5..b656408 100644 --- a/scripts/reservations/addReservation.ts +++ b/scripts/reservations/addReservation.ts @@ -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.') }