diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/BeaconRestApiTypes.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/BeaconRestApiTypes.java index 8fc454f72ec..2e776b3d5f2 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/BeaconRestApiTypes.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/BeaconRestApiTypes.java @@ -76,7 +76,9 @@ import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.datastructures.blocks.SignedBeaconBlockHeader; import tech.pegasys.teku.spec.datastructures.metadata.BlockAndMetaData; +import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.datastructures.validator.BroadcastValidationLevel; +import tech.pegasys.teku.spec.schemas.SchemaDefinitionCache; public class BeaconRestApiTypes { private static final StringValueTypeDefinition STATUS_VALUE = @@ -247,6 +249,26 @@ public class BeaconRestApiTypes { public static final ParameterMetadata ETH_CONSENSUS_VERSION_TYPE = new ParameterMetadata<>(HEADER_CONSENSUS_VERSION, MILESTONE_TYPE); + @SuppressWarnings("unchecked") + public static DeserializableTypeDefinition electraAttestationTypeDef( + final SchemaDefinitionCache schemaDefinitionCache) { + return (DeserializableTypeDefinition) + schemaDefinitionCache + .getSchemaDefinition(SpecMilestone.ELECTRA) + .getAttestationSchema() + .getJsonTypeDefinition(); + } + + @SuppressWarnings("unchecked") + public static DeserializableTypeDefinition phase0AttestationTypeDef( + final SchemaDefinitionCache schemaDefinitionCache) { + return (DeserializableTypeDefinition) + schemaDefinitionCache + .getSchemaDefinition(SpecMilestone.PHASE0) + .getAttestationSchema() + .getJsonTypeDefinition(); + } + @SuppressWarnings("JavaCase") public enum BroadcastValidationParameter { gossip, diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/GetBlockAttestationsV2.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/GetBlockAttestationsV2.java index d309cfef9b0..81b15809640 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/GetBlockAttestationsV2.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/beacon/GetBlockAttestationsV2.java @@ -30,8 +30,8 @@ import tech.pegasys.teku.api.ChainDataProvider; import tech.pegasys.teku.api.DataProvider; import tech.pegasys.teku.api.schema.Version; +import tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes; import tech.pegasys.teku.infrastructure.async.SafeFuture; -import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition; import tech.pegasys.teku.infrastructure.json.types.SerializableOneOfTypeDefinition; import tech.pegasys.teku.infrastructure.json.types.SerializableOneOfTypeDefinitionBuilder; import tech.pegasys.teku.infrastructure.json.types.SerializableTypeDefinition; @@ -39,7 +39,6 @@ import tech.pegasys.teku.infrastructure.restapi.endpoints.EndpointMetadata; import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiEndpoint; import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiRequest; -import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.datastructures.metadata.ObjectAndMetaData; import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.schemas.SchemaDefinitionCache; @@ -92,24 +91,15 @@ public void handleRequest(final RestApiRequest request) throws JsonProcessingExc @SuppressWarnings("unchecked") private static SerializableTypeDefinition>> getResponseType( final SchemaDefinitionCache schemaDefinitionCache) { - final DeserializableTypeDefinition electraAttestationTypeDef = - (DeserializableTypeDefinition) - schemaDefinitionCache - .getSchemaDefinition(SpecMilestone.ELECTRA) - .getAttestationSchema() - .getJsonTypeDefinition(); - - final DeserializableTypeDefinition phase0AttestationTypeDef = - (DeserializableTypeDefinition) - schemaDefinitionCache - .getSchemaDefinition(SpecMilestone.PHASE0) - .getAttestationSchema() - .getJsonTypeDefinition(); final SerializableOneOfTypeDefinition> oneOfTypeDefinition = new SerializableOneOfTypeDefinitionBuilder>() - .withType(electraAttestationsPredicate(), listOf(electraAttestationTypeDef)) - .withType(phase0AttestationsPredicate(), listOf(phase0AttestationTypeDef)) + .withType( + electraAttestationsPredicate(), + listOf(BeaconRestApiTypes.electraAttestationTypeDef(schemaDefinitionCache))) + .withType( + phase0AttestationsPredicate(), + listOf(BeaconRestApiTypes.phase0AttestationTypeDef(schemaDefinitionCache))) .build(); return SerializableTypeDefinition.>>object() diff --git a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/validator/GetAggregateAttestationV2.java b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/validator/GetAggregateAttestationV2.java index 1230ef18b8e..8f9e9e3b064 100644 --- a/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/validator/GetAggregateAttestationV2.java +++ b/data/beaconrestapi/src/main/java/tech/pegasys/teku/beaconrestapi/handlers/v2/validator/GetAggregateAttestationV2.java @@ -28,9 +28,9 @@ import tech.pegasys.teku.api.DataProvider; import tech.pegasys.teku.api.ValidatorDataProvider; import tech.pegasys.teku.api.schema.Version; +import tech.pegasys.teku.beaconrestapi.BeaconRestApiTypes; import tech.pegasys.teku.infrastructure.async.SafeFuture; import tech.pegasys.teku.infrastructure.http.HttpStatusCodes; -import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition; import tech.pegasys.teku.infrastructure.json.types.SerializableOneOfTypeDefinition; import tech.pegasys.teku.infrastructure.json.types.SerializableOneOfTypeDefinitionBuilder; import tech.pegasys.teku.infrastructure.json.types.SerializableTypeDefinition; @@ -39,7 +39,6 @@ import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiEndpoint; import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiRequest; import tech.pegasys.teku.infrastructure.unsigned.UInt64; -import tech.pegasys.teku.spec.SpecMilestone; import tech.pegasys.teku.spec.datastructures.metadata.ObjectAndMetaData; import tech.pegasys.teku.spec.datastructures.operations.Attestation; import tech.pegasys.teku.spec.schemas.SchemaDefinitionCache; @@ -105,24 +104,14 @@ public void handleRequest(final RestApiRequest request) throws JsonProcessingExc private static SerializableTypeDefinition> getResponseType( final SchemaDefinitionCache schemaDefinitionCache) { - final DeserializableTypeDefinition electraAttestationTypeDef = - (DeserializableTypeDefinition) - schemaDefinitionCache - .getSchemaDefinition(SpecMilestone.ELECTRA) - .getAttestationSchema() - .getJsonTypeDefinition(); - - final DeserializableTypeDefinition phase0AttestationTypeDef = - (DeserializableTypeDefinition) - schemaDefinitionCache - .getSchemaDefinition(SpecMilestone.PHASE0) - .getAttestationSchema() - .getJsonTypeDefinition(); - final SerializableOneOfTypeDefinition oneOfTypeDefinition = new SerializableOneOfTypeDefinitionBuilder() - .withType(electraAttestationPredicate(), electraAttestationTypeDef) - .withType(phase0AttestationPredicate(), phase0AttestationTypeDef) + .withType( + electraAttestationPredicate(), + BeaconRestApiTypes.electraAttestationTypeDef(schemaDefinitionCache)) + .withType( + phase0AttestationPredicate(), + BeaconRestApiTypes.phase0AttestationTypeDef(schemaDefinitionCache)) .build(); return SerializableTypeDefinition.>object() @@ -139,6 +128,6 @@ private static Predicate phase0AttestationPredicate() { private static Predicate electraAttestationPredicate() { // Only once we are in Electra attestations will have committee bits - return attestation -> attestation.requiresCommitteeBits(); + return Attestation::requiresCommitteeBits; } }