From a8220ec12f2dc5cdd26f58984af64fe208fe2e7d Mon Sep 17 00:00:00 2001 From: bluezdot <72647326+bluezdot@users.noreply.github.com> Date: Sat, 20 Jul 2024 10:46:39 +0700 Subject: [PATCH] remove merkleize metadata --- .../src/services/chain-service/index.ts | 80 +++++++++---------- packages/extension-base/src/utils/metadata.ts | 26 +++--- 2 files changed, 53 insertions(+), 53 deletions(-) diff --git a/packages/extension-base/src/services/chain-service/index.ts b/packages/extension-base/src/services/chain-service/index.ts index 054eb4b4c3..dfecdb0554 100644 --- a/packages/extension-base/src/services/chain-service/index.ts +++ b/packages/extension-base/src/services/chain-service/index.ts @@ -21,7 +21,7 @@ import Web3 from 'web3'; import { logger as createLogger } from '@polkadot/util/logger'; import { HexString, Logger } from '@polkadot/util/types'; -import { ExtraInfo } from '@polkadot-api/merkleize-metadata'; +// import { ExtraInfo } from '@polkadot-api/merkleize-metadata'; const filterChainInfoMap = (data: Record, ignoredChains: string[]): Record => { return Object.fromEntries( @@ -2017,45 +2017,45 @@ export class ChainService { return this.dbService.stores.metadata.getMetadataByGenesisHash(hash); } - getExtraInfo (chain: string): Omit { - const chainInfo = this.getChainInfoByKey(chain); - - return { - decimals: chainInfo.substrateInfo?.decimals ?? 0, - tokenSymbol: chainInfo.substrateInfo?.symbol ?? 'Unit', - base58Prefix: chainInfo.substrateInfo?.addressPrefix ?? 42 - }; - } - - async calculateMetadataHash (chain: string): Promise { - const metadata = await this.getMetadata(chain); - - if (!metadata || !metadata.hexV15) { - return undefined; - } - - const extraInfo = this.getExtraInfo(chain); - const specVersion = parseInt(metadata.specVersion); - const specName = metadata.specName; - const hexV15 = metadata.hexV15; - - return calculateMetadataHash({ ...extraInfo, specVersion, specName }, hexV15); - } - - async shortenMetadata (chain: string, txBlob: string): Promise { - const metadata = await this.getMetadata(chain); - - if (!metadata || !metadata.hexV15) { - return undefined; - } - - const extraInfo = this.getExtraInfo(chain); - const specVersion = parseInt(metadata.specVersion); - const specName = metadata.specName; - const hexV15 = metadata.hexV15; - - return getShortMetadata(txBlob as HexString, { ...extraInfo, specVersion, specName }, hexV15); - } + // getExtraInfo (chain: string): Omit { + // const chainInfo = this.getChainInfoByKey(chain); + // + // return { + // decimals: chainInfo.substrateInfo?.decimals ?? 0, + // tokenSymbol: chainInfo.substrateInfo?.symbol ?? 'Unit', + // base58Prefix: chainInfo.substrateInfo?.addressPrefix ?? 42 + // }; + // } + + // async calculateMetadataHash (chain: string): Promise { + // const metadata = await this.getMetadata(chain); + // + // if (!metadata || !metadata.hexV15) { + // return undefined; + // } + // + // const extraInfo = this.getExtraInfo(chain); + // const specVersion = parseInt(metadata.specVersion); + // const specName = metadata.specName; + // const hexV15 = metadata.hexV15; + // + // return calculateMetadataHash({ ...extraInfo, specVersion, specName }, hexV15); + // } + + // async shortenMetadata (chain: string, txBlob: string): Promise { + // const metadata = await this.getMetadata(chain); + // + // if (!metadata || !metadata.hexV15) { + // return undefined; + // } + // + // const extraInfo = this.getExtraInfo(chain); + // const specVersion = parseInt(metadata.specVersion); + // const specName = metadata.specName; + // const hexV15 = metadata.hexV15; + // + // return getShortMetadata(txBlob as HexString, { ...extraInfo, specVersion, specName }, hexV15); + // } /* Metadata */ diff --git a/packages/extension-base/src/utils/metadata.ts b/packages/extension-base/src/utils/metadata.ts index 41c6c47c2d..1ce8ac0a3a 100644 --- a/packages/extension-base/src/utils/metadata.ts +++ b/packages/extension-base/src/utils/metadata.ts @@ -5,25 +5,25 @@ import { ChainService } from '@subwallet/extension-base/services/chain-service'; import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types'; import { getSpecExtensions, getSpecTypes } from '@polkadot/types-known'; -import { u8aToHex } from '@polkadot/util'; +// import { u8aToHex } from '@polkadot/util'; import { HexString } from '@polkadot/util/types'; -import { ExtraInfo, merkleizeMetadata } from '@polkadot-api/merkleize-metadata'; +// import { ExtraInfo, merkleizeMetadata } from '@polkadot-api/merkleize-metadata'; export const _isRuntimeUpdated = (signedExtensions?: string[]): boolean => { return signedExtensions ? signedExtensions.includes('CheckMetadataHash') : false; }; -export const calculateMetadataHash = (extraInfo: ExtraInfo, metadataV15: HexString): string => { - const _merkleizeMetadata = merkleizeMetadata(metadataV15, extraInfo); - - return u8aToHex(_merkleizeMetadata.digest()); -}; - -export const getShortMetadata = (blob: HexString, extraInfo: ExtraInfo, metadata: HexString): string => { - const _merkleizeMetadata = merkleizeMetadata(metadata, extraInfo); - - return u8aToHex(_merkleizeMetadata.getProofForExtrinsicPayload(blob)); -}; +// export const calculateMetadataHash = (extraInfo: ExtraInfo, metadataV15: HexString): string => { +// const _merkleizeMetadata = merkleizeMetadata(metadataV15, extraInfo); +// +// return u8aToHex(_merkleizeMetadata.digest()); +// }; +// +// export const getShortMetadata = (blob: HexString, extraInfo: ExtraInfo, metadata: HexString): string => { +// const _merkleizeMetadata = merkleizeMetadata(metadata, extraInfo); +// +// return u8aToHex(_merkleizeMetadata.getProofForExtrinsicPayload(blob)); +// }; export const cacheMetadata = ( chain: string,