Skip to content

Commit

Permalink
Completed Interface and routes
Browse files Browse the repository at this point in the history
  • Loading branch information
HiroyukiNaito committed Mar 8, 2024
1 parent 1c58047 commit 2207ec4
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 5 deletions.
39 changes: 34 additions & 5 deletions packages/api/src/builder/routes.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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<ApiClientResponse<{[HttpStatusCode.OK]: void}, HttpStatusCode.SERVICE_UNAVAILABLE>>;
Expand Down Expand Up @@ -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
>
>;
Expand All @@ -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<Api, ReqTypes> {
Expand All @@ -89,6 +106,17 @@ export function getReqSerializers(config: ChainForkConfig): ReqSerializers<Api,
},
},
submitBlindedBlock: getBeaconReqSerializers(config)["publishBlindedBlock"],
getExpectedWithdrawals: {
writeReq: (state_id, proposal_slot) => ({
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},
},
},
};
}

Expand All @@ -105,5 +133,6 @@ export function getReturnTypes(): ReturnTypes<Api> {
? ssz.allForksExecution[fork].ExecutionPayload
: ssz.bellatrix.ExecutionPayload
),
getExpectedWithdrawals: jsonType("snake"),
};
}
15 changes: 15 additions & 0 deletions packages/api/test/unit/builder/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,19 @@ export const testData: GenericServerTestCases<Api> = {
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,
},
],
},
},
};

0 comments on commit 2207ec4

Please sign in to comment.