refactor(RLN) refactored removing identities to also update rate commitments

This commit is contained in:
Tanner Shaw
2023-08-23 18:52:19 -05:00
parent 39bb7b5559
commit d0ec4ec831

View File

@@ -261,13 +261,23 @@ export function removeIdentityFromRoom(
idc: string,
room: RoomI
): Promise<void | RoomI> {
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;