Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove merkleize metadata #3412

Open
wants to merge 2 commits into
base: subwallet-dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions packages/extension-base/src/services/chain-service/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, _ChainInfo>, ignoredChains: string[]): Record<string, _ChainInfo> => {
return Object.fromEntries(
Expand Down Expand Up @@ -2017,45 +2017,45 @@ export class ChainService {
return this.dbService.stores.metadata.getMetadataByGenesisHash(hash);
}

getExtraInfo (chain: string): Omit<ExtraInfo, 'specVersion' | 'specName'> {
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<string | undefined> {
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<string | undefined> {
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<ExtraInfo, 'specVersion' | 'specName'> {
// 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<string | undefined> {
// 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<string | undefined> {
// 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 */

Expand Down
26 changes: 13 additions & 13 deletions packages/extension-base/src/utils/metadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading