Skip to content

Commit

Permalink
feat: add response headers to produceBlockV3 (#6228)
Browse files Browse the repository at this point in the history
* Add `Eth-Consensus-Version` to produceBlockV3

* Lint

* Lint

* Add header
  • Loading branch information
ensi321 authored Dec 23, 2023
1 parent 267991a commit 61cf1a8
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions packages/api/src/beacon/server/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,28 @@ import {ServerRoutes, getGenericJsonServer} from "../../utils/server/index.js";
import {ServerApi} from "../../interfaces.js";

export function getRoutes(config: ChainForkConfig, api: ServerApi<Api>): ServerRoutes<Api, ReqTypes> {
// All routes return JSON, use a server auto-generator
return getGenericJsonServer<ServerApi<Api>, ReqTypes>({routesData, getReturnTypes, getReqSerializers}, config, api);
const reqSerializers = getReqSerializers();
const returnTypes = getReturnTypes();

// Most of routes return JSON, use a server auto-generator
const serverRoutes = getGenericJsonServer<ServerApi<Api>, ReqTypes>(
{routesData, getReturnTypes, getReqSerializers},
config,
api
);
return {
...serverRoutes,
produceBlockV3: {
...serverRoutes.produceBlockV3,
handler: async (req, res) => {
const response = await api.produceBlockV3(...reqSerializers.produceBlockV3.parseReq(req));
void res.header("Eth-Consensus-Version", response.version);
void res.header("Eth-Execution-Payload-Blinded", response.executionPayloadBlinded);
void res.header("Eth-Execution-Payload-Value", response.executionPayloadValue);
void res.header("Eth-Consensus-Block-Value", response.consensusBlockValue);

return returnTypes.produceBlockV3.toJson(response);
},
},
};
}

0 comments on commit 61cf1a8

Please sign in to comment.