Skip to content

Commit

Permalink
Rebase fixes with the api refac
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Jun 15, 2022
1 parent a1cc59d commit 9e57a7f
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 89 deletions.
4 changes: 1 addition & 3 deletions packages/api/src/beacon/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import * as lightclient from "./lightclient.js";
import * as lodestar from "./lodestar.js";
import * as node from "./node.js";
import * as validator from "./validator.js";
import * as builder from "./builder.js";

type ClientModules = HttpClientModules & {
config: IChainForkConfig;
Expand All @@ -20,7 +19,7 @@ type ClientModules = HttpClientModules & {
/**
* REST HTTP client for all routes
*/
export function getClient(opts: HttpClientOptions, modules: ClientModules): Api & {builder: BuilderApi} {
export function getClient(opts: HttpClientOptions, modules: ClientModules): Api {
const {config} = modules;
const httpClient = modules.httpClient ?? new HttpClient(opts, modules);

Expand All @@ -33,6 +32,5 @@ export function getClient(opts: HttpClientOptions, modules: ClientModules): Api
lodestar: lodestar.getClient(config, httpClient),
node: node.getClient(config, httpClient),
validator: validator.getClient(config, httpClient),
builder: builder.getClient(config, httpClient),
};
}
45 changes: 43 additions & 2 deletions packages/api/src/builder/routes.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,69 @@
import {ReturnTypes, RoutesData, ReqSerializers, reqEmpty, ReqEmpty} from "../utils/index.js";
import {ssz, bellatrix, Slot, Root, BLSPubkey} from "@chainsafe/lodestar-types";
import {fromHexString, toHexString} from "@chainsafe/ssz";
import {
ReturnTypes,
RoutesData,
Schema,
ReqSerializers,
reqOnlyBody,
ContainerData,
reqEmpty,
ReqEmpty,
ArrayOf,
} from "../utils/index.js";
// See /packages/api/src/routes/index.ts for reasoning and instructions to add new routes

export type Api = {
checkStatus(): Promise<void>;
registerValidator(regData: bellatrix.SignedValidatorRegistrationV1[]): Promise<void>;
getPayloadHeader(
slot: Slot,
parentHash: Root,
proposerPubKey: BLSPubkey
): Promise<{data: bellatrix.SignedBuilderBid}>;
submitSignedBlindedBlock(
signedBlock: bellatrix.SignedBlindedBeaconBlock
): Promise<{data: bellatrix.ExecutionPayload}>;
};

/**
* Define javascript values for each route
*/
export const routesData: RoutesData<Api> = {
checkStatus: {url: "/eth/v1/builder/status", method: "GET"},
registerValidator: {url: "/eth/v1/builder/validators", method: "POST"},
getPayloadHeader: {url: "/eth/v1/builder/header/:slot/:parent_hash/:pubkey", method: "GET"},
submitSignedBlindedBlock: {url: "/eth/v1/builder/blinded_blocks", method: "POST"},
};

/* eslint-disable @typescript-eslint/naming-convention */
export type ReqTypes = {
checkStatus: ReqEmpty;
registerValidator: {body: unknown};
getPayloadHeader: {params: {slot: Slot; parent_hash: string; pubkey: string}};
submitSignedBlindedBlock: {body: unknown};
};

export function getReqSerializers(): ReqSerializers<Api, ReqTypes> {
return {
checkStatus: reqEmpty,
registerValidator: reqOnlyBody(ArrayOf(ssz.bellatrix.SignedValidatorRegistrationV1), Schema.Object),
getPayloadHeader: {
writeReq: (slot, parentHash, proposerPubKey) => ({
params: {slot, parent_hash: toHexString(parentHash), pubkey: toHexString(proposerPubKey)},
}),
parseReq: ({params}) => [params.slot, fromHexString(params.parent_hash), fromHexString(params.pubkey)],
schema: {
params: {slot: Schema.UintRequired, parent_hash: Schema.StringRequired, pubkey: Schema.StringRequired},
},
},
submitSignedBlindedBlock: reqOnlyBody(ssz.bellatrix.SignedBlindedBeaconBlock, Schema.Object),
};
}

export function getReturnTypes(): ReturnTypes<Api> {
return {};
return {
getPayloadHeader: ContainerData(ssz.bellatrix.SignedBuilderBid),
submitSignedBlindedBlock: ContainerData(ssz.bellatrix.ExecutionPayload),
};
}
13 changes: 0 additions & 13 deletions packages/api/src/client/builder.ts

This file was deleted.

69 changes: 0 additions & 69 deletions packages/api/src/routes/builder.ts

This file was deleted.

4 changes: 2 additions & 2 deletions packages/lodestar/src/execution/builder/http.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import {bellatrix, Slot, Root, BLSPubkey} from "@chainsafe/lodestar-types";
import {IChainForkConfig} from "@chainsafe/lodestar-config";
import {getClient, BuilderApi} from "@chainsafe/lodestar-api";
import {getClient, Api as BuilderApi} from "@chainsafe/lodestar-api/builder";

import {IExecutionBuilder} from "./interface.js";

Expand All @@ -22,7 +22,7 @@ export class ExecutionBuilderHttp implements IExecutionBuilder {
constructor(opts: ExecutionBuilderHttpOpts, config: IChainForkConfig) {
const baseUrl = opts.urls[0];
if (!baseUrl) throw Error("No Url provided for executionBuilder");
this.api = getClient({baseUrl, timeoutMs: opts.timeout}, {config}).builder;
this.api = getClient({baseUrl, timeoutMs: opts.timeout}, {config});
}

async registerValidator(registrations: bellatrix.SignedValidatorRegistrationV1[]): Promise<void> {
Expand Down

0 comments on commit 9e57a7f

Please sign in to comment.