Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4fd74a04c8 | ||
|
|
421594b0eb | ||
|
|
2e79c25da1 | ||
|
|
ca2a313aec | ||
|
|
693315dad3 | ||
|
|
c2f9ef7ca8 | ||
|
|
fc477b98bd | ||
|
|
b8cdfd226a | ||
|
|
a5725d7bd6 | ||
|
|
8995ef6ae2 | ||
|
|
742baa3dad | ||
|
|
3a37bf1e6b | ||
|
|
f4b51f6311 | ||
|
|
a09fc51693 | ||
|
|
1d8b6a79ef | ||
|
|
164a1b6867 | ||
|
|
032f2dc040 | ||
|
|
3dbe33378c | ||
|
|
bb08ac4a28 | ||
|
|
4656d32e22 | ||
|
|
60c982ed95 | ||
|
|
cacafab912 | ||
|
|
99d4806a0d | ||
|
|
59a194a48d | ||
|
|
d818f61dc8 | ||
|
|
f1cbfff5a6 | ||
|
|
92cdc6c840 | ||
|
|
1ff864ea2f | ||
|
|
071b5ba7cb | ||
|
|
2e6d89a093 | ||
|
|
049a1a59f5 | ||
|
|
201098e9f6 | ||
|
|
423227d385 | ||
|
|
c1facd8b1c | ||
|
|
842d371699 | ||
|
|
bcbd4b8d40 | ||
|
|
b526873837 | ||
|
|
6f85c6783e | ||
|
|
672983f6c1 | ||
|
|
3ee3fb05cc | ||
|
|
8ff32d9c1e | ||
|
|
8ad3d35dd2 | ||
|
|
cb5fdc9078 | ||
|
|
77d894dd00 | ||
|
|
5b40d95b0f | ||
|
|
385d157f3f | ||
|
|
81a2a51610 | ||
|
|
ff8383c5ed | ||
|
|
ca9f671553 | ||
|
|
eb17de0888 | ||
|
|
110c9d199d | ||
|
|
b5cc8f193e | ||
|
|
abebe9ef43 | ||
|
|
e55f69a009 | ||
|
|
9bf854445c | ||
|
|
17f7e4b753 | ||
|
|
0a6c6ec4c5 | ||
|
|
7456113cef | ||
|
|
7051e20d59 | ||
|
|
79dba43f0f | ||
|
|
6bb421dac6 | ||
|
|
0ce28c519f | ||
|
|
cdde702db7 | ||
|
|
6b4a76b54b | ||
|
|
57e2a9dc14 | ||
|
|
798f1e6e91 | ||
|
|
0e264a029e | ||
|
|
8745c059f7 | ||
|
|
adee447cd0 | ||
|
|
63c22414ce | ||
|
|
89992ea03e | ||
|
|
e9d24c3213 | ||
|
|
71b33e2e42 | ||
|
|
023bc5aaa6 | ||
|
|
30d4d8c3a5 | ||
|
|
6963e40074 | ||
|
|
2b6aa7972d | ||
|
|
4908c1c82a | ||
|
|
aaf1273794 | ||
|
|
62ef032594 | ||
|
|
3652436125 | ||
|
|
e947c638ff | ||
|
|
6926a30760 | ||
|
|
4feed1db5d | ||
|
|
d462a1d6c0 | ||
|
|
0e297c6779 | ||
|
|
e07636675f | ||
|
|
69020faaab | ||
|
|
4059682ec2 | ||
|
|
eaf5216d49 | ||
|
|
47142448d7 | ||
|
|
586c90208c | ||
|
|
7e0283d7c0 | ||
|
|
d9ee39f367 | ||
|
|
af1a3385cc | ||
|
|
0d58c77de0 | ||
|
|
b588238836 | ||
|
|
3e702b8629 | ||
|
|
62f46359e2 | ||
|
|
fef349880a | ||
|
|
f59cb12ec7 | ||
|
|
96700eef5d | ||
|
|
7316f68cdf | ||
|
|
0078062d33 | ||
|
|
e8cd8c9448 | ||
|
|
58fa1062eb | ||
|
|
bc2b0d513c | ||
|
|
8af58fcea3 | ||
|
|
180738306b | ||
|
|
efbe9060de | ||
|
|
5b9b5586d3 | ||
|
|
6c174e6634 | ||
|
|
1c2c86126c | ||
|
|
01f32f2706 | ||
|
|
94608b0c3f | ||
|
|
6f581d6122 | ||
|
|
9fcb5fe348 | ||
|
|
43e641f6a1 | ||
|
|
b182fd2428 | ||
|
|
af7c17e4bb | ||
|
|
edff4231ff | ||
|
|
a66b98fece | ||
|
|
4e2fb23bdf | ||
|
|
2900ad303c | ||
|
|
4e756704ea | ||
|
|
efd6c5331d | ||
|
|
619ef6f8eb | ||
|
|
2823504156 | ||
|
|
370dc86817 | ||
|
|
ee5628f856 | ||
|
|
a8f2ba8c30 | ||
|
|
24bd513002 | ||
|
|
f73609103a | ||
|
|
206d399258 | ||
|
|
d531dd374f | ||
|
|
e199a9b11a | ||
|
|
0ad8be71f9 | ||
|
|
9be9f59b6a | ||
|
|
5165ce7caf | ||
|
|
b00b84e314 | ||
|
|
85ae6f949b | ||
|
|
e31966496b | ||
|
|
db2ae1324f | ||
|
|
b152a67150 | ||
|
|
bdfc582ba5 | ||
|
|
7a2754109f | ||
|
|
ca76dc170c |
+3
-1
@@ -1 +1,3 @@
|
||||
19
|
||||
20
|
||||
1.4.2
|
||||
1.6.2
|
||||
@@ -4,6 +4,7 @@ exclude_patterns:
|
||||
- "**/*.test.js"
|
||||
- "**/*.test.ts"
|
||||
- "docs/**/*.js"
|
||||
- "docs/**/*.ts"
|
||||
- "packages/api/src/augment/"
|
||||
- "packages/typegen/scripts"
|
||||
- "packages/typegen/src"
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
**/build/*
|
||||
**/coverage/*
|
||||
**/node_modules/*
|
||||
docs/examples/promise/90_typegen/*
|
||||
|
||||
@@ -26,7 +26,7 @@ jobs:
|
||||
${{ runner.os }}-yarn-
|
||||
- name: lint
|
||||
run: |
|
||||
yarn install --frozen-lockfile
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn lint
|
||||
|
||||
test:
|
||||
@@ -53,7 +53,7 @@ jobs:
|
||||
${{ runner.os }}-yarn-
|
||||
- name: test
|
||||
run: |
|
||||
yarn install --frozen-lockfile
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn test
|
||||
|
||||
build_code:
|
||||
@@ -80,7 +80,7 @@ jobs:
|
||||
${{ runner.os }}-yarn-
|
||||
- name: build
|
||||
run: |
|
||||
yarn install --frozen-lockfile
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn build
|
||||
|
||||
build_docs:
|
||||
@@ -107,5 +107,5 @@ jobs:
|
||||
${{ runner.os }}-yarn-
|
||||
- name: build
|
||||
run: |
|
||||
yarn install --frozen-lockfile
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn docs
|
||||
|
||||
@@ -38,7 +38,7 @@ jobs:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
|
||||
run: |
|
||||
yarn install --frozen-lockfile
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn polkadot-ci-ghact-build
|
||||
|
||||
build_docs:
|
||||
@@ -71,7 +71,7 @@ jobs:
|
||||
GH_PAGES_SRC: build-docs
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
run: |
|
||||
yarn install --frozen-lockfile
|
||||
yarn install --immutable | grep -v 'YN0013'
|
||||
yarn polkadot-ci-ghact-docs
|
||||
|
||||
dummy:
|
||||
|
||||
@@ -13,6 +13,10 @@ tmp/
|
||||
.env.production.local
|
||||
.npmrc
|
||||
.rpt2_cache
|
||||
.yarn/*
|
||||
!.yarn/releases
|
||||
!.yarn/plugins
|
||||
.pnp.*
|
||||
.vscode/
|
||||
cc-test-reporter
|
||||
lerna-debug.log*
|
||||
|
||||
File diff suppressed because one or more lines are too long
+58
File diff suppressed because one or more lines are too long
+10
@@ -0,0 +1,10 @@
|
||||
enableImmutableInstalls: false
|
||||
enableProgressBars: false
|
||||
|
||||
nodeLinker: node-modules
|
||||
|
||||
plugins:
|
||||
- path: .yarn/plugins/@yarnpkg/plugin-interactive-tools.js
|
||||
spec: "@yarnpkg/plugin-interactive-tools"
|
||||
|
||||
yarnPath: .yarn/releases/yarn-berry.js
|
||||
+43
-1
@@ -1,3 +1,45 @@
|
||||
# 1.6.2 Feb 27, 2020
|
||||
|
||||
- Revert checks for arg, not working on `.at()` queries (proper fix in next version)
|
||||
|
||||
# 1.6.1 Mar 12, 2020
|
||||
|
||||
- **Breaking change** `api.rpc.state.queryStorage(...)` now fully decodes the `Vec<StorageChangeSet>` and returns a decoded `[Hash, Codec[]][]` when using this RPC.
|
||||
- `StorageKey` now has an `.args` property, decoded from meta where `twox64_concat` or `blake128_concat` are used on maps
|
||||
- Fix `api.query.*.*.entries` type conversions to return exact types (not `Option` in some cases)
|
||||
- Add `api.query.*.*.keys` to retrieve only the storage keys, similar to `.entries`
|
||||
- Full linked map retrievals will now use direct getStorage queries for faster operation
|
||||
- Underlying rpc-core interfaces now unwraps `Error("...")` when found in responses
|
||||
- Added `derive.eras*` interfaces for queries to new Substrate staking interfaces
|
||||
- Update `derive.account` to cater for new indices module storage (detected with fallbacks)
|
||||
- Adjust derive queries for session without module prefix (DoubleMap -> Map), detected on use
|
||||
- Add runtime validation for map arguments to `api.query.*`
|
||||
- TypeScript interfaces for linked maps now correctly generates as `[Type, Linkage<Next>]`
|
||||
|
||||
# 1.5.1 Mar 06, 2020
|
||||
|
||||
- **Important** Substrate master has updated staking, on older chains supply `StakingLedger: 'StakingLedgerTo223'`
|
||||
- **Important** Substrate master has updated collective, on older chains supply `Votes: 'VotesTo230'`
|
||||
- Add proper support for type generation with an Enum containing an Tuple (Thanks to https://github.com/monitz87)
|
||||
- Fix storage parsing not resulting in rejected Promises (Fix from https://github.com/aniiantt applied)
|
||||
- Remove use of deprecated `Observable.create` (Thanks to https://github.com/Himself65)
|
||||
- Add types & metadata for the latest Polkadot/Substrate runtime versions (master branches)
|
||||
- Type extraction will now allow the same sub-module name across packages, i.e. `@polkadot/types/interfaces/runtime` & `@mine/interfaces/runtime` will be valid
|
||||
- Add `.range([from, to]: [Hash, Hash?], ...args: any[]): [Hash, Codec][]` on all storage entries
|
||||
- Add `.raw(...args: any[]): Promise<Uint8Array & Codec>` to all RPC calls, returning the un-encoded result
|
||||
- Allow pre-module type aliasing with `typesAlias: { <moduleName>: { <meta-type>: <alias-type> } }` in API construction options
|
||||
- Allow `BTreeMap` to be initialized with a `Record<string, any>` object (in addition to `Map`)
|
||||
- Allow for `HashMap<KeyType, ValueType>` definitions
|
||||
- `Bool` will now correctly return `isEmpty` on false/default values
|
||||
- Refresh the `NetworkState` types as returned by the `rpc.system.networkState()` call to current
|
||||
- Expose `registry.createClass(<typeName>)` to allow for creating type classes. If you are using `createClass` or `ClassOf` in your code, it is recommended to swap to this instance.
|
||||
- Add additional derives to `api.derive.staking` to handle lazy-payout retrievals
|
||||
- Update `@polkadot/{util, util-crypto, keyring}` to 1.6.1 & `@polkadot/wasm` to 1.2.1
|
||||
|
||||
# 1.4.2 Feb 27, 2020
|
||||
|
||||
- Fix `api.tx(<extrinsic>): Submittable` decoration (non-working in 1.4.1, now with proper test)
|
||||
|
||||
# 1.4.1 Feb 26, 2020
|
||||
|
||||
- **Breaking change** (TypeScript only) The `*.d.ts` files now contain TypeScript 3.8 features (specifically `#private`), which is not usable in TS versions < 3.8
|
||||
@@ -16,7 +58,7 @@
|
||||
- Expand `.toHuman` on `ExtrinsicEra`, `SubmittableResult` & `Vote`
|
||||
- Move `DigestItem`, `Fixed64`, `H160`, `H256` & `H512` to interfaces in `@polkadot/types/interfaces`
|
||||
- Align construction of unknown types in `registry.get` consistently warn on detection, throw on use
|
||||
- Support for arbitrary UInt types via `UInt<bitLength>` type definitions
|
||||
- Support for arbitrary `u*`` types via `UInt<bitLength>` type definitions
|
||||
- Expose static `.with` on `UInt`, `Int` & `U8aFixed` classes with optional type name override
|
||||
- Remove [11 Jan 2019](https://github.com/polkadot-js/api/issues/574) extrinsic length hack
|
||||
- Use ES `#field` on private class fields as applicable
|
||||
|
||||
@@ -44,7 +44,6 @@ module.exports = {
|
||||
['start/types.basics.md', 'Type basics'],
|
||||
['start/types.extend.md', 'Extending types'],
|
||||
['start/types.create.md', 'Creating types'],
|
||||
['start/extrinsic.extend.md', 'Extending extrinsics'],
|
||||
['start/typescript.md', 'TypeScript interfaces'],
|
||||
['start/typescript.user.md', 'TypeScript user generated'],
|
||||
['start/FAQ.md', 'FAQ']
|
||||
@@ -64,7 +63,8 @@ module.exports = {
|
||||
['examples/promise/06_make_transfer/', 'Make a transfer'],
|
||||
['examples/promise/08_system_events/', 'Display system events'],
|
||||
['examples/promise/09_transfer_events/', 'Transaction with events'],
|
||||
['examples/promise/10_upgrade_chain/', 'Upgrade via sudo']
|
||||
['examples/promise/10_upgrade_chain/', 'Upgrade via sudo'],
|
||||
['examples/promise/90_typegen/', 'TypeScript augmentation']
|
||||
]
|
||||
},
|
||||
{
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
# Chain upgrade
|
||||
|
||||
Performs a chain upgrade using the `sudo` module. This may brick your chain, so us it as an educational sample. (use `substrate --dev purge-chain` to remove DB and recover).
|
||||
Performs a chain upgrade using the `sudo` module. This may brick your chain, so use it as an educational sample. (use `substrate purge-chain --dev` to remove DB and recover).
|
||||
|
||||
<<< @/docs/examples/promise/10_upgrade_chain/index.js
|
||||
|
||||
@@ -0,0 +1,248 @@
|
||||
# typegen
|
||||
|
||||
This is a sample TypeScript project [with full source & config on GithHub](https://github.com/polkadot-js/api/tree/master/docs/examples/promise/90_typegen), that uses `@polkadot/typegen` to generate type definitions that can be used to decorate the `@polkadot/api`. It uses both types defined for the specific chain as well as the chain metadata to generate TypeScript interfaces. This means that interfaces such as `api.query.*`, `api.tx.*` and `api.consts.*` will be decorated based on chain-specific information, instead of an un-augmented catch-all definition.
|
||||
|
||||
**NOTE** This is built using the updates in the `1.4.0` api track and as such it uses the latest (at the time of writing) `@polkadot/api 1.4.0`. If you want to play on your own, it is also suggested that you use the `1.4+` series since some generation types have moved around internally, making it easier to augment.
|
||||
|
||||
## Packages
|
||||
|
||||
For the packages we need from the `@polkadot/*` we have added `@polkadot/api` (we want to do API stuff) and `@polkadot/typegen` (to generate the actual interfaces). So our scripts and dependencies inside `package.json` contain the following -
|
||||
|
||||
```json
|
||||
{
|
||||
"scripts": {
|
||||
"build": "yarn generate:defs && yarn generate:meta",
|
||||
"generate:defs": "ts-node --skip-project node_modules/.bin/polkadot-types-from-defs --package sample-polkadotjs-typegen/interfaces --input ./src/interfaces",
|
||||
"generate:meta": "ts-node --skip-project node_modules/.bin/polkadot-types-from-chain --package sample-polkadotjs-typegen/interfaces --endpoint ./edgeware.json --output ./src/interfaces",
|
||||
"lint": "tsc --noEmit --pretty"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "^1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/typegen": "^1.4.0",
|
||||
"ts-node": "^8.6.2",
|
||||
"typescript": "^3.8.2"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
We will delve into the setup and running the scripts and what they do in a short bit, but as of now just notice that we are running the scripts via `ts-node`. Since we supply our definitions as `*.ts` files, this is important otherwise they will not be parsable. `build` will just run both the types and meta generators (in that order, so metadata can use the types) and we have a `lint` that can just check that everything is as it is meant to be.
|
||||
|
||||
## Metadata setup
|
||||
|
||||
The idea here is to use the actual chain metadata to generate the actual api augmented endpoints. The metadata we are adding here (in addition to the user types), is from the Edgeware Berlin testnet. So this is a real-world example of configuring the API for a specific substrate chain. For the metadata retrieval, we just ran a simple curl command to get it from the node -
|
||||
|
||||
`curl -H "Content-Type: application/json" -d '{"id":"1", "jsonrpc":"2.0", "method": "state_getMetadata", "params":[]}' http://localhost:9933`
|
||||
|
||||
And then add the full JSONPC output as received to the `edgeware.json` file as specified by the generation command. A trimmed version would look like -
|
||||
|
||||
```json
|
||||
{"jsonrpc":"2.0","result":"0x6d6574610b6c185379737....","id":29}
|
||||
```
|
||||
|
||||
The generator can also use a `wss://` as an `--endpoint` param as part of the generation, but in most cases you would want a static metadata to work from in development, hence we are actually adding it here.
|
||||
|
||||
## Types setup
|
||||
|
||||
The types are defined in the `src/interfaces` folder. While this repo contains a number of generated files in there as well, you basically only need to manually add the following -
|
||||
|
||||
- `src/interfaces/definitions.ts` - this just exports all the sub-folder definitions in one go
|
||||
- `src/interfaces/<module>/definitions.ts` - type definitions for a specific module
|
||||
|
||||
This structure fully matches what is available in the `@polkadot/type/interfaces` folder, so the structure is setup based on the convention used in the `@polkadot/types` library. The generating scripts will expect something matching this since the same underlying code is actually used inside `@polkadot/types` as well. The top-level `interfaces/` folder can be name anything, however the internal content structure need to match what is defined above.
|
||||
|
||||
For the top-level the definition file has the following contents -
|
||||
|
||||
```js
|
||||
export { default as signaling } from './signaling/definitions';
|
||||
export { default as treasuryRewards } from './treasuryRewards/definitions';
|
||||
export { default as voting } from './voting/definitions';
|
||||
```
|
||||
|
||||
As explained above, it really is just a re-export of the definitions, so they are all easily accessible to the outside, i.e. we will use this import inside our own code to use the definitions in API initialization. The generation scripts will load this file to determine which types it needs to import. By the `@polkadot/types` convention, match the export names with the folders (preferably your runtime module names), the generation scripts will use these names to find the correct folders to output the generated `types.ts` to.
|
||||
|
||||
For each of the folders, `signaling`, `treasuryRewards` and `voting` another `definitions.ts` file is contained within. Looking at the one from `signaling`, it contains this -
|
||||
|
||||
```js
|
||||
export default {
|
||||
types: {
|
||||
ProposalRecord: {
|
||||
index: 'u32',
|
||||
author: 'AccountId',
|
||||
stage: 'VoteStage',
|
||||
transition_time: 'u32',
|
||||
title: 'Text',
|
||||
contents: 'Text',
|
||||
vote_id: 'u64'
|
||||
},
|
||||
ProposalContents: 'Vec<u8>',
|
||||
ProposalTitle: 'Vec<u8>'
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Just the type definitions (the structure of which you should be familiar with), nested inside a `types: {...}` container. This allows us future extension points, i.e. there is some work to expose the custom RPC types alongside, so that would become another key on a per-module basis.
|
||||
|
||||
In the above, you will note that the `ProposalRecord` references a type for `voting`, i.e. `VoteStage`. The type generation and resolution will determine where the type comes from, and provide the required imports on generation.
|
||||
|
||||
Looking at the example in this repo, it also has `augment*`, `index.ts` and `types.ts` files in the interfaces folder. These are all generated, and will be re-generated when the generator is run - so all edits to these files will be lost. The only requirement for user-edits are the `definitions.ts` files.
|
||||
|
||||
## Generating
|
||||
|
||||
Now that both the metadata nd types setup is completed, we just run the build command via `yarn build` and magically (assuming you didn't have the `augment*` and other generated files), these files will be added. When running this command, the console should display something like -
|
||||
|
||||
```
|
||||
> yarn build
|
||||
$ yarn generate:defs && yarn generate:meta
|
||||
$ ts-node --skip-project \
|
||||
node_modules/.bin/polkadot-types-from-defs \
|
||||
--package sample-polkadotjs-typegen/interfaces \
|
||||
--input ./src/interfaces
|
||||
|
||||
sample-polkadotjs-typegen/src/interfaces/types.ts
|
||||
Generating
|
||||
Extracting interfaces for signaling
|
||||
...
|
||||
Writing
|
||||
|
||||
sample-polkadotjs-typegen/src/interfaces/augment-types.ts
|
||||
Generating
|
||||
Writing
|
||||
|
||||
$ ts-node --skip-project \
|
||||
node_modules/.bin/polkadot-types-from-chain \
|
||||
--package sample-polkadotjs-typegen/interfaces \
|
||||
--endpoint ./edgeware.json \
|
||||
--output ./src/interfaces
|
||||
|
||||
Generating from metadata, 81,267 bytes
|
||||
...
|
||||
|
||||
sample-polkadotjs-typegen/src/interfaces/augment-api.ts
|
||||
Generating
|
||||
Writing
|
||||
|
||||
✨ Done in 4.04s.
|
||||
```
|
||||
|
||||
Now if we check the actual output against the source via `yarn lint`, we would see that valid output has been generated -
|
||||
|
||||
```
|
||||
> yarn lint
|
||||
$ tsc --noEmit --pretty
|
||||
✨ Done in 2.28s.
|
||||
```
|
||||
|
||||
## Peering at the output
|
||||
|
||||
We are ready to use all these generated types this after some TS config. If you take a look at the generated `src/signaling/types.ts`, you would see generated TS interfaces, such as -
|
||||
|
||||
```js
|
||||
import { Struct } from '@polkadot/types/codec';
|
||||
import { Bytes, Text, u32, u64 } from '@polkadot/types/primitive';
|
||||
import { AccountId } from '@polkadot/types/interfaces/runtime';
|
||||
import { VoteStage } from 'sample-polkadotjs-typegen/interfaces/voting';
|
||||
|
||||
/** @name ProposalContents */
|
||||
export interface ProposalContents extends Bytes {}
|
||||
|
||||
/** @name ProposalRecord */
|
||||
export interface ProposalRecord extends Struct {
|
||||
readonly index: u32;
|
||||
readonly author: AccountId;
|
||||
readonly stage: VoteStage;
|
||||
readonly transition_time: u32;
|
||||
readonly title: Text;
|
||||
readonly contents: Text;
|
||||
readonly vote_id: u64;
|
||||
}
|
||||
|
||||
/** @name ProposalTitle */
|
||||
export interface ProposalTitle extends Bytes {}
|
||||
```
|
||||
|
||||
As mentioned earlier, here you will notice the `import { VoteStage }`, the generator has determined that `voting` exports that interface and has added the required imports.
|
||||
|
||||
## TypeScript config
|
||||
|
||||
Now that we have files generated, it is time to make TypeScript aware of the types and add an explicit override into out `tsconfig.json`. After some changes, the paths in the config looks as follow (comments are in teh actual config file here) -
|
||||
|
||||
```json
|
||||
{
|
||||
"compilerOptions": {
|
||||
"paths": {
|
||||
"sample-polkadotjs-typegen/*": ["src/*"],
|
||||
"@polkadot/api/augment": ["src/interfaces/augment-api.ts"],
|
||||
"@polkadot/types/augment": ["src/interfaces/augment-types.ts"]
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Effectively what we do above is tell the TypeScript compiler to not use the built-in API augmentation, but rather to replace it with our version. This means that all types from these are injected not by the substrate-latest-master version, but rather with what we have defined above.
|
||||
|
||||
## Usage
|
||||
|
||||
For simple usage, we have added the `src/index.ts` file that show how the metadata and types actually decorate the API. In addition, we also have setup instructions included here.
|
||||
|
||||
```js
|
||||
// We need to import the augmented definitions "somewhere" in our project, however since we have
|
||||
// it in tsconfig as an override and the api/types has imports, it is not strictly required here.
|
||||
// Because of the tsconfig override, we could import from '@polkadot/{api, types}/augment'
|
||||
import './interfaces/augment-api';
|
||||
import './interfaces/augment-types';
|
||||
|
||||
// all type stuff, the only one we are using here
|
||||
import type { VoteRecord } from './interfaces';
|
||||
|
||||
// external imports
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
// our local stuff
|
||||
import * as definitions from './interfaces/definitions';
|
||||
|
||||
async function main (): Promise<void> {
|
||||
// extract all types from definitions - fast and dirty approach, flatted on 'types'
|
||||
const types = Object.values(definitions).reduce((res, { types }): object => ({ ...res, ...types }), {});
|
||||
|
||||
const api = await ApiPromise.create({
|
||||
types: {
|
||||
...types,
|
||||
// aliases that don't do well as part of interfaces
|
||||
'voting::VoteType': 'VoteType',
|
||||
'voting::TallyType': 'TallyType',
|
||||
// chain-specific overrides
|
||||
Keys: 'SessionKeys4'
|
||||
}
|
||||
});
|
||||
|
||||
// get a query
|
||||
const recordOpt = await api.query.voting.voteRecords(123);
|
||||
|
||||
// the types match with what we expect here
|
||||
let firstRecord: VoteRecord | null = recordOpt.unwrapOr(null);
|
||||
console.log(firstRecord?.toHuman());
|
||||
|
||||
// it even does work for arrays & subscriptions
|
||||
api.query.signaling.activeProposals((results): void => {
|
||||
results.forEach(([hash, blockNumber]): void => {
|
||||
console.log(hash.toHex(), ':', blockNumber.toNumber());
|
||||
});
|
||||
});
|
||||
|
||||
// even createType works, allowing for our types to be used
|
||||
console.log(`Balance2 bitLength:`, [
|
||||
api.createType('Balance2').bitLength(),
|
||||
api.registry.createType('Balance2').bitLength(),
|
||||
createType(api.registry, 'Balance2').bitLength()
|
||||
]);
|
||||
}
|
||||
|
||||
await main();
|
||||
```
|
||||
|
||||
## And that is a ...
|
||||
|
||||
... wrap. Just a really simple walk-through to customizing the API TypeScript definitions for your chain.
|
||||
File diff suppressed because one or more lines are too long
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "sample-polkadotjs-typegen",
|
||||
"version": "0.0.1",
|
||||
"description": "A sample using @polkadot/typegen to generate type definitions",
|
||||
"main": "index.js",
|
||||
"repository": "https://github.com/jacogr/sample-polkadotjs-typegen",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"license": "The Unlicense",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "yarn generate:defs && yarn generate:meta",
|
||||
"generate:defs": "ts-node --skip-project node_modules/.bin/polkadot-types-from-defs --package sample-polkadotjs-typegen/interfaces --input ./src/interfaces",
|
||||
"generate:meta": "ts-node --skip-project node_modules/.bin/polkadot-types-from-chain --package sample-polkadotjs-typegen/interfaces --endpoint ./edgeware.json --output ./src/interfaces --strict",
|
||||
"lint": "tsc --noEmit --pretty"
|
||||
},
|
||||
"dependencies": {
|
||||
"@polkadot/api": "^1.4.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/typegen": "^1.4.0",
|
||||
"ts-node": "^8.6.2",
|
||||
"typescript": "^3.8.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
// We need to import the augmented definitions "somewhere" in our project, however since we have
|
||||
// it in tsconfig as an override and the api/types has imports, it is not strictly required here.
|
||||
// Because of the tsconfig override, we could import from '@polkadot/{api, types}/augment'
|
||||
import './interfaces/augment-api';
|
||||
import './interfaces/augment-types';
|
||||
|
||||
// all type stuff, the only one we are using here
|
||||
import type { VoteRecord } from './interfaces';
|
||||
|
||||
// external imports
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
// our local stuff
|
||||
import * as definitions from './interfaces/definitions';
|
||||
|
||||
async function main (): Promise<void> {
|
||||
// extract all types from definitions - fast and dirty approach, flatted on 'types'
|
||||
const types = Object.values(definitions).reduce((res, { types }): object => ({ ...res, ...types }), {});
|
||||
|
||||
const api = await ApiPromise.create({
|
||||
types: {
|
||||
...types,
|
||||
// aliasses that don't do well as part of interfaces
|
||||
'voting::VoteType': 'VoteType',
|
||||
'voting::TallyType': 'TallyType',
|
||||
// chain-specific overrides
|
||||
Keys: 'SessionKeys4'
|
||||
}
|
||||
});
|
||||
|
||||
// get a query
|
||||
const recordOpt = await api.query.voting.voteRecords(123);
|
||||
|
||||
// the types match with what we expect here
|
||||
let firstRecord: VoteRecord | null = recordOpt.unwrapOr(null);
|
||||
console.log(firstRecord?.toHuman());
|
||||
|
||||
// it even does work for arrays & subscriptions
|
||||
api.query.signaling.activeProposals((results): void => {
|
||||
results.forEach(([hash, blockNumber]): void => {
|
||||
console.log(hash.toHex(), ':', blockNumber.toNumber());
|
||||
});
|
||||
});
|
||||
|
||||
// even createType works, allowing for our types to be used
|
||||
console.log(`Balance2 bitLength:`, [
|
||||
api.createType('Balance2').bitLength(),
|
||||
api.registry.createType('Balance2').bitLength(),
|
||||
createType(api.registry, 'Balance2').bitLength()
|
||||
]);
|
||||
}
|
||||
|
||||
await main();
|
||||
@@ -0,0 +1,253 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { Bytes, u32 } from '@polkadot/types/primitive';
|
||||
import { Gas } from '@polkadot/types/interfaces/contracts';
|
||||
import { Balance, BalanceOf, BlockNumber, Moment, Percent, Permill } from '@polkadot/types/interfaces/runtime';
|
||||
import { SessionIndex } from '@polkadot/types/interfaces/session';
|
||||
import { EraIndex } from '@polkadot/types/interfaces/staking';
|
||||
|
||||
declare module '@polkadot/metadata/Decorated/consts/types' {
|
||||
export interface Constants {
|
||||
timestamp: {
|
||||
|
||||
/**
|
||||
* The minimum period between blocks. Beware that this is different to the *expected* period
|
||||
* that the block production apparatus provides. Your chosen consensus system will generally
|
||||
* work with this to determine a sensible block time. e.g. For Aura, it will be double this
|
||||
* period on default settings.
|
||||
**/
|
||||
minimumPeriod: AugmentedConst<Moment>;
|
||||
};
|
||||
balances: {
|
||||
|
||||
/**
|
||||
* The minimum amount required to keep an account open.
|
||||
**/
|
||||
existentialDeposit: AugmentedConst<Balance>;
|
||||
/**
|
||||
* The fee required to make a transfer.
|
||||
**/
|
||||
transferFee: AugmentedConst<Balance>;
|
||||
/**
|
||||
* The fee required to create an account.
|
||||
**/
|
||||
creationFee: AugmentedConst<Balance>;
|
||||
};
|
||||
transactionPayment: {
|
||||
|
||||
/**
|
||||
* The fee to be paid for making a transaction; the base.
|
||||
**/
|
||||
transactionBaseFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The fee to be paid for making a transaction; the per-byte portion.
|
||||
**/
|
||||
transactionByteFee: AugmentedConst<BalanceOf>;
|
||||
};
|
||||
staking: {
|
||||
|
||||
/**
|
||||
* Number of sessions per era.
|
||||
**/
|
||||
sessionsPerEra: AugmentedConst<SessionIndex>;
|
||||
/**
|
||||
* Number of eras that staked funds must remain bonded for.
|
||||
**/
|
||||
bondingDuration: AugmentedConst<EraIndex>;
|
||||
};
|
||||
session: {
|
||||
|
||||
/**
|
||||
* Used as first key for `NextKeys` and `KeyOwner` to put all the data into the same branch
|
||||
* of the trie.
|
||||
**/
|
||||
dedupKeyPrefix: AugmentedConst<Bytes>;
|
||||
};
|
||||
democracy: {
|
||||
|
||||
/**
|
||||
* The minimum period of locking and the period between a proposal being approved and enacted.
|
||||
* It should generally be a little more than the unstake period to ensure that
|
||||
* voting stakers have an opportunity to remove themselves from the system in the case where
|
||||
* they are on the losing side of a vote.
|
||||
**/
|
||||
enactmentPeriod: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* How often (in blocks) new public referenda are launched.
|
||||
**/
|
||||
launchPeriod: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* How often (in blocks) to check for new votes.
|
||||
**/
|
||||
votingPeriod: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* The minimum amount to be used as a deposit for a public referendum proposal.
|
||||
**/
|
||||
minimumDeposit: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* Minimum voting period allowed for an emergency referendum.
|
||||
**/
|
||||
emergencyVotingPeriod: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* Period in blocks where an external proposal may not be re-submitted after being vetoed.
|
||||
**/
|
||||
cooloffPeriod: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* The amount of balance that must be deposited per byte of preimage stored.
|
||||
**/
|
||||
preimageByteDeposit: AugmentedConst<BalanceOf>;
|
||||
};
|
||||
elections: {
|
||||
|
||||
candidacyBond: AugmentedConst<BalanceOf>;
|
||||
votingBond: AugmentedConst<BalanceOf>;
|
||||
desiredMembers: AugmentedConst<u32>;
|
||||
desiredRunnersUp: AugmentedConst<u32>;
|
||||
termDuration: AugmentedConst<BlockNumber>;
|
||||
};
|
||||
finalityTracker: {
|
||||
|
||||
/**
|
||||
* The number of recent samples to keep from this chain. Default is 101.
|
||||
**/
|
||||
windowSize: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* The delay after which point things become suspicious. Default is 1000.
|
||||
**/
|
||||
reportLatency: AugmentedConst<BlockNumber>;
|
||||
};
|
||||
treasury: {
|
||||
|
||||
/**
|
||||
* Fraction of a proposal's value that should be bonded in order to place the proposal.
|
||||
* An accepted proposal gets these back. A rejected proposal does not.
|
||||
**/
|
||||
proposalBond: AugmentedConst<Permill>;
|
||||
/**
|
||||
* Minimum amount of funds that should be placed in a deposit for making a proposal.
|
||||
**/
|
||||
proposalBondMinimum: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* Period between successive spends.
|
||||
**/
|
||||
spendPeriod: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* Percentage of spare funds (if any) that are burnt per spend period.
|
||||
**/
|
||||
burn: AugmentedConst<Permill>;
|
||||
/**
|
||||
* The period for which a tip remains open after is has achieved threshold tippers.
|
||||
**/
|
||||
tipCountdown: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* The amount of the final tip which goes to the original reporter of the tip.
|
||||
**/
|
||||
tipFindersFee: AugmentedConst<Percent>;
|
||||
/**
|
||||
* The amount held on deposit for placing a tip report.
|
||||
**/
|
||||
tipReportDepositBase: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The amount held on deposit per byte within the tip report reason.
|
||||
**/
|
||||
tipReportDepositPerByte: AugmentedConst<BalanceOf>;
|
||||
};
|
||||
contracts: {
|
||||
|
||||
/**
|
||||
* Number of block delay an extrinsic claim surcharge has.
|
||||
* When claim surcharge is called by an extrinsic the rent is checked
|
||||
* for current_block - delay
|
||||
**/
|
||||
signedClaimHandicap: AugmentedConst<BlockNumber>;
|
||||
/**
|
||||
* The minimum amount required to generate a tombstone.
|
||||
**/
|
||||
tombstoneDeposit: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* Size of a contract at the time of instantiaion. This is a simple way to ensure that
|
||||
* empty contracts eventually gets deleted.
|
||||
**/
|
||||
storageSizeOffset: AugmentedConst<u32>;
|
||||
/**
|
||||
* Price of a byte of storage per one block interval. Should be greater than 0.
|
||||
**/
|
||||
rentByteFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The amount of funds a contract should deposit in order to offset
|
||||
* the cost of one byte.
|
||||
* Let's suppose the deposit is 1,000 BU (balance units)/byte and the rent is 1 BU/byte/day,
|
||||
* then a contract with 1,000,000 BU that uses 1,000 bytes of storage would pay no rent.
|
||||
* But if the balance reduced to 500,000 BU and the storage stayed the same at 1,000,
|
||||
* then it would pay 500 BU/day.
|
||||
**/
|
||||
rentDepositOffset: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* Reward that is received by the party whose touch has led
|
||||
* to removal of a contract.
|
||||
**/
|
||||
surchargeReward: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The fee required to make a transfer.
|
||||
**/
|
||||
transferFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The fee required to create an account.
|
||||
**/
|
||||
creationFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The fee to be paid for making a transaction; the base.
|
||||
**/
|
||||
transactionBaseFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The fee to be paid for making a transaction; the per-byte portion.
|
||||
**/
|
||||
transactionByteFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The fee required to instantiate a contract instance. A reasonable default value
|
||||
* is 21.
|
||||
**/
|
||||
contractFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The base fee charged for calling into a contract. A reasonable default
|
||||
* value is 135.
|
||||
**/
|
||||
callBaseFee: AugmentedConst<Gas>;
|
||||
/**
|
||||
* The base fee charged for instantiating a contract. A reasonable default value
|
||||
* is 175.
|
||||
**/
|
||||
instantiateBaseFee: AugmentedConst<Gas>;
|
||||
/**
|
||||
* The maximum nesting level of a call/instantiate stack. A reasonable default
|
||||
* value is 100.
|
||||
**/
|
||||
maxDepth: AugmentedConst<u32>;
|
||||
/**
|
||||
* The maximum size of a storage value in bytes. A reasonable default is 16 KiB.
|
||||
**/
|
||||
maxValueSize: AugmentedConst<u32>;
|
||||
/**
|
||||
* The maximum amount of gas that could be expended per block. A reasonable
|
||||
* default value is 10_000_000.
|
||||
**/
|
||||
blockGasLimit: AugmentedConst<Gas>;
|
||||
};
|
||||
nicks: {
|
||||
|
||||
/**
|
||||
* Reservation fee.
|
||||
**/
|
||||
reservationFee: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* The minimum length a name may be.
|
||||
**/
|
||||
minLength: AugmentedConst<u32>;
|
||||
/**
|
||||
* The maximum length a name may be.
|
||||
**/
|
||||
maxLength: AugmentedConst<u32>;
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,706 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { AnyNumber, ITuple } from '@polkadot/types/types';
|
||||
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 { BalanceLock, VestingSchedule } from '@polkadot/types/interfaces/balances';
|
||||
import { ProposalIndex, Votes } from '@polkadot/types/interfaces/collective';
|
||||
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
|
||||
import { CodeHash, ContractInfo, Gas, PrefabWasmModule, Schedule } from '@polkadot/types/interfaces/contracts';
|
||||
import { Conviction, PropIndex, Proposal, ReferendumIndex, ReferendumInfo } from '@polkadot/types/interfaces/democracy';
|
||||
import { Vote, VoteThreshold } from '@polkadot/types/interfaces/elections';
|
||||
import { AuthorityList, SetId, StoredPendingChange, StoredState } from '@polkadot/types/interfaces/grandpa';
|
||||
import { RegistrarInfo, Registration } from '@polkadot/types/interfaces/identity';
|
||||
import { AuthIndex } from '@polkadot/types/interfaces/imOnline';
|
||||
import { Kind, OffenceDetails, OpaqueTimeSlot, ReportIdOf } from '@polkadot/types/interfaces/offences';
|
||||
import { AccountId, AccountIndex, Balance, BalanceOf, BlockNumber, Hash, Index, KeyTypeId, Moment, Perbill, ValidatorId, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import { Keys, SessionIndex } from '@polkadot/types/interfaces/session';
|
||||
import { ProposalRecord } from 'sample-polkadotjs-typegen/interfaces/signaling';
|
||||
import { EraIndex, EraPoints, Exposure, Forcing, MomentOf, Nominations, RewardDestination, SlashingSpans, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
|
||||
import { DigestOf, EventIndex, EventRecord } from '@polkadot/types/interfaces/system';
|
||||
import { OpenTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
|
||||
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
|
||||
import { Multisig } from '@polkadot/types/interfaces/utility';
|
||||
import { VoteRecord } from 'sample-polkadotjs-typegen/interfaces/voting';
|
||||
import { Observable } from 'rxjs';
|
||||
import { ApiTypes } from '@polkadot/api/types';
|
||||
|
||||
declare module '@polkadot/api/types/storage' {
|
||||
export interface AugmentedQueries<ApiType> {
|
||||
system: {
|
||||
|
||||
/**
|
||||
* Extrinsics nonce for accounts.
|
||||
**/
|
||||
accountNonce: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Index>>;
|
||||
/**
|
||||
* Total extrinsics count for the current block.
|
||||
**/
|
||||
extrinsicCount: AugmentedQuery<ApiType, () => Observable<Option<u32>>>;
|
||||
/**
|
||||
* Total weight for all extrinsics put together, for the current block.
|
||||
**/
|
||||
allExtrinsicsWeight: AugmentedQuery<ApiType, () => Observable<Option<Weight>>>;
|
||||
/**
|
||||
* Total length (in bytes) for all extrinsics put together, for the current block.
|
||||
**/
|
||||
allExtrinsicsLen: AugmentedQuery<ApiType, () => Observable<Option<u32>>>;
|
||||
/**
|
||||
* Map of block numbers to block hashes.
|
||||
**/
|
||||
blockHash: AugmentedQuery<ApiType, (arg: BlockNumber | AnyNumber | Uint8Array) => Observable<Hash>>;
|
||||
/**
|
||||
* Extrinsics data for the current block (maps an extrinsic's index to its data).
|
||||
**/
|
||||
extrinsicData: AugmentedQuery<ApiType, (arg: u32 | AnyNumber | Uint8Array) => Observable<Bytes>>;
|
||||
/**
|
||||
* The current block number being processed. Set by `execute_block`.
|
||||
**/
|
||||
number: AugmentedQuery<ApiType, () => Observable<BlockNumber>>;
|
||||
/**
|
||||
* Hash of the previous block.
|
||||
**/
|
||||
parentHash: AugmentedQuery<ApiType, () => Observable<Hash>>;
|
||||
/**
|
||||
* Extrinsics root of the current block, also part of the block header.
|
||||
**/
|
||||
extrinsicsRoot: AugmentedQuery<ApiType, () => Observable<Hash>>;
|
||||
/**
|
||||
* Digest of the current block, also part of the block header.
|
||||
**/
|
||||
digest: AugmentedQuery<ApiType, () => Observable<DigestOf>>;
|
||||
/**
|
||||
* Events deposited for the current block.
|
||||
**/
|
||||
events: AugmentedQuery<ApiType, () => Observable<Vec<EventRecord>>>;
|
||||
/**
|
||||
* The number of events in the `Events<T>` list.
|
||||
**/
|
||||
eventCount: AugmentedQuery<ApiType, () => Observable<EventIndex>>;
|
||||
/**
|
||||
* Mapping between a topic (represented by T::Hash) and a vector of indexes
|
||||
* of events in the `<Events<T>>` list.
|
||||
* All topic vectors have deterministic storage locations depending on the topic. This
|
||||
* allows light-clients to leverage the changes trie storage tracking mechanism and
|
||||
* in case of changes fetch the list of events of interest.
|
||||
* The value has the type `(T::BlockNumber, EventIndex)` because if we used only just
|
||||
* the `EventIndex` then in case if the topic has the same contents on the next block
|
||||
* no notification will be triggered thus the event might be lost.
|
||||
**/
|
||||
eventTopics: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Vec<ITuple<[BlockNumber, EventIndex]>>>>;
|
||||
};
|
||||
utility: {
|
||||
|
||||
/**
|
||||
* The set of open multisig operations.
|
||||
**/
|
||||
multisigs: AugmentedQueryDoubleMap<ApiType, (key1: AccountId | string | Uint8Array, key2: U8aFixed | string | Uint8Array) => Observable<Option<Multisig>>>;
|
||||
};
|
||||
timestamp: {
|
||||
|
||||
/**
|
||||
* Current time for the current block.
|
||||
**/
|
||||
now: AugmentedQuery<ApiType, () => Observable<Moment>>;
|
||||
/**
|
||||
* Did the timestamp get updated in this block?
|
||||
**/
|
||||
didUpdate: AugmentedQuery<ApiType, () => Observable<bool>>;
|
||||
};
|
||||
authorship: {
|
||||
|
||||
/**
|
||||
* Uncles
|
||||
**/
|
||||
uncles: AugmentedQuery<ApiType, () => Observable<Vec<UncleEntryItem>>>;
|
||||
/**
|
||||
* Author of current block.
|
||||
**/
|
||||
author: AugmentedQuery<ApiType, () => Observable<Option<AccountId>>>;
|
||||
/**
|
||||
* Whether uncles were already set in this block.
|
||||
**/
|
||||
didSetUncles: AugmentedQuery<ApiType, () => Observable<bool>>;
|
||||
};
|
||||
indices: {
|
||||
|
||||
/**
|
||||
* The next free enumeration set.
|
||||
**/
|
||||
nextEnumSet: AugmentedQuery<ApiType, () => Observable<AccountIndex>>;
|
||||
/**
|
||||
* The enumeration sets.
|
||||
**/
|
||||
enumSet: AugmentedQuery<ApiType, (arg: AccountIndex | AnyNumber | Uint8Array) => Observable<Vec<AccountId>>>;
|
||||
};
|
||||
balances: {
|
||||
|
||||
/**
|
||||
* The total units issued in the system.
|
||||
**/
|
||||
totalIssuance: AugmentedQuery<ApiType, () => Observable<Balance>>;
|
||||
/**
|
||||
* Information regarding the vesting of a given account.
|
||||
**/
|
||||
vesting: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<VestingSchedule>>>;
|
||||
/**
|
||||
* The 'free' balance of a given account.
|
||||
* This is the only balance that matters in terms of most operations on tokens. It
|
||||
* alone is used to determine the balance when in the contract execution environment. When this
|
||||
* balance falls below the value of `ExistentialDeposit`, then the 'current account' is
|
||||
* deleted: specifically `FreeBalance`. Further, the `OnFreeBalanceZero` callback
|
||||
* is invoked, giving a chance to external modules to clean up data associated with
|
||||
* the deleted account.
|
||||
* `frame_system::AccountNonce` is also deleted if `ReservedBalance` is also zero (it also gets
|
||||
* collapsed to zero if it ever becomes less than `ExistentialDeposit`.
|
||||
**/
|
||||
freeBalance: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Balance>>;
|
||||
/**
|
||||
* The amount of the balance of a given account that is externally reserved; this can still get
|
||||
* slashed, but gets slashed last of all.
|
||||
* This balance is a 'reserve' balance that other subsystems use in order to set aside tokens
|
||||
* that are still 'owned' by the account holder, but which are suspendable.
|
||||
* When this balance falls below the value of `ExistentialDeposit`, then this 'reserve account'
|
||||
* is deleted: specifically, `ReservedBalance`.
|
||||
* `frame_system::AccountNonce` is also deleted if `FreeBalance` is also zero (it also gets
|
||||
* collapsed to zero if it ever becomes less than `ExistentialDeposit`.)
|
||||
**/
|
||||
reservedBalance: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Balance>>;
|
||||
/**
|
||||
* Any liquidity locks on some account balances.
|
||||
**/
|
||||
locks: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Vec<BalanceLock>>>;
|
||||
};
|
||||
transactionPayment: {
|
||||
|
||||
nextFeeMultiplier: AugmentedQuery<ApiType, () => Observable<Multiplier>>;
|
||||
};
|
||||
staking: {
|
||||
|
||||
/**
|
||||
* The ideal number of staking participants.
|
||||
**/
|
||||
validatorCount: AugmentedQuery<ApiType, () => Observable<u32>>;
|
||||
/**
|
||||
* Minimum number of staking participants before emergency conditions are imposed.
|
||||
**/
|
||||
minimumValidatorCount: AugmentedQuery<ApiType, () => Observable<u32>>;
|
||||
/**
|
||||
* Any validators that may never be slashed or forcibly kicked. It's a Vec since they're
|
||||
* easy to initialize and the performance hit is minimal (we expect no more than four
|
||||
* invulnerables) and restricted to testnets.
|
||||
**/
|
||||
invulnerables: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>>;
|
||||
/**
|
||||
* Map from all locked "stash" accounts to the controller account.
|
||||
**/
|
||||
bonded: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<AccountId>>>;
|
||||
/**
|
||||
* Map from all (unlocked) "controller" accounts to the info regarding the staking.
|
||||
**/
|
||||
ledger: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<StakingLedger>>>;
|
||||
/**
|
||||
* Where the reward payment should be made. Keyed by stash.
|
||||
**/
|
||||
payee: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<RewardDestination>>;
|
||||
/**
|
||||
* The map from (wannabe) validator stash key to the preferences of that validator.
|
||||
**/
|
||||
validators: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ValidatorPrefs>>;
|
||||
/**
|
||||
* The map from nominator stash key to the set of stash keys of all validators to nominate.
|
||||
* NOTE: is private so that we can ensure upgraded before all typical accesses.
|
||||
* Direct storage APIs can still bypass this protection.
|
||||
**/
|
||||
nominators: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<Nominations>>>;
|
||||
/**
|
||||
* Nominators for a particular account that is in action right now. You can't iterate
|
||||
* through validators here, but you can find them in the Session module.
|
||||
* This is keyed by the stash account.
|
||||
**/
|
||||
stakers: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Exposure>>;
|
||||
/**
|
||||
* The currently elected validator set keyed by stash account ID.
|
||||
**/
|
||||
currentElected: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>>;
|
||||
/**
|
||||
* The current era index.
|
||||
**/
|
||||
currentEra: AugmentedQuery<ApiType, () => Observable<EraIndex>>;
|
||||
/**
|
||||
* The start of the current era.
|
||||
**/
|
||||
currentEraStart: AugmentedQuery<ApiType, () => Observable<MomentOf>>;
|
||||
/**
|
||||
* The session index at which the current era started.
|
||||
**/
|
||||
currentEraStartSessionIndex: AugmentedQuery<ApiType, () => Observable<SessionIndex>>;
|
||||
/**
|
||||
* Rewards for the current era. Using indices of current elected set.
|
||||
**/
|
||||
currentEraPointsEarned: AugmentedQuery<ApiType, () => Observable<EraPoints>>;
|
||||
/**
|
||||
* The amount of balance actively at stake for each validator slot, currently.
|
||||
* This is used to derive rewards and punishments.
|
||||
**/
|
||||
slotStake: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
|
||||
/**
|
||||
* True if the next session change will be a new era regardless of index.
|
||||
**/
|
||||
forceEra: AugmentedQuery<ApiType, () => Observable<Forcing>>;
|
||||
/**
|
||||
* The percentage of the slash that is distributed to reporters.
|
||||
* The rest of the slashed value is handled by the `Slash`.
|
||||
**/
|
||||
slashRewardFraction: AugmentedQuery<ApiType, () => Observable<Perbill>>;
|
||||
/**
|
||||
* The amount of currency given to reporters of a slash event which was
|
||||
* canceled by extraordinary circumstances (e.g. governance).
|
||||
**/
|
||||
canceledSlashPayout: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
|
||||
/**
|
||||
* All unapplied slashes that are queued for later.
|
||||
**/
|
||||
unappliedSlashes: AugmentedQuery<ApiType, (arg: EraIndex | AnyNumber | Uint8Array) => Observable<Vec<UnappliedSlash>>>;
|
||||
/**
|
||||
* A mapping from still-bonded eras to the first session index of that era.
|
||||
**/
|
||||
bondedEras: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[EraIndex, SessionIndex]>>>>;
|
||||
/**
|
||||
* All slashing events on validators, mapped by era to the highest slash proportion
|
||||
* and slash value of the era.
|
||||
**/
|
||||
validatorSlashInEra: AugmentedQueryDoubleMap<ApiType, (key1: EraIndex | AnyNumber | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Option<ITuple<[Perbill, BalanceOf]>>>>;
|
||||
/**
|
||||
* All slashing events on nominators, mapped by era to the highest slash value of the era.
|
||||
**/
|
||||
nominatorSlashInEra: AugmentedQueryDoubleMap<ApiType, (key1: EraIndex | AnyNumber | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Option<BalanceOf>>>;
|
||||
/**
|
||||
* Slashing spans for stash accounts.
|
||||
**/
|
||||
slashingSpans: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<SlashingSpans>>>;
|
||||
/**
|
||||
* Records information about the maximum slash of a stash within a slashing span,
|
||||
* as well as how much reward has been paid out.
|
||||
**/
|
||||
spanSlash: AugmentedQuery<ApiType, (arg: ITuple<[AccountId, SpanIndex]> | [AccountId | string | Uint8Array, SpanIndex | AnyNumber | Uint8Array]) => Observable<SpanRecord>>;
|
||||
/**
|
||||
* The earliest era for which we have a pending, unapplied slash.
|
||||
**/
|
||||
earliestUnappliedSlash: AugmentedQuery<ApiType, () => Observable<Option<EraIndex>>>;
|
||||
/**
|
||||
* The version of storage for upgrade.
|
||||
**/
|
||||
storageVersion: AugmentedQuery<ApiType, () => Observable<u32>>;
|
||||
};
|
||||
session: {
|
||||
|
||||
/**
|
||||
* The current set of validators.
|
||||
**/
|
||||
validators: AugmentedQuery<ApiType, () => Observable<Vec<ValidatorId>>>;
|
||||
/**
|
||||
* Current index of the session.
|
||||
**/
|
||||
currentIndex: AugmentedQuery<ApiType, () => Observable<SessionIndex>>;
|
||||
/**
|
||||
* True if the underlying economic identities or weighting behind the validators
|
||||
* has changed in the queued validator set.
|
||||
**/
|
||||
queuedChanged: AugmentedQuery<ApiType, () => Observable<bool>>;
|
||||
/**
|
||||
* The queued keys for the next session. When the next session begins, these keys
|
||||
* will be used to determine the validator's session keys.
|
||||
**/
|
||||
queuedKeys: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[ValidatorId, Keys]>>>>;
|
||||
/**
|
||||
* Indices of disabled validators.
|
||||
* The set is cleared when `on_session_ending` returns a new set of identities.
|
||||
**/
|
||||
disabledValidators: AugmentedQuery<ApiType, () => Observable<Vec<u32>>>;
|
||||
/**
|
||||
* The next session keys for a validator.
|
||||
* The first key is always `DEDUP_KEY_PREFIX` to have all the data in the same branch of
|
||||
* the trie. Having all data in the same branch should prevent slowing down other queries.
|
||||
**/
|
||||
nextKeys: AugmentedQueryDoubleMap<ApiType, (key1: Bytes | string | Uint8Array, key2: ValidatorId | string | Uint8Array) => Observable<Option<Keys>>>;
|
||||
/**
|
||||
* The owner of a key. The second key is the `KeyTypeId` + the encoded key.
|
||||
* The first key is always `DEDUP_KEY_PREFIX` to have all the data in the same branch of
|
||||
* the trie. Having all data in the same branch should prevent slowing down other queries.
|
||||
**/
|
||||
keyOwner: AugmentedQueryDoubleMap<ApiType, (key1: Bytes | string | Uint8Array, key2: ITuple<[KeyTypeId, Bytes]> | [KeyTypeId | AnyNumber | Uint8Array, Bytes | string | Uint8Array]) => Observable<Option<ValidatorId>>>;
|
||||
};
|
||||
democracy: {
|
||||
|
||||
/**
|
||||
* The number of (public) proposals that have been made so far.
|
||||
**/
|
||||
publicPropCount: AugmentedQuery<ApiType, () => Observable<PropIndex>>;
|
||||
/**
|
||||
* The public proposals. Unsorted. The second item is the proposal's hash.
|
||||
**/
|
||||
publicProps: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[PropIndex, Hash, AccountId]>>>>;
|
||||
/**
|
||||
* Map of hashes to the proposal preimage, along with who registered it and their deposit.
|
||||
* The block number is the block at which it was deposited.
|
||||
**/
|
||||
preimages: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<ITuple<[Bytes, AccountId, BalanceOf, BlockNumber]>>>>;
|
||||
/**
|
||||
* Those who have locked a deposit.
|
||||
**/
|
||||
depositOf: AugmentedQuery<ApiType, (arg: PropIndex | AnyNumber | Uint8Array) => Observable<Option<ITuple<[BalanceOf, Vec<AccountId>]>>>>;
|
||||
/**
|
||||
* The next free referendum index, aka the number of referenda started so far.
|
||||
**/
|
||||
referendumCount: AugmentedQuery<ApiType, () => Observable<ReferendumIndex>>;
|
||||
/**
|
||||
* The lowest referendum index representing an unbaked referendum. Equal to
|
||||
* `ReferendumCount` if there isn't a unbaked referendum.
|
||||
**/
|
||||
lowestUnbaked: AugmentedQuery<ApiType, () => Observable<ReferendumIndex>>;
|
||||
/**
|
||||
* Information concerning any given referendum.
|
||||
**/
|
||||
referendumInfoOf: AugmentedQuery<ApiType, (arg: ReferendumIndex | AnyNumber | Uint8Array) => Observable<Option<ReferendumInfo>>>;
|
||||
/**
|
||||
* Queue of successful referenda to be dispatched. Stored ordered by block number.
|
||||
**/
|
||||
dispatchQueue: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[BlockNumber, Hash, ReferendumIndex]>>>>;
|
||||
/**
|
||||
* Get the voters for the current proposal.
|
||||
**/
|
||||
votersFor: AugmentedQuery<ApiType, (arg: ReferendumIndex | AnyNumber | Uint8Array) => Observable<Vec<AccountId>>>;
|
||||
/**
|
||||
* Get the vote in a given referendum of a particular voter. The result is meaningful only
|
||||
* if `voters_for` includes the voter when called with the referendum (you'll get the
|
||||
* default `Vote` value otherwise). If you don't want to check `voters_for`, then you can
|
||||
* also check for simple existence with `VoteOf::exists` first.
|
||||
**/
|
||||
voteOf: AugmentedQuery<ApiType, (arg: ITuple<[ReferendumIndex, AccountId]> | [ReferendumIndex | AnyNumber | Uint8Array, AccountId | string | Uint8Array]) => Observable<Vote>>;
|
||||
/**
|
||||
* Who is able to vote for whom. Value is the fund-holding account, key is the
|
||||
* vote-transaction-sending account.
|
||||
**/
|
||||
proxy: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<AccountId>>>;
|
||||
/**
|
||||
* Get the account (and lock periods) to which another account is delegating vote.
|
||||
**/
|
||||
delegations: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ITuple<[AccountId, Conviction]>>>;
|
||||
/**
|
||||
* True if the last referendum tabled was submitted externally. False if it was a public
|
||||
* proposal.
|
||||
**/
|
||||
lastTabledWasExternal: AugmentedQuery<ApiType, () => Observable<bool>>;
|
||||
/**
|
||||
* The referendum to be tabled whenever it would be valid to table an external proposal.
|
||||
* This happens when a referendum needs to be tabled and one of two conditions are met:
|
||||
* - `LastTabledWasExternal` is `false`; or
|
||||
* - `PublicProps` is empty.
|
||||
**/
|
||||
nextExternal: AugmentedQuery<ApiType, () => Observable<Option<ITuple<[Hash, VoteThreshold]>>>>;
|
||||
/**
|
||||
* A record of who vetoed what. Maps proposal hash to a possible existent block number
|
||||
* (until when it may not be resubmitted) and who vetoed it.
|
||||
**/
|
||||
blacklist: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<ITuple<[BlockNumber, Vec<AccountId>]>>>>;
|
||||
/**
|
||||
* Record of all proposals that have been subject to emergency cancellation.
|
||||
**/
|
||||
cancellations: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<bool>>;
|
||||
};
|
||||
council: {
|
||||
|
||||
/**
|
||||
* The hashes of the active proposals.
|
||||
**/
|
||||
proposals: AugmentedQuery<ApiType, () => Observable<Vec<Hash>>>;
|
||||
/**
|
||||
* Actual proposal for a given hash, if it's current.
|
||||
**/
|
||||
proposalOf: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<Proposal>>>;
|
||||
/**
|
||||
* Votes on a given proposal, if it is ongoing.
|
||||
**/
|
||||
voting: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<Votes>>>;
|
||||
/**
|
||||
* Proposals so far.
|
||||
**/
|
||||
proposalCount: AugmentedQuery<ApiType, () => Observable<u32>>;
|
||||
/**
|
||||
* The current members of the collective. This is stored sorted (just by value).
|
||||
**/
|
||||
members: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>>;
|
||||
};
|
||||
elections: {
|
||||
|
||||
/**
|
||||
* The current elected membership. Sorted based on account id.
|
||||
**/
|
||||
members: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[AccountId, BalanceOf]>>>>;
|
||||
/**
|
||||
* The current runners_up. Sorted based on low to high merit (worse to best runner).
|
||||
**/
|
||||
runnersUp: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[AccountId, BalanceOf]>>>>;
|
||||
/**
|
||||
* The total number of vote rounds that have happened, excluding the upcoming one.
|
||||
**/
|
||||
electionRounds: AugmentedQuery<ApiType, () => Observable<u32>>;
|
||||
/**
|
||||
* Votes of a particular voter, with the round index of the votes.
|
||||
**/
|
||||
votesOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Vec<AccountId>>>;
|
||||
/**
|
||||
* Locked stake of a voter.
|
||||
**/
|
||||
stakeOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<BalanceOf>>;
|
||||
/**
|
||||
* The present candidate list. Sorted based on account-id. A current member or a runner can
|
||||
* never enter this vector and is always implicitly assumed to be a candidate.
|
||||
**/
|
||||
candidates: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>>;
|
||||
};
|
||||
grandpa: {
|
||||
|
||||
/**
|
||||
* DEPRECATED
|
||||
* This used to store the current authority set, which has been migrated to the well-known
|
||||
* GRANDPA_AUTHORITES_KEY unhashed key.
|
||||
**/
|
||||
authorities: AugmentedQuery<ApiType, () => Observable<AuthorityList>>;
|
||||
/**
|
||||
* State of the current authority set.
|
||||
**/
|
||||
state: AugmentedQuery<ApiType, () => Observable<StoredState>>;
|
||||
/**
|
||||
* Pending change: (signaled at, scheduled change).
|
||||
**/
|
||||
pendingChange: AugmentedQuery<ApiType, () => Observable<Option<StoredPendingChange>>>;
|
||||
/**
|
||||
* next block number where we can force a change.
|
||||
**/
|
||||
nextForced: AugmentedQuery<ApiType, () => Observable<Option<BlockNumber>>>;
|
||||
/**
|
||||
* `true` if we are currently stalled.
|
||||
**/
|
||||
stalled: AugmentedQuery<ApiType, () => Observable<Option<ITuple<[BlockNumber, BlockNumber]>>>>;
|
||||
/**
|
||||
* The number of changes (both in terms of keys and underlying economic responsibilities)
|
||||
* in the "set" of Grandpa validators from genesis.
|
||||
**/
|
||||
currentSetId: AugmentedQuery<ApiType, () => Observable<SetId>>;
|
||||
/**
|
||||
* A mapping from grandpa set ID to the index of the *most recent* session for which its members were responsible.
|
||||
**/
|
||||
setIdSession: AugmentedQuery<ApiType, (arg: SetId | AnyNumber | Uint8Array) => Observable<Option<SessionIndex>>>;
|
||||
};
|
||||
treasury: {
|
||||
|
||||
/**
|
||||
* Number of proposals that have been made.
|
||||
**/
|
||||
proposalCount: AugmentedQuery<ApiType, () => Observable<ProposalIndex>>;
|
||||
/**
|
||||
* Proposals that have been made.
|
||||
**/
|
||||
proposals: AugmentedQuery<ApiType, (arg: ProposalIndex | AnyNumber | Uint8Array) => Observable<Option<TreasuryProposal>>>;
|
||||
/**
|
||||
* Proposal indices that have been approved but not yet awarded.
|
||||
**/
|
||||
approvals: AugmentedQuery<ApiType, () => Observable<Vec<ProposalIndex>>>;
|
||||
/**
|
||||
* Tips that are not yet completed. Keyed by the hash of `(reason, who)` from the value.
|
||||
* This has the insecure enumerable hash function since the key itself is already
|
||||
* guaranteed to be a secure hash.
|
||||
**/
|
||||
tips: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<OpenTip>>>;
|
||||
/**
|
||||
* Simple preimage lookup from the reason's hash to the original data. Again, has an
|
||||
* insecure enumerable hash since the key is guaranteed to be the result of a secure hash.
|
||||
**/
|
||||
reasons: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<Bytes>>>;
|
||||
};
|
||||
contracts: {
|
||||
|
||||
/**
|
||||
* Gas spent so far in this block.
|
||||
**/
|
||||
gasSpent: AugmentedQuery<ApiType, () => Observable<Gas>>;
|
||||
/**
|
||||
* Current cost schedule for contracts.
|
||||
**/
|
||||
currentSchedule: AugmentedQuery<ApiType, () => Observable<Schedule>>;
|
||||
/**
|
||||
* A mapping from an original code hash to the original code, untouched by instrumentation.
|
||||
**/
|
||||
pristineCode: AugmentedQuery<ApiType, (arg: CodeHash | string | Uint8Array) => Observable<Option<Bytes>>>;
|
||||
/**
|
||||
* A mapping between an original code hash and instrumented wasm code, ready for execution.
|
||||
**/
|
||||
codeStorage: AugmentedQuery<ApiType, (arg: CodeHash | string | Uint8Array) => Observable<Option<PrefabWasmModule>>>;
|
||||
/**
|
||||
* The subtrie counter.
|
||||
**/
|
||||
accountCounter: AugmentedQuery<ApiType, () => Observable<u64>>;
|
||||
/**
|
||||
* The code associated with a given account.
|
||||
**/
|
||||
contractInfoOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<ContractInfo>>>;
|
||||
/**
|
||||
* The price of one unit of gas.
|
||||
**/
|
||||
gasPrice: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
|
||||
};
|
||||
identity: {
|
||||
|
||||
/**
|
||||
* Information that is pertinent to identify the entity behind an account.
|
||||
**/
|
||||
identityOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<Registration>>>;
|
||||
/**
|
||||
* The super-identity of an alternative "sub" identity together with its name, within that
|
||||
* context. If the account is not some other account's sub-identity, then just `None`.
|
||||
**/
|
||||
superOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<ITuple<[AccountId, Data]>>>>;
|
||||
/**
|
||||
* Alternative "sub" identities of this account.
|
||||
* The first item is the deposit, the second is a vector of the accounts.
|
||||
**/
|
||||
subsOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ITuple<[BalanceOf, Vec<AccountId>]>>>;
|
||||
/**
|
||||
* The set of registrars. Not expected to get very big as can only be added through a
|
||||
* special origin (likely a council motion).
|
||||
* The index into this can be cast to `RegistrarIndex` to get a valid value.
|
||||
**/
|
||||
registrars: AugmentedQuery<ApiType, () => Observable<Vec<Option<RegistrarInfo>>>>;
|
||||
};
|
||||
imOnline: {
|
||||
|
||||
/**
|
||||
* The block number after which it's ok to send heartbeats in current session.
|
||||
* At the beginning of each session we set this to a value that should
|
||||
* fall roughly in the middle of the session duration.
|
||||
* The idea is to first wait for the validators to produce a block
|
||||
* in the current session, so that the heartbeat later on will not be necessary.
|
||||
**/
|
||||
heartbeatAfter: AugmentedQuery<ApiType, () => Observable<BlockNumber>>;
|
||||
/**
|
||||
* The current set of keys that may issue a heartbeat.
|
||||
**/
|
||||
keys: AugmentedQuery<ApiType, () => Observable<Vec<AuthorityId>>>;
|
||||
/**
|
||||
* For each session index, we keep a mapping of `AuthIndex`
|
||||
* to `offchain::OpaqueNetworkState`.
|
||||
**/
|
||||
receivedHeartbeats: AugmentedQueryDoubleMap<ApiType, (key1: SessionIndex | AnyNumber | Uint8Array, key2: AuthIndex | AnyNumber | Uint8Array) => Observable<Option<Bytes>>>;
|
||||
/**
|
||||
* For each session index, we keep a mapping of `T::ValidatorId` to the
|
||||
* number of blocks authored by the given authority.
|
||||
**/
|
||||
authoredBlocks: AugmentedQueryDoubleMap<ApiType, (key1: SessionIndex | AnyNumber | Uint8Array, key2: ValidatorId | string | Uint8Array) => Observable<u32>>;
|
||||
};
|
||||
offences: {
|
||||
|
||||
/**
|
||||
* The primary structure that holds all offence records keyed by report identifiers.
|
||||
**/
|
||||
reports: AugmentedQuery<ApiType, (arg: ReportIdOf | string | Uint8Array) => Observable<Option<OffenceDetails>>>;
|
||||
/**
|
||||
* A vector of reports of the same kind that happened at the same time slot.
|
||||
**/
|
||||
concurrentReportsIndex: AugmentedQueryDoubleMap<ApiType, (key1: Kind | string | Uint8Array, key2: OpaqueTimeSlot | string | Uint8Array) => Observable<Vec<ReportIdOf>>>;
|
||||
/**
|
||||
* Enumerates all reports of a kind along with the time they happened.
|
||||
* All reports are sorted by the time of offence.
|
||||
* Note that the actual type of this mapping is `Vec<u8>`, this is because values of
|
||||
* different types are not supported at the moment so we are doing the manual serialization.
|
||||
**/
|
||||
reportsByKindIndex: AugmentedQuery<ApiType, (arg: Kind | string | Uint8Array) => Observable<Bytes>>;
|
||||
};
|
||||
randomnessCollectiveFlip: {
|
||||
|
||||
/**
|
||||
* Series of block headers from the last 81 blocks that acts as random seed material. This
|
||||
* is arranged as a ring buffer with `block_number % 81` being the index into the `Vec` of
|
||||
* the oldest hash.
|
||||
**/
|
||||
randomMaterial: AugmentedQuery<ApiType, () => Observable<Vec<Hash>>>;
|
||||
};
|
||||
nicks: {
|
||||
|
||||
/**
|
||||
* The lookup table for names.
|
||||
**/
|
||||
nameOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<ITuple<[Bytes, BalanceOf]>>>>;
|
||||
};
|
||||
sudo: {
|
||||
|
||||
/**
|
||||
* The `AccountId` of the sudo key.
|
||||
**/
|
||||
key: AugmentedQuery<ApiType, () => Observable<AccountId>>;
|
||||
};
|
||||
signaling: {
|
||||
|
||||
/**
|
||||
* The total number of proposals created thus far.
|
||||
**/
|
||||
proposalCount: AugmentedQuery<ApiType, () => Observable<u32>>;
|
||||
/**
|
||||
* A list of all extant proposals.
|
||||
**/
|
||||
inactiveProposals: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[Hash, BlockNumber]>>>>;
|
||||
/**
|
||||
* A list of active proposals along with the time at which they complete.
|
||||
**/
|
||||
activeProposals: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[Hash, BlockNumber]>>>>;
|
||||
/**
|
||||
* A list of completed proposals, pending deletion
|
||||
**/
|
||||
completedProposals: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[Hash, BlockNumber]>>>>;
|
||||
/**
|
||||
* Amount of time a proposal remains in "Voting" stage.
|
||||
**/
|
||||
votingLength: AugmentedQuery<ApiType, () => Observable<BlockNumber>>;
|
||||
/**
|
||||
* Map for retrieving the information about any proposal from its hash.
|
||||
**/
|
||||
proposalOf: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<ProposalRecord>>>;
|
||||
/**
|
||||
* Registration bond
|
||||
**/
|
||||
proposalCreationBond: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
|
||||
};
|
||||
voting: {
|
||||
|
||||
/**
|
||||
* The map of all vote records indexed by id
|
||||
**/
|
||||
voteRecords: AugmentedQuery<ApiType, (arg: u64 | AnyNumber | Uint8Array) => Observable<Option<VoteRecord>>>;
|
||||
/**
|
||||
* The number of vote records that have been created
|
||||
**/
|
||||
voteRecordCount: AugmentedQuery<ApiType, () => Observable<u64>>;
|
||||
};
|
||||
treasuryReward: {
|
||||
|
||||
/**
|
||||
* Interval in number of blocks to reward treasury
|
||||
**/
|
||||
mintingInterval: AugmentedQuery<ApiType, () => Observable<BlockNumber>>;
|
||||
/**
|
||||
* Current payout of module
|
||||
**/
|
||||
currentPayout: AugmentedQuery<ApiType, () => Observable<BalanceOf>>;
|
||||
/**
|
||||
* Current pot
|
||||
**/
|
||||
pot: AugmentedQuery<ApiType, () => Observable<Balance>>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface QueryableStorage<ApiType extends ApiTypes> extends AugmentedQueries<ApiType> {
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import '@polkadot/api/augment/rpc';
|
||||
import './augment-api-consts';
|
||||
import './augment-api-query';
|
||||
import './augment-api-tx';
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,7 @@
|
||||
// order here matches with what is found in (unused removed)
|
||||
// https://www.npmjs.com/package/edgeware-node-types
|
||||
// https://github.com/hicommonwealth/edgeware-node-types/tree/master/types
|
||||
|
||||
export { default as signaling } from './signaling/definitions';
|
||||
export { default as treasuryRewards } from './treasuryRewards/definitions';
|
||||
export { default as voting } from './voting/definitions';
|
||||
@@ -0,0 +1,4 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
export * from './types';
|
||||
@@ -0,0 +1,17 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
|
||||
export default {
|
||||
types: {
|
||||
ProposalRecord: {
|
||||
index: 'u32',
|
||||
author: 'AccountId',
|
||||
stage: 'VoteStage',
|
||||
transition_time: 'u32',
|
||||
title: 'Text',
|
||||
contents: 'Text',
|
||||
vote_id: 'u64'
|
||||
},
|
||||
ProposalContents: 'Vec<u8>',
|
||||
ProposalTitle: 'Vec<u8>'
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
export * from './types';
|
||||
@@ -0,0 +1,24 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { Struct } from '@polkadot/types/codec';
|
||||
import { Bytes, Text, u32, u64 } from '@polkadot/types/primitive';
|
||||
import { AccountId } from '@polkadot/types/interfaces/runtime';
|
||||
import { VoteStage } from 'sample-polkadotjs-typegen/interfaces/voting';
|
||||
|
||||
/** @name ProposalContents */
|
||||
export interface ProposalContents extends Bytes {}
|
||||
|
||||
/** @name ProposalRecord */
|
||||
export interface ProposalRecord extends Struct {
|
||||
readonly index: u32;
|
||||
readonly author: AccountId;
|
||||
readonly stage: VoteStage;
|
||||
readonly transition_time: u32;
|
||||
readonly title: Text;
|
||||
readonly contents: Text;
|
||||
readonly vote_id: u64;
|
||||
}
|
||||
|
||||
/** @name ProposalTitle */
|
||||
export interface ProposalTitle extends Bytes {}
|
||||
@@ -0,0 +1,7 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
|
||||
export default {
|
||||
types: {
|
||||
Balance2: 'u128'
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
export * from './types';
|
||||
@@ -0,0 +1,7 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { u128 } from '@polkadot/types/primitive';
|
||||
|
||||
/** @name Balance2 */
|
||||
export interface Balance2 extends u128 {}
|
||||
@@ -0,0 +1,6 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
export * from './signaling/types';
|
||||
export * from './treasuryRewards/types';
|
||||
export * from './voting/types';
|
||||
@@ -0,0 +1,33 @@
|
||||
/* eslint-disable @typescript-eslint/camelcase */
|
||||
|
||||
export default {
|
||||
types: {
|
||||
VoteStage: {
|
||||
_enum: ['PreVoting', 'Commit', 'Voting', 'Completed']
|
||||
},
|
||||
VoteType: {
|
||||
_enum: ['Binary', 'MultiOption', 'RankedChoice']
|
||||
},
|
||||
TallyType: {
|
||||
_enum: ['OnePerson', 'OneCoin']
|
||||
},
|
||||
VoteOutcome: '[u8; 32]',
|
||||
Tally: 'Option<Vec<(VoteOutcome, u128)>>',
|
||||
VoteData: {
|
||||
initiator: 'AccountId',
|
||||
stage: 'VoteStage',
|
||||
vote_type: 'VoteType',
|
||||
tally_type: 'TallyType',
|
||||
is_commit_reveal: 'bool'
|
||||
},
|
||||
Commitments: 'Vec<(AccountId, VoteOutcome)>',
|
||||
Reveals: 'Vec<(AccountId, Vec<VoteOutcome>)>',
|
||||
VoteRecord: {
|
||||
id: 'u64',
|
||||
commitments: 'Commitments',
|
||||
reveals: 'Reveals',
|
||||
data: 'VoteData',
|
||||
outcomes: 'Vec<VoteOutcome>'
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -0,0 +1,4 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
export * from './types';
|
||||
@@ -0,0 +1,58 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
import { Enum, Option, Struct, U8aFixed, Vec } from '@polkadot/types/codec';
|
||||
import { bool, u128, u64 } from '@polkadot/types/primitive';
|
||||
import { AccountId } from '@polkadot/types/interfaces/runtime';
|
||||
|
||||
/** @name Commitments */
|
||||
export interface Commitments extends Vec<ITuple<[AccountId, VoteOutcome]>> {}
|
||||
|
||||
/** @name Reveals */
|
||||
export interface Reveals extends Vec<ITuple<[AccountId, Vec<VoteOutcome>]>> {}
|
||||
|
||||
/** @name Tally */
|
||||
export interface Tally extends Option<Vec<ITuple<[VoteOutcome, u128]>>> {}
|
||||
|
||||
/** @name TallyType */
|
||||
export interface TallyType extends Enum {
|
||||
readonly isOnePerson: boolean;
|
||||
readonly isOneCoin: boolean;
|
||||
}
|
||||
|
||||
/** @name VoteData */
|
||||
export interface VoteData extends Struct {
|
||||
readonly initiator: AccountId;
|
||||
readonly stage: VoteStage;
|
||||
readonly vote_type: VoteType;
|
||||
readonly tally_type: TallyType;
|
||||
readonly is_commit_reveal: bool;
|
||||
}
|
||||
|
||||
/** @name VoteOutcome */
|
||||
export interface VoteOutcome extends U8aFixed {}
|
||||
|
||||
/** @name VoteRecord */
|
||||
export interface VoteRecord extends Struct {
|
||||
readonly id: u64;
|
||||
readonly commitments: Commitments;
|
||||
readonly reveals: Reveals;
|
||||
readonly data: VoteData;
|
||||
readonly outcomes: Vec<VoteOutcome>;
|
||||
}
|
||||
|
||||
/** @name VoteStage */
|
||||
export interface VoteStage extends Enum {
|
||||
readonly isPreVoting: boolean;
|
||||
readonly isCommit: boolean;
|
||||
readonly isVoting: boolean;
|
||||
readonly isCompleted: boolean;
|
||||
}
|
||||
|
||||
/** @name VoteType */
|
||||
export interface VoteType extends Enum {
|
||||
readonly isBinary: boolean;
|
||||
readonly isMultiOption: boolean;
|
||||
readonly isRankedChoice: boolean;
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
// this is specific with augmented overrides
|
||||
"paths": {
|
||||
// this is the package name we use (in the interface imports, --package for generators)
|
||||
"sample-polkadotjs-typegen/*": ["src/*"],
|
||||
// here we replace the @polkadot/api augmentation with our own, generated from chain
|
||||
"@polkadot/api/augment": ["src/interfaces/augment-api.ts"],
|
||||
// replace the augmented types with our own, as generated from definitions
|
||||
"@polkadot/types/augment": ["src/interfaces/augment-types.ts"]
|
||||
},
|
||||
// some other options, whatever you want for your environment
|
||||
"target": "esnext",
|
||||
"module": "esnext",
|
||||
"jsx": "preserve",
|
||||
"declaration": true,
|
||||
"strict": true,
|
||||
"noImplicitAny": true,
|
||||
"noUnusedLocals": true,
|
||||
"noImplicitReturns": true,
|
||||
"moduleResolution": "node",
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"esModuleInterop": true,
|
||||
"baseUrl": ".",
|
||||
"skipLibCheck": true,
|
||||
"typeRoots": [
|
||||
"./node_modules/@types"
|
||||
]
|
||||
},
|
||||
"exclude": [
|
||||
"build/**/*",
|
||||
"node_modules"
|
||||
]
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
**NOTE** Removed - in metadata v11 we get the extensions from the chain, we need to be able to specify these. These docs are now outdated.
|
||||
|
||||
# Extending extrinsics
|
||||
|
||||
On some chains, the need may arise to customize the extrinsic format. In this section we will explain what extrinsics and their payloads contain, explain how signed extensions work and provide a walk through of an advanced use-case where extrinsics are customized for a specific Substrate chain.
|
||||
@@ -153,6 +155,3 @@ In the above example, should these updates only be made on the node side, withou
|
||||
|
||||
(These extensions are not exposed via metadata at all, and would be quite difficult to do as well - since each of these have specific logic as well as data types assigned.)
|
||||
|
||||
## Using with TypeScript
|
||||
|
||||
The API is built with TypeScript (as are all projects in the [polkadot-js organization](https://github.com/polkadot-js/)) and as such allows developers using TS to have access to all the type interfaces defined on the chain, as well as having access to typings on interacting with the `api.*` namespaces. In the next section we will provide an overview of [what is available in terms of types and TypeScript](typescript.md).
|
||||
@@ -12,6 +12,14 @@ If however you are running against a master branch of either Polkadot or Substra
|
||||
|
||||
Update your version of the API to the [latest version](install.md). Like types, the [metadata interfaces](basics.md) are continuously evolving. For instance with the Polkadot Alexander network, only metadata v3 is available. By the time Kusama launched, this has been bumped to v7. As these versions are added to the Polkadot/Substrate codebase, they are added to the API.
|
||||
|
||||
## The node returns a "Could not convert" error on send
|
||||
|
||||
The typical error that you would see is `Verification Error: Execution(ApiError("Could not convert parameter 'tx' between node and runtime`. This means that the transaction data serialized from the API cannot be deserialized on the node.
|
||||
|
||||
All data transferred between the API and the Node is in a SCALE-encoded binary format, so the [definition of the types](types.extend.md) between the API and the node needs to match 100%. When you find the above, it would mean the definition of the types on the API side does not match what is on the node. Specifically the API encodes against the definition, but since there is a mismatch the Node cannot parse the data correctly.
|
||||
|
||||
To fix this, you should look at the specific `api.tx.*` params and adjust the type definitions for those param types to match what is found on the node side. In some rare cases the cause could be extrinsic formatting related, to track these make an `api.tx.system.remark(data: Bytes)` call, if it fails, the API and node cannot agree on [an extrinsic format and adjustments are required](types.extend.md#impact-on-extrinsics).
|
||||
|
||||
## I would like to sign transactions offline
|
||||
|
||||
The API itself is independent on where the signature comes from and how it is injected. Additionally it implements a signer interface, that can be used for external signing - an example of this is the [polkadot-js/apps](https://github.com/polkadot-js/apps) support for signing via extensions and even the [polkadot-js/extension](https://github.com/polkadot-js/extension) support for tools such as the [Parity Signer](https://github.com/paritytech/parity-signer).
|
||||
|
||||
@@ -21,6 +21,7 @@ import type { Balance } from '@polkadot/types/interfaces';
|
||||
|
||||
...
|
||||
// unwrap out option into a zero Balance whn not found
|
||||
// (This can be done via `.unwrapOrDefault()`, which does the same underlying)
|
||||
const balance: Balance = balanceOpt.unwrapOr(api.createType('Balance'));
|
||||
```
|
||||
|
||||
@@ -45,10 +46,11 @@ api.createType('Balance', 123);
|
||||
// via registry (`.registry` is on all API and Codec objects)
|
||||
api.registry.createType('Balance', 123n);
|
||||
|
||||
// via the low-level approach
|
||||
// via the low-level approach (not recommended)
|
||||
createType(api.registry, 'Balance', '123');
|
||||
```
|
||||
|
||||
## Extending extrinsics
|
||||
## Using with TypeScript
|
||||
|
||||
The API is built with TypeScript (as are all projects in the [polkadot-js organization](https://github.com/polkadot-js/)) and as such allows developers using TS to have access to all the type interfaces defined on the chain, as well as having access to typings on interacting with the `api.*` namespaces. In the next section we will provide an overview of [what is available in terms of types and TypeScript](typescript.md).
|
||||
|
||||
On customized chains, it is possible to [extend the format of the extrinsics and extrinsic payload for the chain](extrinsic.extend.md), next up we will look at this advanced use-case.
|
||||
|
||||
@@ -10,7 +10,7 @@ There is a the [recommendation](install.md#betas) to use a `@polkadot/api@beta`
|
||||
|
||||
## Extension
|
||||
|
||||
As a blockchain toolkit, Substrate makes it easy to add your own modules and types. In most non-trivial implementations, this would mean that developers are adding specific types for their implementation as well. The API will get to know the names of these types via the metadata, however it won't understand what they are, which means it cannot encode or decode them.
|
||||
As a blockchain toolkit, Substrate makes it easy to add your own modules and types. In most non-trivial implementations, this would mean that developers are adding specific types for their implementation as well. The API will get to know the names of these types via the metadata, however it won't understand what they are, which means it cannot encode or decode them. Additionally, when a type is mismatched between the node and the API, the decoding can fail, yielding issues such as [Could not convert errors](FAQ.md#the-node-returns-a-could-not-convert-error-on-send) when submitting transactions.
|
||||
|
||||
To close this gap, the API allows for the injection of types, i.e. you can explicitly define (or override) types for the node/chain you are connecting to. In the simplest example, assuming you have a chain where your `Balance` type is a `u64` (as opposed to the default `u128`), you need to let the API know -
|
||||
|
||||
@@ -26,7 +26,7 @@ const api = await ApiPromise.create({
|
||||
|
||||
The above introduces the `types` registry, effectively allowing overrides and the definition of new types. The override above would mean that immediately the API will treat all occurrences of `Balance` not as the default, but rather as the defined size.
|
||||
|
||||
## User-defined types
|
||||
## User-defined structs
|
||||
|
||||
Registration also applies to any type that can be found on a specific chain, i.e. we can add any types that is available on a specific node -
|
||||
|
||||
@@ -54,6 +54,30 @@ const api = await ApiPromise.create({
|
||||
|
||||
The example above defines non-primitive types (as found in the specific implementation) as structures. Additionally it also shows the user-defined types can depend on other user-defined types with `Transaction` referencing both `TransactionInput` and `TransactionOutput`. Here you can reference any known types, i.e. in the above we have referenced primitives such as `u32` and `Signature` (itself an alias for `H512`).
|
||||
|
||||
## Definition clashes
|
||||
|
||||
As explained in a previous section, the underlying API Codec types have a [number of built-in properties](type.basics.md) and in some cases it could be that your struct has a field that conflicts. These should be minimal, however it can happen. Take the following example where a defined `hash` property clashes with the same-name Codec property -
|
||||
|
||||
```js
|
||||
Document: {
|
||||
name: 'Text',
|
||||
uri: 'Text',
|
||||
hash: 'Text'
|
||||
}
|
||||
```
|
||||
|
||||
For this struct the `hash` will not be exposed, but rather be kept as the built-in `hash`. At this point it is important to know that the values "over-the-wire" for calls, queries, events and consts is in binary form, i.e. it is an encoding of the values only. So on the JS side you can apply a rename with no ill-effects. Here we rename the `hash` to `docHash`, which mean the value will be available on `<instance>.docHash`.
|
||||
|
||||
```js
|
||||
Document: {
|
||||
name: 'Text',
|
||||
uri: 'Text',
|
||||
docHash: 'Text'
|
||||
}
|
||||
```
|
||||
|
||||
## User-defined enum
|
||||
|
||||
One form of types that appear regularly is enums, these can be defined as follow -
|
||||
|
||||
```js
|
||||
@@ -109,7 +133,7 @@ In the same way `typesChain` can be used to match on the actual chain name, i.e.
|
||||
const api = await ApiPromise.create({
|
||||
...,
|
||||
typesChain: {
|
||||
'Kusama CC1': {
|
||||
Kusama: {
|
||||
BlockNumber: 'u32',
|
||||
Index: 'u32'
|
||||
}
|
||||
@@ -137,6 +161,46 @@ const api = await ApiPromise.create({
|
||||
|
||||
`Balance` would be defined as an `u128` at the end. Effectively based on the flow it is first registered as a `u32`, then overridden as a `u64` and finally overridden once more as a `u128` by the chain types.
|
||||
|
||||
## Impact on extrinsics
|
||||
|
||||
When configuring your chain, be cognizant of the types you are using, and always ensure that any changes are replicated back to the API. In an earlier example we configured `Balance` as `u64`, in this case the same changes needs to be applied on the API, especially when there are mismatches compared to Substrate master. Not doing so means that failures will occur. The same would happen when your own types have mismatched fields or types are lacking fields on structs or enums.
|
||||
|
||||
Mismatches also applies to any other chain-specific configured types and can have impacts on transactions. For instance you can customize `Lookup` and `Address` on your chain, changing the default lookup behavior. A real example of this is the Substrate master node vs the Substrate master node-template -
|
||||
|
||||
```rust
|
||||
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
|
||||
type Lookup = Indices;
|
||||
...
|
||||
/// The address format for describing accounts.
|
||||
pub type Address = <Indices as StaticLookup>::Source;
|
||||
```
|
||||
|
||||
And this is what is defined on the node-template -
|
||||
|
||||
```rust
|
||||
/// The lookup mechanism to get account ID from whatever is passed in dispatchers.
|
||||
type Lookup = IdentityLookup<AccountId>;
|
||||
...
|
||||
/// The address format for describing accounts.
|
||||
pub type Address = AccountId;
|
||||
```
|
||||
|
||||
Here the template was customized from the Substrate node defaults and the API needs to know how to map these types. Failure to make adjustments means transactions will fail. With this in mind the correct types that needs to be added here would be -
|
||||
|
||||
```js
|
||||
const api = await ApiPromise.create({
|
||||
...,
|
||||
types: {
|
||||
// mapping the actual specified address format
|
||||
Address: 'AccountId',
|
||||
// mapping the lookup
|
||||
LookupSource: 'AccountId'
|
||||
}
|
||||
});
|
||||
```
|
||||
|
||||
Always look at customization and understand the impacts, replicating these changes between the node and the API. For the above the `Address` type is used in the construction of the `UncheckedExtrinsic` type, while the lookup type is applicable on transactions such as `balances.transfer(to: LookupSource, value: Balance)`
|
||||
|
||||
## Type creation
|
||||
|
||||
While the API always converts all the inputs into the underlying type required by the operation, in some cases you may want to [cret an instance of a type](types.create.md) yourself.
|
||||
While the API always converts all the inputs into the underlying type required by the operation, in some cases you may want to [create an instance of a type](types.create.md) yourself.
|
||||
|
||||
@@ -23,20 +23,22 @@ In the subscription example, we explicitly define `lastHead: Header`, although t
|
||||
|
||||
As indicated, most of the Polkadot/Substrate default types are available via `types/interfaces`. However, for primitives types where there is an actual implementation, these are made available via `@polkadot/types` directly. For instance, `import { u32 } from '@polkadot/types` is valid in this context.
|
||||
|
||||
## Metadata injected
|
||||
## Storage generics
|
||||
|
||||
For any interface injected by metadata, the types are not available by default (although it may be in the future for default interfaces), but rather what the API understands is that all results need to comply to the `Codec` interface. (The base of all our types)
|
||||
For any interface injected by metadata, the types are not fully described but rather names and the API will decode all these into an instance that complies with the `Codec` interface. (The base of all our types)
|
||||
|
||||
However, to make this sane from a developer perspective the injected methods are generic, effectively making the following possible -
|
||||
However, this does allow you to perform overrides via generics, making the following possible -
|
||||
|
||||
```js
|
||||
import { AccountData, Index } from '@polkadot/types/interfaces';
|
||||
import { Balance } from '@polkadot/types/interfaces';
|
||||
|
||||
type Balance2 = Balance;
|
||||
|
||||
...
|
||||
const { nonce, data: balances } = await api.query.system.account<[Index, AccountData]>(ADDR);
|
||||
const total = await api.query.balances.totalIssuance<Balance2>();
|
||||
```
|
||||
|
||||
In both these case we can instruct the TypeScript compiler that the type we are expecting in `Index` and `Balance` respectively, not just pure `Codec`. This means that functions like `.toNumber()` is available on both these types - as opposed to just the [general type defaults](types.basics.md#everything-is-a-type) with `.toHex()` and friends.
|
||||
In this example (although the query does indeed return a `Balance`) we can instruct the TypeScript compiler that we are expecting a `Balance2`, not just the interface as generated. This means that functions like `.toNumber()` is available on both these types - as opposed to just the [general type defaults](types.basics.md#everything-is-a-type) with `.toHex()` and friends.
|
||||
|
||||
## Adding user types
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
# TypeScript user generated
|
||||
|
||||
In the previous section we looked at the TypeScript definitions that are available and is generated from both the chain and definitions. Here we will expand upon the use of the infrastructure created to define types as part of the `@polkadot/types` library and see how to use them to generate your onw defintions and chain types.
|
||||
In the previous section we looked at the TypeScript definitions that are available and is generated from both the chain and definitions. Here we will expand upon the use of the infrastructure created to define types as part of the `@polkadot/types` library and see how to use them to generate your onw definitions and chain types.
|
||||
|
||||
## Definitions
|
||||
|
||||
@@ -9,17 +9,21 @@ A large part of the type definitions are defined not as classes, but rather as s
|
||||
To create TypeScript-aware definitions and keep your files in a single place, you can follow the same approach. Assuming you have a package named `@MeInc/stuff` where you have the definitions in an `stuff/interfaces` folder. Each sub-folder would indicate a runtime module, e.g.
|
||||
|
||||
- `stuff/interfaces/<module>/definitions.ts` for each module (`types.ts` & `index.ts` will be generated)
|
||||
- `stuff/interfaces/defnitions.ts` importing all sub-definitions`
|
||||
- `stuff/interfaces/definitions.ts` importing all sub-definitions`
|
||||
|
||||
With this structure setup, you can generate TypeScript defintions.
|
||||
With this structure setup, you can generate TypeScript definitions.
|
||||
|
||||
In the root of your project (with the `@polkadot/typegen` package installed), you can run `yarn polkadot-types-from-defs --input ./stuff/interfaces --package @MeInc/stuff/interfaces` which will create `types.ts` and `index.ts` files with the generated types. You can use these in exactly the same way as you would use your types from `@polkadot/types/interfaces`.
|
||||
|
||||
## Chain modules
|
||||
|
||||
In the same way as the type library provides defaults from a substrate-base chain, you can also, directly from chain from metadata, generate a complete `api.{consts,query}.*` defintion for your specific chain. The command will create 2 files, `{consts, query}.types.ts` which you can either use to augment the TypeScript defintions, or replace those in `@polkadot/api/*` with your versions (copy, TypeScript replacement or browser/node aliassing).
|
||||
In the same way as the type library provides defaults from a substrate-base chain, you can also, directly from chain from metadata, generate a complete `api.{consts,query}.*` definition for your specific chain. The command will create 2 files, `{consts, query}.types.ts` which you can either use to augment the TypeScript definitions, or replace those in `@polkadot/api/*` with your versions (copy, TypeScript replacement or browser/node aliasing).
|
||||
|
||||
In the root of your project, you can run `yarn polkadot-types-from-chain --endpoint wss://<url> --output ./stuff` and it will create the required output. (Here you can specify an optional `--package @MeInc/stuff` to read definitions for the targetted output folder with the specified package name.)
|
||||
In the root of your project, you can run `yarn polkadot-types-from-chain --endpoint wss://<url> --output ./stuff` and it will create the required output. (Here you can specify an optional `--package @MeInc/stuff` to read definitions for the targeted output folder with the specified package name.)
|
||||
|
||||
## Example of actual use
|
||||
|
||||
The [TypeScript augmentation example](../examples/promise/90_typegen/) example provides a full real-world example of these scripts in action. Additionally it shows all the configurations from a TypeScript as well as an in-use perspective, showing how the types and interfaces are fully augmented based on the provided metadata.
|
||||
|
||||
## And that's a wrap
|
||||
|
||||
|
||||
+1
-1
@@ -9,5 +9,5 @@
|
||||
"packages": [
|
||||
"packages/*"
|
||||
],
|
||||
"version": "1.4.1"
|
||||
"version": "1.6.2"
|
||||
}
|
||||
|
||||
+7
-7
@@ -1,14 +1,13 @@
|
||||
{
|
||||
"version": "1.4.1",
|
||||
"repository": "https://github.com/polkadot-js/api",
|
||||
"author": "Jaco Greeff <jacogr@gmail.com>",
|
||||
"license": "Apache-2",
|
||||
"private": true,
|
||||
"engines": {
|
||||
"yarn": "^1.10.1"
|
||||
},
|
||||
"workspaces": [
|
||||
"packages/*"
|
||||
],
|
||||
"resolutions": {
|
||||
"typescript": "^3.8.2"
|
||||
"typescript": "^3.8.3"
|
||||
},
|
||||
"scripts": {
|
||||
"build": "yarn build:interfaces && polkadot-dev-build-ts && (cd packages/typegen && copyfiles scripts/* build)",
|
||||
@@ -26,8 +25,9 @@
|
||||
"@babel/core": "^7.8.4",
|
||||
"@babel/register": "^7.8.3",
|
||||
"@babel/runtime": "^7.8.4",
|
||||
"@polkadot/dev": "^0.41.4",
|
||||
"@polkadot/ts": "^0.2.3",
|
||||
"@polkadot/dev": "^0.50.30",
|
||||
"@polkadot/ts": "^0.3.7",
|
||||
"@polkadot/typegen": "workspace:packages/typegen",
|
||||
"copyfiles": "^2.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api-contract",
|
||||
"version": "1.4.1",
|
||||
"version": "1.6.2",
|
||||
"description": "Interfaces for interacting with contracts and contract ABIs",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -27,10 +27,10 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.8.4",
|
||||
"@polkadot/api": "1.4.1",
|
||||
"@polkadot/rpc-core": "1.4.1",
|
||||
"@polkadot/types": "1.4.1",
|
||||
"@polkadot/util": "^2.5.1",
|
||||
"@polkadot/api": "1.6.2",
|
||||
"@polkadot/rpc-core": "1.6.2",
|
||||
"@polkadot/types": "1.6.2",
|
||||
"@polkadot/util": "^2.6.2",
|
||||
"bn.js": "^5.1.1",
|
||||
"rxjs": "^6.5.4"
|
||||
}
|
||||
|
||||
@@ -47,10 +47,11 @@ export default class Code<ApiType extends ApiTypes> extends BaseWithTx<ApiType>
|
||||
public createBlueprint = (maxGas: number | BN): CodePutCode<ApiType> => {
|
||||
return {
|
||||
signAndSend: this.decorateMethod(
|
||||
(account: IKeyringPair | string | AccountId | Address): CodePutCodeResultSubscription<ApiType> => this.apiContracts
|
||||
.putCode(maxGas, compactAddLength(this.code))
|
||||
.signAndSend(account)
|
||||
.pipe(map(this.createResult))
|
||||
(account: IKeyringPair | string | AccountId | Address): CodePutCodeResultSubscription<ApiType> =>
|
||||
this.apiContracts
|
||||
.putCode(maxGas, compactAddLength(this.code))
|
||||
.signAndSend(account)
|
||||
.pipe(map(this.createResult))
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -41,8 +41,8 @@ export default class Contract<ApiType extends ApiTypes> extends BaseWithTxAndRpc
|
||||
return {
|
||||
send: this.decorateMethod(
|
||||
as === 'rpc' && this.hasRpcContractsCall
|
||||
? (account: IKeyringPair | string | AccountId | Address): ContractCallResult<'rpc'> => {
|
||||
return this.rpcContractsCall(
|
||||
? (account: IKeyringPair | string | AccountId | Address): ContractCallResult<'rpc'> =>
|
||||
this.rpcContractsCall(
|
||||
this.registry.createType('ContractCallRequest', {
|
||||
origin: account,
|
||||
dest: this.address.toString(),
|
||||
@@ -50,18 +50,13 @@ export default class Contract<ApiType extends ApiTypes> extends BaseWithTxAndRpc
|
||||
gasLimit,
|
||||
inputData: fn(...params)
|
||||
})
|
||||
)
|
||||
.pipe(
|
||||
map((result: ContractExecResult): ContractCallOutcome =>
|
||||
this.createOutcome(result, this.registry.createType('AccountId', account), def, params)
|
||||
)
|
||||
);
|
||||
}
|
||||
: (account: IKeyringPair | string | AccountId | Address): ContractCallResult<'tx'> => {
|
||||
return this.apiContracts
|
||||
).pipe(map((result: ContractExecResult): ContractCallOutcome =>
|
||||
this.createOutcome(result, this.registry.createType('AccountId', account), def, params)
|
||||
))
|
||||
: (account: IKeyringPair | string | AccountId | Address): ContractCallResult<'tx'> =>
|
||||
this.apiContracts
|
||||
.call(this.address, value, gasLimit, fn(...params))
|
||||
.signAndSend(account);
|
||||
}
|
||||
.signAndSend(account)
|
||||
)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -29,14 +29,13 @@ export abstract class Base<ApiType extends ApiTypes> implements ContractBase<Api
|
||||
}
|
||||
|
||||
public get messages (): ContractMessage[] {
|
||||
return this.abi.abi.contract.messages
|
||||
.map(
|
||||
(def: ContractABIMessage, index): ContractMessage => ({
|
||||
index,
|
||||
def,
|
||||
fn: this.abi.messages[def.name] || this.abi.messages[stringCamelCase(name)]
|
||||
})
|
||||
);
|
||||
return this.abi.abi.contract.messages.map(
|
||||
(def: ContractABIMessage, index): ContractMessage => ({
|
||||
index,
|
||||
def,
|
||||
fn: this.abi.messages[def.name] || this.abi.messages[stringCamelCase(name)]
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
public getMessage (nameOrIndex?: string | number): ContractMessage {
|
||||
@@ -46,6 +45,7 @@ export abstract class Base<ApiType extends ApiTypes> implements ContractBase<Api
|
||||
: this.abi.abi.contract.messages.findIndex((message): boolean => nameOrIndex === message.name || nameOrIndex === stringCamelCase(message.name))
|
||||
: 0;
|
||||
const def = this.abi.abi.contract.messages[index];
|
||||
|
||||
assert(!!def, `Attempted to access a contract message that does not exist: ${typeof nameOrIndex === 'number' ? `index ${nameOrIndex}` : nameOrIndex}`);
|
||||
|
||||
const fn = this.abi.messages[def.name] || this.abi.messages[stringCamelCase(def.name)];
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api-derive",
|
||||
"version": "1.4.1",
|
||||
"version": "1.6.2",
|
||||
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -28,17 +28,17 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.8.4",
|
||||
"@polkadot/api": "1.4.1",
|
||||
"@polkadot/rpc-core": "1.4.1",
|
||||
"@polkadot/rpc-provider": "1.4.1",
|
||||
"@polkadot/types": "1.4.1",
|
||||
"@polkadot/util": "^2.5.1",
|
||||
"@polkadot/util-crypto": "^2.5.1",
|
||||
"@polkadot/api": "1.6.2",
|
||||
"@polkadot/rpc-core": "1.6.2",
|
||||
"@polkadot/rpc-provider": "1.6.2",
|
||||
"@polkadot/types": "1.6.2",
|
||||
"@polkadot/util": "^2.6.2",
|
||||
"@polkadot/util-crypto": "^2.6.2",
|
||||
"bn.js": "^5.1.1",
|
||||
"memoizee": "^0.4.14",
|
||||
"rxjs": "^6.5.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.5.1"
|
||||
"@polkadot/keyring": "^2.6.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,17 +26,17 @@ function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIn
|
||||
const accountId = createType(api.registry, 'AccountId', decoded);
|
||||
|
||||
return api.derive.accounts.idToIndex(accountId).pipe(
|
||||
map((accountIndex): AccountIdAndIndex => [accountId, accountIndex] as AccountIdAndIndex)
|
||||
map((accountIndex): AccountIdAndIndex => [accountId, accountIndex])
|
||||
);
|
||||
}
|
||||
|
||||
const accountIndex = createType(api.registry, 'AccountIndex', decoded);
|
||||
|
||||
return api.derive.accounts.indexToId(accountIndex).pipe(
|
||||
map((accountId): AccountIdAndIndex => [accountId, accountIndex] as AccountIdAndIndex)
|
||||
map((accountId): AccountIdAndIndex => [accountId, accountIndex])
|
||||
);
|
||||
} catch (error) {
|
||||
return of([undefined, undefined] as AccountIdAndIndex);
|
||||
return of([undefined, undefined]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import { AccountId, AccountIndex } from '@polkadot/types/interfaces';
|
||||
import { AccountIndexes } from '../types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map, startWith } from 'rxjs/operators';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
@@ -28,7 +28,6 @@ import { memo } from '../util';
|
||||
export function idToIndex (api: ApiInterfaceRx): (accountId: AccountId | string) => Observable<AccountIndex | undefined> {
|
||||
return memo((accountId: AccountId | string): Observable<AccountIndex | undefined> =>
|
||||
api.derive.accounts.indexes().pipe(
|
||||
startWith({}),
|
||||
map((indexes: AccountIndexes): AccountIndex | undefined =>
|
||||
(indexes || {})[accountId.toString()]
|
||||
)
|
||||
|
||||
@@ -9,12 +9,12 @@ import { Observable, of } from 'rxjs';
|
||||
import { map, startWith } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/generic/AccountIndex';
|
||||
import { ClassOf, Option, Vec, createType } from '@polkadot/types';
|
||||
import { Option, Vec, createType } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function queryEnumSet (api: ApiInterfaceRx, _accountIndex: AccountIndex | string): Observable<AccountId | undefined> {
|
||||
const accountIndex = _accountIndex instanceof ClassOf(api.registry, 'AccountIndex')
|
||||
const accountIndex = _accountIndex instanceof api.registry.createClass('AccountIndex')
|
||||
? _accountIndex
|
||||
: createType(api.registry, 'AccountIndex', _accountIndex);
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import { AccountId, AccountIndex } from '@polkadot/types/interfaces';
|
||||
import { AccountIndexes } from '../types';
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { map, startWith, switchMap } from 'rxjs/operators';
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/generic/AccountIndex';
|
||||
import { Vec, createType } from '@polkadot/types';
|
||||
|
||||
@@ -25,24 +25,33 @@ function queryEnumSet (api: ApiInterfaceRx): Observable<AccountIndexes> {
|
||||
api.query.indices.enumSet.multi<Vec<AccountId>>([...Array(next.toNumber() + 1).keys()])
|
||||
),
|
||||
map((all: AccountId[][]): AccountIndexes =>
|
||||
all.reduce((result: AccountIndexes, list, outerIndex): AccountIndexes => {
|
||||
all.reduce((indexes: AccountIndexes, list, outerIndex): AccountIndexes => {
|
||||
(list || []).forEach((accountId, innerIndex): void => {
|
||||
// re-create the index based on position 0 is [0][0] and likewise
|
||||
// 64 (0..63 in first) is [1][0] (the first index value in set 2)
|
||||
const index = (outerIndex * enumsetSize) + innerIndex;
|
||||
|
||||
result[accountId.toString()] = createType(api.registry, 'AccountIndex', index);
|
||||
indexes[accountId.toString()] = createType(api.registry, 'AccountIndex', index);
|
||||
});
|
||||
|
||||
return result;
|
||||
return indexes;
|
||||
}, {})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// TODO Reverse lookup (via query keys)
|
||||
function query (): Observable<AccountIndexes> {
|
||||
return of({} as AccountIndexes);
|
||||
function queryAccounts (api: ApiInterfaceRx): Observable<AccountIndexes> {
|
||||
return api.query.indices.accounts.entries().pipe(
|
||||
map((entries): AccountIndexes =>
|
||||
entries.reduce((indexes: AccountIndexes, [key, idOpt]): AccountIndexes => {
|
||||
if (idOpt.isSome) {
|
||||
indexes[idOpt.unwrap()[0].toString()] = key.args[0] as AccountIndex;
|
||||
}
|
||||
|
||||
return indexes;
|
||||
}, {})
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,10 +71,11 @@ function query (): Observable<AccountIndexes> {
|
||||
*/
|
||||
export function indexes (api: ApiInterfaceRx): () => Observable<AccountIndexes> {
|
||||
return memo((): Observable<AccountIndexes> =>
|
||||
api.query.indices
|
||||
(api.query.indices
|
||||
? api.query.indices.accounts
|
||||
? query()
|
||||
? queryAccounts(api)
|
||||
: queryEnumSet(api)
|
||||
: of({} as AccountIndexes)
|
||||
).pipe(startWith({}))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ type Result = [DerivedBalancesAccount, BlockNumber, ResultBalance];
|
||||
function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBalance, frozenFee, frozenMisc, reservedBalance, votingBalance }, bestNumber, [vesting, locks]]: Result): DerivedBalancesAll {
|
||||
let lockedBalance = createType(api.registry, 'Balance');
|
||||
let lockedBreakdown: (BalanceLock | BalanceLockTo212)[] = [];
|
||||
let allLocked = false;
|
||||
|
||||
if (Array.isArray(locks)) {
|
||||
// only get the locks that are valid until passed the current block
|
||||
@@ -27,6 +28,8 @@ function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBala
|
||||
|
||||
const notAll = lockedBreakdown.filter(({ amount }): boolean => !amount.isMax());
|
||||
|
||||
allLocked = lockedBreakdown.some(({ amount }): boolean => amount.isMax());
|
||||
|
||||
// get the maximum of the locks according to https://github.com/paritytech/substrate/blob/master/srml/balances/src/lib.rs#L699
|
||||
if (notAll.length) {
|
||||
lockedBalance = createType(api.registry, 'Balance', bnMax(...notAll.map(({ amount }): Balance => amount)));
|
||||
@@ -50,7 +53,7 @@ function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBala
|
||||
// ""
|
||||
const floating = freeBalance.sub(lockedBalance);
|
||||
const extraReceived = isVesting ? freeBalance.sub(vestingTotal) : new BN(0);
|
||||
const availableBalance = createType(api.registry, 'Balance', bnMax(new BN(0), isVesting && floating.gt(vestedBalance) ? vestedBalance.add(extraReceived) : floating));
|
||||
const availableBalance = createType(api.registry, 'Balance', allLocked ? 0 : bnMax(new BN(0), isVesting && floating.gt(vestedBalance) ? vestedBalance.add(extraReceived) : floating));
|
||||
|
||||
return {
|
||||
accountId,
|
||||
@@ -92,7 +95,7 @@ function queryOld (api: ApiInterfaceRx, accountId: AccountId): Observable<Result
|
||||
// current (balances vesting)
|
||||
function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable<ResultBalance> {
|
||||
return (
|
||||
api.query.vesting.vesting
|
||||
api.query.vesting?.vesting
|
||||
? api.queryMulti<[Vec<BalanceLock>, Option<VestingInfo>]>([
|
||||
[api.query.balances.locks, accountId],
|
||||
[api.query.vesting.vesting, accountId]
|
||||
|
||||
@@ -29,13 +29,13 @@ export function fees (api: ApiInterfaceRx): () => Observable<DerivedFees> {
|
||||
return memo((): Observable<DerivedFees> =>
|
||||
of([
|
||||
// deprecated - remove
|
||||
(api.consts.balances.creationFee as Balance) || createType(api.registry, 'Balance'),
|
||||
(api.consts.balances.transferFee as Balance) || createType(api.registry, 'Balance'),
|
||||
(api.consts.balances?.creationFee as Balance) || createType(api.registry, 'Balance'),
|
||||
(api.consts.balances?.transferFee as Balance) || createType(api.registry, 'Balance'),
|
||||
|
||||
// current
|
||||
api.consts.balances.existentialDeposit,
|
||||
api.consts.transactionPayment.transactionBaseFee,
|
||||
api.consts.transactionPayment.transactionByteFee
|
||||
(api.consts.balances?.existentialDeposit as Balance) || createType(api.registry, 'Balance'),
|
||||
(api.consts.transactionPayment?.transactionBaseFee as Balance) || createType(api.registry, 'Balance'),
|
||||
(api.consts.transactionPayment?.transactionByteFee as Balance) || createType(api.registry, 'Balance')
|
||||
]).pipe(
|
||||
map(([creationFee, transferFee, existentialDeposit, transactionBaseFee, transactionByteFee]): DerivedFees => ({
|
||||
creationFee,
|
||||
|
||||
@@ -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 { BlockNumber, Header } from '@polkadot/types/interfaces';
|
||||
import { BlockNumber } from '@polkadot/types/interfaces';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
@@ -25,6 +25,6 @@ import { memo } from '../util';
|
||||
export function bestNumber (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
api.derive.chain.subscribeNewHeads().pipe(
|
||||
map((header: Header): BlockNumber => header.number.unwrap())
|
||||
map((header) => header.number.unwrap())
|
||||
));
|
||||
}
|
||||
|
||||
@@ -26,6 +26,6 @@ import { memo } from '../util';
|
||||
export function bestNumberFinalized (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
api.rpc.chain.subscribeFinalizedHeads().pipe(
|
||||
map((header): BlockNumber => header.number.unwrap())
|
||||
map((header) => header.number.unwrap())
|
||||
));
|
||||
}
|
||||
|
||||
@@ -2,14 +2,11 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AccountId } from '@polkadot/types/interfaces';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
import { HeaderExtended } from '../type';
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -32,7 +29,7 @@ export function getHeader (api: ApiInterfaceRx): (hash: Uint8Array | string) =>
|
||||
combineLatest([
|
||||
api.rpc.chain.getHeader(hash),
|
||||
api.query.session
|
||||
? api.query.session.validators.at(hash) as Observable<Vec<AccountId>>
|
||||
? api.query.session.validators.at(hash)
|
||||
: of([])
|
||||
]).pipe(
|
||||
map(([header, validators]): HeaderExtended =>
|
||||
|
||||
@@ -12,9 +12,23 @@ import { Option } from '@polkadot/types';
|
||||
|
||||
type Result = [Hash[], Option<Proposal>[], Option<Votes>[]];
|
||||
|
||||
function parse ([hashes, proposals, votes]: Result): DerivedCollectiveProposal[] {
|
||||
return proposals
|
||||
.map((proposalOpt, index): DerivedCollectiveProposal | null =>
|
||||
proposalOpt.isSome
|
||||
? {
|
||||
hash: hashes[index],
|
||||
proposal: proposalOpt.unwrap(),
|
||||
votes: votes[index].unwrapOr(null)
|
||||
}
|
||||
: null
|
||||
)
|
||||
.filter((proposal): proposal is DerivedCollectiveProposal => !!proposal);
|
||||
}
|
||||
|
||||
export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalCommittee'): () => Observable<DerivedCollectiveProposal[]> {
|
||||
return (): Observable<DerivedCollectiveProposal[]> =>
|
||||
api.query[section]
|
||||
api.query[section]?.proposals
|
||||
? api.query[section].proposals().pipe(
|
||||
switchMap((hashes: Hash[]): Observable<Result> =>
|
||||
hashes.length
|
||||
@@ -25,19 +39,7 @@ export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalC
|
||||
])
|
||||
: of([[], [], []])
|
||||
),
|
||||
map(([hashes, proposals, votes]: Result): DerivedCollectiveProposal[] =>
|
||||
proposals
|
||||
.map((proposalOpt, index): DerivedCollectiveProposal | null =>
|
||||
proposalOpt.isSome
|
||||
? {
|
||||
hash: hashes[index],
|
||||
proposal: proposalOpt.unwrap(),
|
||||
votes: votes[index].unwrapOr(null)
|
||||
}
|
||||
: null
|
||||
)
|
||||
.filter((proposal): boolean => !!proposal) as DerivedCollectiveProposal[]
|
||||
)
|
||||
map(parse)
|
||||
)
|
||||
: of([] as DerivedCollectiveProposal[]);
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ function parse (api: ApiInterfaceRx, { depositors, proposals, preimages }: Resul
|
||||
|
||||
export function proposals (api: ApiInterfaceRx): () => Observable<DeriveProposal[]> {
|
||||
return memo((): Observable<DeriveProposal[]> =>
|
||||
api.query.democracy?.publicProps
|
||||
api.query.democracy?.publicProps && api.query.democracy?.preimages
|
||||
? api.query.democracy.publicProps<Proposals>().pipe(
|
||||
switchMap((proposals) =>
|
||||
combineLatest([
|
||||
|
||||
@@ -44,7 +44,7 @@ function constructInfo (api: ApiInterfaceRx, index: BN | number, _info: Option<R
|
||||
export function retrieveInfo (api: ApiInterfaceRx, index: BN | number, info: Option<ReferendumInfo>): Observable<DerivedReferendum | null> {
|
||||
return ((
|
||||
info?.isSome
|
||||
? api.query.democracy.preimages<PreImage>(info.unwrap().proposalHash)
|
||||
? api.query.democracy.preimages(info.unwrap().proposalHash)
|
||||
: of(undefined)
|
||||
) as Observable<PreImage | undefined>).pipe(
|
||||
map((preimage?: PreImage): DerivedReferendum | null =>
|
||||
|
||||
@@ -29,7 +29,7 @@ export function referendumInfos (api: ApiInterfaceRx): (ids?: (BN | number)[]) =
|
||||
)
|
||||
),
|
||||
map((infos): DerivedReferendum[] =>
|
||||
infos.filter((referendum): boolean => !!referendum) as DerivedReferendum[]
|
||||
infos.filter((referendum): referendum is DerivedReferendum => !!referendum)
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -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 { AccountId, SessionIndex } from '@polkadot/types/interfaces';
|
||||
import { AccountId } from '@polkadot/types/interfaces';
|
||||
import { DerivedHeartbeats } from '../types';
|
||||
|
||||
import { of, Observable, combineLatest } from 'rxjs';
|
||||
@@ -23,9 +23,9 @@ export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable<Deriv
|
||||
combineLatest([
|
||||
of(validators),
|
||||
api.query.imOnline.receivedHeartbeats.multi<Option<Bytes>>(
|
||||
validators.map((_address, index): [SessionIndex, number] => [currentIndex, index])),
|
||||
validators.map((_address, index) => [currentIndex, index])),
|
||||
api.query.imOnline.authoredBlocks.multi<u32>(
|
||||
validators.map((address): [SessionIndex, AccountId] => [currentIndex, address]))
|
||||
validators.map((address) => [currentIndex, address]))
|
||||
])
|
||||
),
|
||||
map(([validators, heartbeats, numBlocks]): DerivedHeartbeats =>
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { CollatorId, ParaId } from '@polkadot/types/interfaces';
|
||||
import { DeriveParachainInfo, DeriveParachainFull, DeriveParachainActive } from '../types';
|
||||
import { Active, DidUpdate, Heads, ParaInfoResult, PendingSwap, RelayDispatchQueue, RetryQueue, SelectedThreads, Watermarks } from './types';
|
||||
import { Active, DidUpdate, Heads, ParaInfoResult, PendingSwap, RelayDispatchQueue, RetryQueue, SelectedThreads } from './types';
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
@@ -21,8 +21,7 @@ type Result = [
|
||||
ParaInfoResult,
|
||||
PendingSwap,
|
||||
Heads,
|
||||
RelayDispatchQueue,
|
||||
Watermarks
|
||||
RelayDispatchQueue
|
||||
];
|
||||
|
||||
function parseActive (id: ParaId, active: Active): DeriveParachainActive | null {
|
||||
@@ -58,7 +57,11 @@ function parseCollators (id: ParaId, collatorQueue: SelectedThreads | RetryQueue
|
||||
});
|
||||
}
|
||||
|
||||
function parse (id: ParaId, [active, retryQueue, selectedThreads, didUpdate, info, pendingSwap, heads, relayDispatchQueue, watermarks]: Result): DeriveParachainFull {
|
||||
function parse (id: ParaId, [active, retryQueue, selectedThreads, didUpdate, info, pendingSwap, heads, relayDispatchQueue]: Result): DeriveParachainFull | null {
|
||||
if (info.isNone) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return {
|
||||
active: parseActive(id, active),
|
||||
didUpdate: didUpdate.isSome
|
||||
@@ -66,12 +69,11 @@ function parse (id: ParaId, [active, retryQueue, selectedThreads, didUpdate, inf
|
||||
: false,
|
||||
heads,
|
||||
id,
|
||||
info: { id, ...info.unwrapOr(null) } as DeriveParachainInfo,
|
||||
info: { id, ...info.unwrap() } as DeriveParachainInfo,
|
||||
pendingSwapId: pendingSwap.unwrapOr(null),
|
||||
relayDispatchQueue,
|
||||
retryCollators: parseCollators(id, retryQueue),
|
||||
selectedCollators: parseCollators(id, selectedThreads),
|
||||
watermark: watermarks.unwrapOr(null)
|
||||
selectedCollators: parseCollators(id, selectedThreads)
|
||||
};
|
||||
}
|
||||
|
||||
@@ -86,11 +88,10 @@ export function info (api: ApiInterfaceRx): (id: ParaId | number) => Observable<
|
||||
[api.query.registrar.paras, id],
|
||||
[api.query.registrar.pendingSwap, id],
|
||||
[api.query.parachains.heads, id],
|
||||
[api.query.parachains.relayDispatchQueue, id],
|
||||
[api.query.parachains.watermarks, id]
|
||||
[api.query.parachains.relayDispatchQueue, id]
|
||||
])
|
||||
.pipe(
|
||||
map((result: Result): DeriveParachainFull =>
|
||||
map((result: Result): DeriveParachainFull | null =>
|
||||
parse(createType(api.registry, 'ParaId', id), result)
|
||||
)
|
||||
)
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
|
||||
import { ParaId } from '@polkadot/types/interfaces';
|
||||
import { DeriveParachain, DeriveParachainInfo } from '../types';
|
||||
import { DidUpdate, ParaInfoResult, PendingSwap, RelayDispatchQueueSize, Watermarks } from './types';
|
||||
import { DidUpdate, ParaInfoResult, PendingSwap, RelayDispatchQueueSize } from './types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
@@ -17,11 +17,10 @@ type Result = [
|
||||
DidUpdate,
|
||||
ParaInfoResult[],
|
||||
PendingSwap[],
|
||||
RelayDispatchQueueSize[],
|
||||
Watermarks[],
|
||||
RelayDispatchQueueSize[]
|
||||
];
|
||||
|
||||
function parse ([ids, didUpdate, infos, pendingSwaps, relayDispatchQueueSizes, watermarks]: Result): DeriveParachain[] {
|
||||
function parse ([ids, didUpdate, infos, pendingSwaps, relayDispatchQueueSizes]: Result): DeriveParachain[] {
|
||||
return ids.map((id, index): DeriveParachain => {
|
||||
return {
|
||||
didUpdate: didUpdate.isSome
|
||||
@@ -30,8 +29,7 @@ function parse ([ids, didUpdate, infos, pendingSwaps, relayDispatchQueueSizes, w
|
||||
id,
|
||||
info: { id, ...infos[index].unwrapOr(null) } as DeriveParachainInfo,
|
||||
pendingSwapId: pendingSwaps[index].unwrapOr(null),
|
||||
relayDispatchQueueSize: relayDispatchQueueSizes[index][0].toNumber(),
|
||||
watermark: watermarks[index].unwrapOr(null)
|
||||
relayDispatchQueueSize: relayDispatchQueueSizes[index][0].toNumber()
|
||||
};
|
||||
});
|
||||
}
|
||||
@@ -46,8 +44,7 @@ export function overview (api: ApiInterfaceRx): () => Observable<DeriveParachain
|
||||
api.query.parachains.didUpdate<DidUpdate>(),
|
||||
api.query.registrar.paras.multi<ParaInfoResult>(paraIds),
|
||||
api.query.registrar.pendingSwap.multi<PendingSwap>(paraIds),
|
||||
api.query.parachains.relayDispatchQueueSize.multi<RelayDispatchQueueSize>(paraIds),
|
||||
api.query.parachains.watermarks.multi<Watermarks>(paraIds)
|
||||
api.query.parachains.relayDispatchQueueSize.multi<RelayDispatchQueueSize>(paraIds)
|
||||
])
|
||||
),
|
||||
map((result: Result): DeriveParachain[] =>
|
||||
|
||||
@@ -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 { BlockNumber, CollatorId, ParaId, ParaInfo, Retriable, UpwardMessage } from '@polkadot/types/interfaces';
|
||||
import { CollatorId, ParaId, ParaInfo, Retriable, UpwardMessage } from '@polkadot/types/interfaces';
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
|
||||
import { Bytes, Option, u32, Vec } from '@polkadot/types';
|
||||
@@ -16,5 +16,33 @@ export type Code = Bytes;
|
||||
export type Heads = Bytes;
|
||||
export type RelayDispatchQueue = Vec<UpwardMessage>
|
||||
export type RelayDispatchQueueSize = ITuple<[u32, u32]>;
|
||||
export type Watermarks = Option<BlockNumber>;
|
||||
export type DidUpdate = Option<Vec<ParaId>>;
|
||||
|
||||
export interface DeriveParachainActive {
|
||||
collatorId: CollatorId;
|
||||
isRetriable: boolean;
|
||||
retries: number;
|
||||
}
|
||||
|
||||
export interface DeriveParachainInfo extends ParaInfo {
|
||||
id: ParaId;
|
||||
icon?: string;
|
||||
name?: string;
|
||||
owner?: string;
|
||||
}
|
||||
|
||||
export interface DeriveParachain {
|
||||
didUpdate: boolean;
|
||||
pendingSwapId: ParaId | null;
|
||||
id: ParaId;
|
||||
info: DeriveParachainInfo | null;
|
||||
relayDispatchQueueSize?: number;
|
||||
}
|
||||
|
||||
export interface DeriveParachainFull extends DeriveParachain {
|
||||
active: DeriveParachainActive | null;
|
||||
heads: Bytes | null;
|
||||
relayDispatchQueue: UpwardMessage[];
|
||||
retryCollators: (CollatorId | null)[];
|
||||
selectedCollators: (CollatorId | null)[];
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { BlockNumber } from '@polkadot/types/interfaces';
|
||||
import { DerivedSessionInfo } from '../types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
@@ -14,6 +13,6 @@ import { memo } from '../util';
|
||||
export function eraLength (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
api.derive.session.info().pipe(
|
||||
map(({ eraLength }: DerivedSessionInfo): BlockNumber => eraLength)
|
||||
map((info) => info.eraLength)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { BlockNumber } from '@polkadot/types/interfaces';
|
||||
import { DerivedSessionInfo } from '../types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
@@ -14,6 +13,6 @@ import { memo } from '../util';
|
||||
export function eraProgress (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
api.derive.session.info().pipe(
|
||||
map(({ eraProgress }: DerivedSessionInfo): BlockNumber => eraProgress)
|
||||
map((info) => info.eraProgress)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { EraIndex, MomentOf, SessionIndex } from '@polkadot/types/interfaces';
|
||||
import { ActiveEraInfo, EraIndex, Moment, SessionIndex } from '@polkadot/types/interfaces';
|
||||
import { DeriveSessionIndexes } from '../types';
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
@@ -12,7 +12,7 @@ import { createType, Option, u32 } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
type Result = [EraIndex, Option<MomentOf>, EraIndex, SessionIndex, u32];
|
||||
type Result = [EraIndex, Option<Moment>, EraIndex, SessionIndex, u32];
|
||||
|
||||
// parse into Indexes
|
||||
function parse ([activeEra, activeEraStart, currentEra, currentIndex, validatorCount]: Result): DeriveSessionIndexes {
|
||||
@@ -34,7 +34,7 @@ function queryNoActive (api: ApiInterfaceRx): Observable<Result> {
|
||||
]).pipe(
|
||||
map(([currentEra, currentIndex, validatorCount]): Result => [
|
||||
currentEra,
|
||||
createType(api.registry, 'Option<MomentOf>'),
|
||||
createType(api.registry, 'Option<Moment>'),
|
||||
currentEra,
|
||||
currentIndex,
|
||||
validatorCount
|
||||
@@ -44,29 +44,32 @@ function queryNoActive (api: ApiInterfaceRx): Observable<Result> {
|
||||
|
||||
// query based on latest
|
||||
function query (api: ApiInterfaceRx): Observable<Result> {
|
||||
return api.queryMulti<[Option<EraIndex>, Option<MomentOf>, Option<EraIndex>, SessionIndex, u32]>([
|
||||
return api.queryMulti<[Option<ActiveEraInfo>, Option<EraIndex>, SessionIndex, u32]>([
|
||||
api.query.staking.activeEra,
|
||||
api.query.staking.activeEraStart,
|
||||
api.query.staking.currentEra,
|
||||
api.query.session.currentIndex,
|
||||
api.query.staking.validatorCount
|
||||
]).pipe(
|
||||
map(([activeEra, activeEraStart, currentEra, currentIndex, validatorCount]): Result => [
|
||||
activeEra.unwrapOr(createType(api.registry, 'EraIndex', 1)),
|
||||
activeEraStart,
|
||||
currentEra.unwrapOr(createType(api.registry, 'EraIndex', 1)),
|
||||
currentIndex,
|
||||
validatorCount
|
||||
])
|
||||
map(([activeOpt, currentEra, currentIndex, validatorCount]): Result => {
|
||||
const { index: activeEra, start: activeEraStart } = activeOpt.unwrapOrDefault();
|
||||
|
||||
return [
|
||||
activeEra,
|
||||
activeEraStart,
|
||||
currentEra.unwrapOr(createType(api.registry, 'EraIndex')),
|
||||
currentIndex,
|
||||
validatorCount
|
||||
];
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
// empty set when none is available
|
||||
function empty (api: ApiInterfaceRx): Observable<Result> {
|
||||
return of([
|
||||
createType(api.registry, 'EraIndex', 1),
|
||||
createType(api.registry, 'Option<MomentOf>'),
|
||||
createType(api.registry, 'EraIndex', 1),
|
||||
createType(api.registry, 'EraIndex'),
|
||||
createType(api.registry, 'Option<Moment>'),
|
||||
createType(api.registry, 'EraIndex'),
|
||||
createType(api.registry, 'SessionIndex', 1),
|
||||
createType(api.registry, 'u32')
|
||||
]);
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { BlockNumber } from '@polkadot/types/interfaces';
|
||||
import { DerivedSessionInfo } from '../types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
@@ -14,6 +13,6 @@ import { memo } from '../util';
|
||||
export function sessionProgress (api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
return memo((): Observable<BlockNumber> =>
|
||||
api.derive.session.info().pipe(
|
||||
map(({ sessionProgress }: DerivedSessionInfo): BlockNumber => sessionProgress)
|
||||
map((info) => info.sessionProgress)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
// 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 { BlockNumber, EraIndex, Moment, SessionIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
import { Option, u32 } from '@polkadot/types';
|
||||
|
||||
export interface DeriveSessionIndexes {
|
||||
activeEra: EraIndex;
|
||||
activeEraStart: Option<Moment>;
|
||||
currentEra: EraIndex;
|
||||
currentIndex: SessionIndex;
|
||||
validatorCount: u32;
|
||||
}
|
||||
|
||||
export interface DerivedSessionInfo extends DeriveSessionIndexes {
|
||||
eraLength: BlockNumber;
|
||||
eraProgress: BlockNumber;
|
||||
isEpoch: boolean;
|
||||
sessionLength: BlockNumber;
|
||||
sessionsPerEra: SessionIndex;
|
||||
sessionProgress: BlockNumber;
|
||||
}
|
||||
@@ -27,12 +27,12 @@ export function member (api: ApiInterfaceRx): (accountId: AccountId) => Observab
|
||||
[api.query.society.suspendedMembers, accountId],
|
||||
[api.query.society.vouching, accountId]
|
||||
]).pipe(
|
||||
map(([payouts, strikes, defenderVote, suspended, vouching]: Result): DeriveSocietyMember => ({
|
||||
map(([payouts, strikes, defenderVotes, suspended, vouching]: Result): DeriveSocietyMember => ({
|
||||
accountId,
|
||||
payouts,
|
||||
isSuspended: suspended.isTrue,
|
||||
strikes,
|
||||
vote: defenderVote.unwrapOr(undefined),
|
||||
vote: defenderVotes.unwrapOr(undefined),
|
||||
vouching: vouching.unwrapOr(undefined)
|
||||
}))
|
||||
)
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// 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 { EraIndex, Exposure } from '@polkadot/types/interfaces';
|
||||
import { DeriveEraExposure, DeriveEraNominatorExposure, DeriveEraValidatorExposure } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap, take } from 'rxjs/operators';
|
||||
import { StorageKey } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function mapStakers (era: EraIndex, stakers: [StorageKey, Exposure][]): DeriveEraExposure {
|
||||
const nominators: DeriveEraNominatorExposure = {};
|
||||
const validators: DeriveEraValidatorExposure = {};
|
||||
|
||||
stakers.forEach(([key, exposure]): void => {
|
||||
const validatorId = key.args[1].toString();
|
||||
|
||||
validators[validatorId] = exposure;
|
||||
|
||||
exposure.others.forEach(({ who }, index): void => {
|
||||
const nominatorId = who.toString();
|
||||
|
||||
nominators[nominatorId] = nominators[nominatorId] || [];
|
||||
nominators[nominatorId].push([validatorId, index]);
|
||||
});
|
||||
});
|
||||
|
||||
return { era, nominators, validators };
|
||||
}
|
||||
|
||||
export function erasExposure (api: ApiInterfaceRx): (withActive?: boolean | BN | number) => Observable<DeriveEraExposure[]> {
|
||||
return memo((withActive?: boolean | BN | number): Observable<DeriveEraExposure[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras): Observable<[EraIndex[], [StorageKey, Exposure][][]]> =>
|
||||
combineLatest([
|
||||
of(eras),
|
||||
eras.length
|
||||
? combineLatest(
|
||||
// we could just do entries over the full set, however the set can be quite large - split it into
|
||||
// batches - may need to re-visit this, or alternatively use pages keys for exceptionally large sets
|
||||
eras.map((era): Observable<[StorageKey, Exposure][]> =>
|
||||
api.query.staking.erasStakersClipped.entries(era).pipe(take(1))
|
||||
)
|
||||
)
|
||||
: of([])
|
||||
])
|
||||
),
|
||||
map(([eras, erasStakers]): DeriveEraExposure[] =>
|
||||
eras.map((era, index): DeriveEraExposure =>
|
||||
mapStakers(era, erasStakers[index])
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
// 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 { ActiveEraInfo, EraIndex } from '@polkadot/types/interfaces';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Option, u32 } from '@polkadot/types';
|
||||
import { isBoolean, isUndefined, bnToBn } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function erasHistoric (api: ApiInterfaceRx): (withActive?: boolean | BN | number) => Observable<EraIndex[]> {
|
||||
return memo((withActive?: boolean | BN | number): Observable<EraIndex[]> =>
|
||||
api.query.staking?.activeEra
|
||||
? api.queryMulti<[Option<ActiveEraInfo>, u32]>([
|
||||
api.query.staking.activeEra,
|
||||
api.query.staking.historyDepth
|
||||
]).pipe(
|
||||
map(([activeEraOpt, historyDepth]): EraIndex[] => {
|
||||
const result: (EraIndex | null)[] = [];
|
||||
const max = historyDepth.toNumber();
|
||||
const activeEra = activeEraOpt.unwrapOrDefault().index.toBn();
|
||||
let lastEra = activeEra;
|
||||
|
||||
while (lastEra.gten(0) && (result.length < max)) {
|
||||
result.push(
|
||||
((lastEra !== activeEra) || (withActive === true))
|
||||
? api.registry.createType('EraIndex', lastEra)
|
||||
: null
|
||||
);
|
||||
|
||||
lastEra = lastEra.subn(1);
|
||||
}
|
||||
|
||||
const startEra = isUndefined(withActive) || isBoolean(withActive)
|
||||
? new BN(0)
|
||||
: bnToBn(withActive);
|
||||
|
||||
// go from oldest to newest
|
||||
return result
|
||||
.filter((era): era is EraIndex =>
|
||||
era
|
||||
? era.gte(startEra)
|
||||
: false
|
||||
)
|
||||
.reverse();
|
||||
})
|
||||
)
|
||||
: of([])
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
// 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 { EraIndex, EraRewardPoints } from '@polkadot/types/interfaces';
|
||||
import { DeriveEraPoints, DeriveEraValPoints } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function mapValidators ({ individual }: EraRewardPoints): DeriveEraValPoints {
|
||||
return [...individual.entries()]
|
||||
.filter(([, points]): boolean => points.gtn(0))
|
||||
.reduce((result: DeriveEraValPoints, [validatorId, points]): DeriveEraValPoints => {
|
||||
result[validatorId.toString()] = points;
|
||||
|
||||
return result;
|
||||
}, {});
|
||||
}
|
||||
|
||||
export function erasPoints (api: ApiInterfaceRx): (withActive?: boolean | BN | number) => Observable<DeriveEraPoints[]> {
|
||||
return memo((withActive?: boolean | number): Observable<DeriveEraPoints[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras): Observable<[EraIndex[], EraRewardPoints[]]> =>
|
||||
combineLatest([
|
||||
of(eras),
|
||||
eras.length
|
||||
? api.query.staking.erasRewardPoints.multi<EraRewardPoints>(eras)
|
||||
: of([])
|
||||
])
|
||||
),
|
||||
map(([eras, points]): DeriveEraPoints[] =>
|
||||
eras.map((era, index): DeriveEraPoints => ({
|
||||
era,
|
||||
eraPoints: points[index].total,
|
||||
validators: mapValidators(points[index])
|
||||
}))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
// 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 { Balance, EraIndex } from '@polkadot/types/interfaces';
|
||||
import { DeriveEraRewards } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Option } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function erasRewards (api: ApiInterfaceRx): (withActive?: boolean | BN | number) => Observable<DeriveEraRewards[]> {
|
||||
return memo((withActive?: boolean | BN | number): Observable<DeriveEraRewards[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
switchMap((eras): Observable<[EraIndex[], Option<Balance>[]]> =>
|
||||
combineLatest([
|
||||
of(eras),
|
||||
eras.length
|
||||
? api.query.staking.erasValidatorReward.multi<Option<Balance>>(eras)
|
||||
: of([])
|
||||
])
|
||||
),
|
||||
map(([eras, rewards]): DeriveEraRewards[] =>
|
||||
eras.map((era, index): DeriveEraRewards => ({
|
||||
era,
|
||||
eraReward: rewards[index].unwrapOrDefault()
|
||||
}))
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -3,8 +3,15 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export * from './account';
|
||||
export * from './erasExposure';
|
||||
export * from './erasHistoric';
|
||||
export * from './erasPoints';
|
||||
export * from './erasRewards';
|
||||
export * from './controllers';
|
||||
export * from './electedInfo';
|
||||
export * from './overview';
|
||||
export * from './query';
|
||||
export * from './stakerExposure';
|
||||
export * from './stakerPoints';
|
||||
export * from './stakerRewards';
|
||||
export * from './validators';
|
||||
|
||||
@@ -41,7 +41,9 @@ export function overview (api: ApiInterfaceRx): () => Observable<DerivedStakingO
|
||||
of({ ...indexes, nextElected, validators }),
|
||||
api.query.staking.erasRewardPoints
|
||||
? api.query.staking.erasRewardPoints<EraRewardPoints>(indexes.activeEra)
|
||||
: retrievePointsPrev(api, indexes.activeEra, nextElected)
|
||||
: api.query.staking.currentEraPointsEarned
|
||||
? retrievePointsPrev(api, indexes.activeEra, nextElected)
|
||||
: of(createType(api.registry, 'EraRewardPoints'))
|
||||
])
|
||||
),
|
||||
map(([info, eraPoints]): DerivedStakingOverview => ({
|
||||
|
||||
@@ -46,7 +46,9 @@ function retrieveCurr (api: ApiInterfaceRx, stashId: AccountId): Observable<Mult
|
||||
[api.query.staking.nominators, stashId],
|
||||
[api.query.staking.payee, stashId],
|
||||
[api.query.staking.validators, stashId],
|
||||
[api.query.session.nextKeys, [api.consts.session.dedupKeyPrefix, 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]]
|
||||
])
|
||||
)
|
||||
@@ -92,3 +94,11 @@ export function query (api: ApiInterfaceRx): (accountId: Uint8Array | string) =>
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function queryMulti (api: ApiInterfaceRx): (...accountIds: (Uint8Array | string)[]) => Observable<DerivedStakingQuery[]> {
|
||||
return memo((...accountIds: (Uint8Array | string)[]): Observable<DerivedStakingQuery[]> =>
|
||||
combineLatest(
|
||||
accountIds.map((accountId) => api.derive.staking.query(accountId))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
// 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 { DeriveStakerExposure, DeriveEraValidatorExposure } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function stakerExposure (api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean | BN | number) => Observable<DeriveStakerExposure[]> {
|
||||
return memo((accountId: Uint8Array | string, withActive?: boolean | BN | number): Observable<DeriveStakerExposure[]> => {
|
||||
const stakerId = api.registry.createType('AccountId', accountId).toString();
|
||||
|
||||
return api.derive.staking.erasExposure(withActive).pipe(
|
||||
map((exposures): DeriveStakerExposure[] =>
|
||||
exposures.map(({ era, nominators: allNominators, validators: allValidators }): DeriveStakerExposure => {
|
||||
const isValidator = !!allValidators[stakerId];
|
||||
const validators: DeriveEraValidatorExposure = {};
|
||||
let nominating: [string, number][] = [];
|
||||
|
||||
if (isValidator) {
|
||||
validators[stakerId] = allValidators[stakerId];
|
||||
} else if (allNominators[stakerId]) {
|
||||
nominating = allNominators[stakerId];
|
||||
|
||||
nominating.forEach(([validatorId]): void => {
|
||||
validators[validatorId] = allValidators[validatorId];
|
||||
});
|
||||
}
|
||||
|
||||
return { era, isEmpty: !Object.keys(validators).length, isValidator, nominating, validators };
|
||||
})
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// 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 { DeriveStakerPoints } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function stakerPoints (api: ApiInterfaceRx): (accountId: Uint8Array | string, withActive?: boolean | BN | number) => Observable<DeriveStakerPoints[]> {
|
||||
return memo((accountId: Uint8Array | string, withActive?: boolean | BN | number): Observable<DeriveStakerPoints[]> => {
|
||||
const stakerId = api.registry.createType('AccountId', accountId).toString();
|
||||
|
||||
return api.derive.staking.erasPoints(withActive).pipe(
|
||||
map((points): DeriveStakerPoints[] =>
|
||||
points.map(({ era, eraPoints, validators }): DeriveStakerPoints => ({
|
||||
era,
|
||||
eraPoints,
|
||||
points: validators[stakerId]
|
||||
? validators[stakerId]
|
||||
: api.registry.createType('RewardPoint')
|
||||
}))
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
// 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 { Balance } from '@polkadot/types/interfaces';
|
||||
import { DeriveEraPoints, DeriveEraRewards, DeriveStakerExposure, DeriveStakerReward } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
type Result = [DeriveEraPoints[], DeriveEraRewards[], DeriveStakerExposure[]];
|
||||
const ZERO = new BN(0);
|
||||
|
||||
function parseRewards (api: ApiInterfaceRx, stakerId: string, [erasPoints, erasRewards, exposures]: Result): DeriveStakerReward[] {
|
||||
return exposures.map(({ era, isEmpty, isValidator, nominating, validators: eraValidators }): DeriveStakerReward => {
|
||||
const { eraPoints, validators: allValPoints } = erasPoints.find((p) => p.era.eq(era)) || { eraPoints: new BN(0), validators: {} };
|
||||
const { eraReward } = erasRewards.find((r) => r.era.eq(era)) || { eraReward: new BN(0) };
|
||||
const validators: Record<string, Balance> = {};
|
||||
let total = ZERO;
|
||||
|
||||
Object.entries(eraValidators).forEach(([validatorId, exposure]): void => {
|
||||
const valPoints = allValPoints[validatorId] || new BN(0);
|
||||
const expTotal = exposure.total.unwrap();
|
||||
let value: BN | undefined;
|
||||
|
||||
if (!expTotal.isZero() && !valPoints.isZero()) {
|
||||
let staked: BN;
|
||||
|
||||
if (validatorId === stakerId) {
|
||||
staked = exposure.own.unwrap();
|
||||
} else {
|
||||
const stakerExp = exposure.others.find(({ who }): boolean => who.eq(stakerId));
|
||||
|
||||
staked = stakerExp
|
||||
? stakerExp.value.unwrap()
|
||||
: ZERO;
|
||||
}
|
||||
|
||||
value = eraReward.mul(valPoints).mul(staked).div(eraPoints).div(expTotal);
|
||||
total = total.add(value);
|
||||
}
|
||||
|
||||
validators[validatorId] = api.registry.createType('Balance', value);
|
||||
});
|
||||
|
||||
return {
|
||||
era,
|
||||
isEmpty,
|
||||
isValidator,
|
||||
nominating,
|
||||
total: api.registry.createType('Balance', total),
|
||||
validators
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export function stakerRewards (api: ApiInterfaceRx): (accountId: Uint8Array | string, startEra: BN | number) => Observable<DeriveStakerReward[]> {
|
||||
return memo((accountId: Uint8Array | string, startEra: BN | number): Observable<DeriveStakerReward[]> => {
|
||||
const stakerId = api.registry.createType('AccountId', accountId).toString();
|
||||
|
||||
return combineLatest([
|
||||
api.derive.staking.erasPoints(startEra),
|
||||
api.derive.staking.erasRewards(startEra),
|
||||
api.derive.staking.stakerExposure(stakerId, startEra)
|
||||
]).pipe(
|
||||
map((result): DeriveStakerReward[] =>
|
||||
parseRewards(api, stakerId, result)
|
||||
)
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
export function stakerRewardsMulti (api: ApiInterfaceRx): (...params: [Uint8Array | string, BN | number][]) => Observable<DeriveStakerReward[][]> {
|
||||
return memo((...params: [Uint8Array | string, BN | number][]): Observable<DeriveStakerReward[][]> =>
|
||||
combineLatest(
|
||||
params.map(([accountId, startEra]) =>
|
||||
api.derive.staking.stakerRewards(accountId, startEra)
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
// 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 { AccountId, Balance, BlockNumber, EraIndex, EraRewardPoints, Exposure, Keys, RewardDestination, RewardPoint, StakingLedger, ValidatorPrefs } from '@polkadot/types/interfaces';
|
||||
import { DeriveSessionIndexes } from '../session/types';
|
||||
|
||||
export type DeriveEraValPoints = Record<string, RewardPoint>;
|
||||
|
||||
export interface DeriveEraPoints {
|
||||
era: EraIndex;
|
||||
eraPoints: RewardPoint;
|
||||
validators: DeriveEraValPoints;
|
||||
}
|
||||
|
||||
export interface DeriveEraRewards {
|
||||
era: EraIndex;
|
||||
eraReward: Balance;
|
||||
}
|
||||
|
||||
export interface DeriveStakerPoints {
|
||||
era: EraIndex;
|
||||
eraPoints: RewardPoint;
|
||||
points: RewardPoint;
|
||||
}
|
||||
|
||||
export type DeriveEraNominatorExposure = Record<string, [string, number][]>;
|
||||
|
||||
export type DeriveEraValidatorExposure = Record<string, Exposure>;
|
||||
|
||||
export interface DeriveEraExposure {
|
||||
era: EraIndex;
|
||||
nominators: DeriveEraNominatorExposure;
|
||||
validators: DeriveEraValidatorExposure;
|
||||
}
|
||||
|
||||
export interface DeriveStakerExposure {
|
||||
era: EraIndex;
|
||||
isEmpty: boolean;
|
||||
isValidator: boolean;
|
||||
nominating: [string, number][];
|
||||
validators: DeriveEraValidatorExposure;
|
||||
}
|
||||
|
||||
export interface DeriveStakerReward {
|
||||
era: EraIndex;
|
||||
isEmpty: boolean;
|
||||
isValidator: boolean;
|
||||
nominating: [string, number][];
|
||||
validators: Record<string, Balance>;
|
||||
total: Balance;
|
||||
}
|
||||
|
||||
export interface DerivedStakingElected {
|
||||
nextElected: AccountId[];
|
||||
info: DerivedStakingQuery[];
|
||||
}
|
||||
|
||||
export interface DeriveStakingValidators {
|
||||
nextElected: AccountId[];
|
||||
validators: AccountId[];
|
||||
}
|
||||
|
||||
export interface DerivedStakingStash {
|
||||
controllerId?: AccountId;
|
||||
exposure?: Exposure;
|
||||
nominators?: AccountId[];
|
||||
nominateAt?: EraIndex;
|
||||
rewardDestination?: RewardDestination;
|
||||
nextKeys?: Keys;
|
||||
stashId?: AccountId;
|
||||
validatorPrefs?: ValidatorPrefs;
|
||||
}
|
||||
|
||||
export interface DerivedStakingQuery extends DerivedStakingStash {
|
||||
accountId: AccountId;
|
||||
nextSessionIds: AccountId[];
|
||||
sessionIds: AccountId[];
|
||||
stakingLedger?: StakingLedger;
|
||||
}
|
||||
|
||||
export interface DerivedStakingAccount extends DerivedStakingQuery {
|
||||
redeemable?: Balance;
|
||||
unlocking?: DerivedUnlocking[];
|
||||
}
|
||||
|
||||
export interface DerivedStakingOverview extends DeriveSessionIndexes {
|
||||
eraPoints: EraRewardPoints;
|
||||
nextElected: AccountId[];
|
||||
validators: AccountId[];
|
||||
}
|
||||
|
||||
export type DerivedUnlocking = {
|
||||
remainingBlocks: BlockNumber;
|
||||
value: Balance;
|
||||
};
|
||||
@@ -3,13 +3,28 @@
|
||||
// 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 { DeriveStakingValidators } from '../types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { map, switchMap, take } from 'rxjs/operators';
|
||||
import { StorageKey } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function queryNextStakers (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
|
||||
return api.derive.session.indexes().pipe(
|
||||
switchMap(({ activeEra }): Observable<StorageKey[]> =>
|
||||
api.query.staking.erasStakers.keys(activeEra.addn(1)).pipe(take(1))
|
||||
),
|
||||
map((keys): AccountId[] =>
|
||||
keys.map((key): AccountId => key.args[1] as AccountId)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Retrieve latest list of validators
|
||||
*/
|
||||
@@ -22,15 +37,16 @@ export function validators (api: ApiInterfaceRx): () => Observable<DeriveStaking
|
||||
api.query.session
|
||||
? api.query.session.validators()
|
||||
: of([]),
|
||||
// FIXME need a replacement for currentElected in new
|
||||
api.query.staking?.currentElected
|
||||
api.query.staking
|
||||
? api.query.staking.erasStakers
|
||||
? of(null)
|
||||
: api.query.staking.currentElected()
|
||||
? queryNextStakers(api)
|
||||
: api.query.staking.currentElected<AccountId[]>()
|
||||
: of([])
|
||||
]).pipe(
|
||||
map(([validators, nextElected]): DeriveStakingValidators => ({
|
||||
nextElected: nextElected || validators,
|
||||
nextElected: nextElected.length
|
||||
? nextElected
|
||||
: validators,
|
||||
validators
|
||||
}))
|
||||
));
|
||||
|
||||
@@ -2,10 +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 { AccountId, AccountIndex, Balance, BalanceLock, BalanceLockTo212, BalanceOf, Bid, BidKind, BlockNumber, CollatorId, EraIndex, EraRewardPoints, Exposure, Hash, Index, Keys, MomentOf, ParaId, ParaInfo, Proposal, PropIndex, ProposalIndex, ReferendumInfo, RegistrationJudgement, RewardDestination, SessionIndex, SetIndex, SocietyVote, StakingLedger, StrikeCount, TreasuryProposal, UpwardMessage, ValidatorPrefs, Vote, Votes, VoteIndex, VouchingStatus } from '@polkadot/types/interfaces';
|
||||
import { AccountId, AccountIndex, Balance, BalanceLock, BalanceLockTo212, BalanceOf, Bid, BidKind, BlockNumber, Hash, Index, Proposal, PropIndex, ProposalIndex, ReferendumInfo, RegistrationJudgement, SetIndex, SocietyVote, StrikeCount, TreasuryProposal, Vote, Votes, VoteIndex, VouchingStatus } from '@polkadot/types/interfaces';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Bytes, Option, u32, Vec } from '@polkadot/types';
|
||||
import { u32, Vec } from '@polkadot/types';
|
||||
|
||||
export * from './parachains/types';
|
||||
export * from './session/types';
|
||||
export * from './staking/types';
|
||||
|
||||
export type AccountIndexes = Record<string, AccountIndex>;
|
||||
|
||||
@@ -108,36 +112,6 @@ export interface RecentlyOffline {
|
||||
count: BN;
|
||||
}
|
||||
|
||||
export interface DeriveParachainActive {
|
||||
collatorId: CollatorId;
|
||||
isRetriable: boolean;
|
||||
retries: number;
|
||||
}
|
||||
|
||||
export interface DeriveParachainInfo extends ParaInfo {
|
||||
id: ParaId;
|
||||
icon?: string;
|
||||
name?: string;
|
||||
owner?: string;
|
||||
}
|
||||
|
||||
export interface DeriveParachain {
|
||||
didUpdate: boolean;
|
||||
pendingSwapId: ParaId | null;
|
||||
id: ParaId;
|
||||
info: DeriveParachainInfo | null;
|
||||
relayDispatchQueueSize?: number;
|
||||
watermark: BlockNumber | null;
|
||||
}
|
||||
|
||||
export interface DeriveParachainFull extends DeriveParachain {
|
||||
active: DeriveParachainActive | null;
|
||||
heads: Bytes | null;
|
||||
relayDispatchQueue: UpwardMessage[];
|
||||
retryCollators: (CollatorId | null)[];
|
||||
selectedCollators: (CollatorId | null)[];
|
||||
}
|
||||
|
||||
export interface DeriveProposalPreImage {
|
||||
at: BlockNumber;
|
||||
balance: Balance;
|
||||
@@ -170,23 +144,6 @@ export interface DerivedReferendumVote {
|
||||
vote: Vote;
|
||||
}
|
||||
|
||||
export interface DeriveSessionIndexes {
|
||||
activeEra: EraIndex;
|
||||
activeEraStart: Option<MomentOf>;
|
||||
currentEra: EraIndex;
|
||||
currentIndex: SessionIndex;
|
||||
validatorCount: u32;
|
||||
}
|
||||
|
||||
export interface DerivedSessionInfo extends DeriveSessionIndexes {
|
||||
eraLength: BlockNumber;
|
||||
eraProgress: BlockNumber;
|
||||
isEpoch: boolean;
|
||||
sessionLength: BlockNumber;
|
||||
sessionsPerEra: SessionIndex;
|
||||
sessionProgress: BlockNumber;
|
||||
}
|
||||
|
||||
export interface DeriveSociety {
|
||||
bids: Bid[];
|
||||
defender?: AccountId;
|
||||
@@ -213,45 +170,6 @@ export interface DeriveSocietyMember {
|
||||
vouching?: VouchingStatus;
|
||||
}
|
||||
|
||||
export interface DerivedStakingElected {
|
||||
nextElected: AccountId[];
|
||||
info: DerivedStakingQuery[];
|
||||
}
|
||||
|
||||
export interface DeriveStakingValidators {
|
||||
nextElected: AccountId[];
|
||||
validators: AccountId[];
|
||||
}
|
||||
|
||||
export interface DerivedStakingStash {
|
||||
controllerId?: AccountId;
|
||||
exposure?: Exposure;
|
||||
nominators?: AccountId[];
|
||||
nominateAt?: EraIndex;
|
||||
rewardDestination?: RewardDestination;
|
||||
nextKeys?: Keys;
|
||||
stashId?: AccountId;
|
||||
validatorPrefs?: ValidatorPrefs;
|
||||
}
|
||||
|
||||
export interface DerivedStakingQuery extends DerivedStakingStash {
|
||||
accountId: AccountId;
|
||||
nextSessionIds: AccountId[];
|
||||
sessionIds: AccountId[];
|
||||
stakingLedger?: StakingLedger;
|
||||
}
|
||||
|
||||
export interface DerivedStakingAccount extends DerivedStakingQuery {
|
||||
redeemable?: Balance;
|
||||
unlocking?: DerivedUnlocking[];
|
||||
}
|
||||
|
||||
export interface DerivedStakingOverview extends DeriveSessionIndexes {
|
||||
eraPoints: EraRewardPoints;
|
||||
nextElected: AccountId[];
|
||||
validators: AccountId[];
|
||||
}
|
||||
|
||||
export interface DerivedTreasuryProposal {
|
||||
council: DerivedCollectiveProposal[];
|
||||
id: ProposalIndex;
|
||||
@@ -264,11 +182,6 @@ export interface DerivedTreasuryProposals {
|
||||
proposals: DerivedTreasuryProposal[];
|
||||
}
|
||||
|
||||
export type DerivedUnlocking = {
|
||||
remainingBlocks: BlockNumber;
|
||||
value: Balance;
|
||||
};
|
||||
|
||||
export interface VoterPosition {
|
||||
globalIndex: BN;
|
||||
index: BN;
|
||||
|
||||
@@ -2,5 +2,9 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { drr } from '@polkadot/rpc-core/rxjs';
|
||||
|
||||
export * from './approvalFlagsToBools';
|
||||
export * from './memo';
|
||||
|
||||
export { drr };
|
||||
|
||||
@@ -19,7 +19,7 @@ const normalizer = JSON.stringify;
|
||||
export function memo <T> (inner: ObsFn<T>): ObsFn<T> {
|
||||
const cached = createMemo(
|
||||
(...params: any[]): Observable<T> =>
|
||||
Observable.create((observer: Observer<T>): VoidCallback => {
|
||||
new Observable((observer: Observer<T>): VoidCallback => {
|
||||
const sub = inner(...params).subscribe(observer);
|
||||
|
||||
return (): void => {
|
||||
|
||||
@@ -95,6 +95,7 @@ Some of the users of the API (let us know if you are missing from the list), inc
|
||||
- [Polkabot](https://gitlab.com/Polkabot) Polkabot is a Matrix chatbot that keeps an eye on the Polkadot network. You can see Polkabot in action in https://matrix.to/#/#polkadot-network-status:matrix.org
|
||||
- [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.
|
||||
|
||||
## Classes
|
||||
|
||||
|
||||
+10
-10
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@polkadot/api",
|
||||
"version": "1.4.1",
|
||||
"version": "1.6.2",
|
||||
"description": "Promise and RxJS wrappers around the Polkadot JS RPC",
|
||||
"main": "index.js",
|
||||
"keywords": [
|
||||
@@ -27,19 +27,19 @@
|
||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api#readme",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.8.4",
|
||||
"@polkadot/api-derive": "1.4.1",
|
||||
"@polkadot/keyring": "^2.5.1",
|
||||
"@polkadot/metadata": "1.4.1",
|
||||
"@polkadot/rpc-core": "1.4.1",
|
||||
"@polkadot/rpc-provider": "1.4.1",
|
||||
"@polkadot/types": "1.4.1",
|
||||
"@polkadot/util": "^2.5.1",
|
||||
"@polkadot/util-crypto": "^2.5.1",
|
||||
"@polkadot/api-derive": "1.6.2",
|
||||
"@polkadot/keyring": "^2.6.2",
|
||||
"@polkadot/metadata": "1.6.2",
|
||||
"@polkadot/rpc-core": "1.6.2",
|
||||
"@polkadot/rpc-provider": "1.6.2",
|
||||
"@polkadot/types": "1.6.2",
|
||||
"@polkadot/util": "^2.6.2",
|
||||
"@polkadot/util-crypto": "^2.6.2",
|
||||
"bn.js": "^5.1.1",
|
||||
"eventemitter3": "^4.0.0",
|
||||
"rxjs": "^6.5.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/keyring": "^2.5.1"
|
||||
"@polkadot/keyring": "^2.6.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -176,7 +176,7 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
|
||||
**/
|
||||
tombstoneDeposit: AugmentedConst<BalanceOf>;
|
||||
/**
|
||||
* Size of a contract at the time of instantiaion. This is a simple way to ensure that
|
||||
* Size of a contract at the time of instantiation. This is a simple way to ensure that
|
||||
* empty contracts eventually gets deleted.
|
||||
**/
|
||||
storageSizeOffset: AugmentedConst<u32>;
|
||||
@@ -265,5 +265,12 @@ declare module '@polkadot/metadata/Decorated/consts/types' {
|
||||
**/
|
||||
challengePeriod: AugmentedConst<BlockNumber>;
|
||||
};
|
||||
vesting: {
|
||||
[index: string]: AugmentedConst<object & Codec>;
|
||||
/**
|
||||
* The minimum amount to be transferred to create a new vesting schedule.
|
||||
**/
|
||||
minVestedTransfer: AugmentedConst<BalanceOf>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,26 +2,26 @@
|
||||
/* eslint-disable @typescript-eslint/no-empty-interface */
|
||||
|
||||
import { AnyNumber, ITuple } from '@polkadot/types/types';
|
||||
import { Option, U8aFixed, Vec } from '@polkadot/types/codec';
|
||||
import { Linkage, 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, MaybeVrf } from '@polkadot/types/interfaces/babe';
|
||||
import { AccountData, BalanceLock } from '@polkadot/types/interfaces/balances';
|
||||
import { AccountData, BalanceLock, ReleasesBalances } from '@polkadot/types/interfaces/balances';
|
||||
import { ProposalIndex, Votes } from '@polkadot/types/interfaces/collective';
|
||||
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
|
||||
import { CodeHash, ContractInfo, Gas, PrefabWasmModule, Schedule } from '@polkadot/types/interfaces/contracts';
|
||||
import { Conviction, PropIndex, Proposal, ReferendumIndex, ReferendumInfo } from '@polkadot/types/interfaces/democracy';
|
||||
import { Conviction, PropIndex, Proposal, ProxyState, ReferendumIndex, ReferendumInfo } from '@polkadot/types/interfaces/democracy';
|
||||
import { Vote, VoteThreshold } from '@polkadot/types/interfaces/elections';
|
||||
import { AuthorityList, SetId, StoredPendingChange, StoredState } from '@polkadot/types/interfaces/grandpa';
|
||||
import { RegistrarInfo, Registration } from '@polkadot/types/interfaces/identity';
|
||||
import { AuthIndex } from '@polkadot/types/interfaces/imOnline';
|
||||
import { Kind, OffenceDetails, OpaqueTimeSlot, ReportIdOf } from '@polkadot/types/interfaces/offences';
|
||||
import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
|
||||
import { AccountId, AccountIndex, Balance, BalanceOf, BlockNumber, Hash, Index, KeyTypeId, Moment, Perbill, ValidatorId, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import { AccountId, AccountIndex, Balance, BalanceOf, BlockNumber, Hash, KeyTypeId, Moment, Perbill, ValidatorId, Weight } from '@polkadot/types/interfaces/runtime';
|
||||
import { Keys, SessionIndex } from '@polkadot/types/interfaces/session';
|
||||
import { Bid, BidKind, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
|
||||
import { EraIndex, EraPoints, Exposure, Forcing, MomentOf, Nominations, RewardDestination, SlashingSpans, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
|
||||
import { DigestOf, EventIndex, EventRecord } from '@polkadot/types/interfaces/system';
|
||||
import { ActiveEraInfo, EraIndex, EraRewardPoints, Exposure, Forcing, Nominations, ReleasesStaking, RewardDestination, SlashingSpans, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
|
||||
import { AccountInfo, DigestOf, EventIndex, EventRecord } from '@polkadot/types/interfaces/system';
|
||||
import { OpenTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
|
||||
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
|
||||
import { Multisig } from '@polkadot/types/interfaces/utility';
|
||||
@@ -36,7 +36,7 @@ declare module '@polkadot/api/types/storage' {
|
||||
/**
|
||||
* The full account information for a particular account ID.
|
||||
**/
|
||||
account: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ITuple<[Index, AccountData]>>> & QueryableStorageEntry<ApiType>;
|
||||
account: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<AccountInfo>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* Total extrinsics count for the current block.
|
||||
**/
|
||||
@@ -92,6 +92,10 @@ declare module '@polkadot/api/types/storage' {
|
||||
* no notification will be triggered thus the event might be lost.
|
||||
**/
|
||||
eventTopics: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Vec<ITuple<[BlockNumber, EventIndex]>>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* A bool to track if the runtime was upgraded last block.
|
||||
**/
|
||||
runtimeUpgraded: AugmentedQuery<ApiType, () => Observable<bool>> & QueryableStorageEntry<ApiType>;
|
||||
};
|
||||
utility: {
|
||||
[index: string]: QueryableStorageEntry<ApiType>;
|
||||
@@ -203,10 +207,10 @@ declare module '@polkadot/api/types/storage' {
|
||||
**/
|
||||
locks: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Vec<BalanceLock>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* True if network has been upgraded to this version.
|
||||
* True for new networks.
|
||||
* Storage version of the pallet.
|
||||
* This is set to v2.0.0 for new networks.
|
||||
**/
|
||||
isUpgraded: AugmentedQuery<ApiType, () => Observable<bool>> & QueryableStorageEntry<ApiType>;
|
||||
storageVersion: AugmentedQuery<ApiType, () => Observable<ReleasesBalances>> & QueryableStorageEntry<ApiType>;
|
||||
};
|
||||
transactionPayment: {
|
||||
[index: string]: QueryableStorageEntry<ApiType>;
|
||||
@@ -214,6 +218,14 @@ declare module '@polkadot/api/types/storage' {
|
||||
};
|
||||
staking: {
|
||||
[index: string]: QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* Number of era to keep in history.
|
||||
* Information is kept for eras in `[current_era - history_depth; current_era]
|
||||
* Must be more than the number of era delayed by session otherwise.
|
||||
* i.e. active era must always be in history.
|
||||
* i.e. `active_era > current_era - history_depth` must be guaranteed.
|
||||
**/
|
||||
historyDepth: AugmentedQuery<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The ideal number of staking participants.
|
||||
**/
|
||||
@@ -243,44 +255,65 @@ declare module '@polkadot/api/types/storage' {
|
||||
/**
|
||||
* The map from (wannabe) validator stash key to the preferences of that validator.
|
||||
**/
|
||||
validators: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ValidatorPrefs>> & QueryableStorageEntry<ApiType>;
|
||||
validators: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ITuple<[ValidatorPrefs, Linkage<AccountId>]>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The map from nominator stash key to the set of stash keys of all validators to nominate.
|
||||
* NOTE: is private so that we can ensure upgraded before all typical accesses.
|
||||
* Direct storage APIs can still bypass this protection.
|
||||
**/
|
||||
nominators: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<Nominations>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* Nominators for a particular account that is in action right now. You can't iterate
|
||||
* through validators here, but you can find them in the Session module.
|
||||
* This is keyed by the stash account.
|
||||
**/
|
||||
stakers: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Exposure>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The currently elected validator set keyed by stash account ID.
|
||||
**/
|
||||
currentElected: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
|
||||
nominators: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<ITuple<[Nominations, Linkage<AccountId>]>>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The current era index.
|
||||
* This is the latest planned era, depending on how session module queues the validator
|
||||
* set, it might be active or not.
|
||||
**/
|
||||
currentEra: AugmentedQuery<ApiType, () => Observable<EraIndex>> & QueryableStorageEntry<ApiType>;
|
||||
currentEra: AugmentedQuery<ApiType, () => Observable<Option<EraIndex>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The start of the current era.
|
||||
* The active era information, it holds index and start.
|
||||
* The active era is the era currently rewarded.
|
||||
* Validator set of this era must be equal to `SessionInterface::validators`.
|
||||
**/
|
||||
currentEraStart: AugmentedQuery<ApiType, () => Observable<MomentOf>> & QueryableStorageEntry<ApiType>;
|
||||
activeEra: AugmentedQuery<ApiType, () => Observable<Option<ActiveEraInfo>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The session index at which the current era started.
|
||||
* The session index at which the era start for the last `HISTORY_DEPTH` eras
|
||||
**/
|
||||
currentEraStartSessionIndex: AugmentedQuery<ApiType, () => Observable<SessionIndex>> & QueryableStorageEntry<ApiType>;
|
||||
erasStartSessionIndex: AugmentedQuery<ApiType, (arg: EraIndex | AnyNumber | Uint8Array) => Observable<Option<SessionIndex>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* Rewards for the current era. Using indices of current elected set.
|
||||
* Exposure of validator at era.
|
||||
* This is keyed first by the era index to allow bulk deletion and then the stash account.
|
||||
* Is it removed after `HISTORY_DEPTH` eras.
|
||||
* If stakers hasn't been set or has been removed then empty exposure is returned.
|
||||
**/
|
||||
currentEraPointsEarned: AugmentedQuery<ApiType, () => Observable<EraPoints>> & QueryableStorageEntry<ApiType>;
|
||||
erasStakers: AugmentedQueryDoubleMap<ApiType, (key1: EraIndex | AnyNumber | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Exposure>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The amount of balance actively at stake for each validator slot, currently.
|
||||
* This is used to derive rewards and punishments.
|
||||
* Clipped Exposure of validator at era.
|
||||
* This is similar to [`ErasStakers`] but number of nominators exposed is reduce to the
|
||||
* `T::MaxNominatorRewardedPerValidator` biggest stakers.
|
||||
* This is used to limit the i/o cost for the nominator payout.
|
||||
* This is keyed fist by the era index to allow bulk deletion and then the stash account.
|
||||
* Is it removed after `HISTORY_DEPTH` eras.
|
||||
* If stakers hasn't been set or has been removed then empty exposure is returned.
|
||||
**/
|
||||
slotStake: AugmentedQuery<ApiType, () => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
|
||||
erasStakersClipped: AugmentedQueryDoubleMap<ApiType, (key1: EraIndex | AnyNumber | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Exposure>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* Similarly to `ErasStakers` this holds the preferences of validators.
|
||||
* This is keyed fist by the era index to allow bulk deletion and then the stash account.
|
||||
* Is it removed after `HISTORY_DEPTH` eras.
|
||||
**/
|
||||
erasValidatorPrefs: AugmentedQueryDoubleMap<ApiType, (key1: EraIndex | AnyNumber | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<ValidatorPrefs>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The total validator era payout for the last `HISTORY_DEPTH` eras.
|
||||
* Eras that haven't finished yet or has been removed doesn't have reward.
|
||||
**/
|
||||
erasValidatorReward: AugmentedQuery<ApiType, (arg: EraIndex | AnyNumber | Uint8Array) => Observable<Option<BalanceOf>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* Rewards for the last `HISTORY_DEPTH` eras.
|
||||
* If reward hasn't been set or has been removed then 0 reward is returned.
|
||||
**/
|
||||
erasRewardPoints: AugmentedQuery<ApiType, (arg: EraIndex | AnyNumber | Uint8Array) => Observable<EraRewardPoints>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The total amount staked for the last `HISTORY_DEPTH` eras.
|
||||
* If total hasn't been set or has been removed then 0 stake is returned.
|
||||
**/
|
||||
erasTotalStake: AugmentedQuery<ApiType, (arg: EraIndex | AnyNumber | Uint8Array) => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* True if the next session change will be a new era regardless of index.
|
||||
**/
|
||||
@@ -301,6 +334,8 @@ declare module '@polkadot/api/types/storage' {
|
||||
unappliedSlashes: AugmentedQuery<ApiType, (arg: EraIndex | AnyNumber | Uint8Array) => Observable<Vec<UnappliedSlash>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* A mapping from still-bonded eras to the first session index of that era.
|
||||
* Must contains information for eras for the range:
|
||||
* `[active_era - bounding_duration; active_era]`
|
||||
**/
|
||||
bondedEras: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[EraIndex, SessionIndex]>>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
@@ -325,6 +360,11 @@ declare module '@polkadot/api/types/storage' {
|
||||
* The earliest era for which we have a pending, unapplied slash.
|
||||
**/
|
||||
earliestUnappliedSlash: AugmentedQuery<ApiType, () => Observable<Option<EraIndex>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* Storage version of the pallet.
|
||||
* This is set to v2.0.0 for new networks.
|
||||
**/
|
||||
storageVersion: AugmentedQuery<ApiType, () => Observable<ReleasesStaking>> & QueryableStorageEntry<ApiType>;
|
||||
};
|
||||
session: {
|
||||
[index: string]: QueryableStorageEntry<ApiType>;
|
||||
@@ -415,11 +455,11 @@ declare module '@polkadot/api/types/storage' {
|
||||
* Who is able to vote for whom. Value is the fund-holding account, key is the
|
||||
* vote-transaction-sending account.
|
||||
**/
|
||||
proxy: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
|
||||
proxy: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<ProxyState>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* Get the account (and lock periods) to which another account is delegating vote.
|
||||
**/
|
||||
delegations: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ITuple<[AccountId, Conviction]>>> & QueryableStorageEntry<ApiType>;
|
||||
delegations: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ITuple<[ITuple<[AccountId, Conviction]>, Linkage<AccountId>]>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* Accounts for which there are locks in action which may be removed at some point in the
|
||||
* future. The value is the block number at which the lock expires and may be removed.
|
||||
@@ -469,6 +509,11 @@ declare module '@polkadot/api/types/storage' {
|
||||
* The current members of the collective. This is stored sorted (just by value).
|
||||
**/
|
||||
members: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The member who provides the default vote for any other members that do not vote before
|
||||
* the timeout. If None, then no member has that privilege.
|
||||
**/
|
||||
prime: AugmentedQuery<ApiType, () => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
|
||||
};
|
||||
technicalCommittee: {
|
||||
[index: string]: QueryableStorageEntry<ApiType>;
|
||||
@@ -492,6 +537,11 @@ declare module '@polkadot/api/types/storage' {
|
||||
* The current members of the collective. This is stored sorted (just by value).
|
||||
**/
|
||||
members: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The member who provides the default vote for any other members that do not vote before
|
||||
* the timeout. If None, then no member has that privilege.
|
||||
**/
|
||||
prime: AugmentedQuery<ApiType, () => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
|
||||
};
|
||||
elections: {
|
||||
[index: string]: QueryableStorageEntry<ApiType>;
|
||||
@@ -510,7 +560,7 @@ declare module '@polkadot/api/types/storage' {
|
||||
/**
|
||||
* Votes of a particular voter, with the round index of the votes.
|
||||
**/
|
||||
votesOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
|
||||
votesOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ITuple<[Vec<AccountId>, Linkage<AccountId>]>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* Locked stake of a voter.
|
||||
**/
|
||||
@@ -527,13 +577,17 @@ declare module '@polkadot/api/types/storage' {
|
||||
* The current membership, stored as an ordered Vec.
|
||||
**/
|
||||
members: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The current prime member, if one exists.
|
||||
**/
|
||||
prime: AugmentedQuery<ApiType, () => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
|
||||
};
|
||||
grandpa: {
|
||||
[index: string]: QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* DEPRECATED
|
||||
* This used to store the current authority set, which has been migrated to the well-known
|
||||
* GRANDPA_AUTHORITES_KEY unhashed key.
|
||||
* GRANDPA_AUTHORITIES_KEY unhashed key.
|
||||
**/
|
||||
authorities: AugmentedQuery<ApiType, () => Observable<AuthorityList>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
@@ -782,10 +836,10 @@ declare module '@polkadot/api/types/storage' {
|
||||
**/
|
||||
activeRecoveries: AugmentedQueryDoubleMap<ApiType, (key1: AccountId | string | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Option<ActiveRecovery>>> & QueryableStorageEntry<ApiType>;
|
||||
/**
|
||||
* The final list of recovered accounts.
|
||||
* Map from the recovered account to the user who can access it.
|
||||
* The list of allowed proxy accounts.
|
||||
* Map from the user who can access it to the recovered account.
|
||||
**/
|
||||
recovered: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
|
||||
proxy: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
|
||||
};
|
||||
vesting: {
|
||||
[index: string]: QueryableStorageEntry<ApiType>;
|
||||
|
||||
@@ -7,7 +7,7 @@ import { Bytes, StorageKey, Text, bool, u32, u64 } from '@polkadot/types/primiti
|
||||
import { Metadata } from '@polkadot/types';
|
||||
import { ContractCallRequest, ContractExecResult } from '@polkadot/types/interfaces/contracts';
|
||||
import { Extrinsic } from '@polkadot/types/interfaces/extrinsics';
|
||||
import { BlockHash, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, StorageChangeSet } from '@polkadot/types/interfaces/rpc';
|
||||
import { BlockHash, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion } from '@polkadot/types/interfaces/rpc';
|
||||
import { AccountId, BlockNumber, H256, Hash, Header, Index, SignedBlock, StorageData } from '@polkadot/types/interfaces/runtime';
|
||||
import { Observable } from 'rxjs';
|
||||
|
||||
@@ -17,175 +17,181 @@ declare module '@polkadot/rpc-core/types.jsonrpc' {
|
||||
/**
|
||||
* Retrieves the next accountIndex as available on the node
|
||||
**/
|
||||
nextIndex(accountId: AccountId | string | Uint8Array): Observable<Index>;
|
||||
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.
|
||||
**/
|
||||
hasKey(publicKey: Bytes | string | Uint8Array, keyType: Text | string): Observable<bool>;
|
||||
hasKey: AugmentedRpc<(publicKey: Bytes | string | Uint8Array, keyType: Text | string) => Observable<bool>>;
|
||||
/**
|
||||
* Returns true if the keystore has private keys for the given session public keys.
|
||||
**/
|
||||
hasSessionKeys(sessionKeys: Bytes | string | Uint8Array): Observable<bool>;
|
||||
hasSessionKeys: AugmentedRpc<(sessionKeys: Bytes | string | Uint8Array) => Observable<bool>>;
|
||||
/**
|
||||
* Insert a key into the keystore.
|
||||
**/
|
||||
insertKey(keyType: Text | string, suri: Text | string, publicKey: Bytes | string | Uint8Array): Observable<Bytes>;
|
||||
insertKey: AugmentedRpc<(keyType: Text | string, suri: Text | string, publicKey: Bytes | string | Uint8Array) => Observable<Bytes>>;
|
||||
/**
|
||||
* Returns all pending extrinsics, potentially grouped by sender
|
||||
**/
|
||||
pendingExtrinsics(): Observable<Vec<Extrinsic>>;
|
||||
pendingExtrinsics: AugmentedRpc<() => Observable<Vec<Extrinsic>>>;
|
||||
/**
|
||||
* Remove given extrinsic from the pool and temporarily ban it to prevent reimporting
|
||||
**/
|
||||
removeExtrinsic(bytesOrHash: Vec<ExtrinsicOrHash> | (ExtrinsicOrHash | { hash: any } | { extrinsic: any } | string | Uint8Array)[]): Observable<Vec<Hash>>;
|
||||
removeExtrinsic: AugmentedRpc<(bytesOrHash: Vec<ExtrinsicOrHash> | (ExtrinsicOrHash | { hash: any } | { extrinsic: any } | string | Uint8Array)[]) => Observable<Vec<Hash>>>;
|
||||
/**
|
||||
* Generate new session keys and returns the corresponding public keys
|
||||
**/
|
||||
rotateKeys(): Observable<Bytes>;
|
||||
rotateKeys: AugmentedRpc<() => Observable<Bytes>>;
|
||||
/**
|
||||
* Submit and subscribe to watch an extrinsic until unsubscribed
|
||||
**/
|
||||
submitAndWatchExtrinsic(extrinsic: IExtrinsic): Observable<ExtrinsicStatus>;
|
||||
submitAndWatchExtrinsic: AugmentedRpc<(extrinsic: IExtrinsic) => Observable<ExtrinsicStatus>>;
|
||||
/**
|
||||
* Submit a fully formatted extrinsic for block inclusion
|
||||
**/
|
||||
submitExtrinsic(extrinsic: IExtrinsic): Observable<Hash>;
|
||||
submitExtrinsic: AugmentedRpc<(extrinsic: IExtrinsic) => Observable<Hash>>;
|
||||
};
|
||||
chain: {
|
||||
/**
|
||||
* Get header and body of a relay chain block
|
||||
**/
|
||||
getBlock(hash?: BlockHash | string | Uint8Array): Observable<SignedBlock>;
|
||||
getBlock: AugmentedRpc<(hash?: BlockHash | string | Uint8Array) => Observable<SignedBlock>>;
|
||||
/**
|
||||
* Get the block hash for a specific block
|
||||
**/
|
||||
getBlockHash(blockNumber?: BlockNumber | AnyNumber | Uint8Array): Observable<BlockHash>;
|
||||
getBlockHash: AugmentedRpc<(blockNumber?: BlockNumber | AnyNumber | Uint8Array) => Observable<BlockHash>>;
|
||||
/**
|
||||
* Get hash of the last finalized block in the canon chain
|
||||
**/
|
||||
getFinalizedHead(): Observable<BlockHash>;
|
||||
getFinalizedHead: AugmentedRpc<() => Observable<BlockHash>>;
|
||||
/**
|
||||
* Retrieves the header for a specific block
|
||||
**/
|
||||
getHeader(hash?: BlockHash | string | Uint8Array): Observable<Header>;
|
||||
getHeader: AugmentedRpc<(hash?: BlockHash | string | Uint8Array) => Observable<Header>>;
|
||||
/**
|
||||
* Retrieves the newest header via subscription
|
||||
**/
|
||||
subscribeAllHeads(): Observable<Header>;
|
||||
subscribeAllHeads: AugmentedRpc<() => Observable<Header>>;
|
||||
/**
|
||||
* Retrieves the best finalized header via subscription
|
||||
**/
|
||||
subscribeFinalizedHeads(): Observable<Header>;
|
||||
subscribeFinalizedHeads: AugmentedRpc<() => Observable<Header>>;
|
||||
/**
|
||||
* Retrieves the best header via subscription
|
||||
**/
|
||||
subscribeNewHeads(): Observable<Header>;
|
||||
subscribeNewHeads: AugmentedRpc<() => Observable<Header>>;
|
||||
};
|
||||
contracts: {
|
||||
/**
|
||||
* Executes a call to a contract
|
||||
**/
|
||||
call(callRequest: ContractCallRequest | { origin?: any; dest?: any; value?: any; gasLimit?: any; inputData?: any } | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<ContractExecResult>;
|
||||
call: AugmentedRpc<(callRequest: ContractCallRequest | { origin?: any; dest?: any; value?: any; gasLimit?: any; inputData?: any } | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable<ContractExecResult>>;
|
||||
/**
|
||||
* Returns the value under a specified storage key in a contract
|
||||
**/
|
||||
getStorage(address: AccountId | string | Uint8Array, key: H256 | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<Option<Bytes>>;
|
||||
getStorage: AugmentedRpc<(address: AccountId | string | Uint8Array, key: H256 | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable<Option<Bytes>>>;
|
||||
};
|
||||
payment: {
|
||||
/**
|
||||
* Retrieves the fee information for an encoded extrinsic
|
||||
**/
|
||||
queryInfo(extrinsic: Bytes | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<RuntimeDispatchInfo>;
|
||||
queryInfo: AugmentedRpc<(extrinsic: Bytes | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable<RuntimeDispatchInfo>>;
|
||||
};
|
||||
rpc: {
|
||||
/**
|
||||
* Retrieves the list of RPC methods that are exposed by the node
|
||||
**/
|
||||
methods(): Observable<RpcMethods>;
|
||||
methods: AugmentedRpc<() => Observable<RpcMethods>>;
|
||||
};
|
||||
state: {
|
||||
/**
|
||||
* Perform a call to a builtin on the chain
|
||||
**/
|
||||
call(method: Text | string, data: Bytes | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<Bytes>;
|
||||
call: AugmentedRpc<(method: Text | string, data: Bytes | string | Uint8Array, at?: BlockHash | string | Uint8Array) => Observable<Bytes>>;
|
||||
/**
|
||||
* Retrieves the keys with prefix of a specific child storage
|
||||
**/
|
||||
getChildKeys(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<Vec<StorageKey>>;
|
||||
getChildKeys: AugmentedRpc<(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array) => Observable<Vec<StorageKey>>>;
|
||||
/**
|
||||
* Retrieves the child storage for a key
|
||||
**/
|
||||
getChildStorage(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<StorageData>;
|
||||
getChildStorage: AugmentedRpc<(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array) => Observable<StorageData>>;
|
||||
/**
|
||||
* Retrieves the child storage hash
|
||||
**/
|
||||
getChildStorageHash(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<Hash>;
|
||||
getChildStorageHash: AugmentedRpc<(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array) => Observable<Hash>>;
|
||||
/**
|
||||
* Retrieves the child storage size
|
||||
**/
|
||||
getChildStorageSize(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<u64>;
|
||||
getChildStorageSize: AugmentedRpc<(childStorageKey: StorageKey | string | Uint8Array | any, childDefinition: StorageKey | string | Uint8Array | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array) => Observable<u64>>;
|
||||
/**
|
||||
* Retrieves the keys with a certain prefix
|
||||
**/
|
||||
getKeys(key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<Vec<StorageKey>>;
|
||||
getKeys: AugmentedRpc<(key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array) => Observable<Vec<StorageKey>>>;
|
||||
/**
|
||||
* Returns the runtime metadata
|
||||
**/
|
||||
getMetadata(at?: BlockHash | string | Uint8Array): Observable<Metadata>;
|
||||
getMetadata: AugmentedRpc<(at?: BlockHash | string | Uint8Array) => Observable<Metadata>>;
|
||||
/**
|
||||
* Get the runtime version
|
||||
**/
|
||||
getRuntimeVersion(at?: BlockHash | string | Uint8Array): Observable<RuntimeVersion>;
|
||||
getStorage<T = Codec>(key: any, block?: Hash | Uint8Array | string): Observable<T>;
|
||||
getRuntimeVersion: AugmentedRpc<(at?: BlockHash | string | Uint8Array) => Observable<RuntimeVersion>>;
|
||||
/**
|
||||
* Retrieves the storage for a key
|
||||
**/
|
||||
getStorage: AugmentedRpc<<T = Codec>(key: StorageKey | string | Uint8Array | any, block?: Hash | Uint8Array | string) => Observable<T>>;
|
||||
/**
|
||||
* Retrieves the storage hash
|
||||
**/
|
||||
getStorageHash(key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<Hash>;
|
||||
getStorageHash: AugmentedRpc<(key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array) => Observable<Hash>>;
|
||||
/**
|
||||
* Retrieves the storage size
|
||||
**/
|
||||
getStorageSize(key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array): Observable<u64>;
|
||||
getStorageSize: AugmentedRpc<(key: StorageKey | string | Uint8Array | any, at?: BlockHash | string | Uint8Array) => Observable<u64>>;
|
||||
/**
|
||||
* Query historical storage entries (by key) starting from a start block
|
||||
**/
|
||||
queryStorage(keys: Vec<StorageKey> | (StorageKey | string | Uint8Array | any)[], startBlock: Hash | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<Vec<StorageChangeSet>>;
|
||||
queryStorage: AugmentedRpc<<T = Codec[]>(keys: Vec<StorageKey> | (StorageKey | string | Uint8Array | any)[], fromBlock?: Hash | Uint8Array | string, toBlock?: Hash | Uint8Array | string) => Observable<[Hash, T][]>>;
|
||||
/**
|
||||
* Retrieves the runtime version via subscription
|
||||
**/
|
||||
subscribeRuntimeVersion(): Observable<RuntimeVersion>;
|
||||
subscribeStorage<T = Codec[]>(keys: any[]): Observable<T>;
|
||||
subscribeRuntimeVersion: AugmentedRpc<() => Observable<RuntimeVersion>>;
|
||||
/**
|
||||
* Subscribes to storage changes for the provided keys
|
||||
**/
|
||||
subscribeStorage: AugmentedRpc<<T = Codec[]>(keys: Vec<StorageKey> | (StorageKey | string | Uint8Array | any)[]) => Observable<T>>;
|
||||
};
|
||||
system: {
|
||||
/**
|
||||
* Retrieves the chain
|
||||
**/
|
||||
chain(): Observable<Text>;
|
||||
chain: AugmentedRpc<() => Observable<Text>>;
|
||||
/**
|
||||
* Return health status of the node
|
||||
**/
|
||||
health(): Observable<Health>;
|
||||
health: AugmentedRpc<() => Observable<Health>>;
|
||||
/**
|
||||
* Retrieves the node name
|
||||
**/
|
||||
name(): Observable<Text>;
|
||||
name: AugmentedRpc<() => Observable<Text>>;
|
||||
/**
|
||||
* Returns current state of the network
|
||||
**/
|
||||
networkState(): Observable<NetworkState>;
|
||||
networkState: AugmentedRpc<() => Observable<NetworkState>>;
|
||||
/**
|
||||
* Returns the currently connected peers
|
||||
**/
|
||||
peers(): Observable<Vec<PeerInfo>>;
|
||||
peers: AugmentedRpc<() => Observable<Vec<PeerInfo>>>;
|
||||
/**
|
||||
* Get a custom set of properties as a JSON object, defined in the chain spec
|
||||
**/
|
||||
properties(): Observable<ChainProperties>;
|
||||
properties: AugmentedRpc<() => Observable<ChainProperties>>;
|
||||
/**
|
||||
* Retrieves the version of the node
|
||||
**/
|
||||
version(): Observable<Text>;
|
||||
version: AugmentedRpc<() => Observable<Text>>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
+293
-33
@@ -8,15 +8,16 @@ import { MemberCount, ProposalIndex } from '@polkadot/types/interfaces/collectiv
|
||||
import { CodeHash, Gas, Schedule } from '@polkadot/types/interfaces/contracts';
|
||||
import { Conviction, PropIndex, Proposal, ReferendumIndex } from '@polkadot/types/interfaces/democracy';
|
||||
import { Vote } from '@polkadot/types/interfaces/elections';
|
||||
import { Signature } from '@polkadot/types/interfaces/extrinsics';
|
||||
import { Extrinsic, Signature } from '@polkadot/types/interfaces/extrinsics';
|
||||
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 } from '@polkadot/types/interfaces/runtime';
|
||||
import { AccountId, AccountIndex, Address, Balance, BalanceOf, BlockNumber, Call, ChangesTrieConfiguration, Hash, Header, KeyValue, LookupSource, Moment, Perbill } from '@polkadot/types/interfaces/runtime';
|
||||
import { Keys } from '@polkadot/types/interfaces/session';
|
||||
import { SocietyJudgement } from '@polkadot/types/interfaces/society';
|
||||
import { EraIndex, RewardDestination, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
|
||||
import { Key } from '@polkadot/types/interfaces/system';
|
||||
import { Timepoint } from '@polkadot/types/interfaces/utility';
|
||||
import { VestingInfo } from '@polkadot/types/interfaces/vesting';
|
||||
import { ApiTypes, SubmittableExtrinsic } from '@polkadot/api/types';
|
||||
|
||||
declare module '@polkadot/api/types/submittable' {
|
||||
@@ -24,9 +25,9 @@ declare module '@polkadot/api/types/submittable' {
|
||||
system: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
* A big dispatch that will disallow any other transaction to be included.
|
||||
* A dispatch that will fill the block weight up to the given ratio.
|
||||
**/
|
||||
fillBlock: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>>;
|
||||
fillBlock: AugmentedSubmittable<(ratio: Perbill | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Make some on-chain remark.
|
||||
**/
|
||||
@@ -59,6 +60,11 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* Kill all storage items with a key that starts with the given prefix.
|
||||
**/
|
||||
killPrefix: AugmentedSubmittable<(prefix: Key | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Kill the sending account, assuming there are no references outstanding and the composite
|
||||
* data is equal to its default value.
|
||||
**/
|
||||
suicide: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
utility: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
@@ -82,7 +88,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* Send a call through an indexed pseudonym of the sender.
|
||||
* The dispatch origin for this call must be _Signed_.
|
||||
* # <weight>
|
||||
* - The weight of the `call`.
|
||||
* - The weight of the `call` + 10,000.
|
||||
* # </weight>
|
||||
**/
|
||||
asSub: AugmentedSubmittable<(index: u16 | AnyNumber | Uint8Array, call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
@@ -213,7 +219,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
claim: AugmentedSubmittable<(index: AccountIndex | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Assign an index already owned by the sender to another account. The balance reservation
|
||||
* is effectively transfered to the new account.
|
||||
* is effectively transferred to the new account.
|
||||
* The dispatch origin for this call must be _Signed_.
|
||||
* - `index`: the index to be re-assigned. This must be owned by the sender.
|
||||
* - `new`: the new owner of the index. This function is a no-op if it is equal to sender.
|
||||
@@ -351,7 +357,8 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - Contains a limited number of reads.
|
||||
* - Each call (requires the remainder of the bonded balance to be above `minimum_balance`)
|
||||
* will cause a new entry to be inserted into a vector (`Ledger.unlocking`) kept in storage.
|
||||
* The only way to clean the aforementioned storage item is also user-controlled via `withdraw_unbonded`.
|
||||
* The only way to clean the aforementioned storage item is also user-controlled via
|
||||
* `withdraw_unbonded`.
|
||||
* - One DB entry.
|
||||
* </weight>
|
||||
**/
|
||||
@@ -469,6 +476,42 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
cancelDeferredSlash: AugmentedSubmittable<(era: EraIndex | AnyNumber | Uint8Array, slashIndices: Vec<u32> | (u32 | AnyNumber | Uint8Array)[]) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Make one nominator's payout for one era.
|
||||
* - `who` is the controller account of the nominator to pay out.
|
||||
* - `era` may not be lower than one following the most recently paid era. If it is higher,
|
||||
* then it indicates an instruction to skip the payout of all previous eras.
|
||||
* - `validators` is the list of all validators that `who` had exposure to during `era`.
|
||||
* If it is incomplete, then less than the full reward will be paid out.
|
||||
* It must not exceed `MAX_NOMINATIONS`.
|
||||
* WARNING: once an era is payed for a validator such validator can't claim the payout of
|
||||
* previous era.
|
||||
* WARNING: Incorrect arguments here can result in loss of payout. Be very careful.
|
||||
* # <weight>
|
||||
* - Number of storage read of `O(validators)`; `validators` is the argument of the call,
|
||||
* and is bounded by `MAX_NOMINATIONS`.
|
||||
* - Each storage read is `O(N)` size and decode complexity; `N` is the maximum
|
||||
* nominations that can be given to a single validator.
|
||||
* - Computation complexity: `O(MAX_NOMINATIONS * logN)`; `MAX_NOMINATIONS` is the
|
||||
* maximum number of validators that may be nominated by a single nominator, it is
|
||||
* bounded only economically (all nominators are required to place a minimum stake).
|
||||
* # </weight>
|
||||
**/
|
||||
payoutNominator: AugmentedSubmittable<(era: EraIndex | AnyNumber | Uint8Array, validators: Vec<ITuple<[AccountId, u32]>> | ([AccountId | string | Uint8Array, u32 | AnyNumber | Uint8Array])[]) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Make one validator's payout for one era.
|
||||
* - `who` is the controller account of the validator to pay out.
|
||||
* - `era` may not be lower than one following the most recently paid era. If it is higher,
|
||||
* then it indicates an instruction to skip the payout of all previous eras.
|
||||
* WARNING: once an era is payed for a validator such validator can't claim the payout of
|
||||
* previous era.
|
||||
* WARNING: Incorrect arguments here can result in loss of payout. Be very careful.
|
||||
* # <weight>
|
||||
* - Time complexity: O(1).
|
||||
* - Contains a limited number of reads and writes.
|
||||
* # </weight>
|
||||
**/
|
||||
payoutValidator: AugmentedSubmittable<(era: EraIndex | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Rebond a portion of the stash scheduled to be unlocked.
|
||||
* # <weight>
|
||||
@@ -477,6 +520,19 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
rebond: AugmentedSubmittable<(value: Compact<BalanceOf> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Set history_depth value.
|
||||
* Origin must be root.
|
||||
**/
|
||||
setHistoryDepth: AugmentedSubmittable<(newHistoryDepth: Compact<EraIndex> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Remove all data structure concerning a staker/stash once its balance is zero.
|
||||
* This is essentially equivalent to `withdraw_unbonded` except it can be called by anyone
|
||||
* and the target `stash` must have no funds left.
|
||||
* This can be called from any origin.
|
||||
* - `stash`: The stash account to reap. Its balance must be zero.
|
||||
**/
|
||||
reapStash: AugmentedSubmittable<(stash: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
session: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
@@ -488,24 +544,45 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # <weight>
|
||||
* - O(log n) in number of accounts.
|
||||
* - One extra DB entry.
|
||||
* - Increases system account refs by one on success iff there were previously no keys set.
|
||||
* In this case, purge_keys will need to be called before the account can be removed.
|
||||
* # </weight>
|
||||
**/
|
||||
setKeys: AugmentedSubmittable<(keys: Keys, proof: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Removes any session key(s) of the function caller.
|
||||
* This doesn't take effect until the next session.
|
||||
* The dispatch origin of this function must be signed.
|
||||
* # <weight>
|
||||
* - O(N) in number of key types.
|
||||
* - Removes N + 1 DB entries.
|
||||
* - Reduces system account refs by one on success.
|
||||
* # </weight>
|
||||
**/
|
||||
purgeKeys: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
democracy: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
* Propose a sensitive action to be taken.
|
||||
* The dispatch origin of this call must be _Signed_ and the sender must
|
||||
* have funds to cover the deposit.
|
||||
* - `proposal_hash`: The hash of the proposal preimage.
|
||||
* - `value`: The amount of deposit (must be at least `MinimumDeposit`).
|
||||
* Emits `Proposed`.
|
||||
* # <weight>
|
||||
* - O(1).
|
||||
* - `O(1)`.
|
||||
* - Two DB changes, one DB entry.
|
||||
* # </weight>
|
||||
**/
|
||||
propose: AugmentedSubmittable<(proposalHash: Hash | string | Uint8Array, value: Compact<BalanceOf> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Propose a sensitive action to be taken.
|
||||
* Signals agreement with a particular proposal.
|
||||
* The dispatch origin of this call must be _Signed_ and the sender
|
||||
* must have funds to cover the deposit, equal to the original deposit.
|
||||
* - `proposal`: The index of the proposal to second.
|
||||
* # <weight>
|
||||
* - O(1).
|
||||
* - `O(1)`.
|
||||
* - One DB entry.
|
||||
* # </weight>
|
||||
**/
|
||||
@@ -513,8 +590,11 @@ declare module '@polkadot/api/types/submittable' {
|
||||
/**
|
||||
* Vote in a referendum. If `vote.is_aye()`, the vote is to enact the proposal;
|
||||
* otherwise it is a vote to keep the status quo.
|
||||
* The dispatch origin of this call must be _Signed_.
|
||||
* - `ref_index`: The index of the referendum to vote for.
|
||||
* - `vote`: The vote configuration.
|
||||
* # <weight>
|
||||
* - O(1).
|
||||
* - `O(1)`.
|
||||
* - One DB change, one DB entry.
|
||||
* # </weight>
|
||||
**/
|
||||
@@ -522,8 +602,11 @@ declare module '@polkadot/api/types/submittable' {
|
||||
/**
|
||||
* Vote in a referendum on behalf of a stash. If `vote.is_aye()`, the vote is to enact
|
||||
* the proposal; otherwise it is a vote to keep the status quo.
|
||||
* The dispatch origin of this call must be _Signed_.
|
||||
* - `ref_index`: The index of the referendum to proxy vote for.
|
||||
* - `vote`: The vote configuration.
|
||||
* # <weight>
|
||||
* - O(1).
|
||||
* - `O(1)`.
|
||||
* - One DB change, one DB entry.
|
||||
* # </weight>
|
||||
**/
|
||||
@@ -531,73 +614,137 @@ declare module '@polkadot/api/types/submittable' {
|
||||
/**
|
||||
* Schedule an emergency cancellation of a referendum. Cannot happen twice to the same
|
||||
* referendum.
|
||||
* The dispatch origin of this call must be `CancellationOrigin`.
|
||||
* -`ref_index`: The index of the referendum to cancel.
|
||||
* # <weight>
|
||||
* - Depends on size of storage vec `VotersFor` for this referendum.
|
||||
* # </weight>
|
||||
**/
|
||||
emergencyCancel: AugmentedSubmittable<(refIndex: ReferendumIndex | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Schedule a referendum to be tabled once it is legal to schedule an external
|
||||
* referendum.
|
||||
* The dispatch origin of this call must be `ExternalOrigin`.
|
||||
* - `proposal_hash`: The preimage hash of the proposal.
|
||||
* # <weight>
|
||||
* - `O(1)`.
|
||||
* - One DB change.
|
||||
* # </weight>
|
||||
**/
|
||||
externalPropose: AugmentedSubmittable<(proposalHash: Hash | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Schedule a majority-carries referendum to be tabled next once it is legal to schedule
|
||||
* an external referendum.
|
||||
* The dispatch of this call must be `ExternalMajorityOrigin`.
|
||||
* - `proposal_hash`: The preimage hash of the proposal.
|
||||
* Unlike `external_propose`, blacklisting has no effect on this and it may replace a
|
||||
* pre-scheduled `external_propose` call.
|
||||
* # <weight>
|
||||
* - `O(1)`.
|
||||
* - One DB change.
|
||||
* # </weight>
|
||||
**/
|
||||
externalProposeMajority: AugmentedSubmittable<(proposalHash: Hash | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Schedule a negative-turnout-bias referendum to be tabled next once it is legal to
|
||||
* schedule an external referendum.
|
||||
* The dispatch of this call must be `ExternalDefaultOrigin`.
|
||||
* - `proposal_hash`: The preimage hash of the proposal.
|
||||
* Unlike `external_propose`, blacklisting has no effect on this and it may replace a
|
||||
* pre-scheduled `external_propose` call.
|
||||
* # <weight>
|
||||
* - `O(1)`.
|
||||
* - One DB change.
|
||||
* # </weight>
|
||||
**/
|
||||
externalProposeDefault: AugmentedSubmittable<(proposalHash: Hash | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Schedule the currently externally-proposed majority-carries referendum to be tabled
|
||||
* immediately. If there is no externally-proposed referendum currently, or if there is one
|
||||
* but it is not a majority-carries referendum then it fails.
|
||||
* The dispatch of this call must be `FastTrackOrigin`.
|
||||
* - `proposal_hash`: The hash of the current external proposal.
|
||||
* - `voting_period`: The period that is allowed for voting on this proposal. Increased to
|
||||
* `EmergencyVotingPeriod` if too low.
|
||||
* - `delay`: The number of block after voting has ended in approval and this should be
|
||||
* enacted. This doesn't have a minimum amount.
|
||||
* Emits `Started`.
|
||||
* # <weight>
|
||||
* - One DB clear.
|
||||
* - One DB change.
|
||||
* - One extra DB entry.
|
||||
* # </weight>
|
||||
**/
|
||||
fastTrack: AugmentedSubmittable<(proposalHash: Hash | string | Uint8Array, votingPeriod: BlockNumber | AnyNumber | Uint8Array, delay: BlockNumber | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Veto and blacklist the external proposal hash.
|
||||
* The dispatch origin of this call must be `VetoOrigin`.
|
||||
* - `proposal_hash`: The preimage hash of the proposal to veto and blacklist.
|
||||
* Emits `Vetoed`.
|
||||
* # <weight>
|
||||
* - Two DB entries.
|
||||
* - One DB clear.
|
||||
* - Performs a binary search on `existing_vetoers` which should not
|
||||
* be very large.
|
||||
* # </weight>
|
||||
**/
|
||||
vetoExternal: AugmentedSubmittable<(proposalHash: Hash | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Remove a referendum.
|
||||
* The dispatch origin of this call must be _Root_.
|
||||
* - `ref_index`: The index of the referendum to cancel.
|
||||
* # <weight>
|
||||
* - `O(1)`.
|
||||
* # </weight>
|
||||
**/
|
||||
cancelReferendum: AugmentedSubmittable<(refIndex: Compact<ReferendumIndex> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Cancel a proposal queued for enactment.
|
||||
* The dispatch origin of this call must be _Root_.
|
||||
* - `which`: The index of the referendum to cancel.
|
||||
* # <weight>
|
||||
* - One DB change.
|
||||
* # </weight>
|
||||
**/
|
||||
cancelQueued: AugmentedSubmittable<(which: ReferendumIndex | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Specify a proxy. Called by the stash.
|
||||
* Specify a proxy that is already open to us. Called by the stash.
|
||||
* NOTE: Used to be called `set_proxy`.
|
||||
* The dispatch origin of this call must be _Signed_.
|
||||
* - `proxy`: The account that will be activated as proxy.
|
||||
* # <weight>
|
||||
* - One extra DB entry.
|
||||
* # </weight>
|
||||
**/
|
||||
setProxy: AugmentedSubmittable<(proxy: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
activateProxy: AugmentedSubmittable<(proxy: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Clear the proxy. Called by the proxy.
|
||||
* NOTE: Used to be called `resign_proxy`.
|
||||
* The dispatch origin of this call must be _Signed_.
|
||||
* # <weight>
|
||||
* - One DB clear.
|
||||
* # </weight>
|
||||
**/
|
||||
resignProxy: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>>;
|
||||
closeProxy: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Clear the proxy. Called by the stash.
|
||||
* Deactivate the proxy, but leave open to this account. Called by the stash.
|
||||
* The proxy must already be active.
|
||||
* NOTE: Used to be called `remove_proxy`.
|
||||
* The dispatch origin of this call must be _Signed_.
|
||||
* - `proxy`: The account that will be deactivated as proxy.
|
||||
* # <weight>
|
||||
* - One DB clear.
|
||||
* # </weight>
|
||||
**/
|
||||
removeProxy: AugmentedSubmittable<(proxy: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
deactivateProxy: AugmentedSubmittable<(proxy: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Delegate vote.
|
||||
* Currency is locked indefinitely for as long as it's delegated.
|
||||
* The dispatch origin of this call must be _Signed_.
|
||||
* - `to`: The account to make a delegate of the sender.
|
||||
* - `conviction`: The conviction that will be attached to the delegated
|
||||
* votes.
|
||||
* Emits `Delegated`.
|
||||
* # <weight>
|
||||
* - One extra DB entry.
|
||||
* # </weight>
|
||||
@@ -605,42 +752,92 @@ declare module '@polkadot/api/types/submittable' {
|
||||
delegate: AugmentedSubmittable<(to: AccountId | string | Uint8Array, conviction: Conviction | ('None' | 'Locked1x' | 'Locked2x' | 'Locked3x' | 'Locked4x' | 'Locked5x' | 'Locked6x') | number | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Undelegate vote.
|
||||
* Must be sent from an account that has called delegate previously.
|
||||
* The tokens will be reduced from an indefinite lock to the maximum
|
||||
* possible according to the conviction of the prior delegation.
|
||||
* The dispatch origin of this call must be _Signed_.
|
||||
* Emits `Undelegated`.
|
||||
* # <weight>
|
||||
* - O(1).
|
||||
* # </weight>
|
||||
**/
|
||||
undelegate: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Veto and blacklist the proposal hash. Must be from Root origin.
|
||||
* Clears all public proposals.
|
||||
* The dispatch origin of this call must be _Root_.
|
||||
* # <weight>
|
||||
* - `O(1)`.
|
||||
* - One DB clear.
|
||||
* # </weight>
|
||||
**/
|
||||
clearPublicProposals: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Register the preimage for an upcoming proposal. This doesn't require the proposal to be
|
||||
* in the dispatch queue but does require a deposit, returned once enacted.
|
||||
* The dispatch origin of this call must be _Signed_.
|
||||
* - `encoded_proposal`: The preimage of a proposal.
|
||||
* Emits `PreimageNoted`.
|
||||
* # <weight>
|
||||
* - Dependent on the size of `encoded_proposal` but protected by a
|
||||
* required deposit.
|
||||
* # </weight>
|
||||
**/
|
||||
notePreimage: AugmentedSubmittable<(encodedProposal: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Register the preimage for an upcoming proposal. This requires the proposal to be
|
||||
* in the dispatch queue. No deposit is needed.
|
||||
* The dispatch origin of this call must be _Signed_.
|
||||
* - `encoded_proposal`: The preimage of a proposal.
|
||||
* Emits `PreimageNoted`.
|
||||
* # <weight>
|
||||
* - Dependent on the size of `encoded_proposal`.
|
||||
* # </weight>
|
||||
**/
|
||||
noteImminentPreimage: AugmentedSubmittable<(encodedProposal: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Remove an expired proposal preimage and collect the deposit.
|
||||
* The dispatch origin of this call must be _Signed_.
|
||||
* - `proposal_hash`: The preimage hash of a proposal.
|
||||
* This will only work after `VotingPeriod` blocks from the time that the preimage was
|
||||
* noted, if it's the same account doing it. If it's a different account, then it'll only
|
||||
* work an additional `EnactmentPeriod` later.
|
||||
* Emits `PreimageReaped`.
|
||||
* # <weight>
|
||||
* - One DB clear.
|
||||
* # </weight>
|
||||
**/
|
||||
reapPreimage: AugmentedSubmittable<(proposalHash: Hash | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Unlock tokens that have an expired lock.
|
||||
* The dispatch origin of this call must be _Signed_.
|
||||
* - `target`: The account to remove the lock on.
|
||||
* Emits `Unlocked`.
|
||||
* # <weight>
|
||||
* - `O(1)`.
|
||||
* # </weight>
|
||||
**/
|
||||
unlock: AugmentedSubmittable<(target: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Become a proxy.
|
||||
* This must be called prior to a later `activate_proxy`.
|
||||
* Origin must be a Signed.
|
||||
* - `target`: The account whose votes will later be proxied.
|
||||
* `close_proxy` must be called before the account can be destroyed.
|
||||
* # <weight>
|
||||
* - One extra DB entry.
|
||||
* # </weight>
|
||||
**/
|
||||
openProxy: AugmentedSubmittable<(target: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
council: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
* Set the collective's membership manually to `new_members`. Be nice to the chain and
|
||||
* provide it pre-sorted.
|
||||
* Set the collective's membership.
|
||||
* - `new_members`: The new member list. Be nice to the chain and
|
||||
* - `prime`: The prime member whose vote sets the default.
|
||||
* Requires root origin.
|
||||
**/
|
||||
setMembers: AugmentedSubmittable<(newMembers: Vec<AccountId> | (AccountId | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType>>;
|
||||
setMembers: AugmentedSubmittable<(newMembers: Vec<AccountId> | (AccountId | string | Uint8Array)[], prime: Option<AccountId> | null | object | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Dispatch a proposal from a member using the `Member` origin.
|
||||
* Origin must be a member of the collective.
|
||||
@@ -660,15 +857,30 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
vote: AugmentedSubmittable<(proposal: Hash | string | Uint8Array, index: Compact<ProposalIndex> | AnyNumber | Uint8Array, approve: bool | boolean | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* May be called by any signed account after the voting duration has ended in order to
|
||||
* finish voting and close the proposal.
|
||||
* Abstentions are counted as rejections unless there is a prime member set and the prime
|
||||
* member cast an approval.
|
||||
* - the weight of `proposal` preimage.
|
||||
* - up to three events deposited.
|
||||
* - one read, two removals, one mutation. (plus three static reads.)
|
||||
* - computation and i/o `O(P + L + M)` where:
|
||||
* - `M` is number of members,
|
||||
* - `P` is number of active proposals,
|
||||
* - `L` is the encoded length of `proposal` preimage.
|
||||
**/
|
||||
close: AugmentedSubmittable<(proposal: Hash | string | Uint8Array, index: Compact<ProposalIndex> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
technicalCommittee: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
/**
|
||||
* Set the collective's membership manually to `new_members`. Be nice to the chain and
|
||||
* provide it pre-sorted.
|
||||
* Set the collective's membership.
|
||||
* - `new_members`: The new member list. Be nice to the chain and
|
||||
* - `prime`: The prime member whose vote sets the default.
|
||||
* Requires root origin.
|
||||
**/
|
||||
setMembers: AugmentedSubmittable<(newMembers: Vec<AccountId> | (AccountId | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType>>;
|
||||
setMembers: AugmentedSubmittable<(newMembers: Vec<AccountId> | (AccountId | string | Uint8Array)[], prime: Option<AccountId> | null | object | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Dispatch a proposal from a member using the `Member` origin.
|
||||
* Origin must be a member of the collective.
|
||||
@@ -688,6 +900,20 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
vote: AugmentedSubmittable<(proposal: Hash | string | Uint8Array, index: Compact<ProposalIndex> | AnyNumber | Uint8Array, approve: bool | boolean | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* May be called by any signed account after the voting duration has ended in order to
|
||||
* finish voting and close the proposal.
|
||||
* Abstentions are counted as rejections unless there is a prime member set and the prime
|
||||
* member cast an approval.
|
||||
* - the weight of `proposal` preimage.
|
||||
* - up to three events deposited.
|
||||
* - one read, two removals, one mutation. (plus three static reads.)
|
||||
* - computation and i/o `O(P + L + M)` where:
|
||||
* - `M` is number of members,
|
||||
* - `P` is number of active proposals,
|
||||
* - `L` is the encoded length of `proposal` preimage.
|
||||
**/
|
||||
close: AugmentedSubmittable<(proposal: Hash | string | Uint8Array, index: Compact<ProposalIndex> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
elections: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
@@ -784,6 +1010,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
/**
|
||||
* Swap out one member `remove` for another `add`.
|
||||
* May only be called from `SwapOrigin` or root.
|
||||
* Prime membership is *not* passed from `remove` to `add`, if extant.
|
||||
**/
|
||||
swapMember: AugmentedSubmittable<(remove: AccountId | string | Uint8Array, add: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
@@ -795,8 +1022,17 @@ declare module '@polkadot/api/types/submittable' {
|
||||
/**
|
||||
* Swap out the sending member for some other key `new`.
|
||||
* May only be called from `Signed` origin of a current member.
|
||||
* Prime membership is passed from the origin account to `new`, if extant.
|
||||
**/
|
||||
changeKey: AugmentedSubmittable<(updated: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Set the prime member. Must be a current member.
|
||||
**/
|
||||
setPrime: AugmentedSubmittable<(who: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Remove the prime member if it exists.
|
||||
**/
|
||||
clearPrime: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
finalityTracker: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
@@ -978,10 +1214,10 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - O(1).
|
||||
* - Limited storage reads.
|
||||
* - One DB write (event).
|
||||
* - Unknown weight of derivative `proposal` execution.
|
||||
* - Weight of derivative `call` execution + 10,000.
|
||||
* # </weight>
|
||||
**/
|
||||
sudo: AugmentedSubmittable<(proposal: Proposal | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
sudo: AugmentedSubmittable<(call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Authenticates the current sudo key and sets the given AccountId (`new`) as the new sudo key.
|
||||
* The dispatch origin for this call must be _Signed_.
|
||||
@@ -1000,10 +1236,10 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - O(1).
|
||||
* - Limited storage reads.
|
||||
* - One DB write (event).
|
||||
* - Unknown weight of derivative `proposal` execution.
|
||||
* - Weight of derivative `call` execution + 10,000.
|
||||
* # </weight>
|
||||
**/
|
||||
sudoAs: AugmentedSubmittable<(who: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, proposal: Proposal | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
sudoAs: AugmentedSubmittable<(who: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, call: Call | { callIndex?: any; args?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
imOnline: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
@@ -1077,7 +1313,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - `reg_index`: The index of the registrar whose judgement is requested.
|
||||
* - `max_fee`: The maximum fee that may be paid. This should just be auto-populated as:
|
||||
* ```nocompile
|
||||
* Self::registrars(reg_index).uwnrap().fee
|
||||
* Self::registrars(reg_index).unwrap().fee
|
||||
* ```
|
||||
* Emits `JudgementRequested` if successful.
|
||||
* # <weight>
|
||||
@@ -1351,7 +1587,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
**/
|
||||
found: AugmentedSubmittable<(founder: AccountId | string | Uint8Array, maxMembers: u32 | AnyNumber | Uint8Array, rules: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Anull the founding of the society.
|
||||
* Annul the founding of the society.
|
||||
* The dispatch origin for this call must be Signed, and the signing account must be both
|
||||
* the `Founder` and the `Head`. This implies that it may only be done when there is one
|
||||
* member.
|
||||
@@ -1447,7 +1683,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* - `account`: The recovered account you want to make a call on-behalf-of.
|
||||
* - `call`: The call you want to make with the recovered account.
|
||||
* # <weight>
|
||||
* - The weight of the `call`.
|
||||
* - The weight of the `call` + 10,000.
|
||||
* - One storage lookup to check account is recovered by `who`. O(1)
|
||||
* # </weight>
|
||||
**/
|
||||
@@ -1571,7 +1807,7 @@ declare module '@polkadot/api/types/submittable' {
|
||||
**/
|
||||
closeRecovery: AugmentedSubmittable<(rescuer: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Remove the recovery process for your account.
|
||||
* Remove the recovery process for your account. Recovered accounts are still accessible.
|
||||
* NOTE: The user must make sure to call `close_recovery` on all active
|
||||
* recovery attempts before calling this function else it will fail.
|
||||
* Payment: By calling this function the recoverable account will unreserve
|
||||
@@ -1589,6 +1825,17 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
removeRecovery: AugmentedSubmittable<() => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Cancel the ability to use `as_recovered` for `account`.
|
||||
* The dispatch origin for this call must be _Signed_ and registered to
|
||||
* be able to make calls on behalf of the recovered account.
|
||||
* Parameters:
|
||||
* - `account`: The recovered account you are able to call on-behalf-of.
|
||||
* # <weight>
|
||||
* - One storage mutation to check account is recovered by `who`. O(1)
|
||||
* # </weight>
|
||||
**/
|
||||
cancelRecovered: AugmentedSubmittable<(account: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
vesting: {
|
||||
[index: string]: SubmittableExtrinsicFunction<ApiType>;
|
||||
@@ -1620,11 +1867,24 @@ declare module '@polkadot/api/types/submittable' {
|
||||
* # </weight>
|
||||
**/
|
||||
vestOther: AugmentedSubmittable<(target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
/**
|
||||
* Create a vested transfer.
|
||||
* The dispatch origin for this call must be _Signed_.
|
||||
* - `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>
|
||||
* - Creates a new storage entry, but is protected by a minimum transfer
|
||||
* amount needed to succeed.
|
||||
* # </weight>
|
||||
**/
|
||||
vestedTransfer: AugmentedSubmittable<(target: LookupSource | Address | AccountId | AccountIndex | string | Uint8Array, schedule: VestingInfo | { locked?: any; perBlock?: any; startingBlock?: any } | string | Uint8Array) => SubmittableExtrinsic<ApiType>>;
|
||||
};
|
||||
}
|
||||
|
||||
export interface SubmittableExtrinsics<ApiType extends ApiTypes> extends AugmentedSubmittables<ApiType> {
|
||||
(extrinsic: Uint8Array | string): SubmittableExtrinsic<ApiType>;
|
||||
(extrinsic: Call | Extrinsic | Uint8Array | string): SubmittableExtrinsic<ApiType>;
|
||||
[index: string]: SubmittableModuleExtrinsics<ApiType>;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,21 +11,23 @@ import { ApiInterfaceRx, ApiOptions, ApiTypes, DecorateMethod, DecoratedRpc, Dec
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { BehaviorSubject, Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { map, switchMap, take } from 'rxjs/operators';
|
||||
import decorateDerive, { ExactDerive } from '@polkadot/api-derive';
|
||||
import { memo } from '@polkadot/api-derive/util';
|
||||
import DecoratedMeta from '@polkadot/metadata/Decorated';
|
||||
import getHasher from '@polkadot/metadata/Decorated/storage/fromMetadata/getHasher';
|
||||
import RpcCore from '@polkadot/rpc-core';
|
||||
import { WsProvider } from '@polkadot/rpc-provider';
|
||||
import { Metadata, Null, Option, Text, TypeRegistry, u64, Vec } from '@polkadot/types';
|
||||
import { Metadata, Null, Option, Raw, Text, TypeRegistry, u64 } from '@polkadot/types';
|
||||
import Linkage, { LinkageResult } from '@polkadot/types/codec/Linkage';
|
||||
import { DEFAULT_VERSION as EXTRINSIC_DEFAULT_VERSION } from '@polkadot/types/extrinsic/constants';
|
||||
import StorageKey, { StorageEntry } from '@polkadot/types/primitive/StorageKey';
|
||||
import StorageKey, { StorageEntry, unwrapStorageType } from '@polkadot/types/primitive/StorageKey';
|
||||
import { assert, compactStripLength, isNull, isUndefined, u8aConcat, u8aToHex } from '@polkadot/util';
|
||||
|
||||
import { createSubmittable } from '../submittable';
|
||||
import { decorateSections, DeriveAllSections } from '../util/decorate';
|
||||
import augmentObject from '../util/augmentObject';
|
||||
import { decorateSections, DeriveAllSections } from '../util/decorate';
|
||||
import { extractStorageArgs } from '../util/validate';
|
||||
import Events from './Events';
|
||||
|
||||
interface MetaDecoration {
|
||||
@@ -48,7 +50,7 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
|
||||
protected _derive?: ReturnType<Decorate<ApiType>['decorateDerive']>;
|
||||
|
||||
protected _extrinsics: SubmittableExtrinsics<ApiType> = {} as SubmittableExtrinsics<ApiType>;
|
||||
protected _extrinsics?: SubmittableExtrinsics<ApiType>;
|
||||
|
||||
protected _extrinsicType: number = EXTRINSIC_DEFAULT_VERSION;
|
||||
|
||||
@@ -160,13 +162,19 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
public injectMetadata (metadata: Metadata, fromEmpty?: boolean): void {
|
||||
const decoratedMeta = new DecoratedMeta(this.registry, metadata);
|
||||
|
||||
if (fromEmpty || !this._extrinsics) {
|
||||
this._extrinsics = this.decorateExtrinsics(decoratedMeta.tx, this.decorateMethod);
|
||||
this._rx.tx = this.decorateExtrinsics(decoratedMeta.tx, this.rxDecorateMethod);
|
||||
} else {
|
||||
augmentObject('tx', this.decorateExtrinsics(decoratedMeta.tx, this.decorateMethod), this._extrinsics, false);
|
||||
augmentObject('', this.decorateExtrinsics(decoratedMeta.tx, this.rxDecorateMethod), this._rx.tx, false);
|
||||
}
|
||||
|
||||
// this API
|
||||
augmentObject('tx', this.decorateExtrinsics(decoratedMeta.tx, this.decorateMethod), this._extrinsics, fromEmpty);
|
||||
augmentObject('query', this.decorateStorage(decoratedMeta.query, this.decorateMethod), this._query, fromEmpty);
|
||||
augmentObject('consts', decoratedMeta.consts, this._consts, fromEmpty);
|
||||
|
||||
// rx
|
||||
augmentObject('', this.decorateExtrinsics(decoratedMeta.tx, this.rxDecorateMethod), this._rx.tx, fromEmpty);
|
||||
augmentObject('', this.decorateStorage(decoratedMeta.query, this.rxDecorateMethod), this._rx.query, fromEmpty);
|
||||
augmentObject('', decoratedMeta.consts, this._rx.consts, fromEmpty);
|
||||
}
|
||||
@@ -230,6 +238,7 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
// skip subscriptions where we have a non-subscribe interface
|
||||
if (this.hasSubscriptions || !(methodName.startsWith('subscribe') || methodName.startsWith('unsubscribe'))) {
|
||||
(section as any)[methodName] = decorateMethod(method, { methodName });
|
||||
(section as any)[methodName].raw = decorateMethod(method.raw, { methodName });
|
||||
}
|
||||
|
||||
return section;
|
||||
@@ -284,9 +293,7 @@ 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[] => creator.meta.type.isDoubleMap
|
||||
? [creator, args]
|
||||
: [creator, ...args];
|
||||
const getArgs = (...args: any[]): any[] => extractStorageArgs(creator, args);
|
||||
|
||||
// FIXME We probably want to be able to query the full list with non-subs as well
|
||||
const decorated = this.hasSubscriptions && creator.iterKey && creator.meta.type.isMap && creator.meta.type.asMap.linked.isTrue
|
||||
@@ -307,8 +314,8 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
decorated.at = decorateMethod((hash: Hash, arg1?: Arg, arg2?: Arg): Observable<Codec> =>
|
||||
this._rpcCore.state.getStorage(getArgs(arg1, arg2), hash));
|
||||
|
||||
decorated.entries = decorateMethod((doubleMapArg?: Arg): Observable<[StorageKey, Codec][]> =>
|
||||
this.retrieveMapEntries(creator, doubleMapArg));
|
||||
decorated.entries = decorateMethod(memo((doubleMapArg?: Arg): Observable<[StorageKey, Codec][]> =>
|
||||
this.retrieveMapEntries(creator, doubleMapArg)));
|
||||
|
||||
decorated.hash = decorateMethod((arg1?: Arg, arg2?: Arg): Observable<Hash> =>
|
||||
this._rpcCore.state.getStorageHash(getArgs(arg1, arg2)));
|
||||
@@ -319,6 +326,9 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
decorated.keyPrefix = (): string =>
|
||||
u8aToHex(creator.keyPrefix);
|
||||
|
||||
decorated.keys = decorateMethod(memo((doubleMapArg?: Arg): Observable<StorageKey[]> =>
|
||||
this.retrieveMapKeys(creator, doubleMapArg)));
|
||||
|
||||
if (this.hasSubscriptions) {
|
||||
// When using double map storage function, user need to pass double map key as an array
|
||||
decorated.multi = decorateMethod((args: (Arg | Arg[])[]): Observable<Codec[]> =>
|
||||
@@ -326,12 +336,28 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
args.map((arg: Arg[] | Arg): [StorageEntry, Arg | Arg[]] => [creator, arg])));
|
||||
}
|
||||
|
||||
decorated.range = decorateMethod(memo((range: [Hash, Hash?], arg1?: Arg, arg2?: Arg): Observable<[Hash, Codec][]> =>
|
||||
this.decorateStorageRange(decorated, [arg1, arg2], range)));
|
||||
|
||||
decorated.size = decorateMethod((arg1?: Arg, arg2?: Arg): Observable<u64> =>
|
||||
this._rpcCore.state.getStorageSize(getArgs(arg1, arg2)));
|
||||
|
||||
return this.decorateFunctionMeta(creator, decorated) as unknown as QueryableStorageEntry<ApiType>;
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return this._rpcCore.state
|
||||
.queryStorage<[Option<Raw>]>([decorated.key(...args)], ...range)
|
||||
.pipe(map((result: [Hash, [Option<Raw>]][]): [Hash, Codec][] =>
|
||||
result.map(([blockHash, [value]]): [Hash, Codec] => [
|
||||
blockHash,
|
||||
this.createType(outputType, value.isSome ? value.unwrap().toHex() : undefined)
|
||||
])
|
||||
));
|
||||
}
|
||||
|
||||
private decorateStorageLinked<ApiType extends ApiTypes> (creator: StorageEntry, decorateMethod: DecorateMethod<ApiType>): ReturnType<DecorateMethod<ApiType>> {
|
||||
const result: Map<Codec, ITuple<[Codec, Linkage<Codec>]> | null> = new Map();
|
||||
let subject: BehaviorSubject<LinkageResult>;
|
||||
@@ -341,8 +367,8 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
// entries can be re-linked in the middle of a list, we subscribe here to make
|
||||
// sure we catch any updates, no matter the list position
|
||||
const getNext = (key: Codec): Observable<LinkageResult> =>
|
||||
this._rpcCore.state.subscribeStorage<[LinkageData | Option<LinkageData>]>([[creator, key]]).pipe(
|
||||
switchMap(([_data]: [LinkageData | Option<LinkageData>]): Observable<LinkageResult> => {
|
||||
this._rpcCore.state.getStorage<LinkageData | Option<LinkageData>>([creator, key]).pipe(
|
||||
switchMap((_data: LinkageData | Option<LinkageData>): Observable<LinkageResult> => {
|
||||
const data = creator.meta.modifier.isOptional
|
||||
? (_data as Option<LinkageData>).unwrapOr(null)
|
||||
: _data as LinkageData;
|
||||
@@ -404,38 +430,44 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
);
|
||||
}
|
||||
|
||||
private retrieveMapEntries (creator: StorageEntry, arg?: Arg): Observable<[StorageKey, Codec][]> {
|
||||
assert(creator.iterKey && (creator.meta.type.isMap || creator.meta.type.isDoubleMap), 'entries can only be retrieved on maps, linked maps and double maps');
|
||||
private retrieveMapKeys ({ iterKey, meta }: StorageEntry, arg?: Arg): Observable<StorageKey[]> {
|
||||
assert(iterKey && (meta.type.isMap || meta.type.isDoubleMap), 'keys can only be retrieved on maps, linked maps and double maps');
|
||||
|
||||
const outputType = creator.meta.type.isMap
|
||||
? creator.meta.type.asMap.value.toString()
|
||||
: creator.meta.type.asDoubleMap.value.toString();
|
||||
const startKey = this.createType('Raw', u8aConcat(
|
||||
iterKey,
|
||||
meta.type.isDoubleMap && !isUndefined(arg) && !isNull(arg)
|
||||
? getHasher(meta.type.asDoubleMap.hasher)(
|
||||
this.createType(meta.type.asDoubleMap.key1.toString() as 'Raw', arg).toU8a()
|
||||
)
|
||||
: new Uint8Array([])
|
||||
));
|
||||
|
||||
return this._rpcCore.state
|
||||
// FIXME This should really be some sort of subscription, so we can get stuff as
|
||||
// it changes (as of now it is a one-shot query). Not sure how to do this though...
|
||||
.getKeys(
|
||||
this.createType('Raw', u8aConcat(
|
||||
creator.iterKey,
|
||||
creator.meta.type.isDoubleMap && !isUndefined(arg) && !isNull(arg)
|
||||
? getHasher(creator.meta.type.asDoubleMap.hasher)(
|
||||
this.createType(creator.meta.type.asDoubleMap.key1.toString() as 'Raw', arg).toU8a()
|
||||
)
|
||||
: new Uint8Array([])
|
||||
))
|
||||
return this._rpcCore.state.getKeys(startKey).pipe(
|
||||
map((keys): StorageKey[] =>
|
||||
keys.map((key) => key.decodeArgsFromMeta(meta))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
private retrieveMapEntries (entry: StorageEntry, arg?: Arg): Observable<[StorageKey, Codec][]> {
|
||||
const outputType = unwrapStorageType(entry.meta.type, entry.meta.modifier.isOptional);
|
||||
|
||||
return this.retrieveMapKeys(entry, arg)
|
||||
.pipe(
|
||||
switchMap((keys): Observable<[StorageKey[], Vec<Codec>]> =>
|
||||
switchMap((keys): Observable<[StorageKey[], Option<Raw>[]]> =>
|
||||
combineLatest([
|
||||
of(keys),
|
||||
// Not 100% sure about this, surely this is just a vec?
|
||||
this._rpcCore.state.subscribeStorage<Vec<Codec>>(
|
||||
keys.map((key) => key.setOutputType(outputType))
|
||||
)
|
||||
// Since we have a default constructed key, we have Option<Raw> as the result
|
||||
// Don't keep the subscription here active, retrieve and get out of Dodge
|
||||
// TODO Once we have a multiple key RPC available, use that via fallback
|
||||
this._rpcCore.state.subscribeStorage<Option<Raw>[]>(keys).pipe(take(1))
|
||||
])
|
||||
),
|
||||
map(([keys, values]): [StorageKey, Codec][] =>
|
||||
keys.map((key, index): [StorageKey, Codec] => [key, values[index]])
|
||||
keys.map((key, index): [StorageKey, Codec] => [
|
||||
key,
|
||||
this.createType(outputType, values[index].isSome ? values[index].unwrap().toHex() : undefined)
|
||||
])
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -31,11 +31,21 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
l.warn('Api will be available in a limited mode since the provider does not support subscriptions');
|
||||
}
|
||||
|
||||
// all injected types added to the registry for overrides
|
||||
this.registry.setKnownTypes({
|
||||
types: options.types,
|
||||
typesAlias: options.typesAlias,
|
||||
typesChain: options.typesChain,
|
||||
typesSpec: options.typesSpec
|
||||
});
|
||||
|
||||
// We only register the types (global) if this is not a cloned instance.
|
||||
// Do right up-front, so we get in the user types before we are actually
|
||||
// doing anything on-chain, this ensures we have the overrides in-place
|
||||
if (!options.source && options.types) {
|
||||
if (!options.source) {
|
||||
this.registerTypes(options.types);
|
||||
} else {
|
||||
this.registry.setKnownTypes(options.source.registry.knownTypes);
|
||||
}
|
||||
|
||||
this._rpc = this.decorateRpc(this._rpcCore, this.decorateMethod);
|
||||
@@ -130,7 +140,7 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
this._runtimeMetadata = metadata;
|
||||
this._runtimeVersion = version;
|
||||
|
||||
this.registerTypes(getSpecTypes(this._runtimeChain as Text, version));
|
||||
this.registerTypes(getSpecTypes(this.registry, this._runtimeChain as Text, version));
|
||||
this.injectMetadata(metadata, false);
|
||||
|
||||
return true;
|
||||
@@ -139,7 +149,6 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
}
|
||||
|
||||
private async metaFromChain (optMetadata: Record<string, string>): Promise<Metadata> {
|
||||
const { typesChain, typesSpec } = this._options;
|
||||
const [runtimeVersion, chain, chainProps] = await Promise.all([
|
||||
this._rpcCore.state.getRuntimeVersion().toPromise(),
|
||||
this._rpcCore.system.chain().toPromise(),
|
||||
@@ -152,8 +161,8 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
|
||||
// do the setup for the specific chain
|
||||
this.registry.setChainProperties(chainProps);
|
||||
this.registerTypes(getSpecTypes(chain, runtimeVersion));
|
||||
this.registerTypes(getUserTypes(chain, runtimeVersion, typesChain, typesSpec));
|
||||
this.registerTypes(getSpecTypes(this.registry, chain, runtimeVersion));
|
||||
this.registerTypes(getUserTypes(this.registry, chain, runtimeVersion));
|
||||
this.subscribeUpdates();
|
||||
|
||||
// filter the RPC methods (this does an rpc-methods call)
|
||||
@@ -173,7 +182,7 @@ export default abstract class Init<ApiType extends ApiTypes> extends Decorate<Ap
|
||||
|
||||
private async initFromMeta (metadata: Metadata): Promise<boolean> {
|
||||
// inject types based on metadata, if applicable
|
||||
this.registerTypes(getMetadataTypes(metadata.version));
|
||||
this.registerTypes(getMetadataTypes(this.registry, metadata.version));
|
||||
|
||||
const metaExtrinsic = metadata.asLatest.extrinsic;
|
||||
|
||||
|
||||
@@ -60,19 +60,49 @@ async function query (api: ApiPromise, keyring: TestKeyringMap): Promise<void> {
|
||||
multiUnsub();
|
||||
});
|
||||
|
||||
// check multi , Promise result
|
||||
const multiRes = await api.queryMulti([
|
||||
[api.query.system.account, keyring.eve.address],
|
||||
// older chains only
|
||||
[api.query.system.accountNonce, keyring.bob.address]
|
||||
]);
|
||||
|
||||
console.log(multiRes);
|
||||
|
||||
// at queries
|
||||
const events = await api.query.system.events.at('0x12345');
|
||||
console.log(`Received ${events.length} events:`);
|
||||
|
||||
// check entries()
|
||||
await api.query.system.account.entries(); // should not take a param
|
||||
await api.query.staking.nominatorSlashInEra.entries(123); // should take a param
|
||||
|
||||
// check range
|
||||
await api.query.balances.freeBalance.range<Balance>(['0x1234'], keyring.bob.address);
|
||||
|
||||
// check range types
|
||||
const entries = await api.query.system.events.range(['0x12345', '0x7890']);
|
||||
console.log(`Received ${entries.length} entries, ${entries.map(([hash, events]) => `${hash.toHex()}: ${events.length} events`)}`);
|
||||
}
|
||||
|
||||
async function rpc (api: ApiPromise): Promise<void> {
|
||||
await api.rpc.chain.subscribeNewHeads((header: Header): void => {
|
||||
console.log('current header:', header);
|
||||
// defaults
|
||||
await api.rpc.chain.subscribeNewHeads((header): void => {
|
||||
console.log('current header #', header.number.toNumber());
|
||||
});
|
||||
|
||||
// with generic params
|
||||
await api.rpc.state.subscribeStorage<[Balance]>(['my_balance_key'], ([balance]): void => {
|
||||
console.log('current balance:', balance.toString());
|
||||
});
|
||||
|
||||
// using raw
|
||||
await api.rpc.chain.getBlock.raw('0x123456');
|
||||
|
||||
// using raw subs
|
||||
api.rpc.chain.subscribeNewHeads.raw((result: Uint8Array): void => {
|
||||
console.log(result);
|
||||
});
|
||||
}
|
||||
|
||||
function types (api: ApiPromise): void {
|
||||
|
||||
@@ -6,7 +6,7 @@ import { detectPackage } from '@polkadot/util';
|
||||
|
||||
// FIXME This really should be `import(...).then(...)`, but need to check rejections
|
||||
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
||||
detectPackage(require('./package.json'), __dirname);
|
||||
detectPackage(require('./package.json'), typeof __dirname !== 'undefined' && __dirname);
|
||||
|
||||
export { Keyring } from '@polkadot/keyring';
|
||||
export { WsProvider } from '@polkadot/rpc-provider';
|
||||
|
||||
@@ -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 { ApiOptions } from '../types';
|
||||
import { ApiOptions, SubmittableExtrinsic } from '../types';
|
||||
|
||||
import createPair from '@polkadot/keyring/pair';
|
||||
import testKeyring from '@polkadot/keyring/testing';
|
||||
@@ -13,6 +13,8 @@ import { hexToU8a } from '@polkadot/util';
|
||||
import { SingleAccountSigner } from '../../test/util';
|
||||
import ApiPromise from './Api';
|
||||
|
||||
const TRANSFER_SIG = '0x62bfcd07a9f50ba32ed9e2c41ca11267ac62a24c95949e25efdccc4989d48573f84754dbbaa1d0937ceb888ad8a2cf71daced1545a839d9d6cceac33a5771401';
|
||||
|
||||
describe('ApiPromise', (): void => {
|
||||
const registry = new TypeRegistry();
|
||||
const keyring = testKeyring({ type: 'ed25519' });
|
||||
@@ -25,6 +27,23 @@ describe('ApiPromise', (): void => {
|
||||
);
|
||||
let provider: Mock;
|
||||
|
||||
async function createTransfer (): Promise<{ api: ApiPromise; transfer: SubmittableExtrinsic<'promise'> }> {
|
||||
provider.subscriptions.state_subscribeStorage.lastValue = {
|
||||
changes: [
|
||||
[
|
||||
'0x26aa394eea5630e07c48ae0c9558cef79c2f82b23e5fd031fb54c292794b4cc4d560eb8d00e57357cf76492334e43bb2ecaa9f28df6a8c4426d7b6090f7ad3c9',
|
||||
'0x00'
|
||||
]
|
||||
]
|
||||
};
|
||||
|
||||
const signer = new SingleAccountSigner(registry, aliceEd);
|
||||
const api = await ApiPromise.create({ provider, registry, signer });
|
||||
const transfer = api.tx.balances.transfer(keyring.getPair('0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e').address, 321_564_789_876_512_345n);
|
||||
|
||||
return { api, transfer: await transfer.signAsync(aliceEd.address, {}) };
|
||||
}
|
||||
|
||||
beforeEach((): void => {
|
||||
jest.setTimeout(3000000);
|
||||
provider = new Mock(registry);
|
||||
@@ -110,24 +129,18 @@ describe('ApiPromise', (): void => {
|
||||
|
||||
describe('decorator.signAsync', (): void => {
|
||||
it('signs a transfer using an external signer', async (): Promise<void> => {
|
||||
provider.subscriptions.state_subscribeStorage.lastValue = {
|
||||
changes: [
|
||||
[
|
||||
'0x26aa394eea5630e07c48ae0c9558cef79c2f82b23e5fd031fb54c292794b4cc4d560eb8d00e57357cf76492334e43bb2ecaa9f28df6a8c4426d7b6090f7ad3c9',
|
||||
'0x00'
|
||||
]
|
||||
]
|
||||
};
|
||||
const { transfer } = await createTransfer();
|
||||
|
||||
const signer = new SingleAccountSigner(registry, aliceEd);
|
||||
const api = await ApiPromise.create({ provider, registry, signer });
|
||||
const transfer = api.tx.balances.transfer(keyring.getPair('0xe659a7a1628cdd93febc04a4e0646ea20e9f5f0ce097d9a05290d4a9e054df4e').address, 321_564_789_876_512_345n);
|
||||
expect(transfer.signature.toHex()).toEqual(TRANSFER_SIG);
|
||||
});
|
||||
});
|
||||
|
||||
await transfer.signAsync(aliceEd.address, {});
|
||||
describe('api.tx(...)', (): void => {
|
||||
it('allows construction from existing extrinsic', async (): Promise<void> => {
|
||||
const { api, transfer } = await createTransfer();
|
||||
|
||||
expect(transfer.signature.toHex()).toEqual(
|
||||
'0x62bfcd07a9f50ba32ed9e2c41ca11267ac62a24c95949e25efdccc4989d48573f84754dbbaa1d0937ceb888ad8a2cf71daced1545a839d9d6cceac33a5771401'
|
||||
);
|
||||
expect(api.tx(transfer.toHex()).signature.toHex()).toEqual(TRANSFER_SIG);
|
||||
expect(api.tx(transfer).signature.toHex()).toEqual(TRANSFER_SIG);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -163,14 +163,14 @@ export default class ApiRx extends ApiBase<'rxjs'> {
|
||||
constructor (options?: ApiOptions) {
|
||||
super(options, 'rxjs', decorateMethod);
|
||||
|
||||
this.#isReadyRx = from(
|
||||
this.#isReadyRx = from<Promise<ApiRx>>(
|
||||
// You can create an observable from an event, however my mind groks this form better
|
||||
new Promise((resolve): void => {
|
||||
super.on('ready', (): void => {
|
||||
resolve(this);
|
||||
});
|
||||
})
|
||||
) as Observable<ApiRx>;
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -3,14 +3,13 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Address, Call, ExtrinsicEra, ExtrinsicStatus, Hash, Header, Index, RuntimeDispatchInfo } from '@polkadot/types/interfaces';
|
||||
import { Address, Call, Extrinsic, ExtrinsicEra, ExtrinsicStatus, Hash, Header, Index, RuntimeDispatchInfo } from '@polkadot/types/interfaces';
|
||||
import { Callback, Codec, Constructor, IKeyringPair, Registry, SignatureOptions, ISubmittableResult } from '@polkadot/types/types';
|
||||
import { ApiInterfaceRx, ApiTypes, SignerResult } from '../types';
|
||||
import { AddressOrPair, SignerOptions, SubmittableExtrinsic, SubmittablePaymentResult, SubmittableResultResult, SubmittableResultSubscription, SubmittableThis } from './types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { first, map, mapTo, mergeMap, switchMap, tap } from 'rxjs/operators';
|
||||
import { ClassOf } from '@polkadot/types';
|
||||
import { assert, isBn, isFunction, isNumber, isUndefined } from '@polkadot/util';
|
||||
|
||||
import { filterEvents, isKeyringPair } from '../util';
|
||||
@@ -32,12 +31,12 @@ const DEFAULT_MORTAL_LENGTH = 5 * ONE_MINUTE;
|
||||
|
||||
export default function createClass <ApiType extends ApiTypes> ({ api, apiType, decorateMethod }: SubmittableOptions<ApiType>): Constructor<SubmittableExtrinsic<ApiType>> {
|
||||
// an instance of the base extrinsic for us to extend
|
||||
const Extrinsic = ClassOf(api.registry, 'Extrinsic');
|
||||
const ExtrinsicBase = api.registry.createClass('Extrinsic');
|
||||
|
||||
return class Submittable extends Extrinsic implements SubmittableExtrinsic<ApiType> {
|
||||
return class Submittable extends ExtrinsicBase implements SubmittableExtrinsic<ApiType> {
|
||||
readonly #ignoreStatusCb: boolean;
|
||||
|
||||
constructor (registry: Registry, extrinsic: Call | Uint8Array | string) {
|
||||
constructor (registry: Registry, extrinsic: Call | Extrinsic | Uint8Array | string) {
|
||||
super(registry, extrinsic, { version: api.extrinsicType });
|
||||
|
||||
this.#ignoreStatusCb = apiType === 'rxjs';
|
||||
|
||||
@@ -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 { Call } from '@polkadot/types/interfaces';
|
||||
import { Call, Extrinsic } from '@polkadot/types/interfaces';
|
||||
import { Constructor } from '@polkadot/types/types';
|
||||
import { ApiInterfaceRx, ApiTypes } from '../types';
|
||||
import { SubmittableExtrinsic } from './types';
|
||||
@@ -15,7 +15,7 @@ type Creator<ApiType extends ApiTypes> = (extrinsic: Call | Uint8Array | string)
|
||||
let Submittable: Constructor<SubmittableExtrinsic<any>>;
|
||||
|
||||
export default function createSubmittable<ApiType extends ApiTypes> (apiType: ApiTypes, api: ApiInterfaceRx, decorateMethod: ApiBase<ApiType>['decorateMethod']): Creator<ApiType> {
|
||||
return (extrinsic: Call | Uint8Array | string): SubmittableExtrinsic<ApiType> => {
|
||||
return (extrinsic: Call | Extrinsic | Uint8Array | string): SubmittableExtrinsic<ApiType> => {
|
||||
// This is not great, but basically what we do here is to only require the
|
||||
// class right at the point it is actually needed - delaying initialization
|
||||
if (!Submittable) {
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { AccountId, Address, ExtrinsicStatus, EventRecord, Hash, RuntimeDispatchInfo } from '@polkadot/types/interfaces';
|
||||
import { AnyNumber, AnyU8a, Callback, Codec, IExtrinsic, IExtrinsicEra, IKeyringPair, SignatureOptions, Signer, ISubmittableResult } from '@polkadot/types/types';
|
||||
import { AccountId, Address, Extrinsic, ExtrinsicStatus, EventRecord, Hash, RuntimeDispatchInfo } from '@polkadot/types/interfaces';
|
||||
import { AnyNumber, AnyU8a, Callback, Codec, IExtrinsicEra, IKeyringPair, SignatureOptions, Signer, ISubmittableResult } from '@polkadot/types/types';
|
||||
import { ApiTypes } from '../types';
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
@@ -43,7 +43,7 @@ export interface SignerOptions {
|
||||
|
||||
export type AddressOrPair = IKeyringPair | string | AccountId | Address;
|
||||
|
||||
export interface SubmittableExtrinsic<ApiType extends ApiTypes> extends IExtrinsic {
|
||||
export interface SubmittableExtrinsic<ApiType extends ApiTypes> extends Extrinsic {
|
||||
paymentInfo (account: AddressOrPair, options?: Partial<SignerOptions>): SubmittablePaymentResult<ApiType>;
|
||||
|
||||
send(): SubmittableResultResult<ApiType>;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user