From d0ec4ec831ddd1c09b0df5feed62e3bb46bf110d Mon Sep 17 00:00:00 2001 From: Tanner Shaw Date: Wed, 23 Aug 2023 18:52:19 -0500 Subject: [PATCH] refactor(RLN) refactored removing identities to also update rate commitments --- src/data/db.ts | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/src/data/db.ts b/src/data/db.ts index e8cdfdb..c0fe463 100644 --- a/src/data/db.ts +++ b/src/data/db.ts @@ -261,13 +261,23 @@ export function removeIdentityFromRoom( idc: string, room: RoomI ): Promise { - const updateIdentities = room.identities?.map((identity) => - identity === idc ? '0n' : identity - ) as string[]; + const updateSemaphoreIdentities = room.semaphoreIdentities?.map((identity) => + identity === idc ? '0n' : identity as string + )as string[]; + + const rateCommitmentsToUpdate = getRateCommitmentHash(BigInt(idc), BigInt(room.userMessageLimit!)).toString() + + const updatedRateCommitments = room.identities?.map((limiter) => + limiter == rateCommitmentsToUpdate ? '0n' : limiter as string + ) + return prisma.rooms .update({ where: { id: room.id }, - data: { identities: updateIdentities } + data: { + identities: updatedRateCommitments, + semaphoreIdentities: updateSemaphoreIdentities + } }) .then((room) => { return room as RoomI;