diff --git a/packages/balances/src/modules/util/buildStorageCoders.ts b/packages/balances/src/modules/util/buildStorageCoders.ts index 6eb0872bcc..b3aecf9485 100644 --- a/packages/balances/src/modules/util/buildStorageCoders.ts +++ b/packages/balances/src/modules/util/buildStorageCoders.ts @@ -1,5 +1,5 @@ import { ChainId, ChainList } from "@talismn/chaindata-provider" -import { V14, V15, getDynamicBuilder, metadata as scaleMetadata } from "@talismn/scale" +import { decodeMetadata, getDynamicBuilder } from "@talismn/scale" import log from "../../log" import { MiniMetadata } from "../../types" @@ -30,14 +30,8 @@ export const buildStorageCoders = < const [, miniMetadata] = findChainMeta(miniMetadatas, moduleType, chain) if (!miniMetadata) return [] if (!miniMetadata.data) return [] - if (miniMetadata.version !== 15 && miniMetadata.version !== 14) return [] - const [metadata, tag] = ((): [V15, "v15"] | [V14, "v14"] | [] => { - const decoded = scaleMetadata.dec(miniMetadata.data) - if (decoded.metadata.tag === "v15") return [decoded.metadata.value, decoded.metadata.tag] - if (decoded.metadata.tag === "v14") return [decoded.metadata.value, decoded.metadata.tag] - return [] - })() + const { metadata, tag } = decodeMetadata(miniMetadata.data) if (!metadata || !tag) return [] try { diff --git a/packages/extension-core/src/domains/accounts/helpers.onChainIds.ts b/packages/extension-core/src/domains/accounts/helpers.onChainIds.ts index 3733c5a4d5..fc0d8e17e3 100644 --- a/packages/extension-core/src/domains/accounts/helpers.onChainIds.ts +++ b/packages/extension-core/src/domains/accounts/helpers.onChainIds.ts @@ -3,7 +3,6 @@ import { OnChainId, OnChainIds, ResolvedNames } from "@talismn/on-chain-id" import { chainConnectors } from "../../rpcs/balance-modules" import { getTypeRegistry } from "../../util/getTypeRegistry" -const chainIdPolkadot = "polkadot" const chainIdAlephZero = "aleph-zero" const aznsSupportedChainIdAlephZero = "alephzero" @@ -14,17 +13,12 @@ export const lookupAddresses = async (addresses: string[]): Promise (await getOnChainId()).lookupAddresses(addresses) const getOnChainId = async () => { - const [{ registry: registryPolkadot }, { registry: registryAlephZero }] = await Promise.all([ - getTypeRegistry(chainIdPolkadot), - getTypeRegistry(chainIdAlephZero), - ]) + const { registry: registryAlephZero } = await getTypeRegistry(chainIdAlephZero) return new OnChainId({ - registryPolkadot, registryAlephZero, chainConnectors, - chainIdPolkadot, chainIdAlephZero, aznsSupportedChainIdAlephZero, }) diff --git a/packages/on-chain-id/src/index.ts b/packages/on-chain-id/src/index.ts index 2d378b098a..35a29c9f03 100644 --- a/packages/on-chain-id/src/index.ts +++ b/packages/on-chain-id/src/index.ts @@ -1,9 +1,4 @@ -import { - lookupAddresses, - lookupAznsAddresses, - lookupEnsAddresses, - lookupPolkadotAddresses, -} from "./util/addressesToNames" +import { lookupAddresses, lookupAznsAddresses, lookupEnsAddresses } from "./util/addressesToNames" import { resolveAznsNames, resolveEnsNames, resolveNames } from "./util/namesToAddresses" import { Config, DropFirst, OptionalConfig } from "./util/types" @@ -22,7 +17,6 @@ export class OnChainId { constructor(config: OptionalConfig) { this.#config = { ...config, - chainIdPolkadot: config.chainIdPolkadot ?? "polkadot", chainIdAlephZero: config.chainIdAlephZero ?? "aleph-zero", aznsSupportedChainIdAlephZero: config.aznsSupportedChainIdAlephZero ?? "alephzero", networkIdEthereum: config.networkIdEthereum ?? "1", @@ -38,8 +32,6 @@ export class OnChainId { lookupAddresses = (...args: DropFirst>) => lookupAddresses(this.#config, ...args) - lookupPolkadotAddresses = (...args: DropFirst>) => - lookupPolkadotAddresses(this.#config, ...args) lookupAznsAddresses = (...args: DropFirst>) => lookupAznsAddresses(this.#config, ...args) lookupEnsAddresses = (...args: DropFirst>) => diff --git a/packages/on-chain-id/src/util/addressesToNames.ts b/packages/on-chain-id/src/util/addressesToNames.ts index 3d24cd6e15..76a5b59439 100644 --- a/packages/on-chain-id/src/util/addressesToNames.ts +++ b/packages/on-chain-id/src/util/addressesToNames.ts @@ -1,33 +1,22 @@ import { resolveAddressToDomain } from "@azns/resolver-core" import { ApiPromise } from "@polkadot/api" -import { RpcStateQuery, RpcStateQueryHelper, StorageHelper } from "@talismn/balances" -import { decodeAnyAddress, isEthereumAddress } from "@talismn/util" +import { isEthereumAddress } from "@talismn/util" import log from "../log" import { Config, OnChainIds } from "./types" /** * Looks up the on-chain identifiers for some addresses. - * - * Prefers ENS, then AZNS, then falls back to Polkadot identities. - * - * Requires a TypeRegistry which has been instantiated on the Polkadot relay chain. - * Talisman Wallet developers can build one by using `/apps/extension/src/core/util/getTypeRegistry.ts`. + * Supports ENS and AZNS. */ export const lookupAddresses = async (config: Config, addresses: string[]): Promise => { const onChainIds: OnChainIds = new Map(addresses.map((address) => [address, null])) - const [/* polkadotIdentities, */ aznsDomains, ensDomains] = await Promise.all([ - // lookupPolkadotAddresses(config, addresses), + const [aznsDomains, ensDomains] = await Promise.all([ lookupAznsAddresses(config, addresses), lookupEnsAddresses(config, addresses), ]) - // polkadotIdentities.forEach((polkadotIdentity, address) => { - // if (!polkadotIdentity) return - // onChainIds.set(address, polkadotIdentity) - // }) - aznsDomains.forEach((domain, address) => { if (!domain) return onChainIds.set(address, domain) @@ -41,80 +30,6 @@ export const lookupAddresses = async (config: Config, addresses: string[]): Prom return onChainIds } -/** - * Looks up the on-chain Polkadot identities for some addresses. - * - * Requires a TypeRegistry which has been instantiated on the Polkadot relay chain. - * Talisman Wallet developers can build one by using `/apps/extension/src/core/util/getTypeRegistry.ts`. - */ -export const lookupPolkadotAddresses = async ( - config: Config, - addresses: string[] -): Promise => { - const onChainIds: OnChainIds = new Map(addresses.map((address) => [address, null])) - - if (!config.chainConnectors.substrate) { - log.warn(`Could not find Substrate chainConnector in OnChainId::lookupPolkadotAddresses`) - return onChainIds - } - - const queries = addresses.flatMap((address): RpcStateQuery<[string, string | null]> | [] => { - const storageHelper = new StorageHelper( - config.registryPolkadot, - "identity", - "identityOf", - decodeAnyAddress(address) - ) - - // filter out queries which we failed to encode (e.g. an invalid address was input) - const stateKey = storageHelper.stateKey - if (!stateKey) return [] - - const decodeResult = (change: string | null): [string, string | null] => { - // eslint-disable-next-line @typescript-eslint/no-explicit-any - const decoded: any = storageHelper.decode(change) - - // explicit null is required here to ensure the frontend knows that the address has been queried - const bytes = decoded?.value?.info?.display?.value - const bytesDecoded = new TextDecoder().decode(bytes) - - const judgements: string[] = - // eslint-disable-next-line @typescript-eslint/no-explicit-any - decoded?.value?.judgements?.flatMap?.((judgement: any) => { - if (judgement?.[1]?.isErroneous) return "Erroneous" - if (judgement?.[1]?.isFeePaid) return "FeePaid" - if (judgement?.[1]?.isKnownGood) return "KnownGood" - if (judgement?.[1]?.isLowQuality) return "LowQuality" - if (judgement?.[1]?.isOutOfDate) return "OutOfDate" - if (judgement?.[1]?.isReasonable) return "Reasonable" - if (judgement?.[1]?.isUnknown) return "Unknown" - - log.warn(`Unknown judgement type ${judgement?.toJSON?.() ?? String(judgement)}`) - return [] - }) ?? [] - if (judgements.length < 1) judgements.push("NoJudgement") - - const display = bytes ? `${bytesDecoded} (${judgements.join(", ")})` : null - - return [address, display] - } - - return { chainId: config.chainIdPolkadot, stateKey, decodeResult } - }) - - const identities = await new RpcStateQueryHelper( - config.chainConnectors.substrate, - queries - ).fetch() - - identities.forEach(([address, polkadotIdentity]) => { - if (!polkadotIdentity) return - onChainIds.set(address, polkadotIdentity) - }) - - return onChainIds -} - /** * Looks up the on-chain AZNS domains for some addresses. */ diff --git a/packages/on-chain-id/src/util/types.ts b/packages/on-chain-id/src/util/types.ts index 9f7a54d30b..9ba0916f73 100644 --- a/packages/on-chain-id/src/util/types.ts +++ b/packages/on-chain-id/src/util/types.ts @@ -17,12 +17,9 @@ export type NsLookupType = "ens" | "azns" export type Config = { // TODO: Create a package for `/apps/extension/src/core/util/getTypeRegistry.ts` which // can be used from outside of the wallet. - registryPolkadot: TypeRegistry registryAlephZero: TypeRegistry chainConnectors: ChainConnectors - /** Used for polkadot identity lookups */ - chainIdPolkadot: string /** Used for azns lookups */ chainIdAlephZero: string /** Used for azns lookups */ @@ -32,7 +29,6 @@ export type Config = { } export type OptionalConfigParams = - | "chainIdPolkadot" | "chainIdAlephZero" | "aznsSupportedChainIdAlephZero" | "networkIdEthereum"