Skip to content

Commit

Permalink
Extract apis constants (#6081)
Browse files Browse the repository at this point in the history
* Extract Rest API common constants
  • Loading branch information
mehdi-aouadi authored Aug 17, 2022
1 parent 89c4d34 commit 5cd7492
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,6 @@ public class RestApiConstants {
public static final String HEADER_CONTENT_DISPOSITION = "Content-Disposition";

public static final String CACHE_NONE = "max-age=0";

public static final String PUBKEY = "pubkey";
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

package tech.pegasys.teku.validator.client.restapi;

import static tech.pegasys.teku.infrastructure.http.RestApiConstants.PUBKEY;
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.BOOLEAN_TYPE;
import static tech.pegasys.teku.infrastructure.json.types.CoreTypes.STRING_TYPE;
import static tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition.enumOf;
Expand All @@ -28,6 +29,8 @@
import tech.pegasys.teku.infrastructure.json.types.CoreTypes;
import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
import tech.pegasys.teku.infrastructure.json.types.SerializableTypeDefinition;
import tech.pegasys.teku.infrastructure.json.types.StringBasedPrimitiveTypeDefinition;
import tech.pegasys.teku.infrastructure.restapi.endpoints.ParameterMetadata;
import tech.pegasys.teku.validator.client.Validator;
import tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeyResult;
import tech.pegasys.teku.validator.client.restapi.apis.schema.DeleteKeysRequest;
Expand Down Expand Up @@ -216,4 +219,15 @@ public class ValidatorTypes {
.name("DeleteRemoteKeysResponse")
.withField("data", listOf(DELETE_KEY_RESULT), DeleteRemoteKeysResponse::getData)
.build();

public static final ParameterMetadata<BLSPublicKey> PARAM_PUBKEY_TYPE =
new ParameterMetadata<>(
PUBKEY,
new StringBasedPrimitiveTypeDefinition.StringTypeBuilder<BLSPublicKey>()
.formatter(value -> value.toBytesCompressed().toHexString())
.parser(value -> BLSPublicKey.fromBytesCompressed(Bytes48.fromHexString(value)))
.pattern("^0x[a-fA-F0-9]{96}$")
.example(
"0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a")
.build());
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_NOT_FOUND;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_NO_CONTENT;
import static tech.pegasys.teku.validator.client.restapi.ValidatorRestApi.TAG_FEE_RECIPIENT;
import static tech.pegasys.teku.validator.client.restapi.apis.GetFeeRecipient.PARAM_PUBKEY_TYPE;
import static tech.pegasys.teku.validator.client.restapi.ValidatorTypes.PARAM_PUBKEY_TYPE;

import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@

import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_NOT_FOUND;
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
import static tech.pegasys.teku.infrastructure.http.RestApiConstants.PUBKEY;
import static tech.pegasys.teku.validator.client.restapi.ValidatorRestApi.TAG_FEE_RECIPIENT;
import static tech.pegasys.teku.validator.client.restapi.ValidatorTypes.PARAM_PUBKEY_TYPE;

import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.Optional;
import java.util.function.Function;
import org.apache.tuweni.bytes.Bytes48;
import tech.pegasys.teku.bls.BLSPublicKey;
import tech.pegasys.teku.infrastructure.json.types.SerializableTypeDefinition;
import tech.pegasys.teku.infrastructure.json.types.StringBasedPrimitiveTypeDefinition;
import tech.pegasys.teku.infrastructure.restapi.endpoints.EndpointMetadata;
import tech.pegasys.teku.infrastructure.restapi.endpoints.ParameterMetadata;
import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiEndpoint;
import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiRequest;
import tech.pegasys.teku.spec.datastructures.eth1.Eth1Address;
Expand All @@ -35,25 +34,14 @@
public class GetFeeRecipient extends RestApiEndpoint {
public static final String ROUTE = "/eth/v1/validator/{pubkey}/feerecipient";
private final Optional<BeaconProposerPreparer> beaconProposerPreparer;
private static final String PARAM_PUBKEY = "pubkey";
public static final ParameterMetadata<BLSPublicKey> PARAM_PUBKEY_TYPE =
new ParameterMetadata<>(
PARAM_PUBKEY,
new StringBasedPrimitiveTypeDefinition.StringTypeBuilder<BLSPublicKey>()
.formatter(value -> value.toBytesCompressed().toHexString())
.parser(value -> BLSPublicKey.fromBytesCompressed(Bytes48.fromHexString(value)))
.pattern("^0x[a-fA-F0-9]{96}$")
.example(
"0x93247f2209abcacf57b75a51dafae777f9dd38bc7053d1af526f220a7489a6d3a2753e5f3e8b1cfe39b56f43611df74a")
.build());

private static final SerializableTypeDefinition<GetFeeRecipientResponse> FEE_RECIPIENT_DATA =
SerializableTypeDefinition.object(GetFeeRecipientResponse.class)
.name("GetFeeRecipientData")
.withField(
"ethaddress", Eth1Address.ETH1ADDRESS_TYPE, GetFeeRecipientResponse::getEthAddress)
.withOptionalField(
"pubkey", ValidatorTypes.PUBKEY_TYPE, GetFeeRecipientResponse::getPublicKey)
PUBKEY, ValidatorTypes.PUBKEY_TYPE, GetFeeRecipientResponse::getPublicKey)
.build();

private static final SerializableTypeDefinition<GetFeeRecipientResponse> RESPONSE_TYPE =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_SERVICE_UNAVAILABLE;
import static tech.pegasys.teku.spec.datastructures.eth1.Eth1Address.ETH1ADDRESS_TYPE;
import static tech.pegasys.teku.validator.client.restapi.ValidatorRestApi.TAG_FEE_RECIPIENT;
import static tech.pegasys.teku.validator.client.restapi.apis.GetFeeRecipient.PARAM_PUBKEY_TYPE;
import static tech.pegasys.teku.validator.client.restapi.ValidatorTypes.PARAM_PUBKEY_TYPE;

import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.Objects;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import static tech.pegasys.teku.infrastructure.http.HttpStatusCodes.SC_OK;
import static tech.pegasys.teku.infrastructure.restapi.MetadataTestUtil.getResponseStringFromMetadata;
import static tech.pegasys.teku.infrastructure.restapi.MetadataTestUtil.verifyMetadataErrorResponse;
import static tech.pegasys.teku.validator.client.restapi.apis.GetFeeRecipient.PARAM_PUBKEY_TYPE;
import static tech.pegasys.teku.validator.client.restapi.ValidatorTypes.PARAM_PUBKEY_TYPE;

import com.fasterxml.jackson.core.JsonProcessingException;
import java.util.Optional;
Expand Down

0 comments on commit 5cd7492

Please sign in to comment.