Compare commits

..
28 Commits
Author SHA1 Message Date
Github Actions 19510c1ede [CI Skip] release/stable 1.27.1
skip-checks: true
2020-08-03 07:18:56 +00:00
Jaco Greeff 97b5c699b1 1.27 (#2462) 2020-08-03 09:08:09 +02:00
Github Actions d2befda86e [CI Skip] release/beta 1.27.0-beta.3
skip-checks: true
2020-07-31 09:46:53 +00:00
Jaco Greeff 740348b48f Bump deps (#2460) 2020-07-31 11:34:00 +02:00
Github Actions 9e2a5cf532 [CI Skip] release/beta 1.27.0-beta.2
skip-checks: true
2020-07-30 16:28:52 +00:00
Jaco Greeff 6df466d9ea Known types for Rococo (#2459)
* Known types for Rococo

* Update rococo.ts
2020-07-30 18:17:32 +02:00
Github Actions e2a2ac2842 [CI Skip] release/beta 1.27.0-beta.1
skip-checks: true
2020-07-28 11:11:30 +00:00
sung wu 5adc846e45 update doc - "create instance" page (#2456)
poc-3.polkadot.io is not available right now. use rpc.polkadot.io instead.
2020-07-28 12:59:27 +02:00
Github Actions 75aa310837 [CI Skip] release/beta 1.27.0-beta.0
skip-checks: true
2020-07-28 10:27:07 +00:00
Jaco Greeff ce0523eb1c Raw toHuman Ascii detection (#2455) 2020-07-28 12:17:26 +02:00
Github Actions eb0370bb66 [CI Skip] release/stable 1.26.1
skip-checks: true
2020-07-27 11:21:29 +00:00
Jaco Greeff 5eb491dc67 1.26 (#2453) 2020-07-27 13:10:07 +02:00
Github Actions b50294ab0f [CI Skip] release/beta 1.26.0-beta.6
skip-checks: true
2020-07-27 10:56:53 +00:00
Keith Ingram e1cb62d2d2 Type for contract call params (#2452) 2020-07-27 12:43:54 +02:00
Github Actions 8ed0ef2295 [CI Skip] release/beta 1.26.0-beta.5
skip-checks: true
2020-07-27 10:18:11 +00:00
Jaco Greeff 956e173323 Metadata bump (#2451) 2020-07-27 12:06:28 +02:00
Github Actions b8a37ba438 [CI Skip] release/beta 1.26.0-beta.4
skip-checks: true
2020-07-27 07:22:38 +00:00
Jaco Greeff e7669c2b00 Add api typesBundle (#2422)
* Add api typesBundle

* Inject user-defined RPC from spec/chain

* Linting cleanups

* Invert check fro non-existing

* Extract bundle injection

* Ignore RPC for the first round

* CHANGELOG

* Merge master
2020-07-27 09:12:04 +02:00
Github Actions 6c309a503d [CI Skip] release/beta 1.26.0-beta.3
skip-checks: true
2020-07-27 07:02:12 +00:00
Jaco Greeff 3cf67c975a Bump deps (#2450) 2020-07-27 08:49:52 +02:00
Github Actions 077914364c [CI Skip] release/beta 1.26.0-beta.2
skip-checks: true
2020-07-25 12:15:51 +00:00
Jaco Greeff 56e4cbdb27 Update .123trigger 2020-07-25 14:03:36 +02:00
nsso 60bfdae734 support rpc import definitions (#2438)
* support import definitions

* fix lint
2020-07-25 13:53:04 +02:00
Jaco Greeff 1cf4d6b9b8 Additional typegen asserts (#2448)
* Additional typegen asserts

* typo

* Revert tuple assert

* Free-standing Vec is valid
2020-07-25 13:47:34 +02:00
Github Actions 40cd9ff51f [CI Skip] release/beta 1.26.0-beta.1
skip-checks: true
2020-07-20 18:13:14 +00:00
Jaco Greeff c7e6e40030 Voting is only free balance (#2444) 2020-07-20 20:03:26 +02:00
Github Actions 97d0bcbfd4 [CI Skip] release/beta 1.26.0-beta.0
skip-checks: true
2020-07-20 10:55:27 +00:00
Shawn Tabrizi 6ca84425d1 Update docs for accountNextIndex (#2443) 2020-07-20 12:45:01 +02:00
30 changed files with 1309 additions and 966 deletions
+3 -2
View File
@@ -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
+16
View File
@@ -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
View File
@@ -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
+1 -1
View File
@@ -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
View File
@@ -9,5 +9,5 @@
"packages": [
"packages/*"
],
"version": "1.25.1"
"version": "1.27.1"
}
+6 -6
View File
@@ -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"
}
+7 -7
View File
@@ -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"
}
}
+5 -5
View File
@@ -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) {
+10 -10
View File
@@ -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"
}
}
+1 -1
View File
@@ -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
View File
@@ -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"
}
}
+10
View File
@@ -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
+34 -1
View File
@@ -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));
+7 -7
View File
@@ -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
+8 -8
View File
@@ -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"
}
}
+27 -12
View File
@@ -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;
+8 -8
View File
@@ -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"
}
}
+8 -8
View File
@@ -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"
+26 -11
View File
@@ -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'
);
}
+17 -11
View File
@@ -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(' | '));
+4 -4
View File
@@ -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": {
+30 -1
View File
@@ -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 || {})
};
}
+2
View File
@@ -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
};
+22
View File
@@ -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;
+7 -7
View File
@@ -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"
}
}
+1 -1
View File
@@ -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();
}
+16
View File
@@ -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': { ... } }`
*/
+827 -703
View File
File diff suppressed because it is too large Load Diff