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 | ||
|
|
8481647d2c | ||
|
|
658dda66a4 | ||
|
|
87f18efe72 | ||
|
|
bcdfcce89c | ||
|
|
9418f1de56 | ||
|
|
37c8b8e592 | ||
|
|
4f8db79a40 | ||
|
|
54cf086a89 | ||
|
|
37ddcaa32d | ||
|
|
6a2baf8352 | ||
|
|
ecca91dffd | ||
|
|
42576d74ac | ||
|
|
26a6f20dbf | ||
|
|
c3ee8393b2 | ||
|
|
b6f0b9f262 | ||
|
|
991dc48020 | ||
|
|
e4a82f9a1d | ||
|
|
c8b6012553 | ||
|
|
d0fe862605 | ||
|
|
61a0198695 | ||
|
|
345a97dc9f | ||
|
|
f821ab8ecd | ||
|
|
f9e2bf332d | ||
|
|
ad69430980 | ||
|
|
d25743016c | ||
|
|
ee0a46adc4 | ||
|
|
f516abfc3f | ||
|
|
1a96ca5c0e | ||
|
|
8c73cd7d6e | ||
|
|
36232c0289 | ||
|
|
50d4e0397f | ||
|
|
539a8c4cb5 | ||
|
|
b849976b3b | ||
|
|
2395401a2b | ||
|
|
0e1bbd5cac | ||
|
|
e9489d41cb | ||
|
|
63483b9db7 | ||
|
|
b26c7f9f0a | ||
|
|
a165c9375c | ||
|
|
28631f7180 | ||
|
|
6489251b47 | ||
|
|
66884febea | ||
|
|
8058dc350f | ||
|
|
63096cc238 | ||
|
|
05600c0cd0 | ||
|
|
eed5e23e65 | ||
|
|
cdf5b15673 | ||
|
|
1922676bd7 | ||
|
|
b6c427e985 | ||
|
|
0327aedf8e | ||
|
|
d7035cebb1 | ||
|
|
8b492021af | ||
|
|
6a01fc7c8c | ||
|
|
bbc30ec9dc | ||
|
|
f07c0628bc | ||
|
|
023c7588e5 | ||
|
|
7dfc8625cc | ||
|
|
8643b5da87 | ||
|
|
afa0e63ae8 | ||
|
|
534303ff45 | ||
|
|
f1ebcddec6 | ||
|
|
657a2006dd | ||
|
|
219e928c01 | ||
|
|
43183118d5 | ||
|
|
76e15d465d | ||
|
|
4c0387e1a3 | ||
|
|
bbbd82eb4a | ||
|
|
a34a7450aa | ||
|
|
bf472fdcf4 | ||
|
|
f428a58006 | ||
|
|
fcce2ab340 | ||
|
|
877eb11717 | ||
|
|
4b55f1be93 | ||
|
|
f2a677634e | ||
|
|
eea4c8775e | ||
|
|
792bf0ec36 | ||
|
|
e3d13107a9 | ||
|
|
e5c2c6a228 | ||
|
|
d2be79132c | ||
|
|
76da2638c1 | ||
|
|
daf3912920 | ||
|
|
6dfebbb9fe | ||
|
|
e55c5f77f7 | ||
|
|
c7315ffb74 | ||
|
|
84eb806f07 | ||
|
|
2493442a2e | ||
|
|
77df7907c7 | ||
|
|
f1b6268784 | ||
|
|
9aa9380251 | ||
|
|
b4306cb60a | ||
|
|
1e83daf797 | ||
|
|
d46d32d9bc | ||
|
|
032a0a595c | ||
|
|
34101ec12b | ||
|
|
4e02b982d3 | ||
|
|
5b96d52fa6 | ||
|
|
735f2b835e | ||
|
|
646e64c286 | ||
|
|
fc9060caa8 | ||
|
|
503c2b3c63 | ||
|
|
168abc130f | ||
|
|
5c5db2709b | ||
|
|
5a4ff5420f | ||
|
|
a1655508ba | ||
|
|
64827a6114 | ||
|
|
2eb09374bc |
+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,11 +1,85 @@
|
||||
# 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'`
|
||||
- Support for custom HTTP headers in providers (Thanks to https://github.com/brad-larson)
|
||||
- Update known types for Centrifuge (Thanks to https://github.com/philipstanislaus)
|
||||
- Update API users with Registrar #1 (Thanks to https://github.com/chevdor)
|
||||
- Raw/Bytes `toHuman()` displays utf-8 as available
|
||||
- Add fallback for `setImmediate` when not polyfilled
|
||||
- Update `NetworkState` reputation type for `system_networkState` RPC
|
||||
- Update session progress calcs for Aura (cater for negative)
|
||||
- Fix class prototype for (basically-deprecated) Linkage type
|
||||
- Add Polkadot types for `purchase` pallet
|
||||
|
||||
## 1.24.1 Jul 13, 2020
|
||||
|
||||
- Added `isAscii` & `isUtf8` getters to `Bytes` & `Raw` types
|
||||
- Added `toUtf8()` helper to `Bytes` & `Raw` types
|
||||
- `@polkadot/util` 2.18
|
||||
|
||||
## 1.23.1 Jul 6, 2020
|
||||
|
||||
- Small README typo fix (Thanks to https://github.com/woss)
|
||||
- Add latest Substrate master types
|
||||
- Adjust `<Codec>.toRawType()` to use registry name as available
|
||||
- Update `ProxyType` for Kusama, Polkadot & Westend with `IdentityJudgement`
|
||||
- Validate number format (signed/unsigned) for number types
|
||||
- Remove core codec dependencies on Base class (with proper TS encapsulation)
|
||||
- `@polkadot/util` 2.17
|
||||
|
||||
## 1.22.1 Jun 30, 2020
|
||||
|
||||
- **Important** Substrate changed the treasury tip structure, on older chains supply `OpenTip: 'OpenTipTo225'`
|
||||
- Allow for `[u8; 33]` in U8aFixed (Thanks to https://github.com/akru)
|
||||
- Improve derive accountId -> accountIndex lookups (optimize entries queries)
|
||||
- Vesting balance calculations via `derive.balances.all` has been updated for locks
|
||||
- Add derive for multi staking rewards with specified eras
|
||||
- `@polkadot/util` 2.16
|
||||
|
||||
## 1.21.1 Jun 23, 2020
|
||||
|
||||
- Fix subscriptions never unsubscribing after the id swap in 1.18.1 (Thanks to https://github.com/dillu24 for testing iterations)
|
||||
- Add support for `CheckMortality` signed extension (old `CheckEra` is now an alias)
|
||||
- Promise API will default to using `getStorage` on non-subscription calls, reducing RPC overhead
|
||||
- Optimize derive BN allocations, using in-place operators as applicable
|
||||
- Add new Substrate types for Babe `EquivocationProof`
|
||||
- Adjust `Releases` enum to use a shared instance
|
||||
|
||||
## 1.20.1 Jun 22, 2020
|
||||
|
||||
- **Important** RPC for `account_nextIndex` has been moved to `system_accountNextIndex` (Aligning with Substrate as a primary alias)
|
||||
- Cleanup map entries support with only Substrate 2.0-era RPCs (when introduced)
|
||||
- Add `system_dryRun` RPC
|
||||
- Optimize `derive.staking.queryMulti` retrievals with additional per-type batching
|
||||
- Add `derive.staking.waitingInfo` (same as `electedInfo` for waiting validators)
|
||||
- Adjust types & metadata for latest Substrate
|
||||
- `@polkadot/util` 2.15
|
||||
|
||||
## 1.19.1 Jun 16, 2020
|
||||
|
||||
- Improve typing on `.entries()` queries (Thanks to https://github.com/monitz87)
|
||||
- Align metadata and types with latest Substrate
|
||||
- Update Polkadot types for current evolution of parachains
|
||||
- Allow for type aliasing on events (aligning with calls & queries)
|
||||
- `@polkadot/util` 2.14
|
||||
|
||||
## 1.18.1 Jun 8, 2020
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
|
||||
# @polkadot/api
|
||||
|
||||
This library provides a clean wrapper around all the methods exposed by a Polkadot/Subtrate network client and defines all the types exposed by a node. For complete documentation around the classes, interfaces and their use, visit the [documentation portal](https://polkadot.js.org/api/).
|
||||
This library provides a clean wrapper around all the methods exposed by a Polkadot/Substrate network client and defines all the types exposed by a node. For complete documentation around the classes, interfaces and their use, visit the [documentation portal](https://polkadot.js.org/api/).
|
||||
|
||||
If you are an existing user, please be sure to track the [CHANGELOG](CHANGELOG.md) and [UPGRADING](UPGRADING.md) guides when changing versions.
|
||||
|
||||
|
||||
+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.19.1"
|
||||
"version": "1.27.1"
|
||||
}
|
||||
|
||||
+7
-7
@@ -24,15 +24,15 @@
|
||||
"test:watch": "polkadot-dev-run-test --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.10.2",
|
||||
"@babel/register": "^7.10.1",
|
||||
"@babel/runtime": "^7.10.2",
|
||||
"@polkadot/dev": "^0.55.10",
|
||||
"@polkadot/ts": "^0.3.26",
|
||||
"@babel/core": "^7.11.0",
|
||||
"@babel/register": "^7.10.5",
|
||||
"@babel/runtime": "^7.11.0",
|
||||
"@polkadot/dev": "^0.55.30",
|
||||
"@polkadot/ts": "^0.3.31",
|
||||
"@polkadot/typegen": "workspace:packages/typegen",
|
||||
"@types/jest": "^26.0.0",
|
||||
"@types/jest": "^26.0.8",
|
||||
"@vuepress/plugin-search": "^1.5.2",
|
||||
"copyfiles": "^2.3.0"
|
||||
},
|
||||
"version": "1.19.1"
|
||||
"version": "1.27.1"
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api-contract",
|
||||
"version": "1.19.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.2",
|
||||
"@polkadot/api": "1.19.1",
|
||||
"@polkadot/rpc-core": "1.19.1",
|
||||
"@polkadot/types": "1.19.1",
|
||||
"@polkadot/util": "^2.14.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.5.5"
|
||||
"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.19.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.2",
|
||||
"@polkadot/api": "1.19.1",
|
||||
"@polkadot/rpc-core": "1.19.1",
|
||||
"@polkadot/rpc-provider": "1.19.1",
|
||||
"@polkadot/types": "1.19.1",
|
||||
"@polkadot/util": "^2.14.1",
|
||||
"@polkadot/util-crypto": "^2.14.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.5.5"
|
||||
"rxjs": "^6.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.14.1"
|
||||
"@polkadot/keyring": "^3.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@ import { memo } from '../util';
|
||||
|
||||
const enumsetSize = ENUMSET_SIZE.toNumber();
|
||||
|
||||
let indicesCache: AccountIndexes | null = null;
|
||||
|
||||
function queryEnumSet (api: ApiInterfaceRx): Observable<AccountIndexes> {
|
||||
return api.query.indices.nextEnumSet<AccountIndex>().pipe(
|
||||
// use the nextEnumSet (which is a counter of the number of sets) to construct
|
||||
@@ -72,11 +74,20 @@ function queryAccounts (api: ApiInterfaceRx): Observable<AccountIndexes> {
|
||||
*/
|
||||
export function indexes (api: ApiInterfaceRx): () => Observable<AccountIndexes> {
|
||||
return memo((): Observable<AccountIndexes> =>
|
||||
(api.query.indices
|
||||
? isFunction(api.query.indices.accounts)
|
||||
? queryAccounts(api)
|
||||
: queryEnumSet(api)
|
||||
: of({} as AccountIndexes)
|
||||
).pipe(startWith({}))
|
||||
indicesCache
|
||||
? of(indicesCache)
|
||||
: (
|
||||
api.query.indices
|
||||
? isFunction(api.query.indices.accounts)
|
||||
? queryAccounts(api).pipe(startWith({}))
|
||||
: queryEnumSet(api).pipe(startWith({}))
|
||||
: of({} as AccountIndexes)
|
||||
).pipe(
|
||||
map((indices): AccountIndexes => {
|
||||
indicesCache = indices;
|
||||
|
||||
return indices;
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -20,15 +20,17 @@ type Result = [DeriveBalancesAccount, BlockNumber, ResultBalance];
|
||||
function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBalance, frozenFee, frozenMisc, reservedBalance, votingBalance }, bestNumber, [vesting, locks]]: Result): DeriveBalancesAll {
|
||||
let lockedBalance = api.registry.createType('Balance');
|
||||
let lockedBreakdown: (BalanceLock | BalanceLockTo212)[] = [];
|
||||
let vestingLocked = api.registry.createType('Balance');
|
||||
let allLocked = false;
|
||||
|
||||
if (Array.isArray(locks)) {
|
||||
// only get the locks that are valid until passed the current block
|
||||
lockedBreakdown = (locks as BalanceLockTo212[]).filter(({ until }): boolean => !until || (bestNumber && until.gt(bestNumber)));
|
||||
|
||||
const notAll = lockedBreakdown.filter(({ amount }): boolean => !amount.isMax());
|
||||
const notAll = lockedBreakdown.filter(({ amount }) => !amount.isMax());
|
||||
|
||||
allLocked = lockedBreakdown.some(({ amount }): boolean => amount.isMax());
|
||||
allLocked = lockedBreakdown.some(({ amount }) => amount.isMax());
|
||||
vestingLocked = api.registry.createType('Balance', lockedBreakdown.filter(({ id }) => id.eq('0x76657374696e6720')).reduce((result: BN, { amount }) => result.iadd(amount), new BN(0)));
|
||||
|
||||
// get the maximum of the locks according to https://github.com/paritytech/substrate/blob/master/srml/balances/src/lib.rs#L699
|
||||
if (notAll.length) {
|
||||
@@ -41,19 +43,11 @@ function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBala
|
||||
// - perBlock is the unlock amount
|
||||
const { locked: vestingTotal, perBlock, startingBlock } = vesting || api.registry.createType('VestingInfo');
|
||||
const isStarted = bestNumber.gt(startingBlock);
|
||||
const vestedBalance = api.registry.createType('Balance', isStarted ? perBlock.mul(bestNumber.sub(startingBlock)) : 0);
|
||||
const isVesting = isStarted && vestedBalance.lt(vestingTotal);
|
||||
|
||||
// The available balance & vested has an interplay here
|
||||
// "
|
||||
// vesting is a guarantee that the account's balance will never go below a certain amount. so it functions in the opposite way, a bit like a lock that is monotonically decreasing rather than a liquid amount that is monotonically increasing.
|
||||
// locks function as the same guarantee - that a balance will not be lower than a particular amount.
|
||||
// because of this you can see that if there is a "vesting lock" that guarantees the balance cannot go below 200, and a "staking lock" that guarantees the balance cannot drop below 300, then we just have two guarantees of which the first is irrelevant.
|
||||
// i.e. (balance >= 200 && balance >= 300) == (balance >= 300)
|
||||
// ""
|
||||
const floating = freeBalance.sub(lockedBalance);
|
||||
const extraReceived = isVesting ? freeBalance.sub(vestingTotal) : new BN(0);
|
||||
const availableBalance = api.registry.createType('Balance', allLocked ? 0 : bnMax(new BN(0), isVesting && floating.gt(vestedBalance) ? vestedBalance.add(extraReceived) : floating));
|
||||
const vestedNow = isStarted ? perBlock.mul(bestNumber.sub(startingBlock)) : new BN(0);
|
||||
const vestedBalance = vestedNow.gt(vestingTotal) ? vestingTotal : api.registry.createType('Balance', vestedNow);
|
||||
const isVesting = isStarted && !vestingLocked.isZero();
|
||||
const vestedClaimable = api.registry.createType('Balance', isVesting ? vestingLocked.sub(vestingTotal.sub(vestedBalance)) : 0);
|
||||
const availableBalance = api.registry.createType('Balance', allLocked ? 0 : bnMax(new BN(0), freeBalance.sub(lockedBalance)));
|
||||
|
||||
return {
|
||||
accountId,
|
||||
@@ -67,6 +61,8 @@ function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBala
|
||||
lockedBreakdown,
|
||||
reservedBalance,
|
||||
vestedBalance,
|
||||
vestedClaimable,
|
||||
vestingLocked,
|
||||
vestingTotal,
|
||||
votingBalance
|
||||
};
|
||||
|
||||
@@ -82,15 +82,15 @@ function calcVotesPrev (votesFor: DeriveReferendumVote[]): DeriveReferendumVoteS
|
||||
if (vote.isAye) {
|
||||
state.allAye.push(derived);
|
||||
state.voteCountAye++;
|
||||
state.votedAye = state.votedAye.add(counted);
|
||||
state.votedAye.iadd(counted);
|
||||
} else {
|
||||
state.allNay.push(derived);
|
||||
state.voteCountNay++;
|
||||
state.votedNay = state.votedNay.add(counted);
|
||||
state.votedNay.iadd(counted);
|
||||
}
|
||||
|
||||
state.voteCount++;
|
||||
state.votedTotal = state.votedTotal.add(counted);
|
||||
state.votedTotal.iadd(counted);
|
||||
|
||||
return state;
|
||||
}, {
|
||||
|
||||
@@ -17,9 +17,9 @@ type ResultSlots = [u64, u64, u64, Option<SessionIndex>];
|
||||
type ResultSlotsFlat = [u64, u64, u64, SessionIndex];
|
||||
|
||||
function createDerive (api: ApiInterfaceRx, info: DeriveSessionInfo, [currentSlot, epochIndex, epochOrGenesisStartSlot, activeEraStartSessionIndex]: ResultSlotsFlat): DeriveSessionProgress {
|
||||
const epochStartSlot = epochIndex.mul(info.sessionLength).add(epochOrGenesisStartSlot);
|
||||
const epochStartSlot = epochIndex.mul(info.sessionLength).iadd(epochOrGenesisStartSlot);
|
||||
const sessionProgress = currentSlot.sub(epochStartSlot);
|
||||
const eraProgress = info.currentIndex.sub(activeEraStartSessionIndex).mul(info.sessionLength).add(sessionProgress);
|
||||
const eraProgress = info.currentIndex.sub(activeEraStartSessionIndex).imul(info.sessionLength).iadd(sessionProgress);
|
||||
|
||||
return {
|
||||
...info,
|
||||
@@ -30,14 +30,11 @@ function createDerive (api: ApiInterfaceRx, info: DeriveSessionInfo, [currentSlo
|
||||
|
||||
function queryAura (api: ApiInterfaceRx): Observable<DeriveSessionProgress> {
|
||||
return api.derive.session.info().pipe(
|
||||
map((info): DeriveSessionProgress =>
|
||||
createDerive(api, info, [
|
||||
api.registry.createType('u64', 1),
|
||||
api.registry.createType('u64', 1),
|
||||
api.registry.createType('u64', 1),
|
||||
api.registry.createType('SessionIndex', 1)
|
||||
])
|
||||
)
|
||||
map((info): DeriveSessionProgress => ({
|
||||
...info,
|
||||
eraProgress: api.registry.createType('BlockNumber'),
|
||||
sessionProgress: api.registry.createType('BlockNumber')
|
||||
}))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Balance, StakingLedger, UnlockChunk } from '@polkadot/types/interfaces'
|
||||
import { DeriveSessionInfo, DeriveStakingAccount, DeriveStakingQuery, DeriveUnlocking } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest } from 'rxjs';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
@@ -21,7 +21,7 @@ function groupByEra (list: UnlockChunk[]): Record<string, BN> {
|
||||
|
||||
map[key] = !map[key]
|
||||
? value.unwrap()
|
||||
: map[key].add(value.unwrap());
|
||||
: map[key].iadd(value.unwrap());
|
||||
|
||||
return map;
|
||||
}, {});
|
||||
@@ -32,8 +32,8 @@ function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger |
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const unlockingChunks = stakingLedger.unlocking.filter(({ era }): boolean =>
|
||||
era.unwrap().sub(sessionInfo.activeEra).gtn(0)
|
||||
const unlockingChunks = stakingLedger.unlocking.filter(({ era }) =>
|
||||
era.unwrap().gt(sessionInfo.activeEra)
|
||||
);
|
||||
|
||||
if (!unlockingChunks.length) {
|
||||
@@ -43,11 +43,13 @@ function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger |
|
||||
// group the unlock chunks that have the same era and sum their values
|
||||
const groupedResult = groupByEra(unlockingChunks);
|
||||
const results = Object.entries(groupedResult).map(([eraString, value]): DeriveUnlocking => ({
|
||||
remainingEras: new BN(eraString).sub(sessionInfo.activeEra),
|
||||
remainingEras: new BN(eraString).isub(sessionInfo.activeEra),
|
||||
value: api.registry.createType('Balance', value)
|
||||
}));
|
||||
|
||||
return results.length ? results : undefined;
|
||||
return results.length
|
||||
? results
|
||||
: undefined;
|
||||
}
|
||||
|
||||
function redeemableSum (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DeriveSessionInfo): Balance {
|
||||
@@ -57,7 +59,7 @@ function redeemableSum (api: ApiInterfaceRx, stakingLedger: StakingLedger | unde
|
||||
|
||||
return api.registry.createType('Balance', stakingLedger.unlocking.reduce((total, { era, value }): BN => {
|
||||
return sessionInfo.activeEra.gte(era.unwrap())
|
||||
? total.add(value.unwrap())
|
||||
? total.iadd(value.unwrap())
|
||||
: total;
|
||||
}, new BN(0)));
|
||||
}
|
||||
@@ -70,23 +72,6 @@ function parseResult (api: ApiInterfaceRx, sessionInfo: DeriveSessionInfo, query
|
||||
};
|
||||
}
|
||||
|
||||
export function _account (api: ApiInterfaceRx): (sessionInfo: DeriveSessionInfo, accountId: Uint8Array | string) => Observable<DeriveStakingAccount> {
|
||||
return memo((sessionInfo: DeriveSessionInfo, accountId: Uint8Array | string): Observable<DeriveStakingAccount> =>
|
||||
api.derive.staking.query(accountId).pipe(
|
||||
map((query) => parseResult(api, sessionInfo, query))
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description From a stash, retrieve the controllerId and fill in all the relevant staking details
|
||||
*/
|
||||
export function account (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable<DeriveStakingAccount> {
|
||||
return memo((accountId: Uint8Array | string): Observable<DeriveStakingAccount> =>
|
||||
api.derive.session.info().pipe(
|
||||
switchMap((sessionInfo) => api.derive.staking._account(sessionInfo, accountId))
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description From a list of stashes, fill in all the relevant staking details
|
||||
*/
|
||||
@@ -94,7 +79,21 @@ export function accounts (api: ApiInterfaceRx): (accountIds: (Uint8Array | strin
|
||||
return memo((accountIds: (Uint8Array | string)[]): Observable<DeriveStakingAccount[]> =>
|
||||
api.derive.session.info().pipe(
|
||||
switchMap((sessionInfo) =>
|
||||
combineLatest(accountIds.map((accountId) => api.derive.staking._account(sessionInfo, accountId)))
|
||||
api.derive.staking.queryMulti(accountIds).pipe(
|
||||
map((queries) => queries.map((query) => parseResult(api, sessionInfo, query)))
|
||||
)
|
||||
)
|
||||
));
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description From a stash, retrieve the controllerId and fill in all the relevant staking details
|
||||
*/
|
||||
export function account (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable<DeriveStakingAccount> {
|
||||
return memo((accountId: Uint8Array | string): Observable<DeriveStakingAccount> =>
|
||||
api.derive.staking.accounts([accountId]).pipe(
|
||||
map(([first]) => first)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId } from '@polkadot/types/interfaces';
|
||||
import { DeriveStakingQuery, DeriveStakingElected } from '../types';
|
||||
import { DeriveStakingElected } from '../types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
@@ -14,18 +13,14 @@ import { memo } from '../util';
|
||||
export function electedInfo (api: ApiInterfaceRx): () => Observable<DeriveStakingElected> {
|
||||
return memo((): Observable<DeriveStakingElected> =>
|
||||
api.derive.staking.validators().pipe(
|
||||
switchMap(({ nextElected }): Observable<[AccountId[], DeriveStakingQuery[]]> =>
|
||||
combineLatest([
|
||||
of(nextElected),
|
||||
combineLatest(
|
||||
nextElected.map((accountId) => api.derive.staking.query(accountId))
|
||||
)
|
||||
])
|
||||
),
|
||||
map(([nextElected, info]): DeriveStakingElected => ({
|
||||
info,
|
||||
nextElected
|
||||
}))
|
||||
switchMap(({ nextElected }): Observable<DeriveStakingElected> =>
|
||||
api.derive.staking.queryMulti(nextElected).pipe(
|
||||
map((info): DeriveStakingElected => ({
|
||||
info,
|
||||
nextElected
|
||||
}))
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ import { Option, u32 } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function erasHistoric (api: ApiInterfaceRx): (withActive?: boolean) => Observable<EraIndex[]> {
|
||||
return memo((withActive?: boolean): Observable<EraIndex[]> =>
|
||||
export function erasHistoric (api: ApiInterfaceRx): (withActive: boolean) => Observable<EraIndex[]> {
|
||||
return memo((withActive: boolean): Observable<EraIndex[]> =>
|
||||
api.query.staking?.activeEra
|
||||
? api.queryMulti<[Option<ActiveEraInfo>, u32]>([
|
||||
api.query.staking.activeEra,
|
||||
|
||||
@@ -21,3 +21,4 @@ export * from './stakerRewards';
|
||||
export * from './stakerSlashes';
|
||||
export * from './stashes';
|
||||
export * from './validators';
|
||||
export * from './waitingInfo';
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, Exposure, Keys, Nominations, RewardDestination, ValidatorPrefs } from '@polkadot/types/interfaces';
|
||||
import { AccountId, EraIndex, Exposure, Keys, Nominations, RewardDestination, StakingLedger, ValidatorPrefs } from '@polkadot/types/interfaces';
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
import { DeriveStakingQuery } from '../types';
|
||||
|
||||
@@ -16,7 +16,7 @@ import { memo } from '../util';
|
||||
|
||||
type MultiResult = [Option<AccountId>, Option<ITuple<[Nominations]> | Nominations>, RewardDestination, ITuple<[ValidatorPrefs]> | ValidatorPrefs, Option<Keys>, Exposure];
|
||||
|
||||
function unwrapSessionIds (stashId: AccountId, queuedKeys: [AccountId, Keys][], nextKeys: Option<Keys>): { nextSessionIds: AccountId[]; sessionIds: AccountId[] } {
|
||||
function parseSessionIds (stashId: AccountId, queuedKeys: [AccountId, Keys][], nextKeys: Option<Keys>): { nextSessionIds: AccountId[]; sessionIds: AccountId[] } {
|
||||
const sessionIds = (queuedKeys.find(([currentId]): boolean =>
|
||||
currentId.eq(stashId)
|
||||
) || [undefined, [] as AccountId[]])[1];
|
||||
@@ -28,6 +28,31 @@ function unwrapSessionIds (stashId: AccountId, queuedKeys: [AccountId, Keys][],
|
||||
};
|
||||
}
|
||||
|
||||
function parseController (stashId: AccountId, queuedKeys: Vec<ITuple<[AccountId, Keys]>>, [controllerIdOpt, nominatorsOpt, rewardDestination, validatorPrefs, nextKeys, exposure]: MultiResult, stakingLedgerOpt: Option<StakingLedger>): DeriveStakingQuery {
|
||||
const controllerId = controllerIdOpt.unwrapOr(null);
|
||||
const nominators = nominatorsOpt.unwrapOr(null);
|
||||
|
||||
return controllerId && stakingLedgerOpt.isSome
|
||||
? {
|
||||
accountId: stashId,
|
||||
controllerId,
|
||||
exposure,
|
||||
nominators: nominators
|
||||
? Array.isArray(nominators)
|
||||
? nominators[0].targets
|
||||
: nominators.targets
|
||||
: [],
|
||||
rewardDestination,
|
||||
stakingLedger: stakingLedgerOpt.unwrapOr(undefined),
|
||||
stashId,
|
||||
validatorPrefs: Array.isArray(validatorPrefs)
|
||||
? validatorPrefs[0]
|
||||
: validatorPrefs,
|
||||
...parseSessionIds(stashId, queuedKeys, nextKeys)
|
||||
}
|
||||
: { accountId: stashId, nextSessionIds: [], sessionIds: [] };
|
||||
}
|
||||
|
||||
function retrievePrev (api: ApiInterfaceRx, stashId: AccountId): Observable<MultiResult> {
|
||||
return api.queryMulti<MultiResult>([
|
||||
[api.query.staking.bonded, stashId],
|
||||
@@ -39,64 +64,43 @@ function retrievePrev (api: ApiInterfaceRx, stashId: AccountId): Observable<Mult
|
||||
]);
|
||||
}
|
||||
|
||||
function retrieveCurr (api: ApiInterfaceRx, stashId: AccountId): Observable<MultiResult> {
|
||||
return api.derive.session.indexes().pipe(
|
||||
switchMap(({ activeEra }) =>
|
||||
api.queryMulti<MultiResult>([
|
||||
[api.query.staking.bonded, stashId],
|
||||
[api.query.staking.nominators, stashId],
|
||||
[api.query.staking.payee, stashId],
|
||||
[api.query.staking.validators, stashId],
|
||||
api.consts.session?.dedupKeyPrefix
|
||||
? [api.query.session.nextKeys, [api.consts.session.dedupKeyPrefix, stashId]]
|
||||
: [api.query.session.nextKeys, stashId],
|
||||
[api.query.staking.erasStakers, [activeEra, stashId]]
|
||||
])
|
||||
function retrieveCurr (api: ApiInterfaceRx, stashIds: AccountId[], activeEra: EraIndex): Observable<MultiResult[]> {
|
||||
return combineLatest([
|
||||
api.query.staking.bonded.multi<Option<AccountId>>(stashIds),
|
||||
api.query.staking.nominators.multi<Option<Nominations>>(stashIds),
|
||||
api.query.staking.payee.multi<RewardDestination>(stashIds),
|
||||
api.query.staking.validators.multi<ValidatorPrefs>(stashIds),
|
||||
api.consts.session?.dedupKeyPrefix
|
||||
? api.query.session.nextKeys.multi<Option<Keys>>(stashIds.map((stashId) => [api.consts.session.dedupKeyPrefix, stashId]))
|
||||
: api.query.session.nextKeys.multi<Option<Keys>>(stashIds),
|
||||
api.query.staking.erasStakers.multi<Exposure>(stashIds.map((stashId) => [activeEra, stashId]))
|
||||
]).pipe(
|
||||
map(([controllerIdOpt, nominatorsOpt, rewardDestination, validatorPrefs, nextKeys, exposure]): MultiResult[] =>
|
||||
controllerIdOpt.map((controllerIdOpt, index): MultiResult =>
|
||||
[controllerIdOpt, nominatorsOpt[index], rewardDestination[index], validatorPrefs[index], nextKeys[index], exposure[index]]
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function retrieveController (api: ApiInterfaceRx, stashId: AccountId, queuedKeys: Vec<ITuple<[AccountId, Keys]>>, [controllerIdOpt, nominatorsOpt, rewardDestination, validatorPrefs, nextKeys, exposure]: MultiResult): Observable<DeriveStakingQuery> {
|
||||
const controllerId = controllerIdOpt.unwrapOr(null);
|
||||
const nominators = nominatorsOpt.unwrapOr(null);
|
||||
function retrieveControllers (api: ApiInterfaceRx, optControllerIds: Option<AccountId>[]): Observable<Option<StakingLedger>[]> {
|
||||
const ids = optControllerIds.filter((opt) => opt.isSome).map((opt) => opt.unwrap());
|
||||
|
||||
return controllerId
|
||||
? api.query.staking.ledger(controllerId).pipe(
|
||||
map((stakingLedgerOpt): DeriveStakingQuery => ({
|
||||
accountId: stashId,
|
||||
controllerId,
|
||||
exposure,
|
||||
nominators: nominators
|
||||
? Array.isArray(nominators)
|
||||
? nominators[0].targets
|
||||
: nominators.targets
|
||||
: [],
|
||||
rewardDestination,
|
||||
stakingLedger: stakingLedgerOpt.unwrapOr(undefined),
|
||||
stashId,
|
||||
validatorPrefs: Array.isArray(validatorPrefs)
|
||||
? validatorPrefs[0]
|
||||
: validatorPrefs,
|
||||
...unwrapSessionIds(stashId, queuedKeys, nextKeys)
|
||||
}))
|
||||
)
|
||||
: of({ accountId: stashId, nextSessionIds: [], sessionIds: [] });
|
||||
}
|
||||
if (!ids.length) {
|
||||
return of(optControllerIds.map(() => api.registry.createType('Option<StakingLedger>')));
|
||||
}
|
||||
|
||||
export function queryWithQueued (api: ApiInterfaceRx): (accountId: Uint8Array | string, queuedKeys: Vec<ITuple<[AccountId, Keys]>>) => Observable<DeriveStakingQuery> {
|
||||
return memo((accountId: Uint8Array | string, queuedKeys: Vec<ITuple<[AccountId, Keys]>>): Observable<DeriveStakingQuery> => {
|
||||
const stashId = api.registry.createType('AccountId', accountId);
|
||||
return api.query.staking.ledger.multi<Option<StakingLedger>>(ids).pipe(
|
||||
map((optLedgers): Option<StakingLedger>[] => {
|
||||
let offset = -1;
|
||||
|
||||
return (
|
||||
isFunction(api.query.staking.erasStakers)
|
||||
? retrieveCurr(api, stashId)
|
||||
: retrievePrev(api, stashId)
|
||||
).pipe(
|
||||
switchMap((result): Observable<DeriveStakingQuery> =>
|
||||
retrieveController(api, stashId, queuedKeys, result)
|
||||
)
|
||||
);
|
||||
});
|
||||
return optControllerIds.map((opt): Option<StakingLedger> =>
|
||||
opt.isSome
|
||||
? optLedgers[++offset]
|
||||
: api.registry.createType('Option<StakingLedger>')
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -104,8 +108,8 @@ export function queryWithQueued (api: ApiInterfaceRx): (accountId: Uint8Array |
|
||||
*/
|
||||
export function query (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable<DeriveStakingQuery> {
|
||||
return memo((accountId: Uint8Array | string): Observable<DeriveStakingQuery> =>
|
||||
api.query.session.queuedKeys<Vec<ITuple<[AccountId, Keys]>>>().pipe(
|
||||
switchMap((queuedKeys) => api.derive.staking.queryWithQueued(accountId, queuedKeys))
|
||||
api.derive.staking.queryMulti([accountId]).pipe(
|
||||
map(([first]) => first)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -113,10 +117,27 @@ export function query (api: ApiInterfaceRx): (accountId: Uint8Array | string) =>
|
||||
export function queryMulti (api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[]) => Observable<DeriveStakingQuery[]> {
|
||||
return memo((accountIds: (Uint8Array | string)[]): Observable<DeriveStakingQuery[]> =>
|
||||
accountIds.length
|
||||
? api.query.session.queuedKeys<Vec<ITuple<[AccountId, Keys]>>>().pipe(
|
||||
switchMap((queuedKeys) => combineLatest(
|
||||
accountIds.map((acc) => api.derive.staking.queryWithQueued(acc, queuedKeys))
|
||||
))
|
||||
? combineLatest([
|
||||
api.query.session.queuedKeys<Vec<ITuple<[AccountId, Keys]>>>(),
|
||||
api.derive.session.indexes()
|
||||
]).pipe(
|
||||
switchMap(([queuedKeys, { activeEra }]): Observable<DeriveStakingQuery[]> => {
|
||||
const stashIds = accountIds.map((accountId) => api.registry.createType('AccountId', accountId));
|
||||
|
||||
return (
|
||||
isFunction(api.query.staking.erasStakers)
|
||||
? retrieveCurr(api, stashIds, activeEra)
|
||||
: combineLatest(stashIds.map((stashId) => retrievePrev(api, stashId)))
|
||||
).pipe(
|
||||
switchMap((results): Observable<DeriveStakingQuery[]> =>
|
||||
retrieveControllers(api, results.map(([optController]) => optController)).pipe(
|
||||
map((stakingLedgerOpts) =>
|
||||
stashIds.map((stashId, index) => parseController(stashId, queuedKeys, results[index], stakingLedgerOpts[index]))
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
})
|
||||
)
|
||||
: of([])
|
||||
);
|
||||
|
||||
@@ -52,7 +52,7 @@ function parseRewards (api: ApiInterfaceRx, stashId: AccountId, [, erasPoints, e
|
||||
: ZERO;
|
||||
}
|
||||
|
||||
value = avail.sub(valCut).mul(staked).div(expTotal).add(validatorId === stakerId ? valCut : ZERO);
|
||||
value = avail.sub(valCut).imul(staked).div(expTotal).iadd(validatorId === stakerId ? valCut : ZERO);
|
||||
}
|
||||
|
||||
validators[validatorId] = {
|
||||
@@ -199,14 +199,18 @@ export function stakerRewards (api: ApiInterfaceRx): (accountId: Uint8Array | st
|
||||
);
|
||||
}
|
||||
|
||||
export function stakerRewardsMulti (api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], withActive?: boolean) => Observable<DeriveStakerReward[][]> {
|
||||
return memo((accountIds: (Uint8Array | string)[], withActive = false): Observable<DeriveStakerReward[][]> =>
|
||||
accountIds.length
|
||||
? api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) =>
|
||||
combineLatest(accountIds.map((acc) => api.derive.staking._stakerRewards(acc, eras, withActive)))
|
||||
)
|
||||
)
|
||||
export function stakerRewardsMultiEras (api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[]) => Observable<DeriveStakerReward[][]> {
|
||||
return memo((accountIds: (Uint8Array | string)[], eras: EraIndex[]): Observable<DeriveStakerReward[][]> =>
|
||||
accountIds.length && eras.length
|
||||
? combineLatest(accountIds.map((acc) => api.derive.staking._stakerRewards(acc, eras, false)))
|
||||
: of([])
|
||||
);
|
||||
}
|
||||
|
||||
export function stakerRewardsMulti (api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], withActive?: boolean) => Observable<DeriveStakerReward[][]> {
|
||||
return memo((accountIds: (Uint8Array | string)[], withActive = false): Observable<DeriveStakerReward[][]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras) => api.derive.staking.stakerRewardsMultiEras(accountIds, eras))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -96,6 +96,11 @@ export interface DeriveStakingElected {
|
||||
info: DeriveStakingQuery[];
|
||||
}
|
||||
|
||||
export interface DeriveStakingWaiting {
|
||||
info: DeriveStakingQuery[];
|
||||
waiting: AccountId[];
|
||||
}
|
||||
|
||||
export interface DeriveStakingValidators {
|
||||
nextElected: AccountId[];
|
||||
validators: AccountId[];
|
||||
|
||||
@@ -18,9 +18,7 @@ export function nextElected (api: ApiInterfaceRx): () => Observable<AccountId[]>
|
||||
// only populate for next era in the last session, so track both here - entries are not
|
||||
// subscriptions, so we need a trigger - currentIndex acts as that trigger to refresh
|
||||
switchMap(({ currentEra }) => api.query.staking.erasStakers.keys(currentEra)),
|
||||
map((keys): AccountId[] =>
|
||||
keys.map((key): AccountId => key.args[1] as AccountId)
|
||||
)
|
||||
map((keys) => keys.map((key) => key.args[1] as AccountId))
|
||||
)
|
||||
: api.query.staking.currentElected<AccountId[]>()
|
||||
);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright 2017-2020 @polkadot/api-derive 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 { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { DeriveStakingWaiting } from '../types';
|
||||
|
||||
import { Observable, combineLatest } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function waitingInfo (api: ApiInterfaceRx): () => Observable<DeriveStakingWaiting> {
|
||||
return memo((): Observable<DeriveStakingWaiting> =>
|
||||
combineLatest([
|
||||
api.derive.staking.validators(),
|
||||
api.derive.staking.stashes()
|
||||
]).pipe(
|
||||
switchMap(([{ nextElected }, stashes]): Observable<DeriveStakingWaiting> => {
|
||||
const elected = nextElected.map((a) => a.toString());
|
||||
const waiting = stashes.filter((v) => !elected.includes(v.toString()));
|
||||
|
||||
return api.derive.staking.queryMulti(waiting).pipe(
|
||||
map((info): DeriveStakingWaiting => ({
|
||||
info,
|
||||
waiting
|
||||
}))
|
||||
);
|
||||
})
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -20,7 +20,7 @@ interface Result {
|
||||
|
||||
function latestNonce (api: ApiInterfaceRx, address: string): Observable<Index> {
|
||||
return api.derive.balances.account(address).pipe(
|
||||
map(({ accountNonce }): Index => accountNonce)
|
||||
map(({ accountNonce }) => accountNonce)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ function signingHeader (api: ApiInterfaceRx): Observable<Header> {
|
||||
switchMap((hash) => api.rpc.chain.getHeader(hash))
|
||||
)
|
||||
]).pipe(
|
||||
map(([current, finalized]): Header =>
|
||||
map(([current, finalized]) =>
|
||||
// determine the hash to use, current when lag > max, else finalized
|
||||
current.number.unwrap().sub(finalized.number.unwrap()).gt(MAX_FINALITY_LAG)
|
||||
? current
|
||||
@@ -57,7 +57,7 @@ export function signingInfo (api: ApiInterfaceRx): (address: string, nonce?: Any
|
||||
header,
|
||||
mortalLength: MORTAL_PERIOD
|
||||
.div(api.consts.babe?.expectedBlockTime || api.consts.timestamp?.minimumPeriod.muln(2) || FALLBACK_PERIOD)
|
||||
.add(MAX_FINALITY_LAG)
|
||||
.iadd(MAX_FINALITY_LAG)
|
||||
.toNumber(),
|
||||
nonce
|
||||
}))
|
||||
|
||||
@@ -31,6 +31,8 @@ export interface DeriveBalancesAll extends DeriveBalancesAccount {
|
||||
availableBalance: Balance;
|
||||
votingBalance: Balance;
|
||||
vestedBalance: Balance;
|
||||
vestedClaimable: Balance;
|
||||
vestingLocked: Balance;
|
||||
vestingTotal: Balance;
|
||||
}
|
||||
|
||||
|
||||
@@ -3,15 +3,11 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.v
|
||||
|
||||
import createMemo from 'memoizee';
|
||||
import { Observable, Observer } from 'rxjs';
|
||||
import { Observable, Observer, TeardownLogic } from 'rxjs';
|
||||
import { drr } from '@polkadot/rpc-core/rxjs';
|
||||
|
||||
type ObsFn <T> = (...params: any[]) => Observable<T>;
|
||||
|
||||
// Normalize via JSON.stringify, allow e.g. AccountId -> ss58
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
const normalizer = JSON.stringify;
|
||||
|
||||
// Wraps a derive, doing 2 things to optimize calls -
|
||||
// 1. creates a memo of the inner fn -> Observable, removing when unsubscribed
|
||||
// 2. wraps the observable in a drr() (which includes an unsub delay)
|
||||
@@ -19,15 +15,19 @@ const normalizer = JSON.stringify;
|
||||
export function memo <T> (inner: ObsFn<T>): ObsFn<T> {
|
||||
const cached = createMemo(
|
||||
(...params: any[]): Observable<T> =>
|
||||
new Observable((observer: Observer<T>): VoidCallback => {
|
||||
const sub = inner(...params).subscribe(observer);
|
||||
new Observable((observer: Observer<T>): TeardownLogic => {
|
||||
const subscription = inner(...params).subscribe(observer);
|
||||
|
||||
return (): void => {
|
||||
cached.delete(...params);
|
||||
sub.unsubscribe();
|
||||
subscription.unsubscribe();
|
||||
};
|
||||
}).pipe(drr()),
|
||||
{ normalizer }
|
||||
{
|
||||
// Normalize via JSON.stringify, allow e.g. AccountId -> ss58
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
normalizer: JSON.stringify
|
||||
}
|
||||
);
|
||||
|
||||
return cached;
|
||||
|
||||
@@ -97,7 +97,7 @@ Some of the users of the API (let us know if you are missing from the list), inc
|
||||
- [Polkawallet.io](https://polkawallet.io) and [Polkawallet (Github)](https://github.com/polkawallet-io/polkawallet-RN/) A mobile wallet for the Polkadot network to manage funds and make transactions, available on both Androind and iOS
|
||||
- [PolkaStats.io](https://polkastats.io), [PolkaStats frontend GitHub repository](https://github.com/Colm3na/polkastats-v2) and [PolkaStats backend GitHub repository](https://github.com/Colm3na/polkastats-backend-v2) Polkadot network statistics (currently Kusama and Alexander). Shows network information and staking details from validators and intentions.
|
||||
- [Polkadot API Server (GitHub)](https://github.com/SimplyVC/polkadot_api_server) A lightweight server for querying Polkadot nodes from any language, built primarily as a backend for [PANIC for Polkadot (GitHub)](https://github.com/SimplyVC/panic_polkadot/), a validator monitoring and alerting tool.
|
||||
|
||||
- [Identity Registrar #1 from Chevdor on Westend, Kusama and Polkadot](https://www.chevdor.com/tags/registrar/)
|
||||
## Classes
|
||||
|
||||
[Classes](SUMMARY.md)
|
||||
|
||||
+13
-13
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api",
|
||||
"version": "1.19.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.2",
|
||||
"@polkadot/api-derive": "1.19.1",
|
||||
"@polkadot/keyring": "^2.14.1",
|
||||
"@polkadot/metadata": "1.19.1",
|
||||
"@polkadot/rpc-core": "1.19.1",
|
||||
"@polkadot/rpc-provider": "1.19.1",
|
||||
"@polkadot/types": "1.19.1",
|
||||
"@polkadot/types-known": "1.19.1",
|
||||
"@polkadot/util": "^2.14.1",
|
||||
"@polkadot/util-crypto": "^2.14.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.5.5"
|
||||
"rxjs": "^6.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.14.1"
|
||||
"@polkadot/keyring": "^3.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
|
||||
import { Codec } from '@polkadot/types/types';
|
||||
import { Vec } from '@polkadot/types/codec';
|
||||
import { u32, u64 } from '@polkadot/types/primitive';
|
||||
import { Balance, BalanceOf, BlockNumber, LockIdentifier, ModuleId, Moment, Percent, Permill, RuntimeDbWeight, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import { u16, u32, u64 } from '@polkadot/types/primitive';
|
||||
import { Balance, BalanceOf, BlockNumber, LockIdentifier, ModuleId, Moment, Perbill, Percent, Permill, RuntimeDbWeight, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import { SessionIndex } from '@polkadot/types/interfaces/session';
|
||||
import { EraIndex } from '@polkadot/types/interfaces/staking';
|
||||
import { WeightToFeeCoefficient } from '@polkadot/types/interfaces/support';
|
||||
@@ -176,6 +176,40 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
|
||||
**/
|
||||
subAccountDeposit: AugmentedConst<BalanceOf>;
|
||||
};
|
||||
proxy: {
|
||||
[index: string]: AugmentedConst<object & Codec>;
|
||||
/**
|
||||
* The maximum amount of proxies allowed for a single account.
|
||||
**/
|
||||
maxProxies: AugmentedConst<u16>;
|
||||
/**
|
||||
* The base amount of currency needed to reserve for creating a proxy.
|
||||
**/
|
||||
proxyDepositBase: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The amount of currency needed per proxy added.
|
||||
**/
|
||||
proxyDepositFactor: AugmentedConst<BalanceOf>;
|
||||
};
|
||||
recovery: {
|
||||
[index: string]: AugmentedConst<object & Codec>;
|
||||
/**
|
||||
* The base amount of currency needed to reserve for creating a recovery configuration.
|
||||
**/
|
||||
configDepositBase: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The amount of currency needed per additional user when creating a recovery configuration.
|
||||
**/
|
||||
friendDepositFactor: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The maximum amount of friends allowed in a recovery configuration.
|
||||
**/
|
||||
maxFriends: AugmentedConst<u16>;
|
||||
/**
|
||||
* The base amount of currency needed to reserve for starting a recovery.
|
||||
**/
|
||||
recoveryDeposit: AugmentedConst<BalanceOf>;
|
||||
};
|
||||
society: {
|
||||
[index: string]: AugmentedConst<object & Codec>;
|
||||
/**
|
||||
@@ -215,10 +249,45 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
|
||||
* Number of eras that staked funds must remain bonded for.
|
||||
**/
|
||||
bondingDuration: AugmentedConst<EraIndex>;
|
||||
/**
|
||||
* The number of blocks before the end of the era from which election submissions are allowed.
|
||||
*
|
||||
* Setting this to zero will disable the offchain compute and only on-chain seq-phragmen will
|
||||
* be used.
|
||||
*
|
||||
* This is bounded by being within the last session. Hence, setting it to a value more than the
|
||||
* length of a session will be pointless.
|
||||
**/
|
||||
electionLookahead: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* Maximum number of balancing iterations to run in the offchain submission.
|
||||
*
|
||||
* If set to 0, balance_solution will not be executed at all.
|
||||
**/
|
||||
maxIterations: AugmentedConst<u32>;
|
||||
/**
|
||||
* The maximum number of nominators rewarded for each validator.
|
||||
*
|
||||
* For each validator only the `$MaxNominatorRewardedPerValidator` biggest stakers can claim
|
||||
* their reward. This used to limit the i/o cost for the nominator payout.
|
||||
**/
|
||||
maxNominatorRewardedPerValidator: AugmentedConst<u32>;
|
||||
/**
|
||||
* The threshold of improvement that should be provided for a new solution to be accepted.
|
||||
**/
|
||||
minSolutionScoreBump: AugmentedConst<Perbill>;
|
||||
/**
|
||||
* Number of sessions per era.
|
||||
**/
|
||||
sessionsPerEra: AugmentedConst<SessionIndex>;
|
||||
/**
|
||||
* Number of eras that slashes are deferred by, after computation.
|
||||
*
|
||||
* This should be less than the bonding duration.
|
||||
* Set to 0 if slashes should be applied immediately, without opportunity for
|
||||
* intervention.
|
||||
**/
|
||||
slashDeferDuration: AugmentedConst<EraIndex>;
|
||||
};
|
||||
system: {
|
||||
[index: string]: AugmentedConst<object & Codec>;
|
||||
|
||||
@@ -6,22 +6,22 @@ import { Option, U8aFixed, Vec } from '@polkadot/types/codec';
|
||||
import { Bytes, Data, bool, u32, u64 } from '@polkadot/types/primitive';
|
||||
import { UncleEntryItem } from '@polkadot/types/interfaces/authorship';
|
||||
import { BabeAuthorityWeight, MaybeRandomness, NextConfigDescriptor, Randomness } from '@polkadot/types/interfaces/babe';
|
||||
import { AccountData, BalanceLock, ReleasesBalances } from '@polkadot/types/interfaces/balances';
|
||||
import { AccountData, BalanceLock } from '@polkadot/types/interfaces/balances';
|
||||
import { ProposalIndex, Votes } from '@polkadot/types/interfaces/collective';
|
||||
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
|
||||
import { CodeHash, ContractInfo, PrefabWasmModule, Schedule } from '@polkadot/types/interfaces/contracts';
|
||||
import { PreimageStatus, PropIndex, Proposal, ReferendumIndex, ReferendumInfo, ReleasesDemocracy, Voting } from '@polkadot/types/interfaces/democracy';
|
||||
import { PreimageStatus, PropIndex, Proposal, ReferendumIndex, ReferendumInfo, Voting } from '@polkadot/types/interfaces/democracy';
|
||||
import { VoteThreshold } from '@polkadot/types/interfaces/elections';
|
||||
import { SetId, StoredPendingChange, StoredState } from '@polkadot/types/interfaces/grandpa';
|
||||
import { RegistrarInfo, Registration } from '@polkadot/types/interfaces/identity';
|
||||
import { AuthIndex } from '@polkadot/types/interfaces/imOnline';
|
||||
import { DeferredOffenceOf, Kind, OffenceDetails, OpaqueTimeSlot, ReportIdOf } from '@polkadot/types/interfaces/offences';
|
||||
import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
|
||||
import { AccountId, AccountIndex, Balance, BalanceOf, BlockNumber, ExtrinsicsWeight, Hash, KeyTypeId, Moment, Perbill, ProxyType, ValidatorId } from '@polkadot/types/interfaces/runtime';
|
||||
import { AccountId, AccountIndex, Balance, BalanceOf, BlockNumber, ExtrinsicsWeight, Hash, KeyTypeId, Moment, OpaqueCall, Perbill, ProxyType, Releases, ValidatorId } from '@polkadot/types/interfaces/runtime';
|
||||
import { Scheduled, TaskAddress } from '@polkadot/types/interfaces/scheduler';
|
||||
import { Keys, SessionIndex } from '@polkadot/types/interfaces/session';
|
||||
import { Bid, BidKind, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
|
||||
import { ActiveEraInfo, ElectionResult, ElectionScore, ElectionStatus, EraIndex, EraRewardPoints, Exposure, Forcing, Nominations, ReleasesStaking, RewardDestination, SlashingSpans, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
|
||||
import { ActiveEraInfo, ElectionResult, ElectionScore, ElectionStatus, EraIndex, EraRewardPoints, Exposure, Forcing, Nominations, RewardDestination, SlashingSpans, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
|
||||
import { AccountInfo, DigestOf, EventIndex, EventRecord, LastRuntimeUpgradeInfo, Phase } from '@polkadot/types/interfaces/system';
|
||||
import { OpenTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
|
||||
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
|
||||
@@ -134,7 +134,7 @@ declare module '@polkadot/api/types/storage' {
|
||||
*
|
||||
* This is set to v2.0.0 for new networks.
|
||||
**/
|
||||
storageVersion: AugmentedQuery<ApiType, () => Observable<ReleasesBalances>> & QueryableStorageEntry<ApiType>;
|
||||
storageVersion: AugmentedQuery<ApiType, () => Observable<Releases>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The total units issued in the system.
|
||||
**/
|
||||
@@ -262,7 +262,7 @@ declare module '@polkadot/api/types/storage' {
|
||||
*
|
||||
* New networks start with last version.
|
||||
**/
|
||||
storageVersion: AugmentedQuery<ApiType, () => Observable<Option<ReleasesDemocracy>>> & QueryableStorageEntry<ApiType>;
|
||||
storageVersion: AugmentedQuery<ApiType, () => Observable<Option<Releases>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* All votes for a particular voter. We store the balance for the number of votes that we
|
||||
* have recorded. The second item is the total amount of delegations, that will be added.
|
||||
@@ -392,6 +392,7 @@ declare module '@polkadot/api/types/storage' {
|
||||
};
|
||||
multisig: {
|
||||
[index: string]: QueryableStorageEntry<ApiType>;
|
||||
calls: AugmentedQuery<ApiType, (arg: U8aFixed | string | Uint8Array) => Observable<Option<ITuple<[OpaqueCall, AccountId, BalanceOf]>>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The set of open multisig operations.
|
||||
**/
|
||||
@@ -469,6 +470,12 @@ declare module '@polkadot/api/types/storage' {
|
||||
* Lookup from identity to the block number and index of the task.
|
||||
**/
|
||||
lookup: AugmentedQuery<ApiType, (arg: Bytes | string | Uint8Array) => Observable<Option<TaskAddress>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* Storage version of the pallet.
|
||||
*
|
||||
* New networks start with last version.
|
||||
**/
|
||||
storageVersion: AugmentedQuery<ApiType, () => Observable<Releases>> & QueryableStorageEntry<ApiType>;
|
||||
};
|
||||
session: {
|
||||
[index: string]: QueryableStorageEntry<ApiType>;
|
||||
@@ -751,7 +758,7 @@ declare module '@polkadot/api/types/storage' {
|
||||
*
|
||||
* This is set to v3.0.0 for new networks.
|
||||
**/
|
||||
storageVersion: AugmentedQuery<ApiType, () => Observable<ReleasesStaking>> & QueryableStorageEntry<ApiType>;
|
||||
storageVersion: AugmentedQuery<ApiType, () => Observable<Releases>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* All unapplied slashes that are queued for later.
|
||||
**/
|
||||
@@ -902,6 +909,7 @@ declare module '@polkadot/api/types/storage' {
|
||||
transactionPayment: {
|
||||
[index: string]: QueryableStorageEntry<ApiType>;
|
||||
nextFeeMultiplier: AugmentedQuery<ApiType, () => Observable<Multiplier>> & QueryableStorageEntry<ApiType>;
|
||||
storageVersion: AugmentedQuery<ApiType, () => Observable<Releases>> & QueryableStorageEntry<ApiType>;
|
||||
};
|
||||
treasury: {
|
||||
[index: string]: QueryableStorageEntry<ApiType>;
|
||||
|
||||
@@ -19,16 +19,10 @@ import { RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment';
|
||||
import { RpcMethods } from '@polkadot/types/interfaces/rpc';
|
||||
import { AccountId, BlockNumber, H256, Hash, Header, Index, Justification, KeyValue, SignedBlock, StorageData } from '@polkadot/types/interfaces/runtime';
|
||||
import { ReadProof, RuntimeVersion } from '@polkadot/types/interfaces/state';
|
||||
import { ChainProperties, ChainType, Health, NetworkState, NodeRole, PeerInfo } from '@polkadot/types/interfaces/system';
|
||||
import { ApplyExtrinsicResult, ChainProperties, ChainType, Health, NetworkState, NodeRole, PeerInfo } from '@polkadot/types/interfaces/system';
|
||||
|
||||
declare module '@polkadot/rpc-core/types.jsonrpc' {
|
||||
export interface RpcInterface {
|
||||
account: {
|
||||
/**
|
||||
* Retrieves the next accountIndex as available on the node
|
||||
**/
|
||||
nextIndex: AugmentedRpc<(accountId: AccountId | string | Uint8Array) => Observable<Index>>;
|
||||
};
|
||||
author: {
|
||||
/**
|
||||
* Returns true if the keystore has private keys for the given public key and key type.
|
||||
@@ -244,6 +238,10 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
|
||||
subscribeStorage: AugmentedRpc<<T = Codec[]>(keys?: Vec<StorageKey> | (StorageKey | string | Uint8Array | any)[]) => Observable<T>>;
|
||||
};
|
||||
system: {
|
||||
/**
|
||||
* Retrieves the next accountIndex as available on the node
|
||||
**/
|
||||
accountNextIndex: AugmentedRpc<(accountId: AccountId | string | Uint8Array) => Observable<Index>>;
|
||||
/**
|
||||
* Adds a reserved peer
|
||||
**/
|
||||
@@ -256,6 +254,10 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
|
||||
* Retrieves the chain type
|
||||
**/
|
||||
chainType: AugmentedRpc<() => Observable<ChainType>>;
|
||||
/**
|
||||
* Dry run an extrinsic at a given block
|
||||
**/
|
||||
dryRun: AugmentedRpc<(extrinsic: Bytes | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable<ApplyExtrinsicResult>>;
|
||||
/**
|
||||
* Return health status of the node
|
||||
**/
|
||||
|
||||
+200
-41
@@ -4,15 +4,16 @@
|
||||
import { AnyNumber, ITuple } from '@polkadot/types/types';
|
||||
import { Compact, Option, U8aFixed, Vec } from '@polkadot/types/codec';
|
||||
import { Bytes, Data, bool, u16, u32, u64 } from '@polkadot/types/primitive';
|
||||
import { BabeEquivocationProof } from '@polkadot/types/interfaces/babe';
|
||||
import { MemberCount, ProposalIndex } from '@polkadot/types/interfaces/collective';
|
||||
import { CodeHash, Gas, Schedule } from '@polkadot/types/interfaces/contracts';
|
||||
import { AccountVote, Conviction, PropIndex, Proposal, ReferendumIndex } from '@polkadot/types/interfaces/democracy';
|
||||
import { DefunctVoter, Renouncing } from '@polkadot/types/interfaces/elections';
|
||||
import { Extrinsic, Signature } from '@polkadot/types/interfaces/extrinsics';
|
||||
import { EquivocationProof, KeyOwnerProof } from '@polkadot/types/interfaces/grandpa';
|
||||
import { GrandpaEquivocationProof, KeyOwnerProof } from '@polkadot/types/interfaces/grandpa';
|
||||
import { IdentityFields, IdentityInfo, IdentityJudgement, RegistrarIndex } from '@polkadot/types/interfaces/identity';
|
||||
import { Heartbeat } from '@polkadot/types/interfaces/imOnline';
|
||||
import { AccountId, AccountIndex, Address, Balance, BalanceOf, BlockNumber, Call, ChangesTrieConfiguration, Hash, Header, KeyValue, LookupSource, Moment, Perbill, ProxyType, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import { AccountId, AccountIndex, Address, Balance, BalanceOf, BlockNumber, Call, ChangesTrieConfiguration, Hash, Header, KeyValue, LookupSource, Moment, OpaqueCall, Perbill, Percent, ProxyType, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import { Period, Priority } from '@polkadot/types/interfaces/scheduler';
|
||||
import { Keys } from '@polkadot/types/interfaces/session';
|
||||
import { SocietyJudgement } from '@polkadot/types/interfaces/society';
|
||||
@@ -31,6 +32,27 @@ declare module '@polkadot/api/types/submittable' {
|
||||
**/
|
||||
setUncles: AugmentedSubmittable<(newUncles: Vec<Header> | (Header | { parentHash?: any; number?: any; stateRoot?: any; extrinsicsRoot?: any; digest?: any } | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
babe: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
* Report authority equivocation/misbehavior. This method will verify
|
||||
* the equivocation proof and validate the given key ownership proof
|
||||
* against the extracted offender. If both are valid, the offence will
|
||||
* be reported.
|
||||
**/
|
||||
reportEquivocation: AugmentedSubmittable<(equivocationProof: BabeEquivocationProof | { offender?: any; slotNumber?: any; firstHeader?: any; secondHeader?: any } | string | Uint8Array, keyOwnerProof: KeyOwnerProof | { session?: any; trieNodes?: any; validatorCount?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Report authority equivocation/misbehavior. This method will verify
|
||||
* the equivocation proof and validate the given key ownership proof
|
||||
* against the extracted offender. If both are valid, the offence will
|
||||
* be reported.
|
||||
* This extrinsic must be called unsigned and it is expected that only
|
||||
* block authors will call it (validated in `ValidateUnsigned`), as such
|
||||
* if the block author is defined it will be defined as the equivocation
|
||||
* reporter.
|
||||
**/
|
||||
reportEquivocationUnsigned: AugmentedSubmittable<(equivocationProof: BabeEquivocationProof | { offender?: any; slotNumber?: any; firstHeader?: any; secondHeader?: any } | string | Uint8Array, keyOwnerProof: KeyOwnerProof | { session?: any; trieNodes?: any; validatorCount?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
balances: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
@@ -868,24 +890,42 @@ 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
|
||||
* against the extracted offender. If both are valid, the offence
|
||||
* will be reported.
|
||||
**/
|
||||
reportEquivocation: AugmentedSubmittable<(equivocationProof: GrandpaEquivocationProof | { setId?: any; equivocation?: any } | string | Uint8Array, keyOwnerProof: KeyOwnerProof | { session?: any; trieNodes?: any; validatorCount?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Report voter equivocation/misbehavior. This method will verify the
|
||||
* equivocation proof and validate the given key ownership proof
|
||||
* against the extracted offender. If both are valid, the offence
|
||||
* will be reported.
|
||||
*
|
||||
* Since the weight of the extrinsic is 0, in order to avoid DoS by
|
||||
* submission of invalid equivocation reports, a mandatory pre-validation of
|
||||
* the extrinsic is implemented in a `SignedExtension`.
|
||||
* This extrinsic must be called unsigned and it is expected that only
|
||||
* block authors will call it (validated in `ValidateUnsigned`), as such
|
||||
* if the block author is defined it will be defined as the equivocation
|
||||
* reporter.
|
||||
**/
|
||||
reportEquivocation: AugmentedSubmittable<(equivocationProof: EquivocationProof | { setId?: any; equivocation?: any } | string | Uint8Array, keyOwnerProof: KeyOwnerProof | { session?: any; trieNodes?: any; validatorCount?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
reportEquivocationUnsigned: AugmentedSubmittable<(equivocationProof: GrandpaEquivocationProof | { setId?: any; equivocation?: any } | string | Uint8Array, keyOwnerProof: KeyOwnerProof | { session?: any; trieNodes?: any; validatorCount?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
identity: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
* Add a registrar to the system.
|
||||
*
|
||||
* The dispatch origin for this call must be `RegistrarOrigin` or `Root`.
|
||||
* The dispatch origin for this call must be `T::RegistrarOrigin`.
|
||||
*
|
||||
* - `account`: the account of the registrar.
|
||||
*
|
||||
@@ -898,6 +938,16 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
addRegistrar: AugmentedSubmittable<(account: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Add the given account to the sender's subs.
|
||||
*
|
||||
* Payment: Balance reserved by a previous `set_subs` call for one sub will be repatriated
|
||||
* to the sender.
|
||||
*
|
||||
* The dispatch origin for this call must be _Signed_ and the sender must have a registered
|
||||
* sub identity of `sub`.
|
||||
**/
|
||||
addSub: AugmentedSubmittable<(sub: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, data: Data | { None: any } | { Raw: any } | { BlakeTwo256: any } | { Sha256: any } | { Keccak256: any } | { ShaThree256: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Cancel a previous request.
|
||||
*
|
||||
@@ -946,7 +996,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* `Slash`. Verification request deposits are not returned; they should be cancelled
|
||||
* manually using `cancel_request`.
|
||||
*
|
||||
* The dispatch origin for this call must be _Root_ or match `T::ForceOrigin`.
|
||||
* The dispatch origin for this call must match `T::ForceOrigin`.
|
||||
*
|
||||
* - `target`: the account whose identity the judgement is upon. This must be an account
|
||||
* with a registered identity.
|
||||
@@ -983,6 +1033,36 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
provideJudgement: AugmentedSubmittable<(regIndex: Compact<RegistrarIndex> | AnyNumber | Uint8Array, target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, judgement: IdentityJudgement | { Unknown: any } | { FeePaid: any } | { Reasonable: any } | { KnownGood: any } | { OutOfDate: any } | { LowQuality: any } | { Erroneous: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Remove the sender as a sub-account.
|
||||
*
|
||||
* Payment: Balance reserved by a previous `set_subs` call for one sub will be repatriated
|
||||
* to the sender (*not* the original depositor).
|
||||
*
|
||||
* The dispatch origin for this call must be _Signed_ and the sender must have a registered
|
||||
* super-identity.
|
||||
*
|
||||
* NOTE: This should not normally be used, but is provided in the case that the non-
|
||||
* controller of an account is maliciously registered as a sub-account.
|
||||
**/
|
||||
quitSub: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Remove the given account from the sender's subs.
|
||||
*
|
||||
* Payment: Balance reserved by a previous `set_subs` call for one sub will be repatriated
|
||||
* to the sender.
|
||||
*
|
||||
* The dispatch origin for this call must be _Signed_ and the sender must have a registered
|
||||
* sub identity of `sub`.
|
||||
**/
|
||||
removeSub: AugmentedSubmittable<(sub: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Alter the associated name of the given sub-account.
|
||||
*
|
||||
* The dispatch origin for this call must be _Signed_ and the sender must have a registered
|
||||
* sub identity of `sub`.
|
||||
**/
|
||||
renameSub: AugmentedSubmittable<(sub: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, data: Data | { None: any } | { Raw: any } | { BlakeTwo256: any } | { Sha256: any } | { Keccak256: any } | { ShaThree256: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Request a judgement from a registrar.
|
||||
*
|
||||
@@ -1280,7 +1360,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Write: Multisig Storage, [Caller Account]
|
||||
* # </weight>
|
||||
**/
|
||||
approveAsMulti: AugmentedSubmittable<(threshold: u16 | AnyNumber | Uint8Array, otherSignatories: Vec<AccountId> | (AccountId | string | Uint8Array)[], maybeTimepoint: Option<Timepoint> | null | object | string | Uint8Array, callHash: U8aFixed | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
approveAsMulti: AugmentedSubmittable<(threshold: u16 | AnyNumber | Uint8Array, otherSignatories: Vec<AccountId> | (AccountId | string | Uint8Array)[], maybeTimepoint: Option<Timepoint> | null | object | string | Uint8Array, callHash: U8aFixed | string | Uint8Array, maxWeight: Weight | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Register approval for a dispatch to be made from a deterministic composite account if
|
||||
* approved by a total of `threshold - 1` of `other_signatories`.
|
||||
@@ -1324,16 +1404,37 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* `DepositBase + threshold * DepositFactor`.
|
||||
* -------------------------------
|
||||
* - Base Weight:
|
||||
* - Create: 46.55 + 0.089 * S µs
|
||||
* - Approve: 34.03 + .112 * S µs
|
||||
* - Complete: 40.36 + .225 * S µs
|
||||
* - Create: 41.89 + 0.118 * S + .002 * Z µs
|
||||
* - Create w/ Store: 53.57 + 0.119 * S + .003 * Z µs
|
||||
* - Approve: 31.39 + 0.136 * S + .002 * Z µs
|
||||
* - Complete: 39.94 + 0.26 * S + .002 * Z µs
|
||||
* - DB Weight:
|
||||
* - Reads: Multisig Storage, [Caller Account]
|
||||
* - Writes: Multisig Storage, [Caller Account]
|
||||
* - Reads: Multisig Storage, [Caller Account], Calls (if `store_call`)
|
||||
* - Writes: Multisig Storage, [Caller Account], Calls (if `store_call`)
|
||||
* - Plus Call Weight
|
||||
* # </weight>
|
||||
**/
|
||||
asMulti: AugmentedSubmittable<(threshold: u16 | AnyNumber | Uint8Array, otherSignatories: Vec<AccountId> | (AccountId | string | Uint8Array)[], maybeTimepoint: Option<Timepoint> | null | object | string | Uint8Array, call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
asMulti: AugmentedSubmittable<(threshold: u16 | AnyNumber | Uint8Array, otherSignatories: Vec<AccountId> | (AccountId | string | Uint8Array)[], maybeTimepoint: Option<Timepoint> | null | object | string | Uint8Array, call: OpaqueCall | string | Uint8Array, storeCall: bool | boolean | Uint8Array, maxWeight: Weight | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Immediately dispatch a multi-signature call using a single approval from the caller.
|
||||
*
|
||||
* The dispatch origin for this call must be _Signed_.
|
||||
*
|
||||
* - `other_signatories`: The accounts (other than the sender) who are part of the
|
||||
* multi-signature, but do not participate in the approval process.
|
||||
* - `call`: The call to be executed.
|
||||
*
|
||||
* Result is equivalent to the dispatched result.
|
||||
*
|
||||
* # <weight>
|
||||
* O(Z + C) where Z is the length of the call and C its execution weight.
|
||||
* -------------------------------
|
||||
* - Base Weight: 33.72 + 0.002 * Z µs
|
||||
* - DB Weight: None
|
||||
* - Plus Call Weight
|
||||
* # </weight>
|
||||
**/
|
||||
asMultiThreshold1: AugmentedSubmittable<(otherSignatories: Vec<AccountId> | (AccountId | string | Uint8Array)[], call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Cancel a pre-existing, on-going multisig transaction. Any deposit reserved previously
|
||||
* for this operation will be unreserved on success.
|
||||
@@ -1357,10 +1458,10 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - I/O: 1 read `O(S)`, one remove.
|
||||
* - Storage: removes one item.
|
||||
* ----------------------------------
|
||||
* - Base Weight: 37.6 + 0.084 * S
|
||||
* - Base Weight: 36.07 + 0.124 * S
|
||||
* - DB Weight:
|
||||
* - Read: Multisig Storage, [Caller Account]
|
||||
* - Write: Multisig Storage, [Caller Account]
|
||||
* - Read: Multisig Storage, [Caller Account], Refund Account, Calls
|
||||
* - Write: Multisig Storage, [Caller Account], Refund Account, Calls
|
||||
* # </weight>
|
||||
**/
|
||||
cancelAsMulti: AugmentedSubmittable<(threshold: u16 | AnyNumber | Uint8Array, otherSignatories: Vec<AccountId> | (AccountId | string | Uint8Array)[], timepoint: Timepoint | { height?: any; index?: any } | string | Uint8Array, callHash: U8aFixed | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
@@ -1727,6 +1828,14 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
schedule: AugmentedSubmittable<(when: BlockNumber | AnyNumber | Uint8Array, maybePeriodic: Option<Period> | null | object | string | Uint8Array, priority: Priority | AnyNumber | Uint8Array, call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Anonymously schedule a task after a delay.
|
||||
*
|
||||
* # <weight>
|
||||
* Same as [`schedule`].
|
||||
* # </weight>
|
||||
**/
|
||||
scheduleAfter: AugmentedSubmittable<(after: BlockNumber | AnyNumber | Uint8Array, maybePeriodic: Option<Period> | null | object | string | Uint8Array, priority: Priority | AnyNumber | Uint8Array, call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Schedule a named task.
|
||||
*
|
||||
@@ -1740,6 +1849,14 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
scheduleNamed: AugmentedSubmittable<(id: Bytes | string | Uint8Array, when: BlockNumber | AnyNumber | Uint8Array, maybePeriodic: Option<Period> | null | object | string | Uint8Array, priority: Priority | AnyNumber | Uint8Array, call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Schedule a named task after a delay.
|
||||
*
|
||||
* # <weight>
|
||||
* Same as [`schedule_named`].
|
||||
* # </weight>
|
||||
**/
|
||||
scheduleNamedAfter: AugmentedSubmittable<(id: Bytes | string | Uint8Array, after: BlockNumber | AnyNumber | Uint8Array, maybePeriodic: Option<Period> | null | object | string | Uint8Array, priority: Priority | AnyNumber | Uint8Array, call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
session: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
@@ -2151,7 +2268,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
/**
|
||||
* Cancel enactment of a deferred slash.
|
||||
*
|
||||
* Can be called by either the root origin or the `T::SlashCancelOrigin`.
|
||||
* Can be called by the `T::SlashCancelOrigin`.
|
||||
*
|
||||
* Parameters: era and indices of the slashes for that era to kill.
|
||||
*
|
||||
@@ -2235,6 +2352,17 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
forceUnstake: AugmentedSubmittable<(stash: AccountId | string | Uint8Array, numSlashingSpans: u32 | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Increments the ideal number of validators.
|
||||
*
|
||||
* The dispatch origin must be Root.
|
||||
*
|
||||
* # <weight>
|
||||
* Base Weight: 1.717 µs
|
||||
* Read/Write: Validator Count
|
||||
* # </weight>
|
||||
**/
|
||||
increaseValidatorCount: AugmentedSubmittable<(additional: Compact<u32> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Declare the desire to nominate `targets` for the origin controller.
|
||||
*
|
||||
@@ -2274,7 +2402,9 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Contains a limited number of reads and writes.
|
||||
* -----------
|
||||
* N is the Number of payouts for the validator (including the validator)
|
||||
* Base Weight: 110 + 54.2 * N µs (Median Slopes)
|
||||
* Base Weight:
|
||||
* - Reward Destination Staked: 110 + 54.2 * N µs (Median Slopes)
|
||||
* - Reward Destination Controller (Creating): 120 + 41.95 * N µs (Median Slopes)
|
||||
* DB Weight:
|
||||
* - Read: EraElectionStatus, CurrentEra, HistoryDepth, ErasValidatorReward,
|
||||
* ErasStakersClipped, ErasRewardPoints, ErasValidatorPrefs (8 items)
|
||||
@@ -2320,6 +2450,17 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
rebond: AugmentedSubmittable<(value: Compact<BalanceOf> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Scale up the ideal number of validators by a factor.
|
||||
*
|
||||
* The dispatch origin must be Root.
|
||||
*
|
||||
* # <weight>
|
||||
* Base Weight: 1.717 µs
|
||||
* Read/Write: Validator Count
|
||||
* # </weight>
|
||||
**/
|
||||
scaleValidatorCount: AugmentedSubmittable<(factor: Percent | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* (Re-)set the controller of a stash.
|
||||
*
|
||||
@@ -2865,7 +3006,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
/**
|
||||
* Add a member `who` to the set.
|
||||
*
|
||||
* May only be called from `AddOrigin` or root.
|
||||
* May only be called from `T::AddOrigin`.
|
||||
**/
|
||||
addMember: AugmentedSubmittable<(who: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
@@ -2878,29 +3019,33 @@ declare module '@polkadot/api/types/submittable' {
|
||||
changeKey: AugmentedSubmittable<(updated: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Remove the prime member if it exists.
|
||||
*
|
||||
* May only be called from `T::PrimeOrigin`.
|
||||
**/
|
||||
clearPrime: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Remove a member `who` from the set.
|
||||
*
|
||||
* May only be called from `RemoveOrigin` or root.
|
||||
* May only be called from `T::RemoveOrigin`.
|
||||
**/
|
||||
removeMember: AugmentedSubmittable<(who: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Change the membership to a new set, disregarding the existing membership. Be nice and
|
||||
* pass `members` pre-sorted.
|
||||
*
|
||||
* May only be called from `ResetOrigin` or root.
|
||||
* May only be called from `T::ResetOrigin`.
|
||||
**/
|
||||
resetMembers: AugmentedSubmittable<(members: Vec<AccountId> | (AccountId | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Set the prime member. Must be a current member.
|
||||
*
|
||||
* May only be called from `T::PrimeOrigin`.
|
||||
**/
|
||||
setPrime: AugmentedSubmittable<(who: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Swap out one member `remove` for another `add`.
|
||||
*
|
||||
* May only be called from `SwapOrigin` or root.
|
||||
* May only be called from `T::SwapOrigin`.
|
||||
*
|
||||
* Prime membership is *not* passed from `remove` to `add`, if extant.
|
||||
**/
|
||||
@@ -2936,6 +3081,8 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* Approve a proposal. At a later time, the proposal will be allocated to the beneficiary
|
||||
* and the original deposit will be returned.
|
||||
*
|
||||
* May only be called from `T::ApproveOrigin`.
|
||||
*
|
||||
* # <weight>
|
||||
* - Complexity: O(1).
|
||||
* - DbReads: `Proposals`, `Approvals`
|
||||
@@ -2978,6 +3125,8 @@ declare module '@polkadot/api/types/submittable' {
|
||||
/**
|
||||
* Reject a proposed spend. The original deposit will be slashed.
|
||||
*
|
||||
* May only be called from `T::RejectOrigin`.
|
||||
*
|
||||
* # <weight>
|
||||
* - Complexity: O(1)
|
||||
* - DbReads: `Proposals`, `rejected proposer account`
|
||||
@@ -3093,7 +3242,10 @@ declare module '@polkadot/api/types/submittable' {
|
||||
*
|
||||
* NOTE: If you need to ensure that any account-based filtering is not honored (i.e.
|
||||
* because you expect `proxy` to have been used prior in the call stack and you do not want
|
||||
* the call restrictions to apply to any sub-accounts), then use `as_sub` instead.
|
||||
* the call restrictions to apply to any sub-accounts), then use `as_multi_threshold_1`
|
||||
* in the Multisig pallet instead.
|
||||
*
|
||||
* NOTE: Prior to version *12, this was called `as_limited_sub`.
|
||||
*
|
||||
* The dispatch origin for this call must be _Signed_.
|
||||
*
|
||||
@@ -3102,22 +3254,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Plus the weight of the `call`
|
||||
* # </weight>
|
||||
**/
|
||||
asLimitedSub: AugmentedSubmittable<(index: u16 | AnyNumber | Uint8Array, call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Send a call through an indexed pseudonym of the sender.
|
||||
*
|
||||
* NOTE: If you need to ensure that any account-based filtering is honored (i.e. because
|
||||
* you expect `proxy` to have been used prior in the call stack and you want it to apply to
|
||||
* any sub-accounts), then use `as_limited_sub` instead.
|
||||
*
|
||||
* The dispatch origin for this call must be _Signed_.
|
||||
*
|
||||
* # <weight>
|
||||
* - Base weight: 2.861 µs
|
||||
* - Plus the weight of the `call`
|
||||
* # </weight>
|
||||
**/
|
||||
asSub: AugmentedSubmittable<(index: u16 | AnyNumber | Uint8Array, call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
asDerivative: AugmentedSubmittable<(index: u16 | AnyNumber | Uint8Array, call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Send a batch of dispatch calls.
|
||||
*
|
||||
@@ -3144,6 +3281,28 @@ declare module '@polkadot/api/types/submittable' {
|
||||
};
|
||||
vesting: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
* Force a vested transfer.
|
||||
*
|
||||
* The dispatch origin for this call must be _Root_.
|
||||
*
|
||||
* - `source`: The account whose funds should be transferred.
|
||||
* - `target`: The account that should be transferred the vested funds.
|
||||
* - `amount`: The amount of funds to transfer and will be vested.
|
||||
* - `schedule`: The vesting schedule attached to the transfer.
|
||||
*
|
||||
* Emits `VestingCreated`.
|
||||
*
|
||||
* # <weight>
|
||||
* - `O(1)`.
|
||||
* - DbWeight: 4 Reads, 4 Writes
|
||||
* - Reads: Vesting Storage, Balances Locks, Target Account, Source Account
|
||||
* - Writes: Vesting Storage, Balances Locks, Target Account, Source Account
|
||||
* - Benchmark: 100.3 + .365 * l µs (min square analysis)
|
||||
* - Using 100 µs fixed. Assuming less than 50 locks on any user, else we may want factor in number of locks.
|
||||
* # </weight>
|
||||
**/
|
||||
forceVestedTransfer: AugmentedSubmittable<(source: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, schedule: VestingInfo | { locked?: any; perBlock?: any; startingBlock?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Unlock any vested funds of the sender account.
|
||||
*
|
||||
|
||||
@@ -11,7 +11,7 @@ import { ApiInterfaceRx, ApiOptions, ApiTypes, DecorateMethod, DecoratedRpc, Dec
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { BehaviorSubject, Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap, take, tap, toArray } from 'rxjs/operators';
|
||||
import { map, switchMap, tap, toArray } from 'rxjs/operators';
|
||||
import decorateDerive, { ExactDerive } from '@polkadot/api-derive';
|
||||
import { memo } from '@polkadot/api-derive/util';
|
||||
import DecoratedMeta from '@polkadot/metadata/Decorated';
|
||||
@@ -145,7 +145,7 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
/**
|
||||
* @description Creates an instance of a type as registered
|
||||
*/
|
||||
public createType <K extends keyof InterfaceTypes> (type: K, ...params: any[]): InterfaceTypes[K] {
|
||||
public createType <K extends keyof InterfaceTypes> (type: K, ...params: unknown[]): InterfaceTypes[K] {
|
||||
return this.registry.createType(type, ...params);
|
||||
}
|
||||
|
||||
@@ -320,68 +320,50 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
|
||||
private _decorateStorageEntry<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): QueryableStorageEntry<ApiType> {
|
||||
// get the storage arguments, with DoubleMap as an array entry, otherwise spread
|
||||
const getArgs = (...args: any[]): any[] => extractStorageArgs(creator, args);
|
||||
const getArgs = (...args: unknown[]): unknown[] => extractStorageArgs(creator, args);
|
||||
|
||||
// Disable this where it occurs for each field we are decorating
|
||||
/* eslint-disable @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment */
|
||||
|
||||
// FIXME We probably want to be able to query the full list with non-subs as well
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const decorated = this.hasSubscriptions && creator.iterKey && creator.meta.type.isMap && creator.meta.type.asMap.linked.isTrue
|
||||
? this._decorateStorageLinked(creator, decorateMethod)
|
||||
: decorateMethod((...args: any[]): Observable<Codec> => (
|
||||
this.hasSubscriptions
|
||||
? this._rpcCore.state
|
||||
// Unfortunately for one-shot calls we also use .subscribeStorage here
|
||||
.subscribeStorage<[Codec]>([getArgs(...args)])
|
||||
// state_storage returns an array of values, since we have just subscribed to
|
||||
// a single entry, we pull that from the array and return it as-is
|
||||
.pipe(map(([data]): Codec => data))
|
||||
: this._rpcCore.state.getStorage(getArgs(...args))
|
||||
), { methodName: creator.method });
|
||||
: this._decorateStorageCall(creator, decorateMethod);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
decorated.creator = creator;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
||||
decorated.at = decorateMethod((hash: Hash, arg1?: Arg, arg2?: Arg): Observable<Codec> =>
|
||||
this._rpcCore.state.getStorage(getArgs(arg1, arg2), hash));
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
||||
decorated.hash = decorateMethod((arg1?: Arg, arg2?: Arg): Observable<Hash> =>
|
||||
this._rpcCore.state.getStorageHash(getArgs(arg1, arg2)));
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
decorated.key = (arg1?: Arg, arg2?: Arg): string =>
|
||||
u8aToHex(compactStripLength(creator(creator.meta.type.isDoubleMap ? [arg1, arg2] : arg1))[1]);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
decorated.keyPrefix = (key1?: Arg): string =>
|
||||
u8aToHex(creator.keyPrefix(key1));
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
||||
decorated.range = decorateMethod((range: [Hash, Hash?], arg1?: Arg, arg2?: Arg): Observable<[Hash, Codec][]> =>
|
||||
this._decorateStorageRange(decorated, [arg1, arg2], range));
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
||||
decorated.size = decorateMethod((arg1?: Arg, arg2?: Arg): Observable<u64> =>
|
||||
this._rpcCore.state.getStorageSize(getArgs(arg1, arg2)));
|
||||
|
||||
// .keys() & .entries() only available on map types
|
||||
if (creator.iterKey && (creator.meta.type.isMap || creator.meta.type.isDoubleMap)) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
||||
decorated.entries = decorateMethod(
|
||||
memo((doubleMapArg?: Arg): Observable<[StorageKey, Codec][]> =>
|
||||
this._retrieveMapEntries(creator, doubleMapArg)));
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
||||
decorated.entriesPaged = decorateMethod(
|
||||
memo((opts: PaginationOptions): Observable<[StorageKey, Codec][]> =>
|
||||
this._retrieveMapEntriesPaged(creator, opts)));
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
||||
decorated.keys = decorateMethod(
|
||||
memo((doubleMapArg?: Arg): Observable<StorageKey[]> =>
|
||||
this._retrieveMapKeys(creator, doubleMapArg)));
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
||||
decorated.keysPaged = decorateMethod(
|
||||
memo((opts: PaginationOptions): Observable<StorageKey[]> =>
|
||||
this._retrieveMapKeysPaged(creator, opts)));
|
||||
@@ -390,15 +372,32 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
// only support multi where subs are available
|
||||
if (this.hasSubscriptions) {
|
||||
// When using double map storage function, user need to pass double map key as an array
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
||||
decorated.multi = decorateMethod((args: (Arg | Arg[])[]): Observable<Codec[]> =>
|
||||
this._rpcCore.state.subscribeStorage(
|
||||
args.map((arg: Arg[] | Arg): [StorageEntry, Arg | Arg[]] => [creator, arg])));
|
||||
}
|
||||
|
||||
/* eslint-enable @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment */
|
||||
|
||||
return this._decorateFunctionMeta(creator as any, decorated) as unknown as QueryableStorageEntry<ApiType>;
|
||||
}
|
||||
|
||||
// Decorate the base storage call. In the case or rxjs or promise-without-callback (await)
|
||||
// we make a subscription, alternatively we push this through a single-shot query
|
||||
private _decorateStorageCall<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): ReturnType<DecorateMethod<ApiType>> {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return decorateMethod((...args: unknown[]): Observable<Codec> => {
|
||||
return this.hasSubscriptions
|
||||
? this._rpcCore.state.subscribeStorage<[Codec]>([extractStorageArgs(creator, args)]).pipe(
|
||||
map(([data]) => data) // extract first/only result from list
|
||||
)
|
||||
: this._rpcCore.state.getStorage(extractStorageArgs(creator, args));
|
||||
}, {
|
||||
methodName: creator.method,
|
||||
overrideNoSub: (...args: unknown[]) => this._rpcCore.state.getStorage(extractStorageArgs(creator, args))
|
||||
});
|
||||
}
|
||||
|
||||
private _decorateStorageRange<ApiType extends ApiTypes> (decorated: QueryableStorageEntry<ApiType>, args: [Arg?, Arg?], range: [Hash, Hash?]): Observable<[Hash, Codec][]> {
|
||||
const outputType = unwrapStorageType(decorated.creator.meta.type, decorated.creator.meta.modifier.isOptional);
|
||||
|
||||
@@ -412,6 +411,8 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
));
|
||||
}
|
||||
|
||||
// This is deprecated/removed on substrate - we still have some live chains, eg. Edgeware needing it, so it
|
||||
// has not been dropped yet. Slated for removal in API 2.0
|
||||
private _decorateStorageLinked<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): ReturnType<DecorateMethod<ApiType>> {
|
||||
const result = new Map<Codec, ITuple<[Codec, Linkage<Codec>]> | null>();
|
||||
let subject: BehaviorSubject<LinkageResult>;
|
||||
@@ -477,15 +478,15 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
// this handles the case where the head changes effectively, i.e. a new entry
|
||||
// appears at the top of the list, the new getNext gets kicked off
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-return
|
||||
return decorateMethod((...args: any[]): Observable<LinkageResult | [Codec, Linkage<Codec>]> =>
|
||||
return decorateMethod((...args: unknown[]): Observable<LinkageResult | [Codec, Linkage<Codec>]> =>
|
||||
args.length
|
||||
? this._rpcCore.state
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
.subscribeStorage<[[Codec, Linkage<Codec>]]>([[creator, ...args]])
|
||||
.pipe(map(([data]): [Codec, Linkage<Codec>] => data))
|
||||
.pipe(map(([data]) => data))
|
||||
: this._rpcCore.state
|
||||
.subscribeStorage<[LinkageResult]>([iterKey()])
|
||||
.pipe(switchMap(([key]): Observable<LinkageResult> => getNext(head = key)))
|
||||
.pipe(switchMap(([key]) => getNext(head = key)))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -495,35 +496,28 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
const headKey = iterKey(arg).toHex();
|
||||
const startSubject = new BehaviorSubject<string>(headKey);
|
||||
|
||||
return this._rpcCore.state.getKeysPaged
|
||||
? startSubject.pipe(
|
||||
switchMap((startKey) =>
|
||||
this._rpcCore.state.getKeysPaged(headKey, PAGE_SIZE_KEYS, startKey).pipe(
|
||||
map((keys) => keys.map((key) => key.setMeta(meta)))
|
||||
)
|
||||
),
|
||||
tap((keys): void => {
|
||||
keys.length === PAGE_SIZE_KEYS
|
||||
? startSubject.next(keys[PAGE_SIZE_KEYS - 1].toHex())
|
||||
: startSubject.complete();
|
||||
}),
|
||||
toArray(), // toArray since we want to startSubject to be completed
|
||||
map((keysArr: StorageKey[][]) => keysArr.reduce((result: StorageKey[], keys) => result.concat(keys), []))
|
||||
)
|
||||
: this._rpcCore.state.getKeys(headKey).pipe(
|
||||
map((keys) => keys.map((key) => key.setMeta(meta)))
|
||||
);
|
||||
return startSubject.pipe(
|
||||
switchMap((startKey) =>
|
||||
this._rpcCore.state.getKeysPaged(headKey, PAGE_SIZE_KEYS, startKey).pipe(
|
||||
map((keys) => keys.map((key) => key.setMeta(meta)))
|
||||
)
|
||||
),
|
||||
tap((keys): void => {
|
||||
keys.length === PAGE_SIZE_KEYS
|
||||
? startSubject.next(keys[PAGE_SIZE_KEYS - 1].toHex())
|
||||
: startSubject.complete();
|
||||
}),
|
||||
toArray(), // toArray since we want to startSubject to be completed
|
||||
map((keysArr: StorageKey[][]) => keysArr.reduce((result: StorageKey[], keys) => result.concat(keys), []))
|
||||
);
|
||||
}
|
||||
|
||||
private _retrieveMapKeysPaged ({ iterKey, meta }: StorageEntry, opts: PaginationOptions): Observable<StorageKey[]> {
|
||||
assert(iterKey && (meta.type.isMap || meta.type.isDoubleMap), 'keys can only be retrieved on maps, linked maps and double maps');
|
||||
|
||||
const headKey = iterKey(opts.arg).toHex();
|
||||
const getKeysPaged = this._rpcCore.state.getKeysPaged;
|
||||
|
||||
assert(getKeysPaged, 'Pagination not supported by the chain');
|
||||
|
||||
return getKeysPaged(headKey, opts.pageSize, opts.startKey || headKey).pipe(
|
||||
return this._rpcCore.state.getKeysPaged(headKey, opts.pageSize, opts.startKey || headKey).pipe(
|
||||
map((keys) => keys.map((key) => key.setMeta(meta)))
|
||||
);
|
||||
}
|
||||
@@ -535,13 +529,11 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
of(keys),
|
||||
...Array(Math.ceil(keys.length / PAGE_SIZE_VALS))
|
||||
.fill(0)
|
||||
.map((_, index): Observable<Codec[]> => {
|
||||
const keyset = keys.slice(index * PAGE_SIZE_VALS, (index * PAGE_SIZE_VALS) + PAGE_SIZE_VALS);
|
||||
|
||||
return this._rpcCore.state.queryStorageAt
|
||||
? this._rpcCore.state.queryStorageAt<Codec[]>(keyset)
|
||||
: this._rpcCore.state.subscribeStorage<Codec[]>(keyset).pipe(take(1));
|
||||
})
|
||||
.map((_, index): Observable<Codec[]> =>
|
||||
this._rpcCore.state.queryStorageAt<Codec[]>(
|
||||
keys.slice(index * PAGE_SIZE_VALS, (index * PAGE_SIZE_VALS) + PAGE_SIZE_VALS)
|
||||
)
|
||||
)
|
||||
])
|
||||
),
|
||||
map(([keys, ...valsArr]): [StorageKey, Codec][] =>
|
||||
@@ -557,9 +549,7 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
switchMap((keys) =>
|
||||
combineLatest<[StorageKey[], ...Codec[][]]>([
|
||||
of(keys),
|
||||
this._rpcCore.state.queryStorageAt
|
||||
? this._rpcCore.state.queryStorageAt<Codec[]>(keys)
|
||||
: this._rpcCore.state.subscribeStorage<Codec[]>(keys).pipe(take(1))
|
||||
this._rpcCore.state.queryStorageAt<Codec[]>(keys)
|
||||
])
|
||||
),
|
||||
map(([keys, ...valsArr]): [StorageKey, Codec][] =>
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -2,31 +2,30 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AnyFunction, Callback, Codec } from '@polkadot/types/types';
|
||||
import { ApiOptions, DecorateMethodOptions, ObsInnerType, StorageEntryPromiseOverloads, UnsubscribePromise } from '../types';
|
||||
import { Callback, Codec } from '@polkadot/types/types';
|
||||
import { ApiOptions, DecorateFn, DecorateMethodOptions, ObsInnerType, StorageEntryPromiseOverloads, UnsubscribePromise, VoidFn } from '../types';
|
||||
|
||||
import { Observable, EMPTY } from 'rxjs';
|
||||
import { catchError, first, tap } from 'rxjs/operators';
|
||||
import { EMPTY, Observable, Subscription } from 'rxjs';
|
||||
import { catchError, tap } from 'rxjs/operators';
|
||||
import { isFunction, assert } from '@polkadot/util';
|
||||
|
||||
import ApiBase from '../base';
|
||||
import Combinator, { CombinatorCallback, CombinatorFunction } from './Combinator';
|
||||
|
||||
interface Tracker {
|
||||
interface Tracker<T> {
|
||||
reject: (value: Error) => Observable<never>;
|
||||
resolve: (value: () => void) => void;
|
||||
resolve: (value: T) => void;
|
||||
}
|
||||
|
||||
// extract the arguments and callback params from a value array possibly containing a callback
|
||||
function extractArgs (args: any[], needsCallback: boolean): [any[], Callback<Codec> | undefined] {
|
||||
function extractArgs (args: unknown[], needsCallback: boolean): [unknown[], Callback<Codec> | undefined] {
|
||||
let callback: Callback<Codec> | undefined;
|
||||
const actualArgs = args.slice();
|
||||
|
||||
// If the last arg is a function, we pop it, put it into callback.
|
||||
// actualArgs will then hold the actual arguments to be passed to `method`
|
||||
if (args.length && isFunction(args[args.length - 1])) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
callback = actualArgs.pop();
|
||||
callback = actualArgs.pop() as Callback<Codec>;
|
||||
}
|
||||
|
||||
// When we need a subscription, ensure that a valid callback is actually passed
|
||||
@@ -36,64 +35,79 @@ function extractArgs (args: any[], needsCallback: boolean): [any[], Callback<Cod
|
||||
}
|
||||
|
||||
// a Promise completion tracker, wrapping an isComplete variable that ensures the promise only resolves once
|
||||
function promiseTracker (resolve: (value: () => void) => void, reject: (value: Error) => void): Tracker {
|
||||
function promiseTracker<T> (resolve: (value: T) => void, reject: (value: Error) => void): Tracker<T> {
|
||||
let isCompleted = false;
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/ban-types
|
||||
const complete = (fn: Function, value: any): void => {
|
||||
if (!isCompleted) {
|
||||
isCompleted = true;
|
||||
|
||||
fn(value);
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
reject: (error: Error): Observable<never> => {
|
||||
complete(reject, error);
|
||||
if (!isCompleted) {
|
||||
isCompleted = true;
|
||||
|
||||
reject(error);
|
||||
}
|
||||
|
||||
return EMPTY;
|
||||
},
|
||||
resolve: (value: any): void => {
|
||||
complete(resolve, value);
|
||||
resolve: (value: T): void => {
|
||||
if (!isCompleted) {
|
||||
isCompleted = true;
|
||||
|
||||
resolve(value);
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Decorate a call for a single-shot result - retrieve and then immediate unsubscribe
|
||||
function decorateCall<Method extends DecorateFn<ObsInnerType<ReturnType<Method>>>> (method: Method, actualArgs: unknown[]): Promise<ObsInnerType<ReturnType<Method>>> {
|
||||
return new Promise((resolve, reject): void => {
|
||||
// single result tracker - either reject with Error or resolve with Codec result
|
||||
const tracker = promiseTracker(resolve, reject);
|
||||
|
||||
// errors reject immediately, any result unsubscribes and resolves
|
||||
const subscription: Subscription = method(...actualArgs).pipe(
|
||||
catchError((error) => tracker.reject(error))
|
||||
).subscribe((result): void => {
|
||||
tracker.resolve(result);
|
||||
typeof setImmediate === 'undefined'
|
||||
? setTimeout(() => subscription.unsubscribe(), 0)
|
||||
: setImmediate(() => subscription.unsubscribe());
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Decorate a subscription where we have a result callback specified
|
||||
function decorateSubscribe<Method extends DecorateFn<ObsInnerType<ReturnType<Method>>>> (method: Method, actualArgs: unknown[], resultCb: Callback<Codec>): UnsubscribePromise {
|
||||
return new Promise<VoidFn>((resolve, reject): void => {
|
||||
// either reject with error or resolve with unsubscribe callback
|
||||
const tracker = promiseTracker(resolve, reject);
|
||||
|
||||
// errors reject immediately, the first result resolves with an unsubscribe promise, all results via callback
|
||||
const subscription: Subscription = method(...actualArgs).pipe(
|
||||
catchError((error) => tracker.reject(error)),
|
||||
tap(() => tracker.resolve(() => subscription.unsubscribe()))
|
||||
).subscribe((result): void => {
|
||||
// We use setImmediate here to ensure that the Promise above (tracker) has resolved, before returning
|
||||
// the first result. By putting is back in the queue, the promise above is guarded for first execution
|
||||
typeof setImmediate === 'undefined'
|
||||
? setTimeout(() => resultCb(result) as void, 0)
|
||||
: setImmediate(() => resultCb(result) as void);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Decorate method for ApiPromise, where the results are converted to the Promise equivalent
|
||||
*/
|
||||
export function decorateMethod<Method extends AnyFunction> (method: Method, options?: DecorateMethodOptions): StorageEntryPromiseOverloads {
|
||||
export function decorateMethod<Method extends DecorateFn<ObsInnerType<ReturnType<Method>>>> (method: Method, options?: DecorateMethodOptions): StorageEntryPromiseOverloads {
|
||||
const needsCallback = options && options.methodName && options.methodName.includes('subscribe');
|
||||
|
||||
return function (...args: any[]): Promise<ObsInnerType<ReturnType<Method>>> | UnsubscribePromise {
|
||||
const [actualArgs, callback] = extractArgs(args, !!needsCallback);
|
||||
return function (...args: unknown[]): Promise<ObsInnerType<ReturnType<Method>>> | UnsubscribePromise {
|
||||
const [actualArgs, resultCb] = extractArgs(args, !!needsCallback);
|
||||
|
||||
if (!callback) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access
|
||||
return method(...actualArgs).pipe(first()).toPromise() as Promise<ObsInnerType<ReturnType<Method>>>;
|
||||
}
|
||||
|
||||
return new Promise((resolve, reject): void => {
|
||||
const tracker = promiseTracker(resolve, reject);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-assignment
|
||||
const subscription: { unsubscribe: () => void } = method(...actualArgs).pipe(
|
||||
// if we find an error (invalid params, etc), reject the promise
|
||||
catchError((error): Observable<never> => tracker.reject(error)),
|
||||
// upon the first result, resolve with the unsub function
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-return
|
||||
tap(() => tracker.resolve(() => subscription.unsubscribe()))
|
||||
).subscribe((result: any): void => {
|
||||
if (setImmediate) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
||||
setImmediate(() => callback(result) as void);
|
||||
} else {
|
||||
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
||||
callback(result);
|
||||
}
|
||||
});
|
||||
}) as UnsubscribePromise;
|
||||
return resultCb
|
||||
? decorateSubscribe(method, actualArgs, resultCb)
|
||||
: decorateCall((options?.overrideNoSub as Method) || method, actualArgs);
|
||||
} as StorageEntryPromiseOverloads;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,14 +2,14 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AnyFunction } from '@polkadot/types/types';
|
||||
import { ApiOptions } from '../types';
|
||||
import { Codec } from '@polkadot/types/types';
|
||||
import { ApiOptions, DecorateFn } from '../types';
|
||||
|
||||
import { from, Observable } from 'rxjs';
|
||||
|
||||
import ApiBase from '../base';
|
||||
|
||||
export function decorateMethod <Method extends AnyFunction> (method: Method): Method {
|
||||
export function decorateMethod <Method extends DecorateFn<Codec>> (method: Method): Method {
|
||||
return method;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import type { Observable } from 'rxjs';
|
||||
import { AnyFunction, Callback, Codec, CodecArg } from '@polkadot/types/types';
|
||||
|
||||
// Prepend an element V onto the beginning of a tuple T.
|
||||
@@ -30,7 +30,9 @@ export type ApiTypes = 'promise' | 'rxjs';
|
||||
// Returns the inner type of an Observable
|
||||
export type ObsInnerType<O extends Observable<any>> = O extends Observable<infer U> ? U : never;
|
||||
|
||||
export type UnsubscribePromise = Promise<() => void>;
|
||||
export type VoidFn = () => void;
|
||||
|
||||
export type UnsubscribePromise = Promise<VoidFn>;
|
||||
|
||||
// FIXME The day TS has higher-kinded types, we can remove this hardcoded stuff
|
||||
export type PromiseOrObs<ApiType extends ApiTypes, T> = ApiType extends 'rxjs'
|
||||
@@ -66,8 +68,11 @@ export type MethodResult<ApiType extends ApiTypes, F extends AnyFunction> = ApiT
|
||||
// information. This describes it.
|
||||
export interface DecorateMethodOptions {
|
||||
methodName?: string;
|
||||
overrideNoSub?: (...args: unknown[]) => Observable<Codec>;
|
||||
}
|
||||
|
||||
export type DecorateFn <T extends Codec> = (...args: any[]) => Observable<T>;
|
||||
|
||||
export interface PaginationOptions<ArgType = CodecArg> {
|
||||
arg?: ArgType;
|
||||
pageSize: number;
|
||||
|
||||
@@ -5,10 +5,11 @@
|
||||
// Augment the modules
|
||||
import '@polkadot/api/augment';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import type BN from 'bn.js';
|
||||
import { DeriveCustom, ExactDerive } from '@polkadot/api-derive';
|
||||
import { Constants } from '@polkadot/metadata/Decorated/types';
|
||||
import { RpcInterface } from '@polkadot/rpc-core/types';
|
||||
import { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
|
||||
import { Metadata } from '@polkadot/types';
|
||||
import { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import { DefinitionRpc, DefinitionRpcSub, Signer, SignatureOptions, Registry, RegisteredTypes } from '@polkadot/types/types';
|
||||
@@ -18,7 +19,6 @@ import ApiBase from '../base';
|
||||
import { DecoratedRpc } from './rpc';
|
||||
import { QueryableStorage, QueryableStorageMulti } from './storage';
|
||||
import { SubmittableExtrinsics } from './submittable';
|
||||
import { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
|
||||
|
||||
export { Signer, SignerResult } from '@polkadot/types/types';
|
||||
export { default as ApiBase } from '../base';
|
||||
|
||||
@@ -32,7 +32,7 @@ function extractKeys (src: Record<string, Record<string, any>>, dst: Record<stri
|
||||
}
|
||||
|
||||
function findSectionExcludes (a: string[], b: string[]): string[] {
|
||||
return a.filter((section): boolean => !b.includes(section));
|
||||
return a.filter((section) => !b.includes(section));
|
||||
}
|
||||
|
||||
function extractSections (src: Record<string, Record<string, any>>, dst: Record<string, Record<string, any>>): StringsStrings {
|
||||
@@ -49,15 +49,15 @@ function findMethodExcludes (src: Record<string, Record<string, any>>, dst: Reco
|
||||
const dstSections = Object.keys(dst);
|
||||
|
||||
return dstSections
|
||||
.filter((section): boolean => srcSections.includes(section))
|
||||
.filter((section) => srcSections.includes(section))
|
||||
.reduce((rmMethods: string[], section): string[] => {
|
||||
const srcMethods = Object.keys(src[section]);
|
||||
|
||||
return rmMethods.concat(
|
||||
...Object
|
||||
.keys(dst[section])
|
||||
.filter((method): boolean => !srcMethods.includes(method))
|
||||
.map((method): string => `${section}.${method}`)
|
||||
.filter((method) => !srcMethods.includes(method))
|
||||
.map((method) => `${section}.${method}`)
|
||||
);
|
||||
}, []);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ export default function filterEvents (extHash: H256, { block: { extrinsics, head
|
||||
return;
|
||||
}
|
||||
|
||||
return allEvents.filter(({ phase }): boolean =>
|
||||
return allEvents.filter(({ phase }) =>
|
||||
// only ApplyExtrinsic has the extrinsic index
|
||||
phase.isApplyExtrinsic && phase.asApplyExtrinsic.eqn(index)
|
||||
);
|
||||
|
||||
@@ -11,7 +11,7 @@ function sig ({ method, section }: StorageEntry, ...args: Type[]): string {
|
||||
return `${section}.${method}(${args.join(', ')})`;
|
||||
}
|
||||
|
||||
function doDoubleMap (creator: StorageEntry, args: any[]): [StorageEntry, [any, any]] {
|
||||
function doDoubleMap (creator: StorageEntry, args: unknown[]): [StorageEntry, [any, any]] {
|
||||
const { key1, key2 } = creator.meta.type.asDoubleMap;
|
||||
|
||||
assert(args.length === 2, `${sig(creator, key1, key2)} is a doublemap, requiring 2 arguments, ${args.length} found`);
|
||||
@@ -20,7 +20,7 @@ function doDoubleMap (creator: StorageEntry, args: any[]): [StorageEntry, [any,
|
||||
return [creator, args as [any, any]];
|
||||
}
|
||||
|
||||
function doMap (creator: StorageEntry, args: any[]): [StorageEntry] | [StorageEntry, any] {
|
||||
function doMap (creator: StorageEntry, args: unknown[]): [StorageEntry] | [StorageEntry, any] {
|
||||
const { key, linked } = creator.meta.type.asMap;
|
||||
|
||||
linked.isTrue
|
||||
@@ -35,7 +35,7 @@ function doMap (creator: StorageEntry, args: any[]): [StorageEntry] | [StorageEn
|
||||
|
||||
// sets up the arguments in the form of [creator, args] ready to be used in a storage
|
||||
// call. Additionally, it verifies that the correct number of arguments have been passed
|
||||
export function extractStorageArgs (creator: StorageEntry, _args: any[]): [StorageEntry, [any, any]] | [StorageEntry] | [StorageEntry, any] {
|
||||
export function extractStorageArgs (creator: StorageEntry, _args: unknown[]): [StorageEntry, [any, any]] | [StorageEntry] | [StorageEntry, any] {
|
||||
const args = _args.filter((arg) => !isUndefined(arg));
|
||||
|
||||
if (creator.meta.type.isDoubleMap) {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/metadata",
|
||||
"version": "1.19.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.2",
|
||||
"@polkadot/types": "1.19.1",
|
||||
"@polkadot/types-known": "1.19.1",
|
||||
"@polkadot/util": "^2.14.1",
|
||||
"@polkadot/util-crypto": "^2.14.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.14.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.19.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.2",
|
||||
"@polkadot/metadata": "1.19.1",
|
||||
"@polkadot/rpc-provider": "1.19.1",
|
||||
"@polkadot/types": "1.19.1",
|
||||
"@polkadot/util": "^2.14.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.5.5"
|
||||
"rxjs": "^6.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.14.1"
|
||||
"@polkadot/keyring": "^3.0.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,10 +12,15 @@ import { combineLatest, from, Observable, Observer, of, throwError } from 'rxjs'
|
||||
import { catchError, map, publishReplay, refCount, switchMap } from 'rxjs/operators';
|
||||
import jsonrpc from '@polkadot/types/interfaces/jsonrpc';
|
||||
import { Option, StorageKey, Vec, createClass, createTypeUnsafe } from '@polkadot/types';
|
||||
import { assert, hexToU8a, isFunction, isNull, isNumber, isUndefined, logger, u8aToU8a } from '@polkadot/util';
|
||||
import { assert, hexToU8a, isFunction, isNull, isUndefined, logger, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import { drr } from './rxjs';
|
||||
|
||||
interface StorageChangeSetJSON {
|
||||
block: string;
|
||||
changes: [string, string | null][];
|
||||
}
|
||||
|
||||
const l = logger('rpc-core');
|
||||
|
||||
const EMPTY_META = {
|
||||
@@ -75,8 +80,6 @@ export default class Rpc implements RpcInterface {
|
||||
// these via the createInterfaces inside the constructor. However... this is not quite visible. The reason
|
||||
// why we don't do for individual assignments is to allow user-defined RPCs to also be defined
|
||||
|
||||
public readonly account!: RpcInterface['account'];
|
||||
|
||||
public readonly author!: RpcInterface['author'];
|
||||
|
||||
public readonly babe!: RpcInterface['babe'];
|
||||
@@ -113,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);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -123,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;
|
||||
@@ -212,7 +230,7 @@ export default class Rpc implements RpcInterface {
|
||||
}
|
||||
|
||||
// create a subscriptor, it subscribes once and resolves with the id as subscribe
|
||||
private _createSubscriber ({ paramsJson, subName, subType, update }: { subType: string; subName: string; paramsJson: AnyJson[]; update: ProviderInterfaceCallback }, errorHandler: (error: Error) => void): Promise<number> {
|
||||
private _createSubscriber ({ paramsJson, subName, subType, update }: { subType: string; subName: string; paramsJson: AnyJson[]; update: ProviderInterfaceCallback }, errorHandler: (error: Error) => void): Promise<number | string> {
|
||||
return new Promise((resolve, reject): void => {
|
||||
this.provider
|
||||
.subscribe(subType, subName, paramsJson, update)
|
||||
@@ -229,11 +247,12 @@ export default class Rpc implements RpcInterface {
|
||||
const subName = `${section}_${subMethod}`;
|
||||
const unsubName = `${section}_${unsubMethod}`;
|
||||
const subType = `${section}_${updateType}`;
|
||||
let memoized: null | RpcInterfaceMethod & memoizee.Memoized<RpcInterfaceMethod> = null;
|
||||
|
||||
const creator = (isRaw: boolean) => (...values: any[]): Observable<any> => {
|
||||
const creator = (isRaw: boolean) => (...values: unknown[]): Observable<any> => {
|
||||
return new Observable((observer: Observer<any>): VoidCallback => {
|
||||
// Have at least an empty promise, as used in the unsubscribe
|
||||
let subscriptionPromise: Promise<number | void> = Promise.resolve();
|
||||
let subscriptionPromise: Promise<number | string | null> = Promise.resolve(null);
|
||||
|
||||
const errorHandler = (error: Error): void => {
|
||||
logErrorMessage(method, def, error);
|
||||
@@ -279,22 +298,21 @@ export default class Rpc implements RpcInterface {
|
||||
// api.query.system.account(addr1).subscribe(); // will output 6 instead of 7 if we don't clear cache
|
||||
// // that's because all our observables are replay(1)
|
||||
// ```
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
memoized.delete(...values);
|
||||
memoized && memoized.delete(...values);
|
||||
|
||||
// Unsubscribe from provider
|
||||
subscriptionPromise
|
||||
.then((subscriptionId): Promise<boolean> =>
|
||||
isNumber(subscriptionId)
|
||||
? this.provider.unsubscribe(subType, unsubName, subscriptionId)
|
||||
: Promise.resolve(false)
|
||||
isNull(subscriptionId)
|
||||
? Promise.resolve(false)
|
||||
: this.provider.unsubscribe(subType, unsubName, subscriptionId)
|
||||
)
|
||||
.catch((error: Error): void => logErrorMessage(method, def, error));
|
||||
.catch((error: Error) => logErrorMessage(method, def, error));
|
||||
};
|
||||
}).pipe(drr());
|
||||
};
|
||||
|
||||
const memoized = memoizee(this._createMethodWithRaw(creator), {
|
||||
memoized = memoizee(this._createMethodWithRaw(creator), {
|
||||
// Dynamic length for argument
|
||||
length: false,
|
||||
// Normalize args so that different args that should be cached
|
||||
@@ -341,10 +359,10 @@ export default class Rpc implements RpcInterface {
|
||||
const keys = params[0] as Vec<StorageKey>;
|
||||
|
||||
return keys
|
||||
? this._formatStorageSet(keys, (result as { changes: [string, string | null][] }).changes)
|
||||
? this._formatStorageSet(keys, (result as StorageChangeSetJSON).changes)
|
||||
: this.registry.createType('StorageChangeSet', result);
|
||||
} else if (rpc.type === 'Vec<StorageChangeSet>') {
|
||||
const mapped = (result as { block: string; changes: [string, string | null][] }[]).map(({ block, changes }): [Hash, Codec[]] => [
|
||||
const mapped = (result as StorageChangeSetJSON[]).map(({ block, changes }): [Hash, Codec[]] => [
|
||||
this.registry.createType('Hash', block),
|
||||
this._formatStorageSet(params[0] as Vec<StorageKey>, changes)
|
||||
]);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { asapScheduler, ConnectableObservable, MonoTypeOperatorFunction, Observable, Subscription } from 'rxjs';
|
||||
import { asapScheduler, ConnectableObservable, MonoTypeOperatorFunction, Observable, Subscription, TeardownLogic } from 'rxjs';
|
||||
|
||||
const DELAY = 1750;
|
||||
|
||||
@@ -11,7 +11,7 @@ function refCountDelayInner <T> (source: Observable<T>): Observable<T> {
|
||||
// state: 0 = disconnected, 1 = disconnecting, 2 = connecting, 3 = connected
|
||||
let [state, refCount, connection, scheduler] = [0, 0, Subscription.EMPTY, Subscription.EMPTY];
|
||||
|
||||
return new Observable((ob) => {
|
||||
return new Observable((ob): TeardownLogic => {
|
||||
source.subscribe(ob);
|
||||
|
||||
if (refCount++ === 0) {
|
||||
@@ -27,12 +27,14 @@ function refCountDelayInner <T> (source: Observable<T>): Observable<T> {
|
||||
return (): void => {
|
||||
if (--refCount === 0) {
|
||||
if (state === 2) {
|
||||
state = 0; scheduler.unsubscribe();
|
||||
state = 0;
|
||||
scheduler.unsubscribe();
|
||||
} else {
|
||||
// state === 3
|
||||
state = 1;
|
||||
scheduler = asapScheduler.schedule((): void => {
|
||||
state = 0; connection.unsubscribe();
|
||||
state = 0;
|
||||
connection.unsubscribe();
|
||||
}, DELAY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/rpc-provider",
|
||||
"version": "1.19.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.2",
|
||||
"@polkadot/metadata": "1.19.1",
|
||||
"@polkadot/types": "1.19.1",
|
||||
"@polkadot/util": "^2.14.1",
|
||||
"@polkadot/util-crypto": "^2.14.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.14.1",
|
||||
"@polkadot/keyring": "^3.0.1",
|
||||
"mock-socket": "^9.0.3",
|
||||
"nock": "^12.0.3"
|
||||
"nock": "^13.0.3"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,6 +24,12 @@ describe('Http', (): void => {
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it('allows custom headers', (): void => {
|
||||
expect(
|
||||
(): Http => new Http('https://', { foo: 'bar' })
|
||||
).not.toThrow();
|
||||
});
|
||||
|
||||
it('always returns isConnected true', (): void => {
|
||||
expect(http.isConnected()).toEqual(true);
|
||||
});
|
||||
|
||||
@@ -40,14 +40,17 @@ export default class HttpProvider implements ProviderInterface {
|
||||
|
||||
readonly #endpoint: string;
|
||||
|
||||
readonly #headers: Record<string, string>;
|
||||
|
||||
/**
|
||||
* @param {string} endpoint The endpoint url starting with http://
|
||||
*/
|
||||
constructor (endpoint: string = defaults.HTTP_URL) {
|
||||
constructor (endpoint: string = defaults.HTTP_URL, headers: Record<string, string> = {}) {
|
||||
assert(/^(https|http):\/\//.test(endpoint), `Endpoint should start with 'http://', received '${endpoint}'`);
|
||||
|
||||
this.#coder = new Coder();
|
||||
this.#endpoint = endpoint;
|
||||
this.#headers = headers;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +105,8 @@ export default class HttpProvider implements ProviderInterface {
|
||||
headers: {
|
||||
Accept: 'application/json',
|
||||
'Content-Length': `${body.length}`,
|
||||
'Content-Type': 'application/json'
|
||||
'Content-Type': 'application/json',
|
||||
...this.#headers
|
||||
},
|
||||
method: 'POST'
|
||||
});
|
||||
|
||||
@@ -49,6 +49,6 @@ export interface ProviderInterface {
|
||||
isConnected (): boolean;
|
||||
on (type: ProviderInterfaceEmitted, sub: ProviderInterfaceEmitCb): () => void;
|
||||
send (method: string, params: any[]): Promise<any>;
|
||||
subscribe (type: string, method: string, params: any[], cb: ProviderInterfaceCallback): Promise<number>;
|
||||
unsubscribe (type: string, method: string, id: number): Promise<boolean>;
|
||||
subscribe (type: string, method: string, params: any[], cb: ProviderInterfaceCallback): Promise<number | string>;
|
||||
unsubscribe (type: string, method: string, id: number | string): Promise<boolean>;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
import { JsonRpcResponse, ProviderInterface, ProviderInterfaceCallback, ProviderInterfaceEmitted, ProviderInterfaceEmitCb } from '../types';
|
||||
|
||||
import EventEmitter from 'eventemitter3';
|
||||
import { assert, isNull, isUndefined, logger } from '@polkadot/util';
|
||||
import { assert, isNull, isUndefined, isChildClass, logger } from '@polkadot/util';
|
||||
|
||||
import Coder from '../coder';
|
||||
import defaults from '../defaults';
|
||||
@@ -67,6 +67,8 @@ export default class WsProvider implements WSProviderInterface {
|
||||
|
||||
readonly #endpoints: string[];
|
||||
|
||||
readonly #headers: Record<string, string>;
|
||||
|
||||
readonly #eventemitter: EventEmitter;
|
||||
|
||||
readonly #handlers: Record<string, WsStateAwaiting> = {};
|
||||
@@ -89,7 +91,7 @@ export default class WsProvider implements WSProviderInterface {
|
||||
* @param {string | string[]} endpoint The endpoint url. Usually `ws://ip:9944` or `wss://ip:9944`, may provide an array of endpoint strings.
|
||||
* @param {boolean} autoConnect Whether to connect automatically or not.
|
||||
*/
|
||||
constructor (endpoint: string | string[] = defaults.WS_URL, autoConnectMs: number | false = 1000) {
|
||||
constructor (endpoint: string | string[] = defaults.WS_URL, autoConnectMs: number | false = 1000, headers: Record<string, string> = {}) {
|
||||
const endpoints = Array.isArray(endpoint)
|
||||
? endpoint
|
||||
: [endpoint];
|
||||
@@ -105,6 +107,7 @@ export default class WsProvider implements WSProviderInterface {
|
||||
this.#coder = new Coder();
|
||||
this.#endpointIndex = -1;
|
||||
this.#endpoints = endpoints;
|
||||
this.#headers = headers;
|
||||
this.#websocket = null;
|
||||
|
||||
if (autoConnectMs > 0) {
|
||||
@@ -138,7 +141,11 @@ export default class WsProvider implements WSProviderInterface {
|
||||
|
||||
const WS = await getWSClass();
|
||||
|
||||
this.#websocket = new WS(this.#endpoints[this.#endpointIndex]);
|
||||
this.#websocket = typeof WebSocket !== 'undefined' && isChildClass(WebSocket, WS)
|
||||
? new WS(this.#endpoints[this.#endpointIndex])
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore - WS may be an instance of w3cwebsocket, which supports headers
|
||||
: new WS(this.#endpoints[this.#endpointIndex], undefined, undefined, this.#headers);
|
||||
this.#websocket.onclose = this.#onSocketClose;
|
||||
this.#websocket.onerror = this.#onSocketError;
|
||||
this.#websocket.onmessage = this.#onSocketMessage;
|
||||
@@ -247,8 +254,8 @@ export default class WsProvider implements WSProviderInterface {
|
||||
* })
|
||||
* ```
|
||||
*/
|
||||
public async subscribe (type: string, method: string, params: any[], callback: ProviderInterfaceCallback): Promise<number> {
|
||||
const id = await this.send(method, params, { callback, type }) as Promise<number>;
|
||||
public async subscribe (type: string, method: string, params: any[], callback: ProviderInterfaceCallback): Promise<number | string> {
|
||||
const id = await this.send(method, params, { callback, type }) as Promise<number | string>;
|
||||
|
||||
return id;
|
||||
}
|
||||
@@ -256,7 +263,7 @@ export default class WsProvider implements WSProviderInterface {
|
||||
/**
|
||||
* @summary Allows unsubscribing to subscriptions made with [[subscribe]].
|
||||
*/
|
||||
public async unsubscribe (type: string, method: string, id: number): Promise<boolean> {
|
||||
public async unsubscribe (type: string, method: string, id: number | string): Promise<boolean> {
|
||||
const subscription = `${type}::${id}`;
|
||||
|
||||
// FIXME This now could happen with re-subscriptions. The issue is that with a re-sub
|
||||
|
||||
@@ -28,6 +28,12 @@ describe('Ws', (): void => {
|
||||
createWs([]).isConnected()
|
||||
).toEqual(false);
|
||||
});
|
||||
|
||||
it('allows you to initialize the provider with custom headers', (): void => {
|
||||
expect(
|
||||
(): WsProvider => new WsProvider(TEST_WS_URL, 1000, { foo: 'bar' })
|
||||
).not.toThrow();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Endpoint Parsing', (): void => {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/typegen",
|
||||
"version": "1.19.1",
|
||||
"version": "1.27.1",
|
||||
"description": "Type generation scripts",
|
||||
"main": "index.js",
|
||||
"bin": {
|
||||
@@ -33,20 +33,20 @@
|
||||
},
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/typegen#readme",
|
||||
"dependencies": {
|
||||
"@babel/core": "^7.10.2",
|
||||
"@babel/register": "^7.10.1",
|
||||
"@babel/runtime": "^7.10.2",
|
||||
"@polkadot/api": "1.19.1",
|
||||
"@polkadot/metadata": "1.19.1",
|
||||
"@polkadot/rpc-provider": "1.19.1",
|
||||
"@polkadot/types": "1.19.1",
|
||||
"@polkadot/util": "^2.14.1",
|
||||
"@babel/core": "^7.11.0",
|
||||
"@babel/register": "^7.10.5",
|
||||
"@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.3.1"
|
||||
"yargs": "^15.4.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/websocket": "^1.0.0",
|
||||
"@types/websocket": "^1.0.1",
|
||||
"@types/yargs": "^15.0.5"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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.19.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.2",
|
||||
"@polkadot/types": "1.19.1",
|
||||
"@polkadot/util": "^2.14.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 || {})
|
||||
};
|
||||
}
|
||||
|
||||
@@ -6,8 +6,10 @@ import { OverrideModuleType } from '@polkadot/types/types';
|
||||
|
||||
// type overrides for modules (where duplication between modules exist)
|
||||
const typesModules: Record<string, OverrideModuleType> = {
|
||||
babe: {
|
||||
EquivocationProof: 'BabeEquivocationProof'
|
||||
},
|
||||
balances: {
|
||||
Releases: 'ReleasesBalances',
|
||||
Status: 'BalanceStatus'
|
||||
},
|
||||
contract: { // old metadata & naming
|
||||
@@ -17,8 +19,9 @@ const typesModules: Record<string, OverrideModuleType> = {
|
||||
contracts: {
|
||||
StorageKey: 'ContractStorageKey'
|
||||
},
|
||||
democracy: {
|
||||
Releases: 'ReleasesDemocracy'
|
||||
grandpa: {
|
||||
Equivocation: 'GrandpaEquivocation',
|
||||
EquivocationProof: 'GrandpaEquivocationProof'
|
||||
},
|
||||
identity: {
|
||||
Judgement: 'IdentityJudgement'
|
||||
@@ -31,8 +34,7 @@ const typesModules: Record<string, OverrideModuleType> = {
|
||||
Vote: 'SocietyVote'
|
||||
},
|
||||
staking: {
|
||||
Compact: 'CompactAssignments',
|
||||
Releases: 'ReleasesStaking'
|
||||
Compact: 'CompactAssignments'
|
||||
},
|
||||
treasury: {
|
||||
Proposal: 'TreasuryProposal'
|
||||
|
||||
@@ -4,17 +4,29 @@
|
||||
|
||||
import { OverrideVersionedType } from '@polkadot/types/types';
|
||||
|
||||
const sharedTypes = {
|
||||
Address: 'GenericAddress',
|
||||
LookupSource: 'GenericAddress',
|
||||
Multiplier: 'Fixed64',
|
||||
ReferendumInfo: 'ReferendumInfoTo239',
|
||||
StakingLedger: 'StakingLedgerTo240',
|
||||
Weight: 'u32'
|
||||
};
|
||||
|
||||
const versioned: OverrideVersionedType[] = [
|
||||
{
|
||||
// most chains started at 1000 (Fulvous at 224)
|
||||
minmax: [1, undefined],
|
||||
minmax: [1, 228],
|
||||
types: {
|
||||
...sharedTypes,
|
||||
Address: 'AccountId',
|
||||
LookupSource: 'AccountId',
|
||||
Multiplier: 'Fixed64',
|
||||
ReferendumInfo: 'ReferendumInfoTo239',
|
||||
StakingLedger: 'StakingLedgerTo240',
|
||||
Weight: 'u32'
|
||||
LookupSource: 'AccountId'
|
||||
}
|
||||
},
|
||||
{
|
||||
minmax: [229, undefined],
|
||||
types: {
|
||||
...sharedTypes
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
|
||||
@@ -4,6 +4,15 @@
|
||||
|
||||
import { OverrideVersionedType } from '@polkadot/types/types';
|
||||
|
||||
const sharedTypes = {
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId',
|
||||
ProxyType: {
|
||||
_enum: ['Any', 'NonTransfer', 'Governance', 'Staking', 'IdentityJudgement']
|
||||
}
|
||||
};
|
||||
|
||||
const versioned: OverrideVersionedType[] = [
|
||||
{
|
||||
// 1020 is first CC3
|
||||
@@ -16,6 +25,7 @@ const versioned: OverrideVersionedType[] = [
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'Address',
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
ReferendumInfo: 'ReferendumInfoTo239',
|
||||
SlashingSpans: 'SlashingSpansTo204',
|
||||
StakingLedger: 'StakingLedgerTo223',
|
||||
@@ -32,6 +42,7 @@ const versioned: OverrideVersionedType[] = [
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'Address',
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
ReferendumInfo: 'ReferendumInfoTo239',
|
||||
SlashingSpans: 'SlashingSpansTo204',
|
||||
StakingLedger: 'StakingLedgerTo223',
|
||||
@@ -49,6 +60,7 @@ const versioned: OverrideVersionedType[] = [
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'Address',
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
ReferendumInfo: 'ReferendumInfoTo239',
|
||||
StakingLedger: 'StakingLedgerTo223',
|
||||
Votes: 'VotesTo230',
|
||||
@@ -59,11 +71,10 @@ const versioned: OverrideVersionedType[] = [
|
||||
minmax: [1046, 1054],
|
||||
types: {
|
||||
// Indices optional, not in transaction
|
||||
Address: 'AccountId',
|
||||
...sharedTypes,
|
||||
DispatchInfo: 'DispatchInfoTo244',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId',
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
ReferendumInfo: 'ReferendumInfoTo239',
|
||||
StakingLedger: 'StakingLedgerTo240',
|
||||
Weight: 'u32'
|
||||
@@ -72,11 +83,10 @@ const versioned: OverrideVersionedType[] = [
|
||||
{
|
||||
minmax: [1055, 1056],
|
||||
types: {
|
||||
Address: 'AccountId',
|
||||
...sharedTypes,
|
||||
DispatchInfo: 'DispatchInfoTo244',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId',
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
StakingLedger: 'StakingLedgerTo240',
|
||||
Weight: 'u32'
|
||||
}
|
||||
@@ -84,18 +94,22 @@ const versioned: OverrideVersionedType[] = [
|
||||
{
|
||||
minmax: [1057, 1061],
|
||||
types: {
|
||||
Address: 'AccountId',
|
||||
...sharedTypes,
|
||||
DispatchInfo: 'DispatchInfoTo244',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId'
|
||||
OpenTip: 'OpenTipTo225'
|
||||
}
|
||||
},
|
||||
{
|
||||
minmax: [1062, undefined],
|
||||
minmax: [1062, 2012],
|
||||
types: {
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId'
|
||||
...sharedTypes,
|
||||
OpenTip: 'OpenTipTo225'
|
||||
}
|
||||
},
|
||||
{
|
||||
minmax: [2013, undefined],
|
||||
types: {
|
||||
...sharedTypes
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@@ -4,25 +4,28 @@
|
||||
|
||||
import { OverrideVersionedType } from '@polkadot/types/types';
|
||||
|
||||
const sharedTypes = {
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId',
|
||||
ProxyType: {
|
||||
_enum: ['Any', 'NonTransfer', 'Governance', 'Staking', 'SudoBalances', 'IdentityJudgement']
|
||||
}
|
||||
};
|
||||
|
||||
// these are override types for Polkadot
|
||||
const versioned: OverrideVersionedType[] = [
|
||||
{
|
||||
minmax: [0, 3],
|
||||
minmax: [0, 12],
|
||||
types: {
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId'
|
||||
...sharedTypes,
|
||||
OpenTip: 'OpenTipTo225'
|
||||
}
|
||||
},
|
||||
{
|
||||
minmax: [4, undefined],
|
||||
minmax: [13, undefined],
|
||||
types: {
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId',
|
||||
ProxyType: {
|
||||
_enum: ['Any', 'NonTransfer', 'Governance', 'Staking', 'SudoBalances']
|
||||
}
|
||||
...sharedTypes
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@@ -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;
|
||||
@@ -4,34 +4,36 @@
|
||||
|
||||
import { OverrideVersionedType } from '@polkadot/types/types';
|
||||
|
||||
const sharedTypes = {
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId',
|
||||
ProxyType: {
|
||||
_enum: ['Any', 'NonTransfer', 'Staking', 'SudoBalances', 'IdentityJudgement']
|
||||
}
|
||||
};
|
||||
|
||||
const versioned: OverrideVersionedType[] = [
|
||||
{
|
||||
minmax: [1, 2],
|
||||
types: {
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId',
|
||||
...sharedTypes,
|
||||
Multiplier: 'Fixed64',
|
||||
OpenTip: 'OpenTipTo225',
|
||||
Weight: 'u32'
|
||||
}
|
||||
},
|
||||
{
|
||||
minmax: [3, 19],
|
||||
minmax: [3, 22],
|
||||
types: {
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId'
|
||||
...sharedTypes,
|
||||
OpenTip: 'OpenTipTo225'
|
||||
}
|
||||
},
|
||||
{
|
||||
minmax: [20, undefined],
|
||||
minmax: [23, undefined],
|
||||
types: {
|
||||
Address: 'AccountId',
|
||||
Keys: 'SessionKeys5',
|
||||
LookupSource: 'AccountId',
|
||||
ProxyType: {
|
||||
_enum: ['Any', 'NonTransfer', 'Staking', 'SudoBalances']
|
||||
}
|
||||
...sharedTypes
|
||||
}
|
||||
}
|
||||
];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/types",
|
||||
"version": "1.19.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.2",
|
||||
"@polkadot/metadata": "1.19.1",
|
||||
"@polkadot/util": "^2.14.1",
|
||||
"@polkadot/util-crypto": "^2.14.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.5.5"
|
||||
"rxjs": "^6.6.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.14.1",
|
||||
"@polkadot/keyring": "^3.0.1",
|
||||
"@types/memoizee": "^0.4.4"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,21 +7,21 @@ import { BlockAttestations, IncludedBlocks, MoreAttestations } from '@polkadot/t
|
||||
import { RawAuraPreDigest } from '@polkadot/types/interfaces/aura';
|
||||
import { ExtrinsicOrHash, ExtrinsicStatus } from '@polkadot/types/interfaces/author';
|
||||
import { UncleEntryItem } from '@polkadot/types/interfaces/authorship';
|
||||
import { AllowedSlots, BabeAuthorityWeight, BabeBlockWeight, BabeWeight, EpochAuthorship, MaybeRandomness, MaybeVrf, NextConfigDescriptor, NextConfigDescriptorV1, Randomness, RawBabePreDigest, RawBabePreDigestCompat, RawBabePreDigestPrimary, RawBabePreDigestPrimaryTo159, RawBabePreDigestSecondaryPlain, RawBabePreDigestSecondaryTo159, RawBabePreDigestSecondaryVRF, RawBabePreDigestTo159, SlotNumber, VrfData, VrfOutput, VrfProof } from '@polkadot/types/interfaces/babe';
|
||||
import { AccountData, BalanceLock, BalanceLockTo212, BalanceStatus, Reasons, ReleasesBalances, VestingSchedule, WithdrawReasons } from '@polkadot/types/interfaces/balances';
|
||||
import { AllowedSlots, BabeAuthorityWeight, BabeBlockWeight, BabeEquivocationProof, BabeWeight, EpochAuthorship, MaybeRandomness, MaybeVrf, NextConfigDescriptor, NextConfigDescriptorV1, Randomness, RawBabePreDigest, RawBabePreDigestCompat, RawBabePreDigestPrimary, RawBabePreDigestPrimaryTo159, RawBabePreDigestSecondaryPlain, RawBabePreDigestSecondaryTo159, RawBabePreDigestSecondaryVRF, RawBabePreDigestTo159, SlotNumber, VrfData, VrfOutput, VrfProof } from '@polkadot/types/interfaces/babe';
|
||||
import { AccountData, BalanceLock, BalanceLockTo212, BalanceStatus, Reasons, VestingSchedule, WithdrawReasons } from '@polkadot/types/interfaces/balances';
|
||||
import { BlockHash } from '@polkadot/types/interfaces/chain';
|
||||
import { PrefixedStorageKey } from '@polkadot/types/interfaces/childstate';
|
||||
import { EthereumAddress, StatementKind } from '@polkadot/types/interfaces/claims';
|
||||
import { MemberCount, ProposalIndex, Votes, VotesTo230 } from '@polkadot/types/interfaces/collective';
|
||||
import { AuthorityId, RawVRFOutput } from '@polkadot/types/interfaces/consensus';
|
||||
import { AliveContractInfo, CodeHash, ContractCallRequest, ContractExecResult, ContractExecResultSuccess, ContractInfo, ContractStorageKey, Gas, PrefabWasmModule, PrefabWasmModuleReserved, Schedule, ScheduleTo212, SeedOf, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts';
|
||||
import { AccountVote, AccountVoteSplit, AccountVoteStandard, Conviction, Delegations, PreimageStatus, PreimageStatusAvailable, PriorLock, PropIndex, Proposal, ProxyState, ReferendumIndex, ReferendumInfo, ReferendumInfoFinished, ReferendumInfoTo239, ReferendumStatus, ReleasesDemocracy, Tally, Voting, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces/democracy';
|
||||
import { AliveContractInfo, CodeHash, ContractCallRequest, ContractExecResult, ContractExecResultSuccess, ContractExecResultSuccessTo255, ContractExecResultTo255, ContractInfo, ContractStorageKey, Gas, PrefabWasmModule, PrefabWasmModuleReserved, Schedule, ScheduleTo212, SeedOf, TombstoneContractInfo, TrieId } from '@polkadot/types/interfaces/contracts';
|
||||
import { AccountVote, AccountVoteSplit, AccountVoteStandard, Conviction, Delegations, PreimageStatus, PreimageStatusAvailable, PriorLock, PropIndex, Proposal, ProxyState, ReferendumIndex, ReferendumInfo, ReferendumInfoFinished, ReferendumInfoTo239, ReferendumStatus, Tally, Voting, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces/democracy';
|
||||
import { ApprovalFlag, DefunctVoter, Renouncing, SetIndex, Vote, VoteIndex, VoteThreshold, VoterInfo } from '@polkadot/types/interfaces/elections';
|
||||
import { CreatedBlock, ImportedAux } from '@polkadot/types/interfaces/engine';
|
||||
import { Account, Log, Vicinity } from '@polkadot/types/interfaces/evm';
|
||||
import { EcdsaSignature, Ed25519Signature, Extrinsic, ExtrinsicEra, ExtrinsicPayload, ExtrinsicPayloadUnknown, ExtrinsicPayloadV1, ExtrinsicPayloadV2, ExtrinsicPayloadV3, ExtrinsicPayloadV4, ExtrinsicSignatureV1, ExtrinsicSignatureV2, ExtrinsicSignatureV3, ExtrinsicSignatureV4, ExtrinsicUnknown, ExtrinsicV1, ExtrinsicV2, ExtrinsicV3, ExtrinsicV4, ImmortalEra, MortalEra, MultiSignature, Signature, SignerPayload, Sr25519Signature } from '@polkadot/types/interfaces/extrinsics';
|
||||
import { AssetOptions, Owner, PermissionLatest, PermissionVersions, PermissionsV1 } from '@polkadot/types/interfaces/genericAsset';
|
||||
import { AuthorityIndex, AuthorityList, AuthorityWeight, Equivocation, EquivocationProof, GrandpaEquivocation, GrandpaPrevote, KeyOwnerProof, NextAuthority, PendingPause, PendingResume, Precommits, Prevotes, ReportedRoundStates, RoundState, SetId, StoredPendingChange, StoredState } from '@polkadot/types/interfaces/grandpa';
|
||||
import { AuthorityIndex, AuthorityList, AuthorityWeight, GrandpaEquivocation, GrandpaEquivocationProof, GrandpaEquivocationValue, GrandpaPrevote, KeyOwnerProof, NextAuthority, PendingPause, PendingResume, Precommits, Prevotes, ReportedRoundStates, RoundState, SetId, StoredPendingChange, StoredState } from '@polkadot/types/interfaces/grandpa';
|
||||
import { IdentityFields, IdentityInfo, IdentityInfoAdditional, IdentityJudgement, RegistrarIndex, RegistrarInfo, Registration, RegistrationJudgement } from '@polkadot/types/interfaces/identity';
|
||||
import { AuthIndex, AuthoritySignature, Heartbeat, HeartbeatTo244, OpaqueMultiaddr, OpaqueNetworkState, OpaquePeerId } from '@polkadot/types/interfaces/imOnline';
|
||||
import { CallMetadataV0, DoubleMapTypeLatest, DoubleMapTypeV10, DoubleMapTypeV11, DoubleMapTypeV3, DoubleMapTypeV4, DoubleMapTypeV5, DoubleMapTypeV6, DoubleMapTypeV7, DoubleMapTypeV8, DoubleMapTypeV9, ErrorMetadataV10, ErrorMetadataV11, ErrorMetadataV8, ErrorMetadataV9, EventMetadataLatest, EventMetadataV0, EventMetadataV1, EventMetadataV10, EventMetadataV11, EventMetadataV2, EventMetadataV3, EventMetadataV4, EventMetadataV5, EventMetadataV6, EventMetadataV7, EventMetadataV8, EventMetadataV9, ExtrinsicMetadataLatest, ExtrinsicMetadataV11, FunctionArgumentMetadataLatest, FunctionArgumentMetadataV0, FunctionArgumentMetadataV1, FunctionArgumentMetadataV10, FunctionArgumentMetadataV11, FunctionArgumentMetadataV2, FunctionArgumentMetadataV3, FunctionArgumentMetadataV4, FunctionArgumentMetadataV5, FunctionArgumentMetadataV6, FunctionArgumentMetadataV7, FunctionArgumentMetadataV8, FunctionArgumentMetadataV9, FunctionMetadataLatest, FunctionMetadataV0, FunctionMetadataV1, FunctionMetadataV10, FunctionMetadataV11, FunctionMetadataV2, FunctionMetadataV3, FunctionMetadataV4, FunctionMetadataV5, FunctionMetadataV6, FunctionMetadataV7, FunctionMetadataV8, FunctionMetadataV9, MapTypeLatest, MapTypeV0, MapTypeV10, MapTypeV11, MapTypeV2, MapTypeV3, MapTypeV4, MapTypeV5, MapTypeV6, MapTypeV7, MapTypeV8, MapTypeV9, MetadataAll, MetadataLatest, MetadataV0, MetadataV1, MetadataV10, MetadataV11, MetadataV2, MetadataV3, MetadataV4, MetadataV5, MetadataV6, MetadataV7, MetadataV8, MetadataV9, ModuleConstantMetadataLatest, ModuleConstantMetadataV10, ModuleConstantMetadataV11, ModuleConstantMetadataV6, ModuleConstantMetadataV7, ModuleConstantMetadataV8, ModuleConstantMetadataV9, ModuleMetadataLatest, ModuleMetadataV0, ModuleMetadataV1, ModuleMetadataV10, ModuleMetadataV11, ModuleMetadataV2, ModuleMetadataV3, ModuleMetadataV4, ModuleMetadataV5, ModuleMetadataV6, ModuleMetadataV7, ModuleMetadataV8, ModuleMetadataV9, OuterDispatchCallV0, OuterDispatchMetadataV0, OuterEventEventMetadataEventsV0, OuterEventEventMetadataV0, OuterEventMetadataV0, PlainTypeLatest, PlainTypeV0, PlainTypeV10, PlainTypeV11, PlainTypeV2, PlainTypeV3, PlainTypeV4, PlainTypeV5, PlainTypeV6, PlainTypeV7, PlainTypeV8, PlainTypeV9, RuntimeModuleMetadataV0, StorageEntryMetadataLatest, StorageEntryMetadataV10, StorageEntryMetadataV11, StorageEntryMetadataV6, StorageEntryMetadataV7, StorageEntryMetadataV8, StorageEntryMetadataV9, StorageEntryModifierLatest, StorageEntryModifierV10, StorageEntryModifierV11, StorageEntryModifierV6, StorageEntryModifierV7, StorageEntryModifierV8, StorageEntryModifierV9, StorageEntryTypeLatest, StorageEntryTypeV10, StorageEntryTypeV11, StorageEntryTypeV6, StorageEntryTypeV7, StorageEntryTypeV8, StorageEntryTypeV9, StorageFunctionMetadataV0, StorageFunctionMetadataV1, StorageFunctionMetadataV2, StorageFunctionMetadataV3, StorageFunctionMetadataV4, StorageFunctionMetadataV5, StorageFunctionModifierV0, StorageFunctionModifierV1, StorageFunctionModifierV2, StorageFunctionModifierV3, StorageFunctionModifierV4, StorageFunctionModifierV5, StorageFunctionTypeV0, StorageFunctionTypeV1, StorageFunctionTypeV2, StorageFunctionTypeV3, StorageFunctionTypeV4, StorageFunctionTypeV5, StorageHasher, StorageHasherV10, StorageHasherV11, StorageHasherV4, StorageHasherV5, StorageHasherV6, StorageHasherV7, StorageHasherV8, StorageHasherV9, StorageMetadataLatest, StorageMetadataV0, StorageMetadataV10, StorageMetadataV11, StorageMetadataV7, StorageMetadataV8, StorageMetadataV9 } from '@polkadot/types/interfaces/metadata';
|
||||
@@ -29,17 +29,19 @@ import { StorageKind } from '@polkadot/types/interfaces/offchain';
|
||||
import { DeferredOffenceOf, Kind, OffenceDetails, Offender, OpaqueTimeSlot, ReportIdOf, Reporter } from '@polkadot/types/interfaces/offences';
|
||||
import { AbridgedCandidateReceipt, AttestedCandidate, AuctionIndex, Bidder, CandidateCommitments, CandidateReceipt, CollatorId, CollatorSignature, DoubleVoteReport, DownwardMessage, GlobalValidationSchedule, HeadData, IncomingParachain, IncomingParachainDeploy, IncomingParachainFixed, LeasePeriod, LeasePeriodOf, LocalValidationData, NewBidder, ParaId, ParaInfo, ParaPastCodeMeta, ParaScheduling, ParachainDispatchOrigin, Remark, Retriable, Scheduling, SigningContext, SlotRange, Statement, SubId, UpwardMessage, ValidationCode, ValidatorSignature, ValidityAttestation, WinningData, WinningDataEntry } from '@polkadot/types/interfaces/parachains';
|
||||
import { RuntimeDispatchInfo } from '@polkadot/types/interfaces/payment';
|
||||
import { Approvals } from '@polkadot/types/interfaces/poll';
|
||||
import { AccountStatus, AccountValidity } from '@polkadot/types/interfaces/purchase';
|
||||
import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
|
||||
import { RpcMethods } from '@polkadot/types/interfaces/rpc';
|
||||
import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, ChangesTrieConfiguration, Consensus, ConsensusEngineId, Digest, DigestItem, DispatchClass, DispatchInfo, DispatchInfoTo190, DispatchInfoTo244, ExtrinsicsWeight, Fixed128, Fixed64, H160, H256, H512, Hash, Header, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, ModuleId, Moment, Origin, Pays, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, ProxyType, RuntimeDbWeight, Seal, SealV0, SignedBlock, StorageData, ValidatorId, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime';
|
||||
import { AccountId, AccountIdOf, AccountIndex, Address, AssetId, Balance, BalanceOf, Block, BlockNumber, Call, ChangesTrieConfiguration, Consensus, ConsensusEngineId, Digest, DigestItem, ExtrinsicsWeight, Fixed128, Fixed64, H160, H256, H512, Hash, Header, Index, Justification, KeyTypeId, KeyValue, LockIdentifier, LookupSource, LookupTarget, ModuleId, Moment, OpaqueCall, Origin, Pays, Perbill, Percent, Permill, Perquintill, Phantom, PhantomData, PreRuntime, ProxyType, Releases, RuntimeDbWeight, Seal, SealV0, SignedBlock, StorageData, ValidatorId, Weight, WeightMultiplier } from '@polkadot/types/interfaces/runtime';
|
||||
import { Period, Priority, SchedulePeriod, SchedulePriority, Scheduled, TaskAddress } from '@polkadot/types/interfaces/scheduler';
|
||||
import { FullIdentification, IdentificationTuple, Keys, MembershipProof, SessionIndex, SessionKeys1, SessionKeys2, SessionKeys3, SessionKeys4, SessionKeys5, SessionKeys6, ValidatorCount } from '@polkadot/types/interfaces/session';
|
||||
import { Bid, BidKind, SocietyJudgement, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
|
||||
import { ActiveEraInfo, CompactAssignments, CompactScore, ElectionCompute, ElectionResult, ElectionScore, ElectionSize, ElectionStatus, EraIndex, EraPoints, EraRewardPoints, EraRewards, Exposure, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, NominatorIndex, OffchainAccuracy, PerU16, PhragmenScore, Points, ReleasesStaking, RewardDestination, RewardPoint, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SpanIndex, SpanRecord, StakingLedger, StakingLedgerTo223, StakingLedgerTo240, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking';
|
||||
import { ActiveEraInfo, CompactAssignments, CompactScore, ElectionCompute, ElectionResult, ElectionScore, ElectionSize, ElectionStatus, EraIndex, EraPoints, EraRewardPoints, EraRewards, Exposure, Forcing, IndividualExposure, KeyType, MomentOf, Nominations, NominatorIndex, OffchainAccuracy, PerU16, PhragmenScore, Points, RewardDestination, RewardPoint, SlashJournalEntry, SlashingSpans, SlashingSpansTo204, SpanIndex, SpanRecord, StakingLedger, StakingLedgerTo223, StakingLedgerTo240, UnappliedSlash, UnappliedSlashOther, UnlockChunk, ValidatorIndex, ValidatorPrefs, ValidatorPrefsTo145, ValidatorPrefsTo196 } from '@polkadot/types/interfaces/staking';
|
||||
import { ApiId, KeyValueOption, ReadProof, RuntimeVersion, RuntimeVersionApi, StorageChangeSet } from '@polkadot/types/interfaces/state';
|
||||
import { WeightToFeeCoefficient } from '@polkadot/types/interfaces/support';
|
||||
import { AccountInfo, ChainProperties, ChainType, DigestOf, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, EventRecordTo76, Health, Key, LastRuntimeUpgradeInfo, NetworkState, NetworkStatePeerset, NetworkStatePeersetInfo, NodeRole, NotConnectedPeer, Peer, PeerEndpoint, PeerEndpointAddr, PeerInfo, PeerPing, Phase, RefCount } from '@polkadot/types/interfaces/system';
|
||||
import { OpenTip, OpenTipFinder, OpenTipTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
|
||||
import { AccountInfo, ApplyExtrinsicResult, ChainProperties, ChainType, DigestOf, DispatchClass, DispatchError, DispatchErrorModule, DispatchErrorTo198, DispatchInfo, DispatchInfoTo190, DispatchInfoTo244, DispatchOutcome, DispatchResult, DispatchResultOf, DispatchResultTo198, Event, EventId, EventIndex, EventRecord, EventRecordTo76, Health, InvalidTransaction, Key, LastRuntimeUpgradeInfo, NetworkState, NetworkStatePeerset, NetworkStatePeersetInfo, NodeRole, NotConnectedPeer, Peer, PeerEndpoint, PeerEndpointAddr, PeerInfo, PeerPing, Phase, RefCount, TransactionValidityError, UnknownTransaction } from '@polkadot/types/interfaces/system';
|
||||
import { OpenTip, OpenTipFinderTo225, OpenTipTip, OpenTipTo225, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
|
||||
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
|
||||
import { CallHash, Multisig, Timepoint } from '@polkadot/types/interfaces/utility';
|
||||
import { VestingInfo } from '@polkadot/types/interfaces/vesting';
|
||||
@@ -171,18 +173,6 @@ declare module '@polkadot/types/types/registry' {
|
||||
DigestItem: DigestItem;
|
||||
'Option<DigestItem>': Option<DigestItem>;
|
||||
'Vec<DigestItem>': Vec<DigestItem>;
|
||||
DispatchClass: DispatchClass;
|
||||
'Option<DispatchClass>': Option<DispatchClass>;
|
||||
'Vec<DispatchClass>': Vec<DispatchClass>;
|
||||
DispatchInfo: DispatchInfo;
|
||||
'Option<DispatchInfo>': Option<DispatchInfo>;
|
||||
'Vec<DispatchInfo>': Vec<DispatchInfo>;
|
||||
DispatchInfoTo190: DispatchInfoTo190;
|
||||
'Option<DispatchInfoTo190>': Option<DispatchInfoTo190>;
|
||||
'Vec<DispatchInfoTo190>': Vec<DispatchInfoTo190>;
|
||||
DispatchInfoTo244: DispatchInfoTo244;
|
||||
'Option<DispatchInfoTo244>': Option<DispatchInfoTo244>;
|
||||
'Vec<DispatchInfoTo244>': Vec<DispatchInfoTo244>;
|
||||
ExtrinsicsWeight: ExtrinsicsWeight;
|
||||
'Option<ExtrinsicsWeight>': Option<ExtrinsicsWeight>;
|
||||
'Vec<ExtrinsicsWeight>': Vec<ExtrinsicsWeight>;
|
||||
@@ -237,6 +227,9 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Compact<Moment>': Compact<Moment>;
|
||||
'Option<Moment>': Option<Moment>;
|
||||
'Vec<Moment>': Vec<Moment>;
|
||||
OpaqueCall: OpaqueCall;
|
||||
'Option<OpaqueCall>': Option<OpaqueCall>;
|
||||
'Vec<OpaqueCall>': Vec<OpaqueCall>;
|
||||
Origin: Origin;
|
||||
'Option<Origin>': Option<Origin>;
|
||||
'Vec<Origin>': Vec<Origin>;
|
||||
@@ -268,6 +261,9 @@ declare module '@polkadot/types/types/registry' {
|
||||
ProxyType: ProxyType;
|
||||
'Option<ProxyType>': Option<ProxyType>;
|
||||
'Vec<ProxyType>': Vec<ProxyType>;
|
||||
Releases: Releases;
|
||||
'Option<Releases>': Option<Releases>;
|
||||
'Vec<Releases>': Vec<Releases>;
|
||||
RuntimeDbWeight: RuntimeDbWeight;
|
||||
'Option<RuntimeDbWeight>': Option<RuntimeDbWeight>;
|
||||
'Vec<RuntimeDbWeight>': Vec<RuntimeDbWeight>;
|
||||
@@ -316,16 +312,19 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Compact<BabeBlockWeight>': Compact<BabeBlockWeight>;
|
||||
'Option<BabeBlockWeight>': Option<BabeBlockWeight>;
|
||||
'Vec<BabeBlockWeight>': Vec<BabeBlockWeight>;
|
||||
BabeEquivocationProof: BabeEquivocationProof;
|
||||
'Option<BabeEquivocationProof>': Option<BabeEquivocationProof>;
|
||||
'Vec<BabeEquivocationProof>': Vec<BabeEquivocationProof>;
|
||||
BabeWeight: BabeWeight;
|
||||
'Compact<BabeWeight>': Compact<BabeWeight>;
|
||||
'Option<BabeWeight>': Option<BabeWeight>;
|
||||
'Vec<BabeWeight>': Vec<BabeWeight>;
|
||||
MaybeRandomness: MaybeRandomness;
|
||||
'Option<MaybeRandomness>': Option<MaybeRandomness>;
|
||||
'Vec<MaybeRandomness>': Vec<MaybeRandomness>;
|
||||
MaybeVrf: MaybeVrf;
|
||||
'Option<MaybeVrf>': Option<MaybeVrf>;
|
||||
'Vec<MaybeVrf>': Vec<MaybeVrf>;
|
||||
BabeWeight: BabeWeight;
|
||||
'Compact<BabeWeight>': Compact<BabeWeight>;
|
||||
'Option<BabeWeight>': Option<BabeWeight>;
|
||||
'Vec<BabeWeight>': Vec<BabeWeight>;
|
||||
EpochAuthorship: EpochAuthorship;
|
||||
'Option<EpochAuthorship>': Option<EpochAuthorship>;
|
||||
'Vec<EpochAuthorship>': Vec<EpochAuthorship>;
|
||||
@@ -387,9 +386,6 @@ declare module '@polkadot/types/types/registry' {
|
||||
BalanceStatus: BalanceStatus;
|
||||
'Option<BalanceStatus>': Option<BalanceStatus>;
|
||||
'Vec<BalanceStatus>': Vec<BalanceStatus>;
|
||||
ReleasesBalances: ReleasesBalances;
|
||||
'Option<ReleasesBalances>': Option<ReleasesBalances>;
|
||||
'Vec<ReleasesBalances>': Vec<ReleasesBalances>;
|
||||
Reasons: Reasons;
|
||||
'Option<Reasons>': Option<Reasons>;
|
||||
'Vec<Reasons>': Vec<Reasons>;
|
||||
@@ -428,6 +424,12 @@ declare module '@polkadot/types/types/registry' {
|
||||
ContractCallRequest: ContractCallRequest;
|
||||
'Option<ContractCallRequest>': Option<ContractCallRequest>;
|
||||
'Vec<ContractCallRequest>': Vec<ContractCallRequest>;
|
||||
ContractExecResultSuccessTo255: ContractExecResultSuccessTo255;
|
||||
'Option<ContractExecResultSuccessTo255>': Option<ContractExecResultSuccessTo255>;
|
||||
'Vec<ContractExecResultSuccessTo255>': Vec<ContractExecResultSuccessTo255>;
|
||||
ContractExecResultTo255: ContractExecResultTo255;
|
||||
'Option<ContractExecResultTo255>': Option<ContractExecResultTo255>;
|
||||
'Vec<ContractExecResultTo255>': Vec<ContractExecResultTo255>;
|
||||
ContractExecResultSuccess: ContractExecResultSuccess;
|
||||
'Option<ContractExecResultSuccess>': Option<ContractExecResultSuccess>;
|
||||
'Vec<ContractExecResultSuccess>': Vec<ContractExecResultSuccess>;
|
||||
@@ -515,9 +517,6 @@ declare module '@polkadot/types/types/registry' {
|
||||
ReferendumStatus: ReferendumStatus;
|
||||
'Option<ReferendumStatus>': Option<ReferendumStatus>;
|
||||
'Vec<ReferendumStatus>': Vec<ReferendumStatus>;
|
||||
ReleasesDemocracy: ReleasesDemocracy;
|
||||
'Option<ReleasesDemocracy>': Option<ReleasesDemocracy>;
|
||||
'Vec<ReleasesDemocracy>': Vec<ReleasesDemocracy>;
|
||||
Tally: Tally;
|
||||
'Option<Tally>': Option<Tally>;
|
||||
'Vec<Tally>': Vec<Tally>;
|
||||
@@ -676,15 +675,15 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Compact<AuthorityWeight>': Compact<AuthorityWeight>;
|
||||
'Option<AuthorityWeight>': Option<AuthorityWeight>;
|
||||
'Vec<AuthorityWeight>': Vec<AuthorityWeight>;
|
||||
Equivocation: Equivocation;
|
||||
'Option<Equivocation>': Option<Equivocation>;
|
||||
'Vec<Equivocation>': Vec<Equivocation>;
|
||||
EquivocationProof: EquivocationProof;
|
||||
'Option<EquivocationProof>': Option<EquivocationProof>;
|
||||
'Vec<EquivocationProof>': Vec<EquivocationProof>;
|
||||
GrandpaEquivocation: GrandpaEquivocation;
|
||||
'Option<GrandpaEquivocation>': Option<GrandpaEquivocation>;
|
||||
'Vec<GrandpaEquivocation>': Vec<GrandpaEquivocation>;
|
||||
GrandpaEquivocationProof: GrandpaEquivocationProof;
|
||||
'Option<GrandpaEquivocationProof>': Option<GrandpaEquivocationProof>;
|
||||
'Vec<GrandpaEquivocationProof>': Vec<GrandpaEquivocationProof>;
|
||||
GrandpaEquivocationValue: GrandpaEquivocationValue;
|
||||
'Option<GrandpaEquivocationValue>': Option<GrandpaEquivocationValue>;
|
||||
'Vec<GrandpaEquivocationValue>': Vec<GrandpaEquivocationValue>;
|
||||
GrandpaPrevote: GrandpaPrevote;
|
||||
'Option<GrandpaPrevote>': Option<GrandpaPrevote>;
|
||||
'Vec<GrandpaPrevote>': Vec<GrandpaPrevote>;
|
||||
@@ -945,9 +944,6 @@ declare module '@polkadot/types/types/registry' {
|
||||
PhragmenScore: PhragmenScore;
|
||||
'Option<PhragmenScore>': Option<PhragmenScore>;
|
||||
'Vec<PhragmenScore>': Vec<PhragmenScore>;
|
||||
ReleasesStaking: ReleasesStaking;
|
||||
'Option<ReleasesStaking>': Option<ReleasesStaking>;
|
||||
'Vec<ReleasesStaking>': Vec<ReleasesStaking>;
|
||||
RewardDestination: RewardDestination;
|
||||
'Option<RewardDestination>': Option<RewardDestination>;
|
||||
'Vec<RewardDestination>': Vec<RewardDestination>;
|
||||
@@ -1008,6 +1004,9 @@ declare module '@polkadot/types/types/registry' {
|
||||
AccountInfo: AccountInfo;
|
||||
'Option<AccountInfo>': Option<AccountInfo>;
|
||||
'Vec<AccountInfo>': Vec<AccountInfo>;
|
||||
ApplyExtrinsicResult: ApplyExtrinsicResult;
|
||||
'Option<ApplyExtrinsicResult>': Option<ApplyExtrinsicResult>;
|
||||
'Vec<ApplyExtrinsicResult>': Vec<ApplyExtrinsicResult>;
|
||||
ChainProperties: ChainProperties;
|
||||
'Option<ChainProperties>': Option<ChainProperties>;
|
||||
'Vec<ChainProperties>': Vec<ChainProperties>;
|
||||
@@ -1017,6 +1016,9 @@ declare module '@polkadot/types/types/registry' {
|
||||
DigestOf: DigestOf;
|
||||
'Option<DigestOf>': Option<DigestOf>;
|
||||
'Vec<DigestOf>': Vec<DigestOf>;
|
||||
DispatchClass: DispatchClass;
|
||||
'Option<DispatchClass>': Option<DispatchClass>;
|
||||
'Vec<DispatchClass>': Vec<DispatchClass>;
|
||||
DispatchError: DispatchError;
|
||||
'Option<DispatchError>': Option<DispatchError>;
|
||||
'Vec<DispatchError>': Vec<DispatchError>;
|
||||
@@ -1026,6 +1028,18 @@ declare module '@polkadot/types/types/registry' {
|
||||
DispatchErrorTo198: DispatchErrorTo198;
|
||||
'Option<DispatchErrorTo198>': Option<DispatchErrorTo198>;
|
||||
'Vec<DispatchErrorTo198>': Vec<DispatchErrorTo198>;
|
||||
DispatchInfo: DispatchInfo;
|
||||
'Option<DispatchInfo>': Option<DispatchInfo>;
|
||||
'Vec<DispatchInfo>': Vec<DispatchInfo>;
|
||||
DispatchInfoTo190: DispatchInfoTo190;
|
||||
'Option<DispatchInfoTo190>': Option<DispatchInfoTo190>;
|
||||
'Vec<DispatchInfoTo190>': Vec<DispatchInfoTo190>;
|
||||
DispatchInfoTo244: DispatchInfoTo244;
|
||||
'Option<DispatchInfoTo244>': Option<DispatchInfoTo244>;
|
||||
'Vec<DispatchInfoTo244>': Vec<DispatchInfoTo244>;
|
||||
DispatchOutcome: DispatchOutcome;
|
||||
'Option<DispatchOutcome>': Option<DispatchOutcome>;
|
||||
'Vec<DispatchOutcome>': Vec<DispatchOutcome>;
|
||||
DispatchResult: DispatchResult;
|
||||
'Option<DispatchResult>': Option<DispatchResult>;
|
||||
'Vec<DispatchResult>': Vec<DispatchResult>;
|
||||
@@ -1054,6 +1068,9 @@ declare module '@polkadot/types/types/registry' {
|
||||
Health: Health;
|
||||
'Option<Health>': Option<Health>;
|
||||
'Vec<Health>': Vec<Health>;
|
||||
InvalidTransaction: InvalidTransaction;
|
||||
'Option<InvalidTransaction>': Option<InvalidTransaction>;
|
||||
'Vec<InvalidTransaction>': Vec<InvalidTransaction>;
|
||||
Key: Key;
|
||||
'Option<Key>': Option<Key>;
|
||||
'Vec<Key>': Vec<Key>;
|
||||
@@ -1097,12 +1114,21 @@ declare module '@polkadot/types/types/registry' {
|
||||
'Compact<RefCount>': Compact<RefCount>;
|
||||
'Option<RefCount>': Option<RefCount>;
|
||||
'Vec<RefCount>': Vec<RefCount>;
|
||||
TransactionValidityError: TransactionValidityError;
|
||||
'Option<TransactionValidityError>': Option<TransactionValidityError>;
|
||||
'Vec<TransactionValidityError>': Vec<TransactionValidityError>;
|
||||
UnknownTransaction: UnknownTransaction;
|
||||
'Option<UnknownTransaction>': Option<UnknownTransaction>;
|
||||
'Vec<UnknownTransaction>': Vec<UnknownTransaction>;
|
||||
OpenTip: OpenTip;
|
||||
'Option<OpenTip>': Option<OpenTip>;
|
||||
'Vec<OpenTip>': Vec<OpenTip>;
|
||||
OpenTipFinder: OpenTipFinder;
|
||||
'Option<OpenTipFinder>': Option<OpenTipFinder>;
|
||||
'Vec<OpenTipFinder>': Vec<OpenTipFinder>;
|
||||
OpenTipTo225: OpenTipTo225;
|
||||
'Option<OpenTipTo225>': Option<OpenTipTo225>;
|
||||
'Vec<OpenTipTo225>': Vec<OpenTipTo225>;
|
||||
OpenTipFinderTo225: OpenTipFinderTo225;
|
||||
'Option<OpenTipFinderTo225>': Option<OpenTipFinderTo225>;
|
||||
'Vec<OpenTipFinderTo225>': Vec<OpenTipFinderTo225>;
|
||||
OpenTipTip: OpenTipTip;
|
||||
'Option<OpenTipTip>': Option<OpenTipTip>;
|
||||
'Vec<OpenTipTip>': Vec<OpenTipTip>;
|
||||
@@ -1253,6 +1279,15 @@ declare module '@polkadot/types/types/registry' {
|
||||
WinningDataEntry: WinningDataEntry;
|
||||
'Option<WinningDataEntry>': Option<WinningDataEntry>;
|
||||
'Vec<WinningDataEntry>': Vec<WinningDataEntry>;
|
||||
Approvals: Approvals;
|
||||
'Option<Approvals>': Option<Approvals>;
|
||||
'Vec<Approvals>': Vec<Approvals>;
|
||||
AccountStatus: AccountStatus;
|
||||
'Option<AccountStatus>': Option<AccountStatus>;
|
||||
'Vec<AccountStatus>': Vec<AccountStatus>;
|
||||
AccountValidity: AccountValidity;
|
||||
'Option<AccountValidity>': Option<AccountValidity>;
|
||||
'Vec<AccountValidity>': Vec<AccountValidity>;
|
||||
CallMetadataV0: CallMetadataV0;
|
||||
'Option<CallMetadataV0>': Option<CallMetadataV0>;
|
||||
'Vec<CallMetadataV0>': Vec<CallMetadataV0>;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { H256 } from '../interfaces/runtime';
|
||||
import { AnyNumber, Codec, Registry } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { assert, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isHex, isString, isU8a, u8aToBn } from '@polkadot/util';
|
||||
import { BN_ZERO, assert, bnToBn, bnToHex, bnToU8a, formatBalance, formatNumber, hexToBn, isHex, isString, isU8a, u8aToBn } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Raw from './Raw';
|
||||
@@ -77,6 +77,7 @@ export default abstract class AbstractInt extends BN implements Codec {
|
||||
this.#isHexJson = isHexJson;
|
||||
this.#isSigned = isSigned;
|
||||
|
||||
assert(isSigned || this.gte(BN_ZERO), `${this.toRawType()}: Negative number passed to unsigned type`);
|
||||
assert(super.bitLength() <= bitLength, `${this.toRawType()}: Input too large. Found input with ${super.bitLength()} bits, expected ${bitLength}`);
|
||||
}
|
||||
|
||||
@@ -161,7 +162,7 @@ export default abstract class AbstractInt extends BN implements Codec {
|
||||
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public toHuman (isExpanded?: boolean): any {
|
||||
public toHuman (isExpanded?: boolean): string {
|
||||
// FIXME we need proper expansion here
|
||||
return this instanceof this.registry.createClass('Balance')
|
||||
? this.isMax()
|
||||
|
||||
@@ -171,7 +171,7 @@ export default class BTreeSet<V extends Codec = Codec> extends Set<V> implements
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (): string {
|
||||
return `BTreeSet<${new this.#ValClass(this.registry).toRawType()}>`;
|
||||
return `BTreeSet<${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,15 +2,17 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AnyNumber, Codec, Constructor, ICompact, InterfaceTypes, Registry } from '../types';
|
||||
import { H256 } from '@polkadot/types/interfaces';
|
||||
import { AnyJson, AnyNumber, Codec, Constructor, ICompact, InterfaceTypes, Registry } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { compactAddLength, compactFromU8a, compactStripLength, compactToU8a, isBigInt, isBn, isNumber, isString } from '@polkadot/util';
|
||||
import { DEFAULT_BITLENGTH } from '@polkadot/util/compact/defaults';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import typeToConstructor from './utils/typeToConstructor';
|
||||
import { UIntBitLength } from './AbstractInt';
|
||||
import Base from './Base';
|
||||
import Raw from './Raw';
|
||||
|
||||
export interface CompactEncodable extends Codec {
|
||||
bitLength (): number;
|
||||
@@ -26,11 +28,17 @@ export interface CompactEncodable extends Codec {
|
||||
* used by other types to add length-prefixed encoding, or in the case of wrapped types, taking
|
||||
* a number and making the compact representation thereof
|
||||
*/
|
||||
export default class Compact<T extends CompactEncodable> extends Base<T> implements ICompact<T> {
|
||||
export default class Compact<T extends CompactEncodable> implements ICompact<T> {
|
||||
public readonly registry: Registry;
|
||||
|
||||
readonly #Type: Constructor<T>;
|
||||
|
||||
readonly #raw: T;
|
||||
|
||||
constructor (registry: Registry, Type: Constructor<T> | keyof InterfaceTypes, value: Compact<T> | AnyNumber = 0) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
super(registry, Compact.decodeCompact<T>(registry, typeToConstructor(registry, Type), value));
|
||||
this.registry = registry;
|
||||
this.#Type = typeToConstructor(registry, Type);
|
||||
this.#raw = Compact.decodeCompact<T>(registry, this.#Type, value) as T;
|
||||
}
|
||||
|
||||
public static with<T extends CompactEncodable> (Type: Constructor<T> | keyof InterfaceTypes): Constructor<Compact<T>> {
|
||||
@@ -61,7 +69,7 @@ export default class Compact<T extends CompactEncodable> extends Base<T> impleme
|
||||
/** @internal */
|
||||
public static decodeCompact<T extends CompactEncodable> (registry: Registry, Type: Constructor<T>, value: Compact<T> | AnyNumber): CompactEncodable {
|
||||
if (value instanceof Compact) {
|
||||
return new Type(registry, value._raw);
|
||||
return new Type(registry, value.#raw);
|
||||
} else if (isString(value) || isNumber(value) || isBn(value) || isBigInt(value)) {
|
||||
return new Type(registry, value);
|
||||
}
|
||||
@@ -71,20 +79,41 @@ export default class Compact<T extends CompactEncodable> extends Base<T> impleme
|
||||
return new Type(registry, _value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The length of the value when encoded as a Uint8Array
|
||||
*/
|
||||
public get encodedLength (): number {
|
||||
return this.toU8a().length;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Checks if the value is an empty value
|
||||
*/
|
||||
public get isEmpty (): boolean {
|
||||
return this.#raw.isEmpty;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the number of bits in the value
|
||||
*/
|
||||
public bitLength (): number {
|
||||
return this._raw.bitLength();
|
||||
return this.#raw.bitLength();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Compares the value of the input to see if there is a match
|
||||
*/
|
||||
public eq (other?: unknown): boolean {
|
||||
return this._raw.eq(
|
||||
return this.#raw.eq(
|
||||
other instanceof Compact
|
||||
? other._raw
|
||||
? other.#raw
|
||||
: other
|
||||
);
|
||||
}
|
||||
@@ -93,21 +122,49 @@ export default class Compact<T extends CompactEncodable> extends Base<T> impleme
|
||||
* @description Returns the BN representation of the number
|
||||
*/
|
||||
public toBn (): BN {
|
||||
return this._raw.toBn();
|
||||
return this.#raw.toBn();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns a hex string representation of the value. isLe returns a LE (number-only) representation
|
||||
*/
|
||||
public toHex (isLe?: boolean): string {
|
||||
return this.#raw.toHex(isLe);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
||||
*/
|
||||
public toHuman (isExtended?: boolean): AnyJson {
|
||||
return this.#raw.toHuman(isExtended);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Converts the Object to JSON, typically used for RPC transfers
|
||||
*/
|
||||
public toJSON (): AnyJson {
|
||||
return this.#raw.toJSON();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the number representation for the value
|
||||
*/
|
||||
public toNumber (): number {
|
||||
return this._raw.toNumber();
|
||||
return this.#raw.toNumber();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (): string {
|
||||
return `Compact<${this._raw.toRawType()}>`;
|
||||
return `Compact<${this.registry.getClassName(this.#Type) || this.#raw.toRawType()}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the string representation of the value
|
||||
*/
|
||||
public toString (): string {
|
||||
return this.#raw.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -116,13 +173,13 @@ export default class Compact<T extends CompactEncodable> extends Base<T> impleme
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public toU8a (isBare?: boolean): Uint8Array {
|
||||
return Compact.encodeU8a(this._raw.toBn());
|
||||
return Compact.encodeU8a(this.#raw.toBn());
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the embedded [[UInt]] or [[Moment]] value
|
||||
*/
|
||||
public unwrap (): T {
|
||||
return this._raw;
|
||||
return this.#raw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { H256 } from '@polkadot/types/interfaces';
|
||||
import { AnyJson, Codec, Constructor, InterfaceTypes, Registry } from '../types';
|
||||
|
||||
import { assert, hexToU8a, isHex, isNumber, isObject, isString, isU8a, isUndefined, stringCamelCase, stringUpperFirst, u8aConcat, u8aToHex } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Null from '../primitive/Null';
|
||||
import { mapToTypeMap } from './utils';
|
||||
import Base from './Base';
|
||||
import Raw from './Raw';
|
||||
import Struct from './Struct';
|
||||
|
||||
// export interface, this is used in Enum.with, so required as public by TS
|
||||
@@ -114,25 +116,29 @@ function decodeEnum (registry: Registry, def: TypesDef, value?: any, index?: num
|
||||
// TODO:
|
||||
// - As per Enum, actually use TS enum
|
||||
// - It should rather probably extend Enum instead of copying code
|
||||
export default class Enum extends Base<Codec> {
|
||||
private _def: TypesDef;
|
||||
export default class Enum implements Codec {
|
||||
public readonly registry: Registry;
|
||||
|
||||
private _index: number;
|
||||
readonly #def: TypesDef;
|
||||
|
||||
private _indexes: number[];
|
||||
readonly #index: number;
|
||||
|
||||
private _isBasic: boolean;
|
||||
readonly #indexes: number[];
|
||||
|
||||
readonly #isBasic: boolean;
|
||||
|
||||
readonly #raw: Codec;
|
||||
|
||||
constructor (registry: Registry, def: Record<string, keyof InterfaceTypes | Constructor> | string[], value?: unknown, index?: number) {
|
||||
const defInfo = extractDef(registry, def);
|
||||
const decoded = decodeEnum(registry, defInfo.def, value, index);
|
||||
|
||||
super(registry, decoded.value);
|
||||
|
||||
this._def = defInfo.def;
|
||||
this._isBasic = defInfo.isBasic;
|
||||
this._indexes = Object.keys(defInfo.def).map((_, index): number => index);
|
||||
this._index = this._indexes.indexOf(decoded.index) || 0;
|
||||
this.registry = registry;
|
||||
this.#def = defInfo.def;
|
||||
this.#isBasic = defInfo.isBasic;
|
||||
this.#indexes = Object.keys(defInfo.def).map((_, index): number => index);
|
||||
this.#index = this.#indexes.indexOf(decoded.index) || 0;
|
||||
this.#raw = decoded.value;
|
||||
}
|
||||
|
||||
public static with (Types: Record<string, keyof InterfaceTypes | Constructor> | string[]): EnumConstructor<Enum> {
|
||||
@@ -140,7 +146,7 @@ export default class Enum extends Base<Codec> {
|
||||
constructor (registry: Registry, value?: unknown, index?: number) {
|
||||
super(registry, Types, value, index);
|
||||
|
||||
Object.keys(this._def).forEach((_key): void => {
|
||||
Object.keys(this.#def).forEach((_key): void => {
|
||||
const name = stringUpperFirst(stringCamelCase(_key.replace(' ', '_')));
|
||||
const askey = `as${name}`;
|
||||
const iskey = `is${name}`;
|
||||
@@ -175,21 +181,35 @@ export default class Enum extends Base<Codec> {
|
||||
* @description The length of the value when encoded as a Uint8Array
|
||||
*/
|
||||
public get encodedLength (): number {
|
||||
return 1 + this._raw.encodedLength;
|
||||
return 1 + this.#raw.encodedLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The index of the metadata value
|
||||
*/
|
||||
public get index (): number {
|
||||
return this._index;
|
||||
return this.#index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description true if this is a basic enum (no values)
|
||||
*/
|
||||
public get isBasic (): boolean {
|
||||
return this._isBasic;
|
||||
return this.#isBasic;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Checks if the value is an empty value
|
||||
*/
|
||||
public get isEmpty (): boolean {
|
||||
return this.#raw.isEmpty;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -203,35 +223,35 @@ export default class Enum extends Base<Codec> {
|
||||
* @description Checks if the Enum points to a [[Null]] type (deprecated, use isNone)
|
||||
*/
|
||||
public get isNull (): boolean {
|
||||
return this._raw instanceof Null;
|
||||
return this.#raw instanceof Null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The available keys for this enum
|
||||
*/
|
||||
public get defEntries (): string[] {
|
||||
return Object.keys(this._def);
|
||||
return Object.keys(this.#def);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The available keys for this enum
|
||||
*/
|
||||
public get defKeys (): string[] {
|
||||
return Object.keys(this._def);
|
||||
return Object.keys(this.#def);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The name of the type this enum value represents
|
||||
*/
|
||||
public get type (): string {
|
||||
return this.defKeys[this._index];
|
||||
return this.defKeys[this.#index];
|
||||
}
|
||||
|
||||
/**
|
||||
* @description The value of the enum
|
||||
*/
|
||||
public get value (): Codec {
|
||||
return this._raw;
|
||||
return this.#raw;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -241,7 +261,7 @@ export default class Enum extends Base<Codec> {
|
||||
// cater for the case where we only pass the enum index
|
||||
if (isNumber(other)) {
|
||||
return this.toNumber() === other;
|
||||
} else if (this._isBasic && isString(other)) {
|
||||
} else if (this.#isBasic && isString(other)) {
|
||||
return this.type === other;
|
||||
} else if (isU8a(other)) {
|
||||
return !this.toU8a().some((entry, index): boolean => entry !== other[index]);
|
||||
@@ -268,34 +288,34 @@ export default class Enum extends Base<Codec> {
|
||||
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
||||
*/
|
||||
public toHuman (isExtended?: boolean): AnyJson {
|
||||
return this._isBasic
|
||||
return this.#isBasic
|
||||
? this.type
|
||||
: { [this.type]: this._raw.toHuman(isExtended) };
|
||||
: { [this.type]: this.#raw.toHuman(isExtended) };
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Converts the Object to JSON, typically used for RPC transfers
|
||||
*/
|
||||
public toJSON (): AnyJson {
|
||||
return this._isBasic
|
||||
return this.#isBasic
|
||||
? this.type
|
||||
: { [this.type]: this._raw.toJSON() };
|
||||
: { [this.type]: this.#raw.toJSON() };
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the number representation for the value
|
||||
*/
|
||||
public toNumber (): number {
|
||||
return this._index;
|
||||
return this.#index;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns a raw struct representation of the enum types
|
||||
*/
|
||||
protected _toRawStruct (): string[] | Record<string, string> {
|
||||
return this._isBasic
|
||||
return this.#isBasic
|
||||
? this.defKeys
|
||||
: Struct.typesToMap(this.registry, this._def);
|
||||
: Struct.typesToMap(this.registry, this.#def);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -319,11 +339,11 @@ export default class Enum extends Base<Codec> {
|
||||
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
||||
*/
|
||||
public toU8a (isBare?: boolean): Uint8Array {
|
||||
const index = this._indexes[this._index];
|
||||
const index = this.#indexes[this.#index];
|
||||
|
||||
return u8aConcat(
|
||||
new Uint8Array([index]),
|
||||
this._raw.toU8a(isBare)
|
||||
this.#raw.toU8a(isBare)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -180,7 +180,7 @@ export default class CodecMap<K extends Codec = Codec, V extends Codec = Codec>
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (): string {
|
||||
return `${this.#type}<${new this.#KeyClass(this.registry).toRawType()},${new this.#ValClass(this.registry).toRawType()}>`;
|
||||
return `${this.#type}<${this.registry.getClassName(this.#KeyClass) || new this.#KeyClass(this.registry).toRawType()},${this.registry.getClassName(this.#ValClass) || new this.#ValClass(this.registry).toRawType()}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -2,13 +2,15 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Codec, Constructor, InterfaceTypes, Registry } from '../types';
|
||||
import { H256 } from '@polkadot/types/interfaces';
|
||||
import { AnyJson, Codec, Constructor, InterfaceTypes, Registry } from '../types';
|
||||
|
||||
import { isNull, isU8a, isUndefined, u8aToHex } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
import Null from '../primitive/Null';
|
||||
import { typeToConstructor } from './utils';
|
||||
import Base from './Base';
|
||||
import Raw from './Raw';
|
||||
|
||||
/** @internal */
|
||||
function decodeOptionU8a (registry: Registry, Type: Constructor, value: Uint8Array): Codec {
|
||||
@@ -48,15 +50,17 @@ function decodeOption (registry: Registry, typeName: Constructor | keyof Interfa
|
||||
* implements that - decodes, checks for optionality and wraps the required structure
|
||||
* with a value if/as required/found.
|
||||
*/
|
||||
export default class Option<T extends Codec> extends Base<T> {
|
||||
export default class Option<T extends Codec> implements Codec {
|
||||
public readonly registry: Registry;
|
||||
|
||||
readonly #Type: Constructor<T>;
|
||||
|
||||
constructor (registry: Registry, typeName: Constructor<T> | keyof InterfaceTypes, value?: unknown) {
|
||||
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||||
// @ts-ignore
|
||||
super(registry, decodeOption(registry, typeName, value));
|
||||
readonly #raw: T;
|
||||
|
||||
constructor (registry: Registry, typeName: Constructor<T> | keyof InterfaceTypes, value?: unknown) {
|
||||
this.registry = registry;
|
||||
this.#Type = typeToConstructor(registry, typeName);
|
||||
this.#raw = decodeOption(registry, typeName, value) as T;
|
||||
}
|
||||
|
||||
public static with<O extends Codec> (Type: Constructor<O> | keyof InterfaceTypes): Constructor<Option<O>> {
|
||||
@@ -72,7 +76,14 @@ export default class Option<T extends Codec> extends Base<T> {
|
||||
*/
|
||||
public get encodedLength (): number {
|
||||
// boolean byte (has value, doesn't have) along with wrapped length
|
||||
return 1 + this._raw.encodedLength;
|
||||
return 1 + this.#raw.encodedLength;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description returns a hash of the contents
|
||||
*/
|
||||
public get hash (): H256 {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -86,7 +97,7 @@ export default class Option<T extends Codec> extends Base<T> {
|
||||
* @description Checks if the Option has no value
|
||||
*/
|
||||
public get isNone (): boolean {
|
||||
return this._raw instanceof Null;
|
||||
return this.#raw instanceof Null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,7 +111,7 @@ export default class Option<T extends Codec> extends Base<T> {
|
||||
* @description The actual value for the Option
|
||||
*/
|
||||
public get value (): Codec {
|
||||
return this._raw;
|
||||
return this.#raw;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -125,31 +136,52 @@ export default class Option<T extends Codec> extends Base<T> {
|
||||
: u8aToHex(this.toU8a().subarray(1));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Converts the Object to to a human-friendly JSON, with additional fields, expansion and formatting of information
|
||||
*/
|
||||
public toHuman (isExtended?: boolean): AnyJson {
|
||||
return this.#raw.toHuman(isExtended);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Converts the Object to JSON, typically used for RPC transfers
|
||||
*/
|
||||
public toJSON (): AnyJson {
|
||||
return this.#raw.toJSON();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (isBare?: boolean): string {
|
||||
const wrapped = new this.#Type(this.registry).toRawType();
|
||||
const wrapped = this.registry.getClassName(this.#Type) || new this.#Type(this.registry).toRawType();
|
||||
|
||||
return isBare
|
||||
? wrapped
|
||||
: `Option<${wrapped}>`;
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the string representation of the value
|
||||
*/
|
||||
public toString (): string {
|
||||
return this.#raw.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Encodes the value as a Uint8Array as per the SCALE specifications
|
||||
* @param isBare true when the value has none of the type-specific prefixes (internal)
|
||||
*/
|
||||
public toU8a (isBare?: boolean): Uint8Array {
|
||||
if (isBare) {
|
||||
return this._raw.toU8a(true);
|
||||
return this.#raw.toU8a(true);
|
||||
}
|
||||
|
||||
const u8a = new Uint8Array(this.encodedLength);
|
||||
|
||||
if (this.isSome) {
|
||||
u8a.set([1]);
|
||||
u8a.set(this._raw.toU8a(), 1);
|
||||
u8a.set(this.#raw.toU8a(), 1);
|
||||
}
|
||||
|
||||
return u8a;
|
||||
@@ -163,7 +195,7 @@ export default class Option<T extends Codec> extends Base<T> {
|
||||
throw new Error('Option: unwrapping a None value');
|
||||
}
|
||||
|
||||
return this._raw;
|
||||
return this.#raw;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,7 @@ const testEncode = (to: CodecTo, expected: any): void =>
|
||||
expect(e[to]()).toEqual(expected);
|
||||
});
|
||||
|
||||
describe('U8a', (): void => {
|
||||
describe('Raw', (): void => {
|
||||
let u8a: Raw;
|
||||
|
||||
beforeEach((): void => {
|
||||
@@ -74,5 +74,21 @@ describe('U8a', (): void => {
|
||||
it('compares against hex inputs', (): void => {
|
||||
expect(u8a.eq('0x0102030405')).toBe(true);
|
||||
});
|
||||
|
||||
it('has valid isAscii', (): void => {
|
||||
expect(u8a.isAscii).toBe(false);
|
||||
expect(new Raw(registry, '0x2021222324').isAscii).toBe(true);
|
||||
});
|
||||
|
||||
it('has valid toUtf8', (): void => {
|
||||
expect(new Raw(registry, 'Приветствую, ми').toUtf8()).toEqual('Приветствую, ми');
|
||||
expect(new Raw(registry, '0xe4bda0e5a5bd').toUtf8()).toEqual('你好');
|
||||
});
|
||||
|
||||
it('throws on invalid utf8', (): void => {
|
||||
expect(
|
||||
() => new Raw(registry, '0x7f07b1f87709608bee603bbc79a0dfc29cd315c1351a83aa31adf7458d7d3003').toUtf8()
|
||||
).toThrow(/The character sequence is not a valid Utf8 string/);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
import { H256 } from '../interfaces/runtime';
|
||||
import { AnyJson, AnyU8a, IU8a, Registry } from '../types';
|
||||
|
||||
import { isU8a, isUndefined, u8aToHex, u8aToU8a } from '@polkadot/util';
|
||||
import { assert, isAscii, isU8a, isUndefined, isUtf8, u8aToHex, u8aToString, u8aToU8a } from '@polkadot/util';
|
||||
import { blake2AsU8a } from '@polkadot/util-crypto';
|
||||
|
||||
/** @internal */
|
||||
@@ -49,11 +49,25 @@ export default class Raw extends Uint8Array implements IU8a {
|
||||
return new Raw(this.registry, blake2AsU8a(this.toU8a(), 256));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true if the wrapped value contains only ASCII printable characters
|
||||
*/
|
||||
public get isAscii (): boolean {
|
||||
return isAscii(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true if the type wraps an empty/default all-0 value
|
||||
*/
|
||||
public get isEmpty (): boolean {
|
||||
return !this.length || isUndefined(this.find((value): boolean => !!value));
|
||||
return !this.length || isUndefined(this.find((value) => !!value));
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns true if the wrapped value contains only utf8 characters
|
||||
*/
|
||||
public get isUtf8 (): boolean {
|
||||
return isUtf8(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -77,7 +91,7 @@ export default class Raw extends Uint8Array implements IU8a {
|
||||
public eq (other?: unknown): boolean {
|
||||
if (other instanceof Uint8Array) {
|
||||
return (this.length === other.length) &&
|
||||
!this.some((value, index): boolean => value !== other[index]);
|
||||
!this.some((value, index) => value !== other[index]);
|
||||
}
|
||||
|
||||
return this.eq(decodeU8a(other));
|
||||
@@ -103,7 +117,9 @@ 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.toJSON();
|
||||
return this.isAscii
|
||||
? this.toUtf8()
|
||||
: this.toJSON();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,4 +151,13 @@ export default class Raw extends Uint8Array implements IU8a {
|
||||
public toU8a (isBare?: boolean): Uint8Array {
|
||||
return Uint8Array.from(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Returns the wrapped data as a UTF-8 string
|
||||
*/
|
||||
public toUtf8 (): string {
|
||||
assert(this.isUtf8, 'The character sequence is not a valid Utf8 string');
|
||||
|
||||
return u8aToString(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -58,6 +58,6 @@ describe('Result', (): void => {
|
||||
});
|
||||
|
||||
it('returns a proper raw typedef rom a built-in', (): void => {
|
||||
expect(registry.createType('DispatchResult').toRawType()).toEqual('Result<(),{"_enum":{"Other":"Null","CannotLookup":"Null","BadOrigin":"Null","Module":"{\\"index\\":\\"u8\\",\\"error\\":\\"u8\\"}"}}>');
|
||||
expect(registry.createType('DispatchResult').toRawType()).toEqual('Result<(),DispatchError>');
|
||||
});
|
||||
});
|
||||
|
||||
@@ -50,7 +50,7 @@ export default class Result<O extends Codec, E extends Codec> extends Enum {
|
||||
* @description Checks if the Result has no value
|
||||
*/
|
||||
public get isEmpty (): boolean {
|
||||
return this.isOk && this._raw.isEmpty;
|
||||
return this.isOk && this.value.isEmpty;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
/* eslint-disable sort-keys */
|
||||
|
||||
import { TypeRegistry } from '../create';
|
||||
import AccountId from '../generic/AccountId';
|
||||
import Text from '../primitive/Text';
|
||||
import U32 from '../primitive/U32';
|
||||
import { CodecTo } from '../types';
|
||||
@@ -221,20 +220,20 @@ describe('Struct', (): void => {
|
||||
it('generates sane toRawType', (): void => {
|
||||
expect(
|
||||
new Struct(registry, {
|
||||
accountId: AccountId,
|
||||
accountId: 'AccountId',
|
||||
balanceCompact: registry.createClass('Compact<Balance>'),
|
||||
blockNumber: registry.createClass('BlockNumber'),
|
||||
compactNumber: registry.createClass('Compact<BlockNumber>'),
|
||||
optionNumber: registry.createClass('Option<BlockNumber>'),
|
||||
counter: U32,
|
||||
vector: Vec.with(AccountId)
|
||||
vector: Vec.with('AccountId')
|
||||
}).toRawType()
|
||||
).toEqual(JSON.stringify({
|
||||
accountId: 'AccountId',
|
||||
balanceCompact: 'Compact<Balance>', // Override in Uint
|
||||
blockNumber: 'u32',
|
||||
compactNumber: 'Compact<u32>',
|
||||
optionNumber: 'Option<u32>',
|
||||
blockNumber: 'BlockNumber',
|
||||
compactNumber: 'Compact<BlockNumber>',
|
||||
optionNumber: 'Option<BlockNumber>',
|
||||
counter: 'u32',
|
||||
vector: 'Vec<AccountId>'
|
||||
}));
|
||||
@@ -242,7 +241,7 @@ describe('Struct', (): void => {
|
||||
|
||||
it('generates sane toRawType (via with)', (): void => {
|
||||
const Type = Struct.with({
|
||||
accountId: AccountId,
|
||||
accountId: 'AccountId',
|
||||
balance: registry.createClass('Balance')
|
||||
});
|
||||
|
||||
|
||||
@@ -267,11 +267,11 @@ export default class Struct<
|
||||
}
|
||||
|
||||
public static typesToMap (registry: Registry, Types: Record<string, Constructor>): Record<string, string> {
|
||||
return Object.entries(Types).reduce((result, [key, Type]): Record<string, string> => {
|
||||
result[key] = new Type(registry).toRawType();
|
||||
return Object.entries(Types).reduce((result: Record<string, string>, [key, Type]): Record<string, string> => {
|
||||
result[key] = registry.getClassName(Type) || new Type(registry).toRawType();
|
||||
|
||||
return result;
|
||||
}, {} as Record<string, string>);
|
||||
}, {});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -131,14 +131,14 @@ describe('Tuple', (): void => {
|
||||
it('generates sane value with array types', (): void => {
|
||||
expect(
|
||||
new Tuple(registry, [U128, registry.createClass('BlockNumber')]).toRawType()
|
||||
).toEqual('(u128,u32)');
|
||||
).toEqual('(u128,BlockNumber)');
|
||||
});
|
||||
|
||||
it('generates sane value with object types', (): void => {
|
||||
expect(
|
||||
// eslint-disable-next-line sort-keys
|
||||
new Tuple(registry, { number: U128, blockNumber: registry.createClass('BlockNumber') }).toRawType()
|
||||
).toEqual('(u128,u32)');
|
||||
).toEqual('(u128,BlockNumber)');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -101,7 +101,9 @@ export default class Tuple extends AbstractArray<Codec> {
|
||||
Array.isArray(this._Types)
|
||||
? this._Types
|
||||
: Object.values(this._Types)
|
||||
).map((Type): string => new Type(this.registry).toRawType());
|
||||
).map((Type) =>
|
||||
this.registry.getClassName(Type) || new Type(this.registry).toRawType()
|
||||
);
|
||||
|
||||
return `(${types.join(',')})`;
|
||||
}
|
||||
|
||||
@@ -8,10 +8,11 @@ import { isString, u8aToU8a } from '@polkadot/util';
|
||||
|
||||
import Raw from './Raw';
|
||||
|
||||
// The 520 here is a weird one - it is explicitly for a [u8; 65] as found as a EcdsaSignature
|
||||
// The 520 here is a weird one - it is explicitly for a [u8; 65] as found as a EcdsaSignature,
|
||||
// and 264 here is explicity for a [u8; 33] as found as EcdsaPublic key.
|
||||
// Likewise 160 is for [u8; 20], which is also a H160, i.e. an Ethereum address. Both these are
|
||||
// as a result of the Polkadot claims module. (Technically we don't need the 520 in here)
|
||||
export type BitLength = 8 | 16 | 32 | 64 | 128 | 160 | 256 | 512 | 520 | 1024 | 2048;
|
||||
export type BitLength = 8 | 16 | 32 | 64 | 128 | 160 | 256 | 264 | 512 | 520 | 1024 | 2048;
|
||||
|
||||
/** @internal */
|
||||
function decodeU8aFixed (value: AnyU8a, bitLength: BitLength): AnyU8a {
|
||||
|
||||
@@ -16,6 +16,12 @@ describe('UInt', (): void => {
|
||||
).toThrow('u32: Input too large. Found input with 164 bits, expected 32');
|
||||
});
|
||||
|
||||
it('fails on negative numbers', (): void => {
|
||||
expect(
|
||||
(): UInt => new UInt(registry, -123, 32)
|
||||
).toThrow('u32: Negative number passed to unsigned type');
|
||||
});
|
||||
|
||||
it('allows for construction via BigInt', (): void => {
|
||||
expect(
|
||||
new UInt(registry, 123456789123456789123456789n, 128).toHuman()
|
||||
|
||||
@@ -92,6 +92,6 @@ export default class Vec<T extends Codec> extends AbstractArray<T> {
|
||||
* @description Returns the base runtime type name for this instance
|
||||
*/
|
||||
public toRawType (): string {
|
||||
return `Vec<${new this._Type(this.registry).toRawType()}>`;
|
||||
return `Vec<${this.registry.getClassName(this._Type) || new this._Type(this.registry).toRawType()}>`;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ const infoMapping: Record<TypeDefInfo, (registry: Registry, value: TypeDef) => C
|
||||
const Clazz = Struct.with({ previous: type, next: type } as any);
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||
ClassOf.prototype.toRawType = function (): string {
|
||||
Clazz.prototype.toRawType = function (): string {
|
||||
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions,@typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call
|
||||
return `Linkage<${this.next.toRawType(true)}>`;
|
||||
};
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { TypeDef, TypeDefInfo } from './types';
|
||||
|
||||
import { getTypeDef } from '.';
|
||||
import { TypeRegistry, getTypeDef } from '.';
|
||||
|
||||
describe('getTypeDef', (): void => {
|
||||
it('does not allow invalid tuples, end )', (): void => {
|
||||
@@ -290,4 +290,32 @@ describe('getTypeDef', (): void => {
|
||||
type: '[[u8;32];3]'
|
||||
});
|
||||
});
|
||||
|
||||
it('creates recursive structures', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
|
||||
registry.register({
|
||||
Recursive: {
|
||||
data: 'Vec<Recursive>'
|
||||
}
|
||||
});
|
||||
|
||||
const raw = registry.createType('Recursive' as 'u32').toRawType();
|
||||
|
||||
expect(
|
||||
getTypeDef(raw)
|
||||
).toEqual({
|
||||
info: TypeDefInfo.Struct,
|
||||
sub: [{
|
||||
info: TypeDefInfo.Vec,
|
||||
name: 'data',
|
||||
sub: {
|
||||
info: TypeDefInfo.Plain,
|
||||
type: 'Recursive'
|
||||
},
|
||||
type: 'Vec<Recursive>'
|
||||
}],
|
||||
type: '{"data":"Vec<Recursive>"}'
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -9,10 +9,17 @@ import { assert } from '@polkadot/util';
|
||||
import sanitize from './sanitize';
|
||||
import { typeSplit } from './typeSplit';
|
||||
|
||||
interface TypeDefOptions {
|
||||
name?: string;
|
||||
displayName?: string;
|
||||
}
|
||||
|
||||
const MAX_NESTED = 64;
|
||||
|
||||
// decode an enum of either of the following forms
|
||||
// { _enum: ['A', 'B', 'C'] }
|
||||
// { _enum: { A: AccountId, B: Balance, C: u32 } }
|
||||
function _decodeEnum (value: TypeDef, details: string[] | Record<string, string>): TypeDef {
|
||||
function _decodeEnum (value: TypeDef, details: string[] | Record<string, string>, count: number): TypeDef {
|
||||
value.info = TypeDefInfo.Enum;
|
||||
|
||||
// not as pretty, but remain compatible with oo7 for both struct and Array types
|
||||
@@ -24,7 +31,7 @@ function _decodeEnum (value: TypeDef, details: string[] | Record<string, string>
|
||||
}))
|
||||
: Object.entries(details).map(([name, type]): TypeDef =>
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
getTypeDef(type || 'Null', { name })
|
||||
getTypeDef(type || 'Null', { name }, count)
|
||||
);
|
||||
|
||||
return value;
|
||||
@@ -50,13 +57,13 @@ function _decodeSet (value: TypeDef, details: Record<string, number>): TypeDef {
|
||||
|
||||
// decode a struct, set or enum
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function _decodeStruct (value: TypeDef, type: string, _: string): TypeDef {
|
||||
function _decodeStruct (value: TypeDef, type: string, _: string, count: number): TypeDef {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||
const parsed: Record<string, any> = JSON.parse(type);
|
||||
const keys = Object.keys(parsed);
|
||||
|
||||
if (keys.length === 1 && keys[0] === '_enum') {
|
||||
return _decodeEnum(value, parsed[keys[0]]);
|
||||
return _decodeEnum(value, parsed[keys[0]], count);
|
||||
} else if (keys.length === 1 && keys[0] === '_set') {
|
||||
return _decodeSet(value, parsed[keys[0]]);
|
||||
}
|
||||
@@ -66,7 +73,7 @@ function _decodeStruct (value: TypeDef, type: string, _: string): TypeDef {
|
||||
: undefined;
|
||||
value.sub = keys.filter((name) => !['_alias'].includes(name)).map((name): TypeDef =>
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
getTypeDef(parsed[name], { name })
|
||||
getTypeDef(parsed[name], { name }, count)
|
||||
);
|
||||
|
||||
return value;
|
||||
@@ -74,7 +81,7 @@ function _decodeStruct (value: TypeDef, type: string, _: string): TypeDef {
|
||||
|
||||
// decode a fixed vector, e.g. [u8;32]
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function _decodeFixedVec (value: TypeDef, type: string, _: string): TypeDef {
|
||||
function _decodeFixedVec (value: TypeDef, type: string, _: string, count: number): TypeDef {
|
||||
const [vecType, strLength, displayName] = type.substr(1, type.length - 2).split(';');
|
||||
const length = parseInt(strLength.trim(), 10);
|
||||
|
||||
@@ -84,18 +91,18 @@ function _decodeFixedVec (value: TypeDef, type: string, _: string): TypeDef {
|
||||
value.displayName = displayName;
|
||||
value.length = length;
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
value.sub = getTypeDef(vecType);
|
||||
value.sub = getTypeDef(vecType, {}, count);
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
// decode a tuple
|
||||
function _decodeTuple (value: TypeDef, _: string, subType: string): TypeDef {
|
||||
function _decodeTuple (value: TypeDef, _: string, subType: string, count: number): TypeDef {
|
||||
value.sub = subType.length === 0
|
||||
? []
|
||||
: typeSplit(subType).map((inner): TypeDef =>
|
||||
// eslint-disable-next-line @typescript-eslint/no-use-before-define
|
||||
getTypeDef(inner)
|
||||
getTypeDef(inner, {}, count)
|
||||
);
|
||||
|
||||
return value;
|
||||
@@ -103,7 +110,7 @@ function _decodeTuple (value: TypeDef, _: string, subType: string): TypeDef {
|
||||
|
||||
// decode a Int/UInt<bitLength[, name]>
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
function _decodeInt (value: TypeDef, type: string, _: string, clazz: 'Int' | 'UInt' = 'Int'): TypeDef {
|
||||
function _decodeAnyInt (value: TypeDef, type: string, _: string, clazz: 'Int' | 'UInt'): TypeDef {
|
||||
const [strLength, displayName] = type.substr(clazz.length + 1, type.length - clazz.length - 1 - 1).split(',');
|
||||
const length = parseInt(strLength.trim(), 10);
|
||||
|
||||
@@ -116,8 +123,12 @@ function _decodeInt (value: TypeDef, type: string, _: string, clazz: 'Int' | 'UI
|
||||
return value;
|
||||
}
|
||||
|
||||
function _decodeInt (value: TypeDef, type: string, subType: string): TypeDef {
|
||||
return _decodeAnyInt(value, type, subType, 'Int');
|
||||
}
|
||||
|
||||
function _decodeUInt (value: TypeDef, type: string, subType: string): TypeDef {
|
||||
return _decodeInt(value, type, subType, 'UInt');
|
||||
return _decodeAnyInt(value, type, subType, 'UInt');
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
@@ -139,7 +150,7 @@ function hasWrapper (type: string, [start, end]: [string, string, TypeDefInfo, a
|
||||
return true;
|
||||
}
|
||||
|
||||
const nestedExtraction: [string, string, TypeDefInfo, (value: TypeDef, type: string, subType: string) => TypeDef][] = [
|
||||
const nestedExtraction: [string, string, TypeDefInfo, (value: TypeDef, type: string, subType: string, count: number) => TypeDef][] = [
|
||||
['[', ']', TypeDefInfo.VecFixed, _decodeFixedVec],
|
||||
['{', '}', TypeDefInfo.Struct, _decodeStruct],
|
||||
['(', ')', TypeDefInfo.Tuple, _decodeTuple],
|
||||
@@ -164,15 +175,17 @@ function extractSubType (type: string, [start, end]: [string, string, TypeDefInf
|
||||
return type.substr(start.length, type.length - start.length - end.length);
|
||||
}
|
||||
|
||||
interface TypeDefOptions {
|
||||
name?: string;
|
||||
displayName?: string;
|
||||
}
|
||||
|
||||
export function getTypeDef (_type: string, { displayName, name }: TypeDefOptions = {}): TypeDef {
|
||||
export function getTypeDef (_type: string, { displayName, name }: TypeDefOptions = {}, count = 0): TypeDef {
|
||||
// create the type via Type, allowing types to be sanitized
|
||||
const type = sanitize(_type);
|
||||
const value: TypeDef = { displayName, info: TypeDefInfo.Plain, name, type };
|
||||
|
||||
if (++count === MAX_NESTED) {
|
||||
console.warn('getTypeDef: Maximum nested limit reached');
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
const nested = nestedExtraction.find((nested): boolean =>
|
||||
hasWrapper(type, nested)
|
||||
);
|
||||
@@ -180,7 +193,7 @@ export function getTypeDef (_type: string, { displayName, name }: TypeDefOptions
|
||||
if (nested) {
|
||||
value.info = nested[2];
|
||||
|
||||
return nested[3](value, type, extractSubType(type, nested));
|
||||
return nested[3](value, type, extractSubType(type, nested), count);
|
||||
}
|
||||
|
||||
const wrapped = wrappedExtraction.find((wrapped): boolean =>
|
||||
@@ -189,7 +202,7 @@ export function getTypeDef (_type: string, { displayName, name }: TypeDefOptions
|
||||
|
||||
if (wrapped) {
|
||||
value.info = wrapped[2];
|
||||
value.sub = getTypeDef(extractSubType(type, wrapped));
|
||||
value.sub = getTypeDef(extractSubType(type, wrapped), {}, count);
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@@ -76,7 +76,35 @@ describe('TypeRegistry', (): void => {
|
||||
expect((first as any).next.unwrap().next.isSome).toBe(false);
|
||||
});
|
||||
|
||||
it('can register cross-referencing types ()', (): void => {
|
||||
it('can register non-embedded recursive types', (): void => {
|
||||
registry.register({
|
||||
Operation: {
|
||||
data: 'OperationData'
|
||||
},
|
||||
OperationData: {
|
||||
ops: 'Vec<Operation>'
|
||||
},
|
||||
Rule: {
|
||||
data: 'RuleData'
|
||||
},
|
||||
RuleData: {
|
||||
ops: 'Vec<Operation>'
|
||||
}
|
||||
});
|
||||
|
||||
expect(registry.hasDef('Rule')).toBe(true);
|
||||
expect(registry.hasClass('Rule')).toBe(false);
|
||||
|
||||
const Rule = registry.getOrThrow('Rule');
|
||||
|
||||
expect(registry.hasClass('Rule')).toBe(true);
|
||||
|
||||
const instance = new Rule(registry);
|
||||
|
||||
expect(instance.toRawType()).toEqual('{"data":"RuleData"}');
|
||||
});
|
||||
|
||||
it('can register cross-referencing types', (): void => {
|
||||
registry.register({
|
||||
A: {
|
||||
next: 'B'
|
||||
|
||||
@@ -153,7 +153,7 @@ export class TypeRegistry implements Registry {
|
||||
/**
|
||||
* @description Creates an instance of a type as registered
|
||||
*/
|
||||
public createType <K extends keyof InterfaceTypes> (type: K, ...params: any[]): InterfaceTypes[K] {
|
||||
public createType <K extends keyof InterfaceTypes> (type: K, ...params: unknown[]): InterfaceTypes[K] {
|
||||
return createType(this, type, ...params);
|
||||
}
|
||||
|
||||
@@ -225,6 +225,14 @@ export class TypeRegistry implements Registry {
|
||||
return this.#chainProperties;
|
||||
}
|
||||
|
||||
public getClassName (clazz: Constructor): string | undefined {
|
||||
const entry = [...this.#classes.entries()].find(([, test]) => test === clazz);
|
||||
|
||||
return entry
|
||||
? entry[0]
|
||||
: undefined;
|
||||
}
|
||||
|
||||
public getDefinition (name: string): string | undefined {
|
||||
return this.#definitions.get(name);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export default {
|
||||
extra: {},
|
||||
types: {}
|
||||
};
|
||||
@@ -4,29 +4,13 @@
|
||||
|
||||
import { ExtDef } from './types';
|
||||
|
||||
import EmptyCheck from './emptyCheck';
|
||||
|
||||
export default {
|
||||
LimitParathreadCommits: {
|
||||
extra: {},
|
||||
types: {}
|
||||
},
|
||||
OnlyStakingAndClaims: {
|
||||
extra: {},
|
||||
types: {}
|
||||
},
|
||||
PrevalidateAttests: {
|
||||
extra: {},
|
||||
types: {}
|
||||
},
|
||||
RestrictFunctionality: {
|
||||
extra: {},
|
||||
types: {}
|
||||
},
|
||||
TransactionCallFilter: {
|
||||
extra: {},
|
||||
types: {}
|
||||
},
|
||||
ValidateDoubleVoteReports: {
|
||||
extra: {},
|
||||
types: {}
|
||||
}
|
||||
LimitParathreadCommits: EmptyCheck,
|
||||
OnlyStakingAndClaims: EmptyCheck,
|
||||
PrevalidateAttests: EmptyCheck,
|
||||
RestrictFunctionality: EmptyCheck,
|
||||
TransactionCallFilter: EmptyCheck,
|
||||
ValidateDoubleVoteReports: EmptyCheck
|
||||
} as ExtDef;
|
||||
|
||||
@@ -4,6 +4,17 @@
|
||||
|
||||
import { ExtDef } from './types';
|
||||
|
||||
import EmptyCheck from './emptyCheck';
|
||||
|
||||
const CheckMortality = {
|
||||
extra: {
|
||||
blockHash: 'Hash'
|
||||
},
|
||||
types: {
|
||||
era: 'ExtrinsicEra'
|
||||
}
|
||||
};
|
||||
|
||||
export default {
|
||||
ChargeTransactionPayment: {
|
||||
extra: {},
|
||||
@@ -11,24 +22,15 @@ export default {
|
||||
tip: 'Compact<Balance>'
|
||||
}
|
||||
},
|
||||
CheckBlockGasLimit: {
|
||||
extra: {},
|
||||
types: {}
|
||||
},
|
||||
CheckEra: {
|
||||
extra: {
|
||||
blockHash: 'Hash'
|
||||
},
|
||||
types: {
|
||||
era: 'ExtrinsicEra'
|
||||
}
|
||||
},
|
||||
CheckBlockGasLimit: EmptyCheck,
|
||||
CheckEra: CheckMortality,
|
||||
CheckGenesis: {
|
||||
extra: {
|
||||
genesisHash: 'Hash'
|
||||
},
|
||||
types: {}
|
||||
},
|
||||
CheckMortality,
|
||||
CheckNonce: {
|
||||
extra: {},
|
||||
types: {
|
||||
@@ -53,16 +55,7 @@ export default {
|
||||
},
|
||||
types: {}
|
||||
},
|
||||
CheckWeight: {
|
||||
extra: {},
|
||||
types: {}
|
||||
},
|
||||
LockStakingStatus: {
|
||||
extra: {},
|
||||
types: {}
|
||||
},
|
||||
ValidateEquivocationReport: {
|
||||
extra: {},
|
||||
types: {}
|
||||
}
|
||||
CheckWeight: EmptyCheck,
|
||||
LockStakingStatus: EmptyCheck,
|
||||
ValidateEquivocationReport: EmptyCheck
|
||||
} as ExtDef;
|
||||
|
||||
@@ -24,15 +24,7 @@ describe('Block', (): void => {
|
||||
).toEqual(
|
||||
// each of the containing structures have been stringified on their own
|
||||
JSON.stringify({
|
||||
header: JSON.stringify({
|
||||
parentHash: 'H256',
|
||||
number: 'Compact<u32>',
|
||||
stateRoot: 'H256',
|
||||
extrinsicsRoot: 'H256',
|
||||
digest: JSON.stringify({
|
||||
logs: 'Vec<{"_enum":{"Other":"Bytes","AuthoritiesChange":"Vec<AccountId>","ChangesTrieRoot":"H256","SealV0":"(u64,H512)","Consensus":"(u32,Bytes)","Seal":"(u32,Bytes)","PreRuntime":"(u32,Bytes)"}}>'
|
||||
})
|
||||
}),
|
||||
header: 'Header',
|
||||
extrinsics: 'Vec<Extrinsic>'
|
||||
})
|
||||
);
|
||||
|
||||
@@ -21,10 +21,15 @@ export default {
|
||||
},
|
||||
BabeAuthorityWeight: 'u64',
|
||||
BabeBlockWeight: 'u32',
|
||||
BabeEquivocationProof: {
|
||||
offender: 'AuthorityId',
|
||||
slotNumber: 'SlotNumber',
|
||||
firstHeader: 'Header',
|
||||
secondHeader: 'Header'
|
||||
},
|
||||
BabeWeight: 'u64',
|
||||
MaybeRandomness: 'Option<Randomness>',
|
||||
MaybeVrf: 'Option<VrfData>',
|
||||
// TODO Remove as soon as merged and metadata static updated
|
||||
BabeWeight: 'u64',
|
||||
EpochAuthorship: {
|
||||
primary: 'Vec<u64>',
|
||||
secondary: 'Vec<u64>'
|
||||
|
||||
@@ -4,7 +4,8 @@
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
import { Enum, Option, Struct, U8aFixed, Vec } from '@polkadot/types/codec';
|
||||
import { u32, u64 } from '@polkadot/types/primitive';
|
||||
import { Hash } from '@polkadot/types/interfaces/runtime';
|
||||
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
|
||||
import { Hash, Header } from '@polkadot/types/interfaces/runtime';
|
||||
|
||||
/** @name AllowedSlots */
|
||||
export interface AllowedSlots extends Enum {
|
||||
@@ -19,6 +20,14 @@ export interface BabeAuthorityWeight extends u64 {}
|
||||
/** @name BabeBlockWeight */
|
||||
export interface BabeBlockWeight extends u32 {}
|
||||
|
||||
/** @name BabeEquivocationProof */
|
||||
export interface BabeEquivocationProof extends Struct {
|
||||
readonly offender: AuthorityId;
|
||||
readonly slotNumber: SlotNumber;
|
||||
readonly firstHeader: Header;
|
||||
readonly secondHeader: Header;
|
||||
}
|
||||
|
||||
/** @name BabeWeight */
|
||||
export interface BabeWeight extends u64 {}
|
||||
|
||||
|
||||
@@ -30,9 +30,6 @@ export default {
|
||||
BalanceStatus: {
|
||||
_enum: ['Free', 'Reserved']
|
||||
},
|
||||
ReleasesBalances: {
|
||||
_enum: ['V1_0_0', 'V2_0_0']
|
||||
},
|
||||
Reasons: {
|
||||
_enum: ['Fee', 'Misc', 'All']
|
||||
},
|
||||
|
||||
@@ -40,12 +40,6 @@ export interface Reasons extends Enum {
|
||||
readonly isAll: boolean;
|
||||
}
|
||||
|
||||
/** @name ReleasesBalances */
|
||||
export interface ReleasesBalances extends Enum {
|
||||
readonly isV100: boolean;
|
||||
readonly isV200: boolean;
|
||||
}
|
||||
|
||||
/** @name VestingSchedule */
|
||||
export interface VestingSchedule extends Struct {
|
||||
readonly offset: Balance;
|
||||
|
||||
@@ -76,10 +76,21 @@ export default {
|
||||
gasLimit: 'u64',
|
||||
inputData: 'Bytes'
|
||||
},
|
||||
ContractExecResultSuccess: {
|
||||
ContractExecResultSuccessTo255: {
|
||||
status: 'u8',
|
||||
data: 'Raw'
|
||||
},
|
||||
ContractExecResultTo255: {
|
||||
_enum: {
|
||||
Success: 'ContractExecResultSuccessTo255',
|
||||
Error: 'Null'
|
||||
}
|
||||
},
|
||||
ContractExecResultSuccess: {
|
||||
flags: 'u32',
|
||||
data: 'Vec<u8>',
|
||||
gasConsumed: 'u64'
|
||||
},
|
||||
ContractExecResult: {
|
||||
_enum: {
|
||||
Success: 'ContractExecResultSuccess',
|
||||
|
||||
@@ -36,10 +36,24 @@ export interface ContractExecResult extends Enum {
|
||||
|
||||
/** @name ContractExecResultSuccess */
|
||||
export interface ContractExecResultSuccess extends Struct {
|
||||
readonly flags: u32;
|
||||
readonly data: Bytes;
|
||||
readonly gasConsumed: u64;
|
||||
}
|
||||
|
||||
/** @name ContractExecResultSuccessTo255 */
|
||||
export interface ContractExecResultSuccessTo255 extends Struct {
|
||||
readonly status: u8;
|
||||
readonly data: Raw;
|
||||
}
|
||||
|
||||
/** @name ContractExecResultTo255 */
|
||||
export interface ContractExecResultTo255 extends Enum {
|
||||
readonly isSuccess: boolean;
|
||||
readonly asSuccess: ContractExecResultSuccessTo255;
|
||||
readonly isError: boolean;
|
||||
}
|
||||
|
||||
/** @name ContractInfo */
|
||||
export interface ContractInfo extends Enum {
|
||||
readonly isAlive: boolean;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user