Skip to content

Commit

Permalink
Added a expected withdrawals API interface
Browse files Browse the repository at this point in the history
  • Loading branch information
HiroyukiNaito committed Mar 13, 2024
1 parent 918924e commit 06f0039
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions packages/api/src/beacon/routes/builder.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {Slot, ValidatorIndex, WithdrawalIndex} from "@lodestar/types";
import {ReturnTypes, RoutesData, Schema, sameType, ReqSerializers} from "../../utils/index.js";
import {HttpStatusCode} from "../../utils/client/httpStatusCode.js";
import {ApiClientResponse} from "../../interfaces.js";
import {StateId, ExecutionOptimistic} from "./beacon/state.js";

export type ExpectedWithdrawals = {
index: WithdrawalIndex;
validatorIndex: ValidatorIndex;
address: string;
amount: number;
};

// See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes

export type Api = {
getExpectedWithdrawals(
stateId: StateId,
proposalSlot?: Slot | undefined
): Promise<
ApiClientResponse<
{
[HttpStatusCode.OK]: {
executionOptimistic: ExecutionOptimistic;
data: ExpectedWithdrawals[];
};
},
HttpStatusCode.NOT_FOUND | HttpStatusCode.BAD_REQUEST
>
>;
};
/**
* Define javascript values for each route
*/
export const routesData: RoutesData<Api> = {
getExpectedWithdrawals: {url: "/eth/v1/builder/states/{state_id}/expected_withdrawals", method: "GET"},
};

/* eslint-disable @typescript-eslint/naming-convention */
export type ReqTypes = {
getExpectedWithdrawals: {params: {state_id: StateId}; query: {proposal_slot?: Slot | undefined}};
};

export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
return {
getExpectedWithdrawals: {
writeReq: (state_id, proposal_slot) => ({
params: {state_id},
query: {proposal_slot},
}),
parseReq: ({params, query}) => [params.state_id, query.proposal_slot],
schema: {
params: {state_id: Schema.StringRequired},
query: {proposal_slot: Schema.Uint},
},
},
};
}

export function getReturnTypes(): ReturnTypes<Api> {
return {
// Just sent the proof JSON as-is
getExpectedWithdrawals: sameType(),
};
}

0 comments on commit 06f0039

Please sign in to comment.