Move api-derive to correct location (#4343)
* Move api-derive to correct location * Adjust (linting ok) * No composite * ApiDerive split * Adjust * Still WIP, getting closer * It lints * derive build issues sorted * It builds :) * Add system_health to mock * api-augment usage * Cleanups * Adjust paths * linting * Some <'s * Revert <>'s * linting * ordering * Augmentation tweaks * yarn.lock * export
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
// Copyright 2017-2021 @polkadot/api-augment authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { QueryableConsts } from '@polkadot/api-augment/consts';
|
||||
import type { QueryableStorage } from '@polkadot/api-augment/query';
|
||||
import type { SubmittableExtrinsics } from '@polkadot/api-augment/tx';
|
||||
import type { DecoratedRpc, QueryableStorageMulti } from '@polkadot/api-base/types';
|
||||
import type { RpcInterface } from '@polkadot/rpc-core/types';
|
||||
import type { Metadata } from '@polkadot/types';
|
||||
import type { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
|
||||
import type { Registry, Signer } from '@polkadot/types/types';
|
||||
|
||||
declare module '@polkadot/api-base/types/api' {
|
||||
// A smaller interface of ApiRx, used in derive and in SubmittableExtrinsic
|
||||
export interface ApiInterfaceRx {
|
||||
consts: QueryableConsts<'rxjs'>;
|
||||
extrinsicType: number;
|
||||
genesisHash?: Hash;
|
||||
hasSubscriptions: boolean;
|
||||
registry: Registry;
|
||||
runtimeMetadata: Metadata;
|
||||
runtimeVersion: RuntimeVersion;
|
||||
query: QueryableStorage<'rxjs'>;
|
||||
queryAt: (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) => Observable<QueryableStorage<'rxjs'>>;
|
||||
queryMulti: QueryableStorageMulti<'rxjs'>;
|
||||
rpc: DecoratedRpc<'rxjs', RpcInterface>;
|
||||
tx: SubmittableExtrinsics<'rxjs'>;
|
||||
signer?: Signer;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
|
||||
/* eslint-disable */
|
||||
|
||||
declare module '@polkadot/api/types/consts' {
|
||||
declare module '@polkadot/api-augment/consts' {
|
||||
import type { ApiTypes, AugmentedConst, QueryableModuleConsts } from '@polkadot/api-base/types';
|
||||
import type { U8aFixed, Vec, bool, u128, u16, u32, u64, u8 } from '@polkadot/types';
|
||||
import type { Perbill, Percent, Permill } from '@polkadot/types/interfaces/runtime';
|
||||
@@ -1,7 +1,7 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
|
||||
/* eslint-disable */
|
||||
|
||||
declare module '@polkadot/api/types/errors' {
|
||||
declare module '@polkadot/api-augment/errors' {
|
||||
import type { ApiTypes, AugmentedError, ModuleErrors } from '@polkadot/api-base/types';
|
||||
|
||||
export interface AugmentedErrors<ApiType extends ApiTypes> {
|
||||
@@ -1,7 +1,7 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
|
||||
/* eslint-disable */
|
||||
|
||||
declare module '@polkadot/api/types/events' {
|
||||
declare module '@polkadot/api-augment/events' {
|
||||
import type { ApiTypes, AugmentedEvent, ModuleEvents } from '@polkadot/api-base/types';
|
||||
import type { Bytes, Null, Option, Result, U8aFixed, Vec, bool, u128, u16, u32, u64, u8 } from '@polkadot/types';
|
||||
import type { AccountId32, H256 } from '@polkadot/types/interfaces/runtime';
|
||||
@@ -0,0 +1,12 @@
|
||||
// Copyright 2017-2021 @polkadot/api-augment authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import '@polkadot/types/augment';
|
||||
import './consts';
|
||||
import './errors';
|
||||
import './events';
|
||||
import './query';
|
||||
import './tx';
|
||||
// these are external to this module
|
||||
import './api';
|
||||
import './rpc';
|
||||
@@ -1,7 +1,7 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
|
||||
/* eslint-disable */
|
||||
|
||||
declare module '@polkadot/api/types/storage' {
|
||||
declare module '@polkadot/api-augment/query' {
|
||||
import type { ApiTypes, AugmentedQuery, QueryableModuleStorage, QueryableModuleStorageAt, QueryableStorageEntry } from '@polkadot/api-base/types';
|
||||
import type { BTreeMap, Bytes, Data, Null, Option, U8aFixed, Vec, WrapperOpaque, bool, u128, u32, u64, u8 } from '@polkadot/types';
|
||||
import type { AccountId32, Call, H256, Perbill, Percent } from '@polkadot/types/interfaces/runtime';
|
||||
@@ -1,7 +1,7 @@
|
||||
// Auto-generated via `yarn polkadot-types-from-chain`, do not edit
|
||||
/* eslint-disable */
|
||||
|
||||
declare module '@polkadot/api/types/submittable' {
|
||||
declare module '@polkadot/api-augment/tx' {
|
||||
import type { ApiTypes, AugmentedSubmittable, SubmittableExtrinsic, SubmittableExtrinsicFunction, SubmittableModuleExtrinsics } from '@polkadot/api-base/types';
|
||||
import type { Bytes, Compact, Data, Option, U8aFixed, Vec, bool, u128, u16, u32, u64, u8 } from '@polkadot/types';
|
||||
import type { Extrinsic } from '@polkadot/types/interfaces/extrinsics';
|
||||
@@ -1,12 +1,14 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// Copyright 2017-2021 @polkadot/api-augment authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import '@polkadot/types/augment';
|
||||
import './consts';
|
||||
import './errors';
|
||||
import './events';
|
||||
import './query';
|
||||
import './rpc';
|
||||
import './tx';
|
||||
// trigger in the same way as we do externally
|
||||
import '@polkadot/api-augment/augment';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
|
||||
// Important: we do the exports here via the full package name
|
||||
export * from '@polkadot/api-augment/consts';
|
||||
export * from '@polkadot/api-augment/errors';
|
||||
export * from '@polkadot/api-augment/events';
|
||||
export * from '@polkadot/api-augment/query';
|
||||
export * from '@polkadot/api-augment/tx';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// Copyright 2017-2021 @polkadot/api-augment authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as rpcInfo } from '@polkadot/rpc-core/packageInfo';
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Copyright 2017-2021 @polkadot/api-contract authors & contributors
|
||||
// Copyright 2017-2021 @polkadot/api-augment authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import './detectPackage';
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
// Copyright 2017-2021 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export const __API_BASE_TYPES_API = 'empty';
|
||||
@@ -1,6 +1,9 @@
|
||||
// Copyright 2017-2021 @polkadot/api authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
// this is augmented, do an augmentation export
|
||||
export * from '@polkadot/api-base/types/api';
|
||||
|
||||
export * from './base';
|
||||
export * from './consts';
|
||||
export * from './errors';
|
||||
|
||||
@@ -24,6 +24,13 @@
|
||||
"main": "index.js",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "^7.16.5",
|
||||
"@polkadot/api-augment": "6.12.2-12",
|
||||
"@polkadot/api-base": "6.12.2-12",
|
||||
"@polkadot/rpc-core": "6.12.2-12",
|
||||
"@polkadot/types": "6.12.2-12",
|
||||
"@polkadot/types-codec": "6.12.2-12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@polkadot/api": "6.12.2-12"
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveApi } from '../types';
|
||||
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
@@ -17,7 +17,7 @@ import { memo } from '../util';
|
||||
* @param {(Address | AccountId | AccountIndex | string | null)} address - An accounts address in various formats.
|
||||
* @description An [[AccountId]]
|
||||
*/
|
||||
export function accountId (instanceId: string, api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | string | null) => Observable<AccountId> {
|
||||
export function accountId (instanceId: string, api: DeriveApi): (address?: Address | AccountId | AccountIndex | string | null) => Observable<AccountId> {
|
||||
return memo(instanceId, (address?: Address | AccountId | AccountIndex | string | null): Observable<AccountId> => {
|
||||
const decoded = isU8a(address)
|
||||
? address
|
||||
+5
-8
@@ -2,18 +2,15 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Vec } from '@polkadot/types';
|
||||
import type { AccountId, Address, Balance } from '@polkadot/types/interfaces';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveAccountFlags } from '../types';
|
||||
import type { DeriveAccountFlags, DeriveApi } from '../types';
|
||||
|
||||
import { combineLatest, map, of } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
type FlagsIntermediate = [
|
||||
Vec<ITuple<[AccountId, Balance]>> | undefined,
|
||||
[AccountId, Balance][] | undefined,
|
||||
AccountId[],
|
||||
AccountId[],
|
||||
AccountId[],
|
||||
@@ -27,7 +24,7 @@ function parseFlags (address: AccountId | Address | string | null | undefined, [
|
||||
: false;
|
||||
|
||||
return {
|
||||
isCouncil: (electionsMembers?.map(([id]: ITuple<[AccountId, Balance]>) => id) || councilMembers || []).some(isIncluded),
|
||||
isCouncil: (electionsMembers?.map(([id]) => id) || councilMembers || []).some(isIncluded),
|
||||
isSociety: (societyMembers || []).some(isIncluded),
|
||||
isSudo: sudoKey?.toString() === address?.toString(),
|
||||
isTechCommittee: (technicalCommitteeMembers || []).some(isIncluded)
|
||||
@@ -38,13 +35,13 @@ function parseFlags (address: AccountId | Address | string | null | undefined, [
|
||||
* @name info
|
||||
* @description Returns account membership flags
|
||||
*/
|
||||
export function flags (instanceId: string, api: ApiInterfaceRx): (address?: AccountId | Address | string | null) => Observable<DeriveAccountFlags> {
|
||||
export function flags (instanceId: string, api: DeriveApi): (address?: AccountId | Address | string | null) => Observable<DeriveAccountFlags> {
|
||||
return memo(instanceId, (address?: AccountId | Address | string | null): Observable<DeriveAccountFlags> => {
|
||||
const elections = api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections;
|
||||
|
||||
return combineLatest([
|
||||
address && elections?.members
|
||||
? elections.members<Vec<ITuple<[AccountId, Balance]>>>()
|
||||
? elections.members<[AccountId, Balance][]>()
|
||||
: of(undefined),
|
||||
address && api.query.council?.members
|
||||
? api.query.council.members()
|
||||
+2
-3
@@ -3,8 +3,7 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { AccountIdAndIndex } from '../types';
|
||||
import type { AccountIdAndIndex, DeriveApi } from '../types';
|
||||
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
@@ -26,7 +25,7 @@ import { memo } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function idAndIndex (instanceId: string, api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | Uint8Array | string | null) => Observable<AccountIdAndIndex> {
|
||||
export function idAndIndex (instanceId: string, api: DeriveApi): (address?: Address | AccountId | AccountIndex | Uint8Array | string | null) => Observable<AccountIdAndIndex> {
|
||||
return memo(instanceId, (address?: Address | AccountId | AccountIndex | Uint8Array | string | null): Observable<AccountIdAndIndex> => {
|
||||
try {
|
||||
// yes, this can fail, don't care too much, catch will catch it
|
||||
+2
-3
@@ -3,8 +3,7 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { AccountId, AccountIndex } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { AccountIndexes } from '../types';
|
||||
import type { AccountIndexes, DeriveApi } from '../types';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
@@ -24,7 +23,7 @@ import { memo } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function idToIndex (instanceId: string, api: ApiInterfaceRx): (accountId: AccountId | string) => Observable<AccountIndex | undefined> {
|
||||
export function idToIndex (instanceId: string, api: DeriveApi): (accountId: AccountId | string) => Observable<AccountIndex | undefined> {
|
||||
return memo(instanceId, (accountId: AccountId | string): Observable<AccountIndex | undefined> =>
|
||||
api.derive.accounts.indexes().pipe(
|
||||
map((indexes: AccountIndexes): AccountIndex | undefined =>
|
||||
+9
-9
@@ -2,12 +2,12 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Data, Option } from '@polkadot/types';
|
||||
import type { Data } from '@polkadot/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { PalletIdentityIdentityInfo, PalletIdentityRegistration } from '@polkadot/types/lookup';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveAccountRegistration, DeriveHasIdentity } from '../types';
|
||||
import type { Option } from '@polkadot/types-codec';
|
||||
import type { ITuple } from '@polkadot/types-codec/types';
|
||||
import type { DeriveAccountRegistration, DeriveApi, DeriveHasIdentity } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -64,7 +64,7 @@ function extractIdentity (identityOfOpt?: Option<PalletIdentityRegistration>, su
|
||||
};
|
||||
}
|
||||
|
||||
function getParent (api: ApiInterfaceRx, identityOfOpt: Option<PalletIdentityRegistration> | undefined, superOfOpt: Option<ITuple<[AccountId, Data]>> | undefined): Observable<[Option<PalletIdentityRegistration> | undefined, [AccountId, Data] | undefined]> {
|
||||
function getParent (api: DeriveApi, identityOfOpt: Option<PalletIdentityRegistration> | undefined, superOfOpt: Option<ITuple<[AccountId, Data]>> | undefined): Observable<[Option<PalletIdentityRegistration> | undefined, [AccountId, Data] | undefined]> {
|
||||
if (identityOfOpt?.isSome) {
|
||||
// this identity has something set
|
||||
return of([identityOfOpt, undefined]);
|
||||
@@ -82,7 +82,7 @@ function getParent (api: ApiInterfaceRx, identityOfOpt: Option<PalletIdentityReg
|
||||
return of([undefined, undefined]);
|
||||
}
|
||||
|
||||
function getBase (api: ApiInterfaceRx, accountId?: AccountId | Uint8Array | string): Observable<[Option<PalletIdentityRegistration> | undefined, Option<ITuple<[AccountId, Data]>> | undefined]> {
|
||||
function getBase (api: DeriveApi, accountId?: AccountId | Uint8Array | string): Observable<[Option<PalletIdentityRegistration> | undefined, Option<ITuple<[AccountId, Data]>> | undefined]> {
|
||||
return accountId && api.query.identity?.identityOf
|
||||
? api.queryMulti<[Option<PalletIdentityRegistration>, Option<ITuple<[AccountId, Data]>>]>([
|
||||
[api.query.identity.identityOf, accountId],
|
||||
@@ -95,7 +95,7 @@ function getBase (api: ApiInterfaceRx, accountId?: AccountId | Uint8Array | stri
|
||||
* @name identity
|
||||
* @description Returns identity info for an account
|
||||
*/
|
||||
export function identity (instanceId: string, api: ApiInterfaceRx): (accountId?: AccountId | Uint8Array | string) => Observable<DeriveAccountRegistration> {
|
||||
export function identity (instanceId: string, api: DeriveApi): (accountId?: AccountId | Uint8Array | string) => Observable<DeriveAccountRegistration> {
|
||||
return memo(instanceId, (accountId?: AccountId | Uint8Array | string): Observable<DeriveAccountRegistration> =>
|
||||
getBase(api, accountId).pipe(
|
||||
switchMap(([identityOfOpt, superOfOpt]) => getParent(api, identityOfOpt, superOfOpt)),
|
||||
@@ -105,11 +105,11 @@ export function identity (instanceId: string, api: ApiInterfaceRx): (accountId?:
|
||||
}
|
||||
|
||||
export const hasIdentity = firstMemo(
|
||||
(api: ApiInterfaceRx, accountId: AccountId | Uint8Array | string) =>
|
||||
(api: DeriveApi, accountId: AccountId | Uint8Array | string) =>
|
||||
api.derive.accounts.hasIdentityMulti([accountId])
|
||||
);
|
||||
|
||||
export function hasIdentityMulti (instanceId: string, api: ApiInterfaceRx): (accountIds: (AccountId | Uint8Array | string)[]) => Observable<DeriveHasIdentity[]> {
|
||||
export function hasIdentityMulti (instanceId: string, api: DeriveApi): (accountIds: (AccountId | Uint8Array | string)[]) => Observable<DeriveHasIdentity[]> {
|
||||
return memo(instanceId, (accountIds: (AccountId | Uint8Array | string)[]): Observable<DeriveHasIdentity[]> =>
|
||||
api.query.identity?.identityOf
|
||||
? combineLatest([
|
||||
+4
-6
@@ -2,10 +2,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { AccountId, AccountIndex, BalanceOf } from '@polkadot/types/interfaces';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { AccountId, AccountIndex } from '@polkadot/types/interfaces';
|
||||
import type { DeriveApi } from '../types';
|
||||
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
@@ -24,10 +22,10 @@ import { memo } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function indexToId (instanceId: string, api: ApiInterfaceRx): (accountIndex: AccountIndex | string) => Observable<AccountId | undefined> {
|
||||
export function indexToId (instanceId: string, api: DeriveApi): (accountIndex: AccountIndex | string) => Observable<AccountId | undefined> {
|
||||
return memo(instanceId, (accountIndex: AccountIndex | string): Observable<AccountId | undefined> =>
|
||||
api.query.indices
|
||||
? api.query.indices.accounts<Option<ITuple<[AccountId, BalanceOf]>>>(accountIndex).pipe(
|
||||
? api.query.indices.accounts(accountIndex).pipe(
|
||||
map((optResult): AccountId | undefined =>
|
||||
optResult.unwrapOr([])[0]
|
||||
)
|
||||
+3
-4
@@ -2,8 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { AccountIndexes } from '../types';
|
||||
import type { AccountIndexes, DeriveApi } from '../types';
|
||||
|
||||
import { map, of, startWith } from 'rxjs';
|
||||
|
||||
@@ -11,7 +10,7 @@ import { memo } from '../util';
|
||||
|
||||
let indicesCache: AccountIndexes | null = null;
|
||||
|
||||
function queryAccounts (api: ApiInterfaceRx): Observable<AccountIndexes> {
|
||||
function queryAccounts (api: DeriveApi): Observable<AccountIndexes> {
|
||||
return api.query.indices.accounts.entries().pipe(
|
||||
map((entries): AccountIndexes =>
|
||||
entries.reduce((indexes: AccountIndexes, [key, idOpt]): AccountIndexes => {
|
||||
@@ -40,7 +39,7 @@ function queryAccounts (api: ApiInterfaceRx): Observable<AccountIndexes> {
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function indexes (instanceId: string, api: ApiInterfaceRx): () => Observable<AccountIndexes> {
|
||||
export function indexes (instanceId: string, api: DeriveApi): () => Observable<AccountIndexes> {
|
||||
return memo(instanceId, (): Observable<AccountIndexes> =>
|
||||
indicesCache
|
||||
? of(indicesCache)
|
||||
@@ -5,8 +5,7 @@ import type { Observable } from 'rxjs';
|
||||
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 { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveAccountInfo, DeriveAccountRegistration } from '../types';
|
||||
import type { DeriveAccountInfo, DeriveAccountRegistration, DeriveApi } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -14,10 +13,10 @@ import { u8aToString } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function retrieveNick (api: ApiInterfaceRx, accountId?: AccountId): Observable<string | undefined> {
|
||||
function retrieveNick (api: DeriveApi, accountId?: AccountId): Observable<string | undefined> {
|
||||
return ((
|
||||
accountId && api.query.nicks?.nameOf
|
||||
? api.query.nicks.nameOf<Option<ITuple<[Bytes, Balance]>>>(accountId)
|
||||
? api.query.nicks.nameOf(accountId)
|
||||
: of(undefined)
|
||||
) as Observable<Option<ITuple<[Bytes, Balance]>> | undefined>).pipe(
|
||||
map((nameOf): string | undefined =>
|
||||
@@ -32,7 +31,7 @@ function retrieveNick (api: ApiInterfaceRx, accountId?: AccountId): Observable<s
|
||||
* @name info
|
||||
* @description Returns aux. info with regards to an account, current that includes the accountId, accountIndex and nickname
|
||||
*/
|
||||
export function info (instanceId: string, api: ApiInterfaceRx): (address?: AccountIndex | AccountId | Address | Uint8Array | string | null) => Observable<DeriveAccountInfo> {
|
||||
export function info (instanceId: string, api: DeriveApi): (address?: AccountIndex | AccountId | Address | Uint8Array | string | null) => Observable<DeriveAccountInfo> {
|
||||
return memo(instanceId, (address?: AccountIndex | AccountId | Address | Uint8Array | string | null): Observable<DeriveAccountInfo> =>
|
||||
api.derive.accounts.idAndIndex(address).pipe(
|
||||
switchMap(([accountId, accountIndex]): Observable<[Partial<DeriveAccountInfo>, DeriveAccountRegistration, string?]> =>
|
||||
+12
-12
@@ -2,10 +2,10 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { QueryableStorageEntry } from '@polkadot/api-base/types';
|
||||
import type { AccountData, AccountId, AccountIndex, AccountInfo, Address, Balance, Index } from '@polkadot/types/interfaces';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx, QueryableStorageEntry } from '../../types';
|
||||
import type { DeriveBalancesAccount, DeriveBalancesAccountData } from '../types';
|
||||
import type { DeriveApi, DeriveBalancesAccount, DeriveBalancesAccountData } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -17,17 +17,17 @@ type BalanceResult = [Balance, Balance, Balance, Balance];
|
||||
|
||||
type Result = [Index, BalanceResult[]];
|
||||
|
||||
type DeriveCustomAccount = ApiInterfaceRx['derive'] & {
|
||||
type DeriveCustomAccount = DeriveApi['derive'] & {
|
||||
[custom: string]: {
|
||||
customAccount?: ApiInterfaceRx['query']['balances']['account']
|
||||
customAccount?: DeriveApi['query']['balances']['account']
|
||||
}
|
||||
}
|
||||
|
||||
function zeroBalance (api: ApiInterfaceRx) {
|
||||
function zeroBalance (api: DeriveApi) {
|
||||
return api.registry.createType('Balance');
|
||||
}
|
||||
|
||||
function getBalance (api: ApiInterfaceRx, [freeBalance, reservedBalance, frozenFee, frozenMisc]: BalanceResult): DeriveBalancesAccountData {
|
||||
function getBalance (api: DeriveApi, [freeBalance, reservedBalance, frozenFee, frozenMisc]: BalanceResult): DeriveBalancesAccountData {
|
||||
const votingBalance = api.registry.createType('Balance', freeBalance.toBn());
|
||||
|
||||
return {
|
||||
@@ -39,7 +39,7 @@ function getBalance (api: ApiInterfaceRx, [freeBalance, reservedBalance, frozenF
|
||||
};
|
||||
}
|
||||
|
||||
function calcBalances (api: ApiInterfaceRx, [accountId, [accountNonce, [primary, ...additional]]]: [AccountId, Result]): DeriveBalancesAccount {
|
||||
function calcBalances (api: DeriveApi, [accountId, [accountNonce, [primary, ...additional]]]: [AccountId, Result]): DeriveBalancesAccount {
|
||||
return {
|
||||
accountId,
|
||||
accountNonce,
|
||||
@@ -49,7 +49,7 @@ function calcBalances (api: ApiInterfaceRx, [accountId, [accountNonce, [primary,
|
||||
}
|
||||
|
||||
// old
|
||||
function queryBalancesFree (api: ApiInterfaceRx, accountId: AccountId): Observable<Result> {
|
||||
function queryBalancesFree (api: DeriveApi, accountId: AccountId): Observable<Result> {
|
||||
return api.queryMulti<[Balance, Balance, Index]>([
|
||||
[api.query.balances.freeBalance, accountId],
|
||||
[api.query.balances.reservedBalance, accountId],
|
||||
@@ -62,7 +62,7 @@ function queryBalancesFree (api: ApiInterfaceRx, accountId: AccountId): Observab
|
||||
);
|
||||
}
|
||||
|
||||
function queryNonceOnly (api: ApiInterfaceRx, accountId: AccountId): Observable<Result> {
|
||||
function queryNonceOnly (api: DeriveApi, accountId: AccountId): Observable<Result> {
|
||||
const fill = (nonce: Index): Result => [
|
||||
nonce,
|
||||
[[zeroBalance(api), zeroBalance(api), zeroBalance(api), zeroBalance(api)]]
|
||||
@@ -79,7 +79,7 @@ function queryNonceOnly (api: ApiInterfaceRx, accountId: AccountId): Observable<
|
||||
: of(fill(api.registry.createType('Index')));
|
||||
}
|
||||
|
||||
function queryBalancesAccount (api: ApiInterfaceRx, accountId: AccountId, modules: string[] = ['balances']): Observable<Result> {
|
||||
function queryBalancesAccount (api: DeriveApi, accountId: AccountId, modules: string[] = ['balances']): Observable<Result> {
|
||||
const balances = modules
|
||||
.map((m): QueryableStorageEntry<'rxjs'> => (api.derive as DeriveCustomAccount)[m]?.customAccount || api.query[m]?.account)
|
||||
.filter((q) => isFunction(q))
|
||||
@@ -102,7 +102,7 @@ function queryBalancesAccount (api: ApiInterfaceRx, accountId: AccountId, module
|
||||
: queryNonceOnly(api, accountId);
|
||||
}
|
||||
|
||||
function querySystemAccount (api: ApiInterfaceRx, accountId: AccountId): Observable<Result> {
|
||||
function querySystemAccount (api: DeriveApi, accountId: AccountId): Observable<Result> {
|
||||
// AccountInfo is current, support old, eg. Edgeware
|
||||
return api.query.system.account<AccountInfo | ITuple<[Index, AccountData]>>(accountId).pipe(
|
||||
map((infoOrTuple): Result => {
|
||||
@@ -144,7 +144,7 @@ function querySystemAccount (api: ApiInterfaceRx, accountId: AccountId): Observa
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function account (instanceId: string, api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable<DeriveBalancesAccount> {
|
||||
export function account (instanceId: string, api: DeriveApi): (address: AccountIndex | AccountId | Address | string) => Observable<DeriveBalancesAccount> {
|
||||
const balanceInstances = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), 'balances');
|
||||
|
||||
return memo(instanceId, (address: AccountIndex | AccountId | Address | string): Observable<DeriveBalancesAccount> =>
|
||||
@@ -2,11 +2,11 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { QueryableStorageMultiArg } from '@polkadot/api-base/types';
|
||||
import type { Option, Vec } from '@polkadot/types';
|
||||
import type { AccountId, AccountIndex, Address, Balance, BalanceLockTo212, BlockNumber, VestingSchedule } from '@polkadot/types/interfaces';
|
||||
import type { PalletBalancesBalanceLock, PalletVestingVestingInfo } from '@polkadot/types/lookup';
|
||||
import type { ApiInterfaceRx, QueryableStorageMultiArg } from '../../types';
|
||||
import type { DeriveBalancesAccount, DeriveBalancesAccountData, DeriveBalancesAll, DeriveBalancesAllAccountData, DeriveBalancesAllVesting } from '../types';
|
||||
import type { DeriveApi, DeriveBalancesAccount, DeriveBalancesAccountData, DeriveBalancesAll, DeriveBalancesAllAccountData, DeriveBalancesAllVesting } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -26,15 +26,15 @@ interface AllLocked {
|
||||
vestingLocked: Balance
|
||||
}
|
||||
|
||||
type DeriveCustomLocks = ApiInterfaceRx['derive'] & {
|
||||
type DeriveCustomLocks = DeriveApi['derive'] & {
|
||||
[custom: string]: {
|
||||
customLocks?: ApiInterfaceRx['query']['balances']['locks']
|
||||
customLocks?: DeriveApi['query']['balances']['locks']
|
||||
}
|
||||
}
|
||||
|
||||
const VESTING_ID = '0x76657374696e6720';
|
||||
|
||||
function calcLocked (api: ApiInterfaceRx, bestNumber: BlockNumber, locks: (PalletBalancesBalanceLock | BalanceLockTo212)[]): AllLocked {
|
||||
function calcLocked (api: DeriveApi, bestNumber: BlockNumber, locks: (PalletBalancesBalanceLock | BalanceLockTo212)[]): AllLocked {
|
||||
let lockedBalance = api.registry.createType('Balance');
|
||||
let lockedBreakdown: (PalletBalancesBalanceLock | BalanceLockTo212)[] = [];
|
||||
let vestingLocked = api.registry.createType('Balance');
|
||||
@@ -57,7 +57,7 @@ function calcLocked (api: ApiInterfaceRx, bestNumber: BlockNumber, locks: (Palle
|
||||
return { allLocked, lockedBalance, lockedBreakdown, vestingLocked };
|
||||
}
|
||||
|
||||
function calcShared (api: ApiInterfaceRx, bestNumber: BlockNumber, data: DeriveBalancesAccountData, locks: (PalletBalancesBalanceLock | BalanceLockTo212)[]): DeriveBalancesAllAccountData {
|
||||
function calcShared (api: DeriveApi, bestNumber: BlockNumber, data: DeriveBalancesAccountData, locks: (PalletBalancesBalanceLock | BalanceLockTo212)[]): DeriveBalancesAllAccountData {
|
||||
const { allLocked, lockedBalance, lockedBreakdown, vestingLocked } = calcLocked(api, bestNumber, locks);
|
||||
|
||||
return {
|
||||
@@ -100,7 +100,7 @@ function calcVesting (bestNumber: BlockNumber, shared: DeriveBalancesAllAccountD
|
||||
};
|
||||
}
|
||||
|
||||
function calcBalances (api: ApiInterfaceRx, [data, bestNumber, [vesting, allLocks]]: Result): DeriveBalancesAll {
|
||||
function calcBalances (api: DeriveApi, [data, bestNumber, [vesting, allLocks]]: Result): DeriveBalancesAll {
|
||||
const shared = calcShared(api, bestNumber, data, allLocks[0]);
|
||||
|
||||
return {
|
||||
@@ -115,7 +115,7 @@ function calcBalances (api: ApiInterfaceRx, [data, bestNumber, [vesting, allLock
|
||||
}
|
||||
|
||||
// old
|
||||
function queryOld (api: ApiInterfaceRx, accountId: AccountId): Observable<ResultBalance> {
|
||||
function queryOld (api: DeriveApi, accountId: AccountId): Observable<ResultBalance> {
|
||||
return api.queryMulti<[Vec<PalletBalancesBalanceLock>, Option<VestingSchedule>]>([
|
||||
[api.query.balances.locks, accountId],
|
||||
[api.query.balances.vesting, accountId]
|
||||
@@ -142,8 +142,8 @@ function queryOld (api: ApiInterfaceRx, accountId: AccountId): Observable<Result
|
||||
const isNonNullable = <T>(nullable: T): nullable is NonNullable<T> => !!nullable;
|
||||
|
||||
// current (balances, vesting)
|
||||
function queryCurrent (api: ApiInterfaceRx, accountId: AccountId, balanceInstances: string[] = ['balances']): Observable<ResultBalance> {
|
||||
const calls = balanceInstances.map((m): ApiInterfaceRx['query']['balances']['locks'] | undefined =>
|
||||
function queryCurrent (api: DeriveApi, accountId: AccountId, balanceInstances: string[] = ['balances']): Observable<ResultBalance> {
|
||||
const calls = balanceInstances.map((m): DeriveApi['query']['balances']['locks'] | undefined =>
|
||||
(api.derive as DeriveCustomLocks)[m]?.customLocks || api.query[m as 'balances']?.locks
|
||||
);
|
||||
const lockEmpty = calls.map((c) => !c);
|
||||
@@ -188,7 +188,7 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId, balanceInstanc
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function all (instanceId: string, api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable<DeriveBalancesAll> {
|
||||
export function all (instanceId: string, api: DeriveApi): (address: AccountIndex | AccountId | Address | string) => Observable<DeriveBalancesAll> {
|
||||
const balanceInstances = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), 'balances');
|
||||
|
||||
return memo(instanceId, (address: AccountIndex | AccountId | Address | string): Observable<DeriveBalancesAll> =>
|
||||
@@ -3,8 +3,7 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Balance } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveFees } from '../types';
|
||||
import type { DeriveApi, DeriveFees } from '../types';
|
||||
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
@@ -23,7 +22,7 @@ import { memo } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function fees (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveFees> {
|
||||
export function fees (instanceId: string, api: DeriveApi): () => Observable<DeriveFees> {
|
||||
return memo(instanceId, (): Observable<DeriveFees> =>
|
||||
of([
|
||||
// deprecated - remove
|
||||
+2
-3
@@ -3,14 +3,13 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveBalancesAccount } from '../types';
|
||||
import type { DeriveApi, DeriveBalancesAccount } from '../types';
|
||||
|
||||
import { combineLatest, of } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function votingBalances (instanceId: string, api: ApiInterfaceRx): (addresses?: (AccountId | AccountIndex | Address | string)[]) => Observable<DeriveBalancesAccount[]> {
|
||||
export function votingBalances (instanceId: string, api: DeriveApi): (addresses?: (AccountId | AccountIndex | Address | string)[]) => Observable<DeriveBalancesAccount[]> {
|
||||
return memo(instanceId, (addresses?: (AccountId | AccountIndex | Address | string)[]): Observable<DeriveBalancesAccount[]> =>
|
||||
!addresses || !addresses.length
|
||||
? of([] as DeriveBalancesAccount[])
|
||||
+9
-8
@@ -1,15 +1,16 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { SubmittableExtrinsic } from '@polkadot/api-base/types';
|
||||
import type { Bytes, Option, StorageKey } from '@polkadot/types';
|
||||
import type { Bounty, BountyIndex, Proposal, ProposalIndex } from '@polkadot/types/interfaces';
|
||||
import type { Codec, InterfaceTypes } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx, SubmittableExtrinsic } from '../../types';
|
||||
import type { DeriveCollectiveProposal } from '../types';
|
||||
import type { DeriveApi, DeriveCollectiveProposal } from '../types';
|
||||
|
||||
import { firstValueFrom, of } from 'rxjs';
|
||||
|
||||
import { ApiPromise } from '../../promise';
|
||||
import { ApiPromise } from '@polkadot/api';
|
||||
|
||||
import { BountyFactory } from '../test/bountyFactory';
|
||||
import { BytesFactory } from '../test/bytesFactory';
|
||||
import { createApiWithAugmentations } from '../test/helpers';
|
||||
@@ -28,7 +29,7 @@ describe('bounties derive', () => {
|
||||
let bytes: (value: string) => Bytes;
|
||||
let api: ApiPromise;
|
||||
let createProposal: (method: SubmittableExtrinsic<'promise'>) => Proposal;
|
||||
let defaultMockApi: ApiInterfaceRx;
|
||||
let defaultMockApi: DeriveApi;
|
||||
|
||||
beforeAll(() => {
|
||||
api = createApiWithAugmentations();
|
||||
@@ -64,7 +65,7 @@ describe('bounties derive', () => {
|
||||
}
|
||||
},
|
||||
tx: api.tx
|
||||
} as unknown as ApiInterfaceRx;
|
||||
} as unknown as DeriveApi;
|
||||
});
|
||||
|
||||
it('creates storage key', function () {
|
||||
@@ -95,7 +96,7 @@ describe('bounties derive', () => {
|
||||
}
|
||||
}
|
||||
}
|
||||
} as unknown as ApiInterfaceRx;
|
||||
} as unknown as DeriveApi;
|
||||
|
||||
const result = await firstValueFrom(bounties('', mockApi)());
|
||||
|
||||
@@ -123,7 +124,7 @@ describe('bounties derive', () => {
|
||||
...defaultMockApi.query,
|
||||
council: null
|
||||
}
|
||||
} as unknown as ApiInterfaceRx;
|
||||
} as unknown as DeriveApi;
|
||||
|
||||
const result = await firstValueFrom(bounties('', mockApi)());
|
||||
|
||||
@@ -148,7 +149,7 @@ describe('bounties derive', () => {
|
||||
{ proposal: createProposal(api.tx.treasury.approveProposal(1)) }] as DeriveCollectiveProposal[])
|
||||
}
|
||||
}
|
||||
} as unknown as ApiInterfaceRx;
|
||||
} as unknown as DeriveApi;
|
||||
|
||||
const result = await firstValueFrom(bounties('', mockApi)());
|
||||
|
||||
+6
-7
@@ -3,10 +3,9 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Bytes, Option } from '@polkadot/types';
|
||||
import type { BountyIndex, ProposalIndex } from '@polkadot/types/interfaces';
|
||||
import type { BountyIndex } from '@polkadot/types/interfaces';
|
||||
import type { PalletBountiesBounty } from '@polkadot/types/lookup';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveBounties, DeriveCollectiveProposal } from '../types';
|
||||
import type { DeriveApi, DeriveBounties, DeriveCollectiveProposal } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -32,18 +31,18 @@ function parseResult ([maybeBounties, maybeDescriptions, ids, bountyProposals]:
|
||||
return bounties;
|
||||
}
|
||||
|
||||
export function bounties (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveBounties> {
|
||||
export function bounties (instanceId: string, api: DeriveApi): () => Observable<DeriveBounties> {
|
||||
const bountyBase = api.query.bounties || api.query.treasury;
|
||||
|
||||
return memo(instanceId, (): Observable<DeriveBounties> =>
|
||||
combineLatest([
|
||||
bountyBase.bountyCount<BountyIndex>(),
|
||||
bountyBase.bountyCount(),
|
||||
api.query.council
|
||||
? api.query.council.proposalCount<ProposalIndex>()
|
||||
? api.query.council.proposalCount()
|
||||
: of(0)
|
||||
]).pipe(
|
||||
switchMap(() => combineLatest([
|
||||
bountyBase.bounties.keys<[BountyIndex]>(),
|
||||
bountyBase.bounties.keys(),
|
||||
api.derive.council
|
||||
? api.derive.council.proposals()
|
||||
: of([])
|
||||
+2
-3
@@ -1,10 +1,9 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '../../../types';
|
||||
import type { DeriveCollectiveProposal } from '../../types';
|
||||
import type { DeriveApi, DeriveCollectiveProposal } from '../../types';
|
||||
|
||||
export function filterBountiesProposals (api: ApiInterfaceRx, allProposals: DeriveCollectiveProposal[]): DeriveCollectiveProposal[] {
|
||||
export function filterBountiesProposals (api: DeriveApi, allProposals: DeriveCollectiveProposal[]): DeriveCollectiveProposal[] {
|
||||
const bountyTxBase = api.tx.bounties ? api.tx.bounties : api.tx.treasury;
|
||||
const bountyProposalCalls = [bountyTxBase.approveBounty, bountyTxBase.closeBounty, bountyTxBase.proposeCurator, bountyTxBase.unassignCurator];
|
||||
|
||||
@@ -1,6 +1,130 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
export * from '@polkadot/api/derive';
|
||||
import type { AnyFunction } from '@polkadot/types/types';
|
||||
import type { DeriveCustom, ExactDerive } from './derive';
|
||||
import type { DeriveApi } from './types';
|
||||
|
||||
export { packageInfo } from './packageInfo';
|
||||
import { lazyDeriveSection } from './util/lazy';
|
||||
import { derive } from './derive';
|
||||
|
||||
export * from './derive';
|
||||
export * from './type';
|
||||
|
||||
interface Avail {
|
||||
instances: string[];
|
||||
methods: string[];
|
||||
withDetect?: boolean;
|
||||
}
|
||||
|
||||
export { lazyDeriveSection };
|
||||
|
||||
// Enable derive only if some of these modules are available
|
||||
const checks: Record<string, Avail> = {
|
||||
contracts: {
|
||||
instances: ['contracts'],
|
||||
methods: []
|
||||
},
|
||||
council: {
|
||||
instances: ['council'],
|
||||
methods: [],
|
||||
withDetect: true
|
||||
},
|
||||
crowdloan: {
|
||||
instances: ['crowdloan'],
|
||||
methods: []
|
||||
},
|
||||
democracy: {
|
||||
instances: ['democracy'],
|
||||
methods: []
|
||||
},
|
||||
elections: {
|
||||
instances: ['phragmenElection', 'electionsPhragmen', 'elections', 'council'],
|
||||
methods: [],
|
||||
withDetect: true
|
||||
},
|
||||
imOnline: {
|
||||
instances: ['imOnline'],
|
||||
methods: []
|
||||
},
|
||||
membership: {
|
||||
instances: ['membership'],
|
||||
methods: []
|
||||
},
|
||||
parachains: {
|
||||
instances: ['parachains', 'registrar'],
|
||||
methods: []
|
||||
},
|
||||
session: {
|
||||
instances: ['session'],
|
||||
methods: []
|
||||
},
|
||||
society: {
|
||||
instances: ['society'],
|
||||
methods: []
|
||||
},
|
||||
staking: {
|
||||
instances: ['staking'],
|
||||
methods: ['erasRewardPoints']
|
||||
},
|
||||
technicalCommittee: {
|
||||
instances: ['technicalCommittee'],
|
||||
methods: [],
|
||||
withDetect: true
|
||||
},
|
||||
treasury: {
|
||||
instances: ['treasury'],
|
||||
methods: []
|
||||
}
|
||||
};
|
||||
|
||||
function getModuleInstances (api: DeriveApi, specName: string, moduleName: string): string[] {
|
||||
return api.registry.getModuleInstances(specName, moduleName) || [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an object that will inject `api` into all the functions inside
|
||||
* `allSections`, and keep the object architecture of `allSections`.
|
||||
*/
|
||||
/** @internal */
|
||||
function injectFunctions (instanceId: string, api: DeriveApi, derives: DeriveCustom): ExactDerive {
|
||||
const result: Record<string, Record<string, AnyFunction>> = {};
|
||||
const names = Object.keys(derives);
|
||||
const keys = Object.keys(api.query);
|
||||
const specName = api.runtimeVersion.specName.toString();
|
||||
|
||||
const filterKeys = (q: string) => keys.includes(q);
|
||||
const filterInstances = (q: string) => getModuleInstances(api, specName, q).some(filterKeys);
|
||||
const filterMethods = (all: string[]) => (m: string) => all.some((q) => keys.includes(q) && api.query[q][m]);
|
||||
const getKeys = (s: string) => Object.keys(derives[s]);
|
||||
const creator = (s: string, m: string) => derives[s][m](instanceId, api);
|
||||
const isIncluded = (c: string) => (!checks[c] || (
|
||||
(checks[c].instances.some(filterKeys) && (
|
||||
!checks[c].methods.length ||
|
||||
checks[c].methods.every(filterMethods(checks[c].instances))
|
||||
)) ||
|
||||
(
|
||||
checks[c].withDetect &&
|
||||
checks[c].instances.some(filterInstances)
|
||||
)
|
||||
));
|
||||
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
const name = names[i];
|
||||
|
||||
isIncluded(name) &&
|
||||
lazyDeriveSection(result, name, getKeys, creator);
|
||||
}
|
||||
|
||||
return result as ExactDerive;
|
||||
}
|
||||
|
||||
// FIXME The return type of this function should be {...ExactDerive, ...DeriveCustom}
|
||||
// For now we just drop the custom derive typings
|
||||
/** @internal */
|
||||
export function getAvailableDerives (instanceId: string, api: DeriveApi, custom: DeriveCustom = {}): ExactDerive {
|
||||
return {
|
||||
...injectFunctions(instanceId, api, derive as DeriveCustom),
|
||||
...injectFunctions(instanceId, api, custom)
|
||||
};
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveApi } from '../types';
|
||||
|
||||
import { unwrapBlockNumber } from './util';
|
||||
|
||||
@@ -18,6 +18,6 @@ import { unwrapBlockNumber } from './util';
|
||||
* ```
|
||||
*/
|
||||
export const bestNumber = unwrapBlockNumber(
|
||||
(api: ApiInterfaceRx) =>
|
||||
(api: DeriveApi) =>
|
||||
api.derive.chain.subscribeNewHeads()
|
||||
);
|
||||
+2
-2
@@ -1,7 +1,7 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveApi } from '../types';
|
||||
|
||||
import { unwrapBlockNumber } from './util';
|
||||
|
||||
@@ -19,6 +19,6 @@ import { unwrapBlockNumber } from './util';
|
||||
* ```
|
||||
*/
|
||||
export const bestNumberFinalized = unwrapBlockNumber(
|
||||
(api: ApiInterfaceRx) =>
|
||||
(api: DeriveApi) =>
|
||||
api.rpc.chain.subscribeFinalizedHeads()
|
||||
);
|
||||
+2
-2
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { BlockNumber } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveApi } from '../types';
|
||||
|
||||
import { combineLatest, map } from 'rxjs';
|
||||
|
||||
@@ -22,7 +22,7 @@ import { memo } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function bestNumberLag (instanceId: string, api: ApiInterfaceRx): () => Observable<BlockNumber> {
|
||||
export function bestNumberLag (instanceId: string, api: DeriveApi): () => Observable<BlockNumber> {
|
||||
return memo(instanceId, (): Observable<BlockNumber> =>
|
||||
combineLatest([
|
||||
api.derive.chain.bestNumber(),
|
||||
+2
-2
@@ -2,8 +2,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { SignedBlockExtended } from '../type/types';
|
||||
import type { DeriveApi } from '../types';
|
||||
|
||||
import { catchError, combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -23,7 +23,7 @@ import { memo } from '../util';
|
||||
* console.log(`block #${block.header.number} was authored by ${author}`);
|
||||
* ```
|
||||
*/
|
||||
export function getBlock (instanceId: string, api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<SignedBlockExtended | undefined> {
|
||||
export function getBlock (instanceId: string, api: DeriveApi): (hash: Uint8Array | string) => Observable<SignedBlockExtended | undefined> {
|
||||
return memo(instanceId, (blockHash: Uint8Array | string): Observable<SignedBlockExtended | undefined> =>
|
||||
combineLatest([
|
||||
api.rpc.chain.getBlock(blockHash),
|
||||
+2
-2
@@ -4,8 +4,8 @@
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { HeaderExtended } from '../type/types';
|
||||
import type { DeriveApi } from '../types';
|
||||
|
||||
import { catchError, combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -26,7 +26,7 @@ import { memo } from '../util';
|
||||
* console.log(`block #${number} was authored by ${author}`);
|
||||
* ```
|
||||
*/
|
||||
export function getHeader (instanceId: string, api: ApiInterfaceRx): (blockHash: Uint8Array | string) => Observable<HeaderExtended | undefined> {
|
||||
export function getHeader (instanceId: string, api: DeriveApi): (blockHash: Uint8Array | string) => Observable<HeaderExtended | undefined> {
|
||||
return memo(instanceId, (blockHash: Uint8Array | string): Observable<HeaderExtended | undefined> =>
|
||||
combineLatest([
|
||||
api.rpc.chain.getHeader(blockHash),
|
||||
+2
-2
@@ -3,8 +3,8 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { SignedBlockExtended } from '../type/types';
|
||||
import type { DeriveApi } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -15,7 +15,7 @@ import { memo } from '../util';
|
||||
* @name subscribeNewBlocks
|
||||
* @returns The latest block & events for that block
|
||||
*/
|
||||
export function subscribeNewBlocks (instanceId: string, api: ApiInterfaceRx): () => Observable<SignedBlockExtended> {
|
||||
export function subscribeNewBlocks (instanceId: string, api: DeriveApi): () => Observable<SignedBlockExtended> {
|
||||
return memo(instanceId, (): Observable<SignedBlockExtended> =>
|
||||
api.derive.chain.subscribeNewHeads().pipe(
|
||||
switchMap((header) => {
|
||||
+2
-2
@@ -3,8 +3,8 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Registry } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { HeaderExtended } from '../type/types';
|
||||
import type { DeriveApi } from '../types';
|
||||
|
||||
import { combineLatest, map, of } from 'rxjs';
|
||||
|
||||
@@ -24,7 +24,7 @@ import { memo } from '../util';
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function subscribeNewHeads (instanceId: string, api: ApiInterfaceRx): () => Observable<HeaderExtended> {
|
||||
export function subscribeNewHeads (instanceId: string, api: DeriveApi): () => Observable<HeaderExtended> {
|
||||
return memo(instanceId, (): Observable<HeaderExtended> =>
|
||||
combineLatest([
|
||||
api.rpc.chain.subscribeNewHeads(),
|
||||
@@ -4,7 +4,7 @@
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Compact } from '@polkadot/types';
|
||||
import type { BlockNumber } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveApi } from '../types';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
@@ -14,8 +14,8 @@ import { memo } from '../util';
|
||||
// we would emit code with ../<somewhere>/src embedded in the *.d.ts files
|
||||
export type { BlockNumber } from '@polkadot/types/interfaces';
|
||||
|
||||
export function unwrapBlockNumber <T extends { number: Compact<BlockNumber> }> (fn: (api: ApiInterfaceRx) => Observable<T>): (instanceId: string, api: ApiInterfaceRx) => () => Observable<BlockNumber> {
|
||||
return (instanceId: string, api: ApiInterfaceRx) =>
|
||||
export function unwrapBlockNumber <T extends { number: Compact<BlockNumber> }> (fn: (api: DeriveApi) => Observable<T>): (instanceId: string, api: DeriveApi) => () => Observable<BlockNumber> {
|
||||
return (instanceId: string, api: DeriveApi) =>
|
||||
memo(instanceId, () => fn(api).pipe(
|
||||
map((r) => r.number.unwrap())
|
||||
));
|
||||
+5
-5
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveApi } from '../types';
|
||||
import type { Collective } from './types';
|
||||
|
||||
import { of } from 'rxjs';
|
||||
@@ -11,7 +11,7 @@ import { isFunction } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function getInstance (api: ApiInterfaceRx, section: string): string {
|
||||
export function getInstance (api: DeriveApi, section: string): string {
|
||||
const instances = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), section);
|
||||
|
||||
return instances && instances.length
|
||||
@@ -19,12 +19,12 @@ export function getInstance (api: ApiInterfaceRx, section: string): string {
|
||||
: section;
|
||||
}
|
||||
|
||||
export function withSection <T, F extends (...args: any[]) => Observable<T>> (_section: Collective, fn: (section: string, api: ApiInterfaceRx, instanceId: string) => F): (instanceId: string, api: ApiInterfaceRx) => F {
|
||||
return (instanceId: string, api: ApiInterfaceRx) =>
|
||||
export function withSection <T, F extends (...args: any[]) => Observable<T>> (_section: Collective, fn: (section: string, api: DeriveApi, instanceId: string) => F): (instanceId: string, api: DeriveApi) => F {
|
||||
return (instanceId: string, api: DeriveApi) =>
|
||||
memo(instanceId, fn(getInstance(api, _section), api, instanceId)) as unknown as F;
|
||||
}
|
||||
|
||||
export function callMethod <T> (method: 'members' | 'proposals' | 'proposalCount', empty: T): (_section: Collective) => (instanceId: string, api: ApiInterfaceRx) => () => Observable<T> {
|
||||
export function callMethod <T> (method: 'members' | 'proposals' | 'proposalCount', empty: T): (_section: Collective) => (instanceId: string, api: DeriveApi) => () => Observable<T> {
|
||||
return (_section: Collective) =>
|
||||
withSection(_section, (section, api) =>
|
||||
(): Observable<T> =>
|
||||
+3
-4
@@ -2,9 +2,8 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveApi } from '../types';
|
||||
import type { Collective } from './types';
|
||||
|
||||
import { map, of } from 'rxjs';
|
||||
@@ -16,11 +15,11 @@ import { withSection } from './helpers';
|
||||
// We are re-exporting these from here to ensure that *.d.ts generation is correct
|
||||
export type { AccountId } from '@polkadot/types/interfaces';
|
||||
|
||||
export function prime (_section: Collective): (instanceId: string, api: ApiInterfaceRx) => () => Observable<AccountId | null> {
|
||||
export function prime (_section: Collective): (instanceId: string, api: DeriveApi) => () => Observable<AccountId | null> {
|
||||
return withSection(_section, (section, api) =>
|
||||
(): Observable<AccountId | null> =>
|
||||
isFunction(api.query[section as 'council']?.prime)
|
||||
? api.query[section as 'council'].prime<Option<AccountId>>().pipe(
|
||||
? api.query[section as 'council'].prime().pipe(
|
||||
map((optPrime): AccountId | null =>
|
||||
optPrime.unwrapOr(null)
|
||||
)
|
||||
+6
-7
@@ -4,8 +4,7 @@
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Option, u32 } from '@polkadot/types';
|
||||
import type { Hash, Proposal, Votes } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveCollectiveProposal } from '../types';
|
||||
import type { DeriveApi, DeriveCollectiveProposal } from '../types';
|
||||
import type { Collective } from './types';
|
||||
|
||||
import { catchError, combineLatest, map, of, switchMap } from 'rxjs';
|
||||
@@ -21,7 +20,7 @@ export type { Hash, Proposal, Votes } from '@polkadot/types/interfaces';
|
||||
|
||||
type Result = [(Hash | Uint8Array | string)[], (Option<Proposal> | null)[], Option<Votes>[]];
|
||||
|
||||
function parse (api: ApiInterfaceRx, [hashes, proposals, votes]: Result): DeriveCollectiveProposal[] {
|
||||
function parse (api: DeriveApi, [hashes, proposals, votes]: Result): DeriveCollectiveProposal[] {
|
||||
return proposals
|
||||
.map((o, index): DeriveCollectiveProposal | null =>
|
||||
o && o.isSome
|
||||
@@ -35,7 +34,7 @@ function parse (api: ApiInterfaceRx, [hashes, proposals, votes]: Result): Derive
|
||||
.filter((proposal): proposal is DeriveCollectiveProposal => !!proposal);
|
||||
}
|
||||
|
||||
function _proposalsFrom (section: string, api: ApiInterfaceRx, hashes: (Hash | Uint8Array | string)[]): Observable<DeriveCollectiveProposal[]> {
|
||||
function _proposalsFrom (section: string, api: DeriveApi, hashes: (Hash | Uint8Array | string)[]): Observable<DeriveCollectiveProposal[]> {
|
||||
return (isFunction(api.query[section]?.proposals) && hashes.length
|
||||
? combineLatest([
|
||||
of(hashes),
|
||||
@@ -55,14 +54,14 @@ function _proposalsFrom (section: string, api: ApiInterfaceRx, hashes: (Hash | U
|
||||
);
|
||||
}
|
||||
|
||||
export function hasProposals (_section: Collective): (instanceId: string, api: ApiInterfaceRx) => () => Observable<boolean> {
|
||||
export function hasProposals (_section: Collective): (instanceId: string, api: DeriveApi) => () => Observable<boolean> {
|
||||
return withSection(_section, (section, api) =>
|
||||
(): Observable<boolean> =>
|
||||
of(isFunction(api.query[section]?.proposals))
|
||||
);
|
||||
}
|
||||
|
||||
export function proposals (_section: Collective): (instanceId: string, api: ApiInterfaceRx) => () => Observable<DeriveCollectiveProposal[]> {
|
||||
export function proposals (_section: Collective): (instanceId: string, api: DeriveApi) => () => Observable<DeriveCollectiveProposal[]> {
|
||||
return withSection(_section, (section, api) =>
|
||||
(): Observable<DeriveCollectiveProposal[]> =>
|
||||
api.derive[section as 'council'].proposalHashes().pipe(
|
||||
@@ -71,7 +70,7 @@ export function proposals (_section: Collective): (instanceId: string, api: ApiI
|
||||
);
|
||||
}
|
||||
|
||||
export function proposal (_section: Collective): (instanceId: string, api: ApiInterfaceRx) => (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
|
||||
export function proposal (_section: Collective): (instanceId: string, api: DeriveApi) => (hash: Hash | Uint8Array | string) => Observable<DeriveCollectiveProposal | null> {
|
||||
return withSection(_section, (section, api) =>
|
||||
(hash: Hash | Uint8Array | string): Observable<DeriveCollectiveProposal | null> =>
|
||||
isFunction(api.query[section]?.proposals)
|
||||
+3
-4
@@ -3,8 +3,7 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveContractFees } from '../types';
|
||||
import type { DeriveApi, DeriveContractFees } from '../types';
|
||||
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
@@ -13,7 +12,7 @@ import { memo } from '../util';
|
||||
type ResultV2 = [BN, BN, BN, BN, BN, BN, BN, BN, BN, BN];
|
||||
|
||||
// query via constants (current applicable path)
|
||||
function queryConstants (api: ApiInterfaceRx): Observable<ResultV2> {
|
||||
function queryConstants (api: DeriveApi): Observable<ResultV2> {
|
||||
return of([
|
||||
// deprecated
|
||||
api.consts.contracts.callBaseFee || api.registry.createType('Balance'),
|
||||
@@ -44,7 +43,7 @@ function queryConstants (api: ApiInterfaceRx): Observable<ResultV2> {
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function fees (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveContractFees> {
|
||||
export function fees (instanceId: string, api: DeriveApi): () => Observable<DeriveContractFees> {
|
||||
return memo(instanceId, (): Observable<DeriveContractFees> => {
|
||||
return queryConstants(api).pipe(
|
||||
map(([callBaseFee, contractFee, creationFee, transactionBaseFee, transactionByteFee, transferFee, rentByteFee, rentDepositOffset, surchargeReward, tombstoneDeposit]): DeriveContractFees => ({
|
||||
@@ -2,12 +2,12 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { QueryableModuleStorage } from '@polkadot/api-base/types';
|
||||
import type { Vec } from '@polkadot/types';
|
||||
import type { AccountId, Balance } from '@polkadot/types/interfaces';
|
||||
import type { PalletElectionsPhragmenVoter } from '@polkadot/types/lookup';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx, QueryableModuleStorage } from '../../types';
|
||||
import type { DeriveCouncilVote, DeriveCouncilVotes } from '../types';
|
||||
import type { DeriveApi, DeriveCouncilVote, DeriveCouncilVotes } from '../types';
|
||||
|
||||
import { combineLatest, map, of } from 'rxjs';
|
||||
|
||||
@@ -36,7 +36,7 @@ function retrieveVoteOf (elections: QueryableModuleStorage<'rxjs'>): Observable<
|
||||
);
|
||||
}
|
||||
|
||||
function retrievePrev (api: ApiInterfaceRx, elections: QueryableModuleStorage<'rxjs'>): Observable<DeriveCouncilVotes> {
|
||||
function retrievePrev (api: DeriveApi, elections: QueryableModuleStorage<'rxjs'>): Observable<DeriveCouncilVotes> {
|
||||
return combineLatest([
|
||||
retrieveStakeOf(elections),
|
||||
retrieveVoteOf(elections)
|
||||
@@ -76,7 +76,7 @@ function retrieveCurrent (elections: QueryableModuleStorage<'rxjs'>): Observable
|
||||
);
|
||||
}
|
||||
|
||||
export function votes (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveCouncilVotes> {
|
||||
export function votes (instanceId: string, api: DeriveApi): () => Observable<DeriveCouncilVotes> {
|
||||
const elections = api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections;
|
||||
|
||||
return memo(instanceId, (): Observable<DeriveCouncilVotes> =>
|
||||
+2
-3
@@ -3,14 +3,13 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveCouncilVote } from '../types';
|
||||
import type { DeriveApi, DeriveCouncilVote } from '../types';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function votesOf (instanceId: string, api: ApiInterfaceRx): (accountId: string | Uint8Array | AccountId) => Observable<DeriveCouncilVote> {
|
||||
export function votesOf (instanceId: string, api: DeriveApi): (accountId: string | Uint8Array | AccountId) => Observable<DeriveCouncilVote> {
|
||||
return memo(instanceId, (accountId: string | Uint8Array | AccountId): Observable<DeriveCouncilVote> =>
|
||||
api.derive.council.votes().pipe(
|
||||
map((votes): DeriveCouncilVote =>
|
||||
+2
-2
@@ -5,7 +5,7 @@ import type { Observable } from 'rxjs';
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { PolkadotRuntimeCommonCrowdloanFundInfo } from '@polkadot/types/lookup';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveApi } from '../types';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
@@ -25,7 +25,7 @@ function createChildKey ({ trieIndex }: PolkadotRuntimeCommonCrowdloanFundInfo):
|
||||
);
|
||||
}
|
||||
|
||||
export function childKey (instanceId: string, api: ApiInterfaceRx): (paraId: string | number | BN) => Observable<string | null> {
|
||||
export function childKey (instanceId: string, api: DeriveApi): (paraId: string | number | BN) => Observable<string | null> {
|
||||
return memo(instanceId, (paraId: string | number | BN): Observable<string | null> =>
|
||||
api.query.crowdloan.funds<Option<PolkadotRuntimeCommonCrowdloanFundInfo>>(paraId).pipe(
|
||||
map((optInfo) =>
|
||||
+7
-8
@@ -4,8 +4,7 @@
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { StorageKey } from '@polkadot/types';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveContributions } from '../types';
|
||||
import type { DeriveApi, DeriveContributions } from '../types';
|
||||
|
||||
import { BehaviorSubject, combineLatest, EMPTY, map, of, startWith, switchMap, tap, toArray } from 'rxjs';
|
||||
|
||||
@@ -22,7 +21,7 @@ interface Changes {
|
||||
|
||||
const PAGE_SIZE_K = 1000; // limit aligned with the 1k on the node (trie lookups are heavy)
|
||||
|
||||
function _getUpdates (api: ApiInterfaceRx, paraId: string | number | BN): Observable<Changes> {
|
||||
function _getUpdates (api: DeriveApi, paraId: string | number | BN): Observable<Changes> {
|
||||
let added: string[] = [];
|
||||
let removed: string[] = [];
|
||||
|
||||
@@ -43,7 +42,7 @@ function _getUpdates (api: ApiInterfaceRx, paraId: string | number | BN): Observ
|
||||
);
|
||||
}
|
||||
|
||||
function _eventTriggerAll (api: ApiInterfaceRx, paraId: string | number | BN): Observable<string> {
|
||||
function _eventTriggerAll (api: DeriveApi, paraId: string | number | BN): Observable<string> {
|
||||
return api.query.system.events().pipe(
|
||||
switchMap((events): Observable<string> => {
|
||||
const items = events.filter(({ event: { data: [eventParaId], method, section } }) =>
|
||||
@@ -60,7 +59,7 @@ function _eventTriggerAll (api: ApiInterfaceRx, paraId: string | number | BN): O
|
||||
);
|
||||
}
|
||||
|
||||
function _getKeysPaged (api: ApiInterfaceRx, childKey: string): Observable<StorageKey[]> {
|
||||
function _getKeysPaged (api: DeriveApi, childKey: string): Observable<StorageKey[]> {
|
||||
const startSubject = new BehaviorSubject<string | undefined>(undefined);
|
||||
|
||||
return startSubject.pipe(
|
||||
@@ -79,7 +78,7 @@ function _getKeysPaged (api: ApiInterfaceRx, childKey: string): Observable<Stora
|
||||
);
|
||||
}
|
||||
|
||||
function _getAll (api: ApiInterfaceRx, paraId: string | number | BN, childKey: string): Observable<string[]> {
|
||||
function _getAll (api: DeriveApi, paraId: string | number | BN, childKey: string): Observable<string[]> {
|
||||
return _eventTriggerAll(api, paraId).pipe(
|
||||
switchMap(() =>
|
||||
isFunction(api.rpc.childstate.getKeysPaged)
|
||||
@@ -92,7 +91,7 @@ function _getAll (api: ApiInterfaceRx, paraId: string | number | BN, childKey: s
|
||||
);
|
||||
}
|
||||
|
||||
function _contributions (api: ApiInterfaceRx, paraId: string | number | BN, childKey: string): Observable<DeriveContributions> {
|
||||
function _contributions (api: DeriveApi, paraId: string | number | BN, childKey: string): Observable<DeriveContributions> {
|
||||
return combineLatest([
|
||||
_getAll(api, paraId, childKey),
|
||||
_getUpdates(api, paraId)
|
||||
@@ -120,7 +119,7 @@ function _contributions (api: ApiInterfaceRx, paraId: string | number | BN, chil
|
||||
);
|
||||
}
|
||||
|
||||
export function contributions (instanceId: string, api: ApiInterfaceRx): (paraId: string | number | BN) => Observable<DeriveContributions> {
|
||||
export function contributions (instanceId: string, api: DeriveApi): (paraId: string | number | BN) => Observable<DeriveContributions> {
|
||||
return memo(instanceId, (paraId: string | number | BN): Observable<DeriveContributions> =>
|
||||
api.derive.crowdloan.childKey(paraId).pipe(
|
||||
switchMap((childKey) =>
|
||||
+1
-1
@@ -3,4 +3,4 @@
|
||||
|
||||
export * from './childKey';
|
||||
export * from './contributions';
|
||||
export * from './onwContributions';
|
||||
export * from './ownContributions';
|
||||
+5
-6
@@ -3,15 +3,14 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveOwnContributions } from '../types';
|
||||
import type { DeriveApi, 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> {
|
||||
function _getValues (api: DeriveApi, 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) =>
|
||||
@@ -30,7 +29,7 @@ function _getValues (api: ApiInterfaceRx, childKey: string, keys: string[]): Obs
|
||||
);
|
||||
}
|
||||
|
||||
function _watchOwnChanges (api: ApiInterfaceRx, paraId: string | number | BN, childkey: string, keys: string[]): Observable<DeriveOwnContributions> {
|
||||
function _watchOwnChanges (api: DeriveApi, paraId: string | number | BN, childkey: string, keys: string[]): Observable<DeriveOwnContributions> {
|
||||
return api.query.system.events().pipe(
|
||||
switchMap((events): Observable<DeriveOwnContributions> => {
|
||||
const changes = extractContributed(paraId, events);
|
||||
@@ -47,7 +46,7 @@ function _watchOwnChanges (api: ApiInterfaceRx, paraId: string | number | BN, ch
|
||||
);
|
||||
}
|
||||
|
||||
function _contributions (api: ApiInterfaceRx, paraId: string | number | BN, childKey: string, keys: string[]): Observable<DeriveOwnContributions> {
|
||||
function _contributions (api: DeriveApi, paraId: string | number | BN, childKey: string, keys: string[]): Observable<DeriveOwnContributions> {
|
||||
return combineLatest([
|
||||
_getValues(api, childKey, keys),
|
||||
_watchOwnChanges(api, paraId, childKey, keys)
|
||||
@@ -59,7 +58,7 @@ function _contributions (api: ApiInterfaceRx, paraId: string | number | BN, chil
|
||||
);
|
||||
}
|
||||
|
||||
export function ownContributions (instanceId: string, api: ApiInterfaceRx): (paraId: string | number | BN, keys: string[]) => Observable<DeriveOwnContributions> {
|
||||
export function ownContributions (instanceId: string, api: DeriveApi): (paraId: string | number | BN, keys: string[]) => Observable<DeriveOwnContributions> {
|
||||
return memo(instanceId, (paraId: string | number | BN, keys: string[]): Observable<DeriveOwnContributions> =>
|
||||
api.derive.crowdloan.childKey(paraId).pipe(
|
||||
switchMap((childKey) =>
|
||||
+3
-3
@@ -1,8 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Vec } from '@polkadot/types';
|
||||
import type { EventRecord } from '@polkadot/types/interfaces';
|
||||
import type { FrameSystemEventRecord } from '@polkadot/types/lookup';
|
||||
import type { Vec } from '@polkadot/types-codec';
|
||||
import type { BN } from '@polkadot/util';
|
||||
|
||||
interface Changes {
|
||||
@@ -11,7 +11,7 @@ interface Changes {
|
||||
removed: string[];
|
||||
}
|
||||
|
||||
export function extractContributed (paraId: string | number | BN, events: Vec<EventRecord>): Changes {
|
||||
export function extractContributed (paraId: string | number | BN, events: Vec<FrameSystemEventRecord>): Changes {
|
||||
const added: string[] = [];
|
||||
const removed: string[] = [];
|
||||
|
||||
+5
-6
@@ -6,8 +6,7 @@ import type { Option, Vec } from '@polkadot/types';
|
||||
import type { BlockNumber, Hash, ReferendumIndex } from '@polkadot/types/interfaces';
|
||||
import type { PalletSchedulerScheduledV2 } from '@polkadot/types/lookup';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveDispatch, DeriveProposalImage } from '../types';
|
||||
import type { DeriveApi, DeriveDispatch, DeriveProposalImage } from '../types';
|
||||
|
||||
import { catchError, combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -23,7 +22,7 @@ interface SchedulerInfo {
|
||||
index: ReferendumIndex;
|
||||
}
|
||||
|
||||
function queryQueue (api: ApiInterfaceRx): Observable<DeriveDispatch[]> {
|
||||
function queryQueue (api: DeriveApi): Observable<DeriveDispatch[]> {
|
||||
return api.query.democracy.dispatchQueue<Vec<ITuple<[BlockNumber, Hash, ReferendumIndex]>>>().pipe(
|
||||
switchMap((dispatches) =>
|
||||
combineLatest([
|
||||
@@ -43,7 +42,7 @@ function queryQueue (api: ApiInterfaceRx): Observable<DeriveDispatch[]> {
|
||||
);
|
||||
}
|
||||
|
||||
function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], (Option<PalletSchedulerScheduledV2>[] | null)[]]> {
|
||||
function schedulerEntries (api: DeriveApi): Observable<[BlockNumber[], (Option<PalletSchedulerScheduledV2>[] | 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
|
||||
@@ -70,7 +69,7 @@ function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], (Opt
|
||||
);
|
||||
}
|
||||
|
||||
function queryScheduler (api: ApiInterfaceRx): Observable<DeriveDispatch[]> {
|
||||
function queryScheduler (api: DeriveApi): Observable<DeriveDispatch[]> {
|
||||
return schedulerEntries(api).pipe(
|
||||
switchMap(([blockNumbers, agendas]): Observable<[SchedulerInfo[], (DeriveProposalImage | undefined)[]]> => {
|
||||
const result: SchedulerInfo[] = [];
|
||||
@@ -100,7 +99,7 @@ function queryScheduler (api: ApiInterfaceRx): Observable<DeriveDispatch[]> {
|
||||
);
|
||||
}
|
||||
|
||||
export function dispatchQueue (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveDispatch[]> {
|
||||
export function dispatchQueue (instanceId: string, api: DeriveApi): () => Observable<DeriveDispatch[]> {
|
||||
return memo(instanceId, (): Observable<DeriveDispatch[]> =>
|
||||
isFunction(api.query.scheduler?.agenda)
|
||||
? queryScheduler(api)
|
||||
+10
-9
@@ -5,8 +5,7 @@ import type { Observable } from 'rxjs';
|
||||
import type { AccountId, ReferendumInfoTo239, Vote } from '@polkadot/types/interfaces';
|
||||
import type { PalletDemocracyReferendumInfo, PalletDemocracyVoteVoting } from '@polkadot/types/lookup';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveDemocracyLock } from '../types';
|
||||
import type { DeriveApi, DeriveDemocracyLock } from '../types';
|
||||
|
||||
import { map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -21,7 +20,7 @@ type VotingDirectVote = VotingDirect['votes'][0];
|
||||
|
||||
const LOCKUPS = [0, 1, 2, 4, 8, 16, 32];
|
||||
|
||||
function parseEnd (api: ApiInterfaceRx, vote: Vote, { approved, end }: ReferendumInfoFinished): [BN, BN] {
|
||||
function parseEnd (api: DeriveApi, vote: Vote, { approved, end }: ReferendumInfoFinished): [BN, BN] {
|
||||
return [
|
||||
end,
|
||||
(approved.isTrue && vote.isAye) || (approved.isFalse && vote.isNay)
|
||||
@@ -29,12 +28,13 @@ function parseEnd (api: ApiInterfaceRx, vote: Vote, { approved, end }: Referendu
|
||||
(
|
||||
api.consts.democracy.voteLockingPeriod ||
|
||||
api.consts.democracy.enactmentPeriod
|
||||
).muln(LOCKUPS[vote.conviction.index]))
|
||||
).muln(LOCKUPS[vote.conviction.index])
|
||||
)
|
||||
: BN_ZERO
|
||||
];
|
||||
}
|
||||
|
||||
function parseLock (api: ApiInterfaceRx, [referendumId, accountVote]: VotingDirectVote, referendum: PalletDemocracyReferendumInfo): DeriveDemocracyLock {
|
||||
function parseLock (api: DeriveApi, [referendumId, accountVote]: VotingDirectVote, referendum: PalletDemocracyReferendumInfo): DeriveDemocracyLock {
|
||||
const { balance, vote } = accountVote.asStandard;
|
||||
const [referendumEnd, unlockAt] = referendum.isFinished
|
||||
? parseEnd(api, vote, referendum.asFinished)
|
||||
@@ -43,7 +43,7 @@ function parseLock (api: ApiInterfaceRx, [referendumId, accountVote]: VotingDire
|
||||
return { balance, isDelegated: false, isFinished: referendum.isFinished, referendumEnd, referendumId, unlockAt, vote };
|
||||
}
|
||||
|
||||
function delegateLocks (api: ApiInterfaceRx, { balance, conviction, target }: VotingDelegating): Observable<DeriveDemocracyLock[]> {
|
||||
function delegateLocks (api: DeriveApi, { balance, conviction, target }: VotingDelegating): Observable<DeriveDemocracyLock[]> {
|
||||
return api.derive.democracy.locks(target).pipe(
|
||||
map((available): DeriveDemocracyLock[] =>
|
||||
available.map(({ isFinished, referendumEnd, referendumId, unlockAt, vote }): DeriveDemocracyLock => ({
|
||||
@@ -58,14 +58,15 @@ function delegateLocks (api: ApiInterfaceRx, { balance, conviction, target }: Vo
|
||||
(
|
||||
api.consts.democracy.voteLockingPeriod ||
|
||||
api.consts.democracy.enactmentPeriod
|
||||
).muln(LOCKUPS[conviction.index])),
|
||||
).muln(LOCKUPS[conviction.index])
|
||||
),
|
||||
vote: api.registry.createType('Vote', { aye: vote.isAye, conviction })
|
||||
}))
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
function directLocks (api: ApiInterfaceRx, { votes }: VotingDirect): Observable<DeriveDemocracyLock[]> {
|
||||
function directLocks (api: DeriveApi, { votes }: VotingDirect): Observable<DeriveDemocracyLock[]> {
|
||||
if (!votes.length) {
|
||||
return of([]);
|
||||
}
|
||||
@@ -86,7 +87,7 @@ function directLocks (api: ApiInterfaceRx, { votes }: VotingDirect): Observable<
|
||||
);
|
||||
}
|
||||
|
||||
export function locks (instanceId: string, api: ApiInterfaceRx): (accountId: string | AccountId) => Observable<DeriveDemocracyLock[]> {
|
||||
export function locks (instanceId: string, api: DeriveApi): (accountId: string | AccountId) => Observable<DeriveDemocracyLock[]> {
|
||||
return memo(instanceId, (accountId: string | AccountId): Observable<DeriveDemocracyLock[]> =>
|
||||
api.query.democracy.votingOf
|
||||
? api.query.democracy.votingOf(accountId).pipe(
|
||||
+3
-4
@@ -6,14 +6,13 @@ import type { Option } from '@polkadot/types';
|
||||
import type { H256 } from '@polkadot/types/interfaces';
|
||||
import type { PalletDemocracyVoteThreshold } from '@polkadot/types/lookup';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveProposalExternal } from '../types';
|
||||
import type { DeriveApi, DeriveProposalExternal } from '../types';
|
||||
|
||||
import { map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function withImage (api: ApiInterfaceRx, nextOpt: Option<ITuple<[H256, PalletDemocracyVoteThreshold]>>): Observable<DeriveProposalExternal | null> {
|
||||
function withImage (api: DeriveApi, nextOpt: Option<ITuple<[H256, PalletDemocracyVoteThreshold]>>): Observable<DeriveProposalExternal | null> {
|
||||
if (nextOpt.isNone) {
|
||||
return of(null);
|
||||
}
|
||||
@@ -29,7 +28,7 @@ function withImage (api: ApiInterfaceRx, nextOpt: Option<ITuple<[H256, PalletDem
|
||||
);
|
||||
}
|
||||
|
||||
export function nextExternal (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveProposalExternal | null> {
|
||||
export function nextExternal (instanceId: string, api: DeriveApi): () => Observable<DeriveProposalExternal | null> {
|
||||
return memo(instanceId, (): Observable<DeriveProposalExternal | null> =>
|
||||
api.query.democracy?.nextExternal
|
||||
? api.query.democracy.nextExternal().pipe(
|
||||
+2
-3
@@ -3,15 +3,14 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Hash } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveProposalImage } from '../types';
|
||||
import type { DeriveApi, DeriveProposalImage } from '../types';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { parseImage } from './util';
|
||||
|
||||
export function preimage (instanceId: string, api: ApiInterfaceRx): (hash: Hash) => Observable<DeriveProposalImage | undefined> {
|
||||
export function preimage (instanceId: string, api: DeriveApi): (hash: Hash) => Observable<DeriveProposalImage | undefined> {
|
||||
return memo(instanceId, (hash: Hash): Observable<DeriveProposalImage | undefined> =>
|
||||
api.query.democracy.preimages(hash).pipe(
|
||||
map((imageOpt) => parseImage(api, imageOpt))
|
||||
+2
-3
@@ -3,15 +3,14 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Hash } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveProposalImage } from '../types';
|
||||
import type { DeriveApi, DeriveProposalImage } from '../types';
|
||||
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
import { parseImage } from './util';
|
||||
|
||||
export function preimages (instanceId: string, api: ApiInterfaceRx): (hashes: Hash[]) => Observable<(DeriveProposalImage | undefined)[]> {
|
||||
export function preimages (instanceId: string, api: DeriveApi): (hashes: Hash[]) => Observable<(DeriveProposalImage | undefined)[]> {
|
||||
return memo(instanceId, (hashes: Hash[]): Observable<(DeriveProposalImage | undefined)[]> =>
|
||||
hashes.length
|
||||
? api.query.democracy.preimages.multi(hashes).pipe(
|
||||
+3
-4
@@ -5,8 +5,7 @@ import type { Observable } from 'rxjs';
|
||||
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 { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveProposal, DeriveProposalImage } from '../types';
|
||||
import type { DeriveApi, DeriveProposal, DeriveProposalImage } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -48,10 +47,10 @@ function parse ([proposals, images, optDepositors]: Result): DeriveProposal[] {
|
||||
});
|
||||
}
|
||||
|
||||
export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveProposal[]> {
|
||||
export function proposals (instanceId: string, api: DeriveApi): () => Observable<DeriveProposal[]> {
|
||||
return memo(instanceId, (): Observable<DeriveProposal[]> =>
|
||||
isFunction(api.query.democracy?.publicProps) && isFunction(api.query.democracy?.preimages)
|
||||
? api.query.democracy.publicProps<Proposals>().pipe(
|
||||
? api.query.democracy.publicProps().pipe(
|
||||
switchMap((proposals) =>
|
||||
proposals.length
|
||||
? combineLatest([
|
||||
+2
-2
@@ -4,13 +4,13 @@
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ReferendumIndex } from '@polkadot/types/interfaces';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveApi } from '../types';
|
||||
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function referendumIds (instanceId: string, api: ApiInterfaceRx): () => Observable<BN[]> {
|
||||
export function referendumIds (instanceId: string, api: DeriveApi): () => Observable<BN[]> {
|
||||
return memo(instanceId, (): Observable<BN[]> =>
|
||||
api.query.democracy?.lowestUnbaked
|
||||
? api.queryMulti<[ReferendumIndex, ReferendumIndex]>([
|
||||
+2
-3
@@ -2,14 +2,13 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveReferendumExt } from '../types';
|
||||
import type { DeriveApi, DeriveReferendumExt } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function referendums (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveReferendumExt[]> {
|
||||
export function referendums (instanceId: string, api: DeriveApi): () => Observable<DeriveReferendumExt[]> {
|
||||
return memo(instanceId, (): Observable<DeriveReferendumExt[]> =>
|
||||
api.derive.democracy.referendumsActive().pipe(
|
||||
switchMap((referendums) =>
|
||||
+2
-3
@@ -2,14 +2,13 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveReferendum } from '../types';
|
||||
import type { DeriveApi, DeriveReferendum } from '../types';
|
||||
|
||||
import { of, switchMap } from 'rxjs';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function referendumsActive (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveReferendum[]> {
|
||||
export function referendumsActive (instanceId: string, api: DeriveApi): () => Observable<DeriveReferendum[]> {
|
||||
return memo(instanceId, (): Observable<DeriveReferendum[]> =>
|
||||
api.derive.democracy.referendumIds().pipe(
|
||||
switchMap((ids): Observable<DeriveReferendum[]> =>
|
||||
+3
-3
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { PalletDemocracyReferendumInfo } from '@polkadot/types/lookup';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveApi } from '../types';
|
||||
|
||||
import { map, switchMap } from 'rxjs';
|
||||
|
||||
@@ -11,7 +11,7 @@ import { memo } from '../util';
|
||||
|
||||
type ReferendumInfoFinished = PalletDemocracyReferendumInfo['asFinished'];
|
||||
|
||||
export function referendumsFinished (instanceId: string, api: ApiInterfaceRx): () => Observable<ReferendumInfoFinished[]> {
|
||||
export function referendumsFinished (instanceId: string, api: DeriveApi): () => Observable<ReferendumInfoFinished[]> {
|
||||
return memo(instanceId, (): Observable<ReferendumInfoFinished[]> =>
|
||||
api.derive.democracy.referendumIds().pipe(
|
||||
switchMap((ids) =>
|
||||
@@ -19,7 +19,7 @@ export function referendumsFinished (instanceId: string, api: ApiInterfaceRx): (
|
||||
),
|
||||
map((infos): ReferendumInfoFinished[] =>
|
||||
infos
|
||||
.map((optInfo) => optInfo.unwrapOr(null))
|
||||
.map((o) => o.unwrapOr(null))
|
||||
.filter((info): info is PalletDemocracyReferendumInfo => !!info && info.isFinished)
|
||||
.map((info) => info.asFinished)
|
||||
)
|
||||
+7
-8
@@ -6,8 +6,7 @@ import type { Option, Vec } from '@polkadot/types';
|
||||
import type { AccountId, ReferendumInfoTo239, Vote } from '@polkadot/types/interfaces';
|
||||
import type { PalletDemocracyReferendumInfo, PalletDemocracyVoteVoting } from '@polkadot/types/lookup';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveBalancesAccount, DeriveReferendum, DeriveReferendumVote, DeriveReferendumVotes } from '../types';
|
||||
import type { DeriveApi, DeriveBalancesAccount, DeriveReferendum, DeriveReferendumVote, DeriveReferendumVotes } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -20,7 +19,7 @@ type VotingDelegating = PalletDemocracyVoteVoting['asDelegating'];
|
||||
type VotingDirect = PalletDemocracyVoteVoting['asDirect'];
|
||||
type VotingDirectVote = VotingDirect['votes'][0];
|
||||
|
||||
function votesPrev (api: ApiInterfaceRx, referendumId: BN): Observable<DeriveReferendumVote[]> {
|
||||
function votesPrev (api: DeriveApi, referendumId: BN): Observable<DeriveReferendumVote[]> {
|
||||
return api.query.democracy.votersFor<Vec<AccountId>>(referendumId).pipe(
|
||||
switchMap((votersFor): Observable<[Vec<AccountId>, Vote[], DeriveBalancesAccount[]]> =>
|
||||
combineLatest([
|
||||
@@ -70,7 +69,7 @@ function extractVotes (mapped: [AccountId, PalletDemocracyVoteVoting][], referen
|
||||
);
|
||||
}
|
||||
|
||||
function votesCurr (api: ApiInterfaceRx, referendumId: BN): Observable<DeriveReferendumVote[]> {
|
||||
function votesCurr (api: DeriveApi, referendumId: BN): Observable<DeriveReferendumVote[]> {
|
||||
return api.query.democracy.votingOf.entries().pipe(
|
||||
map((allVoting): DeriveReferendumVote[] => {
|
||||
const mapped = allVoting.map(([{ args: [accountId] }, voting]): [AccountId, PalletDemocracyVoteVoting] => [accountId, voting]);
|
||||
@@ -101,7 +100,7 @@ function votesCurr (api: ApiInterfaceRx, referendumId: BN): Observable<DeriveRef
|
||||
);
|
||||
}
|
||||
|
||||
export function _referendumVotes (instanceId: string, api: ApiInterfaceRx): (referendum: DeriveReferendum) => Observable<DeriveReferendumVotes> {
|
||||
export function _referendumVotes (instanceId: string, api: DeriveApi): (referendum: DeriveReferendum) => Observable<DeriveReferendumVotes> {
|
||||
return memo(instanceId, (referendum: DeriveReferendum): Observable<DeriveReferendumVotes> =>
|
||||
combineLatest([
|
||||
api.derive.democracy.sqrtElectorate(),
|
||||
@@ -116,7 +115,7 @@ export function _referendumVotes (instanceId: string, api: ApiInterfaceRx): (ref
|
||||
);
|
||||
}
|
||||
|
||||
export function _referendumsVotes (instanceId: string, api: ApiInterfaceRx): (referendums: DeriveReferendum[]) => Observable<DeriveReferendumVotes[]> {
|
||||
export function _referendumsVotes (instanceId: string, api: DeriveApi): (referendums: DeriveReferendum[]) => Observable<DeriveReferendumVotes[]> {
|
||||
return memo(instanceId, (referendums: DeriveReferendum[]): Observable<DeriveReferendumVotes[]> =>
|
||||
referendums.length
|
||||
? combineLatest(
|
||||
@@ -128,7 +127,7 @@ export function _referendumsVotes (instanceId: string, api: ApiInterfaceRx): (re
|
||||
);
|
||||
}
|
||||
|
||||
export function _referendumInfo (instanceId: string, api: ApiInterfaceRx): (index: BN, info: Option<PalletDemocracyReferendumInfo | ReferendumInfoTo239>) => Observable<DeriveReferendum | null> {
|
||||
export function _referendumInfo (instanceId: string, api: DeriveApi): (index: BN, info: Option<PalletDemocracyReferendumInfo | ReferendumInfoTo239>) => Observable<DeriveReferendum | null> {
|
||||
return memo(instanceId, (index: BN, info: Option<PalletDemocracyReferendumInfo | ReferendumInfoTo239>): Observable<DeriveReferendum | null> => {
|
||||
const status = getStatus(info);
|
||||
|
||||
@@ -145,7 +144,7 @@ export function _referendumInfo (instanceId: string, api: ApiInterfaceRx): (inde
|
||||
});
|
||||
}
|
||||
|
||||
export function referendumsInfo (instanceId: string, api: ApiInterfaceRx): (ids: BN[]) => Observable<DeriveReferendum[]> {
|
||||
export function referendumsInfo (instanceId: string, api: DeriveApi): (ids: BN[]) => Observable<DeriveReferendum[]> {
|
||||
return memo(instanceId, (ids: BN[]): Observable<DeriveReferendum[]> =>
|
||||
ids.length
|
||||
? api.query.democracy.referendumInfoOf.multi(ids).pipe(
|
||||
+3
-5
@@ -3,7 +3,7 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { BN } from '@polkadot/util';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveApi } from '../types';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
@@ -11,12 +11,10 @@ import { bnSqrt } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function sqrtElectorate (instanceId: string, api: ApiInterfaceRx): () => Observable<BN> {
|
||||
export function sqrtElectorate (instanceId: string, api: DeriveApi): () => Observable<BN> {
|
||||
return memo(instanceId, (): Observable<BN> =>
|
||||
api.query.balances.totalIssuance().pipe(
|
||||
map((totalIssuance) =>
|
||||
bnSqrt(totalIssuance)
|
||||
)
|
||||
map(bnSqrt)
|
||||
)
|
||||
);
|
||||
}
|
||||
+4
-5
@@ -5,8 +5,7 @@ import type { Bytes, Option } from '@polkadot/types';
|
||||
import type { AccountId, Balance, BlockNumber, PreimageStatus, Proposal, ReferendumInfoTo239, Tally } from '@polkadot/types/interfaces';
|
||||
import type { PalletDemocracyReferendumInfo, PalletDemocracyReferendumStatus, PalletDemocracyVoteThreshold } from '@polkadot/types/lookup';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveProposalImage, DeriveReferendum, DeriveReferendumVote, DeriveReferendumVotes, DeriveReferendumVoteState } from '../types';
|
||||
import type { DeriveApi, DeriveProposalImage, DeriveReferendum, DeriveReferendumVote, DeriveReferendumVotes, DeriveReferendumVoteState } from '../types';
|
||||
|
||||
import { BN, bnSqrt } from '@polkadot/util';
|
||||
|
||||
@@ -27,7 +26,7 @@ function isCurrentStatus (status: PalletDemocracyReferendumStatus | ReferendumIn
|
||||
return !!(status as PalletDemocracyReferendumStatus).tally;
|
||||
}
|
||||
|
||||
function isCurrentPreimage (api: ApiInterfaceRx, imageOpt: Option<OldPreimage> | Option<PreimageStatus>): imageOpt is Option<PreimageStatus> {
|
||||
function isCurrentPreimage (api: DeriveApi, imageOpt: Option<OldPreimage> | Option<PreimageStatus>): imageOpt is Option<PreimageStatus> {
|
||||
return !!imageOpt && !api.query.democracy.dispatchQueue;
|
||||
}
|
||||
|
||||
@@ -152,7 +151,7 @@ export function getStatus (info: Option<PalletDemocracyReferendumInfo | Referend
|
||||
return null;
|
||||
}
|
||||
|
||||
function constructProposal (api: ApiInterfaceRx, [bytes, proposer, balance, at]: PreimageInfo): DeriveProposalImage {
|
||||
function constructProposal (api: DeriveApi, [bytes, proposer, balance, at]: PreimageInfo): DeriveProposalImage {
|
||||
let proposal: Proposal | undefined;
|
||||
|
||||
try {
|
||||
@@ -164,7 +163,7 @@ function constructProposal (api: ApiInterfaceRx, [bytes, proposer, balance, at]:
|
||||
return { at, balance, proposal, proposer };
|
||||
}
|
||||
|
||||
export function parseImage (api: ApiInterfaceRx, imageOpt: Option<OldPreimage> | Option<PreimageStatus>): DeriveProposalImage | undefined {
|
||||
export function parseImage (api: DeriveApi, imageOpt: Option<OldPreimage> | Option<PreimageStatus>): DeriveProposalImage | undefined {
|
||||
if (imageOpt.isNone) {
|
||||
return;
|
||||
}
|
||||
@@ -3,7 +3,6 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { AnyFunction } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx } from '../types';
|
||||
|
||||
import * as accounts from './accounts';
|
||||
import * as balances from './balances';
|
||||
@@ -35,7 +34,7 @@ type DeriveAllSections<AllSections> = {
|
||||
[S in keyof AllSections]: DeriveSection<AllSections[S]>
|
||||
};
|
||||
|
||||
type DeriveCreator = (instanceId: string, api: ApiInterfaceRx) => (...args: unknown[]) => Observable<any>;
|
||||
type DeriveCreator = (instanceId: string, api: unknown) => (...args: unknown[]) => Observable<any>;
|
||||
|
||||
export type DeriveCustom = Record<string, Record<string, DeriveCreator>>;
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import { packageInfo as apiInfo } from '@polkadot/api/packageInfo';
|
||||
import { detectPackage } from '@polkadot/util';
|
||||
|
||||
import { packageInfo } from './packageInfo';
|
||||
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [apiInfo]);
|
||||
detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, []);
|
||||
|
||||
+4
-4
@@ -6,7 +6,7 @@ import type { u32, Vec } from '@polkadot/types';
|
||||
import type { AccountId, Balance, BlockNumber } from '@polkadot/types/interfaces';
|
||||
import type { PalletElectionsPhragmenSeatHolder } from '@polkadot/types/lookup';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveApi } from '../types';
|
||||
import type { DeriveElectionsInfo } from './types';
|
||||
|
||||
import { combineLatest, map, of } from 'rxjs';
|
||||
@@ -42,7 +42,7 @@ function sortAccounts ([, balanceA]: [AccountId, Balance], [, balanceB]: [Accoun
|
||||
return balanceB.cmp(balanceA);
|
||||
}
|
||||
|
||||
function getConstants (api: ApiInterfaceRx, elections: string | null): Partial<DeriveElectionsInfo> {
|
||||
function getConstants (api: DeriveApi, elections: string | null): Partial<DeriveElectionsInfo> {
|
||||
return elections
|
||||
? {
|
||||
candidacyBond: api.consts[elections].candidacyBond as Balance,
|
||||
@@ -54,7 +54,7 @@ function getConstants (api: ApiInterfaceRx, elections: string | null): Partial<D
|
||||
: {};
|
||||
}
|
||||
|
||||
function getModules (api: ApiInterfaceRx): [string, string | null] {
|
||||
function getModules (api: DeriveApi): [string, string | null] {
|
||||
const [council] = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), 'council') || ['council'];
|
||||
const elections = api.query.phragmenElection
|
||||
? 'phragmenElection'
|
||||
@@ -80,7 +80,7 @@ function getModules (api: ApiInterfaceRx): [string, string | null] {
|
||||
* });
|
||||
* ```
|
||||
*/
|
||||
export function info (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveElectionsInfo> {
|
||||
export function info (instanceId: string, api: DeriveApi): () => Observable<DeriveElectionsInfo> {
|
||||
return memo(instanceId, (): Observable<DeriveElectionsInfo> => {
|
||||
const [council, elections] = getModules(api);
|
||||
|
||||
+2
-3
@@ -5,8 +5,7 @@ import type { Observable } from 'rxjs';
|
||||
import type { Option, u32, WrapperOpaque } from '@polkadot/types';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { PalletImOnlineBoundedOpaqueNetworkState } from '@polkadot/types/lookup';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveHeartbeats } from '../types';
|
||||
import type { DeriveApi, DeriveHeartbeats } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -38,7 +37,7 @@ function mapResult ([result, validators, heartbeats, numBlocks]: [DeriveHeartbea
|
||||
/**
|
||||
* @description Return a boolean array indicating whether the passed accounts had received heartbeats in the current session
|
||||
*/
|
||||
export function receivedHeartbeats (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveHeartbeats> {
|
||||
export function receivedHeartbeats (instanceId: string, api: DeriveApi): () => Observable<DeriveHeartbeats> {
|
||||
return memo(instanceId, (): Observable<DeriveHeartbeats> =>
|
||||
api.query.imOnline?.receivedHeartbeats
|
||||
? api.derive.staking.overview().pipe(
|
||||
@@ -7,10 +7,10 @@
|
||||
|
||||
import { from, Observable } from 'rxjs';
|
||||
|
||||
import { ApiRx } from '@polkadot/api';
|
||||
import { MockProvider } from '@polkadot/rpc-provider/mock';
|
||||
import { TypeRegistry } from '@polkadot/types/create';
|
||||
|
||||
import { ApiRx } from '../rx';
|
||||
import { ExactDerive } from '.';
|
||||
|
||||
const testFunction = (api: ApiRx): any => {
|
||||
+2
-3
@@ -3,8 +3,7 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { CollatorId, ParaId } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveParachainActive, DeriveParachainFull, DeriveParachainInfo } from '../types';
|
||||
import type { DeriveApi, DeriveParachainActive, DeriveParachainFull, DeriveParachainInfo } from '../types';
|
||||
import type { Active, DidUpdate, Heads, ParaInfoResult, PendingSwap, RelayDispatchQueue, RetryQueue, SelectedThreads } from './types';
|
||||
|
||||
import { map, of } from 'rxjs';
|
||||
@@ -74,7 +73,7 @@ function parse (id: ParaId, [active, retryQueue, selectedThreads, didUpdate, inf
|
||||
};
|
||||
}
|
||||
|
||||
export function info (instanceId: string, api: ApiInterfaceRx): (id: ParaId | number) => Observable<DeriveParachainFull | null> {
|
||||
export function info (instanceId: string, api: DeriveApi): (id: ParaId | number) => Observable<DeriveParachainFull | null> {
|
||||
return memo(instanceId, (id: ParaId | number): Observable<DeriveParachainFull | null> =>
|
||||
api.query.registrar && api.query.parachains
|
||||
? api.queryMulti<Result>([
|
||||
+2
-3
@@ -3,8 +3,7 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ParaId } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveParachain, DeriveParachainInfo } from '../types';
|
||||
import type { DeriveApi, DeriveParachain, DeriveParachainInfo } from '../types';
|
||||
import type { DidUpdate, ParaInfoResult, PendingSwap, RelayDispatchQueueSize } from './types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
@@ -30,7 +29,7 @@ function parse ([ids, didUpdate, infos, pendingSwaps, relayDispatchQueueSizes]:
|
||||
}));
|
||||
}
|
||||
|
||||
export function overview (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveParachain[]> {
|
||||
export function overview (instanceId: string, api: DeriveApi): () => Observable<DeriveParachain[]> {
|
||||
return memo(instanceId, (): Observable<DeriveParachain[]> =>
|
||||
api.query.registrar?.parachains && api.query.parachains
|
||||
? api.query.registrar.parachains<ParaId[]>().pipe(
|
||||
+5
-6
@@ -4,8 +4,7 @@
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Option, u32 } from '@polkadot/types';
|
||||
import type { ActiveEraInfo, EraIndex, Moment, SessionIndex } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveSessionIndexes } from '../types';
|
||||
import type { DeriveApi, DeriveSessionIndexes } from '../types';
|
||||
|
||||
import { map, of } from 'rxjs';
|
||||
|
||||
@@ -23,7 +22,7 @@ function parse ([currentIndex, activeEra, activeEraStart, currentEra, validatorC
|
||||
}
|
||||
|
||||
// query based on latest
|
||||
function queryStaking (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
|
||||
function queryStaking (api: DeriveApi): Observable<DeriveSessionIndexes> {
|
||||
return api.queryMulti<[SessionIndex, Option<ActiveEraInfo>, Option<EraIndex>, u32]>([
|
||||
api.query.session.currentIndex,
|
||||
api.query.staking.activeEra,
|
||||
@@ -45,7 +44,7 @@ function queryStaking (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
|
||||
}
|
||||
|
||||
// query based on latest
|
||||
function querySession (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
|
||||
function querySession (api: DeriveApi): Observable<DeriveSessionIndexes> {
|
||||
return api.query.session.currentIndex().pipe(
|
||||
map((currentIndex): DeriveSessionIndexes => parse([
|
||||
currentIndex,
|
||||
@@ -58,7 +57,7 @@ function querySession (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
|
||||
}
|
||||
|
||||
// empty set when none is available
|
||||
function empty (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
|
||||
function empty (api: DeriveApi): Observable<DeriveSessionIndexes> {
|
||||
return of(parse([
|
||||
api.registry.createType('SessionIndex', 1),
|
||||
api.registry.createType('EraIndex'),
|
||||
@@ -68,7 +67,7 @@ function empty (api: ApiInterfaceRx): Observable<DeriveSessionIndexes> {
|
||||
]));
|
||||
}
|
||||
|
||||
export function indexes (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSessionIndexes> {
|
||||
export function indexes (instanceId: string, api: DeriveApi): () => Observable<DeriveSessionIndexes> {
|
||||
return memo(instanceId, (): Observable<DeriveSessionIndexes> =>
|
||||
api.query.session
|
||||
? api.query.staking
|
||||
@@ -2,8 +2,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveSessionInfo } from '../types';
|
||||
import type { DeriveApi, DeriveSessionInfo } from '../types';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
@@ -12,7 +11,7 @@ import { memo } from '../util';
|
||||
/**
|
||||
* @description Retrieves all the session and era query and calculates specific values on it as the length of the session and eras
|
||||
*/
|
||||
export function info (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSessionInfo> {
|
||||
export function info (instanceId: string, api: DeriveApi): () => Observable<DeriveSessionInfo> {
|
||||
return memo(instanceId, (): Observable<DeriveSessionInfo> =>
|
||||
api.derive.session.indexes().pipe(
|
||||
map((indexes) => {
|
||||
+7
-8
@@ -4,8 +4,7 @@
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Option, u64 } from '@polkadot/types';
|
||||
import type { BlockNumber, SessionIndex } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveSessionInfo, DeriveSessionProgress } from '../types';
|
||||
import type { DeriveApi, DeriveSessionInfo, DeriveSessionProgress } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -15,8 +14,8 @@ type ResultSlotsNoSession = [u64, u64, u64];
|
||||
type ResultSlots = [u64, u64, u64, Option<SessionIndex>];
|
||||
type ResultSlotsFlat = [u64, u64, u64, SessionIndex];
|
||||
|
||||
function withProgressField (field: 'eraLength' | 'eraProgress' | 'sessionProgress'): (instanceId: string, api: ApiInterfaceRx) => () => Observable<BlockNumber> {
|
||||
return (instanceId: string, api: ApiInterfaceRx) =>
|
||||
function withProgressField (field: 'eraLength' | 'eraProgress' | 'sessionProgress'): (instanceId: string, api: DeriveApi) => () => Observable<BlockNumber> {
|
||||
return (instanceId: string, api: DeriveApi) =>
|
||||
memo(instanceId, (): Observable<BlockNumber> =>
|
||||
api.derive.session.progress().pipe(
|
||||
map((info) => info[field])
|
||||
@@ -24,7 +23,7 @@ function withProgressField (field: 'eraLength' | 'eraProgress' | 'sessionProgres
|
||||
);
|
||||
}
|
||||
|
||||
function createDerive (api: ApiInterfaceRx, info: DeriveSessionInfo, [currentSlot, epochIndex, epochOrGenesisStartSlot, activeEraStartSessionIndex]: ResultSlotsFlat): DeriveSessionProgress {
|
||||
function createDerive (api: DeriveApi, info: DeriveSessionInfo, [currentSlot, epochIndex, epochOrGenesisStartSlot, activeEraStartSessionIndex]: ResultSlotsFlat): DeriveSessionProgress {
|
||||
const epochStartSlot = epochIndex.mul(info.sessionLength).iadd(epochOrGenesisStartSlot);
|
||||
const sessionProgress = currentSlot.sub(epochStartSlot);
|
||||
const eraProgress = info.currentIndex.sub(activeEraStartSessionIndex).imul(info.sessionLength).iadd(sessionProgress);
|
||||
@@ -36,7 +35,7 @@ function createDerive (api: ApiInterfaceRx, info: DeriveSessionInfo, [currentSlo
|
||||
};
|
||||
}
|
||||
|
||||
function queryAura (api: ApiInterfaceRx): Observable<DeriveSessionProgress> {
|
||||
function queryAura (api: DeriveApi): Observable<DeriveSessionProgress> {
|
||||
return api.derive.session.info().pipe(
|
||||
map((info): DeriveSessionProgress => ({
|
||||
...info,
|
||||
@@ -46,7 +45,7 @@ function queryAura (api: ApiInterfaceRx): Observable<DeriveSessionProgress> {
|
||||
);
|
||||
}
|
||||
|
||||
function queryBabe (api: ApiInterfaceRx): Observable<[DeriveSessionInfo, ResultSlotsFlat]> {
|
||||
function queryBabe (api: DeriveApi): Observable<[DeriveSessionInfo, ResultSlotsFlat]> {
|
||||
return api.derive.session.info().pipe(
|
||||
switchMap((info): Observable<[DeriveSessionInfo, ResultSlots | ResultSlotsNoSession]> =>
|
||||
combineLatest([
|
||||
@@ -75,7 +74,7 @@ function queryBabe (api: ApiInterfaceRx): Observable<[DeriveSessionInfo, ResultS
|
||||
/**
|
||||
* @description Retrieves all the session and era query and calculates specific values on it as the length of the session and eras
|
||||
*/
|
||||
export function progress (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSessionProgress> {
|
||||
export function progress (instanceId: string, api: DeriveApi): () => Observable<DeriveSessionProgress> {
|
||||
return memo(instanceId, (): Observable<DeriveSessionProgress> =>
|
||||
api.query.babe
|
||||
? queryBabe(api).pipe(
|
||||
+3
-4
@@ -2,12 +2,11 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { Option } from '@polkadot/types';
|
||||
import type { BalanceOf } from '@polkadot/types/interfaces';
|
||||
import type { PalletSocietyBid, PalletSocietyBidKind } from '@polkadot/types/lookup';
|
||||
import type { ITuple } from '@polkadot/types/types';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveSocietyCandidate } from '../types';
|
||||
import type { Option } from '@polkadot/types-codec';
|
||||
import type { DeriveApi, DeriveSocietyCandidate } from '../types';
|
||||
|
||||
import { combineLatest, map, of, switchMap } from 'rxjs';
|
||||
|
||||
@@ -19,7 +18,7 @@ type Result = [PalletSocietyBid[], ResultSuspend[]]
|
||||
/**
|
||||
* @description Get the candidate info for a society
|
||||
*/
|
||||
export function candidates (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSocietyCandidate[]> {
|
||||
export function candidates (instanceId: string, api: DeriveApi): () => Observable<DeriveSocietyCandidate[]> {
|
||||
return memo(instanceId, (): Observable<DeriveSocietyCandidate[]> =>
|
||||
api.query.society.candidates().pipe(
|
||||
switchMap((candidates): Observable<Result> =>
|
||||
@@ -5,8 +5,7 @@ import type { Observable } from 'rxjs';
|
||||
import type { Option, u32, Vec } from '@polkadot/types';
|
||||
import type { AccountId, BalanceOf } from '@polkadot/types/interfaces';
|
||||
import type { PalletSocietyBid } from '@polkadot/types/lookup';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveSociety } from '../types';
|
||||
import type { DeriveApi, DeriveSociety } from '../types';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
@@ -17,7 +16,7 @@ type Result = [Vec<PalletSocietyBid>, Option<AccountId>, Option<AccountId>, Opti
|
||||
/**
|
||||
* @description Get the overall info for a society
|
||||
*/
|
||||
export function info (instanceId: string, api: ApiInterfaceRx): () => Observable<DeriveSociety> {
|
||||
export function info (instanceId: string, api: DeriveApi): () => Observable<DeriveSociety> {
|
||||
return memo(instanceId, (): Observable<DeriveSociety> =>
|
||||
api.queryMulti<Result>([
|
||||
api.query.society.bids,
|
||||
+2
-3
@@ -3,8 +3,7 @@
|
||||
|
||||
import type { Observable } from 'rxjs';
|
||||
import type { AccountId } from '@polkadot/types/interfaces';
|
||||
import type { ApiInterfaceRx } from '../../types';
|
||||
import type { DeriveSocietyMember } from '../types';
|
||||
import type { DeriveApi, DeriveSocietyMember } from '../types';
|
||||
|
||||
import { map } from 'rxjs';
|
||||
|
||||
@@ -13,7 +12,7 @@ import { memo } from '../util';
|
||||
/**
|
||||
* @description Get the member info for a society
|
||||
*/
|
||||
export function member (instanceId: string, api: ApiInterfaceRx): (accountId: AccountId) => Observable<DeriveSocietyMember> {
|
||||
export function member (instanceId: string, api: DeriveApi): (accountId: AccountId) => Observable<DeriveSocietyMember> {
|
||||
return memo(instanceId, (accountId: AccountId): Observable<DeriveSocietyMember> =>
|
||||
api.derive.society._members([accountId]).pipe(
|
||||
map(([result]) => result)
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user