Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ca79f2f70 | ||
|
|
8fb64f77cd | ||
|
|
d1f86ce78e | ||
|
|
64ff226535 | ||
|
|
e762746ff0 | ||
|
|
ce5c8f7443 | ||
|
|
fc4cbb608c | ||
|
|
7ac3043f83 | ||
|
|
44b56fb0cb | ||
|
|
758ce567e5 | ||
|
|
cb5308b476 | ||
|
|
a9211690be | ||
|
|
a7db14a261 | ||
|
|
3a1f284fa8 | ||
|
|
a0b6c42629 | ||
|
|
f77ae4d99f | ||
|
|
5fa9af8fd3 | ||
|
|
1ff029dc11 | ||
|
|
4c8c9fbb07 | ||
|
|
7057cf365b | ||
|
|
d1bc48e936 | ||
|
|
2dee50f019 | ||
|
|
fa76378702 | ||
|
|
e855da1f13 | ||
|
|
adffde368c | ||
|
|
5278138cc3 | ||
|
|
98249a282e | ||
|
|
b7eeb992cd | ||
|
|
01daf32646 | ||
|
|
51a866fd35 | ||
|
|
53401e29ea | ||
|
|
774f41e6db | ||
|
|
1ca3b295a4 | ||
|
|
82828d8e09 | ||
|
|
131055c1d5 | ||
|
|
bd2e690261 | ||
|
|
1a2ca8ea38 | ||
|
|
0c98593aee | ||
|
|
416e2fbc96 | ||
|
|
c04fb9073e | ||
|
|
4f85ceb2c3 | ||
|
|
9196ce85a0 | ||
|
|
26734bf8bf | ||
|
|
53959d482d | ||
|
|
0a0f110c42 | ||
|
|
47f1350652 | ||
|
|
3c3b7290c2 | ||
|
|
006c686c18 | ||
|
|
44d4a07005 | ||
|
|
6e61be960c | ||
|
|
bd57359dc5 | ||
|
|
10bc6b4060 | ||
|
|
9e681c0666 | ||
|
|
e969382fd0 | ||
|
|
1949a13810 | ||
|
|
362262c4e1 | ||
|
|
ddd5eab7f5 | ||
|
|
1da6193f34 | ||
|
|
c4e553ad80 | ||
|
|
0b83a61600 | ||
|
|
382f7d75c8 | ||
|
|
88e4518f64 | ||
|
|
b1a657d68a | ||
|
|
067f17b28b | ||
|
|
99073e2a88 | ||
|
|
f9a42e47e7 | ||
|
|
b80d72edbd | ||
|
|
1f7b9f7f3a | ||
|
|
843efb2146 | ||
|
|
3619fabe5f | ||
|
|
bf598e392e | ||
|
|
f026137545 | ||
|
|
2264f53a43 | ||
|
|
8ba4029633 | ||
|
|
05cb2cef5a | ||
|
|
3a70594594 | ||
|
|
019cb58dd1 | ||
|
|
d487490ca0 | ||
|
|
b9fad61da0 | ||
|
|
77bf33b4e4 | ||
|
|
7ed7c9d3a8 | ||
|
|
0d2896630d | ||
|
|
74dbff32df | ||
|
|
4653cc0d84 | ||
|
|
50e115f6a1 | ||
|
|
8a5a86e8b3 | ||
|
|
48ef5af93f | ||
|
|
e5c20be666 | ||
|
|
6bf0d5eea9 | ||
|
|
21c57b60a1 | ||
|
|
b1dff22954 | ||
|
|
a3d0cb0999 | ||
|
|
bf946c20db | ||
|
|
664d2c8ab6 | ||
|
|
01a4d6b4a9 | ||
|
|
18454083db | ||
|
|
191abe4e08 | ||
|
|
97fbb4732d | ||
|
|
01f3666cc7 | ||
|
|
468fcdccaa | ||
|
|
c8dd26b0da |
+1
-1
@@ -1 +1 @@
|
|||||||
13
|
16
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ tmp/
|
|||||||
.env.production.local
|
.env.production.local
|
||||||
.npmrc
|
.npmrc
|
||||||
.rpt2_cache
|
.rpt2_cache
|
||||||
|
.vscode/
|
||||||
cc-test-reporter
|
cc-test-reporter
|
||||||
lerna-debug.log*
|
lerna-debug.log*
|
||||||
npm-debug.log*
|
npm-debug.log*
|
||||||
|
|||||||
+22
-2
@@ -1,8 +1,28 @@
|
|||||||
|
# 0.100.1
|
||||||
|
|
||||||
|
- **Important** This will the the last API version with Substrate 1.x support. Although you will still be able to use subsequent versions with older chans, dependent libraries such as sr25519 may not be compatible.
|
||||||
|
- Add support for the Substrate identity module
|
||||||
|
- Remove the `codec/Data` type, to remove a conflict with Substrate. This type is now named `Raw`
|
||||||
|
- Fix for linked maps using `Option`
|
||||||
|
- Add support for `BTreeSet` (Thanks to https://github.com/satellitex)
|
||||||
|
- Add support for Metadata v10
|
||||||
|
- Add support for latest Polkadot/Substrate types
|
||||||
|
- Add `paymentInfo` to submittables to calculate fees
|
||||||
|
|
||||||
|
# 0.99.1
|
||||||
|
|
||||||
|
- **Breaking change** The `Data` and `U8a` type has been renamed and just replaced with the `Raw` type
|
||||||
|
- **Breaking change** The `api.derive.staking.info` has been split into 2 - `staking.query` for non-balance related information (more effective) and `staking.account` that enhances query for all the information previously found `.info`
|
||||||
|
- Cleanup `DoubleMap` hashing to always hash over the full value (in the case of `Vec<T>`, this includes the length)
|
||||||
|
- Update democracy derives to take care of nextTally and lowestU*nbaked
|
||||||
|
- Add additional derives for both council & treasury
|
||||||
|
- Alignment with latest Polkadot/Substrate master branch types
|
||||||
|
|
||||||
# 0.98.1
|
# 0.98.1
|
||||||
|
|
||||||
- Make the TypeScript generation script mor re-usable (Thanks to @xlc)
|
- Make the TypeScript generation script mor re-usable (Thanks to https://github.com/xlc)
|
||||||
- Add `.entries()` for all map-types, returning storage keys and values
|
- Add `.entries()` for all map-types, returning storage keys and values
|
||||||
- Add `.signAsync` to submittable extrinsics (Thanks to @c410-f3r)
|
- Add `.signAsync` to submittable extrinsics (Thanks to https://github.com/c410-f3r)
|
||||||
- Cleanup circular references between internal dependencies
|
- Cleanup circular references between internal dependencies
|
||||||
- Support for new Substrate democracy with preimages in derive
|
- Support for new Substrate democracy with preimages in derive
|
||||||
- Alignment of types with Substrate/Polkadot master branches
|
- Alignment of types with Substrate/Polkadot master branches
|
||||||
|
|||||||
+1
-1
@@ -9,5 +9,5 @@
|
|||||||
"packages": [
|
"packages": [
|
||||||
"packages/*"
|
"packages/*"
|
||||||
],
|
],
|
||||||
"version": "0.98.1"
|
"version": "0.100.1"
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-7
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"version": "0.98.1",
|
"version": "0.100.1",
|
||||||
"private": true,
|
"private": true,
|
||||||
"engines": {
|
"engines": {
|
||||||
"yarn": "^1.10.1"
|
"yarn": "^1.10.1"
|
||||||
@@ -9,7 +9,7 @@
|
|||||||
],
|
],
|
||||||
"resolutions": {
|
"resolutions": {
|
||||||
"babel-core": "^7.0.0-bridge.0",
|
"babel-core": "^7.0.0-bridge.0",
|
||||||
"typescript": "^3.7.2"
|
"typescript": "^3.7.4"
|
||||||
},
|
},
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "yarn build:interfaces && polkadot-dev-build-ts",
|
"build": "yarn build:interfaces && polkadot-dev-build-ts",
|
||||||
@@ -29,10 +29,10 @@
|
|||||||
"test:watch": "jest --coverage --watch"
|
"test:watch": "jest --coverage --watch"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.7.4",
|
"@babel/core": "^7.7.7",
|
||||||
"@babel/register": "^7.7.4",
|
"@babel/register": "^7.7.7",
|
||||||
"@babel/runtime": "^7.7.4",
|
"@babel/runtime": "^7.7.7",
|
||||||
"@polkadot/dev": "^0.32.0-beta.15",
|
"@polkadot/dev": "^0.32.14",
|
||||||
"@polkadot/ts": "^0.1.86"
|
"@polkadot/ts": "^0.1.90"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/api-contract",
|
"name": "@polkadot/api-contract",
|
||||||
"version": "0.98.1",
|
"version": "0.100.1",
|
||||||
"description": "Interfaces for interacting with contracts and contract ABIs",
|
"description": "Interfaces for interacting with contracts and contract ABIs",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -26,7 +26,7 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
|
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.7.4",
|
"@babel/runtime": "^7.7.7",
|
||||||
"@polkadot/types": "^0.98.1"
|
"@polkadot/types": "^0.100.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/types authors & contributors
|
// Copyright 2017-2020 @polkadot/types authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ export default class Contract<ApiType extends ApiTypes> extends BaseWithTxAndRpc
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
send: this.decorateMethod(
|
send: this.decorateMethod(
|
||||||
as === 'rpc'
|
as === 'rpc' && this.hasRpcContractsCall
|
||||||
? (account: IKeyringPair | string | AccountId | Address): ContractCallResult<'rpc'> => {
|
? (account: IKeyringPair | string | AccountId | Address): ContractCallResult<'rpc'> => {
|
||||||
return this.rpcContractsCall(
|
return this.rpcContractsCall(
|
||||||
createType(this.registry, 'ContractCallRequest', {
|
createType(this.registry, 'ContractCallRequest', {
|
||||||
@@ -75,7 +75,7 @@ export default class Contract<ApiType extends ApiTypes> extends BaseWithTxAndRpc
|
|||||||
|
|
||||||
output = message.returnType
|
output = message.returnType
|
||||||
? formatData(this.registry, data, message.returnType)
|
? formatData(this.registry, data, message.returnType)
|
||||||
: createType(this.registry, 'Data', data);
|
: createType(this.registry, 'Raw', data);
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api authors & contributors
|
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api authors & contributors
|
// Copyright 2017-2020 @polkadot/api authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
@@ -7,7 +7,7 @@ import { ApiObject, ContractABIMessage, ContractABIPre, ContractBase, ContractMe
|
|||||||
import { RpcInterface } from '@polkadot/rpc-core/jsonrpc.types';
|
import { RpcInterface } from '@polkadot/rpc-core/jsonrpc.types';
|
||||||
import { Registry } from '@polkadot/types/types';
|
import { Registry } from '@polkadot/types/types';
|
||||||
|
|
||||||
import { assert, stringCamelCase } from '@polkadot/util';
|
import { assert, isFunction, stringCamelCase } from '@polkadot/util';
|
||||||
import Abi from '../Abi';
|
import Abi from '../Abi';
|
||||||
|
|
||||||
export abstract class Base<ApiType extends ApiTypes> implements ContractBase<ApiType> {
|
export abstract class Base<ApiType extends ApiTypes> implements ContractBase<ApiType> {
|
||||||
@@ -66,13 +66,13 @@ export abstract class BaseWithTx<ApiType extends ApiTypes> extends Base<ApiType>
|
|||||||
}
|
}
|
||||||
|
|
||||||
export abstract class BaseWithTxAndRpcCall<ApiType extends ApiTypes> extends BaseWithTx<ApiType> {
|
export abstract class BaseWithTxAndRpcCall<ApiType extends ApiTypes> extends BaseWithTx<ApiType> {
|
||||||
|
public get hasRpcContractsCall (): boolean {
|
||||||
|
return isFunction(this.api.rx.rpc.contracts?.call);
|
||||||
|
}
|
||||||
|
|
||||||
protected get rpcContractsCall (): DecoratedRpc<'rxjs', RpcInterface>['contracts']['call'] {
|
protected get rpcContractsCall (): DecoratedRpc<'rxjs', RpcInterface>['contracts']['call'] {
|
||||||
|
assert(this.hasRpcContractsCall, 'You need to connect to a node with the contracts.call RPC method.');
|
||||||
|
|
||||||
return this.api.rx.rpc.contracts.call;
|
return this.api.rx.rpc.contracts.call;
|
||||||
}
|
}
|
||||||
|
|
||||||
constructor (api: ApiObject<ApiType>, abi: ContractABIPre | Abi, decorateMethod: DecorateMethod<ApiType>) {
|
|
||||||
super(api, abi, decorateMethod);
|
|
||||||
|
|
||||||
assert(this.api.rx.rpc.contracts && this.api.rx.tx.contracts.call, 'You need to connect to a node with the contracts module, the metadata does not enable api.rpc.contracts.call on this instance');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-contract authors & contributors
|
// Copyright 2017-2020 @polkadot/api-contract authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,20 @@
|
|||||||
// Copyright 2017-2019 @polkadot/rpc-core authors & contributors
|
// Copyright 2017-2020 @polkadot/rpc-core authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
import { Codec, Registry, TypeDefInfo, TypeDef } from '@polkadot/types/types';
|
import { Codec, Registry, TypeDefInfo, TypeDef } from '@polkadot/types/types';
|
||||||
|
|
||||||
import { Data, Option, createClass } from '@polkadot/types';
|
import { Option, Raw, createClass } from '@polkadot/types';
|
||||||
import { createTypeUnsafe } from '@polkadot/types/codec';
|
import { createTypeUnsafe } from '@polkadot/types/codec';
|
||||||
|
|
||||||
export function formatData (registry: Registry, data: Data, { info, type }: TypeDef): Codec {
|
export function formatData (registry: Registry, data: Raw, { info, type }: TypeDef): Codec {
|
||||||
const u8a = data.toU8a();
|
|
||||||
|
|
||||||
if (info === TypeDefInfo.Option) {
|
if (info === TypeDefInfo.Option) {
|
||||||
return new Option(
|
return new Option(
|
||||||
registry,
|
registry,
|
||||||
createClass(registry, type),
|
createClass(registry, type),
|
||||||
createTypeUnsafe(registry, type, [u8a], true)
|
createTypeUnsafe(registry, type, [data], true)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return createTypeUnsafe(registry, type, [u8a], true);
|
return createTypeUnsafe(registry, type, [data], true);
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,49 +1,49 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"info": 7,
|
"info": 8,
|
||||||
"type": "{\"value\": {\"cell\": {\"cell\": ([u8;32])}}}",
|
"type": "{\"value\": {\"cell\": {\"cell\": ([u8;32])}}}",
|
||||||
"name": "Flipper",
|
"name": "Flipper",
|
||||||
"namespace": "flipper::normal",
|
"namespace": "flipper::normal",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 7,
|
"info": 8,
|
||||||
"type": "{\"cell\": {\"cell\": ([u8;32])}}",
|
"type": "{\"cell\": {\"cell\": ([u8;32])}}",
|
||||||
"name": "value",
|
"name": "value",
|
||||||
"namespace": "ink_core::storage::value",
|
"namespace": "ink_core::storage::value",
|
||||||
"params": [
|
"params": [
|
||||||
{
|
{
|
||||||
"info": 5,
|
"info": 6,
|
||||||
"type": "bool"
|
"type": "bool"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 7,
|
"info": 8,
|
||||||
"type": "{\"cell\": ([u8;32])}",
|
"type": "{\"cell\": ([u8;32])}",
|
||||||
"name": "cell",
|
"name": "cell",
|
||||||
"namespace": "ink_core::storage::cell::sync_cell",
|
"namespace": "ink_core::storage::cell::sync_cell",
|
||||||
"params": [
|
"params": [
|
||||||
{
|
{
|
||||||
"info": 5,
|
"info": 6,
|
||||||
"type": "bool"
|
"type": "bool"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 8,
|
"info": 9,
|
||||||
"type": "([u8;32])",
|
"type": "([u8;32])",
|
||||||
"name": "cell",
|
"name": "cell",
|
||||||
"namespace": "ink_core::storage::key",
|
"namespace": "ink_core::storage::key",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 10,
|
"info": 11,
|
||||||
"type": "[u8;32]",
|
"type": "[u8;32]",
|
||||||
"ext": {
|
"ext": {
|
||||||
"length": 32,
|
"length": 32,
|
||||||
"type": ""
|
"type": ""
|
||||||
},
|
},
|
||||||
"sub": {
|
"sub": {
|
||||||
"info": 5,
|
"info": 6,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
},
|
},
|
||||||
"index": 0
|
"index": 0
|
||||||
@@ -57,44 +57,44 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"info": 7,
|
"info": 8,
|
||||||
"type": "{\"cell\": {\"cell\": ([u8;32])}}",
|
"type": "{\"cell\": {\"cell\": ([u8;32])}}",
|
||||||
"name": "Value",
|
"name": "Value",
|
||||||
"namespace": "ink_core::storage::value",
|
"namespace": "ink_core::storage::value",
|
||||||
"params": [
|
"params": [
|
||||||
{
|
{
|
||||||
"info": 5,
|
"info": 6,
|
||||||
"type": "bool"
|
"type": "bool"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 7,
|
"info": 8,
|
||||||
"type": "{\"cell\": ([u8;32])}",
|
"type": "{\"cell\": ([u8;32])}",
|
||||||
"name": "cell",
|
"name": "cell",
|
||||||
"namespace": "ink_core::storage::cell::sync_cell",
|
"namespace": "ink_core::storage::cell::sync_cell",
|
||||||
"params": [
|
"params": [
|
||||||
{
|
{
|
||||||
"info": 5,
|
"info": 6,
|
||||||
"type": "bool"
|
"type": "bool"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 8,
|
"info": 9,
|
||||||
"type": "([u8;32])",
|
"type": "([u8;32])",
|
||||||
"name": "cell",
|
"name": "cell",
|
||||||
"namespace": "ink_core::storage::key",
|
"namespace": "ink_core::storage::key",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 10,
|
"info": 11,
|
||||||
"type": "[u8;32]",
|
"type": "[u8;32]",
|
||||||
"ext": {
|
"ext": {
|
||||||
"length": 32,
|
"length": 32,
|
||||||
"type": ""
|
"type": ""
|
||||||
},
|
},
|
||||||
"sub": {
|
"sub": {
|
||||||
"info": 5,
|
"info": 6,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
},
|
},
|
||||||
"index": 0
|
"index": 0
|
||||||
@@ -106,36 +106,36 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"info": 5,
|
"info": 6,
|
||||||
"type": "bool"
|
"type": "bool"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"info": 7,
|
"info": 8,
|
||||||
"type": "{\"cell\": ([u8;32])}",
|
"type": "{\"cell\": ([u8;32])}",
|
||||||
"name": "SyncCell",
|
"name": "SyncCell",
|
||||||
"namespace": "ink_core::storage::cell::sync_cell",
|
"namespace": "ink_core::storage::cell::sync_cell",
|
||||||
"params": [
|
"params": [
|
||||||
{
|
{
|
||||||
"info": 5,
|
"info": 6,
|
||||||
"type": "bool"
|
"type": "bool"
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 8,
|
"info": 9,
|
||||||
"type": "([u8;32])",
|
"type": "([u8;32])",
|
||||||
"name": "cell",
|
"name": "cell",
|
||||||
"namespace": "ink_core::storage::key",
|
"namespace": "ink_core::storage::key",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 10,
|
"info": 11,
|
||||||
"type": "[u8;32]",
|
"type": "[u8;32]",
|
||||||
"ext": {
|
"ext": {
|
||||||
"length": 32,
|
"length": 32,
|
||||||
"type": ""
|
"type": ""
|
||||||
},
|
},
|
||||||
"sub": {
|
"sub": {
|
||||||
"info": 5,
|
"info": 6,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
},
|
},
|
||||||
"index": 0
|
"index": 0
|
||||||
@@ -145,20 +145,20 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"info": 8,
|
"info": 9,
|
||||||
"type": "([u8;32])",
|
"type": "([u8;32])",
|
||||||
"name": "Key",
|
"name": "Key",
|
||||||
"namespace": "ink_core::storage::key",
|
"namespace": "ink_core::storage::key",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 10,
|
"info": 11,
|
||||||
"type": "[u8;32]",
|
"type": "[u8;32]",
|
||||||
"ext": {
|
"ext": {
|
||||||
"length": 32,
|
"length": 32,
|
||||||
"type": ""
|
"type": ""
|
||||||
},
|
},
|
||||||
"sub": {
|
"sub": {
|
||||||
"info": 5,
|
"info": 6,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
},
|
},
|
||||||
"index": 0
|
"index": 0
|
||||||
@@ -166,19 +166,19 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"info": 10,
|
"info": 11,
|
||||||
"type": "[u8;32]",
|
"type": "[u8;32]",
|
||||||
"ext": {
|
"ext": {
|
||||||
"length": 32,
|
"length": 32,
|
||||||
"type": ""
|
"type": ""
|
||||||
},
|
},
|
||||||
"sub": {
|
"sub": {
|
||||||
"info": 5,
|
"info": 6,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"info": 5,
|
"info": 6,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -1,29 +1,29 @@
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"info": 9,
|
"info": 10,
|
||||||
"type": "{ \"value\": \"{ \"cell\": \"{ \"cell\": \"([u8;32])\"} }<u32>\"} }<u32>\"} }",
|
"type": "{ \"value\": \"{ \"cell\": \"{ \"cell\": \"([u8;32])\"} }<u32>\"} }<u32>\"} }",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 9,
|
"info": 10,
|
||||||
"type": "{ \"cell\": \"{ \"cell\": \"([u8;32])\"} }<u32>\"} }",
|
"type": "{ \"cell\": \"{ \"cell\": \"([u8;32])\"} }<u32>\"} }",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 9,
|
"info": 10,
|
||||||
"type": "{ \"cell\": \"([u8;32])\"} }",
|
"type": "{ \"cell\": \"([u8;32])\"} }",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 10,
|
"info": 11,
|
||||||
"type": "([u8;32])",
|
"type": "([u8;32])",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 12,
|
"info": 13,
|
||||||
"type": "[u8;32]",
|
"type": "[u8;32]",
|
||||||
"ext": {
|
"ext": {
|
||||||
"length": 32,
|
"length": 32,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
},
|
},
|
||||||
"sub": {
|
"sub": {
|
||||||
"info": 6,
|
"info": 7,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
},
|
},
|
||||||
"index": 0
|
"index": 0
|
||||||
@@ -37,7 +37,7 @@
|
|||||||
"namespace": "ink_core::storage::cell::sync_cell",
|
"namespace": "ink_core::storage::cell::sync_cell",
|
||||||
"params": [
|
"params": [
|
||||||
{
|
{
|
||||||
"info": 6,
|
"info": 7,
|
||||||
"type": "u32"
|
"type": "u32"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -47,7 +47,7 @@
|
|||||||
"namespace": "ink_core::storage::value",
|
"namespace": "ink_core::storage::value",
|
||||||
"params": [
|
"params": [
|
||||||
{
|
{
|
||||||
"info": 6,
|
"info": 7,
|
||||||
"type": "u32"
|
"type": "u32"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -57,26 +57,26 @@
|
|||||||
"namespace": "incrementer::normal"
|
"namespace": "incrementer::normal"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"info": 9,
|
"info": 10,
|
||||||
"type": "{ \"cell\": \"{ \"cell\": \"([u8;32])\"} }<u32>\"} }",
|
"type": "{ \"cell\": \"{ \"cell\": \"([u8;32])\"} }<u32>\"} }",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 9,
|
"info": 10,
|
||||||
"type": "{ \"cell\": \"([u8;32])\"} }",
|
"type": "{ \"cell\": \"([u8;32])\"} }",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 10,
|
"info": 11,
|
||||||
"type": "([u8;32])",
|
"type": "([u8;32])",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 12,
|
"info": 13,
|
||||||
"type": "[u8;32]",
|
"type": "[u8;32]",
|
||||||
"ext": {
|
"ext": {
|
||||||
"length": 32,
|
"length": 32,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
},
|
},
|
||||||
"sub": {
|
"sub": {
|
||||||
"info": 6,
|
"info": 7,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
},
|
},
|
||||||
"index": 0
|
"index": 0
|
||||||
@@ -90,7 +90,7 @@
|
|||||||
"namespace": "ink_core::storage::cell::sync_cell",
|
"namespace": "ink_core::storage::cell::sync_cell",
|
||||||
"params": [
|
"params": [
|
||||||
{
|
{
|
||||||
"info": 6,
|
"info": 7,
|
||||||
"type": "u32"
|
"type": "u32"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@@ -100,32 +100,32 @@
|
|||||||
"namespace": "ink_core::storage::value",
|
"namespace": "ink_core::storage::value",
|
||||||
"params": [
|
"params": [
|
||||||
{
|
{
|
||||||
"info": 6,
|
"info": 7,
|
||||||
"type": "u32"
|
"type": "u32"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"info": 6,
|
"info": 7,
|
||||||
"type": "u32"
|
"type": "u32"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"info": 9,
|
"info": 10,
|
||||||
"type": "{ \"cell\": \"([u8;32])\"} }",
|
"type": "{ \"cell\": \"([u8;32])\"} }",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 10,
|
"info": 11,
|
||||||
"type": "([u8;32])",
|
"type": "([u8;32])",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 12,
|
"info": 13,
|
||||||
"type": "[u8;32]",
|
"type": "[u8;32]",
|
||||||
"ext": {
|
"ext": {
|
||||||
"length": 32,
|
"length": 32,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
},
|
},
|
||||||
"sub": {
|
"sub": {
|
||||||
"info": 6,
|
"info": 7,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
},
|
},
|
||||||
"index": 0
|
"index": 0
|
||||||
@@ -139,24 +139,24 @@
|
|||||||
"namespace": "ink_core::storage::cell::sync_cell",
|
"namespace": "ink_core::storage::cell::sync_cell",
|
||||||
"params": [
|
"params": [
|
||||||
{
|
{
|
||||||
"info": 6,
|
"info": 7,
|
||||||
"type": "u32"
|
"type": "u32"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"info": 10,
|
"info": 11,
|
||||||
"type": "([u8;32])",
|
"type": "([u8;32])",
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"info": 12,
|
"info": 13,
|
||||||
"type": "[u8;32]",
|
"type": "[u8;32]",
|
||||||
"ext": {
|
"ext": {
|
||||||
"length": 32,
|
"length": 32,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
},
|
},
|
||||||
"sub": {
|
"sub": {
|
||||||
"info": 6,
|
"info": 7,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
},
|
},
|
||||||
"index": 0
|
"index": 0
|
||||||
@@ -166,23 +166,23 @@
|
|||||||
"namespace": "ink_core::storage::key"
|
"namespace": "ink_core::storage::key"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"info": 12,
|
"info": 13,
|
||||||
"type": "[u8;32]",
|
"type": "[u8;32]",
|
||||||
"ext": {
|
"ext": {
|
||||||
"length": 32,
|
"length": 32,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
},
|
},
|
||||||
"sub": {
|
"sub": {
|
||||||
"info": 6,
|
"info": 7,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"info": 6,
|
"info": 7,
|
||||||
"type": "u8"
|
"type": "u8"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"info": 6,
|
"info": 7,
|
||||||
"type": "bool"
|
"type": "bool"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "@polkadot/api-derive",
|
"name": "@polkadot/api-derive",
|
||||||
"version": "0.98.1",
|
"version": "0.100.1",
|
||||||
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
|
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -27,11 +27,11 @@
|
|||||||
},
|
},
|
||||||
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
|
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@babel/runtime": "^7.7.4",
|
"@babel/runtime": "^7.7.7",
|
||||||
"@polkadot/api": "^0.98.1",
|
"@polkadot/api": "^0.100.1",
|
||||||
"@polkadot/types": "^0.98.1"
|
"@polkadot/types": "^0.100.1"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@polkadot/keyring": "^1.7.1"
|
"@polkadot/keyring": "^1.8.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,22 +1,30 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { AccountId, AccountIndex, Address, Balance } from '@polkadot/types/interfaces';
|
import { AccountId, AccountIndex, Address, Balance, Registration } from '@polkadot/types/interfaces';
|
||||||
import { ITuple } from '@polkadot/types/types';
|
import { ITuple } from '@polkadot/types/types';
|
||||||
import { DeriveAccountInfo } from '../types';
|
import { DeriveAccountInfo, DeriveAccountRegistration } from '../types';
|
||||||
|
|
||||||
import { Observable, combineLatest, of } from 'rxjs';
|
import { Observable, combineLatest, of } from 'rxjs';
|
||||||
import { map, switchMap } from 'rxjs/operators';
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
import { Bytes, Option, u32 } from '@polkadot/types';
|
import { Bytes, Data, Option, u32 } from '@polkadot/types';
|
||||||
import { u8aToString } from '@polkadot/util';
|
import { u8aToString } from '@polkadot/util';
|
||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
|
function dataAsString (data: Data): string | undefined {
|
||||||
|
return data.isRaw
|
||||||
|
? u8aToString(data.asRaw.toU8a(true))
|
||||||
|
: data.isSha256
|
||||||
|
? data.asSha256.toHex()
|
||||||
|
: undefined;
|
||||||
|
}
|
||||||
|
|
||||||
function retrieveNick (api: ApiInterfaceRx, accountId?: AccountId): Observable<string | undefined> {
|
function retrieveNick (api: ApiInterfaceRx, accountId?: AccountId): Observable<string | undefined> {
|
||||||
return ((
|
return ((
|
||||||
accountId && api.query.nicks
|
accountId && api.query.nicks?.nameOf
|
||||||
? api.query.nicks.nameOf<Option<ITuple<[Bytes, Balance]>>>(accountId)
|
? api.query.nicks.nameOf<Option<ITuple<[Bytes, Balance]>>>(accountId)
|
||||||
: of(undefined)
|
: of(undefined)
|
||||||
) as Observable<Option<ITuple<[Bytes, Balance]>> | undefined>).pipe(
|
) as Observable<Option<ITuple<[Bytes, Balance]>> | undefined>).pipe(
|
||||||
@@ -28,6 +36,69 @@ function retrieveNick (api: ApiInterfaceRx, accountId?: AccountId): Observable<s
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function extractIdentity (identityOfOpt?: Option<Registration>, superOf?: [AccountId, Data]): DeriveAccountRegistration {
|
||||||
|
if (!identityOfOpt?.isSome) {
|
||||||
|
return { judgements: [] };
|
||||||
|
}
|
||||||
|
|
||||||
|
const { info, judgements } = identityOfOpt.unwrap();
|
||||||
|
const topDisplay = dataAsString(info.display);
|
||||||
|
|
||||||
|
return {
|
||||||
|
display: superOf
|
||||||
|
? dataAsString(superOf[1]) || topDisplay
|
||||||
|
: topDisplay,
|
||||||
|
displayParent: superOf
|
||||||
|
? topDisplay
|
||||||
|
: undefined,
|
||||||
|
email: dataAsString(info.email),
|
||||||
|
image: dataAsString(info.image),
|
||||||
|
legal: dataAsString(info.legal),
|
||||||
|
parent: superOf
|
||||||
|
? superOf[0]
|
||||||
|
: undefined,
|
||||||
|
pgp: info.pgpFingerprint.isSome
|
||||||
|
? info.pgpFingerprint.unwrap().toHex()
|
||||||
|
: undefined,
|
||||||
|
riot: dataAsString(info.riot),
|
||||||
|
twitter: dataAsString(info.twitter),
|
||||||
|
web: dataAsString(info.web),
|
||||||
|
judgements
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function retrieveIdentity (api: ApiInterfaceRx, accountId?: AccountId): Observable<DeriveAccountRegistration> {
|
||||||
|
return ((
|
||||||
|
accountId && api.query.identity?.identityOf
|
||||||
|
? api.queryMulti([
|
||||||
|
[api.query.identity.identityOf, accountId],
|
||||||
|
[api.query.identity.superOf, accountId]
|
||||||
|
])
|
||||||
|
: of([undefined, undefined])
|
||||||
|
) as Observable<[Option<Registration> | undefined, Option<ITuple<[AccountId, Data]>> | undefined]>).pipe(
|
||||||
|
switchMap(([identityOfOpt, superOfOpt]): Observable<[Option<Registration> | undefined, [AccountId, Data] | undefined]> => {
|
||||||
|
if (identityOfOpt?.isSome) {
|
||||||
|
// this identity has something set
|
||||||
|
return of([identityOfOpt, undefined]);
|
||||||
|
} else if (superOfOpt?.isSome) {
|
||||||
|
const superOf = superOfOpt.unwrap();
|
||||||
|
|
||||||
|
// we have a super
|
||||||
|
return combineLatest([
|
||||||
|
api.query.identity.identityOf<Option<Registration>>(superOf[0]),
|
||||||
|
of(superOf)
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// nothing of value returned
|
||||||
|
return of([undefined, undefined]);
|
||||||
|
}),
|
||||||
|
map(([identityOfOpt, superOf]): DeriveAccountRegistration =>
|
||||||
|
extractIdentity(identityOfOpt, superOf)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @name info
|
* @name info
|
||||||
* @description Returns aux. info with regards to an account, current that includes the accountId, accountIndex and nickname
|
* @description Returns aux. info with regards to an account, current that includes the accountId, accountIndex and nickname
|
||||||
@@ -35,14 +106,15 @@ function retrieveNick (api: ApiInterfaceRx, accountId?: AccountId): Observable<s
|
|||||||
export function info (api: ApiInterfaceRx): (address?: AccountIndex | AccountId | Address | string | null) => Observable<DeriveAccountInfo> {
|
export function info (api: ApiInterfaceRx): (address?: AccountIndex | AccountId | Address | string | null) => Observable<DeriveAccountInfo> {
|
||||||
return memo((address?: AccountIndex | AccountId | Address | string | null): Observable<DeriveAccountInfo> =>
|
return memo((address?: AccountIndex | AccountId | Address | string | null): Observable<DeriveAccountInfo> =>
|
||||||
api.derive.accounts.idAndIndex(address).pipe(
|
api.derive.accounts.idAndIndex(address).pipe(
|
||||||
switchMap(([accountId, accountIndex]): Observable<[DeriveAccountInfo, string?]> =>
|
switchMap(([accountId, accountIndex]): Observable<[Partial<DeriveAccountInfo>, DeriveAccountRegistration, string?]> =>
|
||||||
combineLatest([
|
combineLatest([
|
||||||
of({ accountId, accountIndex }),
|
of({ accountId, accountIndex }),
|
||||||
|
retrieveIdentity(api, accountId),
|
||||||
retrieveNick(api, accountId)
|
retrieveNick(api, accountId)
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
map(([{ accountId, accountIndex }, nickname]): DeriveAccountInfo => ({
|
map(([{ accountId, accountIndex }, identity, nickname]): DeriveAccountInfo => ({
|
||||||
accountId, accountIndex, nickname
|
accountId, accountIndex, identity, nickname
|
||||||
}))
|
}))
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
export * from './proposals';
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
// 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 { Hash, Proposal, Votes } from '@polkadot/types/interfaces';
|
||||||
|
import { DerivedCollectiveProposals } from '../types';
|
||||||
|
|
||||||
|
import { combineLatest, Observable, of } from 'rxjs';
|
||||||
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
|
import { Option } from '@polkadot/types';
|
||||||
|
|
||||||
|
export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalCommittee'): () => Observable<DerivedCollectiveProposals> {
|
||||||
|
return (): Observable<DerivedCollectiveProposals> =>
|
||||||
|
api.query[section]
|
||||||
|
? api.query[section].proposals()
|
||||||
|
.pipe(
|
||||||
|
switchMap((hashes: Hash[]): Observable<[Hash[], Option<Proposal>[], Option<Votes>[]]> => {
|
||||||
|
return combineLatest([
|
||||||
|
of(hashes),
|
||||||
|
combineLatest(
|
||||||
|
hashes.map((hash): Observable<Option<Proposal>> => api.query[section].proposalOf(hash))
|
||||||
|
),
|
||||||
|
api.query[section].voting.multi<Option<Votes>>(hashes)
|
||||||
|
]);
|
||||||
|
}),
|
||||||
|
map(([hashes, proposals, votes]): DerivedCollectiveProposals => {
|
||||||
|
const result: DerivedCollectiveProposals = [];
|
||||||
|
|
||||||
|
proposals.forEach((proposalOpt, index): void => {
|
||||||
|
if (proposalOpt.isSome) {
|
||||||
|
result.push({
|
||||||
|
hash: hashes[index],
|
||||||
|
proposal: proposalOpt.unwrap(),
|
||||||
|
votes: votes[index].unwrapOr(null)
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return result;
|
||||||
|
})
|
||||||
|
)
|
||||||
|
: of([] as DerivedCollectiveProposals);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
export * from './proposals';
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// 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 { DerivedCollectiveProposals } from '../types';
|
||||||
|
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { proposals as collectiveProposals } from '../collective';
|
||||||
|
import { memo } from '../util';
|
||||||
|
|
||||||
|
export function proposals (api: ApiInterfaceRx): () => Observable<DerivedCollectiveProposals> {
|
||||||
|
return memo(collectiveProposals(api, 'council'));
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
import { AccountId, Balance, BlockNumber, Hash, PropIndex } from '@polkadot/types/interfaces';
|
import { AccountId, Balance, BlockNumber, Hash, PropIndex, Proposal } from '@polkadot/types/interfaces';
|
||||||
import { ITuple } from '@polkadot/types/types';
|
import { ITuple } from '@polkadot/types/types';
|
||||||
import { DeriveProposal } from '../types';
|
import { DeriveProposal } from '../types';
|
||||||
|
|
||||||
@@ -14,62 +14,70 @@ import { Bytes, Option, Vec, createType } from '@polkadot/types';
|
|||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
export type PreImage = Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>;
|
export type PreImage = Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>;
|
||||||
|
|
||||||
type Depositors = Option<ITuple<[Balance, Vec<AccountId>]>>;
|
type Depositors = Option<ITuple<[Balance, Vec<AccountId>]>>;
|
||||||
|
type Proposals = Vec<ITuple<[PropIndex, Hash, AccountId]>>;
|
||||||
|
|
||||||
|
interface Result {
|
||||||
|
depositors: Depositors[];
|
||||||
|
preimages: PreImage[];
|
||||||
|
proposals: Proposals;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parse (api: ApiInterfaceRx, { depositors, proposals, preimages }: Result): DeriveProposal[] {
|
||||||
|
return proposals
|
||||||
|
.filter(([, , proposer], index): boolean =>
|
||||||
|
!!(depositors[index]?.isSome) && !proposer.isEmpty
|
||||||
|
)
|
||||||
|
.map(([propIndex, hash, proposer], index): DeriveProposal => {
|
||||||
|
const preimage = preimages[index].unwrapOr(null);
|
||||||
|
const depositor = depositors[index].unwrap();
|
||||||
|
let proposal: undefined | Proposal;
|
||||||
|
|
||||||
|
// we could end up in a situation where the proposal is non-decodable, e.g. after an upgrade
|
||||||
|
if (preimage) {
|
||||||
|
try {
|
||||||
|
proposal = createType(api.registry, 'Proposal', preimage[0].toU8a(true));
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
balance: depositor[0],
|
||||||
|
hash,
|
||||||
|
index: propIndex,
|
||||||
|
preimage: preimage
|
||||||
|
? {
|
||||||
|
at: preimage[3],
|
||||||
|
balance: preimage[2],
|
||||||
|
proposer: preimage[1]
|
||||||
|
}
|
||||||
|
: undefined,
|
||||||
|
proposal,
|
||||||
|
proposer,
|
||||||
|
seconds: depositor[1]
|
||||||
|
};
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
export function proposals (api: ApiInterfaceRx): () => Observable<DeriveProposal[]> {
|
export function proposals (api: ApiInterfaceRx): () => Observable<DeriveProposal[]> {
|
||||||
return memo((): Observable<DeriveProposal[]> =>
|
return memo((): Observable<DeriveProposal[]> =>
|
||||||
api.query.democracy
|
api.query.democracy?.publicProps
|
||||||
.publicProps<Vec<ITuple<[PropIndex, Hash, AccountId]>>>()
|
? api.query.democracy
|
||||||
.pipe(
|
.publicProps<Proposals>()
|
||||||
switchMap((proposals) =>
|
.pipe(
|
||||||
combineLatest([
|
switchMap((proposals) =>
|
||||||
of(proposals),
|
combineLatest([
|
||||||
combineLatest(
|
of(proposals),
|
||||||
...proposals.map(([, hash]) =>
|
api.query.democracy.preimages.multi<PreImage>(proposals.map(([, hash]): Hash => hash)),
|
||||||
api.query.democracy.preimages<PreImage>(hash)
|
api.query.democracy.depositOf.multi<Depositors>(proposals.map(([index]): PropIndex => index))
|
||||||
)
|
])
|
||||||
)
|
),
|
||||||
])
|
map(([proposals, preimages, depositors]): DeriveProposal[] =>
|
||||||
),
|
parse(api, { depositors, proposals, preimages })
|
||||||
switchMap(([proposals, preimages]) =>
|
)
|
||||||
combineLatest([
|
|
||||||
of(proposals),
|
|
||||||
of(preimages),
|
|
||||||
combineLatest(
|
|
||||||
...proposals.map(([index]) =>
|
|
||||||
api.query.democracy.depositOf<Depositors>(index)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
])
|
|
||||||
),
|
|
||||||
map(([proposals, _preImages, _depositors]): DeriveProposal[] =>
|
|
||||||
proposals
|
|
||||||
.filter(([, , proposer], index): boolean =>
|
|
||||||
!!(_preImages[index]?.isSome) && !!(_depositors[index]?.isSome) && !proposer.isEmpty
|
|
||||||
)
|
|
||||||
.map(([propIndex, hash, proposer], index): DeriveProposal => {
|
|
||||||
const preImage = _preImages[index].unwrapOr(null);
|
|
||||||
const depositors = _depositors[index].unwrap();
|
|
||||||
|
|
||||||
return {
|
|
||||||
balance: depositors[0],
|
|
||||||
hash,
|
|
||||||
index: propIndex,
|
|
||||||
preimage: preImage
|
|
||||||
? {
|
|
||||||
at: preImage[3],
|
|
||||||
balance: preImage[2],
|
|
||||||
proposer: preImage[1]
|
|
||||||
}
|
|
||||||
: undefined,
|
|
||||||
proposal: preImage
|
|
||||||
? createType(api.registry, 'Proposal', preImage[0].toU8a(true))
|
|
||||||
: undefined,
|
|
||||||
proposer,
|
|
||||||
seconds: depositors[1]
|
|
||||||
};
|
|
||||||
})
|
|
||||||
)
|
)
|
||||||
)
|
: of([] as DeriveProposal[])
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
@@ -15,8 +15,6 @@ import { Option, createType } from '@polkadot/types';
|
|||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
function constructInfo (api: ApiInterfaceRx, index: BN | number, _info: Option<ReferendumInfo>, _preimage?: PreImage): DerivedReferendum | null {
|
function constructInfo (api: ApiInterfaceRx, index: BN | number, _info: Option<ReferendumInfo>, _preimage?: PreImage): DerivedReferendum | null {
|
||||||
console.log(JSON.stringify(_info), JSON.stringify(_preimage));
|
|
||||||
|
|
||||||
const preImage = _preimage?.isSome
|
const preImage = _preimage?.isSome
|
||||||
? _preimage.unwrap()
|
? _preimage.unwrap()
|
||||||
: null;
|
: null;
|
||||||
@@ -44,8 +42,6 @@ function constructInfo (api: ApiInterfaceRx, index: BN | number, _info: Option<R
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function retrieveInfo (api: ApiInterfaceRx, index: BN | number, info: Option<ReferendumInfo>): Observable<DerivedReferendum | null> {
|
export function retrieveInfo (api: ApiInterfaceRx, index: BN | number, info: Option<ReferendumInfo>): Observable<DerivedReferendum | null> {
|
||||||
console.log(JSON.stringify(info));
|
|
||||||
|
|
||||||
return ((
|
return ((
|
||||||
info?.isSome
|
info?.isSome
|
||||||
? api.query.democracy.preimages<PreImage>(info.unwrap().proposalHash)
|
? api.query.democracy.preimages<PreImage>(info.unwrap().proposalHash)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
@@ -14,18 +14,22 @@ import { memo } from '../util';
|
|||||||
|
|
||||||
export function referendums (api: ApiInterfaceRx): () => Observable<DerivedReferendum[]> {
|
export function referendums (api: ApiInterfaceRx): () => Observable<DerivedReferendum[]> {
|
||||||
return memo((): Observable<DerivedReferendum[]> =>
|
return memo((): Observable<DerivedReferendum[]> =>
|
||||||
api.queryMulti<[ReferendumIndex, ReferendumIndex]>([
|
// V2 vs V1 (and early V2)
|
||||||
api.query.democracy.nextTally,
|
api.query.democracy?.lowestUnbaked || api.query.democracy?.nextTally
|
||||||
api.query.democracy.referendumCount
|
? api.queryMulti<[ReferendumIndex, ReferendumIndex]>([
|
||||||
]).pipe(
|
api.query.democracy.lowestUnbaked || api.query.democracy.nextTally,
|
||||||
switchMap(([nextTally, referendumCount]): Observable<DerivedReferendum[]> =>
|
api.query.democracy.referendumCount
|
||||||
referendumCount && nextTally && referendumCount.gt(nextTally) && referendumCount.gtn(0)
|
]).pipe(
|
||||||
? api.derive.democracy.referendumInfos(
|
switchMap(([earliest, referendumCount]): Observable<DerivedReferendum[]> =>
|
||||||
[...Array(referendumCount.sub(nextTally).toNumber())].map((_, i): BN =>
|
referendumCount?.gt(earliest) && referendumCount?.gtn(0)
|
||||||
nextTally.addn(i)
|
? api.derive.democracy.referendumInfos(
|
||||||
|
[...Array(referendumCount.sub(earliest).toNumber())].map((_, i): BN =>
|
||||||
|
earliest.addn(i)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
: of([])
|
||||||
: of([])
|
)
|
||||||
)
|
)
|
||||||
));
|
: of([] as DerivedReferendum[])
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
// Copyright 2017-2019 @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, ApprovalFlag, SetIndex } from '@polkadot/types/interfaces';
|
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
|
||||||
import { Observable, of } from 'rxjs';
|
|
||||||
import { Vec } from '@polkadot/types';
|
|
||||||
import { switchMap, map } from 'rxjs/operators';
|
|
||||||
import { approvalFlagsToBools } from '../util/approvalFlagsToBools';
|
|
||||||
import { memo } from '../util';
|
|
||||||
|
|
||||||
function queryElections (api: ApiInterfaceRx, who: AccountId | string): Observable<boolean[][]> {
|
|
||||||
return api.query.elections.nextVoterSet<SetIndex>().pipe(
|
|
||||||
switchMap((nextVoterSet: SetIndex): Observable<Vec<ApprovalFlag>[]> =>
|
|
||||||
api.query.elections.approvalsOf.multi(
|
|
||||||
[...Array(nextVoterSet.toNumber() + 1).keys()].map((i): [string, number] =>
|
|
||||||
[who.toString(), i]
|
|
||||||
)
|
|
||||||
) as any as Observable<Vec<ApprovalFlag>[]>
|
|
||||||
),
|
|
||||||
map((votes: Vec<ApprovalFlag>[]): boolean[][] =>
|
|
||||||
votes.map((flags: Vec<ApprovalFlag>): boolean[] =>
|
|
||||||
approvalFlagsToBools(flags)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @name approvalsOf
|
|
||||||
* @returns A nested array of boolean approvals for the given account in each voter set index, converted from its ApprovalFlag(s).
|
|
||||||
* @example
|
|
||||||
* <BR>
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* api.derive.elections.approvalsOf(ALICE, (approvals) => {
|
|
||||||
* // approvals === [[false], [true, false], ...]
|
|
||||||
* });
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
export function approvalsOf (api: ApiInterfaceRx): (who: AccountId | string) => Observable<boolean[][]> {
|
|
||||||
return memo((who: AccountId | string): Observable<boolean[][]> =>
|
|
||||||
api.query.elections
|
|
||||||
? queryElections(api, who)
|
|
||||||
: of([])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
// Copyright 2017-2019 @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, ApprovalFlag, SetIndex } from '@polkadot/types/interfaces';
|
|
||||||
|
|
||||||
import BN from 'bn.js';
|
|
||||||
import { Observable, of } from 'rxjs';
|
|
||||||
import { map } from 'rxjs/operators';
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
|
||||||
import { Vec } from '@polkadot/types';
|
|
||||||
|
|
||||||
import { approvalFlagsToBools } from '../util/approvalFlagsToBools';
|
|
||||||
import { memo } from '../util';
|
|
||||||
|
|
||||||
function queryElections (api: ApiInterfaceRx, who: AccountId | string, at: SetIndex | BN | number): Observable<boolean[]> {
|
|
||||||
return api.query.elections.approvalsOf<Vec<ApprovalFlag>>([who.toString(), at]).pipe(
|
|
||||||
map((flags: Vec<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @name approvalsOfAt
|
|
||||||
* @returns An array of boolean approvals for the account and set index, converted from the returned ApprovalFlag.
|
|
||||||
* @example
|
|
||||||
* <BR>
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* api.derive.elections.approvalsOfAt(ALICE, new BN(0), (approvals) => {
|
|
||||||
* // approvals === [false, true, ...]
|
|
||||||
* });
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
export function approvalsOfAt (api: ApiInterfaceRx): (who: AccountId, at: SetIndex) => Observable<boolean[]> {
|
|
||||||
return memo((who: AccountId | string, at: SetIndex | BN | number): Observable<boolean[]> =>
|
|
||||||
api.query.elections
|
|
||||||
? queryElections(api, who, at)
|
|
||||||
: of([])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,9 +1,5 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
export * from './approvalsOf';
|
|
||||||
export * from './approvalsOfAt';
|
|
||||||
export * from './info';
|
export * from './info';
|
||||||
export * from './voters';
|
|
||||||
export * from './voterPositions';
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
import { AccountId, Balance, BlockNumber, SetIndex, VoteIndex } from '@polkadot/types/interfaces';
|
import { AccountId, Balance, BlockNumber } from '@polkadot/types/interfaces';
|
||||||
import { ITuple } from '@polkadot/types/types';
|
import { ITuple } from '@polkadot/types/types';
|
||||||
|
|
||||||
import { Observable, combineLatest } from 'rxjs';
|
import { Observable, combineLatest } from 'rxjs';
|
||||||
@@ -13,40 +13,7 @@ import { createType, Vec, u32 } from '@polkadot/types';
|
|||||||
import { DerivedElectionsInfo } from '../types';
|
import { DerivedElectionsInfo } from '../types';
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
type ResultElectionsInner = [u32, u32, Vec<ITuple<[AccountId, BlockNumber]>>, SetIndex, BlockNumber, VoteIndex, SetIndex];
|
function deriveElections (api: ApiInterfaceRx, candidates: AccountId[], members: [AccountId, Balance][], runnersUp: [AccountId, Balance][], candidacyBond: Balance, desiredSeats: u32, termDuration: BlockNumber, votingBond: Balance): DerivedElectionsInfo {
|
||||||
type ResultElections = [Vec<AccountId>, ResultElectionsInner];
|
|
||||||
|
|
||||||
function deriveElections (api: ApiInterfaceRx, [candidates, [candidateCount, desiredSeats, members, nextVoterSet, termDuration, voteCount, voterCount]]: ResultElections): DerivedElectionsInfo {
|
|
||||||
return {
|
|
||||||
candidates,
|
|
||||||
candidateCount,
|
|
||||||
desiredSeats,
|
|
||||||
nextVoterSet,
|
|
||||||
members: members.map(([accountId]): [AccountId, Balance] => [accountId, createType(api.registry, 'Balance')]),
|
|
||||||
runnersUp: [],
|
|
||||||
termDuration,
|
|
||||||
voteCount,
|
|
||||||
voterCount
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function queryElections (api: ApiInterfaceRx): Observable<DerivedElectionsInfo> {
|
|
||||||
// NOTE We have an issue where candidates can return `null` for an empty array
|
|
||||||
return combineLatest([
|
|
||||||
api.query.elections.candidates<Vec<AccountId>>(),
|
|
||||||
api.queryMulti<ResultElectionsInner>([
|
|
||||||
api.query.elections.candidateCount,
|
|
||||||
api.query.elections.desiredSeats,
|
|
||||||
api.query.elections.members,
|
|
||||||
api.query.elections.nextVoterSet,
|
|
||||||
api.query.elections.termDuration,
|
|
||||||
api.query.elections.voteCount,
|
|
||||||
api.query.elections.voterCount
|
|
||||||
])
|
|
||||||
]).pipe(map((result): DerivedElectionsInfo => deriveElections(api, result)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function derivePhragmen (api: ApiInterfaceRx, candidates: AccountId[], members: [AccountId, Balance][], runnersUp: [AccountId, Balance][], candidacyBond: Balance, desiredSeats: u32, termDuration: BlockNumber, votingBond: Balance): DerivedElectionsInfo {
|
|
||||||
return {
|
return {
|
||||||
candidates,
|
candidates,
|
||||||
candidateCount: createType(api.registry, 'u32', candidates.length),
|
candidateCount: createType(api.registry, 'u32', candidates.length),
|
||||||
@@ -59,23 +26,25 @@ function derivePhragmen (api: ApiInterfaceRx, candidates: AccountId[], members:
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function queryPhragmen (api: ApiInterfaceRx): Observable<DerivedElectionsInfo> {
|
function queryElections (api: ApiInterfaceRx): Observable<DerivedElectionsInfo> {
|
||||||
|
const section = api.query.electionsPhragmen ? 'electionsPhragmen' : 'elections';
|
||||||
|
|
||||||
// NOTE We have an issue where candidates can return `null` for an empty array, hence
|
// NOTE We have an issue where candidates can return `null` for an empty array, hence
|
||||||
// we are not using multi queries here, so empty array is empty (instead of space-filled)
|
// we are not using multi queries here, so empty array is empty (instead of space-filled)
|
||||||
return combineLatest([
|
return combineLatest([
|
||||||
api.query.electionsPhragmen.candidates<Vec<AccountId>>(),
|
api.query[section].candidates<Vec<AccountId>>(),
|
||||||
api.query.electionsPhragmen.members<Vec<ITuple<[AccountId, Balance]>>>(),
|
api.query[section].members<Vec<ITuple<[AccountId, Balance]>>>(),
|
||||||
api.query.electionsPhragmen.runnersUp<Vec<ITuple<[AccountId, Balance]>>>()
|
api.query[section].runnersUp<Vec<ITuple<[AccountId, Balance]>>>()
|
||||||
]).pipe(
|
]).pipe(
|
||||||
map(([candidates, members, runnersUp]): DerivedElectionsInfo => derivePhragmen(
|
map(([candidates, members, runnersUp]): DerivedElectionsInfo => deriveElections(
|
||||||
api,
|
api,
|
||||||
candidates,
|
candidates,
|
||||||
members,
|
members,
|
||||||
runnersUp,
|
runnersUp,
|
||||||
api.consts.electionsPhragmen.candidacyBond as Balance,
|
api.consts[section].candidacyBond as Balance,
|
||||||
api.consts.electionsPhragmen.desiredMembers as u32,
|
api.consts[section].desiredMembers as u32,
|
||||||
api.consts.electionsPhragmen.termDuration as BlockNumber,
|
api.consts[section].termDuration as BlockNumber,
|
||||||
api.consts.electionsPhragmen.votingBond as Balance
|
api.consts[section].votingBond as Balance
|
||||||
))
|
))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -94,9 +63,5 @@ function queryPhragmen (api: ApiInterfaceRx): Observable<DerivedElectionsInfo> {
|
|||||||
* ```
|
* ```
|
||||||
*/
|
*/
|
||||||
export function info (api: ApiInterfaceRx): () => Observable<DerivedElectionsInfo> {
|
export function info (api: ApiInterfaceRx): () => Observable<DerivedElectionsInfo> {
|
||||||
return memo((): Observable<DerivedElectionsInfo> =>
|
return memo((): Observable<DerivedElectionsInfo> => queryElections(api));
|
||||||
api.query.electionsPhragmen
|
|
||||||
? queryPhragmen(api)
|
|
||||||
: queryElections(api)
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
// Copyright 2017-2019 @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, SetIndex } from '@polkadot/types/interfaces';
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
|
||||||
import { Vec, Option, createType, u32 } from '@polkadot/types';
|
|
||||||
import { DerivedVoterPositions } from '../types';
|
|
||||||
|
|
||||||
import BN from 'bn.js';
|
|
||||||
import { of, Observable } from 'rxjs';
|
|
||||||
import { switchMap, map } from 'rxjs/operators';
|
|
||||||
|
|
||||||
import { memo } from '../util';
|
|
||||||
|
|
||||||
function queryElections (api: ApiInterfaceRx): Observable<DerivedVoterPositions> {
|
|
||||||
return api.query.elections.nextVoterSet<SetIndex>().pipe(
|
|
||||||
switchMap((nextVoterSet: SetIndex): Observable<Vec<Option<AccountId>>[]> =>
|
|
||||||
api.query.elections.voters.multi<Vec<Option<AccountId>>>([...Array(+nextVoterSet + 1).keys()].map((_, i): [number] => [i]))
|
|
||||||
),
|
|
||||||
map((voters: Vec<Option<AccountId>>[]): DerivedVoterPositions => {
|
|
||||||
return voters.reduce((result: DerivedVoterPositions, vec, setIndex): DerivedVoterPositions => {
|
|
||||||
vec.forEach((e, index): 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 accountId: AccountId | null = e.unwrapOr(null);
|
|
||||||
|
|
||||||
if (accountId) {
|
|
||||||
result[accountId.toString()] = {
|
|
||||||
globalIndex: (api.consts.elections.voterSetSize as u32).muln(setIndex).addn(index),
|
|
||||||
index: new BN(index),
|
|
||||||
setIndex: createType(api.registry, 'SetIndex', setIndex)
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}, {});
|
|
||||||
})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @name voterPositions
|
|
||||||
* @returns An mapping of all current voter accounts to their voter set and global index.
|
|
||||||
* @example
|
|
||||||
* <BR>
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* api.derive.elections.voterPositions((voters) => {
|
|
||||||
* const { index, setIndex, globalIndex } = voters[ALICE];
|
|
||||||
* console.log(`ALICE is a voter at index ${index} in voter set ${setIndex}, with global index ${globalIndex}.`);
|
|
||||||
* });
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
export function voterPositions (api: ApiInterfaceRx): () => Observable<DerivedVoterPositions> {
|
|
||||||
return memo((): Observable<DerivedVoterPositions> =>
|
|
||||||
api.query.elections
|
|
||||||
? queryElections(api)
|
|
||||||
: of({})
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,46 +0,0 @@
|
|||||||
// Copyright 2017-2019 @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 { AccountId } from '@polkadot/types/interfaces';
|
|
||||||
import { DerivedVoterPositions } from '../types';
|
|
||||||
|
|
||||||
import { Observable, of } from 'rxjs';
|
|
||||||
import { map } from 'rxjs/operators';
|
|
||||||
import { createType, Vec } from '@polkadot/types';
|
|
||||||
|
|
||||||
import { memo } from '../util';
|
|
||||||
|
|
||||||
function queryElections (api: ApiInterfaceRx): Observable<AccountId[]> {
|
|
||||||
return api.derive.elections.voterPositions().pipe(
|
|
||||||
map((voterPositions: DerivedVoterPositions): Vec<AccountId> =>
|
|
||||||
createType(
|
|
||||||
api.registry,
|
|
||||||
'Vec<AccountId>',
|
|
||||||
Object.entries(voterPositions)
|
|
||||||
.sort((a, b): number => a[1].globalIndex.cmp(b[1].globalIndex))
|
|
||||||
.map(([accountId]): AccountId => createType(api.registry, 'AccountId', accountId))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* @name voters
|
|
||||||
* @returns An array of all current voters from all sets.
|
|
||||||
* @example
|
|
||||||
* <BR>
|
|
||||||
*
|
|
||||||
* ```javascript
|
|
||||||
* api.derive.elections.voters((voters) => {
|
|
||||||
* console.log(`There are ${voters.length} current voters.`);
|
|
||||||
* });
|
|
||||||
* ```
|
|
||||||
*/
|
|
||||||
export function voters (api: ApiInterfaceRx): () => Observable<AccountId[]> {
|
|
||||||
return memo((): Observable<AccountId[]> =>
|
|
||||||
api.query.elections
|
|
||||||
? queryElections(api)
|
|
||||||
: of([])
|
|
||||||
);
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
@@ -55,17 +55,13 @@ describe('derive', (): void => {
|
|||||||
testFunction(api)('democracy', 'referendumVotesFor', []);
|
testFunction(api)('democracy', 'referendumVotesFor', []);
|
||||||
testFunction(api)('democracy', 'votes', []);
|
testFunction(api)('democracy', 'votes', []);
|
||||||
|
|
||||||
testFunction(api)('elections', 'approvalsOf', []);
|
|
||||||
// FIXME This one has an additional check which mock doesnt (yet) cater for
|
|
||||||
// testFunction(api)('elections', 'approvalsOfAt', []);
|
|
||||||
testFunction(api)('elections', 'info', []);
|
testFunction(api)('elections', 'info', []);
|
||||||
testFunction(api)('elections', 'voters', []);
|
|
||||||
|
|
||||||
testFunction(api)('session', 'eraLength', []);
|
testFunction(api)('session', 'eraLength', []);
|
||||||
testFunction(api)('session', 'eraProgress', []);
|
testFunction(api)('session', 'eraProgress', []);
|
||||||
testFunction(api)('session', 'sessionProgress', []);
|
testFunction(api)('session', 'sessionProgress', []);
|
||||||
|
|
||||||
testFunction(api)('staking', 'info', []);
|
testFunction(api)('staking', 'account', []);
|
||||||
testFunction(api)('staking', 'recentlyOffline', []);
|
testFunction(api)('staking', 'recentlyOffline', []);
|
||||||
testFunction(api)('staking', 'controllers', []);
|
testFunction(api)('staking', 'controllers', []);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
@@ -11,11 +11,14 @@ import * as accounts from './accounts';
|
|||||||
import * as balances from './balances';
|
import * as balances from './balances';
|
||||||
import * as chain from './chain';
|
import * as chain from './chain';
|
||||||
import * as contracts from './contracts';
|
import * as contracts from './contracts';
|
||||||
|
import * as council from './council';
|
||||||
import * as democracy from './democracy';
|
import * as democracy from './democracy';
|
||||||
import * as elections from './elections';
|
import * as elections from './elections';
|
||||||
import * as imOnline from './imOnline';
|
import * as imOnline from './imOnline';
|
||||||
import * as session from './session';
|
import * as session from './session';
|
||||||
import * as staking from './staking';
|
import * as staking from './staking';
|
||||||
|
import * as technicalCommittee from './technicalCommittee';
|
||||||
|
import * as treasury from './treasury';
|
||||||
|
|
||||||
export * from './type';
|
export * from './type';
|
||||||
|
|
||||||
@@ -56,7 +59,7 @@ function injectFunctions<AllSections> (api: ApiInterfaceRx, allSections: AllSect
|
|||||||
}, {} as DeriveAllSections<AllSections>);
|
}, {} as DeriveAllSections<AllSections>);
|
||||||
}
|
}
|
||||||
|
|
||||||
export const derive = { accounts, balances, chain, contracts, democracy, elections, imOnline, session, staking };
|
export const derive = { accounts, balances, chain, contracts, council, democracy, elections, imOnline, session, staking, technicalCommittee, treasury };
|
||||||
export type ExactDerive = DeriveAllSections<typeof derive>;
|
export type ExactDerive = DeriveAllSections<typeof derive>;
|
||||||
|
|
||||||
// FIXME The return type of this function should be {...ExactDerive, ...DeriveCustom}
|
// FIXME The return type of this function should be {...ExactDerive, ...DeriveCustom}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
// 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, BlockNumber, StakingLedger, UnlockChunk } from '@polkadot/types/interfaces';
|
||||||
|
import { DerivedSessionInfo, DerivedStakingAccount, DerivedStakingQuery, DerivedUnlocking } from '../types';
|
||||||
|
|
||||||
|
import BN from 'bn.js';
|
||||||
|
import { combineLatest, Observable } from 'rxjs';
|
||||||
|
import { map } from 'rxjs/operators';
|
||||||
|
import { createType } from '@polkadot/types';
|
||||||
|
|
||||||
|
import { isUndefined } from '@polkadot/util';
|
||||||
|
|
||||||
|
import { memo } from '../util';
|
||||||
|
|
||||||
|
// groups the supplied chunks by era, i.e. { [era]: BN(total of values) }
|
||||||
|
function groupByEra (list: UnlockChunk[]): Record<string, BN> {
|
||||||
|
return list.reduce((map: Record<string, BN>, { era, value }): Record<string, BN> => {
|
||||||
|
const key = era.toString();
|
||||||
|
|
||||||
|
map[key] = !map[key]
|
||||||
|
? value.unwrap()
|
||||||
|
: map[key].add(value.unwrap());
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}, {});
|
||||||
|
}
|
||||||
|
|
||||||
|
// calculate the remaining blocks in a specific unlock era
|
||||||
|
function remainingBlocks (api: ApiInterfaceRx, era: BN, sessionInfo: DerivedSessionInfo): BlockNumber {
|
||||||
|
const remaining = era.sub(sessionInfo.currentEra);
|
||||||
|
|
||||||
|
// on the Rust side the current-era >= era-for-unlock (removal done on >)
|
||||||
|
return createType(api.registry, 'BlockNumber', remaining.gtn(0)
|
||||||
|
? remaining
|
||||||
|
.subn(1)
|
||||||
|
.mul(sessionInfo.eraLength)
|
||||||
|
.add(sessionInfo.eraLength.sub(sessionInfo.eraProgress))
|
||||||
|
: 0
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DerivedSessionInfo): DerivedUnlocking[] | undefined {
|
||||||
|
if (isUndefined(stakingLedger)) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
const unlockingChunks = stakingLedger.unlocking.filter(({ era }): boolean =>
|
||||||
|
remainingBlocks(api, era.unwrap(), sessionInfo).gtn(0)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!unlockingChunks.length) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
// group the unlock chunks that have the same era and sum their values
|
||||||
|
const groupedResult = groupByEra(unlockingChunks);
|
||||||
|
const results = Object.entries(groupedResult).map(([eraString, value]): DerivedUnlocking => ({
|
||||||
|
value: createType(api.registry, 'Balance', value),
|
||||||
|
remainingBlocks: remainingBlocks(api, new BN(eraString), sessionInfo)
|
||||||
|
}));
|
||||||
|
|
||||||
|
return results.length ? results : undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
function redeemableSum (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DerivedSessionInfo): Balance {
|
||||||
|
if (isUndefined(stakingLedger)) {
|
||||||
|
return createType(api.registry, 'Balance');
|
||||||
|
}
|
||||||
|
|
||||||
|
return createType(api.registry, 'Balance', stakingLedger.unlocking.reduce((total, { era, value }): BN => {
|
||||||
|
return remainingBlocks(api, era.unwrap(), sessionInfo).eqn(0)
|
||||||
|
? total.add(value.unwrap())
|
||||||
|
: total;
|
||||||
|
}, new BN(0)));
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseResult (api: ApiInterfaceRx, sessionInfo: DerivedSessionInfo, query: DerivedStakingQuery): DerivedStakingAccount {
|
||||||
|
return {
|
||||||
|
...query,
|
||||||
|
redeemable: redeemableSum(api, query.stakingLedger, sessionInfo),
|
||||||
|
unlocking: calculateUnlocking(api, query.stakingLedger, sessionInfo)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description From a stash, retrieve the controllerId and fill in all the relevant staking details
|
||||||
|
*/
|
||||||
|
export function account (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable<DerivedStakingAccount> {
|
||||||
|
return memo((accountId: Uint8Array | string): Observable<DerivedStakingAccount> =>
|
||||||
|
combineLatest([
|
||||||
|
api.derive.session.info(),
|
||||||
|
api.derive.staking.query(accountId)
|
||||||
|
]).pipe(
|
||||||
|
map(([sessionInfo, query]: [DerivedSessionInfo, DerivedStakingQuery]) =>
|
||||||
|
parseResult(api, sessionInfo, query))
|
||||||
|
));
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { AccountId } from '@polkadot/types/interfaces';
|
import { AccountId } from '@polkadot/types/interfaces';
|
||||||
import { DerivedStaking, DerivedStakingElected } from '../types';
|
import { DerivedStakingQuery, DerivedStakingElected } from '../types';
|
||||||
|
|
||||||
import { Observable, combineLatest, of } from 'rxjs';
|
import { Observable, combineLatest, of } from 'rxjs';
|
||||||
import { map, switchMap } from 'rxjs/operators';
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
@@ -14,11 +14,11 @@ import { memo } from '../util';
|
|||||||
export function electedInfo (api: ApiInterfaceRx): () => Observable<DerivedStakingElected> {
|
export function electedInfo (api: ApiInterfaceRx): () => Observable<DerivedStakingElected> {
|
||||||
return memo((): Observable<DerivedStakingElected> =>
|
return memo((): Observable<DerivedStakingElected> =>
|
||||||
api.derive.staking.validators().pipe(
|
api.derive.staking.validators().pipe(
|
||||||
switchMap(({ currentElected }): Observable<[AccountId[], DerivedStaking[]]> =>
|
switchMap(({ currentElected }): Observable<[AccountId[], DerivedStakingQuery[]]> =>
|
||||||
combineLatest([
|
combineLatest([
|
||||||
of(currentElected),
|
of(currentElected),
|
||||||
combineLatest(currentElected.map((accountId): Observable<DerivedStaking> =>
|
combineLatest(currentElected.map((accountId): Observable<DerivedStakingQuery> =>
|
||||||
api.derive.staking.info(accountId)
|
api.derive.staking.query(accountId)
|
||||||
))
|
))
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
export * from './account';
|
||||||
export * from './controllers';
|
export * from './controllers';
|
||||||
export * from './electedInfo';
|
export * from './electedInfo';
|
||||||
export * from './info';
|
|
||||||
export * from './overview';
|
export * from './overview';
|
||||||
|
export * from './query';
|
||||||
export * from './recentlyOffline';
|
export * from './recentlyOffline';
|
||||||
export * from './validators';
|
export * from './validators';
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
+19
-92
@@ -1,29 +1,24 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||||
import { AccountId, Balance, BlockNumber, Exposure, Keys, Nominations, RewardDestination, StakingLedger, UnlockChunk, ValidatorPrefs } from '@polkadot/types/interfaces';
|
import { AccountId, Exposure, Keys, Nominations, RewardDestination, StakingLedger, ValidatorPrefs } from '@polkadot/types/interfaces';
|
||||||
import { ITuple } from '@polkadot/types/types';
|
import { ITuple } from '@polkadot/types/types';
|
||||||
import { DerivedRecentlyOffline, DerivedSessionInfo, DerivedStaking, DerivedUnlocking } from '../types';
|
import { DerivedStakingQuery } from '../types';
|
||||||
|
|
||||||
import BN from 'bn.js';
|
|
||||||
import { combineLatest, Observable, of } from 'rxjs';
|
import { combineLatest, Observable, of } from 'rxjs';
|
||||||
import { map, switchMap } from 'rxjs/operators';
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
import { createType, Option, Vec } from '@polkadot/types';
|
import { createType, Option, Vec } from '@polkadot/types';
|
||||||
|
|
||||||
import { isUndefined } from '@polkadot/util';
|
|
||||||
|
|
||||||
import { memo } from '../util';
|
import { memo } from '../util';
|
||||||
|
|
||||||
interface ParseInput {
|
interface ParseInput {
|
||||||
accountId: AccountId;
|
accountId: AccountId;
|
||||||
controllerId: AccountId;
|
controllerId: AccountId;
|
||||||
recentlyOffline?: DerivedRecentlyOffline;
|
|
||||||
nominators: AccountId[];
|
nominators: AccountId[];
|
||||||
rewardDestination: RewardDestination;
|
rewardDestination: RewardDestination;
|
||||||
queuedKeys?: [AccountId, Keys][];
|
queuedKeys?: [AccountId, Keys][];
|
||||||
sessionInfo: DerivedSessionInfo;
|
|
||||||
stakers: Exposure;
|
stakers: Exposure;
|
||||||
stakingLedger: Option<StakingLedger>;
|
stakingLedger: Option<StakingLedger>;
|
||||||
stashId: AccountId;
|
stashId: AccountId;
|
||||||
@@ -32,68 +27,6 @@ interface ParseInput {
|
|||||||
nextKeyFor?: Option<AccountId>;
|
nextKeyFor?: Option<AccountId>;
|
||||||
}
|
}
|
||||||
|
|
||||||
// groups the supplied chunks by era, i.e. { [era]: BN(total of values) }
|
|
||||||
function groupByEra (list: UnlockChunk[]): Record<string, BN> {
|
|
||||||
return list.reduce((map: Record<string, BN>, { era, value }): Record<string, BN> => {
|
|
||||||
const key = era.toString();
|
|
||||||
|
|
||||||
map[key] = !map[key]
|
|
||||||
? value.unwrap()
|
|
||||||
: map[key].add(value.unwrap());
|
|
||||||
|
|
||||||
return map;
|
|
||||||
}, {});
|
|
||||||
}
|
|
||||||
|
|
||||||
// calculate the remaining blocks in a specific unlock era
|
|
||||||
function remainingBlocks (api: ApiInterfaceRx, era: BN, sessionInfo: DerivedSessionInfo): BlockNumber {
|
|
||||||
const remaining = era.sub(sessionInfo.currentEra);
|
|
||||||
|
|
||||||
// on the Rust side the current-era >= era-for-unlock (removal done on >)
|
|
||||||
return createType(api.registry, 'BlockNumber', remaining.gtn(0)
|
|
||||||
? remaining
|
|
||||||
.subn(1)
|
|
||||||
.mul(sessionInfo.eraLength)
|
|
||||||
.add(sessionInfo.eraLength.sub(sessionInfo.eraProgress))
|
|
||||||
: 0
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DerivedSessionInfo): DerivedUnlocking[] | undefined {
|
|
||||||
if (isUndefined(stakingLedger)) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
const unlockingChunks = stakingLedger.unlocking.filter(({ era }): boolean =>
|
|
||||||
remainingBlocks(api, era.unwrap(), sessionInfo).gtn(0)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!unlockingChunks.length) {
|
|
||||||
return undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
// group the unlock chunks that have the same era and sum their values
|
|
||||||
const groupedResult = groupByEra(unlockingChunks);
|
|
||||||
const results = Object.entries(groupedResult).map(([eraString, value]): DerivedUnlocking => ({
|
|
||||||
value: createType(api.registry, 'Balance', value),
|
|
||||||
remainingBlocks: remainingBlocks(api, new BN(eraString), sessionInfo)
|
|
||||||
}));
|
|
||||||
|
|
||||||
return results.length ? results : undefined;
|
|
||||||
}
|
|
||||||
|
|
||||||
function redeemableSum (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DerivedSessionInfo): Balance {
|
|
||||||
if (isUndefined(stakingLedger)) {
|
|
||||||
return createType(api.registry, 'Balance');
|
|
||||||
}
|
|
||||||
|
|
||||||
return createType(api.registry, 'Balance', stakingLedger.unlocking.reduce((total, { era, value }): BN => {
|
|
||||||
return remainingBlocks(api, era.unwrap(), sessionInfo).eqn(0)
|
|
||||||
? total.add(value.unwrap())
|
|
||||||
: total;
|
|
||||||
}, new BN(0)));
|
|
||||||
}
|
|
||||||
|
|
||||||
function unwrapSessionIds (stashId: AccountId, queuedKeys: Option<AccountId> | [AccountId, Keys][], nextKeys: Option<Keys>): { nextSessionIds: AccountId[]; sessionIds: AccountId[] } {
|
function unwrapSessionIds (stashId: AccountId, queuedKeys: Option<AccountId> | [AccountId, Keys][], nextKeys: Option<Keys>): { nextSessionIds: AccountId[]; sessionIds: AccountId[] } {
|
||||||
// for 2.x we have a Vec<(ValidatorId,Keys)> of the keys
|
// for 2.x we have a Vec<(ValidatorId,Keys)> of the keys
|
||||||
if (Array.isArray(queuedKeys)) {
|
if (Array.isArray(queuedKeys)) {
|
||||||
@@ -119,7 +52,7 @@ function unwrapSessionIds (stashId: AccountId, queuedKeys: Option<AccountId> | [
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function parseResult (api: ApiInterfaceRx, { accountId, controllerId, stashId, sessionInfo, recentlyOffline = {}, nextKeyFor, queuedKeys, stakingLedger, nominators, rewardDestination, stakers, validatorPrefs, nextKeys }: ParseInput): DerivedStaking {
|
function parseResult (api: ApiInterfaceRx, { accountId, controllerId, stashId, nextKeyFor, queuedKeys, stakingLedger, nominators, rewardDestination, stakers, validatorPrefs, nextKeys }: ParseInput): DerivedStakingQuery {
|
||||||
const _stakingLedger = stakingLedger.unwrapOr(undefined);
|
const _stakingLedger = stakingLedger.unwrapOr(undefined);
|
||||||
const _nextKeyFor = nextKeyFor || createType(api.registry, 'Option<AccountId>', null);
|
const _nextKeyFor = nextKeyFor || createType(api.registry, 'Option<AccountId>', null);
|
||||||
const _nextKeys = nextKeys || createType(api.registry, 'Option<Keys>', null);
|
const _nextKeys = nextKeys || createType(api.registry, 'Option<Keys>', null);
|
||||||
@@ -128,13 +61,10 @@ function parseResult (api: ApiInterfaceRx, { accountId, controllerId, stashId, s
|
|||||||
accountId,
|
accountId,
|
||||||
controllerId,
|
controllerId,
|
||||||
nominators,
|
nominators,
|
||||||
offline: recentlyOffline[stashId.toString()],
|
|
||||||
redeemable: redeemableSum(api, _stakingLedger, sessionInfo),
|
|
||||||
rewardDestination,
|
rewardDestination,
|
||||||
stakers,
|
stakers,
|
||||||
stakingLedger: _stakingLedger,
|
stakingLedger: _stakingLedger,
|
||||||
stashId,
|
stashId,
|
||||||
unlocking: calculateUnlocking(api, _stakingLedger, sessionInfo),
|
|
||||||
validatorPrefs,
|
validatorPrefs,
|
||||||
...unwrapSessionIds(stashId, queuedKeys || _nextKeyFor, _nextKeys)
|
...unwrapSessionIds(stashId, queuedKeys || _nextKeyFor, _nextKeys)
|
||||||
};
|
};
|
||||||
@@ -142,10 +72,8 @@ function parseResult (api: ApiInterfaceRx, { accountId, controllerId, stashId, s
|
|||||||
|
|
||||||
type MultiResultV1 = [Option<AccountId>, Option<StakingLedger>, [Vec<AccountId>], RewardDestination, Exposure, ITuple<[ValidatorPrefs]>];
|
type MultiResultV1 = [Option<AccountId>, Option<StakingLedger>, [Vec<AccountId>], RewardDestination, Exposure, ITuple<[ValidatorPrefs]>];
|
||||||
|
|
||||||
function retrieveInfoV1 (api: ApiInterfaceRx, accountId: AccountId, stashId: AccountId, controllerId: AccountId): Observable<DerivedStaking> {
|
function retrieveInfoV1 (api: ApiInterfaceRx, accountId: AccountId, stashId: AccountId, controllerId: AccountId): Observable<DerivedStakingQuery> {
|
||||||
return combineLatest([
|
return (
|
||||||
api.derive.session.info(),
|
|
||||||
api.derive.staking.recentlyOffline(),
|
|
||||||
api.queryMulti([
|
api.queryMulti([
|
||||||
[api.query.session.nextKeyFor, controllerId],
|
[api.query.session.nextKeyFor, controllerId],
|
||||||
[api.query.staking.ledger, controllerId],
|
[api.query.staking.ledger, controllerId],
|
||||||
@@ -154,18 +82,17 @@ function retrieveInfoV1 (api: ApiInterfaceRx, accountId: AccountId, stashId: Acc
|
|||||||
[api.query.staking.stakers, stashId],
|
[api.query.staking.stakers, stashId],
|
||||||
[api.query.staking.validators, stashId]
|
[api.query.staking.validators, stashId]
|
||||||
]) as Observable<MultiResultV1>
|
]) as Observable<MultiResultV1>
|
||||||
]).pipe(map(([sessionInfo, recentlyOffline, [nextKeyFor, stakingLedger, [nominators], rewardDestination, stakers, [validatorPrefs]]]: [DerivedSessionInfo, DerivedRecentlyOffline, MultiResultV1]): DerivedStaking =>
|
).pipe(map(([nextKeyFor, stakingLedger, [nominators], rewardDestination, stakers, [validatorPrefs]]: MultiResultV1): DerivedStakingQuery =>
|
||||||
parseResult(api, {
|
parseResult(api, {
|
||||||
accountId, controllerId, stashId, sessionInfo, recentlyOffline, nextKeyFor, stakingLedger, nominators, rewardDestination, stakers, validatorPrefs
|
accountId, controllerId, stashId, nextKeyFor, stakingLedger, nominators, rewardDestination, stakers, validatorPrefs
|
||||||
})
|
})
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
type MultiResultV2 = [[Vec<AccountId>] | Option<ITuple<[Nominations]>>, RewardDestination, Exposure, [ValidatorPrefs], Option<Keys>, Option<StakingLedger>];
|
type MultiResultV2 = [[Vec<AccountId>] | Option<ITuple<[Nominations]>>, RewardDestination, Exposure, [ValidatorPrefs], Option<Keys>, Option<StakingLedger>];
|
||||||
|
|
||||||
function retrieveInfoV2 (api: ApiInterfaceRx, accountId: AccountId, stashId: AccountId, controllerId: AccountId): Observable<DerivedStaking> {
|
function retrieveInfoV2 (api: ApiInterfaceRx, accountId: AccountId, stashId: AccountId, controllerId: AccountId): Observable<DerivedStakingQuery> {
|
||||||
return combineLatest([
|
return combineLatest([
|
||||||
api.derive.session.info(),
|
|
||||||
api.query.session.queuedKeys<Vec<ITuple<[AccountId, Keys]>>>(),
|
api.query.session.queuedKeys<Vec<ITuple<[AccountId, Keys]>>>(),
|
||||||
api.queryMulti([
|
api.queryMulti([
|
||||||
[api.query.staking.nominators, stashId],
|
[api.query.staking.nominators, stashId],
|
||||||
@@ -175,7 +102,7 @@ function retrieveInfoV2 (api: ApiInterfaceRx, accountId: AccountId, stashId: Acc
|
|||||||
[api.query.session.nextKeys, [api.consts.session.dedupKeyPrefix, stashId]],
|
[api.query.session.nextKeys, [api.consts.session.dedupKeyPrefix, stashId]],
|
||||||
[api.query.staking.ledger, controllerId]
|
[api.query.staking.ledger, controllerId]
|
||||||
]) as Observable<MultiResultV2>
|
]) as Observable<MultiResultV2>
|
||||||
]).pipe(map(([sessionInfo, queuedKeys, [_nominators, rewardDestination, stakers, [validatorPrefs], nextKeys, stakingLedger]]: [DerivedSessionInfo, [AccountId, Keys][], MultiResultV2]): DerivedStaking => {
|
]).pipe(map(([queuedKeys, [_nominators, rewardDestination, stakers, [validatorPrefs], nextKeys, stakingLedger]]: [[AccountId, Keys][], MultiResultV2]): DerivedStakingQuery => {
|
||||||
// if we have staking.storageVersion it indicates the new structure, unwrap as needed
|
// if we have staking.storageVersion it indicates the new structure, unwrap as needed
|
||||||
// FIXME We really want to be pulling all the new (valuable) info along
|
// FIXME We really want to be pulling all the new (valuable) info along
|
||||||
const nominators: AccountId[] = api.query.staking.storageVersion
|
const nominators: AccountId[] = api.query.staking.storageVersion
|
||||||
@@ -185,17 +112,17 @@ function retrieveInfoV2 (api: ApiInterfaceRx, accountId: AccountId, stashId: Acc
|
|||||||
: (_nominators as [Vec<AccountId>])[0];
|
: (_nominators as [Vec<AccountId>])[0];
|
||||||
|
|
||||||
return parseResult(api, {
|
return parseResult(api, {
|
||||||
accountId, controllerId, stashId, sessionInfo, queuedKeys, stakingLedger, nominators, rewardDestination, stakers, validatorPrefs, nextKeys
|
accountId, controllerId, stashId, queuedKeys, stakingLedger, nominators, rewardDestination, stakers, validatorPrefs, nextKeys
|
||||||
});
|
});
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
function retrieveV1 (api: ApiInterfaceRx, accountId: AccountId): Observable<DerivedStaking> {
|
function retrieveV1 (api: ApiInterfaceRx, accountId: AccountId): Observable<DerivedStakingQuery> {
|
||||||
// depending on where we come from, this may be a controller or stash
|
// depending on where we come from, this may be a controller or stash
|
||||||
return combineLatest([
|
return combineLatest([
|
||||||
api.query.staking.bonded<Option<AccountId>>(accountId),
|
api.query.staking.bonded<Option<AccountId>>(accountId),
|
||||||
api.query.staking.ledger<Option<StakingLedger>>(accountId)
|
api.query.staking.ledger<Option<StakingLedger>>(accountId)
|
||||||
]).pipe(switchMap(([bonded, stakingLedger]): Observable<DerivedStaking> =>
|
]).pipe(switchMap(([bonded, stakingLedger]): Observable<DerivedStakingQuery> =>
|
||||||
stakingLedger.isSome
|
stakingLedger.isSome
|
||||||
? retrieveInfoV1(api, accountId, stakingLedger.unwrap().stash, accountId)
|
? retrieveInfoV1(api, accountId, stakingLedger.unwrap().stash, accountId)
|
||||||
: bonded.isSome
|
: bonded.isSome
|
||||||
@@ -204,10 +131,10 @@ function retrieveV1 (api: ApiInterfaceRx, accountId: AccountId): Observable<Deri
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
function retrieveV2 (api: ApiInterfaceRx, stashId: AccountId): Observable<DerivedStaking> {
|
function retrieveV2 (api: ApiInterfaceRx, stashId: AccountId): Observable<DerivedStakingQuery> {
|
||||||
return api.query.staking
|
return api.query.staking
|
||||||
.bonded<Option<AccountId>>(stashId)
|
.bonded<Option<AccountId>>(stashId)
|
||||||
.pipe(switchMap((controllerId): Observable<DerivedStaking> =>
|
.pipe(switchMap((controllerId): Observable<DerivedStakingQuery> =>
|
||||||
controllerId.isSome
|
controllerId.isSome
|
||||||
? retrieveInfoV2(api, stashId, stashId, controllerId.unwrap())
|
? retrieveInfoV2(api, stashId, stashId, controllerId.unwrap())
|
||||||
: of({ accountId: stashId, nextSessionIds: [], sessionIds: [] })
|
: of({ accountId: stashId, nextSessionIds: [], sessionIds: [] })
|
||||||
@@ -217,11 +144,11 @@ function retrieveV2 (api: ApiInterfaceRx, stashId: AccountId): Observable<Derive
|
|||||||
/**
|
/**
|
||||||
* @description From a stash, retrieve the controllerId and fill in all the relevant staking details
|
* @description From a stash, retrieve the controllerId and fill in all the relevant staking details
|
||||||
*/
|
*/
|
||||||
export function info (api: ApiInterfaceRx): (_accountId: Uint8Array | string) => Observable<DerivedStaking> {
|
export function query (api: ApiInterfaceRx): (_accountId: Uint8Array | string) => Observable<DerivedStakingQuery> {
|
||||||
const query = api.consts.session
|
const retrieve = api.consts.session
|
||||||
? retrieveV2
|
? retrieveV2
|
||||||
: retrieveV1;
|
: retrieveV1;
|
||||||
|
|
||||||
return memo((accountId: Uint8Array | string): Observable<DerivedStaking> =>
|
return memo((accountId: Uint8Array | string): Observable<DerivedStakingQuery> =>
|
||||||
query(api, createType(api.registry, 'AccountId', accountId)));
|
retrieve(api, createType(api.registry, 'AccountId', accountId)));
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
export * from './proposals';
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
// 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 { DerivedCollectiveProposals } from '../types';
|
||||||
|
|
||||||
|
import { Observable } from 'rxjs';
|
||||||
|
import { proposals as collectiveProposals } from '../collective';
|
||||||
|
import { memo } from '../util';
|
||||||
|
|
||||||
|
export function proposals (api: ApiInterfaceRx): () => Observable<DerivedCollectiveProposals> {
|
||||||
|
return memo(collectiveProposals(api, 'technicalCommittee'));
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
export * from './proposals';
|
||||||
@@ -0,0 +1,97 @@
|
|||||||
|
// 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 { ProposalIndex, TreasuryProposal } from '@polkadot/types/interfaces';
|
||||||
|
import { DerivedCollectiveProposals, DerivedTreasuryProposal, DerivedTreasuryProposals } from '../types';
|
||||||
|
|
||||||
|
import { Observable, combineLatest, of } from 'rxjs';
|
||||||
|
import { map, switchMap } from 'rxjs/operators';
|
||||||
|
import { createType, Option } from '@polkadot/types';
|
||||||
|
|
||||||
|
import { memo } from '../util';
|
||||||
|
|
||||||
|
interface Result {
|
||||||
|
allIds: ProposalIndex[];
|
||||||
|
allProposals: Option<TreasuryProposal>[];
|
||||||
|
approvalIds: ProposalIndex[];
|
||||||
|
councilProposals: DerivedCollectiveProposals;
|
||||||
|
proposalCount: ProposalIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
function parseResult (_api: ApiInterfaceRx, { allIds, allProposals, approvalIds, councilProposals, proposalCount }: Result): DerivedTreasuryProposals {
|
||||||
|
const approvals: DerivedTreasuryProposal[] = [];
|
||||||
|
const proposals: DerivedTreasuryProposal[] = [];
|
||||||
|
const councilTreasury = councilProposals.filter(({ proposal: { methodName, sectionName } }): boolean =>
|
||||||
|
sectionName === 'treasury' &&
|
||||||
|
['approveProposal', 'rejectProposal'].includes(methodName)
|
||||||
|
);
|
||||||
|
|
||||||
|
allIds.forEach((id, index): void => {
|
||||||
|
if (allProposals[index].isSome) {
|
||||||
|
const council = councilTreasury
|
||||||
|
.filter(({ proposal }): boolean => id.eq(proposal.args[0]))
|
||||||
|
.sort((a, b): number => a.proposal.methodName.localeCompare(b.proposal.methodName));
|
||||||
|
const isApproval = approvalIds.some((approvalId): boolean => approvalId.eq(id));
|
||||||
|
const derived = { council, id, proposal: allProposals[index].unwrap() };
|
||||||
|
|
||||||
|
if (isApproval) {
|
||||||
|
approvals.push(derived);
|
||||||
|
} else {
|
||||||
|
proposals.push(derived);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return { approvals, proposalCount, proposals };
|
||||||
|
}
|
||||||
|
|
||||||
|
function retrieveProposals (api: ApiInterfaceRx, proposalCount: ProposalIndex, approvalIds: ProposalIndex[]): Observable<DerivedTreasuryProposals> {
|
||||||
|
const proposalIds: ProposalIndex[] = [];
|
||||||
|
const count = proposalCount.toNumber();
|
||||||
|
|
||||||
|
for (let index = 0; index < count; index++) {
|
||||||
|
const isApproval = approvalIds.some((id): boolean => id.eqn(index));
|
||||||
|
|
||||||
|
if (!isApproval) {
|
||||||
|
proposalIds.push(createType(api.registry, 'ProposalIndex', index));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const allIds = [...proposalIds, ...approvalIds];
|
||||||
|
|
||||||
|
return combineLatest([
|
||||||
|
// We are doing single subscriptions on all these, multi may yield old results
|
||||||
|
combineLatest(
|
||||||
|
allIds.map((id): Observable<Option<TreasuryProposal>> => api.query.treasury.proposals(id))
|
||||||
|
),
|
||||||
|
api.derive.council.proposals()
|
||||||
|
]).pipe(
|
||||||
|
map(([allProposals, councilProposals]: [Option<TreasuryProposal>[], DerivedCollectiveProposals]): DerivedTreasuryProposals =>
|
||||||
|
parseResult(api, { allIds, allProposals, approvalIds, councilProposals, proposalCount })
|
||||||
|
)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Retrieve all active and approved treasury proposals, along with their info
|
||||||
|
*/
|
||||||
|
export function proposals (api: ApiInterfaceRx): () => Observable<DerivedTreasuryProposals> {
|
||||||
|
return memo((): Observable<DerivedTreasuryProposals> =>
|
||||||
|
api.query.treasury
|
||||||
|
? combineLatest([
|
||||||
|
api.query.treasury.proposalCount(),
|
||||||
|
api.query.treasury.approvals()
|
||||||
|
]).pipe(
|
||||||
|
switchMap(([proposalCount, approvalIds]: [ProposalIndex, ProposalIndex[]]) =>
|
||||||
|
retrieveProposals(api, proposalCount, approvalIds)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
: of({
|
||||||
|
approvals: [],
|
||||||
|
proposalCount: createType(api.registry, 'ProposalIndex'),
|
||||||
|
proposals: []
|
||||||
|
} as DerivedTreasuryProposals)
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,32 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
import { AccountId, AccountIndex, Balance, BalanceLock, BlockNumber, EraIndex, EraPoints, Exposure, Hash, Index, Keys, Proposal, PropIndex, ReferendumInfo, RewardDestination, SessionIndex, SetIndex, StakingLedger, ValidatorPrefs, Vote, VoteIndex } from '@polkadot/types/interfaces';
|
import { AccountId, AccountIndex, Balance, BalanceLock, BlockNumber, EraIndex, EraPoints, Exposure, Hash, Index, Keys, Proposal, PropIndex, ProposalIndex, ReferendumInfo, RegistrationJudgement, RewardDestination, SessionIndex, SetIndex, StakingLedger, TreasuryProposal, ValidatorPrefs, Vote, Votes, VoteIndex } from '@polkadot/types/interfaces';
|
||||||
|
|
||||||
import BN from 'bn.js';
|
import BN from 'bn.js';
|
||||||
import { u32, Vec } from '@polkadot/types';
|
import { u32, Vec } from '@polkadot/types';
|
||||||
|
|
||||||
export type AccountIndexes = Record<string, AccountIndex>;
|
export type AccountIndexes = Record<string, AccountIndex>;
|
||||||
|
|
||||||
|
export interface DeriveAccountRegistration {
|
||||||
|
display?: string;
|
||||||
|
displayParent?: string;
|
||||||
|
email?: string;
|
||||||
|
image?: string;
|
||||||
|
legal?: string;
|
||||||
|
parent?: AccountId;
|
||||||
|
pgp?: string;
|
||||||
|
riot?: string;
|
||||||
|
twitter?: string;
|
||||||
|
web?: string;
|
||||||
|
judgements: RegistrationJudgement[];
|
||||||
|
}
|
||||||
|
|
||||||
export interface DeriveAccountInfo {
|
export interface DeriveAccountInfo {
|
||||||
accountId?: AccountId;
|
accountId?: AccountId;
|
||||||
accountIndex?: AccountIndex;
|
accountIndex?: AccountIndex;
|
||||||
|
identity: DeriveAccountRegistration;
|
||||||
nickname?: string;
|
nickname?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -44,6 +59,14 @@ export interface DerivedContractFees {
|
|||||||
transferFee: BN;
|
transferFee: BN;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface DerivedCollectiveProposal {
|
||||||
|
hash: Hash;
|
||||||
|
proposal: Proposal;
|
||||||
|
votes: Votes | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DerivedCollectiveProposals = DerivedCollectiveProposal[];
|
||||||
|
|
||||||
export interface DerivedElectionsInfo {
|
export interface DerivedElectionsInfo {
|
||||||
candidates: AccountId[];
|
candidates: AccountId[];
|
||||||
candidateCount: u32;
|
candidateCount: u32;
|
||||||
@@ -126,24 +149,9 @@ export interface DerivedSessionInfo extends DeriveSessionIndexes {
|
|||||||
sessionProgress: BlockNumber;
|
sessionProgress: BlockNumber;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DerivedStakingAccount = [AccountId, DerivedStakingOnlineStatus];
|
|
||||||
|
|
||||||
export type DerivedStakingAccounts = DerivedStakingAccount[];
|
|
||||||
|
|
||||||
export interface DerivedStakingElected {
|
export interface DerivedStakingElected {
|
||||||
currentElected: AccountId[];
|
currentElected: AccountId[];
|
||||||
info: DerivedStaking[];
|
info: DerivedStakingQuery[];
|
||||||
}
|
|
||||||
|
|
||||||
export interface DerivedStakingOnlineStatus {
|
|
||||||
online?: {
|
|
||||||
isOnline: boolean;
|
|
||||||
blockNumber?: BlockNumber;
|
|
||||||
};
|
|
||||||
offline?: {
|
|
||||||
blockNumber: BlockNumber;
|
|
||||||
count: BN;
|
|
||||||
}[];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DeriveStakingValidators {
|
export interface DeriveStakingValidators {
|
||||||
@@ -161,12 +169,15 @@ export interface DerivedStakingStash {
|
|||||||
validatorPrefs?: ValidatorPrefs;
|
validatorPrefs?: ValidatorPrefs;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DerivedStaking extends DerivedStakingOnlineStatus, DerivedStakingStash {
|
export interface DerivedStakingQuery extends DerivedStakingStash {
|
||||||
accountId: AccountId;
|
accountId: AccountId;
|
||||||
nextSessionIds: AccountId[];
|
nextSessionIds: AccountId[];
|
||||||
redeemable?: Balance;
|
|
||||||
sessionIds: AccountId[];
|
sessionIds: AccountId[];
|
||||||
stakingLedger?: StakingLedger;
|
stakingLedger?: StakingLedger;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DerivedStakingAccount extends DerivedStakingQuery {
|
||||||
|
redeemable?: Balance;
|
||||||
unlocking?: DerivedUnlocking[];
|
unlocking?: DerivedUnlocking[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -176,7 +187,22 @@ export interface DerivedStakingOverview extends DeriveSessionIndexes {
|
|||||||
validators: AccountId[];
|
validators: AccountId[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export type DerivedUnlocking = { remainingBlocks: BlockNumber; value: Balance };
|
export interface DerivedTreasuryProposal {
|
||||||
|
council: DerivedCollectiveProposal[];
|
||||||
|
id: ProposalIndex;
|
||||||
|
proposal: TreasuryProposal;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface DerivedTreasuryProposals {
|
||||||
|
approvals: DerivedTreasuryProposal[];
|
||||||
|
proposalCount: ProposalIndex;
|
||||||
|
proposals: DerivedTreasuryProposal[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DerivedUnlocking = {
|
||||||
|
remainingBlocks: BlockNumber;
|
||||||
|
value: Balance;
|
||||||
|
};
|
||||||
|
|
||||||
export interface VoterPosition {
|
export interface VoterPosition {
|
||||||
globalIndex: BN;
|
globalIndex: BN;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
// Copyright 2017-2020 @polkadot/api-derive authors & contributors
|
||||||
// This software may be modified and distributed under the terms
|
// This software may be modified and distributed under the terms
|
||||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user