Skip to content

Commit

Permalink
Coordinator: generic upstream client interface (#232)
Browse files Browse the repository at this point in the history
* move ResourcesUti to kotlin extensions

* add jvm-libs:generic:extensions:tuweni

* fix test jvm-libs:generic:extensions:tuweni

* fix test jvm-libs:generic:extensions:tuweni

* adds blob decompressor

* adds blob decompressor

* add vertx client options helper

* fix VertxHttpJsonRpcClientFactory#createV2

* adds BlockInterval jvm-libs

* adapt code to new BlockInterval

* adds generic upstream client interface
  • Loading branch information
jpnovais authored Oct 23, 2024
1 parent 00ffc73 commit 9c6497f
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 3 deletions.
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

0 comments on commit 9c6497f

Please sign in to comment.