diff --git a/models/src/main/kotlin/io/provenance/api/models/entity/EntityID.kt b/models/src/main/kotlin/io/provenance/api/models/entity/EntityID.kt index 54748950..35230e1a 100644 --- a/models/src/main/kotlin/io/provenance/api/models/entity/EntityID.kt +++ b/models/src/main/kotlin/io/provenance/api/models/entity/EntityID.kt @@ -15,10 +15,10 @@ sealed interface Entity { val id: String } data class KongConsumer( val entityId: String, val username: String?, - val customId: String, + val customId: String?, ) : Entity { override val id: String - get() = entityId + get() = customId ?: username ?: entityId } data class MemberUUID(val value: UUID) : Entity { diff --git a/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/approve/ApproveContractBatchExecution.kt b/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/approve/ApproveContractBatchExecution.kt index 932d1a5e..741f094f 100644 --- a/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/approve/ApproveContractBatchExecution.kt +++ b/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/approve/ApproveContractBatchExecution.kt @@ -66,7 +66,7 @@ class ApproveContractBatchExecution( } }.fold( onSuccess = { - log.info("Successfully processed batch $index of ${chunked.size}") + log.debug { "Successfully processed batch $index of ${chunked.size}" } }, onFailure = { error -> errors.add( diff --git a/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/common/ContractUtilities.kt b/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/common/ContractUtilities.kt index c18cb784..6a54ceae 100644 --- a/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/common/ContractUtilities.kt +++ b/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/common/ContractUtilities.kt @@ -69,7 +69,7 @@ class ContractUtilities( participantsMap, scopeToUse, config.contract.scopeSpecificationName, - audiences.map { it.encryptionKey.toJavaPublicKey() }.toSet() + audiences.map { audience -> audience.encryptionKey.toJavaPublicKey() }.toSet() ) } } diff --git a/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/execute/ExecuteContractBatch.kt b/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/execute/ExecuteContractBatch.kt index 8ebfc648..e761ea0e 100644 --- a/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/execute/ExecuteContractBatch.kt +++ b/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/execute/ExecuteContractBatch.kt @@ -83,7 +83,7 @@ class ExecuteContractBatch( } }.fold( onSuccess = { - log.info("Successfully processed batch $index of ${chunkedSignedResult.size}") + log.debug { "Successfully processed batch $index of ${chunkedSignedResult.size}" } }, onFailure = { error -> errors.add( @@ -111,7 +111,7 @@ class ExecuteContractBatch( ) }.fold( onSuccess = { - log.info("Successfully processed batch $index of ${chunkedFragResult.size}") + log.debug { "Successfully processed batch $index of ${chunkedFragResult.size}" } }, onFailure = { errors.add( diff --git a/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/submit/SubmitContractBatchExecutionResult.kt b/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/submit/SubmitContractBatchExecutionResult.kt index 90282e93..d708595b 100644 --- a/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/submit/SubmitContractBatchExecutionResult.kt +++ b/service/src/main/kotlin/io/provenance/api/domain/usecase/cee/submit/SubmitContractBatchExecutionResult.kt @@ -67,7 +67,7 @@ class SubmitContractBatchExecutionResult( } }.fold( onSuccess = { - log.info("Successfully processed batch $index of ${pair.size}") + log.debug { "Successfully processed batch $index of ${pair.size}" } }, onFailure = { errors.add( diff --git a/service/src/main/kotlin/io/provenance/api/domain/usecase/objectStore/replication/EnableReplication.kt b/service/src/main/kotlin/io/provenance/api/domain/usecase/objectStore/replication/EnableReplication.kt index 167b4e50..bed124f0 100644 --- a/service/src/main/kotlin/io/provenance/api/domain/usecase/objectStore/replication/EnableReplication.kt +++ b/service/src/main/kotlin/io/provenance/api/domain/usecase/objectStore/replication/EnableReplication.kt @@ -27,8 +27,9 @@ class EnableReplication( args.targetSigningPublicKey.toJavaPublicKey(), args.targetEncryptionPublicKey.toJavaPublicKey(), args.targetObjectStoreAddress, - ) ?: throw IllegalStateException("Error performing operation") - } - log.info("createPublicKey() response: ${publicKeyResponse.toJson()}") + ) + } ?: throw IllegalStateException("Error performing operation") + + log.debug { "createPublicKey() response: ${publicKeyResponse.toJson()}" } } } diff --git a/service/src/main/kotlin/io/provenance/api/domain/usecase/provenance/account/models/GetSignerRequest.kt b/service/src/main/kotlin/io/provenance/api/domain/usecase/provenance/account/models/GetSignerRequest.kt index 3d2d52da..20f8ac8b 100644 --- a/service/src/main/kotlin/io/provenance/api/domain/usecase/provenance/account/models/GetSignerRequest.kt +++ b/service/src/main/kotlin/io/provenance/api/domain/usecase/provenance/account/models/GetSignerRequest.kt @@ -9,9 +9,9 @@ import java.util.UUID sealed interface GetSignerRequest { companion object { - operator fun invoke(id: Entity, account: AccountInfo): GetSignerRequest = when (id) { - is KongConsumer -> GetSignerByAddressRequest(id.customId, account) - is MemberUUID -> GetSignerByUUIDRequest(id.value, account) + operator fun invoke(entity: Entity, account: AccountInfo): GetSignerRequest = when (entity) { + is KongConsumer -> GetSignerByAddressRequest(entity.id, account) + is MemberUUID -> GetSignerByUUIDRequest(entity.value, account) } } diff --git a/service/src/main/kotlin/io/provenance/api/domain/usecase/provenance/tx/permissions/dataAccess/UpdateScopeDataAccess.kt b/service/src/main/kotlin/io/provenance/api/domain/usecase/provenance/tx/permissions/dataAccess/UpdateScopeDataAccess.kt index 90d6487c..e5b7897a 100644 --- a/service/src/main/kotlin/io/provenance/api/domain/usecase/provenance/tx/permissions/dataAccess/UpdateScopeDataAccess.kt +++ b/service/src/main/kotlin/io/provenance/api/domain/usecase/provenance/tx/permissions/dataAccess/UpdateScopeDataAccess.kt @@ -93,20 +93,12 @@ class UpdateScopeDataAccess( DataAccessChangeType.ADD -> { runCatching { addAction(change) - } - .fold( - onSuccess = { result -> result }, - onFailure = { error -> errors.add(error) } - ) + }.getOrElse { error -> errors.add(error) } } DataAccessChangeType.REMOVE -> { runCatching { removeAction(change) - } - .fold( - onSuccess = { result -> result }, - onFailure = { error -> errors.add(error) } - ) + }.getOrElse { error -> errors.add(error) } } } } diff --git a/service/src/main/kotlin/io/provenance/api/frameworks/cee/P8eContractService.kt b/service/src/main/kotlin/io/provenance/api/frameworks/cee/P8eContractService.kt index 8e006918..1d750977 100644 --- a/service/src/main/kotlin/io/provenance/api/frameworks/cee/P8eContractService.kt +++ b/service/src/main/kotlin/io/provenance/api/frameworks/cee/P8eContractService.kt @@ -21,7 +21,7 @@ import org.springframework.stereotype.Component @Component class P8eContractService : ContractService { - private val log = KotlinLogging.logger { } + private val log = KotlinLogging.logger("P8eContractService") override fun getContract(contractName: String): Class { return Class.forName(contractName).asSubclass(P8eContract::class.java) @@ -64,29 +64,31 @@ class P8eContractService : ContractService { } override fun executeContract(client: Client, session: Session): ExecutionResult = - runCatchingExecutionResult() { + runCatchingExecutionResult { client.execute(session) } override fun executeContract(client: Client, envelope: Envelope): ExecutionResult = - runCatchingExecutionResult() { + runCatchingExecutionResult { client.execute(envelope) } - private fun runCatchingExecutionResult(execution: () -> ExecutionResult): ExecutionResult = - runCatching { - execution() - }.fold( - onSuccess = { result -> result }, - onFailure = { throwable -> - throw ContractExecutionException("Contract execution failed: ${throwable.message}", throwable) - } - ) + private fun runCatchingExecutionResult(execution: () -> ExecutionResult): ExecutionResult = runCatching { + execution() + }.getOrElse { throwable -> + throw ContractExecutionException("Contract execution failed: ${throwable.message}", throwable) + } - private fun Session.Builder.configureSession(records: Map, sessionUuid: UUID? = null, participants: Map?, audiences: Set): Session = + private fun Session.Builder.configureSession( + records: Map, + sessionUuid: UUID? = null, + participants: Map?, + audiences: Set, + ): Session = this.setSessionUuid(sessionUuid ?: UUID.randomUUID()) - .also { records.forEach { record -> it.addProposedRecord(record.key, record.value) } } .also { + records.forEach { record -> it.addProposedRecord(record.key, record.value) } + participants?.forEach { participant -> it.addParticipant( participant.key, diff --git a/service/src/main/kotlin/io/provenance/api/frameworks/provenance/ProvenanceService.kt b/service/src/main/kotlin/io/provenance/api/frameworks/provenance/ProvenanceService.kt index 68e89089..97fdb23f 100644 --- a/service/src/main/kotlin/io/provenance/api/frameworks/provenance/ProvenanceService.kt +++ b/service/src/main/kotlin/io/provenance/api/frameworks/provenance/ProvenanceService.kt @@ -153,17 +153,12 @@ class ProvenanceService : Provenance { val account = getBaseAccount(pbClient, signer.address()) val cachedOffset = cachedSequenceMap.getOrPut(signer.address()) { CachedAccountSequence() } - runCatching { + return runCatching { action(pbClient, account, cachedOffset.getAndIncrementOffset(account.sequence)) - }.fold( - onSuccess = { - return it - }, - onFailure = { - cachedOffset.getAndDecrement(account.sequence) - throw it - } - ) + }.getOrElse { + cachedOffset.getAndDecrement(account.sequence) + throw it + } } } } diff --git a/service/src/main/kotlin/io/provenance/api/frameworks/web/external/cee/CeeApi.kt b/service/src/main/kotlin/io/provenance/api/frameworks/web/external/cee/CeeApi.kt index da5876b4..10aced45 100644 --- a/service/src/main/kotlin/io/provenance/api/frameworks/web/external/cee/CeeApi.kt +++ b/service/src/main/kotlin/io/provenance/api/frameworks/web/external/cee/CeeApi.kt @@ -269,7 +269,6 @@ class CeeApi { POST("/execute", handler::executeContract) POST("/submit", handler::submitContractResult) POST("/reject", handler::rejectContractExecution) - GET("/headers", handler::showHeaders) "/batch".nest { POST("/execute", handler::executeContractBatch) POST("/submit", handler::submitContractBatchResult) diff --git a/service/src/main/kotlin/io/provenance/api/frameworks/web/external/cee/CeeHandler.kt b/service/src/main/kotlin/io/provenance/api/frameworks/web/external/cee/CeeHandler.kt index 293bb219..5d387327 100644 --- a/service/src/main/kotlin/io/provenance/api/frameworks/web/external/cee/CeeHandler.kt +++ b/service/src/main/kotlin/io/provenance/api/frameworks/web/external/cee/CeeHandler.kt @@ -18,14 +18,11 @@ import io.provenance.api.domain.usecase.cee.submit.models.SubmitContractBatchExe import io.provenance.api.domain.usecase.cee.submit.models.SubmitContractExecutionResultRequestWrapper import io.provenance.api.frameworks.web.misc.foldToServerResponse import io.provenance.api.frameworks.web.misc.getEntity -import mu.KotlinLogging import org.springframework.stereotype.Component import org.springframework.web.reactive.function.server.ServerRequest import org.springframework.web.reactive.function.server.ServerResponse import org.springframework.web.reactive.function.server.awaitBody -private val log = KotlinLogging.logger("CeeHandler") - @Component class CeeHandler( private val executeContract: ExecuteContract, @@ -68,8 +65,4 @@ class CeeHandler( suspend fun rejectContractBatchExecution(req: ServerRequest): ServerResponse = runCatching { rejectContractBatchExecution.execute(RejectContractBatchRequestWrapper(req.getEntity(), req.awaitBody())) }.foldToServerResponse() - - suspend fun showHeaders(req: ServerRequest): ServerResponse = runCatching { - req.headers().also { log.info { "headers: $it" } } - }.foldToServerResponse() } diff --git a/service/src/main/kotlin/io/provenance/api/frameworks/web/external/provenance/ProvenanceHandler.kt b/service/src/main/kotlin/io/provenance/api/frameworks/web/external/provenance/ProvenanceHandler.kt index f8983a00..43ceb322 100644 --- a/service/src/main/kotlin/io/provenance/api/frameworks/web/external/provenance/ProvenanceHandler.kt +++ b/service/src/main/kotlin/io/provenance/api/frameworks/web/external/provenance/ProvenanceHandler.kt @@ -141,11 +141,11 @@ class ProvenanceHandler( ) }.foldToServerResponse() - suspend fun checkCustody(req: ServerRequest): ServerResponse = kotlin.runCatching { + suspend fun checkCustody(req: ServerRequest): ServerResponse = runCatching { getSigner.execute( GetSignerRequest( - id = req.getEntity(), - account = req.awaitBodyOrNull() ?: AccountInfo() + entity = req.getEntity(), + account = req.awaitBodyOrNull() ?: AccountInfo(), ) ) }.fold( diff --git a/service/src/main/kotlin/io/provenance/api/frameworks/web/misc/ServerRequestExt.kt b/service/src/main/kotlin/io/provenance/api/frameworks/web/misc/ServerRequestExt.kt index 77f33eab..ad4d8431 100644 --- a/service/src/main/kotlin/io/provenance/api/frameworks/web/misc/ServerRequestExt.kt +++ b/service/src/main/kotlin/io/provenance/api/frameworks/web/misc/ServerRequestExt.kt @@ -8,7 +8,7 @@ import org.springframework.web.reactive.function.server.ServerRequest import org.springframework.web.reactive.function.server.awaitBodyOrNull import java.util.UUID -private val log = KotlinLogging.logger {} +private val log = KotlinLogging.logger("ServerRequest") val ServerRequest.ipAddress: String get() = headers().firstHeader("x-real-ip") ?: remoteAddress().get().address.toString() @@ -37,9 +37,7 @@ private fun ServerRequest.getConsumerOrNull(): KongConsumer? { KongConsumer( entityId = id, username = headers().firstHeader("x-consumer-username"), - customId = requireNotNull(headers().firstHeader("x-consumer-custom-id")) { - "Custom ID for consumer (x-consumer-custom-id) missing" - }, + customId = headers().firstHeader("x-consumer-custom-id"), ) } }