diff --git a/jvm-libs/linea/core/client-interface/build.gradle b/jvm-libs/linea/core/client-interface/build.gradle new file mode 100644 index 000000000..1b9412c59 --- /dev/null +++ b/jvm-libs/linea/core/client-interface/build.gradle @@ -0,0 +1,9 @@ +plugins { + id 'net.consensys.zkevm.kotlin-library-conventions' +} + +dependencies { + implementation(project(':jvm-libs:generic:extensions:kotlin')) + implementation(project(':jvm-libs:linea:core:domain-models')) + implementation(project(':jvm-libs:generic:errors')) +} diff --git a/jvm-libs/linea/core/client-interface/src/main/kotlin/build/linea/clients/Client.kt b/jvm-libs/linea/core/client-interface/src/main/kotlin/build/linea/clients/Client.kt new file mode 100644 index 000000000..dc0688ee5 --- /dev/null +++ b/jvm-libs/linea/core/client-interface/src/main/kotlin/build/linea/clients/Client.kt @@ -0,0 +1,36 @@ +package build.linea.clients + +import com.github.michaelbull.result.Err +import com.github.michaelbull.result.Ok +import com.github.michaelbull.result.Result +import net.consensys.linea.errors.ErrorResponse +import tech.pegasys.teku.infrastructure.async.SafeFuture + +/** + * Marker interface for error types. + * Allow concrete clients to extend this interface to define their own error types. + */ +interface ClientError + +class ClientException( + override val message: String, + val errorType: ClientError? +) : + RuntimeException(errorType?.let { "errorType=$it $message" } ?: message) + +interface Client { + fun makeRequest(request: Request): Response +} + +interface AsyncClient { + fun makeRequest(request: Request): SafeFuture +} + +fun SafeFuture>>.unwrapResultMonad(): SafeFuture { + return this.thenCompose { + when (it) { + is Ok -> SafeFuture.completedFuture(it.value) + is Err -> SafeFuture.failedFuture(ClientException(it.error.message, it.error.type)) + } + } +} diff --git a/settings.gradle b/settings.gradle index 7385b4635..193adcb56 100644 --- a/settings.gradle +++ b/settings.gradle @@ -11,21 +11,22 @@ include 'jvm-libs:generic:vertx-helper' include 'jvm-libs:generic:errors' include 'jvm-libs:generic:persistence:db' +include 'jvm-libs:linea:core:client-interface' include 'jvm-libs:linea:core:domain-models' +include 'jvm-libs:linea:core:long-running-service' include 'jvm-libs:linea:core:metrics' include 'jvm-libs:linea:core:traces' -include 'jvm-libs:linea:web3j-extensions' include 'jvm-libs:linea:blob-compressor' include 'jvm-libs:linea:blob-decompressor' include 'jvm-libs:linea:blob-shnarf-calculator' -include 'jvm-libs:linea:core:long-running-service' include 'jvm-libs:linea:linea-contracts:l1-rollup' include 'jvm-libs:linea:linea-contracts:l2-message-service' include 'jvm-libs:linea:metrics:micrometer' include 'jvm-libs:linea:teku-execution-client' +include 'jvm-libs:linea:testing:file-system' include 'jvm-libs:linea:testing:l1-blob-and-proof-submission' include 'jvm-libs:linea:testing:teku-helper' -include 'jvm-libs:linea:testing:file-system' +include 'jvm-libs:linea:web3j-extensions' include 'coordinator:app' include 'coordinator:core'