Allow index calc as fallback (#391)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -11,6 +11,6 @@
|
||||
"license": "ISC",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.1.2",
|
||||
"@polkadot/util": "^0.32.12"
|
||||
"@polkadot/util": "^0.32.13"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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({
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user