From 2311d2952e52a7393e9ffb2292b83bc11f181bf7 Mon Sep 17 00:00:00 2001 From: pablomendezroyo Date: Fri, 10 Mar 2023 12:54:20 +0100 Subject: [PATCH 1/3] Implement get withdrawal creds on backned --- packages/brain/src/calls/validators.ts | 29 ++++++++++++++++++- .../src/types/customValidators/types.ts | 6 ++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/brain/src/calls/validators.ts b/packages/brain/src/calls/validators.ts index ba799a7a..28562619 100644 --- a/packages/brain/src/calls/validators.ts +++ b/packages/brain/src/calls/validators.ts @@ -16,6 +16,9 @@ import { Network, isFeeRecipientEditable, NonEditableFeeRecipientTag, + WithdrawalCredentialsFormat, + isValidEcdsaPubkey, + isValidBlsPubkey, } from "@stakingbrain/common"; import { beaconchainApi, @@ -319,17 +322,41 @@ export async function getValidators(): Promise { }); const validators: CustomValidatorGetResponse[] = []; - for (const [pubkey, { tag, feeRecipient }] of Object.entries(data)) + for (const [pubkey, { tag, feeRecipient }] of Object.entries(data)) { + let format: WithdrawalCredentialsFormat, + withdrawalAddress = ""; + try { + withdrawalAddress = ( + await beaconchainApi.getValidatorFromState({ + state: "head", + pubkey, + }) + ).data.validator.withdrawal_credentials; + format = isValidEcdsaPubkey(withdrawalAddress) + ? "ecdsa" + : isValidBlsPubkey(pubkey) + ? "bls" + : "unknown"; + } catch (e) { + logger.error(e); + format = "error"; + } + validators.push({ pubkey, tag, feeRecipient, + withdrawalCredentials: { + address: withdrawalAddress, + format, + }, validatorImported: validatorPubkeys.includes(pubkey), signerImported: signerPubkeys.includes(pubkey), validatorFeeRecipientCorrect: validatorsFeeRecipients.some( (feeRecipient) => feeRecipient === feeRecipient ), }); + } return validators; } diff --git a/packages/common/src/types/customValidators/types.ts b/packages/common/src/types/customValidators/types.ts index 8cb7cf78..aa1c0bcf 100644 --- a/packages/common/src/types/customValidators/types.ts +++ b/packages/common/src/types/customValidators/types.ts @@ -16,10 +16,16 @@ export interface CustomValidatorUpdateRequest { pubkey: string; feeRecipient: string; } + +export type WithdrawalCredentialsFormat = "ecdsa" | "bls" | "unknown" | "error"; export interface CustomValidatorGetResponse { pubkey: string; tag: Tag; feeRecipient: string; + withdrawalCredentials?: { + format: WithdrawalCredentialsFormat; + address: string; + }; signerImported?: boolean; validatorImported?: boolean; validatorFeeRecipientCorrect?: boolean; From 1412452126d0261935ec3ebb92e8ac8e1b5f15b5 Mon Sep 17 00:00:00 2001 From: pablomendezroyo Date: Fri, 10 Mar 2023 13:16:05 +0100 Subject: [PATCH 2/3] add withdrawal cred to the frontend --- .../src/types/customValidators/types.ts | 2 +- .../ValidatorList/KeystoresDataGrid.tsx | 23 +++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/packages/common/src/types/customValidators/types.ts b/packages/common/src/types/customValidators/types.ts index aa1c0bcf..aea2d44c 100644 --- a/packages/common/src/types/customValidators/types.ts +++ b/packages/common/src/types/customValidators/types.ts @@ -22,7 +22,7 @@ export interface CustomValidatorGetResponse { pubkey: string; tag: Tag; feeRecipient: string; - withdrawalCredentials?: { + withdrawalCredentials: { format: WithdrawalCredentialsFormat; address: string; }; diff --git a/packages/ui/src/components/ValidatorList/KeystoresDataGrid.tsx b/packages/ui/src/components/ValidatorList/KeystoresDataGrid.tsx index 1b899709..5a5a892e 100644 --- a/packages/ui/src/components/ValidatorList/KeystoresDataGrid.tsx +++ b/packages/ui/src/components/ValidatorList/KeystoresDataGrid.tsx @@ -12,7 +12,7 @@ import EditIcon from "@mui/icons-material/Edit"; import CheckCircleIcon from "@mui/icons-material/CheckCircle"; import CancelIcon from "@mui/icons-material/Cancel"; import HelpIcon from "@mui/icons-material/Help"; -import { CircularProgress, IconButton, Tooltip } from "@mui/material"; +import { Chip, CircularProgress, IconButton, Tooltip } from "@mui/material"; import { HeaderTypography } from "../../Styles/Typographies"; import { Box } from "@mui/system"; import UploadFileIcon from "@mui/icons-material/UploadFile"; @@ -120,6 +120,7 @@ export default function KeystoresDataGrid({ : "", feeRecipient: row.feeRecipient, tag: row.tag, + withdrawalCredentials: row.withdrawalCredentials, pubkeyInValidator: row.validatorImported, pubkeyInSigner: row.signerImported, feeRecipientImported: row.validatorFeeRecipientCorrect, @@ -138,8 +139,7 @@ export default function KeystoresDataGrid({ sortable: false, align: "center", headerAlign: "center", - // eslint-disable-next-line @typescript-eslint/no-explicit-any - renderCell: (rowData: any) => ( + renderCell: (rowData) => ( ( + + ), + headerClassName: "tableHeader", + width: 60, + }, { field: "pubkeyInSigner", headerName: "Pubkey In Signer", @@ -228,7 +244,6 @@ export default function KeystoresDataGrid({ } ); - async function getValidatorSummaryURL() { if (!beaconchaApiParamsMap?.get(network)) { setValidatorSummaryURL(""); From 4eab409ef147ff38ea797279f6677fc1ca17cfeb Mon Sep 17 00:00:00 2001 From: pablomendezroyo Date: Fri, 10 Mar 2023 13:39:55 +0100 Subject: [PATCH 3/3] Improve frontend --- .../ValidatorList/KeystoresDataGrid.tsx | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/packages/ui/src/components/ValidatorList/KeystoresDataGrid.tsx b/packages/ui/src/components/ValidatorList/KeystoresDataGrid.tsx index 5a5a892e..54c41953 100644 --- a/packages/ui/src/components/ValidatorList/KeystoresDataGrid.tsx +++ b/packages/ui/src/components/ValidatorList/KeystoresDataGrid.tsx @@ -12,7 +12,7 @@ import EditIcon from "@mui/icons-material/Edit"; import CheckCircleIcon from "@mui/icons-material/CheckCircle"; import CancelIcon from "@mui/icons-material/Cancel"; import HelpIcon from "@mui/icons-material/Help"; -import { Chip, CircularProgress, IconButton, Tooltip } from "@mui/material"; +import { CircularProgress, IconButton, Tooltip } from "@mui/material"; import { HeaderTypography } from "../../Styles/Typographies"; import { Box } from "@mui/system"; import UploadFileIcon from "@mui/icons-material/UploadFile"; @@ -153,9 +153,9 @@ export default function KeystoresDataGrid({ width: 60, }, { - field: "withdrawalFormat", - headerName: "Withdrawal Format", - description: "Withdrawal Address format of the validator", + field: "isWithdrawalEcdsa", + headerName: "WD is ECDSA", + description: "Weather the withdrawal address is ECDSA or not", disableReorder: true, disableColumnMenu: true, disableExport: true, @@ -163,10 +163,18 @@ export default function KeystoresDataGrid({ align: "center", headerAlign: "center", renderCell: (rowData) => ( - +
+ {rowData.row.withdrawalCredentials.format === "ecdsa" ? ( + + ) : rowData.row.withdrawalCredentials.format === "bls" ? ( + + ) : ( + + )} +
), headerClassName: "tableHeader", - width: 60, + width: 120, }, { field: "pubkeyInSigner",