Skip to content

Commit

Permalink
Make slashingProtectionStr optional (#4296)
Browse files Browse the repository at this point in the history
  • Loading branch information
dapplion authored Jul 17, 2022
1 parent 13558b5 commit ab13fe2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/api/src/keymanager/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ export type Api = {
importKeystores(
keystoresStr: KeystoreStr[],
passwords: string[],
slashingProtectionStr: SlashingProtectionData
slashingProtectionStr?: SlashingProtectionData
): Promise<{
data: ResponseStatus<ImportStatus>[];
}>;
Expand Down Expand Up @@ -184,7 +184,7 @@ export type ReqTypes = {
body: {
keystores: KeystoreStr[];
passwords: string[];
slashingProtection: SlashingProtectionData;
slashingProtection?: SlashingProtectionData;
};
};
deleteKeystores: {body: {pubkeys: string[]}};
Expand Down
18 changes: 10 additions & 8 deletions packages/cli/src/cmds/validator/keymanager/impl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,17 @@ export class KeymanagerApi implements Api {
async importKeystores(
keystoresStr: KeystoreStr[],
passwords: string[],
slashingProtectionStr: SlashingProtectionData
slashingProtectionStr?: SlashingProtectionData
): ReturnType<Api["importKeystores"]> {
// The arguments to this function is passed in within the body of an HTTP request
// hence fastify will parse it into an object before this function is called.
// Even though the slashingProtectionStr is typed as SlashingProtectionData,
// at runtime, when the handler for the request is selected, it would see slashingProtectionStr
// as an object, hence trying to parse it using JSON.parse won't work. Instead, we cast straight to Interchange
const interchange = ensureJSON<Interchange>(slashingProtectionStr);
await this.validator.importInterchange(interchange);
if (slashingProtectionStr) {
// The arguments to this function is passed in within the body of an HTTP request
// hence fastify will parse it into an object before this function is called.
// Even though the slashingProtectionStr is typed as SlashingProtectionData,
// at runtime, when the handler for the request is selected, it would see slashingProtectionStr
// as an object, hence trying to parse it using JSON.parse won't work. Instead, we cast straight to Interchange
const interchange = ensureJSON<Interchange>(slashingProtectionStr);
await this.validator.importInterchange(interchange);
}

const statuses: {status: ImportStatus; message?: string}[] = [];

Expand Down

0 comments on commit ab13fe2

Please sign in to comment.