From 57b780018084d419dafcaee47e504a2c59448d0e Mon Sep 17 00:00:00 2001 From: Shota Jolbordi Date: Wed, 20 Mar 2024 20:50:32 +0400 Subject: [PATCH] Try fix Signed-off-by: Shota Jolbordi --- .../core/service/CredentialServiceImpl.scala | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialServiceImpl.scala b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialServiceImpl.scala index 0e98ac6d93..06b2af96df 100644 --- a/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialServiceImpl.scala +++ b/pollux/lib/core/src/main/scala/io/iohk/atala/pollux/core/service/CredentialServiceImpl.scala @@ -1111,7 +1111,7 @@ private class CredentialServiceImpl( statusListRegistryUrl: String, jwtIssuer: JwtIssuer ): ZIO[WalletAccessContext, CredentialServiceError, CredentialStatus] = { - for { + val effect = for { lastStatusList <- credentialStatusListRepository.getLatestOfTheWallet.mapError(RepositoryError.apply) currentStatusList <- lastStatusList .fold(credentialStatusListRepository.createNewForTheWallet(jwtIssuer, statusListRegistryUrl))( @@ -1120,24 +1120,19 @@ private class CredentialServiceImpl( .mapError(RepositoryError.apply) size = currentStatusList.size lastUsedIndex = currentStatusList.lastUsedIndex - statusListToBeUsed <- issueCredentialSem.withPermit { - for { - statusListToBeUsed <- - if lastUsedIndex < size then ZIO.succeed(currentStatusList) - else - credentialStatusListRepository - .createNewForTheWallet(jwtIssuer, statusListRegistryUrl) - .mapError(RepositoryError.apply) - - _ <- credentialStatusListRepository - .allocateSpaceForCredential( - issueCredentialRecordId = record.id, - credentialStatusListId = statusListToBeUsed.id, - statusListIndex = statusListToBeUsed.lastUsedIndex + 1 - ) + statusListToBeUsed <- + if lastUsedIndex < size then ZIO.succeed(currentStatusList) + else + credentialStatusListRepository + .createNewForTheWallet(jwtIssuer, statusListRegistryUrl) .mapError(RepositoryError.apply) - } yield statusListToBeUsed - } + _ <- credentialStatusListRepository + .allocateSpaceForCredential( + issueCredentialRecordId = record.id, + credentialStatusListId = statusListToBeUsed.id, + statusListIndex = statusListToBeUsed.lastUsedIndex + 1 + ) + .mapError(RepositoryError.apply) } yield CredentialStatus( id = s"$statusListRegistryUrl/credential-status/${statusListToBeUsed.id}#${statusListToBeUsed.lastUsedIndex + 1}", `type` = "StatusList2021Entry", @@ -1145,6 +1140,7 @@ private class CredentialServiceImpl( statusListIndex = lastUsedIndex + 1, statusListCredential = s"$statusListRegistryUrl/credential-status/${statusListToBeUsed.id}" ) + issueCredentialSem.withPermit(effect) } override def generateAnonCredsCredential(