Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
19510c1ede | ||
|
|
97b5c699b1 | ||
|
|
d2befda86e | ||
|
|
740348b48f | ||
|
|
9e2a5cf532 | ||
|
|
6df466d9ea | ||
|
|
e2a2ac2842 | ||
|
|
5adc846e45 | ||
|
|
75aa310837 | ||
|
|
ce0523eb1c | ||
|
|
eb0370bb66 | ||
|
|
5eb491dc67 | ||
|
|
b50294ab0f | ||
|
|
e1cb62d2d2 | ||
|
|
8ed0ef2295 | ||
|
|
956e173323 | ||
|
|
b8a37ba438 | ||
|
|
e7669c2b00 | ||
|
|
6c309a503d | ||
|
|
3cf67c975a | ||
|
|
077914364c | ||
|
|
56e4cbdb27 | ||
|
|
60bfdae734 | ||
|
|
1cf4d6b9b8 | ||
|
|
40cd9ff51f | ||
|
|
c7e6e40030 | ||
|
|
97d0bcbfd4 | ||
|
|
6ca84425d1 |
+3
-2
@@ -1,5 +1,6 @@
|
||||
24
|
||||
25
|
||||
1.4.2
|
||||
1.6.2
|
||||
1.11.2
|
||||
1.12.21.17.2
|
||||
1.12.2
|
||||
1.17.2
|
||||
|
||||
@@ -1,5 +1,21 @@
|
||||
# CHANGELOG
|
||||
|
||||
## 1.27.1 Aug 3, 2020
|
||||
|
||||
- Remove outdated example poc-3 RPC reference (Thanks to https://github.com/swswsw)
|
||||
- Raw/Bytes `toHuman` detects ASCII sequence for text output
|
||||
- Add know types for the Rococo chain
|
||||
|
||||
## 1.26.1 Jul 27, 2020
|
||||
|
||||
- Update docs for the new `system.accountNextIndex` (Thanks to https://github.com/shawntabrizi)
|
||||
- Update contracts call parameter typing (Thanks to https://github.com/kwingram25)
|
||||
- Adjust votingBalance to only return `freeBalance` (only council voting is free + reserved)
|
||||
- Additional checks for referenced Vec sub-type deconstruction in typegen
|
||||
- Allow for API `typesBundle` option to inject a group of chain versions types
|
||||
- Update metadata static tests for latest Substrate
|
||||
- `@polkadot/util` 3.0
|
||||
|
||||
## 1.25.1 Jul 20, 2020
|
||||
|
||||
- **Important** Contract RPC result updated on Substrate, on older chains supply `ContractExecResult: 'ContractExecResultTo255'`
|
||||
|
||||
+3
-3
@@ -97,12 +97,12 @@ api.tx.utility
|
||||
|
||||
## How do I take the pending tx pool into account in my nonce?
|
||||
|
||||
The `system.account` query will always contain the current state, i.e. it will reflect the nonce for the last known block. As such when sending multiple transactions in quick succession (see batching above), there may be transactions in the pool that has the same nonce that `signAndSend` would apply - this call doesn't do any magic, it simply reads the state for the nonce. Since we can specify options to the `signandSend` operation, we can override the nonce, either by manually incrementing it o querying it via `nextNonce`.
|
||||
The `system.account` query will always contain the current state, i.e. it will reflect the nonce for the last known block. As such when sending multiple transactions in quick succession (see batching above), there may be transactions in the pool that has the same nonce that `signAndSend` would apply - this call doesn't do any magic, it simply reads the state for the nonce. Since we can specify options to the `signAndSend` operation, we can override the nonce, either by manually incrementing it or querying it via `rpc.system.accountNextIndex`.
|
||||
|
||||
```js
|
||||
for (let i = 0; i < 10; i++) {
|
||||
// retrieve the nextNonce, taking txs in the pool into account
|
||||
const nonce = await api.rpc.account.nextNonce(sender);
|
||||
// retrieve sender's next index/nonce, taking txs in the pool into account
|
||||
const nonce = await api.rpc.system.accountNextIndex(sender);
|
||||
|
||||
// send, just retrieving the hash, not waiting on status
|
||||
const txhash = await api.tx.balances
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ApiPromise, WsProvider } from '@polkadot/api';
|
||||
|
||||
...
|
||||
// Construct
|
||||
const wsProvider = new WsProvider('wss://poc-3.polkadot.io');
|
||||
const wsProvider = new WsProvider('wss://rpc.polkadot.io');
|
||||
const api = await ApiPromise.create({ provider: wsProvider });
|
||||
|
||||
// Do something
|
||||
|
||||
+1
-1
@@ -9,5 +9,5 @@
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"version": "1.25.1"
|
||||
"version": "1.27.1"
|
||||
}
|
||||
|
||||
+6
-6
@@ -24,15 +24,15 @@
|
||||
"test:watch": "polkadot-dev-run-test --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.10.5",
|
||||
"@babel/core": "^7.11.0",
|
||||
"@babel/register": "^7.10.5",
|
||||
"@babel/runtime": "^7.10.5",
|
||||
"@polkadot/dev": "^0.55.27",
|
||||
"@polkadot/ts": "^0.3.29",
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/dev": "^0.55.30",
|
||||
"@polkadot/ts": "^0.3.31",
|
||||
"@polkadot/typegen": "workspace:packages/typegen",
|
||||
"@types/jest": "^26.0.5",
|
||||
"@types/jest": "^26.0.8",
|
||||
"@vuepress/plugin-search": "^1.5.2",
|
||||
"copyfiles": "^2.3.0"
|
||||
},
|
||||
"version": "1.25.1"
|
||||
"version": "1.27.1"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api-contract",
|
||||
"version": "1.25.1",
|
||||
"version": "1.27.1",
|
||||
"description": "Interfaces for interacting with contracts and contract ABIs",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,12 +26,12 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.10.5",
|
||||
"@polkadot/api": "1.25.1",
|
||||
"@polkadot/rpc-core": "1.25.1",
|
||||
"@polkadot/types": "1.25.1",
|
||||
"@polkadot/util": "^2.18.1",
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/api": "1.27.1",
|
||||
"@polkadot/rpc-core": "1.27.1",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"bn.js": "^5.1.2",
|
||||
"rxjs": "^6.6.0"
|
||||
"rxjs": "^6.6.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { ApiTypes, DecorateMethod, ObsInnerType } from '@polkadot/api/types';
|
||||
import { AccountId, Address, ContractExecResult } from '@polkadot/types/interfaces';
|
||||
import { Codec, IKeyringPair } from '@polkadot/types/types';
|
||||
import { Codec, CodecArg, IKeyringPair } from '@polkadot/types/types';
|
||||
import { ApiObject, ContractABIMessage, ContractABIPre, ContractCallOutcome } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
@@ -38,9 +38,9 @@ export default class Contract<ApiType extends ApiTypes> extends BaseWithTxAndRpc
|
||||
this.address = this.registry.createType('Address', address);
|
||||
}
|
||||
|
||||
public call (as: 'rpc', message: string, value: BN | number, gasLimit: BN | number, ...params: any[]): ContractCall<ApiType, 'rpc'>;
|
||||
public call (as: 'tx', message: string, value: BN | number, gasLimit: BN | number, ...params: any[]): ContractCall<ApiType, 'tx'>;
|
||||
public call<CallType extends ContractCallTypes> (as: CallType, message: string, value: BN | number, gasLimit: BN | number, ...params: any[]): ContractCall<ApiType, CallType> {
|
||||
public call (as: 'rpc', message: string, value: BN | number, gasLimit: BN | number, ...params: CodecArg[]): ContractCall<ApiType, 'rpc'>;
|
||||
public call (as: 'tx', message: string, value: BN | number, gasLimit: BN | number, ...params: CodecArg[]): ContractCall<ApiType, 'tx'>;
|
||||
public call<CallType extends ContractCallTypes> (as: CallType, message: string, value: BN | number, gasLimit: BN | number, ...params: CodecArg[]): ContractCall<ApiType, CallType> {
|
||||
const { def, fn } = this.getMessage(message);
|
||||
|
||||
return {
|
||||
@@ -67,7 +67,7 @@ export default class Contract<ApiType extends ApiTypes> extends BaseWithTxAndRpc
|
||||
};
|
||||
}
|
||||
|
||||
private _createOutcome (result: ContractExecResult, origin: AccountId, message: ContractABIMessage, params: any[]): ContractCallOutcome {
|
||||
private _createOutcome (result: ContractExecResult, origin: AccountId, message: ContractABIMessage, params: CodecArg[]): ContractCallOutcome {
|
||||
let output: Codec | null = null;
|
||||
|
||||
if (result.isSuccess) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api-derive",
|
||||
"version": "1.25.1",
|
||||
"version": "1.27.1",
|
||||
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -27,18 +27,18 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.10.5",
|
||||
"@polkadot/api": "1.25.1",
|
||||
"@polkadot/rpc-core": "1.25.1",
|
||||
"@polkadot/rpc-provider": "1.25.1",
|
||||
"@polkadot/types": "1.25.1",
|
||||
"@polkadot/util": "^2.18.1",
|
||||
"@polkadot/util-crypto": "^2.18.1",
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/api": "1.27.1",
|
||||
"@polkadot/rpc-core": "1.27.1",
|
||||
"@polkadot/rpc-provider": "1.27.1",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"@polkadot/util-crypto": "^3.0.1",
|
||||
"bn.js": "^5.1.2",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.6.0"
|
||||
"rxjs": "^6.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.18.1"
|
||||
"@polkadot/keyring": "^3.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ function calcBalances (api: ApiInterfaceRx, [accountId, [freeBalance, reservedBa
|
||||
frozenFee,
|
||||
frozenMisc,
|
||||
reservedBalance,
|
||||
votingBalance: api.registry.createType('Balance', freeBalance.add(reservedBalance))
|
||||
votingBalance: api.registry.createType('Balance', freeBalance.toBn())
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+13
-13
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api",
|
||||
"version": "1.25.1",
|
||||
"version": "1.27.1",
|
||||
"description": "Promise and RxJS wrappers around the Polkadot JS RPC",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,21 +26,21 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.10.5",
|
||||
"@polkadot/api-derive": "1.25.1",
|
||||
"@polkadot/keyring": "^2.18.1",
|
||||
"@polkadot/metadata": "1.25.1",
|
||||
"@polkadot/rpc-core": "1.25.1",
|
||||
"@polkadot/rpc-provider": "1.25.1",
|
||||
"@polkadot/types": "1.25.1",
|
||||
"@polkadot/types-known": "1.25.1",
|
||||
"@polkadot/util": "^2.18.1",
|
||||
"@polkadot/util-crypto": "^2.18.1",
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/api-derive": "1.27.1",
|
||||
"@polkadot/keyring": "^3.0.1",
|
||||
"@polkadot/metadata": "1.27.1",
|
||||
"@polkadot/rpc-core": "1.27.1",
|
||||
"@polkadot/rpc-provider": "1.27.1",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/types-known": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"@polkadot/util-crypto": "^3.0.1",
|
||||
"bn.js": "^5.1.2",
|
||||
"eventemitter3": "^4.0.4",
|
||||
"rxjs": "^6.6.0"
|
||||
"rxjs": "^6.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.18.1"
|
||||
"@polkadot/keyring": "^3.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -890,6 +890,16 @@ declare module '@polkadot/api/types/submittable' {
|
||||
};
|
||||
grandpa: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
* Note that the current authority set of the GRANDPA finality gadget has
|
||||
* stalled. This will trigger a forced authority set change at the beginning
|
||||
* of the next session, to be enacted `delay` blocks after that. The delay
|
||||
* should be high enough to safely assume that the block signalling the
|
||||
* forced change will not be re-orged (e.g. 1000 blocks). The GRANDPA voters
|
||||
* will start the new authority set using the given finalized block as base.
|
||||
* Only callable by root.
|
||||
**/
|
||||
noteStalled: AugmentedSubmittable<(delay: BlockNumber | AnyNumber | Uint8Array, bestFinalizedBlockNumber: BlockNumber | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Report voter equivocation/misbehavior. This method will verify the
|
||||
* equivocation proof and validate the given key ownership proof
|
||||
|
||||
@@ -9,7 +9,7 @@ import { Observable, Subscription, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Metadata, Text } from '@polkadot/types';
|
||||
import { LATEST_EXTRINSIC_VERSION } from '@polkadot/types/extrinsic/Extrinsic';
|
||||
import { getMetadataTypes, getSpecTypes } from '@polkadot/types-known';
|
||||
import { getMetadataTypes, getSpecAlias, getSpecTypes } from '@polkadot/types-known';
|
||||
import { logger } from '@polkadot/util';
|
||||
import { cryptoWaitReady } from '@polkadot/util-crypto';
|
||||
|
||||
@@ -35,6 +35,7 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
this.registry.setKnownTypes({
|
||||
types: options.types,
|
||||
typesAlias: options.typesAlias,
|
||||
typesBundle: options.typesBundle,
|
||||
typesChain: options.typesChain,
|
||||
typesSpec: options.typesSpec
|
||||
});
|
||||
@@ -147,6 +148,33 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
).subscribe();
|
||||
}
|
||||
|
||||
private _adjustBundleTypes (chain: Text, specName: Text): void {
|
||||
// adjust known type aliases
|
||||
this.registry.knownTypes.typesAlias = getSpecAlias(this.registry, chain, specName);
|
||||
|
||||
// FIXME For the first round, we are not adjusting the user-injected RPCs
|
||||
// inject any user-level RPCs now that we have the chain/spec
|
||||
// this._rpcCore.addUserInterfaces(getSpecRpc(this.registry, chain, specName));
|
||||
|
||||
// const extraRpc = this._decorateRpc(this._rpcCore, this._decorateMethod);
|
||||
|
||||
// // FIXME this is a mess
|
||||
// Object.entries(extraRpc).forEach(([section, value]): void => {
|
||||
// if (this._rpc) {
|
||||
// if (!this._rpc[section as 'author']) {
|
||||
// this._rpc[section as 'author'] = {} as DecoratedRpcSection<ApiType, RpcInterface['author']>;
|
||||
// }
|
||||
|
||||
// Object.entries(value).forEach(([name, method]): void => {
|
||||
// if (this._rpc && !this._rpc[section as 'author'][name as 'hasKey']) {
|
||||
// // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
// this._rpc[section as 'author'][name as 'hasKey'] = method;
|
||||
// }
|
||||
// });
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
private async _metaFromChain (optMetadata: Record<string, string>): Promise<Metadata> {
|
||||
const [runtimeVersion, chain, chainProps] = await Promise.all([
|
||||
this._rpcCore.state.getRuntimeVersion().toPromise(),
|
||||
@@ -159,6 +187,11 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
this._runtimeVersion = runtimeVersion;
|
||||
this._rx.runtimeVersion = runtimeVersion;
|
||||
|
||||
// adjust types based on bundled info
|
||||
if (this.registry.knownTypes.typesBundle) {
|
||||
this._adjustBundleTypes(chain, runtimeVersion.specName);
|
||||
}
|
||||
|
||||
// do the setup for the specific chain
|
||||
this.registry.setChainProperties(chainProps);
|
||||
this.registerTypes(getSpecTypes(this.registry, chain, runtimeVersion.specName, runtimeVersion.specVersion));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/metadata",
|
||||
"version": "1.25.1",
|
||||
"version": "1.27.1",
|
||||
"description": "Helpers to extract information from runtime metadata",
|
||||
"main": "index.js",
|
||||
"publishConfig": {
|
||||
@@ -26,14 +26,14 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/type-metadata#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.10.5",
|
||||
"@polkadot/types": "1.25.1",
|
||||
"@polkadot/types-known": "1.25.1",
|
||||
"@polkadot/util": "^2.18.1",
|
||||
"@polkadot/util-crypto": "^2.18.1",
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/types-known": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"@polkadot/util-crypto": "^3.0.1",
|
||||
"bn.js": "^5.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.18.1"
|
||||
"@polkadot/keyring": "^3.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because one or more lines are too long
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/rpc-core",
|
||||
"version": "1.25.1",
|
||||
"version": "1.27.1",
|
||||
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,15 +26,15 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-core#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.10.5",
|
||||
"@polkadot/metadata": "1.25.1",
|
||||
"@polkadot/rpc-provider": "1.25.1",
|
||||
"@polkadot/types": "1.25.1",
|
||||
"@polkadot/util": "^2.18.1",
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/metadata": "1.27.1",
|
||||
"@polkadot/rpc-provider": "1.27.1",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.6.0"
|
||||
"rxjs": "^6.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.18.1"
|
||||
"@polkadot/keyring": "^3.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,7 +116,12 @@ export default class Rpc implements RpcInterface {
|
||||
this.registry = registry;
|
||||
this.provider = provider;
|
||||
|
||||
this._createInterfaces(userRpc);
|
||||
const sectionNames = Object.keys(jsonrpc);
|
||||
|
||||
// these are the base keys (i.e. part of jsonrpc)
|
||||
this.sections.push(...sectionNames);
|
||||
|
||||
this.addUserInterfaces(userRpc);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,27 +131,37 @@ export default class Rpc implements RpcInterface {
|
||||
this.provider.disconnect();
|
||||
}
|
||||
|
||||
private _createInterfaces<Section extends keyof RpcInterface> (userRpc: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>): void {
|
||||
const sectionNames = Object.keys(jsonrpc);
|
||||
|
||||
// these are the base keys (i.e. part of jsonrpc)
|
||||
this.sections.push(...sectionNames);
|
||||
|
||||
public addUserInterfaces<Section extends keyof RpcInterface> (userRpc: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>): void {
|
||||
// add any extra user-defined sections
|
||||
this.sections.push(...Object.keys(userRpc).filter((key): boolean => !this.sections.includes(key)));
|
||||
this.sections.push(...Object.keys(userRpc).filter((key) => !this.sections.includes(key)));
|
||||
|
||||
// decorate the sections with base and user methods
|
||||
this.sections.forEach((sectionName): void => {
|
||||
(this as Record<string, unknown>)[sectionName as Section] = {
|
||||
...this._createInterface(sectionName, jsonrpc[sectionName as 'babe'] || {}),
|
||||
...this._createInterface(sectionName, userRpc[sectionName] || {})
|
||||
};
|
||||
if (!(this as Record<string, unknown>)[sectionName as Section]) {
|
||||
(this as Record<string, unknown>)[sectionName as Section] = {};
|
||||
}
|
||||
|
||||
const section = (this as Record<string, unknown>)[sectionName as Section] as Record<string, any>;
|
||||
|
||||
Object
|
||||
.entries({
|
||||
...this._createInterface(sectionName, jsonrpc[sectionName as 'babe'] || {}),
|
||||
...this._createInterface(sectionName, userRpc[sectionName] || {})
|
||||
})
|
||||
.forEach(([key, value]): void => {
|
||||
// we don't want to clobber existing, i.e. when this is called again after chain is determined
|
||||
if (!section[key]) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
section[key] = value;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
private _createInterface<Section extends keyof RpcInterface> (section: string, methods: Record<string, DefinitionRpc | DefinitionRpcSub>): RpcInterface[Section] {
|
||||
return Object
|
||||
.keys(methods)
|
||||
.filter((method) => !this.mapping.has(`${section}_${method}`))
|
||||
.reduce((exposed, method): RpcInterface[Section] => {
|
||||
const def = methods[method];
|
||||
const isSubscription = !!(def as DefinitionRpcSub).pubsub;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/rpc-provider",
|
||||
"version": "1.25.1",
|
||||
"version": "1.27.1",
|
||||
"description": "Transport providers for the API",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,19 +26,19 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/rpc-provider#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.10.5",
|
||||
"@polkadot/metadata": "1.25.1",
|
||||
"@polkadot/types": "1.25.1",
|
||||
"@polkadot/util": "^2.18.1",
|
||||
"@polkadot/util-crypto": "^2.18.1",
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/metadata": "1.27.1",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"@polkadot/util-crypto": "^3.0.1",
|
||||
"bn.js": "^5.1.2",
|
||||
"eventemitter3": "^4.0.4",
|
||||
"isomorphic-fetch": "^2.2.1",
|
||||
"websocket": "^1.0.31"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.18.1",
|
||||
"@polkadot/keyring": "^3.0.1",
|
||||
"mock-socket": "^9.0.3",
|
||||
"nock": "^13.0.2"
|
||||
"nock": "^13.0.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/typegen",
|
||||
"version": "1.25.1",
|
||||
"version": "1.27.1",
|
||||
"description": "Type generation scripts",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
@@ -33,14 +33,14 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/typegen#readme",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.10.5",
|
||||
"@babel/core": "^7.11.0",
|
||||
"@babel/register": "^7.10.5",
|
||||
"@babel/runtime": "^7.10.5",
|
||||
"@polkadot/api": "1.25.1",
|
||||
"@polkadot/metadata": "1.25.1",
|
||||
"@polkadot/rpc-provider": "1.25.1",
|
||||
"@polkadot/types": "1.25.1",
|
||||
"@polkadot/util": "^2.18.1",
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/api": "1.27.1",
|
||||
"@polkadot/metadata": "1.27.1",
|
||||
"@polkadot/rpc-provider": "1.27.1",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"handlebars": "^4.7.6",
|
||||
"websocket": "^1.0.31",
|
||||
"yargs": "^15.4.1"
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
import Handlebars from 'handlebars';
|
||||
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
import * as definitions from '@polkadot/types/interfaces/definitions';
|
||||
import { Definitions } from '@polkadot/types/types';
|
||||
import * as defaultDefinitions from '@polkadot/types/interfaces/definitions';
|
||||
|
||||
import { createImports, getSimilarTypes, readTemplate, setImports, writeFile } from '../util';
|
||||
import { createImports, getSimilarTypes, formatType, readTemplate, setImports, writeFile } from '../util';
|
||||
|
||||
const StorageKeyTye = 'StorageKey | string | Uint8Array | any';
|
||||
|
||||
@@ -15,21 +16,28 @@ const template = readTemplate('rpc');
|
||||
const generateRpcTypesTemplate = Handlebars.compile(template);
|
||||
|
||||
/** @internal */
|
||||
export default function generateRpcTypes (dest = 'packages/api/src/augment/rpc.ts'): void {
|
||||
export function generateRpcTypes (importDefinitions: { [importPath: string]: Record<string, Definitions> }, dest: string): void {
|
||||
writeFile(dest, (): string => {
|
||||
const registry = new TypeRegistry();
|
||||
const allTypes = { '@polkadot/types/interfaces': definitions };
|
||||
const imports = createImports(allTypes);
|
||||
const allDefs = Object.entries(allTypes).reduce((defs, [path, obj]) => {
|
||||
|
||||
const imports = createImports(importDefinitions);
|
||||
const definitions = imports.definitions as Record<string, Definitions>;
|
||||
|
||||
const allDefs = Object.entries(importDefinitions).reduce((defs, [path, obj]) => {
|
||||
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [`${path}/${key}`]: value }), defs);
|
||||
}, {});
|
||||
|
||||
const rpcKeys = Object
|
||||
.keys(definitions)
|
||||
.filter((key) => Object.keys(definitions[key as 'babe'].rpc || {}).length !== 0)
|
||||
.filter((key) => Object.keys(definitions[key].rpc || {}).length !== 0)
|
||||
.sort();
|
||||
const modules = rpcKeys.map((section) => {
|
||||
const allMethods = Object.keys(definitions[section as 'babe'].rpc).sort().map((methodName) => {
|
||||
const def = definitions[section as 'babe'].rpc[methodName];
|
||||
|
||||
const modules = rpcKeys.map((sectionFullName) => {
|
||||
const rpc = definitions[sectionFullName].rpc;
|
||||
const section = sectionFullName.split('/').pop();
|
||||
|
||||
const allMethods = Object.keys(rpc).sort().map((methodName) => {
|
||||
const def = rpc[methodName];
|
||||
|
||||
let args;
|
||||
let type;
|
||||
@@ -69,7 +77,7 @@ export default function generateRpcTypes (dest = 'packages/api/src/augment/rpc.t
|
||||
return `${param.name}${param.isOptional ? '?' : ''}: ${similarTypes.join(' | ')}`;
|
||||
});
|
||||
|
||||
type = def.type;
|
||||
type = formatType(allDefs, def.type, imports);
|
||||
generic = '';
|
||||
}
|
||||
|
||||
@@ -105,3 +113,10 @@ export default function generateRpcTypes (dest = 'packages/api/src/augment/rpc.t
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
export default function generateDefaultRpcTypes (): void {
|
||||
generateRpcTypes(
|
||||
{ '@polkadot/types/interfaces': defaultDefinitions },
|
||||
'packages/api/src/augment/rpc.ts'
|
||||
);
|
||||
}
|
||||
|
||||
@@ -92,18 +92,22 @@ export function getSimilarTypes (definitions: Record<string, ModuleTypes>, regis
|
||||
const Clazz = ClassOfUnsafe(registry, type);
|
||||
|
||||
if (isChildClass(Vec, Clazz)) {
|
||||
const subDef = (getTypeDef(type).sub) as TypeDef;
|
||||
const vecDef = getTypeDef(type);
|
||||
const subDef = (vecDef.sub) as TypeDef;
|
||||
|
||||
if (subDef.info === TypeDefInfo.Plain) {
|
||||
possibleTypes.push(`(${getSimilarTypes(definitions, registry, subDef.type, imports).join(' | ')})[]`);
|
||||
} else if (subDef.info === TypeDefInfo.Tuple) {
|
||||
const subs = (subDef.sub as TypeDef[]).map(({ type }): string =>
|
||||
getSimilarTypes(definitions, registry, type, imports).join(' | ')
|
||||
);
|
||||
// this could be that we define a Vec type and refer to it by name
|
||||
if (subDef) {
|
||||
if (subDef.info === TypeDefInfo.Plain) {
|
||||
possibleTypes.push(`(${getSimilarTypes(definitions, registry, subDef.type, imports).join(' | ')})[]`);
|
||||
} else if (subDef.info === TypeDefInfo.Tuple) {
|
||||
const subs = (subDef.sub as TypeDef[]).map(({ type }): string =>
|
||||
getSimilarTypes(definitions, registry, type, imports).join(' | ')
|
||||
);
|
||||
|
||||
possibleTypes.push(`([${subs.join(', ')}])[]`);
|
||||
} else {
|
||||
throw new Error(`Unhandled subtype in Vec, ${JSON.stringify(subDef)}`);
|
||||
possibleTypes.push(`([${subs.join(', ')}])[]`);
|
||||
} else {
|
||||
throw new Error(`Unhandled subtype in Vec, ${JSON.stringify(subDef)}`);
|
||||
}
|
||||
}
|
||||
} else if (isChildClass(Enum, Clazz)) {
|
||||
const e = new (Clazz as Constructor)(registry) as Enum;
|
||||
@@ -141,8 +145,10 @@ export function getSimilarTypes (definitions: Record<string, ModuleTypes>, regis
|
||||
} else if (isChildClass(String, Clazz)) {
|
||||
possibleTypes.push('string');
|
||||
} else if (isChildClass(Tuple, Clazz)) {
|
||||
const subDef = getTypeDef(type).sub;
|
||||
const tupDef = getTypeDef(type);
|
||||
const subDef = tupDef.sub;
|
||||
|
||||
// this could be that we define a Tuple type and refer to it by name
|
||||
if (Array.isArray(subDef)) {
|
||||
const subs = subDef.map(({ type }) => getSimilarTypes(definitions, registry, type, imports).join(' | '));
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/types-known",
|
||||
"version": "1.25.1",
|
||||
"version": "1.27.1",
|
||||
"description": "A JavaScript wrapper for the Polkadot JsonRPC interface",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,9 +26,9 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types-known#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.10.5",
|
||||
"@polkadot/types": "1.25.1",
|
||||
"@polkadot/util": "^2.18.1",
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/types": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"bn.js": "^5.1.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import type BN from 'bn.js';
|
||||
import { Registry, RegistryTypes, OverrideModuleType, OverrideVersionedType } from '@polkadot/types/types';
|
||||
import { DefinitionRpc, DefinitionRpcSub, Registry, RegistryTypes, OverrideModuleType, OverrideVersionedType } from '@polkadot/types/types';
|
||||
|
||||
import { Text } from '@polkadot/types';
|
||||
import { bnToBn, isUndefined } from '@polkadot/util';
|
||||
@@ -58,7 +58,36 @@ export function getSpecTypes ({ knownTypes }: Registry, chainName: Text | string
|
||||
return {
|
||||
...filterVersions(typesSpec[_specName], _specVersion),
|
||||
...filterVersions(typesChain[_chainName], _specVersion),
|
||||
...filterVersions(knownTypes.typesBundle?.spec?.[_specName]?.types, _specVersion),
|
||||
...filterVersions(knownTypes.typesBundle?.chain?.[_chainName]?.types, _specVersion),
|
||||
...(knownTypes.typesSpec?.[_specName] || {}),
|
||||
...(knownTypes.typesChain?.[_chainName] || {})
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Based on the chain and runtimeVersion, get the applicable rpc definitions (ready for registration)
|
||||
*/
|
||||
export function getSpecRpc ({ knownTypes }: Registry, chainName: Text | string, specName: Text | string): Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>> {
|
||||
const _chainName = chainName.toString();
|
||||
const _specName = specName.toString();
|
||||
|
||||
return {
|
||||
...(knownTypes.typesBundle?.spec?.[_specName]?.rpc || {}),
|
||||
...(knownTypes.typesBundle?.chain?.[_chainName]?.rpc || {})
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Based on the chain and runtimeVersion, get the applicable alias definitions (ready for registration)
|
||||
*/
|
||||
export function getSpecAlias ({ knownTypes }: Registry, chainName: Text | string, specName: Text | string): Record<string, OverrideModuleType> {
|
||||
const _chainName = chainName.toString();
|
||||
const _specName = specName.toString();
|
||||
|
||||
return {
|
||||
...(knownTypes.typesAlias || {}),
|
||||
...(knownTypes.typesBundle?.spec?.[_specName]?.alias || {}),
|
||||
...(knownTypes.typesBundle?.chain?.[_chainName]?.alias || {})
|
||||
};
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import { OverrideVersionedType } from '@polkadot/types/types';
|
||||
import centrifugeChain from './centrifuge-chain';
|
||||
import kusama from './kusama';
|
||||
import polkadot from './polkadot';
|
||||
import rococo from './rococo';
|
||||
import westend from './westend';
|
||||
|
||||
// Type overrides for specific spec types & versions as given in runtimeVersion
|
||||
@@ -14,6 +15,7 @@ const typesSpec: Record<string, OverrideVersionedType[]> = {
|
||||
'centrifuge-chain': centrifugeChain,
|
||||
kusama,
|
||||
polkadot,
|
||||
rococo,
|
||||
westend
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
// Copyright 2017-2020 @polkadot/types-known authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { OverrideVersionedType } from '@polkadot/types/types';
|
||||
|
||||
const sharedTypes = {
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId'
|
||||
};
|
||||
|
||||
const versioned: OverrideVersionedType[] = [
|
||||
{
|
||||
minmax: [0, undefined],
|
||||
types: {
|
||||
...sharedTypes
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
export default versioned;
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/types",
|
||||
"version": "1.25.1",
|
||||
"version": "1.27.1",
|
||||
"description": "Implementation of the Parity codec",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -26,17 +26,17 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.10.5",
|
||||
"@polkadot/metadata": "1.25.1",
|
||||
"@polkadot/util": "^2.18.1",
|
||||
"@polkadot/util-crypto": "^2.18.1",
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/metadata": "1.27.1",
|
||||
"@polkadot/util": "^3.0.1",
|
||||
"@polkadot/util-crypto": "^3.0.1",
|
||||
"@types/bn.js": "^4.11.6",
|
||||
"bn.js": "^5.1.2",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.6.0"
|
||||
"rxjs": "^6.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.18.1",
|
||||
"@polkadot/keyring": "^3.0.1",
|
||||
"@types/memoizee": "^0.4.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -117,7 +117,7 @@ export default class Raw extends Uint8Array implements IU8a {
|
||||
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
||||
*/
|
||||
public toHuman (): AnyJson {
|
||||
return this.isUtf8
|
||||
return this.isAscii
|
||||
? this.toUtf8()
|
||||
: this.toJSON();
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import type BN from 'bn.js';
|
||||
import { ChainProperties } from '../interfaces/system';
|
||||
import { CallFunction } from './calls';
|
||||
import { Codec, Constructor } from './codec';
|
||||
import { DefinitionRpc, DefinitionRpcSub } from './definitions';
|
||||
import { AnyJson } from './helpers';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-interface
|
||||
@@ -19,6 +20,17 @@ export interface OverrideVersionedType {
|
||||
|
||||
export type OverrideModuleType = Record<string, string>;
|
||||
|
||||
export interface OverrideBundleDefinition {
|
||||
alias?: Record<string, OverrideModuleType>;
|
||||
rpc?: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>;
|
||||
types?: OverrideVersionedType[];
|
||||
}
|
||||
|
||||
export interface OverrideBundleType {
|
||||
chain?: Record<string, OverrideBundleDefinition>;
|
||||
spec?: Record<string, OverrideBundleDefinition>;
|
||||
}
|
||||
|
||||
export type RegistryTypes = Record<string, Constructor | string | Record<string, string> | { _enum: string[] | Record<string, string | null> } | { _set: Record<string, number> }>;
|
||||
|
||||
export interface RegistryMetadataText extends String, Codec {
|
||||
@@ -97,6 +109,10 @@ export interface RegisteredTypes {
|
||||
* @description Alias an types, as received via the metadata, to a JS-specific type to avoid conflicts. For instance, you can rename the `Proposal` in the `treasury` module to `TreasuryProposal` as to not have conflicts with the one for democracy.
|
||||
*/
|
||||
typesAlias?: Record<string, OverrideModuleType>;
|
||||
/**
|
||||
* @description A bundle of types related to chain & spec that is injected based on what the chain contains
|
||||
*/
|
||||
typesBundle?: OverrideBundleType;
|
||||
/**
|
||||
* @description Additional types that are injected based on the chain we are connecting to. There are keyed by the chain, i.e. `{ 'Kusama CC1': { ... } }`
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user