From d5917c8b5aa96f04be36c74d65a59d171a30e143 Mon Sep 17 00:00:00 2001 From: Yaroslav Grishajev Date: Thu, 12 Dec 2024 17:35:13 +0100 Subject: [PATCH] feat(deployment): sign same wallet transactions in a batch --- ...ale-managed-deployments-cleaner.service.ts | 41 +++++++++---------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/apps/api/src/deployment/services/stale-managed-deployments-cleaner/stale-managed-deployments-cleaner.service.ts b/apps/api/src/deployment/services/stale-managed-deployments-cleaner/stale-managed-deployments-cleaner.service.ts index ded9b8eab..55bd15b51 100644 --- a/apps/api/src/deployment/services/stale-managed-deployments-cleaner/stale-managed-deployments-cleaner.service.ts +++ b/apps/api/src/deployment/services/stale-managed-deployments-cleaner/stale-managed-deployments-cleaner.service.ts @@ -54,30 +54,27 @@ export class StaleManagedDeploymentsCleanerService { createdHeight: currentHeight - this.MAX_LIVE_BLOCKS }); - const closeAllWalletStaleDeployments = deployments.map(async deployment => { - const message = this.rpcMessageService.getCloseDeploymentMsg(wallet.address, deployment.dseq); - this.logger.info({ event: "DEPLOYMENT_CLEAN_UP", params: { owner: wallet.address, dseq: deployment.dseq } }); + const messages = deployments.map(deployment => this.rpcMessageService.getCloseDeploymentMsg(wallet.address, deployment.dseq)); - try { - await client.signAndBroadcast([message]); - this.logger.info({ event: "DEPLOYMENT_CLEAN_UP_SUCCESS" }); - } catch (error) { - if (error.message.includes("not allowed to pay fees")) { - await this.managedUserWalletService.authorizeSpending({ - address: wallet.address, - limits: { - fees: this.config.FEE_ALLOWANCE_REFILL_AMOUNT - } - }); + this.logger.info({ event: "DEPLOYMENT_CLEAN_UP", owner: wallet.address }); - await client.signAndBroadcast([message]); - this.logger.info({ event: "DEPLOYMENT_CLEAN_UP_SUCCESS" }); - } else { - throw error; - } - } - }); + try { + await client.signAndBroadcast(messages); + this.logger.info({ event: "DEPLOYMENT_CLEAN_UP_SUCCESS", owner: wallet.address }); + } catch (error) { + if (error.message.includes("not allowed to pay fees")) { + await this.managedUserWalletService.authorizeSpending({ + address: wallet.address, + limits: { + fees: this.config.FEE_ALLOWANCE_REFILL_AMOUNT + } + }); - await Promise.all(closeAllWalletStaleDeployments); + await client.signAndBroadcast(messages); + this.logger.info({ event: "DEPLOYMENT_CLEAN_UP_SUCCESS", owner: wallet.address }); + } else { + throw error; + } + } } }