Skip to content

Commit

Permalink
fix the return types
Browse files Browse the repository at this point in the history
  • Loading branch information
g11tech committed Sep 6, 2022
1 parent d7e9d61 commit 38d5150
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 56 deletions.
4 changes: 0 additions & 4 deletions packages/api/src/keymanager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,6 @@ export {
ImportRemoteKeyStatus,
DeleteRemoteKeyStatus,
ResponseStatus,
SetFeeRecipientStatus,
DeleteFeeRecipientStatus,
SetGasLimitStatus,
DeleteGasLimitStatus,
SignerDefinition,
KeystoreStr,
SlashingProtectionData,
Expand Down
52 changes: 15 additions & 37 deletions packages/api/src/keymanager/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,31 +42,20 @@ export enum DeleteRemoteKeyStatus {
error = "error",
}

export enum SetFeeRecipientStatus {
set = "successfully updated",
error = "error",
}

export enum DeleteFeeRecipientStatus {
deleted = "Successfully deleted",
error = "error",
}

export enum SetGasLimitStatus {
set = "successfully updated",
error = "error",
}

export enum DeleteGasLimitStatus {
deleted = "Successfully deleted",
error = "error",
}

export type ResponseStatus<Status> = {
status: Status;
message?: string;
};

export type FeeRecipientData = {
pubkey: string;
ethaddress: string;
};
export type GasLimitData = {
pubkey: string;
gasLimit: string;
};

export type SignerDefinition = {
pubkey: PubkeyHex;
/**
Expand Down Expand Up @@ -190,24 +179,18 @@ export type Api = {
getFeeRecipient(
pubkey: string
): Promise<{
data: {
pubkey: string;
ethaddress: string;
};
data: FeeRecipientData;
}>;
setFeeRecipient(pubkey: string, ethaddress: string): Promise<{data: ResponseStatus<SetFeeRecipientStatus>}>;
deleteFeeRecipient(pubkey: string): Promise<{data: ResponseStatus<DeleteFeeRecipientStatus>}>;
setFeeRecipient(pubkey: string, ethaddress: string): Promise<void>;
deleteFeeRecipient(pubkey: string): Promise<void>;

getGasLimit(
pubkey: string
): Promise<{
data: {
pubkey: string;
gas_limit: string;
};
data: GasLimitData;
}>;
setGasLimit(pubkey: string, ethaddress: string): Promise<{data: ResponseStatus<SetGasLimitStatus>}>;
deleteGasLimit(pubkey: string): Promise<{data: ResponseStatus<DeleteGasLimitStatus>}>;
setGasLimit(pubkey: string, ethaddress: string): Promise<void>;
deleteGasLimit(pubkey: string): Promise<void>;
};

export const routesData: RoutesData<Api> = {
Expand Down Expand Up @@ -344,11 +327,6 @@ export function getReturnTypes(): ReturnTypes<Api> {
deleteRemoteKeys: jsonType("snake"),

getFeeRecipient: jsonType("snake"),
setFeeRecipient: jsonType("snake"),
deleteFeeRecipient: jsonType("snake"),

getGasLimit: jsonType("snake"),
setGasLimit: jsonType("snake"),
deleteGasLimit: jsonType("snake"),
};
}
20 changes: 6 additions & 14 deletions packages/cli/src/cmds/validator/keymanager/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ import {
SlashingProtectionData,
SignerDefinition,
ImportRemoteKeyStatus,
SetFeeRecipientStatus,
DeleteFeeRecipientStatus,
SetGasLimitStatus,
DeleteGasLimitStatus,
} from "@lodestar/api/keymanager";
import {fromHexString} from "@chainsafe/ssz";
import {Interchange, SignerType, Validator} from "@lodestar/validator";
Expand All @@ -33,45 +29,41 @@ export class KeymanagerApi implements Api {
}
}

async setFeeRecipient(pubkeyHex: string, ethaddress: string): ReturnType<Api["setFeeRecipient"]> {
async setFeeRecipient(pubkeyHex: string, ethaddress: string): Promise<void> {
try {
this.validator.validatorStore.setFeeRecipient(pubkeyHex, parseFeeRecipient(ethaddress));
return {data: {status: SetFeeRecipientStatus.set}};
} catch (e) {
throw Error((e as Error).message);
}
}

async deleteFeeRecipient(pubkeyHex: string): ReturnType<Api["deleteFeeRecipient"]> {
async deleteFeeRecipient(pubkeyHex: string): Promise<void> {
try {
this.validator.validatorStore.deleteFeeRecipient(pubkeyHex);
return {data: {status: DeleteFeeRecipientStatus.deleted}};
} catch (e) {
throw Error((e as Error).message);
}
}

async getGasLimit(pubkeyHex: string): ReturnType<Api["getGasLimit"]> {
try {
return {data: {pubkey: pubkeyHex, gas_limit: String(this.validator.validatorStore.getGasLimit(pubkeyHex))}};
return {data: {pubkey: pubkeyHex, gasLimit: String(this.validator.validatorStore.getGasLimit(pubkeyHex))}};
} catch (e) {
throw Error((e as Error).message);
}
}

async setGasLimit(pubkeyHex: string, gas_limit: string): ReturnType<Api["setGasLimit"]> {
async setGasLimit(pubkeyHex: string, gasLimit: string): Promise<void> {
try {
this.validator.validatorStore.setGasLimit(pubkeyHex, gas_limit);
return {data: {status: SetGasLimitStatus.set}};
this.validator.validatorStore.setGasLimit(pubkeyHex, gasLimit);
} catch (e) {
throw Error((e as Error).message);
}
}

async deleteGasLimit(pubkeyHex: string): ReturnType<Api["deleteGasLimit"]> {
async deleteGasLimit(pubkeyHex: string): Promise<void> {
try {
this.validator.validatorStore.deleteGasLimit(pubkeyHex);
return {data: {status: DeleteGasLimitStatus.deleted}};
} catch (e) {
throw Error((e as Error).message);
}
Expand Down
2 changes: 1 addition & 1 deletion packages/validator/src/services/validatorStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ export class ValidatorStore {
}
}

setGasLimit(pubkeyHex: PubkeyHex, gasLimitString: string): void {
setGasLimit(pubkeyHex: PubkeyHex, gasLimitString: string | number): void {
if (Number.isNaN(Number(gasLimitString))) {
throw Error("Gas Limit is Not a number");
}
Expand Down

0 comments on commit 38d5150

Please sign in to comment.