-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Coordinator: generic upstream client interface (#232)
* 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
Showing
3 changed files
with
49 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')) | ||
} |
36 changes: 36 additions & 0 deletions
36
jvm-libs/linea/core/client-interface/src/main/kotlin/build/linea/clients/Client.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters