Compare commits

...
91 Commits
Author SHA1 Message Date
Github Actions 20f18c72e5 [CI Skip] release/stable 5.1.1
skip-checks: true
2021-07-19 13:14:57 +00:00
Jaco 6a31cbe1a2 5.1.1 (#3783)
* 5.1.1

* Bump common
2021-07-19 15:01:07 +02:00
Jaco acba636d16 Latest v14 metadata (#3782) 2021-07-19 14:27:10 +02:00
Github Actions 6356fe0571 [CI Skip] release/beta 5.0.2-12
skip-checks: true
2021-07-19 08:27:44 +00:00
Jaco 3e17824539 Move Lookup check to registry (#3780) 2021-07-19 10:17:26 +02:00
Github Actions db9e580f82 [CI Skip] release/beta 5.0.2-11
skip-checks: true
2021-07-17 09:47:49 +00:00
Jaco 5ffcba6dd5 Adjust with current scale-info outputs (#3779)
* Adjust with current scale-info outputs

* Linting

* Exhaustive check for encoders
2021-07-17 11:36:19 +02:00
Github Actions 731846088c [CI Skip] release/beta 5.0.2-10
skip-checks: true
2021-07-16 14:50:41 +00:00
Jaco 8b87689489 Add PortableRegistry for v14 lookups (#3778) 2021-07-16 16:39:38 +02:00
Github Actions 5a299adddc [CI Skip] release/beta 5.0.2-9
skip-checks: true
2021-07-16 13:42:49 +00:00
Jaco 99bb6cfe71 Additional AccountId{20, 32} mappings (#3777) 2021-07-16 15:31:18 +02:00
Github Actions ad9a8605d7 [CI Skip] release/beta 5.0.2-8
skip-checks: true
2021-07-16 12:07:44 +00:00
Jaco d62bfc55ac Adjust scale-info types (updated v14, contracts rename) (#3776)
* Adjust scale-info types (updated v14, contracts rename)

* Adjust v14 metadata

* PortableRegistry -> lookup

* Rewrite json
2021-07-16 13:57:44 +02:00
Github Actions 311740a1a2 [CI Skip] release/beta 5.0.2-7
skip-checks: true
2021-07-15 08:45:19 +00:00
Jaco 3285f1f122 v14 Type changes (#3774)
* v14 Type changes

* Registry
2021-07-15 10:34:41 +02:00
Github Actions 2a9711a3cb [CI Skip] release/beta 5.0.2-6
skip-checks: true
2021-07-14 05:53:10 +00:00
Jaco 3ea7cb47ce Update v14 types (#3771) 2021-07-14 07:42:30 +02:00
Github Actions 82fc46881a [CI Skip] release/beta 5.0.2-5
skip-checks: true
2021-07-13 20:55:31 +00:00
Denis Tsai e7758ad54c realign AccountKey20Junction to polkadot xcm's Junction enum (#3770) 2021-07-13 22:43:08 +02:00
Github Actions 7d3ab4c5c1 [CI Skip] release/beta 5.0.2-4
skip-checks: true
2021-07-13 10:01:59 +00:00
Jaco 6c87a6f0af Partial latest to v14 mapping (#3767) 2021-07-13 11:52:10 +02:00
Github Actions fc5e4afe44 [CI Skip] release/beta 5.0.2-3
skip-checks: true
2021-07-13 09:38:21 +00:00
Jaco 48ef04b8ca Metadata v14 types (#3765)
* Metadata v14 types

* Linting w/ CHANGELOG

* Previous-gen SiType as SiType0
2021-07-13 11:28:44 +02:00
Github Actions 1b526fe618 [CI Skip] release/beta 5.0.2-2
skip-checks: true
2021-07-13 06:45:10 +00:00
Ian He 8d6bd931f3 add user additional rpcs during api.clone() (#3764) 2021-07-13 08:35:46 +02:00
Github Actions b317a8eb9b [CI Skip] release/beta 5.0.2-1
skip-checks: true
2021-07-12 10:14:40 +00:00
Jaco 8e65545a3c Allow nested struct generation (#3760)
* Allow nested struct generation

* CHANGELOG

* Update packages/typegen/src/util/formatting.ts

* Rebuild
2021-07-12 12:04:41 +02:00
Github Actions 4ded189697 [CI Skip] release/beta 5.0.2-0
skip-checks: true
2021-07-12 09:51:43 +00:00
Jaco b503441341 Update ParaPastCodeMeta with ReplacementTimes (#3758) 2021-07-12 11:39:46 +02:00
Github Actions f27076c8dc [CI Skip] release/stable 5.0.1
skip-checks: true
2021-07-11 10:36:42 +00:00
Jaco 7fd9c1c8b1 5.0.1 (#3757)
* 5.0.1

* version bump

* Bump common
2021-07-11 12:26:03 +02:00
Github Actions 4aafeed026 [CI Skip] release/beta 4.17.2-20
skip-checks: true
2021-07-11 05:44:10 +00:00
Jaco f7f81b2b99 Align static metadata with latest Substrate (#3756) 2021-07-11 07:32:17 +02:00
Github Actions 0a501c6a3f [CI Skip] release/beta 4.17.2-19
skip-checks: true
2021-07-10 05:25:02 +00:00
Jaco 9ad95d91a0 Adjust scheduler derive (empty results) (#3755) 2021-07-10 07:11:29 +02:00
Github Actions abb4170577 [CI Skip] release/beta 4.17.2-18
skip-checks: true
2021-07-09 12:42:33 +00:00
Jaco 081f223bb2 Adjust bundles (no @polkadot/networks) (#3754) 2021-07-09 14:33:23 +02:00
Github Actions f0778b613f [CI Skip] release/beta 4.17.2-17
skip-checks: true
2021-07-09 09:02:15 +00:00
Jaco 27c6423b28 Adjust bundle creation (#3752) 2021-07-09 10:51:01 +02:00
Github Actions 8803bdd55e [CI Skip] release/beta 4.17.2-16
skip-checks: true
2021-07-09 04:25:51 +00:00
Jaco 445a080f7d Adjust Ws .disconnect() logic to always clear auto-connect (#3749) 2021-07-09 06:14:30 +02:00
Github Actions e13a7ff5a1 [CI Skip] release/beta 4.17.2-15
skip-checks: true
2021-07-08 12:51:54 +00:00
Jaco 18cbfe4a56 Bump deps (#3745) 2021-07-08 14:42:49 +02:00
Github Actions 3397e680e2 [CI Skip] release/beta 4.17.2-14
skip-checks: true
2021-07-08 08:39:39 +00:00
Jaco e2fa996df4 Crowdloan contributions derive (#3704)
* Crwodloan contributions derive

* Handle deltas

* Opt

* Expand childKey

* Keep all previous changes

* Rework

* Adjust

* Cleanups

* Cleanups

* Pass through childKey

* deltas

* CHANGELOG

* ownContributions

* cleanups

* watch events
2021-07-08 10:30:27 +02:00
Github Actions 76d23c54a6 [CI Skip] release/beta 4.17.2-13
skip-checks: true
2021-07-08 04:44:13 +00:00
Jaco bd58f11c92 Westend 9080 (#3744) 2021-07-08 06:33:24 +02:00
Github Actions 2a3b685fb1 [CI Skip] release/beta 4.17.2-12
skip-checks: true
2021-07-07 18:51:37 +00:00
Jaco 3c59a4d417 Single module bundle via rollup (#3731)
* Single module bundle via rollup

* use createBundle

* override all

* Update rollup.config.mjs

* Add bundle import

* Remove x-* packages

* Adjust

* Adjust

* Rebuild

* Internal helpers

* Adjust locations

* Bump common

* CHANGELOG

* Update rollup.config.mjs
2021-07-07 20:39:49 +02:00
Github Actions 8d7b18526c [CI Skip] release/beta 4.17.2-11
skip-checks: true
2021-07-07 12:09:20 +00:00
Jaco 92a1f603d9 Move metadata into types (circular deps hell) (#3743)
* Move metadata into types (circular deps hells)

* Adjust

* Additional

* Additional

* Last round?

* Adjust imports

* Adjust

* packages

* Bump common
2021-07-07 14:00:30 +02:00
Github Actions 968d9078b1 [CI Skip] release/beta 4.17.2-10
skip-checks: true
2021-07-07 09:46:11 +00:00
Jaco 81be70e15b Introduce bundle exports (#3742)
* Introduce bundle exports

* Move memo

* Cleanup imports

* Move DoNotConstruct
2021-07-07 11:35:30 +02:00
Jaco Greeff 33ee38dc7a Bump common 2021-07-07 10:37:46 +03:00
Github Actions 90dd0656e2 [CI Skip] release/beta 4.17.2-9
skip-checks: true
2021-07-07 07:34:50 +00:00
Jaco ff3882f5f7 Bump common (w/ rxjs 7) (#3736)
* Bump common (w/ rxjs 7)

* Adjust

* pre bump

* Cleanup imports

* Add missing switchMap

* CHANGELOG

* Remove duplicate imports

* Bump common

* Direct rxjs import
2021-07-07 09:26:30 +02:00
Github Actions 852daebfd8 [CI Skip] release/beta 4.17.2-7
skip-checks: true
2021-07-07 05:32:26 +00:00
Jaco bde3c61f74 Small referendum optimization (#3741) 2021-07-07 07:22:50 +02:00
Github Actions 883b1aa5c2 [CI Skip] release/beta 4.17.2-6
skip-checks: true
2021-07-07 05:11:23 +00:00
Jaco 716b09737c Allow for non-decodable scheduler entries (#3740) 2021-07-07 07:02:19 +02:00
Github Actions 7d3bc36ef7 [CI Skip] release/beta 4.17.2-5
skip-checks: true
2021-07-07 04:41:58 +00:00
Jaco a3c283cdf3 combineLatest type fixes (remove deprecated) (#3739) 2021-07-07 06:30:56 +02:00
Github Actions 2d634a5b00 [CI Skip] release/beta 4.17.2-4
skip-checks: true
2021-07-07 04:20:20 +00:00
Jaco 113e514b45 Add BlockNumberFor (#3738) 2021-07-07 06:11:44 +02:00
Github Actions ae7edc2111 [CI Skip] release/beta 4.17.2-3
skip-checks: true
2021-07-06 08:47:54 +00:00
Jaco 9ac8a23b20 Update .123trigger 2021-07-06 10:39:15 +02:00
Jaco Greeff a97938a80c Bump deps 2021-07-06 10:08:16 +03:00
Jaco Greeff 4b34d6cdf7 Bump dev 2021-07-06 09:57:25 +03:00
Jaco 89c7d73951 Expose gasRequired (as available) (#3732) 2021-07-06 08:53:23 +02:00
Github Actions 0990359968 [CI Skip] release/beta 4.17.2-2
skip-checks: true
2021-07-06 05:57:29 +00:00
Jaco Greeff 7f28af2029 Bump dev 2021-07-06 08:46:43 +03:00
Github Actions 896247320c [CI Skip] release/beta 4.17.2-1
skip-checks: true
2021-07-06 04:40:52 +00:00
Jaco a635c64910 Add Westend historic HeartbeatTo244 (#3730) 2021-07-06 06:30:17 +02:00
Github Actions 398461163f [CI Skip] release/beta 4.17.2-0
skip-checks: true
2021-07-05 15:48:15 +00:00
Jaco 4d25c2a363 Bump dev (#3726) 2021-07-05 17:37:00 +02:00
Github Actions cbe2dfbd82 [CI Skip] release/stable 4.17.1
skip-checks: true
2021-07-05 08:02:45 +00:00
Jaco 5442a2e5fe 4.17 (#3724) 2021-07-05 09:53:56 +02:00
Github Actions 58b4d8c84f [CI Skip] release/beta 4.16.3-5
skip-checks: true
2021-07-05 06:42:55 +00:00
Jaco f5c6c8a072 Attach constructed registry to metadata (#3723)
* Attach constructed registry to metadata

* Remove return

* CHANGELOG
2021-07-05 08:31:06 +02:00
Github Actions 9d5ab4a2d6 [CI Skip] release/beta 4.16.3-4
skip-checks: true
2021-07-02 07:42:19 +00:00
Jaco 32f704459f api.at(blockHash).{consts, errors, events, query} (#3710)
* api.at(blockHash).{consts, errors, events, query}

* Manual tests for apiAt

* Adjust helpers... not perfect, but best for now

* Expand decorated return

* Re-add compable injectMetadata

* CHANGELOG

* Bump jest global timeout
2021-07-02 09:30:25 +02:00
Jaco e4795182ca Align static metadata with latest Substrate (#3717) 2021-07-02 09:30:01 +02:00
Github Actions 3297dbdaab [CI Skip] release/beta 4.16.3-3
skip-checks: true
2021-07-02 07:23:16 +00:00
Jaco a65a5985e6 Bump TS (#3718) 2021-07-02 09:14:50 +02:00
Github Actions 77eac494ad [CI Skip] release/beta 4.16.3-2
skip-checks: true
2021-07-02 04:58:49 +00:00
Jaco 4498f59607 Detect on elections (#3716) 2021-07-02 06:47:43 +02:00
Jaco 6322913310 Allow for fallback types (struct-only as a start) (#3714)
* Allow for fallback types (struct-only as a start)

* Filter fallback & alias from structs

* Don't clobber existing fallbackType
2021-07-01 12:54:02 +02:00
Github Actions be2f34a045 [CI Skip] release/beta 4.16.3-1
skip-checks: true
2021-07-01 08:26:48 +00:00
Jaco cce0c89168 Adjust collective with instances (#3712)
* Adjust collective with instances

* Update CHANGELOG

* Add prime & proposalaHashes to all

* Export members collective

* prime

* Optional constants

* Move constant expansion

* proposalCount derive

* candidateCount is non-optional
2021-07-01 10:17:48 +02:00
Github Actions 58cc197c89 [CI Skip] release/beta 4.16.3-0
skip-checks: true
2021-06-28 12:12:50 +00:00
Arjan Zijderveld bbb6d0eda9 Added Emergency to ElectionPhase (#3707)
Link to new field:

https://github.com/paritytech/substrate/blob/6242d37f43ec5aa9b6131a8e61b8d4e71b063907/frame/election-provider-multi-phase/src/lib.rs#L337
2021-06-28 14:03:57 +02:00
341 changed files with 47666 additions and 7084 deletions
+2 -3
View File
@@ -1,4 +1,4 @@
31
32
1.4.2
1.6.2
1.11.2
@@ -23,5 +23,4 @@
4.7.2
4.9.2
4.11.2
4.16.2
4.16.2
+57
View File
@@ -1,5 +1,62 @@
# CHANGELOG
## 5.1.1 Jul 19, 2021
- **Breaking changes** With the support for v14 metadata parsing, the `documentation` fields on metadata was renamed to `docs` for consistency, aligning with the SCALE type generators.
Contributed:
- Don't clear rpc decoration on Api clone (Thanks to https://github.com/ianhe8x)
- Align Xcm Junction type with Substrate (Thanks to https://github.com/dt665m)
Changes:
- Update `ParaPastCodeMeta` with `ReplacementTimes`
- Add mappings for `AccountId20` & `AccountId32` types
- Adjust scale-info types with Substrate (mapping for api-contracts to old)
- Allow nested structs in enum definitions & generation
- Allow for parsing of v14 metadata (not enabled by default, not merged into Substrate as of yet)
## 5.0.1 Jul 11, 2021
Upgrade priority: Low. Recommended for users of current-generation Substrate chains.
- **Breaking change** The `@polkadot/metadata` package has been removed, adjust imports to `@polkadot/types`
- **Important** Internally rxjs has been upgraded to the 7.0 version, affecting users of the `ApiRx` interface
Changes:
- Remove the `@polkadot/metadata` package, consolidate into `@polkadot/types`
- Contract reads will now expose an additional `gasRequired` (total estimated)
- Allow schedule derives to handle scheduler entries that cannot decode
- Add missing historic `Heartbeat: HeartbeatTo244` mapping to Westend
- Adjust Ws `.disconnect()` logic to always clear auto-connect
- Add `BlockNumberFor` type mapping
- Add Westend 9080 upgrade block
- Add `derive.crowdloan.contributions(paraId)`
- Allow building as a completely stand-alone browser bundle (experimental)
- Update to latest `@polkadot/x-rxjs` with RxJs 7.2
- Align static metadata with latest Substrate
## 4.17.1 Jul 5, 2021
Upgrade priority: Low. Allows cleaner access to multiple `.at` queries via new API.
Contributed:
- Added `Emergency` to `ElectionPhase` (Thanks to https://github.com/arjanz)
Changes:
- Added `await api.at(<blockHash>)` to retrieve API instances at a point
- Added `fallbackType` for type classes (only struct, as defined)
- Allow `instances` API config to drive derive collective locations
- Ensure correct registry is attached to historic metadata
- Align static metadata with latest Substrate
## 4.16.2 Jun 27, 2021
Upgrade priority: Low. Recommended for Polkadot with runtime >= 9050.
+1 -1
View File
@@ -27,6 +27,6 @@ module.exports = {
'<rootDir>/packages/types/build',
'<rootDir>/packages/types-known/build'
],
testTimeout: 10000,
testTimeout: 30000,
transformIgnorePatterns: ['/node_modules/(?!@polkadot|@babel/runtime/helpers/esm/)']
};
+5 -4
View File
@@ -8,13 +8,14 @@
"packages/*"
],
"resolutions": {
"typescript": "^4.3.4"
"typescript": "^4.3.5"
},
"scripts": {
"build": "yarn build:interfaces && polkadot-dev-build-ts",
"build:extra": "(cd packages/typegen && copyfiles scripts/* build)",
"build:interfaces": "polkadot-types-internal-interfaces",
"build:release": "polkadot-ci-ghact-build",
"build:rollup": "polkadot-exec-rollup --config",
"docs:metadata": "polkadot-types-internal-metadata",
"chain:info": "polkadot-types-chain-info",
"lint": "polkadot-dev-run-lint",
@@ -28,11 +29,11 @@
"@babel/core": "^7.14.6",
"@babel/register": "^7.14.5",
"@babel/runtime": "^7.14.6",
"@polkadot/dev": "^0.62.43",
"@polkadot/ts": "^0.4.1",
"@polkadot/dev": "^0.62.57",
"@polkadot/ts": "^0.4.4",
"@polkadot/typegen": "workspace:packages/typegen",
"@types/jest": "^26.0.23",
"copyfiles": "^2.4.1"
},
"version": "4.16.2"
"version": "5.1.1"
}
+5 -5
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-contract",
"version": "4.16.2",
"version": "5.1.1",
"type": "module",
"description": "Interfaces for interacting with contracts and contract ABIs",
"main": "index.js",
@@ -20,9 +20,9 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-contract#readme",
"dependencies": {
"@babel/runtime": "^7.14.6",
"@polkadot/api": "4.16.2",
"@polkadot/types": "4.16.2",
"@polkadot/util": "^6.10.1",
"@polkadot/x-rxjs": "^6.10.1"
"@polkadot/api": "5.1.1",
"@polkadot/types": "5.1.1",
"@polkadot/util": "^7.0.2",
"rxjs": "^7.2.0"
}
}
+1 -1
View File
@@ -49,7 +49,7 @@ export class Abi {
this.registry.setMetaTypes(this.project.types);
this.project.types.forEach((_, index) =>
this.registry.getMetaTypeDef({ type: this.registry.createType('SiLookupTypeId', index + this.registry.typeOffset) })
this.registry.getMetaTypeDef({ type: this.registry.createType('Si0LookupTypeId', index + this.registry.typeOffset) })
);
this.constructors = this.project.spec.constructors.map((spec: ContractConstructorSpec, index) =>
this.#createMessage(spec, index, {
+17 -18
View File
@@ -1,20 +1,19 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ChainProperties, ContractDisplayName, SiField, SiLookupTypeId, SiType, SiTypeDefArray, SiTypeDefSequence, SiTypeDefTuple, SiTypeDefVariant, SiVariant } from '@polkadot/types/interfaces';
import type { ChainProperties, ContractDisplayName, Si0Field, Si0LookupTypeId, Si0Type, Si0TypeDefArray, Si0TypeDefSequence, Si0TypeDefTuple, Si0TypeDefVariant, Si0Variant } from '@polkadot/types/interfaces';
import type { InterfaceTypes, TypeDef } from '@polkadot/types/types';
import { TypeRegistry, withTypeString } from '@polkadot/types/create';
import { TypeDefInfo } from '@polkadot/types/types';
import { TypeDefInfo, TypeRegistry, withTypeString } from '@polkadot/types';
import { assert, isUndefined } from '@polkadot/util';
interface PartialTypeSpec {
readonly type: SiLookupTypeId;
readonly type: Si0LookupTypeId;
readonly displayName?: ContractDisplayName;
}
// convert the offset into project-specific, index-1
export function getRegistryOffset (id: SiLookupTypeId, typeOffset: number): number {
export function getRegistryOffset (id: Si0LookupTypeId, typeOffset: number): number {
return id.toNumber() - typeOffset;
}
@@ -30,7 +29,7 @@ export class MetaRegistry extends TypeRegistry {
public readonly typeOffset;
#siTypes: SiType[] = [];
#siTypes: Si0Type[] = [];
constructor (metadataVersion: string, chainProperties?: ChainProperties) {
super();
@@ -45,7 +44,7 @@ export class MetaRegistry extends TypeRegistry {
}
}
public setMetaTypes (metaTypes: SiType[]): void {
public setMetaTypes (metaTypes: Si0Type[]): void {
this.#siTypes = metaTypes;
}
@@ -84,15 +83,15 @@ export class MetaRegistry extends TypeRegistry {
return typeDef;
}
#getMetaType = (id: SiLookupTypeId): SiType => {
#getMetaType = (id: Si0LookupTypeId): Si0Type => {
const type = this.#siTypes[getRegistryOffset(id, this.typeOffset)];
assert(!isUndefined(type), () => `getMetaType:: Unable to find ${id.toNumber()} in type values`);
return this.createType('SiType', type);
return this.createType('Si0Type', type);
}
#extract = (type: SiType, id: SiLookupTypeId): TypeDef => {
#extract = (type: Si0Type, id: Si0LookupTypeId): TypeDef => {
const path = [...type.path];
const isPrimitivePath = !!path.length && (
(path.length > 2 && path[0].eq('ink_env') && path[1].eq('types')) ||
@@ -137,7 +136,7 @@ export class MetaRegistry extends TypeRegistry {
});
}
#extractArray = ({ len: length, type }: SiTypeDefArray): Omit<TypeDef, 'type'> => {
#extractArray = ({ len: length, type }: Si0TypeDefArray): Omit<TypeDef, 'type'> => {
assert(!length || length.toNumber() <= 256, 'MetaRegistry: Only support for [Type; <length>], where length <= 256');
return {
@@ -147,7 +146,7 @@ export class MetaRegistry extends TypeRegistry {
};
}
#extractFields = (fields: SiField[]): Omit<TypeDef, 'type'> => {
#extractFields = (fields: Si0Field[]): Omit<TypeDef, 'type'> => {
const [isStruct, isTuple] = fields.reduce(([isAllNamed, isAllUnnamed], { name }) => ([
isAllNamed && name.isSome,
isAllUnnamed && name.isNone
@@ -175,7 +174,7 @@ export class MetaRegistry extends TypeRegistry {
};
}
#extractPrimitive = (type: SiType): TypeDef => {
#extractPrimitive = (type: Si0Type): TypeDef => {
const typeStr = type.def.asPrimitive.type.toString();
return {
@@ -184,14 +183,14 @@ export class MetaRegistry extends TypeRegistry {
};
}
#extractPrimitivePath = (type: SiType): TypeDef => {
#extractPrimitivePath = (type: Si0Type): TypeDef => {
return {
info: TypeDefInfo.Plain,
type: type.path[type.path.length - 1].toString()
};
}
#extractSequence = ({ type }: SiTypeDefSequence, id: SiLookupTypeId): Omit<TypeDef, 'type'> => {
#extractSequence = ({ type }: Si0TypeDefSequence, id: Si0LookupTypeId): Omit<TypeDef, 'type'> => {
assert(!!type, () => `ContractRegistry: Invalid sequence type found at id ${id.toString()}`);
return {
@@ -200,7 +199,7 @@ export class MetaRegistry extends TypeRegistry {
};
}
#extractTuple = (ids: SiTypeDefTuple): Omit<TypeDef, 'type'> => {
#extractTuple = (ids: Si0TypeDefTuple): Omit<TypeDef, 'type'> => {
return ids.length === 1
? this.getMetaTypeDef({ type: ids[0] })
: {
@@ -209,7 +208,7 @@ export class MetaRegistry extends TypeRegistry {
};
}
#extractVariant = ({ variants }: SiTypeDefVariant, id: SiLookupTypeId): Omit<TypeDef, 'type'> => {
#extractVariant = ({ variants }: Si0TypeDefVariant, id: Si0LookupTypeId): Omit<TypeDef, 'type'> => {
const { params, path } = this.#getMetaType(id);
const specialVariant = path[0].toString();
@@ -232,7 +231,7 @@ export class MetaRegistry extends TypeRegistry {
};
}
#extractVariantSub = (variants: SiVariant[]): TypeDef[] => {
#extractVariantSub = (variants: Si0Variant[]): TypeDef[] => {
return variants.every(({ fields }) => fields.length === 0)
? variants.map(({ discriminant, name }) => ({
...(
+3 -3
View File
@@ -4,7 +4,7 @@
import fs from 'fs';
import path from 'path';
import { decorateMethod } from '@polkadot/api/promise';
import { decorateMethodPromise } from '@polkadot/api';
import contractFlipper from '../../test/contracts/ink/flipper.contract.json';
import abiFlipper from '../../test/contracts/ink/flipper.json';
@@ -16,13 +16,13 @@ const wasmFlipper = fs.readFileSync(path.join(__dirname, '../../test/contracts/i
describe('Code', (): void => {
it('can construct with an individual ABI/WASM combo', (): void => {
expect(
() => new Code(mockApi, abiFlipper, wasmFlipper, decorateMethod)
() => new Code(mockApi, abiFlipper, wasmFlipper, decorateMethodPromise)
).not.toThrow();
});
it('can construct with an .contract ABI', (): void => {
expect(
() => new Code(mockApi, contractFlipper, null, decorateMethod)
() => new Code(mockApi, contractFlipper, null, decorateMethodPromise)
).not.toThrow();
});
});
+6 -2
View File
@@ -9,11 +9,12 @@ import type { AnyJson, CodecArg, ISubmittableResult } from '@polkadot/types/type
import type { AbiMessage, ContractCallOutcome, ContractOptions, DecodedEvent } from '../types';
import type { ContractCallResult, ContractCallSend, ContractQuery, ContractTx, MapMessageQuery, MapMessageTx } from './types';
import { map } from 'rxjs';
import { SubmittableResult } from '@polkadot/api';
import { ApiBase } from '@polkadot/api/base';
import { createTypeUnsafe } from '@polkadot/types';
import { assert, BN, BN_HUNDRED, BN_ONE, BN_ZERO, bnToBn, isFunction, isUndefined, logger } from '@polkadot/util';
import { map } from '@polkadot/x-rxjs/operators';
import { Abi } from '../Abi';
import { applyOnEvent, extractOptions, isOptions } from '../util';
@@ -145,9 +146,12 @@ export class Contract<ApiType extends ApiTypes> extends Base<ApiType> {
value
})
.pipe(
map(({ debugMessage, gasConsumed, result }): ContractCallOutcome => ({
map(({ debugMessage, gasConsumed, gasRequired, result }): ContractCallOutcome => ({
debugMessage,
gasConsumed,
gasRequired: gasRequired && !gasRequired.isZero()
? gasRequired
: gasConsumed,
output: result.isOk && message.returnType
? createTypeUnsafe(this.registry, message.returnType.type, [result.asOk.data.toU8a(true)], { isPedantic: true })
: null,
+1 -1
View File
@@ -1,12 +1,12 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
import type { ApiTypes, ObsInnerType } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import type { CodecArg } from '@polkadot/types/types';
import type { BN } from '@polkadot/util';
import type { Observable } from '@polkadot/x-rxjs';
import type { AbiMessage, BlueprintOptions, ContractCallOutcome, ContractOptions } from '../types';
export interface BlueprintDeploy<ApiType extends ApiTypes> {
+7
View File
@@ -0,0 +1,7 @@
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
// SPDX-License-Identifier: Apache-2.0
export { Abi } from './Abi';
export { packageInfo } from './packageInfo';
export { Blueprint as BlueprintPromise, Code as CodePromise, Contract as ContractPromise } from './promise';
export { Blueprint as BlueprintRx, Code as CodeRx, Contract as ContractRx } from './rx';
+1 -4
View File
@@ -3,7 +3,4 @@
import './detectPackage';
export { Abi } from './Abi';
export { packageInfo } from './packageInfo';
export { Blueprint as BlueprintPromise, Code as CodePromise, Contract as ContractPromise } from './promise';
export { Blueprint as BlueprintRx, Code as CodeRx, Contract as ContractRx } from './rx';
export * from './bundle';
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/api-contract', version: '4.16.2' };
export const packageInfo = { name: '@polkadot/api-contract', version: '5.1.1' };
@@ -4,14 +4,13 @@
import type { Hash } from '@polkadot/types/interfaces';
import type { AnyJson } from '@polkadot/types/types';
import { ApiPromise } from '@polkadot/api';
import { decorateMethod } from '@polkadot/api/promise';
import { ApiPromise, decorateMethodPromise } from '@polkadot/api';
import { Abi } from '../Abi';
import { Blueprint as BaseBlueprint } from '../base';
export class Blueprint extends BaseBlueprint<'promise'> {
constructor (api: ApiPromise, abi: AnyJson | Abi, codeHash: string | Hash) {
super(api, abi, codeHash, decorateMethod);
super(api, abi, codeHash, decorateMethodPromise);
}
}
+2 -2
View File
@@ -4,13 +4,13 @@
import type { ApiPromise } from '@polkadot/api';
import type { AnyJson } from '@polkadot/types/types';
import { decorateMethod } from '@polkadot/api/promise';
import { decorateMethodPromise } from '@polkadot/api';
import { Abi } from '../Abi';
import { Code as BaseCode } from '../base';
export class Code extends BaseCode<'promise'> {
constructor (api: ApiPromise, abi: AnyJson | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
super(api, abi, wasm, decorateMethod);
super(api, abi, wasm, decorateMethodPromise);
}
}
@@ -4,14 +4,13 @@
import type { AccountId } from '@polkadot/types/interfaces';
import type { AnyJson } from '@polkadot/types/types';
import { ApiPromise } from '@polkadot/api';
import { decorateMethod } from '@polkadot/api/promise';
import { ApiPromise, decorateMethodPromise } from '@polkadot/api';
import { Abi } from '../Abi';
import { Contract as BaseContract } from '../base';
export class Contract extends BaseContract<'promise'> {
constructor (api: ApiPromise, abi: AnyJson | Abi, address: string | AccountId) {
super(api, abi, address, decorateMethod);
super(api, abi, address, decorateMethodPromise);
}
}
+2 -3
View File
@@ -4,14 +4,13 @@
import type { Hash } from '@polkadot/types/interfaces';
import type { AnyJson } from '@polkadot/types/types';
import { ApiRx } from '@polkadot/api';
import { decorateMethod } from '@polkadot/api/rx';
import { ApiRx, decorateMethodRx } from '@polkadot/api';
import { Abi } from '../Abi';
import { Blueprint as BaseBlueprint } from '../base';
export class Blueprint extends BaseBlueprint<'rxjs'> {
constructor (api: ApiRx, abi: AnyJson | Abi, codeHash: string | Hash) {
super(api, abi, codeHash, decorateMethod);
super(api, abi, codeHash, decorateMethodRx);
}
}
+2 -2
View File
@@ -4,13 +4,13 @@
import type { ApiRx } from '@polkadot/api';
import type { AnyJson } from '@polkadot/types/types';
import { decorateMethod } from '@polkadot/api/rx';
import { decorateMethodRx } from '@polkadot/api';
import { Abi } from '../Abi';
import { Code as BaseCode } from '../base';
export class Code extends BaseCode<'rxjs'> {
constructor (api: ApiRx, abi: AnyJson | Abi, wasm: Uint8Array | string | Buffer | null | undefined) {
super(api, abi, wasm, decorateMethod);
super(api, abi, wasm, decorateMethodRx);
}
}
+2 -3
View File
@@ -4,14 +4,13 @@
import type { AccountId } from '@polkadot/types/interfaces';
import type { AnyJson } from '@polkadot/types/types';
import { ApiRx } from '@polkadot/api';
import { decorateMethod } from '@polkadot/api/rx';
import { ApiRx, decorateMethodRx } from '@polkadot/api';
import { Abi } from '../Abi';
import { Contract as BaseContract } from '../base';
export class Contract extends BaseContract<'rxjs'> {
constructor (api: ApiRx, abi: AnyJson | Abi, address: string | AccountId) {
super(api, abi, address, decorateMethod);
super(api, abi, address, decorateMethodRx);
}
}
+1
View File
@@ -55,6 +55,7 @@ export interface InterfaceContractCalls {
export interface ContractCallOutcome {
debugMessage: Text;
gasConsumed: u64;
gasRequired: u64;
output: Codec | null;
result: ContractExecResultResult;
}
+9 -9
View File
@@ -1,6 +1,6 @@
{
"name": "@polkadot/api-derive",
"version": "4.16.2",
"version": "5.1.1",
"type": "module",
"description": "Common functions used across Polkadot, derived from RPC calls and storage queries.",
"main": "index.js",
@@ -20,15 +20,15 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/api-derive#readme",
"dependencies": {
"@babel/runtime": "^7.14.6",
"@polkadot/api": "4.16.2",
"@polkadot/rpc-core": "4.16.2",
"@polkadot/types": "4.16.2",
"@polkadot/util": "^6.10.1",
"@polkadot/util-crypto": "^6.10.1",
"@polkadot/x-rxjs": "^6.10.1"
"@polkadot/api": "5.1.1",
"@polkadot/rpc-core": "5.1.1",
"@polkadot/types": "5.1.1",
"@polkadot/util": "^7.0.2",
"@polkadot/util-crypto": "^7.0.2",
"rxjs": "^7.2.0"
},
"devDependencies": {
"@polkadot/keyring": "^6.10.1",
"@polkadot/rpc-provider": "4.16.2"
"@polkadot/keyring": "^7.0.2",
"@polkadot/rpc-provider": "5.1.1"
}
}
@@ -1,14 +1,14 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import { map, of } from 'rxjs';
import { assertReturn, isU8a } from '@polkadot/util';
import { decodeAddress } from '@polkadot/util-crypto';
import { of } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
+4 -5
View File
@@ -1,15 +1,14 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Vec } from '@polkadot/types';
import type { AccountId, Address, Balance } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveAccountFlags } from '../types';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { combineLatest, map, of } from 'rxjs';
import { memo } from '../util';
@@ -47,9 +46,9 @@ export function flags (instanceId: string, api: ApiInterfaceRx): (address?: Acco
? 'electionsPhragmen'
: 'elections';
return combineLatest<FlagsIntermediate>([
return combineLatest([
address && api.query[councilSection]?.members
? api.query[councilSection].members()
? api.query[councilSection].members<Vec<ITuple<[AccountId, Balance]>>>()
: of(undefined),
address && api.query.council?.members
? api.query.council.members()
@@ -1,15 +1,15 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { AccountIdAndIndex } from '../types';
import { map, of } from 'rxjs';
import { isU8a } from '@polkadot/util';
import { decodeAddress } from '@polkadot/util-crypto';
import { of } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
@@ -1,12 +1,12 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId, AccountIndex } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { AccountIndexes } from '../types';
import { map } from '@polkadot/x-rxjs/operators';
import { map } from 'rxjs';
import { memo } from '../util';
+3 -3
View File
@@ -1,16 +1,16 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Data, Option } from '@polkadot/types';
import type { AccountId, IdentityInfoAdditional, Registration } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveAccountRegistration, DeriveHasIdentity } from '../types';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { isHex, u8aToString } from '@polkadot/util';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
@@ -1,14 +1,13 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option } from '@polkadot/types';
import type { AccountId, AccountIndex, BalanceOf } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import { of } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { map, of } from 'rxjs';
import { memo } from '../util';
+2 -3
View File
@@ -1,12 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { AccountIndexes } from '../types';
import { of } from '@polkadot/x-rxjs';
import { map, startWith } from '@polkadot/x-rxjs/operators';
import { map, of, startWith } from 'rxjs';
import { memo } from '../util';
+3 -3
View File
@@ -1,16 +1,16 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Bytes, Option, u32 } from '@polkadot/types';
import type { AccountId, AccountIndex, Address, Balance } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveAccountInfo, DeriveAccountRegistration } from '../types';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { u8aToString } from '@polkadot/util';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
+3 -3
View File
@@ -1,15 +1,15 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx, QueryableStorageMultiArg } from '@polkadot/api/types';
import type { AccountData, AccountId, AccountIndex, AccountInfo, Address, Balance, Index } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveBalancesAccount, DeriveBalancesAccountData } from '../types';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { assert, isFunction } from '@polkadot/util';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
+3 -3
View File
@@ -1,15 +1,15 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx, QueryableStorageMultiArg } from '@polkadot/api/types';
import type { Option, Vec } from '@polkadot/types';
import type { AccountId, AccountIndex, Address, Balance, BalanceLock, BalanceLockTo212, BlockNumber, VestingInfo, VestingSchedule } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveBalancesAccount, DeriveBalancesAccountData, DeriveBalancesAll, DeriveBalancesAllAccountData } from '../types';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { BN, bnMax, isFunction } from '@polkadot/util';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
+2 -3
View File
@@ -1,13 +1,12 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Balance } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveFees } from '../types';
import { of } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { map, of } from 'rxjs';
import { memo } from '../util';
@@ -1,12 +1,12 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveBalancesAccount } from '../types';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { combineLatest, of } from 'rxjs';
import { memo } from '../util';
@@ -6,10 +6,11 @@ import type { Bytes, Option, StorageKey } from '@polkadot/types';
import type { Bounty, BountyIndex, ProposalIndex } from '@polkadot/types/interfaces';
import type { Codec, InterfaceTypes } from '@polkadot/types/types';
import { firstValueFrom, of } from 'rxjs';
import { ApiPromise } from '@polkadot/api';
import { DeriveCollectiveProposal } from '@polkadot/api-derive/types';
import { Proposal } from '@polkadot/types/interfaces';
import { of } from '@polkadot/x-rxjs';
import { BountyFactory } from '../../test/bountyFactory';
import { BytesFactory } from '../../test/bytesFactory';
@@ -98,7 +99,7 @@ describe('bounties derive', () => {
}
} as unknown as ApiInterfaceRx;
const result = await bounties('', mockApi)().toPromise();
const result = await firstValueFrom(bounties('', mockApi)());
expect(result).toHaveLength(2);
expect(result[0].bounty.proposer.toString()).toEqual(DEFAULT_PROPOSER);
@@ -110,7 +111,7 @@ describe('bounties derive', () => {
});
it('returns motions', async () => {
const result = await bounties('', defaultMockApi)().toPromise();
const result = await firstValueFrom(bounties('', defaultMockApi)());
expect(result).toHaveLength(2);
expect(result[0].proposals).toHaveLength(0);
@@ -126,7 +127,7 @@ describe('bounties derive', () => {
}
} as unknown as ApiInterfaceRx;
const result = await bounties('', mockApi)().toPromise();
const result = await firstValueFrom(bounties('', mockApi)());
expect(result).toHaveLength(2);
expect(result[0].bounty.proposer.toString()).toEqual(DEFAULT_PROPOSER);
@@ -151,7 +152,7 @@ describe('bounties derive', () => {
}
} as unknown as ApiInterfaceRx;
const result = await bounties('', mockApi)().toPromise();
const result = await firstValueFrom(bounties('', mockApi)());
expect(result).toHaveLength(2);
expect(result[0].proposals).toHaveLength(0);
+4 -4
View File
@@ -1,15 +1,15 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { DeriveBounties, DeriveCollectiveProposal } from '@polkadot/api-derive/types';
import type { Bytes, Option } from '@polkadot/types';
import type { Bounty, BountyIndex, ProposalIndex } from '@polkadot/types/interfaces';
import type { DeriveBounties, DeriveCollectiveProposal } from '../types';
import { memo } from '@polkadot/api-derive/util';
import { combineLatest, Observable, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { memo } from '../util';
import { filterBountiesProposals } from './helpers/filterBountyProposals';
type Result = [Option<Bounty>[], Option<Bytes>[], BountyIndex[], DeriveCollectiveProposal[]];
+114
View File
@@ -0,0 +1,114 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AnyFunction } from '@polkadot/types/types';
import * as accounts from './accounts';
import * as balances from './balances';
import * as bounties from './bounties';
import * as chain from './chain';
import * as contracts from './contracts';
import * as council from './council';
import * as crowdloan from './crowdloan';
import * as democracy from './democracy';
import * as elections from './elections';
import * as imOnline from './imOnline';
import * as membership from './membership';
import * as parachains from './parachains';
import * as session from './session';
import * as society from './society';
import * as staking from './staking';
import * as technicalCommittee from './technicalCommittee';
import * as treasury from './treasury';
import * as tx from './tx';
export { packageInfo } from './packageInfo';
export * from './type';
interface Avail {
instances: string[];
withDetect?: boolean;
}
export const derive = { accounts, balances, bounties, chain, contracts, council, crowdloan, democracy, elections, imOnline, membership, parachains, session, society, staking, technicalCommittee, treasury, tx };
type DeriveSection<Section> = {
[Method in keyof Section]: Section[Method] extends AnyFunction
? ReturnType<Section[Method]> // ReturnType<Section[Method]> will be the inner function, i.e. without (api) argument
: never;
};
type DeriveAllSections<AllSections> = {
[Section in keyof AllSections]: DeriveSection<AllSections[Section]>
};
type DeriveCreator = (instanceId: string, api: ApiInterfaceRx) => (...args: unknown[]) => Observable<any>;
export type DeriveCustom = Record<string, Record<string, DeriveCreator>>;
export type ExactDerive = DeriveAllSections<typeof derive>;
// Enable derive only if some of these modules are available
const checks: Record<string, Avail> = {
contracts: { instances: ['contracts'] },
council: { instances: ['council'], withDetect: true },
crowdloan: { instances: ['crowdloan'] },
democracy: { instances: ['democracy'] },
elections: { instances: ['phragmenElection', 'electionsPhragmen', 'elections', 'council'], withDetect: true },
imOnline: { instances: ['imOnline'] },
membership: { instances: ['membership'] },
parachains: { instances: ['parachains', 'registrar'] },
session: { instances: ['session'] },
society: { instances: ['society'] },
staking: { instances: ['staking'] },
technicalCommittee: { instances: ['technicalCommittee'], withDetect: true },
treasury: { instances: ['treasury'] }
};
/**
* Returns an object that will inject `api` into all the functions inside
* `allSections`, and keep the object architecture of `allSections`.
*/
/** @internal */
function injectFunctions<AllSections> (instanceId: string, api: ApiInterfaceRx, allSections: AllSections): DeriveAllSections<AllSections> {
const queryKeys = Object.keys(api.query);
const specName = api.runtimeVersion.specName.toString();
return Object
.keys(allSections)
.filter((sectionName) =>
!checks[sectionName] ||
checks[sectionName].instances.some((q) => queryKeys.includes(q)) ||
(
checks[sectionName].withDetect &&
checks[sectionName].instances.some((q) =>
(api.registry.getModuleInstances(specName, q) || []).some((q) => queryKeys.includes(q))
)
)
)
.reduce((derives, sectionName): DeriveAllSections<AllSections> => {
const section = allSections[sectionName as keyof AllSections];
derives[sectionName as keyof AllSections] = Object
.entries(section)
.reduce((methods, [methodName, creator]): DeriveSection<typeof section> => {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
methods[methodName as keyof typeof section] = creator(instanceId, api);
return methods;
}, {} as DeriveSection<typeof section>);
return derives;
}, {} as DeriveAllSections<AllSections>);
}
// FIXME The return type of this function should be {...ExactDerive, ...DeriveCustom}
// For now we just drop the custom derive typings
/** @internal */
export function decorateDerive (instanceId: string, api: ApiInterfaceRx, custom: DeriveCustom = {}): ExactDerive {
return {
...injectFunctions(instanceId, api, derive),
...injectFunctions(instanceId, api, custom)
};
}
+2 -2
View File
@@ -1,11 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { BlockNumber } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { map } from 'rxjs';
import { memo } from '../util';
@@ -1,11 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { BlockNumber } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { map } from 'rxjs';
import { memo } from '../util';
@@ -1,12 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { BlockNumber } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import { combineLatest } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { combineLatest, map } from 'rxjs';
import { memo } from '../util';
+2 -3
View File
@@ -1,12 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { SignedBlockExtended } from '../type/types';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { catchError, map } from '@polkadot/x-rxjs/operators';
import { catchError, combineLatest, map, of } from 'rxjs';
import { createSignedBlockExtended } from '../type';
import { memo } from '../util';
+2 -3
View File
@@ -1,12 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { HeaderExtended } from '../type/types';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { catchError, map } from '@polkadot/x-rxjs/operators';
import { catchError, combineLatest, map, of } from 'rxjs';
import { createHeaderExtended } from '../type';
import { memo } from '../util';
@@ -1,14 +1,13 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Vec } from '@polkadot/types';
import type { EventRecord, SignedBlock } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { HeaderExtended, SignedBlockExtended } from '../type/types';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { createSignedBlockExtended } from '../type';
import { memo } from '../util';
@@ -1,12 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { HeaderExtended } from '../type/types';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { combineLatest, map, of } from 'rxjs';
import { createHeaderExtended } from '../type';
import { memo } from '../util';
@@ -0,0 +1,12 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ApiInterfaceRx } from '@polkadot/api/types';
export function getInstance (api: ApiInterfaceRx, section: string): string {
const instances = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), section);
return instances && instances.length
? instances[0]
: section;
}
@@ -1,4 +1,6 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './members';
export * from './prime';
export * from './proposals';
@@ -0,0 +1,24 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import type { Collective } from './types';
import { of } from 'rxjs';
import { isFunction } from '@polkadot/util';
import { memo } from '../util';
import { getInstance } from './getInstance';
export function members (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<AccountId[]> {
const section = getInstance(api, _section);
return memo(instanceId, (): Observable<AccountId[]> =>
isFunction(api.query[section]?.members)
? api.query[section as 'council'].members()
: of([])
);
}
@@ -0,0 +1,28 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option } from '@polkadot/types';
import type { AccountId } from '@polkadot/types/interfaces';
import { map, of } from 'rxjs';
import { isFunction } from '@polkadot/util';
import { memo } from '../util';
import { getInstance } from './getInstance';
export function prime (instanceId: string, api: ApiInterfaceRx, _section: string): () => Observable<AccountId | null> {
const section = getInstance(api, _section);
return memo(instanceId, (): Observable<AccountId | null> =>
isFunction(api.query[section as 'council']?.prime)
? api.query[section as 'council'].prime<Option<AccountId>>().pipe(
map((optPrime): AccountId | null =>
optPrime.unwrapOr(null)
)
)
: of(null)
);
}
+53 -19
View File
@@ -1,19 +1,19 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option } from '@polkadot/types';
import type { Option, u32 } from '@polkadot/types';
import type { Hash, Proposal, Votes } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveCollectiveProposal } from '../types';
import type { Collective } from './types';
import { catchError, combineLatest, map, of, switchMap } from 'rxjs';
import { isFunction } from '@polkadot/util';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { catchError, map, switchMap } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
type Collective = 'council' | 'membership' | 'technicalCommittee';
import { getInstance } from './getInstance';
type Result = [(Hash | Uint8Array | string)[], (Option<Proposal> | null)[], Option<Votes>[]];
@@ -31,39 +31,73 @@ function parse (api: ApiInterfaceRx, [hashes, proposals, votes]: Result): Derive
.filter((proposal): proposal is DeriveCollectiveProposal => !!proposal);
}
function _proposalsFrom (instanceId: string, api: ApiInterfaceRx, section: Collective): (hashes: (Hash | Uint8Array | string)[]) => Observable<DeriveCollectiveProposal[]> {
function _proposalsFrom (instanceId: string, api: ApiInterfaceRx, section: string): (hashes: (Hash | Uint8Array | string)[]) => Observable<DeriveCollectiveProposal[]> {
return memo(instanceId, (hashes: (Hash | Uint8Array | string)[]): Observable<DeriveCollectiveProposal[]> =>
(isFunction(api.query[section]?.proposals) && hashes.length
? combineLatest<Result>([
? combineLatest([
of(hashes),
// this should simply be api.query[section].proposalOf.multi<Option<Proposal>>(hashes),
// however we have had cases on Edgeware where the indices have moved around after an
// upgrade, which results in invalid on-chain data
combineLatest(hashes.map((hash) =>
// this should simply be api.query[section].proposalOf.multi<Option<Proposal>>(hashes),
// however we have had cases on Edgeware where the indices have moved around after an
// upgrade, which results in invalid on-chain data
api.query[section].proposalOf(hash).pipe(catchError(() => of(null)))
api.query[section].proposalOf<Option<Proposal>>(hash).pipe(
catchError(() => of(null))
)
)),
api.query[section].voting.multi<Option<Votes>>(hashes)
])
: of([[], [], []] as Result)
: of<Result>([[], [], []])
).pipe(
map((result) => parse(api, result))
)
);
}
export function proposals (instanceId: string, api: ApiInterfaceRx, section: Collective): () => Observable<DeriveCollectiveProposal[]> {
const proposalsFrom = _proposalsFrom(instanceId, api, section);
export function hasProposals (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<boolean> {
const section = getInstance(api, _section);
return memo(instanceId, (): Observable<DeriveCollectiveProposal[]> =>
isFunction(api.query[section]?.proposals)
? api.query[section as 'council'].proposals().pipe(
switchMap(proposalsFrom)
)
: of([] as DeriveCollectiveProposal[])
return memo(instanceId, (): Observable<boolean> =>
of(isFunction(api.query[section]?.proposals))
);
}
export function proposal (instanceId: string, api: ApiInterfaceRx, section: Collective): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
export function proposalCount (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<u32 | null> {
const section = getInstance(api, _section);
return memo(instanceId, (): Observable<u32 | null> =>
isFunction(api.query[section].proposalCount)
? api.query[section as 'council'].proposalCount()
: of(null)
);
}
export function proposalHashes (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<Hash[]> {
const section = getInstance(api, _section);
return memo(instanceId, (): Observable<Hash[]> =>
isFunction(api.query[section]?.proposals)
? api.query[section as 'council'].proposals()
: of([])
);
}
export function proposals (instanceId: string, api: ApiInterfaceRx, _section: Collective): () => Observable<DeriveCollectiveProposal[]> {
const section = getInstance(api, _section);
const proposalsFrom = _proposalsFrom(instanceId, api, section);
const getHashes = proposalHashes(instanceId, api, _section);
return memo(instanceId, (): Observable<DeriveCollectiveProposal[]> =>
getHashes().pipe(
switchMap(proposalsFrom)
)
);
}
export function proposal (instanceId: string, api: ApiInterfaceRx, _section: Collective): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
const section = getInstance(api, _section);
const proposalsFrom = _proposalsFrom(instanceId, api, section);
return memo(instanceId, (hash: Hash | Uint8Array | string): Observable<DeriveCollectiveProposal | null> =>
@@ -0,0 +1,4 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
export type Collective = 'council' | 'membership' | 'technicalCommittee';
+2 -3
View File
@@ -1,13 +1,12 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { BN } from '@polkadot/util';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveContractFees } from '../types';
import { of } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { map, of } from 'rxjs';
import { memo } from '../util';
+2
View File
@@ -1,6 +1,8 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './members';
export * from './prime';
export * from './proposals';
export * from './votes';
export * from './votesOf';
@@ -0,0 +1,13 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import { members as collectiveMembers } from '../collective';
import { memo } from '../util';
export function members (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId[]> {
return memo(instanceId, collectiveMembers(instanceId, api, 'council'));
}
+13
View File
@@ -0,0 +1,13 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import { prime as collectivePrime } from '../collective';
import { memo } from '../util';
export function prime (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId | null> {
return memo(instanceId, collectivePrime(instanceId, api, 'council'));
}
+15 -2
View File
@@ -1,18 +1,31 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { u32 } from '@polkadot/types';
import type { Hash } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveCollectiveProposal } from '../types';
import { proposal as collectiveProposal, proposals as collectiveProposals } from '../collective';
import { hasProposals as collectiveHasProposals, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective';
import { memo } from '../util';
export function hasProposals (instanceId: string, api: ApiInterfaceRx): () => Observable<boolean> {
return memo(instanceId, collectiveHasProposals(instanceId, api, 'council'));
}
export function proposal (instanceId: string, api: ApiInterfaceRx): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
return memo(instanceId, collectiveProposal(instanceId, api, 'council'));
}
export function proposalCount (instanceId: string, api: ApiInterfaceRx): () => Observable<u32 | null> {
return memo(instanceId, collectiveProposalCount(instanceId, api, 'council'));
}
export function proposalHashes (instanceId: string, api: ApiInterfaceRx): () => Observable<Hash[]> {
return memo(instanceId, collectiveProposalHashes(instanceId, api, 'council'));
}
export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveCollectiveProposal[]> {
return memo(instanceId, collectiveProposals(instanceId, api, 'council'));
}
+20 -16
View File
@@ -1,15 +1,14 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx, QueryableModuleStorage } from '@polkadot/api/types';
import type { Vec } from '@polkadot/types';
import type { AccountId, Balance, Voter } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveCouncilVote, DeriveCouncilVotes } from '../types';
import { combineLatest } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { combineLatest, map, of } from 'rxjs';
import { memo } from '../util';
@@ -20,24 +19,27 @@ function isVoter (value: VoteEntry): value is Voter {
return !Array.isArray(value);
}
function retrieveStakeOf (api: ApiInterfaceRx): Observable<[AccountId, Balance][]> {
return (api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections).stakeOf.entries<Balance, [AccountId]>().pipe(
function retrieveStakeOf (elections: QueryableModuleStorage<'rxjs'>): Observable<[AccountId, Balance][]> {
return elections.stakeOf.entries<Balance, [AccountId]>().pipe(
map((entries) =>
entries.map(([{ args: [accountId] }, stake]) => [accountId, stake])
)
);
}
function retrieveVoteOf (api: ApiInterfaceRx): Observable<[AccountId, AccountId[]][]> {
return (api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections).votesOf.entries<Vec<AccountId>, [AccountId]>().pipe(
function retrieveVoteOf (elections: QueryableModuleStorage<'rxjs'>): Observable<[AccountId, AccountId[]][]> {
return elections.votesOf.entries<Vec<AccountId>, [AccountId]>().pipe(
map((entries) =>
entries.map(([{ args: [accountId] }, votes]) => [accountId, votes])
)
);
}
function retrievePrev (api: ApiInterfaceRx): Observable<DeriveCouncilVotes> {
return combineLatest([retrieveStakeOf(api), retrieveVoteOf(api)]).pipe(
function retrievePrev (api: ApiInterfaceRx, elections: QueryableModuleStorage<'rxjs'>): Observable<DeriveCouncilVotes> {
return combineLatest([
retrieveStakeOf(elections),
retrieveVoteOf(elections)
]).pipe(
map(([stakes, votes]): DeriveCouncilVotes => {
const result: DeriveCouncilVotes = [];
@@ -60,9 +62,7 @@ function retrievePrev (api: ApiInterfaceRx): Observable<DeriveCouncilVotes> {
);
}
function retrieveCurrent (api: ApiInterfaceRx): Observable<DeriveCouncilVotes> {
const elections = (api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections);
function retrieveCurrent (elections: QueryableModuleStorage<'rxjs'>): Observable<DeriveCouncilVotes> {
return elections.voting.entries<VoteEntry, [AccountId]>().pipe(
map((entries): DeriveCouncilVotes =>
entries.map(([{ args: [accountId] }, value]): [AccountId, DeriveCouncilVote] => [
@@ -76,9 +76,13 @@ function retrieveCurrent (api: ApiInterfaceRx): Observable<DeriveCouncilVotes> {
}
export function votes (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveCouncilVotes> {
const elections = api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections;
return memo(instanceId, (): Observable<DeriveCouncilVotes> =>
(api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections).stakeOf
? retrievePrev(api)
: retrieveCurrent(api)
elections
? elections.stakeOf
? retrievePrev(api, elections)
: retrieveCurrent(elections)
: of([])
);
}
+2 -2
View File
@@ -1,12 +1,12 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveCouncilVote } from '../types';
import { map } from '@polkadot/x-rxjs/operators';
import { map } from 'rxjs';
import { memo } from '../util';
@@ -0,0 +1,37 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option } from '@polkadot/types';
import type { FundInfo, ParaId } from '@polkadot/types/interfaces';
import { map } from 'rxjs';
import { u8aConcat, u8aToHex } from '@polkadot/util';
import { blake2AsU8a } from '@polkadot/util-crypto';
import { memo } from '../util';
function createChildKey ({ trieIndex }: FundInfo): string {
return u8aToHex(
u8aConcat(
':child_storage:default:',
blake2AsU8a(
u8aConcat('crowdloan', trieIndex.toU8a())
)
)
);
}
export function childKey (instanceId: string, api: ApiInterfaceRx): (paraId: string | number | ParaId) => Observable<string | null> {
return memo(instanceId, (paraId: string | number | ParaId): Observable<string | null> =>
api.query.crowdloan.funds<Option<FundInfo>>(paraId).pipe(
map((optInfo) =>
optInfo.isSome
? createChildKey(optInfo.unwrap())
: null
)
)
);
}
@@ -0,0 +1,135 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { StorageKey } from '@polkadot/types';
import type { ParaId } from '@polkadot/types/interfaces';
import type { DeriveContributions } from '../types';
import { BehaviorSubject, combineLatest, EMPTY, map, of, startWith, switchMap, tap, toArray } from 'rxjs';
import { arrayFlatten, isFunction } from '@polkadot/util';
import { memo } from '../util';
import { extractContributed } from './util';
interface Changes {
added: string[];
blockHash: string;
removed: string[];
}
const PAGE_SIZE_K = 1000; // limit aligned with the 1k on the node (trie lookups are heavy)
function _getUpdates (api: ApiInterfaceRx, paraId: string | number | ParaId): Observable<Changes> {
let added: string[] = [];
let removed: string[] = [];
return api.query.system.events().pipe(
switchMap((events): Observable<Changes> => {
const changes = extractContributed(paraId, events);
if (changes.added.length || changes.removed.length) {
added = added.concat(...changes.added);
removed = removed.concat(...changes.removed);
return of({ added, addedDelta: changes.added, blockHash: events.createdAtHash?.toHex() || '-', removed, removedDelta: changes.removed });
}
return EMPTY;
}),
startWith({ added, addedDelta: [], blockHash: '-', removed, removedDelta: [] })
);
}
function _eventTriggerAll (api: ApiInterfaceRx, paraId: string | number | ParaId): Observable<string> {
return api.query.system.events().pipe(
switchMap((events): Observable<string> => {
const items = events.filter(({ event: { data: [eventParaId], method, section } }) =>
section === 'crowdloan' &&
['AllRefunded', 'Dissolved', 'PartiallyRefunded'].includes(method) &&
eventParaId.eq(paraId)
);
return items.length
? of(events.createdAtHash?.toHex() || '-')
: EMPTY;
}),
startWith('-')
);
}
function _getKeysPaged (api: ApiInterfaceRx, childKey: string): Observable<StorageKey[]> {
const startSubject = new BehaviorSubject<string | undefined>(undefined);
return startSubject.pipe(
switchMap((startKey) =>
api.rpc.childstate.getKeysPaged(childKey, '0x', PAGE_SIZE_K, startKey)
),
tap((keys): void => {
setTimeout((): void => {
keys.length === PAGE_SIZE_K
? startSubject.next(keys[PAGE_SIZE_K - 1].toHex())
: startSubject.complete();
}, 0);
}),
toArray(), // toArray since we want to startSubject to be completed
map((keyArr: StorageKey[][]) => arrayFlatten(keyArr))
);
}
function _getAll (api: ApiInterfaceRx, paraId: string | number | ParaId, childKey: string): Observable<string[]> {
return _eventTriggerAll(api, paraId).pipe(
switchMap(() =>
// FIXME Needs testing and being enabled
// eslint-disable-next-line no-constant-condition
isFunction(api.rpc.childstate.getKeysPaged) && false
? _getKeysPaged(api, childKey)
: api.rpc.childstate.getKeys(childKey, '0x')
),
map((keys) =>
keys.map((k) => k.toHex())
)
);
}
function _contributions (api: ApiInterfaceRx, paraId: string | number | ParaId, childKey: string): Observable<DeriveContributions> {
return combineLatest([
_getAll(api, paraId, childKey),
_getUpdates(api, paraId)
]).pipe(
map(([keys, { added, blockHash, removed }]): DeriveContributions => {
const contributorsMap: Record<string, boolean> = {};
keys.forEach((k): void => {
contributorsMap[k] = true;
});
added.forEach((k): void => {
contributorsMap[k] = true;
});
removed.forEach((k): void => {
delete contributorsMap[k];
});
return {
blockHash,
contributorsHex: Object.keys(contributorsMap)
};
})
);
}
export function contributions (instanceId: string, api: ApiInterfaceRx): (paraId: string | number | ParaId) => Observable<DeriveContributions> {
return memo(instanceId, (paraId: string | number | ParaId): Observable<DeriveContributions> =>
api.derive.crowdloan.childKey(paraId).pipe(
switchMap((childKey) =>
childKey
? _contributions(api, paraId, childKey)
: of({ blockHash: '-', contributorsHex: [] })
)
)
);
}
@@ -0,0 +1,6 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './childKey';
export * from './contributions';
export * from './onwContributions';
@@ -0,0 +1,72 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { ParaId } from '@polkadot/types/interfaces';
import type { DeriveOwnContributions } from '../types';
import { combineLatest, EMPTY, map, of, startWith, switchMap } from 'rxjs';
import { memo } from '../util';
import { extractContributed } from './util';
function _getValues (api: ApiInterfaceRx, childKey: string, keys: string[]): Observable<DeriveOwnContributions> {
// We actually would love to use multi-keys https://github.com/paritytech/substrate/issues/9203
return combineLatest(keys.map((k) => api.rpc.childstate.getStorage(childKey, k))).pipe(
map((values) =>
values
.map((v) => api.registry.createType('Option<StorageData>', v))
.map((o) =>
o.isSome
? api.registry.createType('Balance', o.unwrap())
: api.registry.createType('Balance')
)
.reduce((all: DeriveOwnContributions, b, index): DeriveOwnContributions => ({
...all,
[keys[index]]: b
}), {})
)
);
}
function _watchOwnChanges (api: ApiInterfaceRx, paraId: string | number | ParaId, childkey: string, keys: string[]): Observable<DeriveOwnContributions> {
return api.query.system.events().pipe(
switchMap((events): Observable<DeriveOwnContributions> => {
const changes = extractContributed(paraId, events);
const filtered = keys.filter((k) =>
changes.added.includes(k) ||
changes.removed.includes(k)
);
return filtered.length
? _getValues(api, childkey, filtered)
: EMPTY;
}),
startWith({})
);
}
function _contributions (api: ApiInterfaceRx, paraId: string | number | ParaId, childKey: string, keys: string[]): Observable<DeriveOwnContributions> {
return combineLatest([
_getValues(api, childKey, keys),
_watchOwnChanges(api, paraId, childKey, keys)
]).pipe(
map(([all, latest]) => ({
...all,
...latest
}))
);
}
export function ownContributions (instanceId: string, api: ApiInterfaceRx): (paraId: string | number | ParaId, keys: string[]) => Observable<DeriveOwnContributions> {
return memo(instanceId, (paraId: string | number | ParaId, keys: string[]): Observable<DeriveOwnContributions> =>
api.derive.crowdloan.childKey(paraId).pipe(
switchMap((childKey) =>
childKey && keys.length
? _contributions(api, paraId, childKey, keys)
: of({})
)
)
);
}
@@ -0,0 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Balance } from '@polkadot/types/interfaces';
export interface DeriveContributions {
blockHash: string;
contributorsHex: string[];
}
export type DeriveOwnContributions = Record<string, Balance>;
+32
View File
@@ -0,0 +1,32 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Vec } from '@polkadot/types';
import type { EventRecord, ParaId } from '@polkadot/types/interfaces';
interface Changes {
added: string[];
blockHash: string;
removed: string[];
}
export function extractContributed (paraId: string | number | ParaId, events: Vec<EventRecord>): Changes {
const added: string[] = [];
const removed: string[] = [];
return events
.filter(({ event: { data: [, eventParaId], method, section } }) =>
section === 'crowdloan' &&
['Contributed', 'Withdrew'].includes(method) &&
eventParaId.eq(paraId)
)
.reduce((result: Changes, { event: { data: [accountId], method } }): Changes => {
if (method === 'Contributed') {
result.added.push(accountId.toHex());
} else {
result.removed.push(accountId.toHex());
}
return result;
}, { added, blockHash: events.createdAtHash?.toHex() || '-', removed });
}
@@ -1,16 +1,16 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option, u64, Vec } from '@polkadot/types';
import type { BlockNumber, Hash, ReferendumIndex, Scheduled } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveDispatch, DeriveProposalImage } from '../types';
import { catchError, combineLatest, map, of, switchMap } from 'rxjs';
import { isFunction, stringToHex } from '@polkadot/util';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
@@ -42,7 +42,7 @@ function queryQueue (api: ApiInterfaceRx): Observable<DeriveDispatch[]> {
);
}
function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], Option<Scheduled>[][]]> {
function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], (Option<Scheduled>[] | null)[]]> {
// We don't get entries, but rather we get the keys (triggered via finished referendums) and
// the subscribe to those keys - this means we pickup when the schedulers actually executes
// at a block, the entry for that block will become empty
@@ -53,10 +53,20 @@ function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], Opti
switchMap((keys) => {
const blockNumbers = keys.map(({ args: [blockNumber] }) => blockNumber);
return combineLatest([
of(blockNumbers),
api.query.scheduler.agenda.multi<Vec<Option<Scheduled>>>(blockNumbers)
]);
return blockNumbers.length
? combineLatest([
of(blockNumbers),
// this should simply be api.query.scheduler.agenda.multi<Vec<Option<Scheduled>>>,
// however we have had cases on Darwinia where the indices have moved around after an
// upgrade, which results in invalid on-chain data
combineLatest(blockNumbers.map((blockNumber) =>
api.query.scheduler.agenda<Vec<Option<Scheduled>>>(blockNumber).pipe(
// this does create an issue since it discards all at that block
catchError(() => of(null))
)
))
])
: of<[BlockNumber[], null[]]>([[], []]);
})
);
}
@@ -67,26 +77,30 @@ function queryScheduler (api: ApiInterfaceRx): Observable<DeriveDispatch[]> {
const result: SchedulerInfo[] = [];
blockNumbers.forEach((at, index): void => {
agendas[index].filter((optScheduled) => optScheduled.isSome).forEach((optScheduled): void => {
const scheduled = optScheduled.unwrap();
(agendas[index] || [])
.filter((opt) => opt.isSome)
.forEach((optScheduled): void => {
const scheduled = optScheduled.unwrap();
if (scheduled.maybeId.isSome) {
const id = scheduled.maybeId.unwrap().toHex();
if (scheduled.maybeId.isSome) {
const id = scheduled.maybeId.unwrap().toHex();
if (id.startsWith(DEMOCRACY_ID)) {
const [, index] = api.registry.createType('(u64, ReferendumIndex)' as any, id) as ITuple<[u64, ReferendumIndex]>;
const imageHash = scheduled.call.args[0] as Hash;
if (id.startsWith(DEMOCRACY_ID)) {
const [, index] = api.registry.createType('(u64, ReferendumIndex)' as any, id) as ITuple<[u64, ReferendumIndex]>;
const imageHash = scheduled.call.args[0] as Hash;
result.push({ at, imageHash, index });
result.push({ at, imageHash, index });
}
}
}
});
});
});
return combineLatest([
of(result),
api.derive.democracy.preimages(result.map(({ imageHash }) => imageHash))
]);
return result.length
? combineLatest([
of(result),
api.derive.democracy.preimages(result.map(({ imageHash }) => imageHash))
])
: of([[], []]);
}),
map(([infos, images]): DeriveDispatch[] =>
infos.map((info, index) => ({ ...info, image: images[index] }))
+3 -3
View File
@@ -1,16 +1,16 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option } from '@polkadot/types';
import type { AccountId, ReferendumInfo, ReferendumInfoFinished, ReferendumInfoTo239, Vote, VotingDelegating, VotingDirect, VotingDirectVote } from '@polkadot/types/interfaces';
import type { BN } from '@polkadot/util';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveDemocracyLock } from '../types';
import { map, of, switchMap } from 'rxjs';
import { BN_ZERO, isUndefined } from '@polkadot/util';
import { of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
@@ -1,15 +1,14 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option } from '@polkadot/types';
import type { Hash, VoteThreshold } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveProposalExternal } from '../types';
import { of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { map, of, switchMap } from 'rxjs';
import { memo } from '../util';
@@ -1,14 +1,14 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Bytes, Option } from '@polkadot/types';
import type { AccountId, Balance, BlockNumber, Hash } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveProposalImage } from '../types';
import { map } from '@polkadot/x-rxjs/operators';
import { map } from 'rxjs';
import { memo } from '../util';
import { parseImage } from './util';
@@ -1,14 +1,14 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Bytes, Option } from '@polkadot/types';
import type { AccountId, Balance, BlockNumber, Hash } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveProposalImage } from '../types';
import { map } from '@polkadot/x-rxjs/operators';
import { map, of } from 'rxjs';
import { memo } from '../util';
import { parseImage } from './util';
@@ -17,10 +17,12 @@ type PreImage = Option<ITuple<[Bytes, AccountId, Balance, BlockNumber]>>;
export function preimages (instanceId: string, api: ApiInterfaceRx): (hashes: Hash[]) => Observable<(DeriveProposalImage | undefined)[]> {
return memo(instanceId, (hashes: Hash[]): Observable<(DeriveProposalImage | undefined)[]> =>
api.query.democracy.preimages.multi<PreImage>(hashes).pipe(
map((images): (DeriveProposalImage | undefined)[] =>
images.map((imageOpt) => parseImage(api, imageOpt))
hashes.length
? api.query.democracy.preimages.multi<PreImage>(hashes).pipe(
map((images): (DeriveProposalImage | undefined)[] =>
images.map((imageOpt) => parseImage(api, imageOpt))
)
)
)
: of([])
);
}
+13 -11
View File
@@ -1,23 +1,23 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option, Vec } from '@polkadot/types';
import type { AccountId, Balance, Hash, PropIndex } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveProposal, DeriveProposalImage } from '../types';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { isFunction } from '@polkadot/util';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
type DepositorsNew = Option<ITuple<[Vec<AccountId>, Balance]>>;
type DepositorsOld = Option<ITuple<[Balance, Vec<AccountId>]>>;
type Depositors = DepositorsNew | DepositorsOld;
type Proposals = Vec<ITuple<[PropIndex, Hash, AccountId]>>;
type Proposals = ITuple<[PropIndex, Hash, AccountId]>[];
type Result = [Proposals, (DeriveProposalImage | undefined)[], Depositors[]];
// eslint-disable-next-line @typescript-eslint/no-unused-vars
@@ -54,13 +54,15 @@ export function proposals (instanceId: string, api: ApiInterfaceRx): () => Obser
isFunction(api.query.democracy?.publicProps) && isFunction(api.query.democracy?.preimages)
? api.query.democracy.publicProps<Proposals>().pipe(
switchMap((proposals) =>
combineLatest([
of(proposals),
api.derive.democracy.preimages(
proposals.map(([, hash]): Hash => hash)),
api.query.democracy.depositOf.multi<Depositors>(
proposals.map(([index]): PropIndex => index))
])
proposals.length
? combineLatest([
of(proposals),
api.derive.democracy.preimages(
proposals.map(([, hash]): Hash => hash)),
api.query.democracy.depositOf.multi<Depositors>(
proposals.map(([index]): PropIndex => index))
])
: of<Result>([[], [], []])
),
map(parse)
)
@@ -1,13 +1,12 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { ReferendumIndex } from '@polkadot/types/interfaces';
import type { BN } from '@polkadot/util';
import type { Observable } from '@polkadot/x-rxjs';
import { of } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { map, of } from 'rxjs';
import { memo } from '../util';
@@ -1,12 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveReferendumExt } from '../types';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { memo } from '../util';
@@ -14,10 +13,12 @@ export function referendums (instanceId: string, api: ApiInterfaceRx): () => Obs
return memo(instanceId, (): Observable<DeriveReferendumExt[]> =>
api.derive.democracy.referendumsActive().pipe(
switchMap((referendums) =>
combineLatest([
of(referendums),
api.derive.democracy._referendumsVotes(referendums)
])
referendums.length
? combineLatest([
of(referendums),
api.derive.democracy._referendumsVotes(referendums)
])
: of([[], []])
),
map(([referendums, votes]) =>
referendums.map((referendum, index): DeriveReferendumExt => ({
@@ -1,12 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveReferendum } from '../types';
import { of } from '@polkadot/x-rxjs';
import { switchMap } from '@polkadot/x-rxjs/operators';
import { of, switchMap } from 'rxjs';
import { memo } from '../util';
@@ -1,24 +1,25 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option } from '@polkadot/types';
import type { ReferendumInfo, ReferendumInfoFinished } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { map, switchMap } from 'rxjs';
import { memo } from '../util';
export function referendumsFinished (instanceId: string, api: ApiInterfaceRx): () => Observable<ReferendumInfoFinished[]> {
return memo(instanceId, (): Observable<ReferendumInfoFinished[]> =>
api.derive.democracy.referendumIds().pipe(
switchMap((ids) => api.query.democracy.referendumInfoOf.multi<Option<ReferendumInfo>>(ids)),
switchMap((ids) =>
api.query.democracy.referendumInfoOf.multi<Option<ReferendumInfo>>(ids)
),
map((infos): ReferendumInfoFinished[] =>
infos
.filter((optInfo) => optInfo.isSome)
.map((optInfo) => optInfo.unwrap())
.filter((info) => info.isFinished)
.map((optInfo) => optInfo.unwrapOr(null))
.filter((info): info is ReferendumInfo => !!info && info.isFinished)
.map((info) => info.asFinished)
)
)
@@ -1,16 +1,16 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option, Vec } from '@polkadot/types';
import type { AccountId, ReferendumInfo, ReferendumInfoTo239, Vote, Voting, VotingDelegating, VotingDirectVote } from '@polkadot/types/interfaces';
import type { BN } from '@polkadot/util';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveBalancesAccount, DeriveReferendum, DeriveReferendumVote, DeriveReferendumVotes } from '../types';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { isFunction } from '@polkadot/util';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
import { calcVotes, getStatus, parseImage } from './util';
@@ -1,12 +1,13 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { BN } from '@polkadot/util';
import type { Observable } from '@polkadot/x-rxjs';
import { map } from 'rxjs';
import { bnSqrt } from '@polkadot/util';
import { map } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
+34 -16
View File
@@ -1,14 +1,14 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { u32, Vec } from '@polkadot/types';
import type { AccountId, Balance, BlockNumber, SeatHolder } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveElectionsInfo } from './types';
import { map } from '@polkadot/x-rxjs/operators';
import { combineLatest, map, of } from 'rxjs';
import { memo } from '../util';
@@ -42,30 +42,48 @@ function sortAccounts ([, balanceA]: [AccountId, Balance], [, balanceB]: [Accoun
}
function queryElections (api: ApiInterfaceRx): Observable<DeriveElectionsInfo> {
const section = api.query.phragmenElection
const elections = api.query.phragmenElection
? 'phragmenElection'
: api.query.electionsPhragmen
? 'electionsPhragmen'
: 'elections';
: api.query.elections
? 'elections'
: null;
const [council] = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), 'council') || ['council'];
return api.queryMulti<[Vec<AccountId>, Vec<Candidate>, Vec<Member>, Vec<Member>]>([
api.query.council.members,
api.query[section].candidates,
api.query[section].members,
api.query[section].runnersUp
]).pipe(
return (
elections
? api.queryMulti<[Vec<AccountId>, Vec<Candidate>, Vec<Member>, Vec<Member>]>([
api.query[council].members,
api.query[elections].candidates,
api.query[elections].members,
api.query[elections].runnersUp
])
: combineLatest([
api.query[council].members<Vec<AccountId>>(),
of<Candidate[]>([]),
of<Member[]>([]),
of<Member[]>([])
])
).pipe(
map(([councilMembers, candidates, members, runnersUp]): DeriveElectionsInfo => ({
candidacyBond: api.consts[section].candidacyBond as Balance,
...(
elections
? {
candidacyBond: api.consts[elections].candidacyBond as Balance,
desiredRunnersUp: api.consts[elections].desiredRunnersUp as u32,
desiredSeats: api.consts[elections].desiredMembers as u32,
termDuration: api.consts[elections].termDuration as BlockNumber,
votingBond: api.consts[elections].votingBond as Balance
}
: {}
),
candidateCount: api.registry.createType('u32', candidates.length),
candidates: candidates.map(getCandidate),
desiredRunnersUp: api.consts[section].desiredRunnersUp as u32,
desiredSeats: api.consts[section].desiredMembers as u32,
members: members.length
? members.map(getAccountTuple).sort(sortAccounts)
: councilMembers.map((accountId): [AccountId, Balance] => [accountId, api.registry.createType('Balance')]),
runnersUp: runnersUp.map(getAccountTuple).sort(sortAccounts),
termDuration: api.consts[section].termDuration as BlockNumber,
votingBond: api.consts[section].votingBond as Balance
runnersUp: runnersUp.map(getAccountTuple).sort(sortAccounts)
}))
);
}
+3 -3
View File
@@ -8,12 +8,12 @@ export interface DeriveElectionsInfo {
candidates: AccountId[];
candidateCount: u32;
candidacyBond?: Balance;
desiredRunnersUp: u32;
desiredSeats: u32;
desiredRunnersUp?: u32;
desiredSeats?: u32;
members: [AccountId, Balance][];
nextVoterSet?: SetIndex;
runnersUp: [AccountId, Balance][];
termDuration: BlockNumber;
termDuration?: BlockNumber;
voteCount?: VoteIndex;
voterCount?: SetIndex;
votingBond?: Balance;
@@ -1,15 +1,15 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Bytes, Option, u32 } from '@polkadot/types';
import type { AccountId } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveHeartbeats } from '../types';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { BN_ZERO } from '@polkadot/util';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
+2 -1
View File
@@ -5,10 +5,11 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/restrict-template-expressions */
import { from, Observable } from 'rxjs';
import { ApiRx } from '@polkadot/api/rx';
import { MockProvider } from '@polkadot/rpc-provider/mock';
import { TypeRegistry } from '@polkadot/types/create';
import { from, Observable } from '@polkadot/x-rxjs';
import { ExactDerive } from '.';
+1 -100
View File
@@ -3,103 +3,4 @@
import './detectPackage';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AnyFunction } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import * as accounts from './accounts';
import * as balances from './balances';
import * as bounties from './bounties';
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 membership from './membership';
import * as parachains from './parachains';
import * as session from './session';
import * as society from './society';
import * as staking from './staking';
import * as technicalCommittee from './technicalCommittee';
import * as treasury from './treasury';
import * as tx from './tx';
export { packageInfo } from './packageInfo';
export * from './type';
export const derive = { accounts, balances, bounties, chain, contracts, council, democracy, elections, imOnline, membership, parachains, session, society, staking, technicalCommittee, treasury, tx };
type DeriveSection<Section> = {
[Method in keyof Section]: Section[Method] extends AnyFunction
? ReturnType<Section[Method]> // ReturnType<Section[Method]> will be the inner function, i.e. without (api) argument
: never;
};
type DeriveAllSections<AllSections> = {
[Section in keyof AllSections]: DeriveSection<AllSections[Section]>
};
export type DeriveCustom = Record<string, Record<string, (instanceId: string, api: ApiInterfaceRx) => (...args: any[]) => Observable<any>>>;
export type ExactDerive = DeriveAllSections<typeof derive>;
// Enable derive only if some of these modules are available
const deriveAvail: Record<string, string[]> = {
contracts: ['contracts'],
council: ['council'],
democracy: ['democracy'],
elections: ['phragmenElection', 'electionsPhragmen', 'elections'],
imOnline: ['imOnline'],
membership: ['membership'],
parachains: ['parachains', 'registrar'],
session: ['session'],
society: ['society'],
staking: ['staking'],
technicalCommittee: ['technicalCommittee'],
treasury: ['treasury']
};
/**
* Returns an object that will inject `api` into all the functions inside
* `allSections`, and keep the object architecture of `allSections`.
*/
/** @internal */
function injectFunctions<AllSections> (instanceId: string, api: ApiInterfaceRx, allSections: AllSections): DeriveAllSections<AllSections> {
const queryKeys = Object.keys(api.query);
return Object
.keys(allSections)
.filter((sectionName): boolean =>
!deriveAvail[sectionName] || deriveAvail[sectionName].some((query): boolean => queryKeys.includes(query))
)
.reduce((deriveAcc, sectionName): DeriveAllSections<AllSections> => {
const section = allSections[sectionName as keyof AllSections];
deriveAcc[sectionName as keyof AllSections] = Object
.keys(section)
.reduce((sectionAcc, _methodName): DeriveSection<typeof section> => {
const methodName = _methodName as keyof typeof section;
// Not sure what to do here, casting as any. Though the final types are good
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call
const method = (section[methodName] as any)(instanceId, api);
// idem
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-member-access
(sectionAcc as any)[methodName] = method;
return sectionAcc;
}, {} as DeriveSection<typeof section>);
return deriveAcc;
}, {} as DeriveAllSections<AllSections>);
}
// FIXME The return type of this function should be {...ExactDerive, ...DeriveCustom}
// For now we just drop the custom derive typings
/** @internal */
export function decorateDerive (instanceId: string, api: ApiInterfaceRx, custom: DeriveCustom = {}): ExactDerive {
return {
...injectFunctions(instanceId, api, derive),
...injectFunctions(instanceId, api, custom)
};
}
export * from './bundle';
@@ -1,4 +1,6 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './members';
export * from './prime';
export * from './proposals';
@@ -0,0 +1,13 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import { members as collectiveMembers } from '../collective';
import { memo } from '../util';
export function members (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId[]> {
return memo(instanceId, collectiveMembers(instanceId, api, 'membership'));
}
@@ -0,0 +1,13 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import { prime as collectivePrime } from '../collective';
import { memo } from '../util';
export function prime (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountId | null> {
return memo(instanceId, collectivePrime(instanceId, api, 'membership'));
}
@@ -1,13 +1,31 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { u32 } from '@polkadot/types';
import type { Hash } from '@polkadot/types/interfaces';
import type { DeriveCollectiveProposal } from '../types';
import { proposals as collectiveProposals } from '../collective';
import { hasProposals as collectiveHasProposals, proposal as collectiveProposal, proposalCount as collectiveProposalCount, proposalHashes as collectiveProposalHashes, proposals as collectiveProposals } from '../collective';
import { memo } from '../util';
export function hasProposals (instanceId: string, api: ApiInterfaceRx): () => Observable<boolean> {
return memo(instanceId, collectiveHasProposals(instanceId, api, 'membership'));
}
export function proposal (instanceId: string, api: ApiInterfaceRx): (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
return memo(instanceId, collectiveProposal(instanceId, api, 'membership'));
}
export function proposalCount (instanceId: string, api: ApiInterfaceRx): () => Observable<u32 | null> {
return memo(instanceId, collectiveProposalCount(instanceId, api, 'membership'));
}
export function proposalHashes (instanceId: string, api: ApiInterfaceRx): () => Observable<Hash[]> {
return memo(instanceId, collectiveProposalHashes(instanceId, api, 'membership'));
}
export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveCollectiveProposal[]> {
return memo(instanceId, collectiveProposals(instanceId, api, 'membership'));
}
+1 -1
View File
@@ -3,4 +3,4 @@
// Auto-generated by @polkadot/dev, do not edit
export const packageInfo = { name: '@polkadot/api-derive', version: '4.16.2' };
export const packageInfo = { name: '@polkadot/api-derive', version: '5.1.1' };
+2 -3
View File
@@ -1,14 +1,13 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { CollatorId, ParaId } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveParachainActive, DeriveParachainFull, DeriveParachainInfo } from '../types';
import type { Active, DidUpdate, Heads, ParaInfoResult, PendingSwap, RelayDispatchQueue, RetryQueue, SelectedThreads } from './types';
import { of } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { map, of } from 'rxjs';
import { memo } from '../util';
import { didUpdateToBool } from './util';
@@ -1,14 +1,13 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { ParaId } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveParachain, DeriveParachainInfo } from '../types';
import type { DidUpdate, ParaInfoResult, PendingSwap, RelayDispatchQueueSize } from './types';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { memo } from '../util';
import { didUpdateToBool } from './util';
+2 -2
View File
@@ -1,11 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { BlockNumber } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { map } from 'rxjs';
import { memo } from '../util';
@@ -1,11 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { BlockNumber } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { map } from 'rxjs';
import { memo } from '../util';
+2 -3
View File
@@ -1,14 +1,13 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option, u32 } from '@polkadot/types';
import type { ActiveEraInfo, EraIndex, Moment, SessionIndex } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveSessionIndexes } from '../types';
import { of } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { map, of } from 'rxjs';
import { memo } from '../util';
+2 -2
View File
@@ -1,11 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveSessionInfo } from '../types';
import { map } from '@polkadot/x-rxjs/operators';
import { map } from 'rxjs';
import { memo } from '../util';
+2 -3
View File
@@ -1,14 +1,13 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option, u64 } from '@polkadot/types';
import type { SessionIndex } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveSessionInfo, DeriveSessionProgress } from '../types';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { memo } from '../util';
@@ -1,11 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { BlockNumber } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import { map } from '@polkadot/x-rxjs/operators';
import { map } from 'rxjs';
import { memo } from '../util';
@@ -1,15 +1,14 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option, Vec } from '@polkadot/types';
import type { AccountId, BalanceOf, Bid, BidKind } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveSocietyCandidate } from '../types';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { memo } from '../util';
+2 -2
View File
@@ -1,13 +1,13 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Option, u32, Vec } from '@polkadot/types';
import type { AccountId, BalanceOf, Bid } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveSociety } from '../types';
import { map } from '@polkadot/x-rxjs/operators';
import { map } from 'rxjs';
import { memo } from '../util';
+2 -2
View File
@@ -1,12 +1,12 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveSocietyMember } from '../types';
import { map } from '@polkadot/x-rxjs/operators';
import { map } from 'rxjs';
import { memo } from '../util';
+8 -11
View File
@@ -1,29 +1,26 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { bool, Option, Vec } from '@polkadot/types';
import type { AccountId, Balance, BlockNumber, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces';
import type { ITuple } from '@polkadot/types/types';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveSocietyMember } from '../types';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { memo } from '../util';
type Result = [AccountId[], Vec<ITuple<[BlockNumber, Balance]>>[], StrikeCount[], Option<SocietyVote>[], bool[], Option<VouchingStatus>[]];
export function _members (instanceId: string, api: ApiInterfaceRx): (accountIds: AccountId[]) => Observable<DeriveSocietyMember[]> {
return memo(instanceId, (accountIds: AccountId[]): Observable<DeriveSocietyMember[]> =>
combineLatest<Result>([
combineLatest([
of(accountIds),
api.query.society.payouts.multi(accountIds),
api.query.society.strikes.multi(accountIds),
api.query.society.defenderVotes.multi(accountIds),
api.query.society.suspendedMembers.multi(accountIds),
api.query.society.vouching.multi(accountIds)
api.query.society.payouts.multi<Vec<ITuple<[BlockNumber, Balance]>>>(accountIds),
api.query.society.strikes.multi<StrikeCount>(accountIds),
api.query.society.defenderVotes.multi<Option<SocietyVote>>(accountIds),
api.query.society.suspendedMembers.multi<bool>(accountIds),
api.query.society.vouching.multi<Option<VouchingStatus>>(accountIds)
]).pipe(
map(([accountIds, payouts, strikes, defenderVotes, suspended, vouching]) =>
accountIds.map((accountId, index) => ({
+3 -2
View File
@@ -1,13 +1,14 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Balance, StakingLedger, UnlockChunk } from '@polkadot/types/interfaces';
import type { DeriveSessionInfo, DeriveStakingAccount, DeriveStakingKeys, DeriveStakingQuery, DeriveUnlocking } from '../types';
import { combineLatest, map, switchMap } from 'rxjs';
import { BN, BN_ZERO } from '@polkadot/util';
import { combineLatest, Observable } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
@@ -1,11 +1,11 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { EraRewardPoints } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import { switchMap } from '@polkadot/x-rxjs/operators';
import { switchMap } from 'rxjs';
import { memo } from '../util';
@@ -1,13 +1,14 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { AccountId } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveStakingElected, StakingQueryFlags } from '../types';
import { map, switchMap } from 'rxjs';
import { arrayFlatten } from '@polkadot/util';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { memo } from '../util';
@@ -1,14 +1,13 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { StorageKey } from '@polkadot/types';
import type { AccountId, EraIndex, Exposure } from '@polkadot/types/interfaces';
import type { Observable } from '@polkadot/x-rxjs';
import type { DeriveEraExposure, DeriveEraNominatorExposure, DeriveEraValidatorExposure } from '../types';
import { combineLatest, of } from '@polkadot/x-rxjs';
import { map, switchMap } from '@polkadot/x-rxjs/operators';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { deriveCache, memo } from '../util';

Some files were not shown because too many files have changed in this diff Show More