Allow index calc as fallback (#391)

This commit is contained in:
Jaco Greeff
2018-11-10 11:56:43 +01:00
committed by GitHub
parent 614416e1bc
commit d5bca161b5
11 changed files with 40 additions and 36 deletions
+2 -2
View File
@@ -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);
}
});
});
+1 -1
View File
@@ -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"
}
}
+3 -3
View File
@@ -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",
+1 -1
View File
@@ -11,6 +11,6 @@
"license": "ISC",
"dependencies": {
"@babel/runtime": "^7.1.2",
"@polkadot/util": "^0.32.12"
"@polkadot/util": "^0.32.13"
}
}
+8 -1
View File
@@ -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();
@@ -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({
+3 -3
View File
@@ -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"
}
}
+1 -1
View File
@@ -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;
@@ -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
+2 -2
View File
@@ -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"
}
}
+15 -15
View File
@@ -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"