Compare commits

..
101 Commits
Author SHA1 Message Date
Github Actions 2ca79f2f70 [CI Skip] 0.100.1
skip-checks: true
2020-01-13 15:19:07 +00:00
Jaco Greeff 8fb64f77cd 0.100 (#1716) 2020-01-13 16:11:56 +01:00
Github Actions d1f86ce78e [CI Skip] 0.100.0-beta.30
skip-checks: true
2020-01-13 14:24:03 +00:00
Keith IngramandJaco Greeff 64ff226535 Fix api.derive.collective (#1711)
* fix api.derive.collective

* imports

* Update proposals.ts

Co-authored-by: Jaco Greeff <jacogr@gmail.com>
2020-01-13 15:17:04 +01:00
Github Actions e762746ff0 [CI Skip] 0.100.0-beta.29
skip-checks: true
2020-01-13 11:03:54 +00:00
Xiliang Chen ce5c8f7443 fix AssetOptions def (#1714) 2020-01-13 11:55:51 +01:00
Github Actions fc4cbb608c [CI Skip] 0.100.0-beta.28
skip-checks: true
2020-01-12 13:50:01 +00:00
Jaco Greeff 7ac3043f83 Extract sub identities (via accounts derive) (#1713)
* Extract sub identities

* Cleanups
2020-01-12 14:42:42 +01:00
Github Actions 44b56fb0cb [CI Skip] 0.100.0-beta.27
skip-checks: true
2020-01-10 15:06:03 +00:00
Jaco Greeff 758ce567e5 Failsafe on proposal decode (fallback ro preimage only) (#1710) 2020-01-10 15:58:56 +01:00
Github Actions cb5308b476 [CI Skip] 0.100.0-beta.26
skip-checks: true
2020-01-10 13:55:10 +00:00
Amaury Martiny a9211690be Remove v9->v10 hack (#1694)
* Remove v9->v10 hack

* Update static

* Update JSON
2020-01-10 14:47:06 +01:00
Github Actions a7db14a261 [CI Skip] 0.100.0-beta.25
skip-checks: true
2020-01-10 13:03:45 +00:00
Jaco Greeff 3a1f284fa8 Treasury OpenTip (#1708) 2020-01-10 13:56:05 +01:00
Github Actions a0b6c42629 [CI Skip] 0.100.0-beta.24
skip-checks: true
2020-01-10 11:10:20 +00:00
Jaco Greeff f77ae4d99f Add percent type (#1707) 2020-01-10 12:02:35 +01:00
Github Actions 5fa9af8fd3 [CI Skip] 0.100.0-beta.23
skip-checks: true
2020-01-10 10:32:55 +00:00
Jaco Greeff 1ff029dc11 Update IdentityInfo with twitter field (#1706)
* Update IdentityInfo with twitter field

* Rebuild

* Update test with twitter
2020-01-10 11:25:10 +01:00
Github Actions 4c8c9fbb07 [CI Skip] 0.100.0-beta.22
skip-checks: true
2020-01-09 13:47:13 +00:00
Jaco Greeff 7057cf365b Add paymentInfo to submittables (#1582)
* Add paymentInfo to submittables

* Cleanup paymentInfo call

* Use 0x42...42 dummy sigs

* Re-add paymentInfo to submittable

* Add correct signFake interfaces

* CHANGELOG
2020-01-09 14:40:25 +01:00
Github Actions d1bc48e936 [CI Skip] 0.100.0-beta.21
skip-checks: true
2020-01-09 11:07:18 +00:00
Jaco Greeff 2dee50f019 Bump deps (#1704) 2020-01-09 11:59:21 +01:00
Github Actions fa76378702 [CI Skip] 0.100.0-beta.20
skip-checks: true
2020-01-08 08:29:06 +00:00
Jaco Greeff e855da1f13 Make a start at the Polkadot launch types (#1700)
* Make a start at the Polkadot launch types

* Add missing old DispatchInfo
2020-01-08 09:21:23 +01:00
Github Actions adffde368c [CI Skip] 0.100.0-beta.19
skip-checks: true
2020-01-07 09:01:45 +00:00
Jaco Greeff 5278138cc3 Make submittable signAsync Observable-aware (#1698)
* Make submittable signAsync Observable-aware

* rxjs test for signAsync

* Cleanup tests, pass signer in .create

* Simplify Observable creation
2020-01-07 09:54:04 +01:00
Github Actions 98249a282e [CI Skip] 0.100.0-beta.18
skip-checks: true
2020-01-06 13:20:39 +00:00
Jaco Greeff b7eeb992cd Bump deps (#1699) 2020-01-06 14:12:49 +01:00
Github Actions 01daf32646 [CI Skip] 0.100.0-beta.17
skip-checks: true
2020-01-03 16:45:58 +00:00
Amaury Martiny 51a866fd35 Update kusama static from 1032 to 1033 (#1696)
* Update kusama static from 1032 to 1033

* Update comment

* Rename variables

* Test 1032 and 1033

* Got exact metadata from kusama
2020-01-03 17:38:32 +01:00
Github Actions 53401e29ea [CI Skip] 0.100.0-beta.16
skip-checks: true
2020-01-03 11:13:30 +00:00
Amaury Martiny 774f41e6db Only apply hack if exactly metadata from kusama 1032 (#1695) 2020-01-03 12:05:27 +01:00
Github Actions 1ca3b295a4 [CI Skip] 0.100.0-beta.15
skip-checks: true
2020-01-02 17:11:51 +00:00
Keith IngramandAmaury Martiny 82828d8e09 Add metadata v10/11, blake2_128concat hasher (#1691)
* v11, blake2_128concat

* MetadataAll

* Add storage hasher v4 and v10

* Make lint pass

* Add correct interfaces

* Fix lint

* Update metadata definitions

* Update v10 metadata

* Update packages/types/src/interfaces/utility/definitions.ts

* Update v11

* Add HACK

* Skip v9 tests (part of HACK)

* Correct function names

Co-authored-by: Amaury Martiny <amaury.martiny@protonmail.com>
2020-01-02 18:04:42 +01:00
Github Actions 131055c1d5 [CI Skip] 0.100.0-beta.14
skip-checks: true
2019-12-20 10:04:22 +00:00
Jaco Greeff bd2e690261 Update DispatchError for Kusama (#1686) 2019-12-20 10:57:37 +01:00
Github Actions 1a2ca8ea38 [CI Skip] 0.100.0-beta.13
skip-checks: true
2019-12-19 14:44:19 +00:00
Jaco Greeff 0c98593aee Update DispatchError as enum (#1682)
* Update DispatchError as enum

* Add DispatchResult

* Update tests for DispatchResult

* Rebuild
2019-12-19 15:37:36 +01:00
Github Actions 416e2fbc96 [CI Skip] 0.100.0-beta.12
skip-checks: true
2019-12-19 13:14:08 +00:00
Jaco Greeff c04fb9073e Don't query proposal via multi (#1683) 2019-12-19 14:07:23 +01:00
Github Actions 4f85ceb2c3 [CI Skip] 0.100.0-beta.11
skip-checks: true
2019-12-19 10:09:06 +00:00
Jaco Greeff 9196ce85a0 Expand identity derive fields (incl. all) (#1680) 2019-12-19 11:00:47 +01:00
Github Actions 26734bf8bf [CI Skip] 0.100.0-beta.10
skip-checks: true
2019-12-18 15:30:04 +00:00
satellitex 53959d482d Add BTreeSet<V> Codec (#1639)
* add BTreeSet Codec

* Add following BTreeMap

* fix linting

* fix linting

* add validate Types and encode Types

* type def info is incremented.

* fix compareSet
2019-12-18 16:22:54 +01:00
Github Actions 0a0f110c42 [CI Skip] 0.100.0-beta.9
skip-checks: true
2019-12-17 16:28:01 +00:00
Keith Ingram 47f1350652 Additional rpcContractCall guard (#1677)
* additional rpc guard

* isFunction

* isFunction
2019-12-17 17:21:19 +01:00
Github Actions 3c3b7290c2 [CI Skip] 0.100.0-beta.8
skip-checks: true
2019-12-17 14:40:40 +00:00
Jaco Greeff 006c686c18 Fix linked maps with optional entries (#1676)
* Fix linked maps with optional entries

* Revert entries() change for linked maps
2019-12-17 15:33:45 +01:00
Github Actions 44d4a07005 [CI Skip] 0.100.0-beta.7
skip-checks: true
2019-12-16 11:41:13 +00:00
Github Actions 6e61be960c [CI Skip] 0.100.0-beta.6
skip-checks: true
2019-12-16 11:02:37 +00:00
Jaco Greeff bd57359dc5 Cleanuop preimage check (#1674) 2019-12-16 11:56:42 +01:00
Github Actions 10bc6b4060 [CI Skip] 0.100.0-beta.5
skip-checks: true
2019-12-16 09:49:08 +00:00
Jaco Greeff 9e681c0666 Update .123trigger 2019-12-16 10:42:04 +01:00
Github Actions e969382fd0 [CI Skip] 0.100.0-beta.4
skip-checks: true
2019-12-16 09:36:41 +00:00
Jaco Greeff 1949a13810 Update .123trigger 2019-12-16 10:30:18 +01:00
Github Actions 362262c4e1 [CI Skip] 0.100.0-beta.3
skip-checks: true
2019-12-15 20:44:20 +00:00
Keith Ingram ddd5eab7f5 collective proposals (#1671) 2019-12-15 15:37:27 -05:00
Github Actions 1da6193f34 [CI Skip] 0.100.0-beta.2
skip-checks: true
2019-12-15 11:22:45 +00:00
Jaco Greeff c4e553ad80 Add identity names to derive.accounts.info (#1673) 2019-12-15 12:16:17 +01:00
Github Actions 0b83a61600 [CI Skip] 0.100.0-beta.1
skip-checks: true
2019-12-15 09:04:04 +00:00
Jaco Greeff 382f7d75c8 Data has custom encodedLength 2019-12-15 09:56:30 +01:00
Github Actions 88e4518f64 [CI Skip] 0.100.0-beta.0
skip-checks: true
2019-12-15 07:50:37 +00:00
Jaco Greeff b1a657d68a Custom encoding for identity Data (#1672)
* Custom encoding for identity Data

* Custom encoding for IdentityFields

* Allow empty U8a input to Data

* IdentityField tests
2019-12-15 08:43:22 +01:00
Jaco Greeff 067f17b28b Enum with single-entry encoding (#1670)
* Enum with single-entry encoding

* Expand test with breakdown
2019-12-13 11:19:38 +01:00
Github Actions 99073e2a88 [CI Skip] 0.99.1
skip-checks: true
2019-12-13 09:33:27 +00:00
Jaco Greeff f9a42e47e7 0.99 (#1669)
* 0.99

* Rewrite yarn.lock
2019-12-13 10:26:41 +01:00
Github Actions b80d72edbd [CI Skip] 0.99.0-beta.16
skip-checks: true
2019-12-12 06:51:19 +00:00
Jaco Greeff 1f7b9f7f3a democracy.lowestUnbaked (#1665) 2019-12-12 07:43:56 +01:00
Github Actions 843efb2146 [CI Skip] 0.99.0-beta.15
skip-checks: true
2019-12-11 17:24:47 +00:00
Jaco Greeff 3619fabe5f Update .123trigger 2019-12-11 18:17:29 +01:00
Github Actions bf598e392e [CI Skip] 0.99.0-beta.14
skip-checks: true
2019-12-11 16:43:19 +00:00
Jaco Greeff f026137545 Chace down more phantoms (#1664) 2019-12-11 17:35:57 +01:00
Github Actions 2264f53a43 [CI Skip] 0.99.0-beta.13
skip-checks: true
2019-12-09 22:09:01 +00:00
Jaco Greeff 8ba4029633 Fix elections typo 2019-12-09 23:01:46 +01:00
Github Actions 05cb2cef5a [CI Skip] 0.99.0-beta.12
skip-checks: true
2019-12-09 21:12:47 +00:00
Keith Ingram 3a70594594 Combine elections.info derive (#1659)
* Combine elections.info derive

* remove tests
2019-12-09 22:05:56 +01:00
Github Actions 019cb58dd1 [CI Skip] 0.99.0-beta.11
skip-checks: true
2019-12-09 19:43:53 +00:00
Jaco Greeff d487490ca0 Identity types (#1658)
* Identity types

* Refine findMeta* error outputs

* Cleanups, don't return crappy info, fail

* Revert callIndex with size alloc
2019-12-09 20:36:52 +01:00
Github Actions b9fad61da0 [CI Skip] 0.99.0-beta.10
skip-checks: true
2019-12-09 17:24:49 +00:00
Jaco Greeff 77bf33b4e4 Derive with optional democracy (#1657)
* Derive with optional democracy

* Cleanup optionals

* Multi for preimage retrievals

* Convert indexes to hex before lookup
2019-12-09 18:17:41 +01:00
Github Actions 7ed7c9d3a8 [CI Skip] 0.99.0-beta.9
skip-checks: true
2019-12-09 14:44:41 +00:00
Jaco Greeff 0d2896630d Replace Data/U8a with un-aliassed Raw (#1656)
* Replace Data with un-aliassed U8a

* Export U8a

* Explicitly add U8a to the registry

* U8a -> Raw
2019-12-09 15:38:07 +01:00
Github Actions 74dbff32df [CI Skip] 0.99.0-beta.8
skip-checks: true
2019-12-09 13:24:56 +00:00
Jaco Greeff 4653cc0d84 Add council & treasury derives (#1654) 2019-12-09 14:18:13 +01:00
Github Actions 50e115f6a1 [CI Skip] 0.99.0-beta.7
skip-checks: true
2019-12-09 09:22:19 +00:00
Jaco Greeff 8a5a86e8b3 Better performant per-account staking queries (#1652)
* Better performant per-account staking queries

* Rename retrieval (no confusion)

* staking.info -> staking.account

* Update .info test
2019-12-09 10:14:51 +01:00
Jaco Greeff 48ef5af93f Add missing BTreeMap is metadata checking (#1653) 2019-12-09 10:14:12 +01:00
Github Actions e5c20be666 [CI Skip] 0.99.0-beta.6
skip-checks: true
2019-12-09 07:44:00 +00:00
Jaco Greeff 6bf0d5eea9 DoubleMap hashing over full value (#1650)
* DoubleMap hashing over full value

* Expand Bytes tests

* Expand

* Hashing test with soublemaps

* Small extra test comments
2019-12-09 08:37:47 +01:00
Github Actions 21c57b60a1 [CI Skip] 0.99.0-beta.5
skip-checks: true
2019-12-07 22:07:10 +00:00
Keith Ingram b1dff22954 Fix encodeWithParams for only valid types (#1644)
* fix param display

* space
2019-12-07 23:00:02 +01:00
Github Actions a3d0cb0999 [CI Skip] 0.99.0-beta.4
skip-checks: true
2019-12-07 13:18:44 +00:00
Jaco Greeff bf946c20db Latest metadata (#1647)
* Latest metadata

* Updte static version (v9)

* Update tests for new storage keys

* Bump deps

* Bump extra

* Case, V8 -> v8
2019-12-07 14:13:20 +01:00
Github Actions 664d2c8ab6 [CI Skip] 0.99.0-beta.3
skip-checks: true
2019-12-05 18:56:23 +00:00
Jaco Greeff 01a4d6b4a9 Remove RPC data toU8a (#1643) 2019-12-05 19:49:50 +01:00
Github Actions 18454083db [CI Skip] 0.99.0-beta.2
skip-checks: true
2019-12-05 12:01:09 +00:00
Jaco Greeff 191abe4e08 Cleanup Text from U8a (wrapper class) (#1642)
* Cleanup Text from U8a (wrapper class)

* U8a test
2019-12-05 12:54:52 +01:00
Github Actions 97fbb4732d [CI Skip] 0.99.0-beta.1
skip-checks: true
2019-12-05 10:16:01 +00:00
Jaco Greeff 01f3666cc7 Bump deps (#1641)
* Bump deps

* Linting
2019-12-05 11:09:27 +01:00
Github Actions 468fcdccaa [CI Skip] 0.99.0-beta.0
skip-checks: true
2019-12-04 14:53:39 +00:00
Jaco Greeff c8dd26b0da Remove debug logs (#1637) 2019-12-04 15:46:56 +01:00
534 changed files with 20343 additions and 5684 deletions
+1 -1
View File
@@ -1 +1 @@
13
16
+1
View File
@@ -12,6 +12,7 @@ tmp/
.env.production.local
.npmrc
.rpt2_cache
.vscode/
cc-test-reporter
lerna-debug.log*
npm-debug.log*
+22 -2
View File
@@ -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
- 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 `.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
- Support for new Substrate democracy with preimages in derive
- Alignment of types with Substrate/Polkadot master branches
+1 -1
View File
@@ -9,5 +9,5 @@
"packages": [
"packages/*"
],
"version": "0.98.1"
"version": "0.100.1"
}
+7 -7
View File
@@ -1,5 +1,5 @@
{
"version": "0.98.1",
"version": "0.100.1",
"private": true,
"engines": {
"yarn": "^1.10.1"
@@ -9,7 +9,7 @@
],
"resolutions": {
"babel-core": "^7.0.0-bridge.0",
"typescript": "^3.7.2"
"typescript": "^3.7.4"
},
"scripts": {
"build": "yarn build:interfaces && polkadot-dev-build-ts",
@@ -29,10 +29,10 @@
"test:watch": "jest --coverage --watch"
},
"devDependencies": {
"@babel/core": "^7.7.4",
"@babel/register": "^7.7.4",
"@babel/runtime": "^7.7.4",
"@polkadot/dev": "^0.32.0-beta.15",
"@polkadot/ts": "^0.1.86"
"@babel/core": "^7.7.7",
"@babel/register": "^7.7.7",
"@babel/runtime": "^7.7.7",
"@polkadot/dev": "^0.32.14",
"@polkadot/ts": "^0.1.90"
}
}
+3 -3
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-contract",
"version": "0.98.1",
"version": "0.100.1",
"description": "Interfaces for interacting with contracts and contract ABIs",
"main": "index.js",
"keywords": [
@@ -26,7 +26,7 @@
},
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
"dependencies": {
"@babel/runtime": "^7.7.4",
"@polkadot/types": "^0.98.1"
"@babel/runtime": "^7.7.7",
"@polkadot/types": "^0.100.1"
}
}
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// 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
// 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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+3 -3
View File
@@ -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
// 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 {
send: this.decorateMethod(
as === 'rpc'
as === 'rpc' && this.hasRpcContractsCall
? (account: IKeyringPair | string | AccountId | Address): ContractCallResult<'rpc'> => {
return this.rpcContractsCall(
createType(this.registry, 'ContractCallRequest', {
@@ -75,7 +75,7 @@ export default class Contract<ApiType extends ApiTypes> extends BaseWithTxAndRpc
output = message.returnType
? formatData(this.registry, data, message.returnType)
: createType(this.registry, 'Data', data);
: createType(this.registry, 'Raw', data);
}
return {
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+8 -8
View File
@@ -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
// 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 { Registry } from '@polkadot/types/types';
import { assert, stringCamelCase } from '@polkadot/util';
import { assert, isFunction, stringCamelCase } from '@polkadot/util';
import Abi from '../Abi';
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> {
public get hasRpcContractsCall (): boolean {
return isFunction(this.api.rx.rpc.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;
}
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 -1
View File
@@ -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
// 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
// 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
// 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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+5 -7
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
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';
export function formatData (registry: Registry, data: Data, { info, type }: TypeDef): Codec {
const u8a = data.toU8a();
export function formatData (registry: Registry, data: Raw, { info, type }: TypeDef): Codec {
if (info === TypeDefInfo.Option) {
return new Option(
registry,
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])}}}",
"name": "Flipper",
"namespace": "flipper::normal",
"sub": [
{
"info": 7,
"info": 8,
"type": "{\"cell\": {\"cell\": ([u8;32])}}",
"name": "value",
"namespace": "ink_core::storage::value",
"params": [
{
"info": 5,
"info": 6,
"type": "bool"
}
],
"sub": [
{
"info": 7,
"info": 8,
"type": "{\"cell\": ([u8;32])}",
"name": "cell",
"namespace": "ink_core::storage::cell::sync_cell",
"params": [
{
"info": 5,
"info": 6,
"type": "bool"
}
],
"sub": [
{
"info": 8,
"info": 9,
"type": "([u8;32])",
"name": "cell",
"namespace": "ink_core::storage::key",
"sub": [
{
"info": 10,
"info": 11,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": ""
},
"sub": {
"info": 5,
"info": 6,
"type": "u8"
},
"index": 0
@@ -57,44 +57,44 @@
]
},
{
"info": 7,
"info": 8,
"type": "{\"cell\": {\"cell\": ([u8;32])}}",
"name": "Value",
"namespace": "ink_core::storage::value",
"params": [
{
"info": 5,
"info": 6,
"type": "bool"
}
],
"sub": [
{
"info": 7,
"info": 8,
"type": "{\"cell\": ([u8;32])}",
"name": "cell",
"namespace": "ink_core::storage::cell::sync_cell",
"params": [
{
"info": 5,
"info": 6,
"type": "bool"
}
],
"sub": [
{
"info": 8,
"info": 9,
"type": "([u8;32])",
"name": "cell",
"namespace": "ink_core::storage::key",
"sub": [
{
"info": 10,
"info": 11,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": ""
},
"sub": {
"info": 5,
"info": 6,
"type": "u8"
},
"index": 0
@@ -106,36 +106,36 @@
]
},
{
"info": 5,
"info": 6,
"type": "bool"
},
{
"info": 7,
"info": 8,
"type": "{\"cell\": ([u8;32])}",
"name": "SyncCell",
"namespace": "ink_core::storage::cell::sync_cell",
"params": [
{
"info": 5,
"info": 6,
"type": "bool"
}
],
"sub": [
{
"info": 8,
"info": 9,
"type": "([u8;32])",
"name": "cell",
"namespace": "ink_core::storage::key",
"sub": [
{
"info": 10,
"info": 11,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": ""
},
"sub": {
"info": 5,
"info": 6,
"type": "u8"
},
"index": 0
@@ -145,20 +145,20 @@
]
},
{
"info": 8,
"info": 9,
"type": "([u8;32])",
"name": "Key",
"namespace": "ink_core::storage::key",
"sub": [
{
"info": 10,
"info": 11,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": ""
},
"sub": {
"info": 5,
"info": 6,
"type": "u8"
},
"index": 0
@@ -166,19 +166,19 @@
]
},
{
"info": 10,
"info": 11,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": ""
},
"sub": {
"info": 5,
"info": 6,
"type": "u8"
}
},
{
"info": 5,
"info": 6,
"type": "u8"
}
]
@@ -1,29 +1,29 @@
[
{
"info": 9,
"info": 10,
"type": "{ \"value\": \"{ \"cell\": \"{ \"cell\": \"([u8;32])\"} }<u32>\"} }<u32>\"} }",
"sub": [
{
"info": 9,
"info": 10,
"type": "{ \"cell\": \"{ \"cell\": \"([u8;32])\"} }<u32>\"} }",
"sub": [
{
"info": 9,
"info": 10,
"type": "{ \"cell\": \"([u8;32])\"} }",
"sub": [
{
"info": 10,
"info": 11,
"type": "([u8;32])",
"sub": [
{
"info": 12,
"info": 13,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"sub": {
"info": 6,
"info": 7,
"type": "u8"
},
"index": 0
@@ -37,7 +37,7 @@
"namespace": "ink_core::storage::cell::sync_cell",
"params": [
{
"info": 6,
"info": 7,
"type": "u32"
}
]
@@ -47,7 +47,7 @@
"namespace": "ink_core::storage::value",
"params": [
{
"info": 6,
"info": 7,
"type": "u32"
}
]
@@ -57,26 +57,26 @@
"namespace": "incrementer::normal"
},
{
"info": 9,
"info": 10,
"type": "{ \"cell\": \"{ \"cell\": \"([u8;32])\"} }<u32>\"} }",
"sub": [
{
"info": 9,
"info": 10,
"type": "{ \"cell\": \"([u8;32])\"} }",
"sub": [
{
"info": 10,
"info": 11,
"type": "([u8;32])",
"sub": [
{
"info": 12,
"info": 13,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"sub": {
"info": 6,
"info": 7,
"type": "u8"
},
"index": 0
@@ -90,7 +90,7 @@
"namespace": "ink_core::storage::cell::sync_cell",
"params": [
{
"info": 6,
"info": 7,
"type": "u32"
}
]
@@ -100,32 +100,32 @@
"namespace": "ink_core::storage::value",
"params": [
{
"info": 6,
"info": 7,
"type": "u32"
}
]
},
{
"info": 6,
"info": 7,
"type": "u32"
},
{
"info": 9,
"info": 10,
"type": "{ \"cell\": \"([u8;32])\"} }",
"sub": [
{
"info": 10,
"info": 11,
"type": "([u8;32])",
"sub": [
{
"info": 12,
"info": 13,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"sub": {
"info": 6,
"info": 7,
"type": "u8"
},
"index": 0
@@ -139,24 +139,24 @@
"namespace": "ink_core::storage::cell::sync_cell",
"params": [
{
"info": 6,
"info": 7,
"type": "u32"
}
]
},
{
"info": 10,
"info": 11,
"type": "([u8;32])",
"sub": [
{
"info": 12,
"info": 13,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"sub": {
"info": 6,
"info": 7,
"type": "u8"
},
"index": 0
@@ -166,23 +166,23 @@
"namespace": "ink_core::storage::key"
},
{
"info": 12,
"info": 13,
"type": "[u8;32]",
"ext": {
"length": 32,
"type": "u8"
},
"sub": {
"info": 6,
"info": 7,
"type": "u8"
}
},
{
"info": 6,
"info": 7,
"type": "u8"
},
{
"info": 6,
"info": 7,
"type": "bool"
}
]
File diff suppressed because it is too large Load Diff
File diff suppressed because it is too large Load Diff
+5 -5
View File
@@ -1,6 +1,6 @@
{
"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.",
"main": "index.js",
"keywords": [
@@ -27,11 +27,11 @@
},
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
"dependencies": {
"@babel/runtime": "^7.7.4",
"@polkadot/api": "^0.98.1",
"@polkadot/types": "^0.98.1"
"@babel/runtime": "^7.7.7",
"@polkadot/api": "^0.100.1",
"@polkadot/types": "^0.100.1"
},
"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
// 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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// 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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+80 -8
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
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 { DeriveAccountInfo } from '../types';
import { DeriveAccountInfo, DeriveAccountRegistration } from '../types';
import { Observable, combineLatest, of } from 'rxjs';
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 { 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> {
return ((
accountId && api.query.nicks
accountId && api.query.nicks?.nameOf
? api.query.nicks.nameOf<Option<ITuple<[Bytes, Balance]>>>(accountId)
: of(undefined)
) 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
* @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> {
return memo((address?: AccountIndex | AccountId | Address | string | null): Observable<DeriveAccountInfo> =>
api.derive.accounts.idAndIndex(address).pipe(
switchMap(([accountId, accountIndex]): Observable<[DeriveAccountInfo, string?]> =>
switchMap(([accountId, accountIndex]): Observable<[Partial<DeriveAccountInfo>, DeriveAccountRegistration, string?]> =>
combineLatest([
of({ accountId, accountIndex }),
retrieveIdentity(api, accountId),
retrieveNick(api, accountId)
])
),
map(([{ accountId, accountIndex }, nickname]): DeriveAccountInfo => ({
accountId, accountIndex, nickname
map(([{ accountId, accountIndex }, identity, nickname]): DeriveAccountInfo => ({
accountId, accountIndex, identity, nickname
}))
));
}
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// 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
// 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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// 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
// 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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// 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
// 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 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+5
View File
@@ -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 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+62 -54
View File
@@ -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
// 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 { DeriveProposal } from '../types';
@@ -14,62 +14,70 @@ import { Bytes, Option, Vec, createType } from '@polkadot/types';
import { memo } from '../util';
export type PreImage = Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>;
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[]> {
return memo((): Observable<DeriveProposal[]> =>
api.query.democracy
.publicProps<Vec<ITuple<[PropIndex, Hash, AccountId]>>>()
.pipe(
switchMap((proposals) =>
combineLatest([
of(proposals),
combineLatest(
...proposals.map(([, hash]) =>
api.query.democracy.preimages<PreImage>(hash)
)
)
])
),
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]
};
})
api.query.democracy?.publicProps
? api.query.democracy
.publicProps<Proposals>()
.pipe(
switchMap((proposals) =>
combineLatest([
of(proposals),
api.query.democracy.preimages.multi<PreImage>(proposals.map(([, hash]): Hash => hash)),
api.query.democracy.depositOf.multi<Depositors>(proposals.map(([index]): PropIndex => index))
])
),
map(([proposals, preimages, depositors]): DeriveProposal[] =>
parse(api, { depositors, proposals, preimages })
)
)
)
: 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
// 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';
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
? _preimage.unwrap()
: 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> {
console.log(JSON.stringify(info));
return ((
info?.isSome
? 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
// 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
// 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
// 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[]> {
return memo((): Observable<DerivedReferendum[]> =>
api.queryMulti<[ReferendumIndex, ReferendumIndex]>([
api.query.democracy.nextTally,
api.query.democracy.referendumCount
]).pipe(
switchMap(([nextTally, referendumCount]): Observable<DerivedReferendum[]> =>
referendumCount && nextTally && referendumCount.gt(nextTally) && referendumCount.gtn(0)
? api.derive.democracy.referendumInfos(
[...Array(referendumCount.sub(nextTally).toNumber())].map((_, i): BN =>
nextTally.addn(i)
// V2 vs V1 (and early V2)
api.query.democracy?.lowestUnbaked || api.query.democracy?.nextTally
? api.queryMulti<[ReferendumIndex, ReferendumIndex]>([
api.query.democracy.lowestUnbaked || api.query.democracy.nextTally,
api.query.democracy.referendumCount
]).pipe(
switchMap(([earliest, referendumCount]): Observable<DerivedReferendum[]> =>
referendumCount?.gt(earliest) && referendumCount?.gtn(0)
? api.derive.democracy.referendumInfos(
[...Array(referendumCount.sub(earliest).toNumber())].map((_, i): BN =>
earliest.addn(i)
)
)
)
: of([])
: of([])
)
)
));
: of([] as DerivedReferendum[])
);
}
+1 -1
View File
@@ -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
// 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 -5
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
export * from './approvalsOf';
export * from './approvalsOfAt';
export * from './info';
export * from './voters';
export * from './voterPositions';
+15 -50
View File
@@ -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
// 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 { Observable, combineLatest } from 'rxjs';
@@ -13,40 +13,7 @@ import { createType, Vec, u32 } from '@polkadot/types';
import { DerivedElectionsInfo } from '../types';
import { memo } from '../util';
type ResultElectionsInner = [u32, u32, Vec<ITuple<[AccountId, BlockNumber]>>, SetIndex, BlockNumber, VoteIndex, SetIndex];
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 {
function deriveElections (api: ApiInterfaceRx, candidates: AccountId[], members: [AccountId, Balance][], runnersUp: [AccountId, Balance][], candidacyBond: Balance, desiredSeats: u32, termDuration: BlockNumber, votingBond: Balance): DerivedElectionsInfo {
return {
candidates,
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
// we are not using multi queries here, so empty array is empty (instead of space-filled)
return combineLatest([
api.query.electionsPhragmen.candidates<Vec<AccountId>>(),
api.query.electionsPhragmen.members<Vec<ITuple<[AccountId, Balance]>>>(),
api.query.electionsPhragmen.runnersUp<Vec<ITuple<[AccountId, Balance]>>>()
api.query[section].candidates<Vec<AccountId>>(),
api.query[section].members<Vec<ITuple<[AccountId, Balance]>>>(),
api.query[section].runnersUp<Vec<ITuple<[AccountId, Balance]>>>()
]).pipe(
map(([candidates, members, runnersUp]): DerivedElectionsInfo => derivePhragmen(
map(([candidates, members, runnersUp]): DerivedElectionsInfo => deriveElections(
api,
candidates,
members,
runnersUp,
api.consts.electionsPhragmen.candidacyBond as Balance,
api.consts.electionsPhragmen.desiredMembers as u32,
api.consts.electionsPhragmen.termDuration as BlockNumber,
api.consts.electionsPhragmen.votingBond as Balance
api.consts[section].candidacyBond as Balance,
api.consts[section].desiredMembers as u32,
api.consts[section].termDuration as BlockNumber,
api.consts[section].votingBond as Balance
))
);
}
@@ -94,9 +63,5 @@ function queryPhragmen (api: ApiInterfaceRx): Observable<DerivedElectionsInfo> {
* ```
*/
export function info (api: ApiInterfaceRx): () => Observable<DerivedElectionsInfo> {
return memo((): Observable<DerivedElectionsInfo> =>
api.query.electionsPhragmen
? queryPhragmen(api)
: queryElections(api)
);
return memo((): Observable<DerivedElectionsInfo> => 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 -1
View File
@@ -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
// 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
// of the Apache-2.0 license. See the LICENSE file for details.
+2 -6
View File
@@ -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
// 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', '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', 'voters', []);
testFunction(api)('session', 'eraLength', []);
testFunction(api)('session', 'eraProgress', []);
testFunction(api)('session', 'sessionProgress', []);
testFunction(api)('staking', 'info', []);
testFunction(api)('staking', 'account', []);
testFunction(api)('staking', 'recentlyOffline', []);
testFunction(api)('staking', 'controllers', []);
});
+5 -2
View File
@@ -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
// 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 chain from './chain';
import * as contracts from './contracts';
import * as council from './council';
import * as democracy from './democracy';
import * as elections from './elections';
import * as imOnline from './imOnline';
import * as session from './session';
import * as staking from './staking';
import * as technicalCommittee from './technicalCommittee';
import * as treasury from './treasury';
export * from './type';
@@ -56,7 +59,7 @@ function injectFunctions<AllSections> (api: ApiInterfaceRx, allSections: AllSect
}, {} 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>;
// FIXME The return type of this function should be {...ExactDerive, ...DeriveCustom}
+1 -1
View File
@@ -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
// 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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// 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
// of the Apache-2.0 license. See the LICENSE file for details.
+100
View File
@@ -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
// 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
// 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 { DerivedStaking, DerivedStakingElected } from '../types';
import { DerivedStakingQuery, DerivedStakingElected } from '../types';
import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
@@ -14,11 +14,11 @@ import { memo } from '../util';
export function electedInfo (api: ApiInterfaceRx): () => Observable<DerivedStakingElected> {
return memo((): Observable<DerivedStakingElected> =>
api.derive.staking.validators().pipe(
switchMap(({ currentElected }): Observable<[AccountId[], DerivedStaking[]]> =>
switchMap(({ currentElected }): Observable<[AccountId[], DerivedStakingQuery[]]> =>
combineLatest([
of(currentElected),
combineLatest(currentElected.map((accountId): Observable<DerivedStaking> =>
api.derive.staking.info(accountId)
combineLatest(currentElected.map((accountId): Observable<DerivedStakingQuery> =>
api.derive.staking.query(accountId)
))
])
),
+3 -2
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
export * from './account';
export * from './controllers';
export * from './electedInfo';
export * from './info';
export * from './overview';
export * from './query';
export * from './recentlyOffline';
export * from './validators';
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
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 { DerivedRecentlyOffline, DerivedSessionInfo, DerivedStaking, DerivedUnlocking } from '../types';
import { DerivedStakingQuery } from '../types';
import BN from 'bn.js';
import { combineLatest, Observable, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { createType, Option, Vec } from '@polkadot/types';
import { isUndefined } from '@polkadot/util';
import { memo } from '../util';
interface ParseInput {
accountId: AccountId;
controllerId: AccountId;
recentlyOffline?: DerivedRecentlyOffline;
nominators: AccountId[];
rewardDestination: RewardDestination;
queuedKeys?: [AccountId, Keys][];
sessionInfo: DerivedSessionInfo;
stakers: Exposure;
stakingLedger: Option<StakingLedger>;
stashId: AccountId;
@@ -32,68 +27,6 @@ interface ParseInput {
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[] } {
// for 2.x we have a Vec<(ValidatorId,Keys)> of the keys
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 _nextKeyFor = nextKeyFor || createType(api.registry, 'Option<AccountId>', null);
const _nextKeys = nextKeys || createType(api.registry, 'Option<Keys>', null);
@@ -128,13 +61,10 @@ function parseResult (api: ApiInterfaceRx, { accountId, controllerId, stashId, s
accountId,
controllerId,
nominators,
offline: recentlyOffline[stashId.toString()],
redeemable: redeemableSum(api, _stakingLedger, sessionInfo),
rewardDestination,
stakers,
stakingLedger: _stakingLedger,
stashId,
unlocking: calculateUnlocking(api, _stakingLedger, sessionInfo),
validatorPrefs,
...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]>];
function retrieveInfoV1 (api: ApiInterfaceRx, accountId: AccountId, stashId: AccountId, controllerId: AccountId): Observable<DerivedStaking> {
return combineLatest([
api.derive.session.info(),
api.derive.staking.recentlyOffline(),
function retrieveInfoV1 (api: ApiInterfaceRx, accountId: AccountId, stashId: AccountId, controllerId: AccountId): Observable<DerivedStakingQuery> {
return (
api.queryMulti([
[api.query.session.nextKeyFor, 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.validators, stashId]
]) 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, {
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>];
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([
api.derive.session.info(),
api.query.session.queuedKeys<Vec<ITuple<[AccountId, Keys]>>>(),
api.queryMulti([
[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.staking.ledger, controllerId]
]) 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
// FIXME We really want to be pulling all the new (valuable) info along
const nominators: AccountId[] = api.query.staking.storageVersion
@@ -185,17 +112,17 @@ function retrieveInfoV2 (api: ApiInterfaceRx, accountId: AccountId, stashId: Acc
: (_nominators as [Vec<AccountId>])[0];
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
return combineLatest([
api.query.staking.bonded<Option<AccountId>>(accountId),
api.query.staking.ledger<Option<StakingLedger>>(accountId)
]).pipe(switchMap(([bonded, stakingLedger]): Observable<DerivedStaking> =>
]).pipe(switchMap(([bonded, stakingLedger]): Observable<DerivedStakingQuery> =>
stakingLedger.isSome
? retrieveInfoV1(api, accountId, stakingLedger.unwrap().stash, accountId)
: 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
.bonded<Option<AccountId>>(stashId)
.pipe(switchMap((controllerId): Observable<DerivedStaking> =>
.pipe(switchMap((controllerId): Observable<DerivedStakingQuery> =>
controllerId.isSome
? retrieveInfoV2(api, stashId, stashId, controllerId.unwrap())
: 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
*/
export function info (api: ApiInterfaceRx): (_accountId: Uint8Array | string) => Observable<DerivedStaking> {
const query = api.consts.session
export function query (api: ApiInterfaceRx): (_accountId: Uint8Array | string) => Observable<DerivedStakingQuery> {
const retrieve = api.consts.session
? retrieveV2
: retrieveV1;
return memo((accountId: Uint8Array | string): Observable<DerivedStaking> =>
query(api, createType(api.registry, 'AccountId', accountId)));
return memo((accountId: Uint8Array | string): Observable<DerivedStakingQuery> =>
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
// 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
// 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
// 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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// of the Apache-2.0 license. See the LICENSE file for details.
+47 -21
View File
@@ -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
// 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 { u32, Vec } from '@polkadot/types';
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 {
accountId?: AccountId;
accountIndex?: AccountIndex;
identity: DeriveAccountRegistration;
nickname?: string;
}
@@ -44,6 +59,14 @@ export interface DerivedContractFees {
transferFee: BN;
}
export interface DerivedCollectiveProposal {
hash: Hash;
proposal: Proposal;
votes: Votes | null;
}
export type DerivedCollectiveProposals = DerivedCollectiveProposal[];
export interface DerivedElectionsInfo {
candidates: AccountId[];
candidateCount: u32;
@@ -126,24 +149,9 @@ export interface DerivedSessionInfo extends DeriveSessionIndexes {
sessionProgress: BlockNumber;
}
export type DerivedStakingAccount = [AccountId, DerivedStakingOnlineStatus];
export type DerivedStakingAccounts = DerivedStakingAccount[];
export interface DerivedStakingElected {
currentElected: AccountId[];
info: DerivedStaking[];
}
export interface DerivedStakingOnlineStatus {
online?: {
isOnline: boolean;
blockNumber?: BlockNumber;
};
offline?: {
blockNumber: BlockNumber;
count: BN;
}[];
info: DerivedStakingQuery[];
}
export interface DeriveStakingValidators {
@@ -161,12 +169,15 @@ export interface DerivedStakingStash {
validatorPrefs?: ValidatorPrefs;
}
export interface DerivedStaking extends DerivedStakingOnlineStatus, DerivedStakingStash {
export interface DerivedStakingQuery extends DerivedStakingStash {
accountId: AccountId;
nextSessionIds: AccountId[];
redeemable?: Balance;
sessionIds: AccountId[];
stakingLedger?: StakingLedger;
}
export interface DerivedStakingAccount extends DerivedStakingQuery {
redeemable?: Balance;
unlocking?: DerivedUnlocking[];
}
@@ -176,7 +187,22 @@ export interface DerivedStakingOverview extends DeriveSessionIndexes {
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 {
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
// 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
// of the Apache-2.0 license. See the LICENSE file for details.
+1 -1
View File
@@ -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
// 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