From 2207ec4006c9084af7be246b0f2b11f72922698b Mon Sep 17 00:00:00 2001 From: Hiroyuki Naito Date: Fri, 8 Mar 2024 19:25:59 +0900 Subject: [PATCH] Completed Interface and routes --- packages/api/src/builder/routes.ts | 39 +++++++++++++++++++--- packages/api/test/unit/builder/testData.ts | 15 +++++++++ 2 files changed, 49 insertions(+), 5 deletions(-) diff --git a/packages/api/src/builder/routes.ts b/packages/api/src/builder/routes.ts index 991c7ecbb55b..f1612aca17bb 100644 --- a/packages/api/src/builder/routes.ts +++ b/packages/api/src/builder/routes.ts @@ -1,8 +1,8 @@ import {fromHexString, toHexString} from "@chainsafe/ssz"; -import {ssz, allForks, bellatrix, Slot, Root, BLSPubkey, StateId} from "@lodestar/types"; +import {ssz, allForks, bellatrix, Slot, Root, BLSPubkey, ValidatorIndex, WithdrawalIndex} from "@lodestar/types"; import {ForkName, isForkExecution, isForkBlobs} from "@lodestar/params"; import {ChainForkConfig} from "@lodestar/config"; - +import {UintNum64} from "@lodestar/types/src/primitive/types.js"; import { ReturnTypes, RoutesData, @@ -13,11 +13,21 @@ import { ReqEmpty, ArrayOf, WithVersion, + jsonType, } from "../utils/index.js"; // See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes import {getReqSerializers as getBeaconReqSerializers} from "../beacon/routes/beacon/block.js"; import {HttpStatusCode} from "../utils/client/httpStatusCode.js"; import {ApiClientResponse} from "../interfaces.js"; +import {StateId, ExecutionOptimistic} from "../beacon/routes/beacon/state.js"; + +export type Finalized = boolean; +export type ExpectedWithdrawals = { + index: WithdrawalIndex; + validatorIndex: ValidatorIndex; + address: string; + amount: UintNum64; +}; export type Api = { status(): Promise>; @@ -46,10 +56,17 @@ export type Api = { > >; getExpectedWithdrawals( - stateId: StateId + state_id: StateId, + proposal_slot?: Slot ): Promise< ApiClientResponse< - {[HttpStatusCode.OK]: {execution_optimistic: Boolean, finalized: Boolean; data: allForks.SignedBuilderBid}}, + { + [HttpStatusCode.OK]: { + executionOptimistic: ExecutionOptimistic; + finalized: Finalized; + data: ExpectedWithdrawals[]; + }; + }, HttpStatusCode.NOT_FOUND | HttpStatusCode.BAD_REQUEST > >; @@ -72,7 +89,7 @@ export type ReqTypes = { registerValidator: {body: unknown}; getHeader: {params: {slot: Slot; parent_hash: string; pubkey: string}}; submitBlindedBlock: {body: unknown}; - getExpectedWithdrawals: {query: {proposal_slot: Slot}}; + getExpectedWithdrawals: {params: {state_id: StateId}; query: {proposal_slot?: Slot}}; }; export function getReqSerializers(config: ChainForkConfig): ReqSerializers { @@ -89,6 +106,17 @@ export function getReqSerializers(config: ChainForkConfig): ReqSerializers ({ + params: {state_id}, + query: {proposal_slot}, + }), + parseReq: ({params, query}) => [params.state_id, query.proposal_slot ?? 0], + schema: { + params: {state_id: Schema.StringRequired}, + query: {proposal_slot: Schema.Uint}, + }, + }, }; } @@ -105,5 +133,6 @@ export function getReturnTypes(): ReturnTypes { ? ssz.allForksExecution[fork].ExecutionPayload : ssz.bellatrix.ExecutionPayload ), + getExpectedWithdrawals: jsonType("snake"), }; } diff --git a/packages/api/test/unit/builder/testData.ts b/packages/api/test/unit/builder/testData.ts index e198e6971905..cb949dda8d53 100644 --- a/packages/api/test/unit/builder/testData.ts +++ b/packages/api/test/unit/builder/testData.ts @@ -26,4 +26,19 @@ export const testData: GenericServerTestCases = { args: [ssz.deneb.SignedBlindedBeaconBlock.defaultValue()], res: {version: ForkName.bellatrix, data: ssz.bellatrix.ExecutionPayload.defaultValue()}, }, + getExpectedWithdrawals: { + args: ["head", 1], + res: { + executionOptimistic: false, + finalized: false, + data: [ + { + index: 1, + validatorIndex: 1, + address: "0xAbcF8e0d4e9587369b2301D0790347320302cc09", + amount: 1, + }, + ], + }, + }, };