diff --git a/src/services/coretime/CoretimeService.spec.ts b/src/services/coretime/CoretimeService.spec.ts index f9cf2155b..12f052346 100644 --- a/src/services/coretime/CoretimeService.spec.ts +++ b/src/services/coretime/CoretimeService.spec.ts @@ -14,8 +14,8 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import { ApiPromise } from '@polkadot/api'; -import { Hash } from '@polkadot/types/interfaces'; +import type { ApiPromise } from '@polkadot/api'; +import type { Hash } from '@polkadot/types/interfaces'; import { kusamaCoretimeMetadata } from '../../test-helpers/metadata/coretimeKusamaMetadata'; import { kusamaMetadataV1003003 } from '../../test-helpers/metadata/kusamaMetadataV1003003'; diff --git a/src/services/coretime/CoretimeService.ts b/src/services/coretime/CoretimeService.ts index 0b9c3b8c4..8d8076033 100644 --- a/src/services/coretime/CoretimeService.ts +++ b/src/services/coretime/CoretimeService.ts @@ -17,25 +17,25 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . -import { ApiDecoration, QueryableModuleStorage } from '@polkadot/api/types'; -import { Option, StorageKey, U16, U32, Vec } from '@polkadot/types'; -import { BlockHash, ParaId } from '@polkadot/types/interfaces'; -import { - PalletBrokerConfigRecord, - PalletBrokerLeaseRecordItem, - PalletBrokerPotentialRenewalId, - PalletBrokerPotentialRenewalRecord, - PalletBrokerRegionId, - PalletBrokerRegionRecord, - PalletBrokerSaleInfoRecord, - PalletBrokerScheduleItem, - PalletBrokerStatusRecord, +import type { ApiDecoration, QueryableModuleStorage } from '@polkadot/api/types'; +import type { Option, StorageKey, U32 } from '@polkadot/types'; +import type { BlockHash, ParaId } from '@polkadot/types/interfaces'; +import type { + // PalletBrokerConfigRecord, + // PalletBrokerLeaseRecordItem, + // PalletBrokerPotentialRenewalId, + // PalletBrokerPotentialRenewalRecord, + // PalletBrokerRegionId, + // PalletBrokerRegionRecord, + // PalletBrokerSaleInfoRecord, + // PalletBrokerScheduleItem, + // PalletBrokerStatusRecord, PolkadotRuntimeParachainsAssignerCoretimeCoreDescriptor, PolkadotRuntimeParachainsParasParaLifecycle, } from '@polkadot/types/lookup'; import { BN } from '@polkadot/util'; -import { +import type { ICoretimeChainInfo, ICoretimeCores, ICoretimeLeases, @@ -82,9 +82,7 @@ const SCALE = new BN(10000); export class CoretimeService extends AbstractService { private getAndDecodeRegions = async (api: ApiDecoration<'promise'>): Promise => { const regions = await api.query.broker.regions.entries(); - const regs = regions as unknown as [StorageKey<[PalletBrokerRegionId]>, Option][]; - - const regionsInfo = regs.map((region) => { + const regionsInfo = regions.map((region) => { return extractRegionInfo([region[0], region[1]]); }); @@ -93,15 +91,14 @@ export class CoretimeService extends AbstractService { private getAndDecodeLeases = async (api: ApiDecoration<'promise'>): Promise => { const leases = await api.query.broker.leases(); - return (leases as unknown as Vec).map((lease) => extractLeaseInfo(lease)); + return leases.map((lease) => extractLeaseInfo(lease)); }; private getAndDecodeWorkload = async (api: ApiDecoration<'promise'>): Promise => { const workloads = await api.query.broker.workload.entries(); - const wls = workloads as unknown as [StorageKey<[U32]>, Vec][]; return sortByCore( - wls.map((workload) => { + workloads.map((workload) => { return extractWorkloadInfo(workload[1], workload[0].args[0].toNumber()); }), ); @@ -109,10 +106,10 @@ export class CoretimeService extends AbstractService { private getAndDecodeWorkplan = async (api: ApiDecoration<'promise'>): Promise => { const workplans = await api.query.broker.workplan.entries(); - const wpls = workplans as unknown as [StorageKey<[U32, U16]>, Option>][]; + const wplsInfo = sortByCore( - wpls.map(([key, val]) => { - const [timeslice, core] = key.args[0].toArray(); + workplans.map(([key, val]) => { + const [timeslice, core] = key.args[0].map((a) => a.toNumber()); return extractWorkplanInfo(val, core, timeslice); }), ); @@ -121,30 +118,27 @@ export class CoretimeService extends AbstractService { }; private getAndDecodeSaleInfo = async (api: ApiDecoration<'promise'>): Promise => { - const saleInfo = (await api.query.broker.saleInfo()) as unknown as Option; + const saleInfo = await api.query.broker.saleInfo(); return saleInfo.isSome ? extractSaleInfo(saleInfo.unwrap()) : null; }; private getAndDecodeStatus = async (api: ApiDecoration<'promise'>): Promise => { const status = await api.query.broker.status(); - return extractStatusInfo(status as unknown as Option); + return extractStatusInfo(status); }; private getAndDecodeConfiguration = async (api: ApiDecoration<'promise'>): Promise => { const configuration = await api.query.broker.configuration(); - return extractConfigInfo(configuration as unknown as Option); + return extractConfigInfo(configuration); }; private getAndDecodePotentialRenewals = async (api: ApiDecoration<'promise'>): Promise => { const potentialRenewals = await api.query.broker.potentialRenewals.entries(); - const renewals = potentialRenewals as unknown as [ - StorageKey<[PalletBrokerPotentialRenewalId]>, - Option, - ][]; + const potentialRenewalsInfo = sortByCore( - renewals.map((renewal) => extractPotentialRenewalInfo(renewal[1], renewal[0])), + potentialRenewals.map((renewal) => extractPotentialRenewalInfo(renewal[1], renewal[0])), ); return potentialRenewalsInfo; @@ -153,7 +147,7 @@ export class CoretimeService extends AbstractService { private getAndDecodeReservations = async (api: ApiDecoration<'promise'>): Promise => { const reservations = await api.query.broker.reservations(); - return (reservations as unknown as Vec>).map((res) => extractReservationInfo(res)); + return reservations.map((res) => extractReservationInfo(res)); }; private getAndDecodeCoreSchedules = async (api: ApiDecoration<'promise'>): Promise[]> => { @@ -591,7 +585,7 @@ export class CoretimeService extends AbstractService { } private getChainType(specName: string): ChainType { - const relay = ['polkadot', 'kusama', 'westend', 'rococo', 'paseo']; + const relay = ['polkadot', 'kusama', 'westend', 'paseo']; if (relay.includes(specName.toLowerCase())) { return ChainType.Relay; } else { diff --git a/src/services/coretime/util.ts b/src/services/coretime/util.ts index 90515c191..6f0f5df7f 100644 --- a/src/services/coretime/util.ts +++ b/src/services/coretime/util.ts @@ -17,7 +17,8 @@ import { PolkadotRuntimeParachainsAssignerCoretimeWorkState, PolkadotRuntimeParachainsParasParaLifecycle, } from '@polkadot/types/lookup'; -import { Option, U32, Vec } from '@polkadot/types-codec'; +import { Option, Vec } from '@polkadot/types-codec'; +import { AnyTuple } from '@polkadot/types-codec/types'; import { BN } from '@polkadot/util'; import { @@ -209,7 +210,7 @@ export function extractConfigInfo(info: Option): TConf } export function extractCoreDescriptorInfo( - _key: StorageKey<[U32]>, + _key: StorageKey, info: PolkadotRuntimeParachainsAssignerCoretimeCoreDescriptor, ): TCoreDescriptor { const currentWork: PolkadotRuntimeParachainsAssignerCoretimeWorkState | null = info?.currentWork.isSome