Skip to content

Commit e1d30db

Browse files
committed
chore: dedup mapToGeneralStatus()
1 parent 3aa9e07 commit e1d30db

File tree

1 file changed

+10
-23
lines changed
  • packages/beacon-node/src/api/impl/beacon/state

1 file changed

+10
-23
lines changed

packages/beacon-node/src/api/impl/beacon/state/utils.ts

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,16 @@ import {routes} from "@lodestar/api";
33
import {CheckpointWithHex, IForkChoice} from "@lodestar/fork-choice";
44
import {GENESIS_SLOT} from "@lodestar/params";
55
import {BeaconStateAllForks, CachedBeaconStateAllForks} from "@lodestar/state-transition";
6-
import {BLSPubkey, Epoch, RootHex, Slot, ValidatorIndex, getValidatorStatus, phase0} from "@lodestar/types";
6+
import {
7+
BLSPubkey,
8+
Epoch,
9+
RootHex,
10+
Slot,
11+
ValidatorIndex,
12+
getValidatorStatus,
13+
mapToGeneralStatus,
14+
phase0,
15+
} from "@lodestar/types";
716
import {fromHex} from "@lodestar/utils";
817
import {IBeaconChain} from "../../../../chain/index.js";
918
import {ApiError, ValidationError} from "../../errors.js";
@@ -65,28 +74,6 @@ export async function getStateResponseWithRegen(
6574
return res;
6675
}
6776

68-
type GeneralValidatorStatus = "active" | "pending" | "exited" | "withdrawal";
69-
70-
function mapToGeneralStatus(subStatus: routes.beacon.ValidatorStatus): GeneralValidatorStatus {
71-
switch (subStatus) {
72-
case "active_ongoing":
73-
case "active_exiting":
74-
case "active_slashed":
75-
return "active";
76-
case "pending_initialized":
77-
case "pending_queued":
78-
return "pending";
79-
case "exited_slashed":
80-
case "exited_unslashed":
81-
return "exited";
82-
case "withdrawal_possible":
83-
case "withdrawal_done":
84-
return "withdrawal";
85-
default:
86-
throw new Error(`Unknown substatus: ${subStatus}`);
87-
}
88-
}
89-
9077
export function toValidatorResponse(
9178
index: ValidatorIndex,
9279
validator: phase0.Validator,

0 commit comments

Comments
 (0)