Skip to content

Commit edc12e8

Browse files
committed
Fix set graffiti request
1 parent cad8580 commit edc12e8

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

validator/client/src/main/java/tech/pegasys/teku/validator/client/restapi/apis/SetGraffiti.java

+15-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
import com.fasterxml.jackson.core.JsonProcessingException;
2424
import java.io.IOException;
2525
import java.util.Optional;
26+
import java.util.function.Function;
2627
import tech.pegasys.teku.bls.BLSPublicKey;
28+
import tech.pegasys.teku.infrastructure.json.types.DeserializableTypeDefinition;
2729
import tech.pegasys.teku.infrastructure.restapi.endpoints.EndpointMetadata;
2830
import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiEndpoint;
2931
import tech.pegasys.teku.infrastructure.restapi.endpoints.RestApiRequest;
@@ -35,6 +37,18 @@ public class SetGraffiti extends RestApiEndpoint {
3537
private final KeyManager keyManager;
3638
private final GraffitiManager graffitiManager;
3739

40+
public static final DeserializableTypeDefinition<String> GRAFFITI_REQUEST_TYPE =
41+
DeserializableTypeDefinition.object(String.class, StringBuilder.class)
42+
.initializer(StringBuilder::new)
43+
.finisher(StringBuilder::toString)
44+
.withField(
45+
"graffiti",
46+
STRING_TYPE.withDescription(
47+
"Arbitrary data to set in the graffiti field of BeaconBlockBody"),
48+
Function.identity(),
49+
StringBuilder::append)
50+
.build();
51+
3852
public SetGraffiti(final KeyManager keyManager, final GraffitiManager graffitiManager) {
3953
super(
4054
EndpointMetadata.post(GetGraffiti.ROUTE)
@@ -44,7 +58,7 @@ public SetGraffiti(final KeyManager keyManager, final GraffitiManager graffitiMa
4458
.tags(TAG_GRAFFITI)
4559
.withBearerAuthSecurity()
4660
.pathParam(PARAM_PUBKEY_TYPE)
47-
.requestBodyType(STRING_TYPE.withDescription("Graffiti string"))
61+
.requestBodyType(GRAFFITI_REQUEST_TYPE)
4862
.response(SC_NO_CONTENT, "Successfully updated graffiti.")
4963
.withAuthenticationResponses()
5064
.withNotFoundResponse()

validator/client/src/test/resources/tech/pegasys/teku/validator/client/restapi/paths/_eth_v1_validator_{pubkey}_graffiti.json

+8-2
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,14 @@
9999
"content" : {
100100
"application/json" : {
101101
"schema" : {
102-
"type" : "string",
103-
"description" : "Graffiti string"
102+
"type" : "object",
103+
"required" : [ "graffiti" ],
104+
"properties" : {
105+
"graffiti" : {
106+
"type" : "string",
107+
"description" : "Arbitrary data to set in the graffiti field of BeaconBlockBody"
108+
}
109+
}
104110
}
105111
}
106112
}

0 commit comments

Comments
 (0)