diff --git a/packages/api-observable/src/Base.ts b/packages/api-observable/src/Base.ts index 70b0ca7972..7d20f96473 100644 --- a/packages/api-observable/src/Base.ts +++ b/packages/api-observable/src/Base.ts @@ -53,7 +53,7 @@ export default class ApiBase { } try { - // FIXME This now gets done in api-core/rpc-core as well, cleanup as soon as we + // FIXME This now gets done in api/Base as well, cleanup as soon as we // have apis based on api-rx & api-promise (For now a bit of inefficiency) const meta = await this._api.state.getMetadata().toPromise(); @@ -70,7 +70,7 @@ export default class ApiBase { resolveReady(true); } } catch (error) { - // swallow + console.error(error); } }); }); diff --git a/packages/rpc-core/package.json b/packages/rpc-core/package.json index 855d91bbe8..55e34e6aa6 100644 --- a/packages/rpc-core/package.json +++ b/packages/rpc-core/package.json @@ -32,6 +32,6 @@ "@babel/runtime": "^7.1.2", "@polkadot/jsonrpc": "^0.31.108", "@polkadot/rpc-provider": "^0.31.108", - "@polkadot/util": "^0.32.12" + "@polkadot/util": "^0.32.13" } } diff --git a/packages/rpc-provider/package.json b/packages/rpc-provider/package.json index 4d487ee91d..f64eb7b899 100644 --- a/packages/rpc-provider/package.json +++ b/packages/rpc-provider/package.json @@ -30,10 +30,10 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme", "dependencies": { "@babel/runtime": "^7.1.2", - "@polkadot/keyring": "^0.32.12", + "@polkadot/keyring": "^0.32.13", "@polkadot/storage": "^0.31.108", - "@polkadot/util": "^0.32.12", - "@polkadot/util-crypto": "^0.32.12", + "@polkadot/util": "^0.32.13", + "@polkadot/util-crypto": "^0.32.13", "@types/nock": "^9.3.0", "eventemitter3": "^3.1.0", "isomorphic-fetch": "^2.2.1", diff --git a/packages/type-extrinsics/package.json b/packages/type-extrinsics/package.json index b957bf328e..e876c63d50 100644 --- a/packages/type-extrinsics/package.json +++ b/packages/type-extrinsics/package.json @@ -11,6 +11,6 @@ "license": "ISC", "dependencies": { "@babel/runtime": "^7.1.2", - "@polkadot/util": "^0.32.12" + "@polkadot/util": "^0.32.13" } } diff --git a/packages/type-extrinsics/src/fromMetadata.ts b/packages/type-extrinsics/src/fromMetadata.ts index 51bd14fceb..d7aee7477d 100644 --- a/packages/type-extrinsics/src/fromMetadata.ts +++ b/packages/type-extrinsics/src/fromMetadata.ts @@ -18,13 +18,20 @@ import extrinsics from './index'; * @param metadata - The metadata to extend the storage object against. */ export default function fromMetadata (metadata: Metadata): Extrinsics { + let indexCount = -1; + const findIndex = (prefix: string): number => { + indexCount++; + const mod = metadata.calls.find((item) => item.prefix.toString() === prefix ); if (!mod) { - throw new Error(`Unable to find module index for '${prefix}'`); + console.error(`Unable to find module index for '${prefix}'`); + + // compatible with old versions + return indexCount; } return mod.index.toNumber(); diff --git a/packages/type-extrinsics/src/utils/createUnchecked.ts b/packages/type-extrinsics/src/utils/createUnchecked.ts index f5ec51fba2..9bd932b4fd 100644 --- a/packages/type-extrinsics/src/utils/createUnchecked.ts +++ b/packages/type-extrinsics/src/utils/createUnchecked.ts @@ -6,6 +6,7 @@ import { ExtrinsicFunction } from '../types'; import { FunctionMetadata } from '@polkadot/types/Metadata'; import { Extrinsic, Method } from '@polkadot/types/index'; +import { assert } from '@polkadot/util'; /** * From the metadata of a function in the module's storage, generate the function @@ -25,9 +26,7 @@ export default function createDescriptor ( const expectedArgs = Method.filterOrigin(meta); extrinsicFn = (...args: any[]): Extrinsic => { - if (expectedArgs.length.valueOf() !== args.length) { - throw new Error(`Extrinsic ${section}.${method} expects ${expectedArgs.length.valueOf()} arguments, got ${args.length}.`); - } + assert(expectedArgs.length.valueOf() === args.length, `Extrinsic ${section}.${method} expects ${expectedArgs.length.valueOf()} arguments, got ${args.length}.`); return new Extrinsic({ method: new Method({ diff --git a/packages/type-storage/package.json b/packages/type-storage/package.json index af4ae6842c..6e8961d49f 100644 --- a/packages/type-storage/package.json +++ b/packages/type-storage/package.json @@ -30,9 +30,9 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-storage#readme", "dependencies": { "@babel/runtime": "^7.1.2", - "@polkadot/keyring": "^0.32.12", + "@polkadot/keyring": "^0.32.13", "@polkadot/types": "^0.31.108", - "@polkadot/util": "^0.32.12", - "@polkadot/util-crypto": "^0.32.12" + "@polkadot/util": "^0.32.13", + "@polkadot/util-crypto": "^0.32.13" } } diff --git a/packages/type-storage/src/fromMetadata.ts b/packages/type-storage/src/fromMetadata.ts index 05519a82d9..06f0b6bc0d 100644 --- a/packages/type-storage/src/fromMetadata.ts +++ b/packages/type-storage/src/fromMetadata.ts @@ -31,8 +31,8 @@ export default function fromMetadata (metadata: Metadata): Storage { const prefix = moduleMetadata.storage.prefix; + // For access, we change the index names, i.e. Balances.FreeBalance -> balances.freeBalance result[stringLowerFirst(prefix.toString())] = moduleMetadata.storage.functions.reduce((newModule, func) => { - // Lowercase the 'f' in storage.balances.freeBalance newModule[stringLowerFirst(func.name.toString())] = createFunction(prefix, func.name, func); return newModule; diff --git a/packages/type-storage/src/utils/createFunction.ts b/packages/type-storage/src/utils/createFunction.ts index c5b00dcc37..13017dcf7a 100644 --- a/packages/type-storage/src/utils/createFunction.ts +++ b/packages/type-storage/src/utils/createFunction.ts @@ -7,7 +7,7 @@ import { createType } from '@polkadot/types/codec'; import { StorageFunctionMetadata } from '@polkadot/types/Metadata'; import { StorageFunction } from '@polkadot/types/StorageKey'; import { Text } from '@polkadot/types/index'; -import { isNull, isUndefined, stringLowerFirst, stringToU8a, u8aConcat } from '@polkadot/util'; +import { assert, isNull, isUndefined, stringLowerFirst, stringToU8a, u8aConcat } from '@polkadot/util'; import { xxhashAsU8a } from '@polkadot/util-crypto'; export interface CreateItemOptions { @@ -54,9 +54,7 @@ export default function createFunction ( ); } - if (isUndefined(arg) || isNull(arg)) { - throw new Error(`${meta.name} expects one argument`); - } + assert(!isUndefined(arg) && !isNull(arg), `${meta.name} expects one argument`); const type = meta.type.asMap.key.toString(); // Argument type, as string diff --git a/packages/types/package.json b/packages/types/package.json index 101c0ca5c0..f322295a29 100644 --- a/packages/types/package.json +++ b/packages/types/package.json @@ -30,7 +30,7 @@ "homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme", "dependencies": { "@babel/runtime": "^7.1.2", - "@polkadot/keyring": "^0.32.12", - "@polkadot/util": "^0.32.12" + "@polkadot/keyring": "^0.32.13", + "@polkadot/util": "^0.32.13" } } diff --git a/yarn.lock b/yarn.lock index 139665eeb6..c5e3109f8e 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1313,14 +1313,14 @@ typedoc-plugin-markdown "^1.1.17" typescript "^3.1.3" -"@polkadot/keyring@^0.32.12": - version "0.32.12" - resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.32.12.tgz#b801bb88bc059d0d76cb6412440a451b070b2db8" - integrity sha512-YMHmXC8t943Kh/HQmsCcYkjpz3Hs2f4xPCIcKo1H1HZyUOMjNMiIIl0yReVlit1QHIL1M7ggWlX+B5k3g5Vdkg== +"@polkadot/keyring@^0.32.13": + version "0.32.13" + resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-0.32.13.tgz#a1da9139c0428ee53286376286422d573ecd693c" + integrity sha512-sa86Tu5r+7o4XDZRpsG2Cv3AM0FhQ4cdI74HHIMICHakru8bxdFUWTQEQG8eDhoHDge174wTVT72UGOo/GgZcA== dependencies: "@babel/runtime" "^7.1.2" - "@polkadot/util" "^0.32.12" - "@polkadot/util-crypto" "^0.32.12" + "@polkadot/util" "^0.32.13" + "@polkadot/util-crypto" "^0.32.13" "@types/bs58" "^3.0.30" bs58 "^4.0.1" @@ -1331,13 +1331,13 @@ dependencies: "@types/node" "^10.12.0" -"@polkadot/util-crypto@^0.32.12": - version "0.32.12" - resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.32.12.tgz#f44221d88e12aeddec0c80453240519bf7126fac" - integrity sha512-mwKI8TNEKuSBGIyC4LnQtLIcuacPaoGjmqlKe7FcugD0J0vJRZ+YJnYJCHr76ndIJhik0j4YmU5tLrwatY+J4Q== +"@polkadot/util-crypto@^0.32.13": + version "0.32.13" + resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-0.32.13.tgz#e4231a9889e3e07dc301ad7924c8db3ca639fce0" + integrity sha512-AvLcC7drJ8O8VK7t30TaBnWrkcdXlbbGXMZ15YPDbXSEVYW2CqorDzJejBwYKsEzlnRjpNGp3q9ImjpYjtthlA== dependencies: "@babel/runtime" "^7.1.2" - "@polkadot/util" "^0.32.12" + "@polkadot/util" "^0.32.13" "@types/bip39" "^2.4.0" bip39 "^2.5.0" blakejs "^1.1.0" @@ -1345,10 +1345,10 @@ tweetnacl "^1.0.0" xxhashjs "^0.2.2" -"@polkadot/util@^0.32.12": - version "0.32.12" - resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.32.12.tgz#60e7e2c88dce0febb7ba431460931ed73e36f3ed" - integrity sha512-KEnocbZgtHtxB9n7OW6WrgfLL6RNvVc5LhAnbAzgPosS6paSJakTlDVfyige0rjySQxBMmxp98i2RaR4VVaryw== +"@polkadot/util@^0.32.13": + version "0.32.13" + resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-0.32.13.tgz#5fbd805917f5e5b874f80bdee75f44a7046bacd1" + integrity sha512-5cmwlEgXu5erHPXnsCEKb4En95g4QajVFpTtGDlwiwga105XwhoZJCDqKYS1jtCu28MpE9GDbQ0PjZf4ibxT8w== dependencies: "@babel/runtime" "^7.1.2" "@types/bn.js" "^4.11.2"