Skip to content

Commit

Permalink
refactor public keys route and handler
Browse files Browse the repository at this point in the history
 -- extract artifactsignerprovider in route instead of handler
  • Loading branch information
usmansaleem committed Nov 4, 2024
1 parent b8f7910 commit 0ddab6e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import tech.pegasys.web3signer.core.Context;
import tech.pegasys.web3signer.core.routes.Web3SignerRoute;
import tech.pegasys.web3signer.core.service.http.handlers.commitboost.CommitBoostPublicKeysHandler;
import tech.pegasys.web3signer.signing.ArtifactSignerProvider;
import tech.pegasys.web3signer.signing.config.DefaultArtifactSignerProvider;

import io.vertx.core.http.HttpMethod;
import io.vertx.core.json.JsonObject;
Expand All @@ -23,9 +25,16 @@
public class CommitBoostPublicKeysRoute implements Web3SignerRoute {
private static final String PATH = "/signer/v1/get_pubkeys";
private final Context context;
private final ArtifactSignerProvider artifactSignerProvider;

public CommitBoostPublicKeysRoute(final Context context) {
this.context = context;
// there should be only one DefaultArtifactSignerProvider in eth2 mode
artifactSignerProvider =
context.getArtifactSignerProviders().stream()
.filter(p -> p instanceof DefaultArtifactSignerProvider)
.findFirst()
.orElseThrow();
}

@Override
Expand All @@ -36,7 +45,7 @@ public void register() {
.produces(JSON_HEADER)
.handler(
new BlockingHandlerDecorator(
new CommitBoostPublicKeysHandler(context.getArtifactSignerProviders()), false))
new CommitBoostPublicKeysHandler(artifactSignerProvider), false))
.failureHandler(context.getErrorHandler())
.failureHandler(
ctx -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@
import tech.pegasys.web3signer.core.service.http.handlers.commitboost.json.PublicKeysResponse;
import tech.pegasys.web3signer.signing.ArtifactSignerProvider;
import tech.pegasys.web3signer.signing.KeyType;
import tech.pegasys.web3signer.signing.config.DefaultArtifactSignerProvider;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
Expand All @@ -36,22 +34,15 @@

public class CommitBoostPublicKeysHandler implements Handler<RoutingContext> {
private static final Logger LOG = LogManager.getLogger();
private final List<ArtifactSignerProvider> artifactSignerProviders;
private final ArtifactSignerProvider artifactSignerProvider;
private final ObjectMapper objectMapper = SigningObjectMapperFactory.createObjectMapper();

public CommitBoostPublicKeysHandler(final List<ArtifactSignerProvider> artifactSignerProviders) {
this.artifactSignerProviders = artifactSignerProviders;
public CommitBoostPublicKeysHandler(final ArtifactSignerProvider artifactSignerProvider) {
this.artifactSignerProvider = artifactSignerProvider;
}

@Override
public void handle(final RoutingContext context) {
// obtain DefaultArtifactSignerProvider as that is the only one we are dealing in eth2 mode.
final ArtifactSignerProvider artifactSignerProvider =
artifactSignerProviders.stream()
.filter(provider -> provider instanceof DefaultArtifactSignerProvider)
.findFirst()
.orElseThrow();

final PublicKeysResponse publicKeysResponse = toPublicKeysResponse(artifactSignerProvider);
try {
final String jsonEncoded = objectMapper.writeValueAsString(publicKeysResponse);
Expand Down

0 comments on commit 0ddab6e

Please sign in to comment.