-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(explorer): add validators joining next epoch (#5269)
* first steps * feat: add hook * feat: see logs * cleanup * fix import * fix format * minor fixes * fix foramt * fix types * resolve comments * fix import * fix: show correct information * cleanup * concat pending validators * fix lint * feat: reorder two lines * feat: move to types folder * fix lint * fix build --------- Co-authored-by: Marc Espin <[email protected]>
- Loading branch information
1 parent
0072f5b
commit d0d0f6d
Showing
8 changed files
with
181 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ | |
export * from './constants'; | ||
export * from './enums'; | ||
export * from './utils'; | ||
export * from './types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './validator.types'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { type IotaValidatorSummary } from '@iota/iota-sdk/client'; | ||
|
||
export type IotaValidatorSummaryExtended = IotaValidatorSummary & { isPending?: boolean }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
// Copyright (c) 2024 IOTA Stiftung | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
import type { IotaObjectResponse, MoveStruct, MoveValue } from '@iota/iota-sdk/client'; | ||
import type { IotaValidatorSummaryExtended } from '../types'; | ||
|
||
function isMoveStructWithFields( | ||
data: MoveStruct, | ||
): data is { fields: { [key: string]: MoveValue }; type: string } { | ||
return ( | ||
typeof data === 'object' && | ||
data !== null && | ||
'fields' in data && | ||
typeof data.fields === 'object' && | ||
data.fields !== null | ||
); | ||
} | ||
|
||
function getMoveFields(object: MoveStruct): { [key: string]: MoveValue } { | ||
if (isMoveStructWithFields(object)) { | ||
return object.fields as { [key: string]: MoveValue }; | ||
} | ||
return {}; | ||
} | ||
|
||
interface MoveStructFields { | ||
fields: { [key: string]: MoveValue }; | ||
} | ||
|
||
export function sanitizePendingValidators( | ||
allPendings: IotaObjectResponse[] | undefined, | ||
): IotaValidatorSummaryExtended[] { | ||
return ( | ||
allPendings?.map(({ data }) => { | ||
const fields = | ||
(data && | ||
data.content && | ||
data.content.dataType === 'moveObject' && | ||
getMoveFields(data.content)) || | ||
{} || | ||
{}; | ||
const value = fields.value as MoveStructFields; | ||
const metadata = (value?.fields?.metadata as MoveStructFields)?.fields || {}; | ||
const stakingPool = (value?.fields?.staking_pool as MoveStructFields)?.fields || {}; | ||
const exchangeRates = (stakingPool.exchange_rates as MoveStructFields)?.fields || {}; | ||
|
||
return { | ||
isPending: true, | ||
authorityPubkeyBytes: '', | ||
commissionRate: String(value?.fields.commission_rate), | ||
description: String(metadata.description), | ||
exchangeRatesId: ( | ||
exchangeRates.id as { | ||
id: string; | ||
} | ||
)?.id, | ||
exchangeRatesSize: String(exchangeRates.size), | ||
gasPrice: String(value?.fields.gas_price), | ||
imageUrl: String(metadata.image_url), | ||
iotaAddress: String(metadata.iota_address), | ||
name: String(metadata.name), | ||
netAddress: String(metadata.net_address), | ||
networkPubkeyBytes: '', | ||
nextEpochCommissionRate: String(value?.fields.next_epoch_commission_rate), | ||
nextEpochGasPrice: String(value?.fields.next_epoch_gas_price), | ||
nextEpochStake: String(value?.fields.next_epoch_stake), | ||
operationCapId: String(value?.fields.operation_cap_id), | ||
p2pAddress: String(metadata.p2p_address), | ||
pendingPoolTokenWithdraw: String(stakingPool.pending_pool_token_withdraw), | ||
pendingStake: String(stakingPool.pending_stake), | ||
pendingTotalIotaWithdraw: String(stakingPool.pending_total_iota_withdraw), | ||
poolTokenBalance: String(stakingPool.pool_token_balance), | ||
primaryAddress: String(metadata.primary_address), | ||
projectUrl: String(metadata.project_url), | ||
proofOfPossessionBytes: '', | ||
protocolPubkeyBytes: '', | ||
rewardsPool: String(stakingPool.rewards_pool), | ||
stakingPoolId: ( | ||
stakingPool.id as { | ||
id: string; | ||
} | ||
)?.id, | ||
stakingPoolIotaBalance: String(stakingPool.iota_balance), | ||
votingPower: String(value?.fields.voting_power), | ||
}; | ||
}) || [] | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters