Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coordinator: generic upstream client interface #232

Merged
merged 12 commits into from
Oct 23, 2024
9 changes: 9 additions & 0 deletions jvm-libs/linea/core/client-interface/build.gradle
Original file line number Diff line number Diff line change
@@ -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'))
}
Original file line number Diff line number Diff line change
@@ -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<Request, Response> {
fun makeRequest(request: Request): Response
}

interface AsyncClient<Request, Response> {
fun makeRequest(request: Request): SafeFuture<Response>
}

fun <T, E : ClientError> SafeFuture<Result<T, ErrorResponse<E>>>.unwrapResultMonad(): SafeFuture<T> {
return this.thenCompose {
when (it) {
is Ok -> SafeFuture.completedFuture(it.value)
is Err -> SafeFuture.failedFuture(ClientException(it.error.message, it.error.type))
}
}
}
7 changes: 4 additions & 3 deletions settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading