Unverified Commit fae7a7eb authored by Hanwen Cheng's avatar Hanwen Cheng Committed by GitHub
Browse files

fix: sync extend types with polkadot.js/api (#586)

* fix: sync with polkadot known types

* use big number here

* make lint happy

* remove ts supress

* rephrase
parent 82adf6d5
Pipeline #86244 failed with stages
in 4 minutes and 12 seconds
......@@ -15,26 +15,63 @@
// along with Parity. If not, see <http://www.gnu.org/licenses/>.
import { Metadata, TypeRegistry } from '@polkadot/types';
import { TYPES_SPEC } from '@polkadot/types/known/overrides';
import { RegistryTypes } from '@polkadot/types/types';
import { getSpecTypes } from '@polkadot/types-known';
import { Container } from 'unstated';
import { SUBSTRATE_NETWORK_LIST } from 'constants/networkSpecs';
import { getMetadata } from 'utils/identitiesUtils';
//Map PathId to Polkadot.js/api spec names and chain names
type NetworkTypes = {
alias?: string;
chains: {
[key: string]: string;
};
};
type NetworkTypesMap = {
[key: string]: NetworkTypes;
};
const networkTypesMap: NetworkTypesMap = {
centrifuge: {
alias: 'centrifuge-chain',
chains: {}
},
kusama: { chains: {} },
polkadot: {
chains: {
westend: 'Westend'
}
}
};
export const getOverrideTypes = (
registry: TypeRegistry,
pathId: string
): any => {
let specName = '',
chainName = '';
Object.entries(networkTypesMap).find(
([networkName, networkTypes]: [string, NetworkTypes]) => {
if (networkName === pathId) {
specName = networkTypes.alias ?? networkName;
} else if (networkTypes.chains.hasOwnProperty(pathId)) {
const chainAlias = networkTypes.chains[pathId];
specName = networkTypes.alias ?? networkName;
chainName = chainAlias ?? pathId;
} else {
return false;
}
return true;
}
);
return getSpecTypes(registry, chainName, specName, Number.MAX_SAFE_INTEGER);
};
type RegistriesStoreState = {
registries: Map<string, TypeRegistry>;
dumbRegistry: TypeRegistry;
};
function getLatestVersionOverrideTypes(
networkPathId: string
): undefined | RegistryTypes {
if (!TYPES_SPEC.hasOwnProperty(networkPathId)) return undefined;
const latestVersionNumber = TYPES_SPEC[networkPathId].length - 1;
return TYPES_SPEC[networkPathId][latestVersionNumber].types;
}
export default class RegistriesStore extends Container<RegistriesStoreState> {
state: RegistriesStoreState = {
dumbRegistry: new TypeRegistry(),
......@@ -50,10 +87,7 @@ export default class RegistriesStore extends Container<RegistriesStoreState> {
const networkParams = SUBSTRATE_NETWORK_LIST[networkKey];
const newRegistry = new TypeRegistry();
const networkMetadataRaw = getMetadata(networkKey);
const override = getLatestVersionOverrideTypes(networkParams.pathId);
if (override !== undefined) {
newRegistry.register(override);
}
newRegistry.register(getOverrideTypes(newRegistry, networkParams.pathId));
const metadata = new Metadata(newRegistry, networkMetadataRaw);
newRegistry.setMetadata(metadata);
registries.set(networkKey, newRegistry);
......
......@@ -30,6 +30,7 @@ import {
SUBSTRATE_NETWORK_LIST,
SubstrateNetworkKeys
} from 'constants/networkSpecs';
import { getOverrideTypes } from 'stores/RegistriesStore';
import { SubstrateCompletedParsedData } from 'types/scannerTypes';
import {
constructDataFromBytes,
......@@ -120,6 +121,14 @@ describe.skip('sanity check', () => {
});
});
describe('type registry should get override types', () => {
it('get network latest override types', () => {
const testRegistry = new TypeRegistry();
const kusamaOverrideTypes = getOverrideTypes(testRegistry, 'westend');
expect(kusamaOverrideTypes).not.toEqual({});
});
});
describe('decoders', () => {
describe('strings', () => {
it('check if string is ascii', () => {
......
......@@ -1239,126 +1239,138 @@
"@types/yargs" "^15.0.0"
chalk "^3.0.0"
"@polkadot/api-derive@1.9.0-beta.8":
version "1.9.0-beta.8"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-1.9.0-beta.8.tgz#e9604ddbf0a69ebd4443a78347339ef528c99d4f"
integrity sha512-pRorOuWWLwen1dNeMbpTiyU65awM5LOWW/x2/ZprvQsOzdgeIPylc2flmnZD+SIC/jdcYW9+QsvbgDlV5MXJkQ==
"@polkadot/api-derive@1.10.0-beta.3":
version "1.10.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/api-derive/-/api-derive-1.10.0-beta.3.tgz#da2d26760f50ef702422ed40916800993e0e3c6e"
integrity sha512-fM7iJak8diBzo/tP79LsTmA2rj7JAzQ0BC3heXlCLBL+IHG/32Skb6GQJvCZSKzjNh72BusF1bU6d2jbRD4hnw==
dependencies:
"@babel/runtime" "^7.9.2"
"@polkadot/api" "1.9.0-beta.8"
"@polkadot/rpc-core" "1.9.0-beta.8"
"@polkadot/rpc-provider" "1.9.0-beta.8"
"@polkadot/types" "1.9.0-beta.8"
"@polkadot/util" "^2.7.0-beta.8"
"@polkadot/util-crypto" "^2.7.0-beta.8"
"@polkadot/api" "1.10.0-beta.3"
"@polkadot/rpc-core" "1.10.0-beta.3"
"@polkadot/rpc-provider" "1.10.0-beta.3"
"@polkadot/types" "1.10.0-beta.3"
"@polkadot/util" "^2.7.1"
"@polkadot/util-crypto" "^2.7.1"
bn.js "^5.1.1"
memoizee "^0.4.14"
rxjs "^6.5.4"
"@polkadot/api@1.9.0-beta.8":
version "1.9.0-beta.8"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-1.9.0-beta.8.tgz#8f3ec07a04e479e04c837eaa56281b2a26718255"
integrity sha512-H6w6FaauXwizOS5s3GkyeKVumXQOoMzE8Wev+0R1UpqDF8OGIwQr96vTQ3PEght2q51Rnsiw5bc8hkeXWtuaog==
"@polkadot/api@1.10.0-beta.3":
version "1.10.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/api/-/api-1.10.0-beta.3.tgz#e32959b90ddb4ccee348b6643511d52806e4055b"
integrity sha512-tUWhoL52bykB2Jz5SCNvA32NrGF1+bsKPuIIG7ZnzK15NLwGlr9VQVJIMqH6kssYIkdR6V/8EpoXSKw3wRUxfw==
dependencies:
"@babel/runtime" "^7.9.2"
"@polkadot/api-derive" "1.9.0-beta.8"
"@polkadot/keyring" "^2.7.0-beta.8"
"@polkadot/metadata" "1.9.0-beta.8"
"@polkadot/rpc-core" "1.9.0-beta.8"
"@polkadot/rpc-provider" "1.9.0-beta.8"
"@polkadot/types" "1.9.0-beta.8"
"@polkadot/util" "^2.7.0-beta.8"
"@polkadot/util-crypto" "^2.7.0-beta.8"
"@polkadot/api-derive" "1.10.0-beta.3"
"@polkadot/keyring" "^2.7.1"
"@polkadot/metadata" "1.10.0-beta.3"
"@polkadot/rpc-core" "1.10.0-beta.3"
"@polkadot/rpc-provider" "1.10.0-beta.3"
"@polkadot/types" "1.10.0-beta.3"
"@polkadot/types-known" "1.10.0-beta.3"
"@polkadot/util" "^2.7.1"
"@polkadot/util-crypto" "^2.7.1"
bn.js "^5.1.1"
eventemitter3 "^4.0.0"
rxjs "^6.5.4"
"@polkadot/keyring@^2.7.0-beta.8":
version "2.7.0-beta.8"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-2.7.0-beta.8.tgz#bdb803c714a9292d03d4d24838ece356f32b6f32"
integrity sha512-3DEw0wTCkNf9JASR3h5I9xiipWrhHMPioL80EspqJQ6XiXnMAckvULntLXCnVrOIMIpXdzHNkyxmz/QYf1l7kg==
"@polkadot/keyring@^2.7.1":
version "2.7.1"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-2.7.1.tgz#714d564b80305a343d83ff07baae59173af5f463"
integrity sha512-aQkc6TT0kaLwEa7rxit/M6/uWJ03wWY1owZychW9slfXH/tmWMCSM0m6z78MIAzdnSTVY7ztpjDfxrPOCHlLYA==
dependencies:
"@babel/runtime" "^7.9.2"
"@polkadot/util" "2.7.0-beta.8"
"@polkadot/util-crypto" "2.7.0-beta.8"
"@polkadot/util" "2.7.1"
"@polkadot/util-crypto" "2.7.1"
"@polkadot/metadata@1.9.0-beta.8":
version "1.9.0-beta.8"
resolved "https://registry.yarnpkg.com/@polkadot/metadata/-/metadata-1.9.0-beta.8.tgz#da9e1acb86352bbbdb4dc40f38485a05a57bb057"
integrity sha512-Ii78cRm23I4RkhK9PPOGdi9nCXT1aBjAs/m+1DVaPVyKfNEsOhnHh19Aj8Jj+VSuCkY+YVkgzb86wmhmJTtr9w==
"@polkadot/metadata@1.10.0-beta.3":
version "1.10.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/metadata/-/metadata-1.10.0-beta.3.tgz#66485751a6ead994327ebe69e2d79c192c81c3ed"
integrity sha512-EGbNiiBcQOpkfHLsXR1PSFMgcraYOoGH3o/p+A3HK/eyD8yMXfPu1VKJZ7UWyBrH/4p9ImK86TyHaq+ew5fc3w==
dependencies:
"@babel/runtime" "^7.9.2"
"@polkadot/types" "1.9.0-beta.8"
"@polkadot/util" "^2.7.0-beta.8"
"@polkadot/util-crypto" "^2.7.0-beta.8"
"@polkadot/types" "1.10.0-beta.3"
"@polkadot/types-known" "1.10.0-beta.3"
"@polkadot/util" "^2.7.1"
"@polkadot/util-crypto" "^2.7.1"
bn.js "^5.1.1"
"@polkadot/reactnative-identicon@0.52.0-beta.20":
version "0.52.0-beta.20"
resolved "https://registry.yarnpkg.com/@polkadot/reactnative-identicon/-/reactnative-identicon-0.52.0-beta.20.tgz#cf2e3f6e57a6854fb7e436ff77a6e373c8b50491"
integrity sha512-GPtzgu6s2X7c/t/TRApCFTqjzzY5cV8DMpQR0a+p170k/UuFFEqsj9f4QWjfalozsVzcg5yWCkeYhD4BLf8ioA==
"@polkadot/reactnative-identicon@0.52.0-beta.24":
version "0.52.0-beta.24"
resolved "https://registry.yarnpkg.com/@polkadot/reactnative-identicon/-/reactnative-identicon-0.52.0-beta.24.tgz#b3eef3fb565f508a5ffa54ed2bbc980873707f92"
integrity sha512-WzuT4vHRwZZhhPiE2zPJyZHRdzyIfAGf3hOfV4jIDGiuPuWhVcsFzwgea5Wgf9vdJZc6vcILCJ3Aw8K/9RXg8Q==
dependencies:
"@babel/runtime" "^7.9.2"
"@polkadot/ui-shared" "0.52.0-beta.20"
"@polkadot/ui-shared" "0.52.0-beta.24"
react-native-svg "^12.0.3"
"@polkadot/rpc-core@1.9.0-beta.8":
version "1.9.0-beta.8"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-1.9.0-beta.8.tgz#da110f3190212a632dd4d859f444d4c0d7e2dbad"
integrity sha512-/PvVqq45ybdu86NlOlJ+oQLFLxcERDzLrBigKTKhv3j252ujLCLHHT80CyLfTiYcno4G6D34CNY3fXEbcP7N3A==
"@polkadot/rpc-core@1.10.0-beta.3":
version "1.10.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-core/-/rpc-core-1.10.0-beta.3.tgz#831ce90e55f5ae744b3a92967178209d74ed6519"
integrity sha512-AOzZbZbM6E4r9wXm7izK3w8jk9bPTgHcCsdxxE5YNgwffZHXaSQrj5KuFh+UJW30fTFZmhYkp3wvquZlXOKXaA==
dependencies:
"@babel/runtime" "^7.9.2"
"@polkadot/metadata" "1.9.0-beta.8"
"@polkadot/rpc-provider" "1.9.0-beta.8"
"@polkadot/types" "1.9.0-beta.8"
"@polkadot/util" "^2.7.0-beta.8"
"@polkadot/metadata" "1.10.0-beta.3"
"@polkadot/rpc-provider" "1.10.0-beta.3"
"@polkadot/types" "1.10.0-beta.3"
"@polkadot/util" "^2.7.1"
memoizee "^0.4.14"
rxjs "^6.5.4"
"@polkadot/rpc-provider@1.9.0-beta.8":
version "1.9.0-beta.8"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-1.9.0-beta.8.tgz#d2cbec605c50b1a93a58354fa551941c63f32662"
integrity sha512-Nm/KyReZvHmDcRmKe0gpAjz/3CW9n4aJIgoGGq9IFRN4ov1/DIu7lcb5NBHK9dswvDhYKMhQ5JR+95+6gWoPIQ==
"@polkadot/rpc-provider@1.10.0-beta.3":
version "1.10.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/rpc-provider/-/rpc-provider-1.10.0-beta.3.tgz#a150bd3854b5f6680798d58fab429deacfb919af"
integrity sha512-/rA8BijPqN60Y0QcRrQDFJJTaWNZRUXOOSDlkTkLv0a/hoiIc2TFP7JbgO+6au+EsQuWQTKy9/U0BPxHAf3q3w==
dependencies:
"@babel/runtime" "^7.9.2"
"@polkadot/metadata" "1.9.0-beta.8"
"@polkadot/types" "1.9.0-beta.8"
"@polkadot/util" "^2.7.0-beta.8"
"@polkadot/util-crypto" "^2.7.0-beta.8"
"@polkadot/metadata" "1.10.0-beta.3"
"@polkadot/types" "1.10.0-beta.3"
"@polkadot/util" "^2.7.1"
"@polkadot/util-crypto" "^2.7.1"
bn.js "^5.1.1"
eventemitter3 "^4.0.0"
isomorphic-fetch "^2.2.1"
websocket "^1.0.31"
"@polkadot/types@1.9.0-beta.8":
version "1.9.0-beta.8"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-1.9.0-beta.8.tgz#94ac34b6270654812b2e208623a696e21f16b7e7"
integrity sha512-2AZXAxVPnDVK4JrlEedJ2PBpXgbNJDErJQJ4c9ezBmAvvQG0bw/OWGx+Jf+fMfnivlw75BkeOrgab64I44UOjw==
"@polkadot/types-known@1.10.0-beta.3":
version "1.10.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/types-known/-/types-known-1.10.0-beta.3.tgz#f82f81a3c056e19d8961ebb32d46dbd7694302a9"
integrity sha512-6iMx9LDTiOJKoIrH+d5JaOePWPt2l3PjpPJXx341ec/HF82okC8R4nTcfJ95iDaGVBxi+G7NyYFRl4rRLadlqQ==
dependencies:
"@babel/runtime" "^7.9.2"
"@polkadot/types" "1.10.0-beta.3"
"@polkadot/util" "^2.7.1"
bn.js "^5.1.1"
"@polkadot/types@1.10.0-beta.3":
version "1.10.0-beta.3"
resolved "https://registry.yarnpkg.com/@polkadot/types/-/types-1.10.0-beta.3.tgz#54c12350d332b8f974492ecbfea1f379ce75b4cc"
integrity sha512-LY4oQN4ydkdGdEyTIMgEA2aHviNp0JqKCoEHD3RinlfhXCVwUFYLNtJKJZqMrx1zDUeWFEkCpjiFhylZ5mcviA==
dependencies:
"@babel/runtime" "^7.9.2"
"@polkadot/metadata" "1.9.0-beta.8"
"@polkadot/util" "^2.7.0-beta.8"
"@polkadot/util-crypto" "^2.7.0-beta.8"
"@polkadot/metadata" "1.10.0-beta.3"
"@polkadot/util" "^2.7.1"
"@polkadot/util-crypto" "^2.7.1"
"@types/bn.js" "^4.11.6"
bn.js "^5.1.1"
memoizee "^0.4.14"
rxjs "^6.5.4"
"@polkadot/ui-shared@0.52.0-beta.20":
version "0.52.0-beta.20"
resolved "https://registry.yarnpkg.com/@polkadot/ui-shared/-/ui-shared-0.52.0-beta.20.tgz#aecaabe6619f95d5eda3daea7b90860e5478bcbb"
integrity sha512-9GsuMc/RyTL7ZLRRoDehF+TzwvMYOmdCZDPWjgAsvEVElORPdUGDL8m0So4FVyGBU4yxmeoHYudGaNnnlmB2eA==
"@polkadot/ui-shared@0.52.0-beta.24":
version "0.52.0-beta.24"
resolved "https://registry.yarnpkg.com/@polkadot/ui-shared/-/ui-shared-0.52.0-beta.24.tgz#c9bb16702799b47750341c61b8206d05982bf2a1"
integrity sha512-ioUrh1+txTenZUDjHRqIjo6VeVkp4RIVIZH+HlL3XAJ9zigcwBhGiiHXGV8cbkJQMvVmFj0wozgnH7/rkgFuIg==
dependencies:
"@babel/runtime" "^7.9.2"
color "^3.1.2"
"@polkadot/util-crypto@2.7.0-beta.8", "@polkadot/util-crypto@^2.7.0-beta.8":
version "2.7.0-beta.8"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-2.7.0-beta.8.tgz#2adb891cd755fbc1c9647b9fea86c3b7f1541530"
integrity sha512-315wO7N41BteRd3sIsbbH1Y9qNNYZiRl24Lh3TFgSiW5g4YuGjwRlHHjUoS+K+nn70UU3+4/0KXpX7CpxIa72A==
"@polkadot/util-crypto@2.7.1", "@polkadot/util-crypto@^2.7.1":
version "2.7.1"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-2.7.1.tgz#627ff9aa29379da7c5aa3727829ae8a0e80cd7d8"
integrity sha512-8Y+9Fv0g/AfyJLB1a9WyCClzYuf9IVLRGhAcb0I4mAL/KqfHoEzGCBGd1PjmcRboOBrtq6IYTOppwA0c6WOGww==
dependencies:
"@babel/runtime" "^7.9.2"
"@polkadot/util" "2.7.0-beta.8"
"@polkadot/util" "2.7.1"
"@polkadot/wasm-crypto" "^1.2.1"
base-x "^3.0.8"
bip39 "^3.0.2"
......@@ -1371,10 +1383,41 @@
tweetnacl "^1.0.3"
xxhashjs "^0.2.2"
"@polkadot/util@2.7.0-beta.8", "@polkadot/util@^2.7.0-beta.8":
version "2.7.0-beta.8"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-2.7.0-beta.8.tgz#8e3fa6c4dbc12a0cee5b9c4542c6e1cfc73ca3f1"
integrity sha512-gNudeHosA0ZbzOB4bLp7GQQs0XcVPBwEuSQsotbC+IgVIWhJZ0ZAhf/vwAXmHYJyzn8Nzvg17yjdW210b+H6bw==
"@polkadot/util-crypto@2.8.0-beta.2":
version "2.8.0-beta.2"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-2.8.0-beta.2.tgz#b35f1886fdc36ca0d21c76b465e0bb442505812c"
integrity sha512-UiQAmplITPr2RuRR0Od0Pa23yqcraYgpGkpQ7Sj7RCITUvi7ZWgRhQDnfqdcyJSY3o25BYuWsRMWEhzP5PSaRw==
dependencies:
"@babel/runtime" "^7.9.2"
"@polkadot/util" "2.8.0-beta.2"
"@polkadot/wasm-crypto" "^1.2.1"
base-x "^3.0.8"
bip39 "^3.0.2"
blakejs "^1.1.0"
bn.js "^5.1.1"
bs58 "^4.0.1"
elliptic "^6.5.2"
js-sha3 "^0.8.0"
pbkdf2 "^3.0.17"
tweetnacl "^1.0.3"
xxhashjs "^0.2.2"
"@polkadot/util@2.7.1", "@polkadot/util@^2.7.1":
version "2.7.1"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-2.7.1.tgz#adc5b9c8ea17179e4ea2061ddee84d21a0d50cc2"
integrity sha512-bvYnqhXV3N8m+i92uq2XrqRi4DEUYgdMhDeCIzf0t8ZQ0mcGhhROMuULhlpT+IlHwAlfewQ17HwB2qLtB6mGLw==
dependencies:
"@babel/runtime" "^7.9.2"
"@types/bn.js" "^4.11.6"
bn.js "^5.1.1"
camelcase "^5.3.1"
chalk "^3.0.0"
ip-regex "^4.1.0"
"@polkadot/util@2.8.0-beta.2":
version "2.8.0-beta.2"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-2.8.0-beta.2.tgz#d2cd5b360cb06bd03b73b91d61c260998f8e2fe5"
integrity sha512-y5FYSbk1rU5/G2l+u5AmxWquzm5chJaRn+1jUoPv0n4kuVIpu3fB2VzKUqtozM8JiScTkBEQWlOEs2v0QdUc3g==
dependencies:
"@babel/runtime" "^7.9.2"
"@types/bn.js" "^4.11.6"
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment