diff --git a/packages/api-augment/src/augment/api.ts b/packages/api-augment/src/augment/api.ts new file mode 100644 index 0000000000..9679e7449b --- /dev/null +++ b/packages/api-augment/src/augment/api.ts @@ -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>; + queryMulti: QueryableStorageMulti<'rxjs'>; + rpc: DecoratedRpc<'rxjs', RpcInterface>; + tx: SubmittableExtrinsics<'rxjs'>; + signer?: Signer; + } +} diff --git a/packages/api-augment/src/consts.ts b/packages/api-augment/src/augment/consts.ts similarity index 99% rename from packages/api-augment/src/consts.ts rename to packages/api-augment/src/augment/consts.ts index 1cb94d7e45..a9cbe1f33d 100644 --- a/packages/api-augment/src/consts.ts +++ b/packages/api-augment/src/augment/consts.ts @@ -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'; diff --git a/packages/api-augment/src/errors.ts b/packages/api-augment/src/augment/errors.ts similarity index 99% rename from packages/api-augment/src/errors.ts rename to packages/api-augment/src/augment/errors.ts index 8180de3889..58ba3ee561 100644 --- a/packages/api-augment/src/errors.ts +++ b/packages/api-augment/src/augment/errors.ts @@ -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 { diff --git a/packages/api-augment/src/events.ts b/packages/api-augment/src/augment/events.ts similarity index 99% rename from packages/api-augment/src/events.ts rename to packages/api-augment/src/augment/events.ts index 24608a73d2..9032a26ee1 100644 --- a/packages/api-augment/src/events.ts +++ b/packages/api-augment/src/augment/events.ts @@ -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'; diff --git a/packages/api-augment/src/augment/index.ts b/packages/api-augment/src/augment/index.ts new file mode 100644 index 0000000000..04234a686c --- /dev/null +++ b/packages/api-augment/src/augment/index.ts @@ -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'; diff --git a/packages/api-augment/src/query.ts b/packages/api-augment/src/augment/query.ts similarity index 99% rename from packages/api-augment/src/query.ts rename to packages/api-augment/src/augment/query.ts index a8503b4a3c..ed5e9a17cd 100644 --- a/packages/api-augment/src/query.ts +++ b/packages/api-augment/src/augment/query.ts @@ -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'; diff --git a/packages/api-augment/src/rpc.ts b/packages/api-augment/src/augment/rpc.ts similarity index 100% rename from packages/api-augment/src/rpc.ts rename to packages/api-augment/src/augment/rpc.ts diff --git a/packages/api-augment/src/tx.ts b/packages/api-augment/src/augment/tx.ts similarity index 99% rename from packages/api-augment/src/tx.ts rename to packages/api-augment/src/augment/tx.ts index 865f3a7a18..bbf594579f 100644 --- a/packages/api-augment/src/tx.ts +++ b/packages/api-augment/src/augment/tx.ts @@ -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'; diff --git a/packages/api-augment/src/bundle.ts b/packages/api-augment/src/bundle.ts index 9dba0c3543..c616ab3b87 100644 --- a/packages/api-augment/src/bundle.ts +++ b/packages/api-augment/src/bundle.ts @@ -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'; diff --git a/packages/api-augment/src/detectPackage.ts b/packages/api-augment/src/detectPackage.ts index 829ddb77a7..7dd3156094 100644 --- a/packages/api-augment/src/detectPackage.ts +++ b/packages/api-augment/src/detectPackage.ts @@ -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'; diff --git a/packages/api-augment/src/index.ts b/packages/api-augment/src/index.ts index b718d85e20..594d9f24be 100644 --- a/packages/api-augment/src/index.ts +++ b/packages/api-augment/src/index.ts @@ -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'; diff --git a/packages/api-base/src/types/api.ts b/packages/api-base/src/types/api.ts new file mode 100644 index 0000000000..c1ec47e738 --- /dev/null +++ b/packages/api-base/src/types/api.ts @@ -0,0 +1,4 @@ +// Copyright 2017-2021 @polkadot/api authors & contributors +// SPDX-License-Identifier: Apache-2.0 + +export const __API_BASE_TYPES_API = 'empty'; diff --git a/packages/api-base/src/types/index.ts b/packages/api-base/src/types/index.ts index 0f544142cd..8467aabc38 100644 --- a/packages/api-base/src/types/index.ts +++ b/packages/api-base/src/types/index.ts @@ -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'; diff --git a/packages/api-derive/package.json b/packages/api-derive/package.json index 0002781512..3326b014cd 100644 --- a/packages/api-derive/package.json +++ b/packages/api-derive/package.json @@ -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" } } diff --git a/packages/api/src/derive/accounts/accountId.ts b/packages/api-derive/src/accounts/accountId.ts similarity index 84% rename from packages/api/src/derive/accounts/accountId.ts rename to packages/api-derive/src/accounts/accountId.ts index c9952e83b9..2d0db25925 100644 --- a/packages/api/src/derive/accounts/accountId.ts +++ b/packages/api-derive/src/accounts/accountId.ts @@ -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 { +export function accountId (instanceId: string, api: DeriveApi): (address?: Address | AccountId | AccountIndex | string | null) => Observable { return memo(instanceId, (address?: Address | AccountId | AccountIndex | string | null): Observable => { const decoded = isU8a(address) ? address diff --git a/packages/api/src/derive/accounts/flags.ts b/packages/api-derive/src/accounts/flags.ts similarity index 75% rename from packages/api/src/derive/accounts/flags.ts rename to packages/api-derive/src/accounts/flags.ts index 4cc8d47a27..eb864c3f62 100644 --- a/packages/api/src/derive/accounts/flags.ts +++ b/packages/api-derive/src/accounts/flags.ts @@ -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> | 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 { +export function flags (instanceId: string, api: DeriveApi): (address?: AccountId | Address | string | null) => Observable { return memo(instanceId, (address?: AccountId | Address | string | null): Observable => { const elections = api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections; return combineLatest([ address && elections?.members - ? elections.members>>() + ? elections.members<[AccountId, Balance][]>() : of(undefined), address && api.query.council?.members ? api.query.council.members() diff --git a/packages/api/src/derive/accounts/idAndIndex.ts b/packages/api-derive/src/accounts/idAndIndex.ts similarity index 85% rename from packages/api/src/derive/accounts/idAndIndex.ts rename to packages/api-derive/src/accounts/idAndIndex.ts index f29aaeb358..e113cefda8 100644 --- a/packages/api/src/derive/accounts/idAndIndex.ts +++ b/packages/api-derive/src/accounts/idAndIndex.ts @@ -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 { +export function idAndIndex (instanceId: string, api: DeriveApi): (address?: Address | AccountId | AccountIndex | Uint8Array | string | null) => Observable { return memo(instanceId, (address?: Address | AccountId | AccountIndex | Uint8Array | string | null): Observable => { try { // yes, this can fail, don't care too much, catch will catch it diff --git a/packages/api/src/derive/accounts/idToIndex.ts b/packages/api-derive/src/accounts/idToIndex.ts similarity index 80% rename from packages/api/src/derive/accounts/idToIndex.ts rename to packages/api-derive/src/accounts/idToIndex.ts index 57cb636e57..4f8a7bea5e 100644 --- a/packages/api/src/derive/accounts/idToIndex.ts +++ b/packages/api-derive/src/accounts/idToIndex.ts @@ -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 { +export function idToIndex (instanceId: string, api: DeriveApi): (accountId: AccountId | string) => Observable { return memo(instanceId, (accountId: AccountId | string): Observable => api.derive.accounts.indexes().pipe( map((indexes: AccountIndexes): AccountIndex | undefined => diff --git a/packages/api/src/derive/accounts/identity.ts b/packages/api-derive/src/accounts/identity.ts similarity index 79% rename from packages/api/src/derive/accounts/identity.ts rename to packages/api-derive/src/accounts/identity.ts index 1a3ee0c331..a8258d3895 100644 --- a/packages/api/src/derive/accounts/identity.ts +++ b/packages/api-derive/src/accounts/identity.ts @@ -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, su }; } -function getParent (api: ApiInterfaceRx, identityOfOpt: Option | undefined, superOfOpt: Option> | undefined): Observable<[Option | undefined, [AccountId, Data] | undefined]> { +function getParent (api: DeriveApi, identityOfOpt: Option | undefined, superOfOpt: Option> | undefined): Observable<[Option | 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 | undefined, Option> | undefined]> { +function getBase (api: DeriveApi, accountId?: AccountId | Uint8Array | string): Observable<[Option | undefined, Option> | undefined]> { return accountId && api.query.identity?.identityOf ? api.queryMulti<[Option, Option>]>([ [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 { +export function identity (instanceId: string, api: DeriveApi): (accountId?: AccountId | Uint8Array | string) => Observable { return memo(instanceId, (accountId?: AccountId | Uint8Array | string): Observable => 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 { +export function hasIdentityMulti (instanceId: string, api: DeriveApi): (accountIds: (AccountId | Uint8Array | string)[]) => Observable { return memo(instanceId, (accountIds: (AccountId | Uint8Array | string)[]): Observable => api.query.identity?.identityOf ? combineLatest([ diff --git a/packages/api/src/derive/accounts/index.ts b/packages/api-derive/src/accounts/index.ts similarity index 100% rename from packages/api/src/derive/accounts/index.ts rename to packages/api-derive/src/accounts/index.ts diff --git a/packages/api/src/derive/accounts/indexToId.ts b/packages/api-derive/src/accounts/indexToId.ts similarity index 62% rename from packages/api/src/derive/accounts/indexToId.ts rename to packages/api-derive/src/accounts/indexToId.ts index 37950da194..6eb0c60712 100644 --- a/packages/api/src/derive/accounts/indexToId.ts +++ b/packages/api-derive/src/accounts/indexToId.ts @@ -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 { +export function indexToId (instanceId: string, api: DeriveApi): (accountIndex: AccountIndex | string) => Observable { return memo(instanceId, (accountIndex: AccountIndex | string): Observable => api.query.indices - ? api.query.indices.accounts>>(accountIndex).pipe( + ? api.query.indices.accounts(accountIndex).pipe( map((optResult): AccountId | undefined => optResult.unwrapOr([])[0] ) diff --git a/packages/api/src/derive/accounts/indexes.ts b/packages/api-derive/src/accounts/indexes.ts similarity index 84% rename from packages/api/src/derive/accounts/indexes.ts rename to packages/api-derive/src/accounts/indexes.ts index 6c61a83676..0210f8906d 100644 --- a/packages/api/src/derive/accounts/indexes.ts +++ b/packages/api-derive/src/accounts/indexes.ts @@ -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 { +function queryAccounts (api: DeriveApi): Observable { 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 { * }); * ``` */ -export function indexes (instanceId: string, api: ApiInterfaceRx): () => Observable { +export function indexes (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => indicesCache ? of(indicesCache) diff --git a/packages/api/src/derive/accounts/info.ts b/packages/api-derive/src/accounts/info.ts similarity index 77% rename from packages/api/src/derive/accounts/info.ts rename to packages/api-derive/src/accounts/info.ts index b558cbbf29..6db49e93dd 100644 --- a/packages/api/src/derive/accounts/info.ts +++ b/packages/api-derive/src/accounts/info.ts @@ -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 { +function retrieveNick (api: DeriveApi, accountId?: AccountId): Observable { return (( accountId && api.query.nicks?.nameOf - ? api.query.nicks.nameOf>>(accountId) + ? api.query.nicks.nameOf(accountId) : of(undefined) ) as Observable> | undefined>).pipe( map((nameOf): string | undefined => @@ -32,7 +31,7 @@ function retrieveNick (api: ApiInterfaceRx, accountId?: AccountId): Observable Observable { +export function info (instanceId: string, api: DeriveApi): (address?: AccountIndex | AccountId | Address | Uint8Array | string | null) => Observable { return memo(instanceId, (address?: AccountIndex | AccountId | Address | Uint8Array | string | null): Observable => api.derive.accounts.idAndIndex(address).pipe( switchMap(([accountId, accountIndex]): Observable<[Partial, DeriveAccountRegistration, string?]> => diff --git a/packages/api/src/derive/accounts/types.ts b/packages/api-derive/src/accounts/types.ts similarity index 100% rename from packages/api/src/derive/accounts/types.ts rename to packages/api-derive/src/accounts/types.ts diff --git a/packages/api/src/derive/balances/account.ts b/packages/api-derive/src/balances/account.ts similarity index 81% rename from packages/api/src/derive/balances/account.ts rename to packages/api-derive/src/balances/account.ts index beb740202e..456221c617 100644 --- a/packages/api/src/derive/balances/account.ts +++ b/packages/api-derive/src/balances/account.ts @@ -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 { +function queryBalancesFree (api: DeriveApi, accountId: AccountId): Observable { 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 { +function queryNonceOnly (api: DeriveApi, accountId: AccountId): Observable { 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 { +function queryBalancesAccount (api: DeriveApi, accountId: AccountId, modules: string[] = ['balances']): Observable { 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 { +function querySystemAccount (api: DeriveApi, accountId: AccountId): Observable { // AccountInfo is current, support old, eg. Edgeware return api.query.system.account>(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 { +export function account (instanceId: string, api: DeriveApi): (address: AccountIndex | AccountId | Address | string) => Observable { const balanceInstances = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), 'balances'); return memo(instanceId, (address: AccountIndex | AccountId | Address | string): Observable => diff --git a/packages/api/src/derive/balances/all.ts b/packages/api-derive/src/balances/all.ts similarity index 85% rename from packages/api/src/derive/balances/all.ts rename to packages/api-derive/src/balances/all.ts index 60a3b06f22..34ab2566d9 100644 --- a/packages/api/src/derive/balances/all.ts +++ b/packages/api-derive/src/balances/all.ts @@ -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 { +function queryOld (api: DeriveApi, accountId: AccountId): Observable { return api.queryMulti<[Vec, Option]>([ [api.query.balances.locks, accountId], [api.query.balances.vesting, accountId] @@ -142,8 +142,8 @@ function queryOld (api: ApiInterfaceRx, accountId: AccountId): Observable(nullable: T): nullable is NonNullable => !!nullable; // current (balances, vesting) -function queryCurrent (api: ApiInterfaceRx, accountId: AccountId, balanceInstances: string[] = ['balances']): Observable { - const calls = balanceInstances.map((m): ApiInterfaceRx['query']['balances']['locks'] | undefined => +function queryCurrent (api: DeriveApi, accountId: AccountId, balanceInstances: string[] = ['balances']): Observable { + 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 { +export function all (instanceId: string, api: DeriveApi): (address: AccountIndex | AccountId | Address | string) => Observable { const balanceInstances = api.registry.getModuleInstances(api.runtimeVersion.specName.toString(), 'balances'); return memo(instanceId, (address: AccountIndex | AccountId | Address | string): Observable => diff --git a/packages/api/src/derive/balances/fees.ts b/packages/api-derive/src/balances/fees.ts similarity index 89% rename from packages/api/src/derive/balances/fees.ts rename to packages/api-derive/src/balances/fees.ts index 875133a5cc..9251c835b9 100644 --- a/packages/api/src/derive/balances/fees.ts +++ b/packages/api-derive/src/balances/fees.ts @@ -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 { +export function fees (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => of([ // deprecated - remove diff --git a/packages/api/src/derive/balances/index.ts b/packages/api-derive/src/balances/index.ts similarity index 100% rename from packages/api/src/derive/balances/index.ts rename to packages/api-derive/src/balances/index.ts diff --git a/packages/api/src/derive/balances/types.ts b/packages/api-derive/src/balances/types.ts similarity index 100% rename from packages/api/src/derive/balances/types.ts rename to packages/api-derive/src/balances/types.ts diff --git a/packages/api/src/derive/balances/votingBalances.ts b/packages/api-derive/src/balances/votingBalances.ts similarity index 70% rename from packages/api/src/derive/balances/votingBalances.ts rename to packages/api-derive/src/balances/votingBalances.ts index 7d82a02bae..510403ce75 100644 --- a/packages/api/src/derive/balances/votingBalances.ts +++ b/packages/api-derive/src/balances/votingBalances.ts @@ -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 { +export function votingBalances (instanceId: string, api: DeriveApi): (addresses?: (AccountId | AccountIndex | Address | string)[]) => Observable { return memo(instanceId, (addresses?: (AccountId | AccountIndex | Address | string)[]): Observable => !addresses || !addresses.length ? of([] as DeriveBalancesAccount[]) diff --git a/packages/api/src/derive/bounties/bounties.spec.ts b/packages/api-derive/src/bounties/bounties.spec.ts similarity index 93% rename from packages/api/src/derive/bounties/bounties.spec.ts rename to packages/api-derive/src/bounties/bounties.spec.ts index 486f5a2c12..90c8e60c0f 100644 --- a/packages/api/src/derive/bounties/bounties.spec.ts +++ b/packages/api-derive/src/bounties/bounties.spec.ts @@ -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)()); diff --git a/packages/api/src/derive/bounties/bounties.ts b/packages/api-derive/src/bounties/bounties.ts similarity index 79% rename from packages/api/src/derive/bounties/bounties.ts rename to packages/api-derive/src/bounties/bounties.ts index 64833bd435..9a6b8c84f4 100644 --- a/packages/api/src/derive/bounties/bounties.ts +++ b/packages/api-derive/src/bounties/bounties.ts @@ -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 { +export function bounties (instanceId: string, api: DeriveApi): () => Observable { const bountyBase = api.query.bounties || api.query.treasury; return memo(instanceId, (): Observable => combineLatest([ - bountyBase.bountyCount(), + bountyBase.bountyCount(), api.query.council - ? api.query.council.proposalCount() + ? api.query.council.proposalCount() : of(0) ]).pipe( switchMap(() => combineLatest([ - bountyBase.bounties.keys<[BountyIndex]>(), + bountyBase.bounties.keys(), api.derive.council ? api.derive.council.proposals() : of([]) diff --git a/packages/api/src/derive/bounties/helpers/filterBountyProposals.ts b/packages/api-derive/src/bounties/helpers/filterBountyProposals.ts similarity index 64% rename from packages/api/src/derive/bounties/helpers/filterBountyProposals.ts rename to packages/api-derive/src/bounties/helpers/filterBountyProposals.ts index c762cef7d2..41c4b9d746 100644 --- a/packages/api/src/derive/bounties/helpers/filterBountyProposals.ts +++ b/packages/api-derive/src/bounties/helpers/filterBountyProposals.ts @@ -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]; diff --git a/packages/api/src/derive/bounties/index.ts b/packages/api-derive/src/bounties/index.ts similarity index 100% rename from packages/api/src/derive/bounties/index.ts rename to packages/api-derive/src/bounties/index.ts diff --git a/packages/api-derive/src/bundle.ts b/packages/api-derive/src/bundle.ts index fed8dcd11e..68281fa560 100644 --- a/packages/api-derive/src/bundle.ts +++ b/packages/api-derive/src/bundle.ts @@ -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 = { + 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> = {}; + 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) + }; +} diff --git a/packages/api/src/derive/chain/bestNumber.ts b/packages/api-derive/src/chain/bestNumber.ts similarity index 85% rename from packages/api/src/derive/chain/bestNumber.ts rename to packages/api-derive/src/chain/bestNumber.ts index a95d7fc806..62326840a7 100644 --- a/packages/api/src/derive/chain/bestNumber.ts +++ b/packages/api-derive/src/chain/bestNumber.ts @@ -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() ); diff --git a/packages/api/src/derive/chain/bestNumberFinalized.ts b/packages/api-derive/src/chain/bestNumberFinalized.ts similarity index 87% rename from packages/api/src/derive/chain/bestNumberFinalized.ts rename to packages/api-derive/src/chain/bestNumberFinalized.ts index 43cf9c8fd0..5ae0081fea 100644 --- a/packages/api/src/derive/chain/bestNumberFinalized.ts +++ b/packages/api-derive/src/chain/bestNumberFinalized.ts @@ -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() ); diff --git a/packages/api/src/derive/chain/bestNumberLag.ts b/packages/api-derive/src/chain/bestNumberLag.ts similarity index 85% rename from packages/api/src/derive/chain/bestNumberLag.ts rename to packages/api-derive/src/chain/bestNumberLag.ts index 8ed53598cf..b286547273 100644 --- a/packages/api/src/derive/chain/bestNumberLag.ts +++ b/packages/api-derive/src/chain/bestNumberLag.ts @@ -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 { +export function bestNumberLag (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => combineLatest([ api.derive.chain.bestNumber(), diff --git a/packages/api/src/derive/chain/getBlock.ts b/packages/api-derive/src/chain/getBlock.ts similarity index 89% rename from packages/api/src/derive/chain/getBlock.ts rename to packages/api-derive/src/chain/getBlock.ts index 4b10dac04f..f96c135019 100644 --- a/packages/api/src/derive/chain/getBlock.ts +++ b/packages/api-derive/src/chain/getBlock.ts @@ -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 { +export function getBlock (instanceId: string, api: DeriveApi): (hash: Uint8Array | string) => Observable { return memo(instanceId, (blockHash: Uint8Array | string): Observable => combineLatest([ api.rpc.chain.getBlock(blockHash), diff --git a/packages/api/src/derive/chain/getHeader.ts b/packages/api-derive/src/chain/getHeader.ts similarity index 89% rename from packages/api/src/derive/chain/getHeader.ts rename to packages/api-derive/src/chain/getHeader.ts index aba84763ff..80deeab07a 100644 --- a/packages/api/src/derive/chain/getHeader.ts +++ b/packages/api-derive/src/chain/getHeader.ts @@ -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 { +export function getHeader (instanceId: string, api: DeriveApi): (blockHash: Uint8Array | string) => Observable { return memo(instanceId, (blockHash: Uint8Array | string): Observable => combineLatest([ api.rpc.chain.getHeader(blockHash), diff --git a/packages/api/src/derive/chain/index.ts b/packages/api-derive/src/chain/index.ts similarity index 100% rename from packages/api/src/derive/chain/index.ts rename to packages/api-derive/src/chain/index.ts diff --git a/packages/api/src/derive/chain/subscribeNewBlocks.ts b/packages/api-derive/src/chain/subscribeNewBlocks.ts similarity index 87% rename from packages/api/src/derive/chain/subscribeNewBlocks.ts rename to packages/api-derive/src/chain/subscribeNewBlocks.ts index 8b0c11cbb1..b43a748ddb 100644 --- a/packages/api/src/derive/chain/subscribeNewBlocks.ts +++ b/packages/api-derive/src/chain/subscribeNewBlocks.ts @@ -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 { +export function subscribeNewBlocks (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.derive.chain.subscribeNewHeads().pipe( switchMap((header) => { diff --git a/packages/api/src/derive/chain/subscribeNewHeads.ts b/packages/api-derive/src/chain/subscribeNewHeads.ts similarity index 87% rename from packages/api/src/derive/chain/subscribeNewHeads.ts rename to packages/api-derive/src/chain/subscribeNewHeads.ts index 6b9e41d905..9499ed919f 100644 --- a/packages/api/src/derive/chain/subscribeNewHeads.ts +++ b/packages/api-derive/src/chain/subscribeNewHeads.ts @@ -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 { +export function subscribeNewHeads (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => combineLatest([ api.rpc.chain.subscribeNewHeads(), diff --git a/packages/api/src/derive/chain/util.ts b/packages/api-derive/src/chain/util.ts similarity index 74% rename from packages/api/src/derive/chain/util.ts rename to packages/api-derive/src/chain/util.ts index f40ca20a00..0ad8b73aaf 100644 --- a/packages/api/src/derive/chain/util.ts +++ b/packages/api-derive/src/chain/util.ts @@ -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 ..//src embedded in the *.d.ts files export type { BlockNumber } from '@polkadot/types/interfaces'; -export function unwrapBlockNumber }> (fn: (api: ApiInterfaceRx) => Observable): (instanceId: string, api: ApiInterfaceRx) => () => Observable { - return (instanceId: string, api: ApiInterfaceRx) => +export function unwrapBlockNumber }> (fn: (api: DeriveApi) => Observable): (instanceId: string, api: DeriveApi) => () => Observable { + return (instanceId: string, api: DeriveApi) => memo(instanceId, () => fn(api).pipe( map((r) => r.number.unwrap()) )); diff --git a/packages/api/src/derive/collective/helpers.ts b/packages/api-derive/src/collective/helpers.ts similarity index 72% rename from packages/api/src/derive/collective/helpers.ts rename to packages/api-derive/src/collective/helpers.ts index 81169c8d41..b852173b78 100644 --- a/packages/api/src/derive/collective/helpers.ts +++ b/packages/api-derive/src/collective/helpers.ts @@ -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 Observable> (_section: Collective, fn: (section: string, api: ApiInterfaceRx, instanceId: string) => F): (instanceId: string, api: ApiInterfaceRx) => F { - return (instanceId: string, api: ApiInterfaceRx) => +export function withSection Observable> (_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 (method: 'members' | 'proposals' | 'proposalCount', empty: T): (_section: Collective) => (instanceId: string, api: ApiInterfaceRx) => () => Observable { +export function callMethod (method: 'members' | 'proposals' | 'proposalCount', empty: T): (_section: Collective) => (instanceId: string, api: DeriveApi) => () => Observable { return (_section: Collective) => withSection(_section, (section, api) => (): Observable => diff --git a/packages/api/src/derive/collective/index.ts b/packages/api-derive/src/collective/index.ts similarity index 100% rename from packages/api/src/derive/collective/index.ts rename to packages/api-derive/src/collective/index.ts diff --git a/packages/api/src/derive/collective/members.ts b/packages/api-derive/src/collective/members.ts similarity index 100% rename from packages/api/src/derive/collective/members.ts rename to packages/api-derive/src/collective/members.ts diff --git a/packages/api/src/derive/collective/prime.ts b/packages/api-derive/src/collective/prime.ts similarity index 78% rename from packages/api/src/derive/collective/prime.ts rename to packages/api-derive/src/collective/prime.ts index a98d124824..ad5187c248 100644 --- a/packages/api/src/derive/collective/prime.ts +++ b/packages/api-derive/src/collective/prime.ts @@ -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 { +export function prime (_section: Collective): (instanceId: string, api: DeriveApi) => () => Observable { return withSection(_section, (section, api) => (): Observable => isFunction(api.query[section as 'council']?.prime) - ? api.query[section as 'council'].prime>().pipe( + ? api.query[section as 'council'].prime().pipe( map((optPrime): AccountId | null => optPrime.unwrapOr(null) ) diff --git a/packages/api/src/derive/collective/proposals.ts b/packages/api-derive/src/collective/proposals.ts similarity index 82% rename from packages/api/src/derive/collective/proposals.ts rename to packages/api-derive/src/collective/proposals.ts index 26505cd1da..18b5881437 100644 --- a/packages/api/src/derive/collective/proposals.ts +++ b/packages/api-derive/src/collective/proposals.ts @@ -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 | null)[], Option[]]; -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 { +function _proposalsFrom (section: string, api: DeriveApi, hashes: (Hash | Uint8Array | string)[]): Observable { 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 { +export function hasProposals (_section: Collective): (instanceId: string, api: DeriveApi) => () => Observable { return withSection(_section, (section, api) => (): Observable => of(isFunction(api.query[section]?.proposals)) ); } -export function proposals (_section: Collective): (instanceId: string, api: ApiInterfaceRx) => () => Observable { +export function proposals (_section: Collective): (instanceId: string, api: DeriveApi) => () => Observable { return withSection(_section, (section, api) => (): Observable => 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 { +export function proposal (_section: Collective): (instanceId: string, api: DeriveApi) => (hash: Hash | Uint8Array | string) => Observable { return withSection(_section, (section, api) => (hash: Hash | Uint8Array | string): Observable => isFunction(api.query[section]?.proposals) diff --git a/packages/api/src/derive/collective/types.ts b/packages/api-derive/src/collective/types.ts similarity index 100% rename from packages/api/src/derive/collective/types.ts rename to packages/api-derive/src/collective/types.ts diff --git a/packages/api/src/derive/contracts/fees.ts b/packages/api-derive/src/contracts/fees.ts similarity index 88% rename from packages/api/src/derive/contracts/fees.ts rename to packages/api-derive/src/contracts/fees.ts index cff791bdb5..8c8692a566 100644 --- a/packages/api/src/derive/contracts/fees.ts +++ b/packages/api-derive/src/contracts/fees.ts @@ -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 { +function queryConstants (api: DeriveApi): Observable { return of([ // deprecated api.consts.contracts.callBaseFee || api.registry.createType('Balance'), @@ -44,7 +43,7 @@ function queryConstants (api: ApiInterfaceRx): Observable { * }); * ``` */ -export function fees (instanceId: string, api: ApiInterfaceRx): () => Observable { +export function fees (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => { return queryConstants(api).pipe( map(([callBaseFee, contractFee, creationFee, transactionBaseFee, transactionByteFee, transferFee, rentByteFee, rentDepositOffset, surchargeReward, tombstoneDeposit]): DeriveContractFees => ({ diff --git a/packages/api/src/derive/contracts/index.ts b/packages/api-derive/src/contracts/index.ts similarity index 100% rename from packages/api/src/derive/contracts/index.ts rename to packages/api-derive/src/contracts/index.ts diff --git a/packages/api/src/derive/council/index.ts b/packages/api-derive/src/council/index.ts similarity index 100% rename from packages/api/src/derive/council/index.ts rename to packages/api-derive/src/council/index.ts diff --git a/packages/api/src/derive/council/types.ts b/packages/api-derive/src/council/types.ts similarity index 100% rename from packages/api/src/derive/council/types.ts rename to packages/api-derive/src/council/types.ts diff --git a/packages/api/src/derive/council/votes.ts b/packages/api-derive/src/council/votes.ts similarity index 87% rename from packages/api/src/derive/council/votes.ts rename to packages/api-derive/src/council/votes.ts index 54f7356a75..cc1dc19a3f 100644 --- a/packages/api/src/derive/council/votes.ts +++ b/packages/api-derive/src/council/votes.ts @@ -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 { +function retrievePrev (api: DeriveApi, elections: QueryableModuleStorage<'rxjs'>): Observable { return combineLatest([ retrieveStakeOf(elections), retrieveVoteOf(elections) @@ -76,7 +76,7 @@ function retrieveCurrent (elections: QueryableModuleStorage<'rxjs'>): Observable ); } -export function votes (instanceId: string, api: ApiInterfaceRx): () => Observable { +export function votes (instanceId: string, api: DeriveApi): () => Observable { const elections = api.query.phragmenElection || api.query.electionsPhragmen || api.query.elections; return memo(instanceId, (): Observable => diff --git a/packages/api/src/derive/council/votesOf.ts b/packages/api-derive/src/council/votesOf.ts similarity index 72% rename from packages/api/src/derive/council/votesOf.ts rename to packages/api-derive/src/council/votesOf.ts index 63002c05f4..e17f8ccf06 100644 --- a/packages/api/src/derive/council/votesOf.ts +++ b/packages/api-derive/src/council/votesOf.ts @@ -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 { +export function votesOf (instanceId: string, api: DeriveApi): (accountId: string | Uint8Array | AccountId) => Observable { return memo(instanceId, (accountId: string | Uint8Array | AccountId): Observable => api.derive.council.votes().pipe( map((votes): DeriveCouncilVote => diff --git a/packages/api/src/derive/crowdloan/childKey.ts b/packages/api-derive/src/crowdloan/childKey.ts similarity index 85% rename from packages/api/src/derive/crowdloan/childKey.ts rename to packages/api-derive/src/crowdloan/childKey.ts index 9eb32135ae..a15f37e056 100644 --- a/packages/api/src/derive/crowdloan/childKey.ts +++ b/packages/api-derive/src/crowdloan/childKey.ts @@ -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 { +export function childKey (instanceId: string, api: DeriveApi): (paraId: string | number | BN) => Observable { return memo(instanceId, (paraId: string | number | BN): Observable => api.query.crowdloan.funds>(paraId).pipe( map((optInfo) => diff --git a/packages/api/src/derive/crowdloan/contributions.ts b/packages/api-derive/src/crowdloan/contributions.ts similarity index 82% rename from packages/api/src/derive/crowdloan/contributions.ts rename to packages/api-derive/src/crowdloan/contributions.ts index 61b66c4800..e8ddb74800 100644 --- a/packages/api/src/derive/crowdloan/contributions.ts +++ b/packages/api-derive/src/crowdloan/contributions.ts @@ -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 { +function _getUpdates (api: DeriveApi, paraId: string | number | BN): Observable { 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 { +function _eventTriggerAll (api: DeriveApi, paraId: string | number | BN): Observable { return api.query.system.events().pipe( switchMap((events): Observable => { 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 { +function _getKeysPaged (api: DeriveApi, childKey: string): Observable { const startSubject = new BehaviorSubject(undefined); return startSubject.pipe( @@ -79,7 +78,7 @@ function _getKeysPaged (api: ApiInterfaceRx, childKey: string): Observable { +function _getAll (api: DeriveApi, paraId: string | number | BN, childKey: string): Observable { 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 { +function _contributions (api: DeriveApi, paraId: string | number | BN, childKey: string): Observable { 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 { +export function contributions (instanceId: string, api: DeriveApi): (paraId: string | number | BN) => Observable { return memo(instanceId, (paraId: string | number | BN): Observable => api.derive.crowdloan.childKey(paraId).pipe( switchMap((childKey) => diff --git a/packages/api/src/derive/crowdloan/index.ts b/packages/api-derive/src/crowdloan/index.ts similarity index 82% rename from packages/api/src/derive/crowdloan/index.ts rename to packages/api-derive/src/crowdloan/index.ts index 77ebd02849..03bf27dd84 100644 --- a/packages/api/src/derive/crowdloan/index.ts +++ b/packages/api-derive/src/crowdloan/index.ts @@ -3,4 +3,4 @@ export * from './childKey'; export * from './contributions'; -export * from './onwContributions'; +export * from './ownContributions'; diff --git a/packages/api/src/derive/crowdloan/onwContributions.ts b/packages/api-derive/src/crowdloan/ownContributions.ts similarity index 73% rename from packages/api/src/derive/crowdloan/onwContributions.ts rename to packages/api-derive/src/crowdloan/ownContributions.ts index 2131e1d764..f437042497 100644 --- a/packages/api/src/derive/crowdloan/onwContributions.ts +++ b/packages/api-derive/src/crowdloan/ownContributions.ts @@ -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 { +function _getValues (api: DeriveApi, childKey: string, keys: string[]): Observable { // 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 { +function _watchOwnChanges (api: DeriveApi, paraId: string | number | BN, childkey: string, keys: string[]): Observable { return api.query.system.events().pipe( switchMap((events): Observable => { 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 { +function _contributions (api: DeriveApi, paraId: string | number | BN, childKey: string, keys: string[]): Observable { 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 { +export function ownContributions (instanceId: string, api: DeriveApi): (paraId: string | number | BN, keys: string[]) => Observable { return memo(instanceId, (paraId: string | number | BN, keys: string[]): Observable => api.derive.crowdloan.childKey(paraId).pipe( switchMap((childKey) => diff --git a/packages/api/src/derive/crowdloan/types.ts b/packages/api-derive/src/crowdloan/types.ts similarity index 100% rename from packages/api/src/derive/crowdloan/types.ts rename to packages/api-derive/src/crowdloan/types.ts diff --git a/packages/api/src/derive/crowdloan/util.ts b/packages/api-derive/src/crowdloan/util.ts similarity index 84% rename from packages/api/src/derive/crowdloan/util.ts rename to packages/api-derive/src/crowdloan/util.ts index 9642f1806c..de2d8e486f 100644 --- a/packages/api/src/derive/crowdloan/util.ts +++ b/packages/api-derive/src/crowdloan/util.ts @@ -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): Changes { +export function extractContributed (paraId: string | number | BN, events: Vec): Changes { const added: string[] = []; const removed: string[] = []; diff --git a/packages/api/src/derive/democracy/dispatchQueue.ts b/packages/api-derive/src/democracy/dispatchQueue.ts similarity index 87% rename from packages/api/src/derive/democracy/dispatchQueue.ts rename to packages/api-derive/src/democracy/dispatchQueue.ts index 1a86675dc1..9794b17d11 100644 --- a/packages/api/src/derive/democracy/dispatchQueue.ts +++ b/packages/api-derive/src/democracy/dispatchQueue.ts @@ -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 { +function queryQueue (api: DeriveApi): Observable { return api.query.democracy.dispatchQueue>>().pipe( switchMap((dispatches) => combineLatest([ @@ -43,7 +42,7 @@ function queryQueue (api: ApiInterfaceRx): Observable { ); } -function schedulerEntries (api: ApiInterfaceRx): Observable<[BlockNumber[], (Option[] | null)[]]> { +function schedulerEntries (api: DeriveApi): Observable<[BlockNumber[], (Option[] | 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 { +function queryScheduler (api: DeriveApi): Observable { return schedulerEntries(api).pipe( switchMap(([blockNumbers, agendas]): Observable<[SchedulerInfo[], (DeriveProposalImage | undefined)[]]> => { const result: SchedulerInfo[] = []; @@ -100,7 +99,7 @@ function queryScheduler (api: ApiInterfaceRx): Observable { ); } -export function dispatchQueue (instanceId: string, api: ApiInterfaceRx): () => Observable { +export function dispatchQueue (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => isFunction(api.query.scheduler?.agenda) ? queryScheduler(api) diff --git a/packages/api/src/derive/democracy/index.ts b/packages/api-derive/src/democracy/index.ts similarity index 100% rename from packages/api/src/derive/democracy/index.ts rename to packages/api-derive/src/democracy/index.ts diff --git a/packages/api/src/derive/democracy/locks.ts b/packages/api-derive/src/democracy/locks.ts similarity index 78% rename from packages/api/src/derive/democracy/locks.ts rename to packages/api-derive/src/democracy/locks.ts index 8faaa7a567..43b3ebdecb 100644 --- a/packages/api/src/derive/democracy/locks.ts +++ b/packages/api-derive/src/democracy/locks.ts @@ -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 { +function delegateLocks (api: DeriveApi, { balance, conviction, target }: VotingDelegating): Observable { 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 { +function directLocks (api: DeriveApi, { votes }: VotingDirect): Observable { 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 { +export function locks (instanceId: string, api: DeriveApi): (accountId: string | AccountId) => Observable { return memo(instanceId, (accountId: string | AccountId): Observable => api.query.democracy.votingOf ? api.query.democracy.votingOf(accountId).pipe( diff --git a/packages/api/src/derive/democracy/nextExternal.ts b/packages/api-derive/src/democracy/nextExternal.ts similarity index 72% rename from packages/api/src/derive/democracy/nextExternal.ts rename to packages/api-derive/src/democracy/nextExternal.ts index a4d6e40c8c..8a543cef4c 100644 --- a/packages/api/src/derive/democracy/nextExternal.ts +++ b/packages/api-derive/src/democracy/nextExternal.ts @@ -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>): Observable { +function withImage (api: DeriveApi, nextOpt: Option>): Observable { if (nextOpt.isNone) { return of(null); } @@ -29,7 +28,7 @@ function withImage (api: ApiInterfaceRx, nextOpt: Option Observable { +export function nextExternal (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.query.democracy?.nextExternal ? api.query.democracy.nextExternal().pipe( diff --git a/packages/api/src/derive/democracy/preimage.ts b/packages/api-derive/src/democracy/preimage.ts similarity index 68% rename from packages/api/src/derive/democracy/preimage.ts rename to packages/api-derive/src/democracy/preimage.ts index 1c73fa3474..8b15d280ad 100644 --- a/packages/api/src/derive/democracy/preimage.ts +++ b/packages/api-derive/src/democracy/preimage.ts @@ -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 { +export function preimage (instanceId: string, api: DeriveApi): (hash: Hash) => Observable { return memo(instanceId, (hash: Hash): Observable => api.query.democracy.preimages(hash).pipe( map((imageOpt) => parseImage(api, imageOpt)) diff --git a/packages/api/src/derive/democracy/preimages.ts b/packages/api-derive/src/democracy/preimages.ts similarity index 72% rename from packages/api/src/derive/democracy/preimages.ts rename to packages/api-derive/src/democracy/preimages.ts index db2c639842..bbb2348c5d 100644 --- a/packages/api/src/derive/democracy/preimages.ts +++ b/packages/api-derive/src/democracy/preimages.ts @@ -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( diff --git a/packages/api/src/derive/democracy/proposals.ts b/packages/api-derive/src/democracy/proposals.ts similarity index 89% rename from packages/api/src/derive/democracy/proposals.ts rename to packages/api-derive/src/democracy/proposals.ts index 94082025b5..2677deded2 100644 --- a/packages/api/src/derive/democracy/proposals.ts +++ b/packages/api-derive/src/democracy/proposals.ts @@ -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 { +export function proposals (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => isFunction(api.query.democracy?.publicProps) && isFunction(api.query.democracy?.preimages) - ? api.query.democracy.publicProps().pipe( + ? api.query.democracy.publicProps().pipe( switchMap((proposals) => proposals.length ? combineLatest([ diff --git a/packages/api/src/derive/democracy/referendumIds.ts b/packages/api-derive/src/democracy/referendumIds.ts similarity index 85% rename from packages/api/src/derive/democracy/referendumIds.ts rename to packages/api-derive/src/democracy/referendumIds.ts index f086af5c76..36ee1ac8f1 100644 --- a/packages/api/src/derive/democracy/referendumIds.ts +++ b/packages/api-derive/src/democracy/referendumIds.ts @@ -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 { +export function referendumIds (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.query.democracy?.lowestUnbaked ? api.queryMulti<[ReferendumIndex, ReferendumIndex]>([ diff --git a/packages/api/src/derive/democracy/referendums.ts b/packages/api-derive/src/democracy/referendums.ts similarity index 78% rename from packages/api/src/derive/democracy/referendums.ts rename to packages/api-derive/src/democracy/referendums.ts index e756a39e04..559d55ae5a 100644 --- a/packages/api/src/derive/democracy/referendums.ts +++ b/packages/api-derive/src/democracy/referendums.ts @@ -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 { +export function referendums (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.derive.democracy.referendumsActive().pipe( switchMap((referendums) => diff --git a/packages/api/src/derive/democracy/referendumsActive.ts b/packages/api-derive/src/democracy/referendumsActive.ts similarity index 69% rename from packages/api/src/derive/democracy/referendumsActive.ts rename to packages/api-derive/src/democracy/referendumsActive.ts index 622224bcb7..e35211fc8d 100644 --- a/packages/api/src/derive/democracy/referendumsActive.ts +++ b/packages/api-derive/src/democracy/referendumsActive.ts @@ -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 { +export function referendumsActive (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.derive.democracy.referendumIds().pipe( switchMap((ids): Observable => diff --git a/packages/api/src/derive/democracy/referendumsFinished.ts b/packages/api-derive/src/democracy/referendumsFinished.ts similarity index 77% rename from packages/api/src/derive/democracy/referendumsFinished.ts rename to packages/api-derive/src/democracy/referendumsFinished.ts index a4bfa474f2..7b45831f64 100644 --- a/packages/api/src/derive/democracy/referendumsFinished.ts +++ b/packages/api-derive/src/democracy/referendumsFinished.ts @@ -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 { +export function referendumsFinished (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => 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) ) diff --git a/packages/api/src/derive/democracy/referendumsInfo.ts b/packages/api-derive/src/democracy/referendumsInfo.ts similarity index 84% rename from packages/api/src/derive/democracy/referendumsInfo.ts rename to packages/api-derive/src/democracy/referendumsInfo.ts index a1b06cd6cc..ab8ea0147d 100644 --- a/packages/api/src/derive/democracy/referendumsInfo.ts +++ b/packages/api-derive/src/democracy/referendumsInfo.ts @@ -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 { +function votesPrev (api: DeriveApi, referendumId: BN): Observable { return api.query.democracy.votersFor>(referendumId).pipe( switchMap((votersFor): Observable<[Vec, Vote[], DeriveBalancesAccount[]]> => combineLatest([ @@ -70,7 +69,7 @@ function extractVotes (mapped: [AccountId, PalletDemocracyVoteVoting][], referen ); } -function votesCurr (api: ApiInterfaceRx, referendumId: BN): Observable { +function votesCurr (api: DeriveApi, referendumId: BN): Observable { 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 Observable { +export function _referendumVotes (instanceId: string, api: DeriveApi): (referendum: DeriveReferendum) => Observable { return memo(instanceId, (referendum: DeriveReferendum): Observable => 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 { +export function _referendumsVotes (instanceId: string, api: DeriveApi): (referendums: DeriveReferendum[]) => Observable { return memo(instanceId, (referendums: DeriveReferendum[]): Observable => 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) => Observable { +export function _referendumInfo (instanceId: string, api: DeriveApi): (index: BN, info: Option) => Observable { return memo(instanceId, (index: BN, info: Option): Observable => { 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 { +export function referendumsInfo (instanceId: string, api: DeriveApi): (ids: BN[]) => Observable { return memo(instanceId, (ids: BN[]): Observable => ids.length ? api.query.democracy.referendumInfoOf.multi(ids).pipe( diff --git a/packages/api/src/derive/democracy/sqrtElectorate.ts b/packages/api-derive/src/democracy/sqrtElectorate.ts similarity index 65% rename from packages/api/src/derive/democracy/sqrtElectorate.ts rename to packages/api-derive/src/democracy/sqrtElectorate.ts index 36c25f7f8f..04e845321a 100644 --- a/packages/api/src/derive/democracy/sqrtElectorate.ts +++ b/packages/api-derive/src/democracy/sqrtElectorate.ts @@ -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 { +export function sqrtElectorate (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.query.balances.totalIssuance().pipe( - map((totalIssuance) => - bnSqrt(totalIssuance) - ) + map(bnSqrt) ) ); } diff --git a/packages/api/src/derive/democracy/types.ts b/packages/api-derive/src/democracy/types.ts similarity index 100% rename from packages/api/src/derive/democracy/types.ts rename to packages/api-derive/src/democracy/types.ts diff --git a/packages/api/src/derive/democracy/util.ts b/packages/api-derive/src/democracy/util.ts similarity index 89% rename from packages/api/src/derive/democracy/util.ts rename to packages/api-derive/src/democracy/util.ts index 4843f38bab..0baf037309 100644 --- a/packages/api/src/derive/democracy/util.ts +++ b/packages/api-derive/src/democracy/util.ts @@ -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 | Option): imageOpt is Option { +function isCurrentPreimage (api: DeriveApi, imageOpt: Option | Option): imageOpt is Option { return !!imageOpt && !api.query.democracy.dispatchQueue; } @@ -152,7 +151,7 @@ export function getStatus (info: Option | Option): DeriveProposalImage | undefined { +export function parseImage (api: DeriveApi, imageOpt: Option | Option): DeriveProposalImage | undefined { if (imageOpt.isNone) { return; } diff --git a/packages/api/src/derive/derive.ts b/packages/api-derive/src/derive.ts similarity index 91% rename from packages/api/src/derive/derive.ts rename to packages/api-derive/src/derive.ts index 88471fb0de..7af6b3157e 100644 --- a/packages/api/src/derive/derive.ts +++ b/packages/api-derive/src/derive.ts @@ -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 = { [S in keyof AllSections]: DeriveSection }; -type DeriveCreator = (instanceId: string, api: ApiInterfaceRx) => (...args: unknown[]) => Observable; +type DeriveCreator = (instanceId: string, api: unknown) => (...args: unknown[]) => Observable; export type DeriveCustom = Record>; diff --git a/packages/api-derive/src/detectPackage.ts b/packages/api-derive/src/detectPackage.ts index d52fdd0b61..8f08383acb 100644 --- a/packages/api-derive/src/detectPackage.ts +++ b/packages/api-derive/src/detectPackage.ts @@ -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, []); diff --git a/packages/api/src/derive/elections/index.ts b/packages/api-derive/src/elections/index.ts similarity index 100% rename from packages/api/src/derive/elections/index.ts rename to packages/api-derive/src/elections/index.ts diff --git a/packages/api/src/derive/elections/info.ts b/packages/api-derive/src/elections/info.ts similarity index 91% rename from packages/api/src/derive/elections/info.ts rename to packages/api-derive/src/elections/info.ts index 0edc0825ea..0fce2d8155 100644 --- a/packages/api/src/derive/elections/info.ts +++ b/packages/api-derive/src/elections/info.ts @@ -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 { +function getConstants (api: DeriveApi, elections: string | null): Partial { return elections ? { candidacyBond: api.consts[elections].candidacyBond as Balance, @@ -54,7 +54,7 @@ function getConstants (api: ApiInterfaceRx, elections: string | null): Partial Observable { +export function info (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => { const [council, elections] = getModules(api); diff --git a/packages/api/src/derive/elections/types.ts b/packages/api-derive/src/elections/types.ts similarity index 100% rename from packages/api/src/derive/elections/types.ts rename to packages/api-derive/src/elections/types.ts diff --git a/packages/api/src/derive/imOnline/index.ts b/packages/api-derive/src/imOnline/index.ts similarity index 100% rename from packages/api/src/derive/imOnline/index.ts rename to packages/api-derive/src/imOnline/index.ts diff --git a/packages/api/src/derive/imOnline/receivedHeartbeats.ts b/packages/api-derive/src/imOnline/receivedHeartbeats.ts similarity index 90% rename from packages/api/src/derive/imOnline/receivedHeartbeats.ts rename to packages/api-derive/src/imOnline/receivedHeartbeats.ts index 48ed15e68b..9eec8935c9 100644 --- a/packages/api/src/derive/imOnline/receivedHeartbeats.ts +++ b/packages/api-derive/src/imOnline/receivedHeartbeats.ts @@ -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 { +export function receivedHeartbeats (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.query.imOnline?.receivedHeartbeats ? api.derive.staking.overview().pipe( diff --git a/packages/api/src/derive/index.spec.ts b/packages/api-derive/src/index.spec.ts similarity index 98% rename from packages/api/src/derive/index.spec.ts rename to packages/api-derive/src/index.spec.ts index db9176f710..b67506f687 100644 --- a/packages/api/src/derive/index.spec.ts +++ b/packages/api-derive/src/index.spec.ts @@ -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 => { diff --git a/packages/api/src/derive/membership/index.ts b/packages/api-derive/src/membership/index.ts similarity index 100% rename from packages/api/src/derive/membership/index.ts rename to packages/api-derive/src/membership/index.ts diff --git a/packages/api/src/derive/parachains/index.ts b/packages/api-derive/src/parachains/index.ts similarity index 100% rename from packages/api/src/derive/parachains/index.ts rename to packages/api-derive/src/parachains/index.ts diff --git a/packages/api/src/derive/parachains/info.ts b/packages/api-derive/src/parachains/info.ts similarity index 90% rename from packages/api/src/derive/parachains/info.ts rename to packages/api-derive/src/parachains/info.ts index d347118a22..d2fefa88d4 100644 --- a/packages/api/src/derive/parachains/info.ts +++ b/packages/api-derive/src/parachains/info.ts @@ -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 { +export function info (instanceId: string, api: DeriveApi): (id: ParaId | number) => Observable { return memo(instanceId, (id: ParaId | number): Observable => api.query.registrar && api.query.parachains ? api.queryMulti([ diff --git a/packages/api/src/derive/parachains/overview.ts b/packages/api-derive/src/parachains/overview.ts similarity index 87% rename from packages/api/src/derive/parachains/overview.ts rename to packages/api-derive/src/parachains/overview.ts index bd570cfec1..7865ee0c8c 100644 --- a/packages/api/src/derive/parachains/overview.ts +++ b/packages/api-derive/src/parachains/overview.ts @@ -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 { +export function overview (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.query.registrar?.parachains && api.query.parachains ? api.query.registrar.parachains().pipe( diff --git a/packages/api/src/derive/parachains/types.ts b/packages/api-derive/src/parachains/types.ts similarity index 100% rename from packages/api/src/derive/parachains/types.ts rename to packages/api-derive/src/parachains/types.ts diff --git a/packages/api/src/derive/parachains/util.ts b/packages/api-derive/src/parachains/util.ts similarity index 100% rename from packages/api/src/derive/parachains/util.ts rename to packages/api-derive/src/parachains/util.ts diff --git a/packages/api/src/derive/session/index.ts b/packages/api-derive/src/session/index.ts similarity index 100% rename from packages/api/src/derive/session/index.ts rename to packages/api-derive/src/session/index.ts diff --git a/packages/api/src/derive/session/indexes.ts b/packages/api-derive/src/session/indexes.ts similarity index 82% rename from packages/api/src/derive/session/indexes.ts rename to packages/api-derive/src/session/indexes.ts index 6abf3f2ab7..e05ca53a58 100644 --- a/packages/api/src/derive/session/indexes.ts +++ b/packages/api-derive/src/session/indexes.ts @@ -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 { +function queryStaking (api: DeriveApi): Observable { return api.queryMulti<[SessionIndex, Option, Option, u32]>([ api.query.session.currentIndex, api.query.staking.activeEra, @@ -45,7 +44,7 @@ function queryStaking (api: ApiInterfaceRx): Observable { } // query based on latest -function querySession (api: ApiInterfaceRx): Observable { +function querySession (api: DeriveApi): Observable { return api.query.session.currentIndex().pipe( map((currentIndex): DeriveSessionIndexes => parse([ currentIndex, @@ -58,7 +57,7 @@ function querySession (api: ApiInterfaceRx): Observable { } // empty set when none is available -function empty (api: ApiInterfaceRx): Observable { +function empty (api: DeriveApi): Observable { return of(parse([ api.registry.createType('SessionIndex', 1), api.registry.createType('EraIndex'), @@ -68,7 +67,7 @@ function empty (api: ApiInterfaceRx): Observable { ])); } -export function indexes (instanceId: string, api: ApiInterfaceRx): () => Observable { +export function indexes (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.query.session ? api.query.staking diff --git a/packages/api/src/derive/session/info.ts b/packages/api-derive/src/session/info.ts similarity index 82% rename from packages/api/src/derive/session/info.ts rename to packages/api-derive/src/session/info.ts index cc1e9274f3..c7e5c94e99 100644 --- a/packages/api/src/derive/session/info.ts +++ b/packages/api-derive/src/session/info.ts @@ -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 { +export function info (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.derive.session.indexes().pipe( map((indexes) => { diff --git a/packages/api/src/derive/session/progress.ts b/packages/api-derive/src/session/progress.ts similarity index 80% rename from packages/api/src/derive/session/progress.ts rename to packages/api-derive/src/session/progress.ts index 5547e4fafd..a992495348 100644 --- a/packages/api/src/derive/session/progress.ts +++ b/packages/api-derive/src/session/progress.ts @@ -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]; type ResultSlotsFlat = [u64, u64, u64, SessionIndex]; -function withProgressField (field: 'eraLength' | 'eraProgress' | 'sessionProgress'): (instanceId: string, api: ApiInterfaceRx) => () => Observable { - return (instanceId: string, api: ApiInterfaceRx) => +function withProgressField (field: 'eraLength' | 'eraProgress' | 'sessionProgress'): (instanceId: string, api: DeriveApi) => () => Observable { + return (instanceId: string, api: DeriveApi) => memo(instanceId, (): Observable => 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 { +function queryAura (api: DeriveApi): Observable { return api.derive.session.info().pipe( map((info): DeriveSessionProgress => ({ ...info, @@ -46,7 +45,7 @@ function queryAura (api: ApiInterfaceRx): Observable { ); } -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 { +export function progress (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.query.babe ? queryBabe(api).pipe( diff --git a/packages/api/src/derive/session/types.ts b/packages/api-derive/src/session/types.ts similarity index 100% rename from packages/api/src/derive/session/types.ts rename to packages/api-derive/src/session/types.ts diff --git a/packages/api/src/derive/society/candidates.ts b/packages/api-derive/src/society/candidates.ts similarity index 82% rename from packages/api/src/derive/society/candidates.ts rename to packages/api-derive/src/society/candidates.ts index 01bb063cda..b140a2f644 100644 --- a/packages/api/src/derive/society/candidates.ts +++ b/packages/api-derive/src/society/candidates.ts @@ -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 { +export function candidates (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.query.society.candidates().pipe( switchMap((candidates): Observable => diff --git a/packages/api/src/derive/society/index.ts b/packages/api-derive/src/society/index.ts similarity index 100% rename from packages/api/src/derive/society/index.ts rename to packages/api-derive/src/society/index.ts diff --git a/packages/api/src/derive/society/info.ts b/packages/api-derive/src/society/info.ts similarity index 86% rename from packages/api/src/derive/society/info.ts rename to packages/api-derive/src/society/info.ts index a67d0eb909..e37a317074 100644 --- a/packages/api/src/derive/society/info.ts +++ b/packages/api-derive/src/society/info.ts @@ -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, Option, Option, Opti /** * @description Get the overall info for a society */ -export function info (instanceId: string, api: ApiInterfaceRx): () => Observable { +export function info (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.queryMulti([ api.query.society.bids, diff --git a/packages/api/src/derive/society/member.ts b/packages/api-derive/src/society/member.ts similarity index 68% rename from packages/api/src/derive/society/member.ts rename to packages/api-derive/src/society/member.ts index 1bece7ba0e..7a0581ab9f 100644 --- a/packages/api/src/derive/society/member.ts +++ b/packages/api-derive/src/society/member.ts @@ -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 { +export function member (instanceId: string, api: DeriveApi): (accountId: AccountId) => Observable { return memo(instanceId, (accountId: AccountId): Observable => api.derive.society._members([accountId]).pipe( map(([result]) => result) diff --git a/packages/api/src/derive/society/members.ts b/packages/api-derive/src/society/members.ts similarity index 77% rename from packages/api/src/derive/society/members.ts rename to packages/api-derive/src/society/members.ts index a2830772ef..142a7ce8bc 100644 --- a/packages/api/src/derive/society/members.ts +++ b/packages/api-derive/src/society/members.ts @@ -3,14 +3,13 @@ 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 { combineLatest, map, of, switchMap } from 'rxjs'; import { memo } from '../util'; -export function _members (instanceId: string, api: ApiInterfaceRx): (accountIds: AccountId[]) => Observable { +export function _members (instanceId: string, api: DeriveApi): (accountIds: AccountId[]) => Observable { return memo(instanceId, (accountIds: AccountId[]): Observable => combineLatest([ of(accountIds), @@ -38,9 +37,9 @@ export function _members (instanceId: string, api: ApiInterfaceRx): (accountIds: /** * @description Get the member info for a society */ -export function members (instanceId: string, api: ApiInterfaceRx): () => Observable { +export function members (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => - api.query.society.members().pipe( + api.query.society.members().pipe( switchMap((members) => api.derive.society._members(members)) ) ); diff --git a/packages/api/src/derive/society/types.ts b/packages/api-derive/src/society/types.ts similarity index 100% rename from packages/api/src/derive/society/types.ts rename to packages/api-derive/src/society/types.ts diff --git a/packages/api/src/derive/staking/account.ts b/packages/api-derive/src/staking/account.ts similarity index 76% rename from packages/api/src/derive/staking/account.ts rename to packages/api-derive/src/staking/account.ts index 61852a5b89..81e1800ff8 100644 --- a/packages/api/src/derive/staking/account.ts +++ b/packages/api-derive/src/staking/account.ts @@ -4,8 +4,7 @@ import type { Observable } from 'rxjs'; import type { Balance } from '@polkadot/types/interfaces'; import type { PalletStakingStakingLedger, PalletStakingUnlockChunk } from '@polkadot/types/lookup'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveSessionInfo, DeriveStakingAccount, DeriveStakingKeys, DeriveStakingQuery, DeriveUnlocking } from '../types'; +import type { DeriveApi, DeriveSessionInfo, DeriveStakingAccount, DeriveStakingKeys, DeriveStakingQuery, DeriveUnlocking } from '../types'; import { combineLatest, map, switchMap } from 'rxjs'; @@ -30,7 +29,7 @@ function groupByEra (list: PalletStakingUnlockChunk[]): Record { }, {}); } -function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: PalletStakingStakingLedger | undefined, sessionInfo: DeriveSessionInfo): DeriveUnlocking[] | undefined { +function calculateUnlocking (api: DeriveApi, stakingLedger: PalletStakingStakingLedger | undefined, sessionInfo: DeriveSessionInfo): DeriveUnlocking[] | undefined { const results = Object .entries(groupByEra( (stakingLedger?.unlocking || []).filter(({ era }) => era.unwrap().gt(sessionInfo.activeEra)) @@ -45,7 +44,7 @@ function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: PalletStakingSt : undefined; } -function redeemableSum (api: ApiInterfaceRx, stakingLedger: PalletStakingStakingLedger | undefined, sessionInfo: DeriveSessionInfo): Balance { +function redeemableSum (api: DeriveApi, stakingLedger: PalletStakingStakingLedger | undefined, sessionInfo: DeriveSessionInfo): Balance { return api.registry.createType('Balance', (stakingLedger?.unlocking || [] as PalletStakingUnlockChunk[]).reduce((total, { era, value }): BN => { return sessionInfo.activeEra.gte(era.unwrap()) ? total.iadd(value.unwrap()) @@ -53,7 +52,7 @@ function redeemableSum (api: ApiInterfaceRx, stakingLedger: PalletStakingStaking }, new BN(0))); } -function parseResult (api: ApiInterfaceRx, sessionInfo: DeriveSessionInfo, keys: DeriveStakingKeys, query: DeriveStakingQuery): DeriveStakingAccount { +function parseResult (api: DeriveApi, sessionInfo: DeriveSessionInfo, keys: DeriveStakingKeys, query: DeriveStakingQuery): DeriveStakingAccount { return { ...keys, ...query, @@ -65,7 +64,7 @@ function parseResult (api: ApiInterfaceRx, sessionInfo: DeriveSessionInfo, keys: /** * @description From a list of stashes, fill in all the relevant staking details */ -export function accounts (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[]) => Observable { +export function accounts (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[]) => Observable { return memo(instanceId, (accountIds: (Uint8Array | string)[]): Observable => api.derive.session.info().pipe( switchMap((sessionInfo) => @@ -86,6 +85,6 @@ export function accounts (instanceId: string, api: ApiInterfaceRx): (accountIds: * @description From a stash, retrieve the controllerId and fill in all the relevant staking details */ export const account = firstMemo( - (api: ApiInterfaceRx, accountId: Uint8Array | string) => + (api: DeriveApi, accountId: Uint8Array | string) => api.derive.staking.accounts([accountId]) ); diff --git a/packages/api/src/derive/staking/cache.ts b/packages/api-derive/src/staking/cache.ts similarity index 100% rename from packages/api/src/derive/staking/cache.ts rename to packages/api-derive/src/staking/cache.ts diff --git a/packages/api/src/derive/staking/currentPoints.ts b/packages/api-derive/src/staking/currentPoints.ts similarity index 68% rename from packages/api/src/derive/staking/currentPoints.ts rename to packages/api-derive/src/staking/currentPoints.ts index 2697acf62e..b39db48eb6 100644 --- a/packages/api/src/derive/staking/currentPoints.ts +++ b/packages/api-derive/src/staking/currentPoints.ts @@ -3,7 +3,7 @@ import type { Observable } from 'rxjs'; import type { PalletStakingEraRewardPoints } from '@polkadot/types/lookup'; -import type { ApiInterfaceRx } from '../../types'; +import type { DeriveApi } from '../types'; import { switchMap } from 'rxjs'; @@ -12,11 +12,11 @@ import { memo } from '../util'; /** * @description Retrieve the staking overview, including elected and points earned */ -export function currentPoints (instanceId: string, api: ApiInterfaceRx): () => Observable { +export function currentPoints (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.derive.session.indexes().pipe( switchMap(({ activeEra }) => - api.query.staking.erasRewardPoints(activeEra) + api.query.staking.erasRewardPoints(activeEra) ) )); } diff --git a/packages/api/src/derive/staking/electedInfo.ts b/packages/api-derive/src/staking/electedInfo.ts similarity index 80% rename from packages/api/src/derive/staking/electedInfo.ts rename to packages/api-derive/src/staking/electedInfo.ts index 425a34c6df..cfdc5ac7b6 100644 --- a/packages/api/src/derive/staking/electedInfo.ts +++ b/packages/api-derive/src/staking/electedInfo.ts @@ -3,8 +3,7 @@ import type { Observable } from 'rxjs'; import type { AccountId } from '@polkadot/types/interfaces'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveStakingElected, StakingQueryFlags } from '../types'; +import type { DeriveApi, DeriveStakingElected, StakingQueryFlags } from '../types'; import { map, switchMap } from 'rxjs'; @@ -18,7 +17,7 @@ function combineAccounts (nextElected: AccountId[], validators: AccountId[]): Ac return arrayFlatten([nextElected, validators.filter((v) => !nextElected.find((n) => n.eq(v)))]); } -export function electedInfo (instanceId: string, api: ApiInterfaceRx): (flags?: StakingQueryFlags) => Observable { +export function electedInfo (instanceId: string, api: DeriveApi): (flags?: StakingQueryFlags) => Observable { return memo(instanceId, (flags: StakingQueryFlags = DEFAULT_FLAGS): Observable => api.derive.staking.validators().pipe( switchMap(({ nextElected, validators }): Observable => diff --git a/packages/api/src/derive/staking/erasExposure.ts b/packages/api-derive/src/staking/erasExposure.ts similarity index 85% rename from packages/api/src/derive/staking/erasExposure.ts rename to packages/api-derive/src/staking/erasExposure.ts index 081e279a80..032f975253 100644 --- a/packages/api/src/derive/staking/erasExposure.ts +++ b/packages/api-derive/src/staking/erasExposure.ts @@ -5,8 +5,7 @@ import type { Observable } from 'rxjs'; import type { StorageKey } from '@polkadot/types'; import type { AccountId, EraIndex } from '@polkadot/types/interfaces'; import type { PalletStakingExposure } from '@polkadot/types/lookup'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveEraExposure, DeriveEraNominatorExposure, DeriveEraValidatorExposure } from '../types'; +import type { DeriveApi, DeriveEraExposure, DeriveEraNominatorExposure, DeriveEraValidatorExposure } from '../types'; import { map, of } from 'rxjs'; @@ -38,7 +37,7 @@ function mapStakers (era: EraIndex, stakers: KeysAndExposures): DeriveEraExposur return { era, nominators, validators }; } -export function _eraExposure (instanceId: string, api: ApiInterfaceRx): (era: EraIndex, withActive?: boolean) => Observable { +export function _eraExposure (instanceId: string, api: DeriveApi): (era: EraIndex, withActive?: boolean) => Observable { return memo(instanceId, (era: EraIndex, withActive = false): Observable => { const [cacheKey, cached] = getEraCache(CACHE_KEY, era, withActive); diff --git a/packages/api/src/derive/staking/erasHistoric.ts b/packages/api-derive/src/staking/erasHistoric.ts similarity index 87% rename from packages/api/src/derive/staking/erasHistoric.ts rename to packages/api-derive/src/staking/erasHistoric.ts index 40ff4140f4..2f225a9940 100644 --- a/packages/api/src/derive/staking/erasHistoric.ts +++ b/packages/api-derive/src/staking/erasHistoric.ts @@ -5,7 +5,7 @@ import type { Observable } from 'rxjs'; import type { Option, u32 } from '@polkadot/types'; import type { ActiveEraInfo, EraIndex } from '@polkadot/types/interfaces'; import type { BN } from '@polkadot/util'; -import type { ApiInterfaceRx } from '../../types'; +import type { DeriveApi } from '../types'; import { map } from 'rxjs'; @@ -13,7 +13,7 @@ import { BN_ONE, BN_ZERO } from '@polkadot/util'; import { memo } from '../util'; -export function erasHistoric (instanceId: string, api: ApiInterfaceRx): (withActive?: boolean) => Observable { +export function erasHistoric (instanceId: string, api: DeriveApi): (withActive?: boolean) => Observable { return memo(instanceId, (withActive?: boolean): Observable => api.queryMulti<[Option, u32]>([ api.query.staking.activeEra, diff --git a/packages/api/src/derive/staking/erasPoints.ts b/packages/api-derive/src/staking/erasPoints.ts similarity index 86% rename from packages/api/src/derive/staking/erasPoints.ts rename to packages/api-derive/src/staking/erasPoints.ts index 23bff45a3e..d33f35c2b5 100644 --- a/packages/api/src/derive/staking/erasPoints.ts +++ b/packages/api-derive/src/staking/erasPoints.ts @@ -4,8 +4,7 @@ import type { Observable } from 'rxjs'; import type { EraIndex } from '@polkadot/types/interfaces'; import type { PalletStakingEraRewardPoints } from '@polkadot/types/lookup'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveEraPoints, DeriveEraValPoints } from '../types'; +import type { DeriveApi, DeriveEraPoints, DeriveEraValPoints } from '../types'; import { map, of } from 'rxjs'; @@ -35,7 +34,7 @@ function mapPoints (eras: EraIndex[], points: PalletStakingEraRewardPoints[]): D })); } -export function _erasPoints (instanceId: string, api: ApiInterfaceRx): (eras: EraIndex[], withActive: boolean) => Observable { +export function _erasPoints (instanceId: string, api: DeriveApi): (eras: EraIndex[], withActive: boolean) => Observable { return memo(instanceId, (eras: EraIndex[], withActive: boolean): Observable => { if (!eras.length) { return of([]); diff --git a/packages/api/src/derive/staking/erasPrefs.ts b/packages/api-derive/src/staking/erasPrefs.ts similarity index 84% rename from packages/api/src/derive/staking/erasPrefs.ts rename to packages/api-derive/src/staking/erasPrefs.ts index 7af072da75..1fb827a139 100644 --- a/packages/api/src/derive/staking/erasPrefs.ts +++ b/packages/api-derive/src/staking/erasPrefs.ts @@ -5,8 +5,7 @@ import type { Observable } from 'rxjs'; import type { StorageKey } from '@polkadot/types'; import type { EraIndex } from '@polkadot/types/interfaces'; import type { PalletStakingValidatorPrefs } from '@polkadot/types/lookup'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveEraPrefs, DeriveEraValPrefs } from '../types'; +import type { DeriveApi, DeriveEraPrefs, DeriveEraValPrefs } from '../types'; import { map, of } from 'rxjs'; @@ -26,7 +25,7 @@ function mapPrefs (era: EraIndex, all: [StorageKey, PalletStakingValidatorPrefs] return { era, validators }; } -export function _eraPrefs (instanceId: string, api: ApiInterfaceRx): (era: EraIndex, withActive: boolean) => Observable { +export function _eraPrefs (instanceId: string, api: DeriveApi): (era: EraIndex, withActive: boolean) => Observable { return memo(instanceId, (era: EraIndex, withActive: boolean): Observable => { const [cacheKey, cached] = getEraCache(CACHE_KEY, era, withActive); diff --git a/packages/api/src/derive/staking/erasRewards.ts b/packages/api-derive/src/staking/erasRewards.ts similarity index 84% rename from packages/api/src/derive/staking/erasRewards.ts rename to packages/api-derive/src/staking/erasRewards.ts index 2444193abb..8352c4fb21 100644 --- a/packages/api/src/derive/staking/erasRewards.ts +++ b/packages/api-derive/src/staking/erasRewards.ts @@ -4,8 +4,7 @@ import type { Observable } from 'rxjs'; import type { Option } from '@polkadot/types'; import type { Balance, EraIndex } from '@polkadot/types/interfaces'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveEraRewards } from '../types'; +import type { DeriveApi, DeriveEraRewards } from '../types'; import { map, of } from 'rxjs'; @@ -22,7 +21,7 @@ function mapRewards (eras: EraIndex[], optRewards: Option[]): DeriveEra })); } -export function _erasRewards (instanceId: string, api: ApiInterfaceRx): (eras: EraIndex[], withActive: boolean) => Observable { +export function _erasRewards (instanceId: string, api: DeriveApi): (eras: EraIndex[], withActive: boolean) => Observable { return memo(instanceId, (eras: EraIndex[], withActive: boolean): Observable => { if (!eras.length) { return of([]); diff --git a/packages/api/src/derive/staking/erasSlashes.ts b/packages/api-derive/src/staking/erasSlashes.ts similarity index 86% rename from packages/api/src/derive/staking/erasSlashes.ts rename to packages/api-derive/src/staking/erasSlashes.ts index 3e036ad214..7a82810a24 100644 --- a/packages/api/src/derive/staking/erasSlashes.ts +++ b/packages/api-derive/src/staking/erasSlashes.ts @@ -5,8 +5,7 @@ import type { Observable } from 'rxjs'; import type { Option, StorageKey } from '@polkadot/types'; import type { BalanceOf, EraIndex, Perbill } from '@polkadot/types/interfaces'; import type { ITuple } from '@polkadot/types/types'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveEraSlashes, DeriveEraValSlash } from '../types'; +import type { DeriveApi, DeriveEraSlashes, DeriveEraValSlash } from '../types'; import { combineLatest, map, of } from 'rxjs'; @@ -31,7 +30,7 @@ function mapSlashes (era: EraIndex, noms: [StorageKey, Option][], val return { era, nominators, validators }; } -export function _eraSlashes (instanceId: string, api: ApiInterfaceRx): (era: EraIndex, withActive: boolean) => Observable { +export function _eraSlashes (instanceId: string, api: DeriveApi): (era: EraIndex, withActive: boolean) => Observable { return memo(instanceId, (era: EraIndex, withActive: boolean): Observable => { const [cacheKey, cached] = getEraCache(CACHE_KEY, era, withActive); diff --git a/packages/api/src/derive/staking/index.ts b/packages/api-derive/src/staking/index.ts similarity index 100% rename from packages/api/src/derive/staking/index.ts rename to packages/api-derive/src/staking/index.ts diff --git a/packages/api/src/derive/staking/keys.ts b/packages/api-derive/src/staking/keys.ts similarity index 88% rename from packages/api/src/derive/staking/keys.ts rename to packages/api-derive/src/staking/keys.ts index d0a2338843..9311156043 100644 --- a/packages/api/src/derive/staking/keys.ts +++ b/packages/api-derive/src/staking/keys.ts @@ -6,7 +6,7 @@ import type { Option, Vec } from '@polkadot/types'; import type { AccountId } from '@polkadot/types/interfaces'; import type { NodeRuntimeSessionKeys } from '@polkadot/types/lookup'; import type { ITuple } from '@polkadot/types/types'; -import type { ApiInterfaceRx } from '../../types'; +import type { DeriveApi } from '../types'; import type { DeriveStakingKeys } from './types'; import { combineLatest, map, of, switchMap } from 'rxjs'; @@ -28,11 +28,11 @@ function extractsIds (stashId: Uint8Array | string, queuedKeys: [AccountId, Node } export const keys = firstMemo( - (api: ApiInterfaceRx, stashId: Uint8Array | string) => + (api: DeriveApi, stashId: Uint8Array | string) => api.derive.staking.keysMulti([stashId]) ); -export function keysMulti (instanceId: string, api: ApiInterfaceRx): (stashIds: (Uint8Array | string)[]) => Observable { +export function keysMulti (instanceId: string, api: DeriveApi): (stashIds: (Uint8Array | string)[]) => Observable { return memo(instanceId, (stashIds: (Uint8Array | string)[]): Observable => stashIds.length ? api.query.session.queuedKeys().pipe( diff --git a/packages/api/src/derive/staking/overview.ts b/packages/api-derive/src/staking/overview.ts similarity index 75% rename from packages/api/src/derive/staking/overview.ts rename to packages/api-derive/src/staking/overview.ts index 5e802cd2ab..7332d1a41d 100644 --- a/packages/api/src/derive/staking/overview.ts +++ b/packages/api-derive/src/staking/overview.ts @@ -2,8 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import type { Observable } from 'rxjs'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveStakingOverview } from '../types'; +import type { DeriveApi, DeriveStakingOverview } from '../types'; import { combineLatest, map } from 'rxjs'; @@ -12,7 +11,7 @@ import { memo } from '../util'; /** * @description Retrieve the staking overview, including elected and points earned */ -export function overview (instanceId: string, api: ApiInterfaceRx): () => Observable { +export function overview (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => combineLatest([ api.derive.session.indexes(), diff --git a/packages/api/src/derive/staking/ownExposure.ts b/packages/api-derive/src/staking/ownExposure.ts similarity index 76% rename from packages/api/src/derive/staking/ownExposure.ts rename to packages/api-derive/src/staking/ownExposure.ts index 469874b595..cc51baabab 100644 --- a/packages/api/src/derive/staking/ownExposure.ts +++ b/packages/api-derive/src/staking/ownExposure.ts @@ -2,17 +2,17 @@ // SPDX-License-Identifier: Apache-2.0 import type { Observable } from 'rxjs'; +import type { QueryableStorageMultiArg } from '@polkadot/api-base/types'; import type { EraIndex } from '@polkadot/types/interfaces'; import type { PalletStakingExposure } from '@polkadot/types/lookup'; -import type { ApiInterfaceRx, QueryableStorageMultiArg } from '../../types'; -import type { DeriveOwnExposure } from '../types'; +import type { DeriveApi, DeriveOwnExposure } from '../types'; import { map, of } from 'rxjs'; import { firstMemo, memo } from '../util'; import { erasHistoricApplyAccount } from './util'; -export function _ownExposures (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable { +export function _ownExposures (instanceId: string, api: DeriveApi): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable { // eslint-disable-next-line @typescript-eslint/no-unused-vars return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean): Observable => eras.length @@ -29,7 +29,7 @@ export function _ownExposures (instanceId: string, api: ApiInterfaceRx): (accoun } export const ownExposure = firstMemo( - (api: ApiInterfaceRx, accountId: Uint8Array | string, era: EraIndex) => + (api: DeriveApi, accountId: Uint8Array | string, era: EraIndex) => api.derive.staking._ownExposures(accountId, [era], true) ); diff --git a/packages/api/src/derive/staking/ownSlashes.ts b/packages/api-derive/src/staking/ownSlashes.ts similarity index 79% rename from packages/api/src/derive/staking/ownSlashes.ts rename to packages/api-derive/src/staking/ownSlashes.ts index 5554e1a652..26c2fe7af6 100644 --- a/packages/api/src/derive/staking/ownSlashes.ts +++ b/packages/api-derive/src/staking/ownSlashes.ts @@ -2,18 +2,18 @@ // SPDX-License-Identifier: Apache-2.0 import type { Observable } from 'rxjs'; +import type { QueryableStorageMultiArg } from '@polkadot/api-base/types'; import type { Option } from '@polkadot/types'; import type { BalanceOf, EraIndex, Perbill } from '@polkadot/types/interfaces'; import type { ITuple } from '@polkadot/types/types'; -import type { ApiInterfaceRx, QueryableStorageMultiArg } from '../../types'; -import type { DeriveStakerSlashes } from '../types'; +import type { DeriveApi, DeriveStakerSlashes } from '../types'; import { map, of } from 'rxjs'; import { firstMemo, memo } from '../util'; import { erasHistoricApplyAccount } from './util'; -export function _ownSlashes (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable { +export function _ownSlashes (instanceId: string, api: DeriveApi): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable { // eslint-disable-next-line @typescript-eslint/no-unused-vars return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean): Observable => eras.length @@ -35,7 +35,7 @@ export function _ownSlashes (instanceId: string, api: ApiInterfaceRx): (accountI } export const ownSlash = firstMemo( - (api: ApiInterfaceRx, accountId: Uint8Array | string, era: EraIndex) => + (api: DeriveApi, accountId: Uint8Array | string, era: EraIndex) => api.derive.staking._ownSlashes(accountId, [era], true) ); diff --git a/packages/api/src/derive/staking/query.ts b/packages/api-derive/src/staking/query.ts similarity index 77% rename from packages/api/src/derive/staking/query.ts rename to packages/api-derive/src/staking/query.ts index 2ef39359bd..3cf68b94a4 100644 --- a/packages/api/src/derive/staking/query.ts +++ b/packages/api-derive/src/staking/query.ts @@ -5,8 +5,7 @@ import type { Observable } from 'rxjs'; import type { Option } from '@polkadot/types'; import type { AccountId, EraIndex } from '@polkadot/types/interfaces'; import type { PalletStakingExposure, PalletStakingNominations, PalletStakingRewardDestination, PalletStakingStakingLedger, PalletStakingValidatorPrefs } from '@polkadot/types/lookup'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveStakingQuery, StakingQueryFlags } from '../types'; +import type { DeriveApi, DeriveStakingQuery, StakingQueryFlags } from '../types'; import { combineLatest, map, of, switchMap } from 'rxjs'; @@ -27,7 +26,7 @@ function parseDetails (stashId: AccountId, controllerIdOpt: Option | }; } -function getLedgers (api: ApiInterfaceRx, optIds: (Option | null)[], { withLedger = false }: StakingQueryFlags): Observable[]> { +function getLedgers (api: DeriveApi, optIds: (Option | null)[], { withLedger = false }: StakingQueryFlags): Observable[]> { const ids = optIds .filter((o): o is Option => withLedger && !!o && o.isSome) .map((o) => o.unwrap()); @@ -41,8 +40,8 @@ function getLedgers (api: ApiInterfaceRx, optIds: (Option | null)[], map((optLedgers): Option[] => { let offset = -1; - return optIds.map((opt): Option => - opt && opt.isSome + return optIds.map((o): Option => + o && o.isSome ? optLedgers[++offset] || emptyLed : emptyLed ); @@ -50,7 +49,7 @@ function getLedgers (api: ApiInterfaceRx, optIds: (Option | null)[], ); } -function getStashInfo (api: ApiInterfaceRx, stashIds: AccountId[], activeEra: EraIndex, { withController, withDestination, withExposure, withLedger, withNominations, withPrefs }: StakingQueryFlags): Observable<[(Option | null)[], Option[], PalletStakingRewardDestination[], PalletStakingValidatorPrefs[], PalletStakingExposure[]]> { +function getStashInfo (api: DeriveApi, stashIds: AccountId[], activeEra: EraIndex, { withController, withDestination, withExposure, withLedger, withNominations, withPrefs }: StakingQueryFlags): Observable<[(Option | null)[], Option[], PalletStakingRewardDestination[], PalletStakingValidatorPrefs[], PalletStakingExposure[]]> { const emptyNoms = api.registry.createType>('Option'); const emptyRewa = api.registry.createType('RewardDestination'); const emptyExpo = api.registry.createType('Exposure'); @@ -75,7 +74,7 @@ function getStashInfo (api: ApiInterfaceRx, stashIds: AccountId[], activeEra: Er ]); } -function getBatch (api: ApiInterfaceRx, activeEra: EraIndex, stashIds: AccountId[], flags: StakingQueryFlags): Observable { +function getBatch (api: DeriveApi, activeEra: EraIndex, stashIds: AccountId[], flags: StakingQueryFlags): Observable { return getStashInfo(api, stashIds, activeEra, flags).pipe( switchMap(([controllerIdOpt, nominatorsOpt, rewardDestination, validatorPrefs, exposure]): Observable => getLedgers(api, controllerIdOpt, flags).pipe( @@ -94,11 +93,11 @@ function getBatch (api: ApiInterfaceRx, activeEra: EraIndex, stashIds: AccountId * @description From a stash, retrieve the controllerId and all relevant details */ export const query = firstMemo( - (api: ApiInterfaceRx, accountId: Uint8Array | string, flags: StakingQueryFlags) => + (api: DeriveApi, accountId: Uint8Array | string, flags: StakingQueryFlags) => api.derive.staking.queryMulti([accountId], flags) ); -export function queryMulti (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], flags: StakingQueryFlags) => Observable { +export function queryMulti (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[], flags: StakingQueryFlags) => Observable { return memo(instanceId, (accountIds: (Uint8Array | string)[], flags: StakingQueryFlags): Observable => accountIds.length ? api.derive.session.indexes().pipe( diff --git a/packages/api/src/derive/staking/stakerExposure.ts b/packages/api-derive/src/staking/stakerExposure.ts similarity index 79% rename from packages/api/src/derive/staking/stakerExposure.ts rename to packages/api-derive/src/staking/stakerExposure.ts index 81c1fa445a..b467d155d9 100644 --- a/packages/api/src/derive/staking/stakerExposure.ts +++ b/packages/api-derive/src/staking/stakerExposure.ts @@ -3,14 +3,14 @@ import type { Observable } from 'rxjs'; import type { EraIndex } from '@polkadot/types/interfaces'; -import type { ApiInterfaceRx } from '../../types'; +import type { DeriveApi } from '../types'; import type { DeriveEraValidatorExposure, DeriveStakerExposure } from './types'; import { map, switchMap } from 'rxjs'; import { firstMemo, memo } from '../util'; -export function _stakerExposures (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive?: boolean) => Observable { +export function _stakerExposures (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive?: boolean) => Observable { return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive = false): Observable => { const stakerIds = accountIds.map((a) => api.registry.createType('AccountId', a).toString()); @@ -38,7 +38,7 @@ export function _stakerExposures (instanceId: string, api: ApiInterfaceRx): (acc }); } -export function stakerExposures (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], withActive?: boolean) => Observable { +export function stakerExposures (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[], withActive?: boolean) => Observable { return memo(instanceId, (accountIds: (Uint8Array | string)[], withActive = false): Observable => api.derive.staking.erasHistoric(withActive).pipe( switchMap((eras) => api.derive.staking._stakerExposures(accountIds, eras, withActive)) @@ -47,6 +47,6 @@ export function stakerExposures (instanceId: string, api: ApiInterfaceRx): (acco } export const stakerExposure = firstMemo( - (api: ApiInterfaceRx, accountId: Uint8Array | string, withActive?: boolean) => + (api: DeriveApi, accountId: Uint8Array | string, withActive?: boolean) => api.derive.staking.stakerExposures([accountId], withActive) ); diff --git a/packages/api/src/derive/staking/stakerPoints.ts b/packages/api-derive/src/staking/stakerPoints.ts similarity index 76% rename from packages/api/src/derive/staking/stakerPoints.ts rename to packages/api-derive/src/staking/stakerPoints.ts index db24abc3e6..c6015ea7c1 100644 --- a/packages/api/src/derive/staking/stakerPoints.ts +++ b/packages/api-derive/src/staking/stakerPoints.ts @@ -3,15 +3,14 @@ import type { Observable } from 'rxjs'; import type { EraIndex } from '@polkadot/types/interfaces'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveStakerPoints } from '../types'; +import type { DeriveApi, DeriveStakerPoints } from '../types'; import { map } from 'rxjs'; import { memo } from '../util'; import { erasHistoricApplyAccount } from './util'; -export function _stakerPoints (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable { +export function _stakerPoints (instanceId: string, api: DeriveApi): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable { return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean): Observable => { const stakerId = api.registry.createType('AccountId', accountId).toString(); diff --git a/packages/api/src/derive/staking/stakerPrefs.ts b/packages/api-derive/src/staking/stakerPrefs.ts similarity index 75% rename from packages/api/src/derive/staking/stakerPrefs.ts rename to packages/api-derive/src/staking/stakerPrefs.ts index 4a1ac9ec26..d816f38db3 100644 --- a/packages/api/src/derive/staking/stakerPrefs.ts +++ b/packages/api-derive/src/staking/stakerPrefs.ts @@ -3,15 +3,14 @@ import type { Observable } from 'rxjs'; import type { EraIndex } from '@polkadot/types/interfaces'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveStakerPrefs } from '../types'; +import type { DeriveApi, DeriveStakerPrefs } from '../types'; import { map } from 'rxjs'; import { memo } from '../util'; import { erasHistoricApplyAccount } from './util'; -export function _stakerPrefs (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable { +export function _stakerPrefs (instanceId: string, api: DeriveApi): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable { // eslint-disable-next-line @typescript-eslint/no-unused-vars return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], _withActive: boolean): Observable => api.query.staking.erasValidatorPrefs.multi(eras.map((e) => [e, accountId])).pipe( diff --git a/packages/api/src/derive/staking/stakerRewards.ts b/packages/api-derive/src/staking/stakerRewards.ts similarity index 86% rename from packages/api/src/derive/staking/stakerRewards.ts rename to packages/api-derive/src/staking/stakerRewards.ts index a0e32c820f..55d2a57cb3 100644 --- a/packages/api/src/derive/staking/stakerRewards.ts +++ b/packages/api-derive/src/staking/stakerRewards.ts @@ -5,8 +5,7 @@ import type { Observable } from 'rxjs'; import type { AccountId, EraIndex } from '@polkadot/types/interfaces'; import type { PalletStakingStakingLedger } from '@polkadot/types/lookup'; import type { BN } from '@polkadot/util'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveEraPoints, DeriveEraPrefs, DeriveEraRewards, DeriveEraValPrefs, DeriveStakerExposure, DeriveStakerReward, DeriveStakerRewardValidator } from '../types'; +import type { DeriveApi, DeriveEraPoints, DeriveEraPrefs, DeriveEraRewards, DeriveEraValPrefs, DeriveStakerExposure, DeriveStakerReward, DeriveStakerRewardValidator } from '../types'; import type { DeriveStakingQuery } from './types'; import { combineLatest, map, of, switchMap } from 'rxjs'; @@ -17,7 +16,7 @@ import { firstMemo, memo } from '../util'; type ErasResult = [DeriveEraPoints[], DeriveEraPrefs[], DeriveEraRewards[]]; -function parseRewards (api: ApiInterfaceRx, stashId: AccountId, [erasPoints, erasPrefs, erasRewards]: ErasResult, exposures: DeriveStakerExposure[]): DeriveStakerReward[] { +function parseRewards (api: DeriveApi, stashId: AccountId, [erasPoints, erasPrefs, erasRewards]: ErasResult, exposures: DeriveStakerExposure[]): DeriveStakerReward[] { return exposures.map(({ era, isEmpty, isValidator, nominating, validators: eraValidators }): DeriveStakerReward => { const { eraPoints, validators: allValPoints } = erasPoints.find((p) => p.era.eq(era)) || { eraPoints: BN_ZERO, validators: {} }; const { eraReward } = erasRewards.find((r) => r.era.eq(era)) || { eraReward: api.registry.createType('Balance') }; @@ -132,7 +131,7 @@ function filterRewards (eras: EraIndex[], valInfo: [string, DeriveStakingQuery][ })); } -export function _stakerRewardsEras (instanceId: string, api: ApiInterfaceRx): (eras: EraIndex[], withActive?: boolean) => Observable { +export function _stakerRewardsEras (instanceId: string, api: DeriveApi): (eras: EraIndex[], withActive?: boolean) => Observable { return memo(instanceId, (eras: EraIndex[], withActive = false): Observable => combineLatest([ api.derive.staking._erasPoints(eras, withActive), @@ -142,7 +141,7 @@ export function _stakerRewardsEras (instanceId: string, api: ApiInterfaceRx): (e ); } -export function _stakerRewards (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive?: boolean) => Observable { +export function _stakerRewards (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive?: boolean) => Observable { return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[], withActive = false): Observable => combineLatest([ api.derive.staking.queryMulti(accountIds, { withLedger: true }), @@ -185,13 +184,13 @@ export function _stakerRewards (instanceId: string, api: ApiInterfaceRx): (accou } export const stakerRewards = firstMemo( - (api: ApiInterfaceRx, accountId: Uint8Array | string, withActive?: boolean) => + (api: DeriveApi, accountId: Uint8Array | string, withActive?: boolean) => api.derive.staking.erasHistoric(withActive).pipe( switchMap((eras) => api.derive.staking._stakerRewards([accountId], eras, withActive)) ) ); -export function stakerRewardsMultiEras (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], eras: EraIndex[]) => Observable { +export function stakerRewardsMultiEras (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[], eras: EraIndex[]) => Observable { return memo(instanceId, (accountIds: (Uint8Array | string)[], eras: EraIndex[]): Observable => accountIds.length && eras.length ? api.derive.staking._stakerRewards(accountIds, eras, false) @@ -199,7 +198,7 @@ export function stakerRewardsMultiEras (instanceId: string, api: ApiInterfaceRx) ); } -export function stakerRewardsMulti (instanceId: string, api: ApiInterfaceRx): (accountIds: (Uint8Array | string)[], withActive?: boolean) => Observable { +export function stakerRewardsMulti (instanceId: string, api: DeriveApi): (accountIds: (Uint8Array | string)[], withActive?: boolean) => Observable { return memo(instanceId, (accountIds: (Uint8Array | string)[], withActive = false): Observable => api.derive.staking.erasHistoric(withActive).pipe( switchMap((eras) => api.derive.staking.stakerRewardsMultiEras(accountIds, eras)) diff --git a/packages/api/src/derive/staking/stakerSlashes.ts b/packages/api-derive/src/staking/stakerSlashes.ts similarity index 76% rename from packages/api/src/derive/staking/stakerSlashes.ts rename to packages/api-derive/src/staking/stakerSlashes.ts index 178fe6c437..c713fd30ec 100644 --- a/packages/api/src/derive/staking/stakerSlashes.ts +++ b/packages/api-derive/src/staking/stakerSlashes.ts @@ -3,15 +3,14 @@ import type { Observable } from 'rxjs'; import type { EraIndex } from '@polkadot/types/interfaces'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveStakerSlashes } from '../types'; +import type { DeriveApi, DeriveStakerSlashes } from '../types'; import { map } from 'rxjs'; import { memo } from '../util'; import { erasHistoricApplyAccount } from './util'; -export function _stakerSlashes (instanceId: string, api: ApiInterfaceRx): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable { +export function _stakerSlashes (instanceId: string, api: DeriveApi): (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean) => Observable { return memo(instanceId, (accountId: Uint8Array | string, eras: EraIndex[], withActive: boolean): Observable => { const stakerId = api.registry.createType('AccountId', accountId).toString(); diff --git a/packages/api/src/derive/staking/stashes.ts b/packages/api-derive/src/staking/stashes.ts similarity index 76% rename from packages/api/src/derive/staking/stashes.ts rename to packages/api-derive/src/staking/stashes.ts index 7576dffa35..de4027ace3 100644 --- a/packages/api/src/derive/staking/stashes.ts +++ b/packages/api-derive/src/staking/stashes.ts @@ -3,13 +3,13 @@ import type { Observable } from 'rxjs'; import type { AccountId } from '@polkadot/types/interfaces'; -import type { ApiInterfaceRx } from '../../types'; +import type { DeriveApi } from '../types'; import { map, startWith, switchMap } from 'rxjs'; import { drr, memo } from '../util'; -function onBondedEvent (api: ApiInterfaceRx): Observable { +function onBondedEvent (api: DeriveApi): Observable { let current = Date.now(); return api.query.system.events().pipe( @@ -36,11 +36,11 @@ function onBondedEvent (api: ApiInterfaceRx): Observable { /** * @description Retrieve the list of all validator stashes */ -export function stashes (instanceId: string, api: ApiInterfaceRx): () => Observable { +export function stashes (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => onBondedEvent(api).pipe( switchMap(() => api.query.staking.validators.keys()), - map((keys) => keys.map(({ args: [validatorId] }) => validatorId).filter((a) => a)) + map((keys) => keys.map(({ args: [v] }) => v).filter((a) => a)) ) ); } diff --git a/packages/api/src/derive/staking/types.ts b/packages/api-derive/src/staking/types.ts similarity index 100% rename from packages/api/src/derive/staking/types.ts rename to packages/api-derive/src/staking/types.ts diff --git a/packages/api/src/derive/staking/util.ts b/packages/api-derive/src/staking/util.ts similarity index 74% rename from packages/api/src/derive/staking/util.ts rename to packages/api-derive/src/staking/util.ts index 33b2d1b509..7d006105bf 100644 --- a/packages/api/src/derive/staking/util.ts +++ b/packages/api-derive/src/staking/util.ts @@ -2,9 +2,10 @@ // SPDX-License-Identifier: Apache-2.0 import type { Observable } from 'rxjs'; +import type { ObsInnerType } from '@polkadot/api-base/types'; import type { EraIndex } from '@polkadot/types/interfaces'; -import type { ApiInterfaceRx, ObsInnerType } from '../../types'; import type { ExactDerive } from '../derive'; +import type { DeriveApi } from '../types'; import { combineLatest, of, switchMap } from 'rxjs'; @@ -16,8 +17,8 @@ export function filterEras (eras: EraIndex[], list return eras.filter((e) => !list.some(({ era }) => e.eq(era))); } -export function erasHistoricApply (fn: F): (instanceId: string, api: ApiInterfaceRx) => (withActive?: boolean) => ApplyReturn { - return (instanceId: string, api: ApiInterfaceRx) => +export function erasHistoricApply (fn: F): (instanceId: string, api: DeriveApi) => (withActive?: boolean) => ApplyReturn { + return (instanceId: string, api: DeriveApi) => // Cannot quite get the typing right, but it is right in the code // eslint-disable-next-line @typescript-eslint/no-unsafe-return memo(instanceId, (withActive = false) => @@ -27,8 +28,8 @@ export function erasHistoricApply (fn: F): (instanceId: string, api: ApiInterfaceRx) => (accountId: string | Uint8Array, withActive?: boolean) => ApplyReturn { - return (instanceId: string, api: ApiInterfaceRx) => +export function erasHistoricApplyAccount (fn: F): (instanceId: string, api: DeriveApi) => (accountId: string | Uint8Array, withActive?: boolean) => ApplyReturn { + return (instanceId: string, api: DeriveApi) => // Cannot quite get the typing right, but it is right in the code // eslint-disable-next-line @typescript-eslint/no-unsafe-return memo(instanceId, (accountId: string | Uint8Array, withActive = false) => @@ -38,8 +39,8 @@ export function erasHistoricApplyAccount (fn: F): (instanceId: string, api: ApiInterfaceRx) => (era: EraIndex) => ApplyReturn { - return (instanceId: string, api: ApiInterfaceRx) => +export function singleEra (fn: F): (instanceId: string, api: DeriveApi) => (era: EraIndex) => ApplyReturn { + return (instanceId: string, api: DeriveApi) => // Cannot quite get the typing right, but it is right in the code // eslint-disable-next-line @typescript-eslint/no-unsafe-return memo(instanceId, (era: EraIndex) => @@ -47,8 +48,8 @@ export function singleEra (fn: F): (instanceId: string, api: ApiInterfaceRx) => (eras: EraIndex[], withActive: boolean) => Observable>[]> { - return (instanceId: string, api: ApiInterfaceRx) => +export function combineEras (fn: F): (instanceId: string, api: DeriveApi) => (eras: EraIndex[], withActive: boolean) => Observable>[]> { + return (instanceId: string, api: DeriveApi) => // Cannot quite get the typing right, but it is right in the code // eslint-disable-next-line @typescript-eslint/no-unsafe-return memo(instanceId, (eras: EraIndex[], withActive: boolean) => diff --git a/packages/api/src/derive/staking/validators.ts b/packages/api-derive/src/staking/validators.ts similarity index 83% rename from packages/api/src/derive/staking/validators.ts rename to packages/api-derive/src/staking/validators.ts index 2f048492e4..2e57a6145f 100644 --- a/packages/api/src/derive/staking/validators.ts +++ b/packages/api-derive/src/staking/validators.ts @@ -3,14 +3,13 @@ import type { Observable } from 'rxjs'; import type { AccountId } from '@polkadot/types/interfaces'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveStakingValidators } from '../types'; +import type { DeriveApi, DeriveStakingValidators } from '../types'; import { combineLatest, map, of, switchMap } from 'rxjs'; import { memo } from '../util'; -export function nextElected (instanceId: string, api: ApiInterfaceRx): () => Observable { +export function nextElected (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.query.staking.erasStakers ? api.derive.session.indexes().pipe( @@ -26,7 +25,7 @@ export function nextElected (instanceId: string, api: ApiInterfaceRx): () => Obs /** * @description Retrieve latest list of validators */ -export function validators (instanceId: string, api: ApiInterfaceRx): () => Observable { +export function validators (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => // Sadly the node-template is (for some obscure reason) not comprehensive, so while the derive works // in all actual real-world deployed chains, it does create some confusion for limited template chains diff --git a/packages/api/src/derive/staking/waitingInfo.ts b/packages/api-derive/src/staking/waitingInfo.ts similarity index 78% rename from packages/api/src/derive/staking/waitingInfo.ts rename to packages/api-derive/src/staking/waitingInfo.ts index 125cbc84b5..26c3e2793c 100644 --- a/packages/api/src/derive/staking/waitingInfo.ts +++ b/packages/api-derive/src/staking/waitingInfo.ts @@ -2,8 +2,7 @@ // SPDX-License-Identifier: Apache-2.0 import type { Observable } from 'rxjs'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveStakingWaiting, StakingQueryFlags } from '../types'; +import type { DeriveApi, DeriveStakingWaiting, StakingQueryFlags } from '../types'; import { combineLatest, map, switchMap } from 'rxjs'; @@ -11,7 +10,7 @@ import { memo } from '../util'; const DEFAULT_FLAGS = { withController: true, withPrefs: true }; -export function waitingInfo (instanceId: string, api: ApiInterfaceRx): (flags?: StakingQueryFlags) => Observable { +export function waitingInfo (instanceId: string, api: DeriveApi): (flags?: StakingQueryFlags) => Observable { return memo(instanceId, (flags: StakingQueryFlags = DEFAULT_FLAGS): Observable => combineLatest([ api.derive.staking.validators(), diff --git a/packages/api/src/derive/technicalCommittee/index.ts b/packages/api-derive/src/technicalCommittee/index.ts similarity index 100% rename from packages/api/src/derive/technicalCommittee/index.ts rename to packages/api-derive/src/technicalCommittee/index.ts diff --git a/packages/api/src/derive/test/bountyFactory.ts b/packages/api-derive/src/test/bountyFactory.ts similarity index 96% rename from packages/api/src/derive/test/bountyFactory.ts rename to packages/api-derive/src/test/bountyFactory.ts index c1a019b576..4f24db4979 100644 --- a/packages/api/src/derive/test/bountyFactory.ts +++ b/packages/api-derive/src/test/bountyFactory.ts @@ -1,12 +1,11 @@ // Copyright 2017-2021 @polkadot/api authors & contributors // SPDX-License-Identifier: Apache-2.0 +import { ApiPromise } from '@polkadot/api'; import { Option, StorageKey } from '@polkadot/types'; import { Bounty, BountyIndex } from '@polkadot/types/interfaces'; import { Codec, Constructor, InterfaceTypes, Registry } from '@polkadot/types/types'; -import { ApiPromise } from '../../promise'; - export class BountyFactory { readonly #api: ApiPromise; readonly #registry: Registry; diff --git a/packages/api/src/derive/test/bytesFactory.ts b/packages/api-derive/src/test/bytesFactory.ts similarity index 100% rename from packages/api/src/derive/test/bytesFactory.ts rename to packages/api-derive/src/test/bytesFactory.ts diff --git a/packages/api/src/derive/test/helpers.ts b/packages/api-derive/src/test/helpers.ts similarity index 76% rename from packages/api/src/derive/test/helpers.ts rename to packages/api-derive/src/test/helpers.ts index 1ad82465c1..1c93a9ac38 100644 --- a/packages/api/src/derive/test/helpers.ts +++ b/packages/api-derive/src/test/helpers.ts @@ -1,18 +1,20 @@ // Copyright 2017-2021 @polkadot/api authors & contributors // SPDX-License-Identifier: Apache-2.0 +import { ApiPromise, WsProvider } from '@polkadot/api'; import { Metadata, TypeRegistry } from '@polkadot/types'; import metaStatic from '@polkadot/types-support/metadata/static-substrate'; -import { ApiPromise, WsProvider } from '../..'; - export function createApiWithAugmentations (): ApiPromise { const registry = new TypeRegistry(); const metadata = new Metadata(registry, metaStatic); registry.setMetadata(metadata); - const api = new ApiPromise({ provider: new WsProvider('ws://', false), registry }); + const api = new ApiPromise({ + provider: new WsProvider('ws://', false), + registry + }); api.injectMetadata(metadata, true, registry); diff --git a/packages/api/src/derive/test/proposalFactory.ts b/packages/api-derive/src/test/proposalFactory.ts similarity index 85% rename from packages/api/src/derive/test/proposalFactory.ts rename to packages/api-derive/src/test/proposalFactory.ts index 8f3d301d7e..be263218df 100644 --- a/packages/api/src/derive/test/proposalFactory.ts +++ b/packages/api-derive/src/test/proposalFactory.ts @@ -1,13 +1,12 @@ // Copyright 2017-2021 @polkadot/api authors & contributors // SPDX-License-Identifier: Apache-2.0 -import type { SubmittableExtrinsic } from '../../types'; +import type { ApiPromise } from '@polkadot/api'; +import type { SubmittableExtrinsic } from '@polkadot/api-base/types'; import { Proposal, ProposalIndex } from '@polkadot/types/interfaces'; import { Registry } from '@polkadot/types/types'; -import { ApiPromise } from '../..'; - export class ProposalFactory { readonly #api: ApiPromise; readonly #registry: Registry; diff --git a/packages/api/src/derive/treasury/index.ts b/packages/api-derive/src/treasury/index.ts similarity index 100% rename from packages/api/src/derive/treasury/index.ts rename to packages/api-derive/src/treasury/index.ts diff --git a/packages/api/src/derive/treasury/proposals.ts b/packages/api-derive/src/treasury/proposals.ts similarity index 77% rename from packages/api/src/derive/treasury/proposals.ts rename to packages/api-derive/src/treasury/proposals.ts index be9a2daffa..99c21274d6 100644 --- a/packages/api/src/derive/treasury/proposals.ts +++ b/packages/api-derive/src/treasury/proposals.ts @@ -5,8 +5,7 @@ import type { Observable } from 'rxjs'; import type { Option } from '@polkadot/types'; import type { ProposalIndex } from '@polkadot/types/interfaces'; import type { PalletTreasuryProposal } from '@polkadot/types/lookup'; -import type { ApiInterfaceRx } from '../../types'; -import type { DeriveCollectiveProposal, DeriveTreasuryProposal, DeriveTreasuryProposals } from '../types'; +import type { DeriveApi, DeriveCollectiveProposal, DeriveTreasuryProposal, DeriveTreasuryProposals } from '../types'; import { combineLatest, map, of, switchMap } from 'rxjs'; @@ -20,7 +19,7 @@ interface Result { proposalCount: ProposalIndex; } -function parseResult (api: ApiInterfaceRx, { allIds, allProposals, approvalIds, councilProposals, proposalCount }: Result): DeriveTreasuryProposals { +function parseResult (api: DeriveApi, { allIds, allProposals, approvalIds, councilProposals, proposalCount }: Result): DeriveTreasuryProposals { const approvals: DeriveTreasuryProposal[] = []; const proposals: DeriveTreasuryProposal[] = []; const councilTreasury = councilProposals.filter(({ proposal }) => @@ -47,7 +46,7 @@ function parseResult (api: ApiInterfaceRx, { allIds, allProposals, approvalIds, return { approvals, proposalCount, proposals }; } -function retrieveProposals (api: ApiInterfaceRx, proposalCount: ProposalIndex, approvalIds: ProposalIndex[]): Observable { +function retrieveProposals (api: DeriveApi, proposalCount: ProposalIndex, approvalIds: ProposalIndex[]): Observable { const proposalIds: ProposalIndex[] = []; const count = proposalCount.toNumber(); @@ -65,7 +64,7 @@ function retrieveProposals (api: ApiInterfaceRx, proposalCount: ProposalIndex, a ? api.derive.council.proposals() : of([] as DeriveCollectiveProposal[]) ]).pipe( - map(([allProposals, councilProposals]: [Option[], DeriveCollectiveProposal[]]): DeriveTreasuryProposals => + map(([allProposals, councilProposals]): DeriveTreasuryProposals => parseResult(api, { allIds, allProposals, approvalIds, councilProposals, proposalCount }) ) ); @@ -74,14 +73,14 @@ function retrieveProposals (api: ApiInterfaceRx, proposalCount: ProposalIndex, a /** * @description Retrieve all active and approved treasury proposals, along with their info */ -export function proposals (instanceId: string, api: ApiInterfaceRx): () => Observable { +export function proposals (instanceId: string, api: DeriveApi): () => Observable { return memo(instanceId, (): Observable => api.query.treasury ? combineLatest([ api.query.treasury.proposalCount(), api.query.treasury.approvals() ]).pipe( - switchMap(([proposalCount, approvalIds]: [ProposalIndex, ProposalIndex[]]) => + switchMap(([proposalCount, approvalIds]) => retrieveProposals(api, proposalCount, approvalIds) ) ) diff --git a/packages/api/src/derive/tx/constants.ts b/packages/api-derive/src/tx/constants.ts similarity index 100% rename from packages/api/src/derive/tx/constants.ts rename to packages/api-derive/src/tx/constants.ts diff --git a/packages/api/src/derive/tx/events.ts b/packages/api-derive/src/tx/events.ts similarity index 75% rename from packages/api/src/derive/tx/events.ts rename to packages/api-derive/src/tx/events.ts index 6c91d5ad0e..57a4572cbc 100644 --- a/packages/api/src/derive/tx/events.ts +++ b/packages/api-derive/src/tx/events.ts @@ -3,7 +3,7 @@ import type { Observable } from 'rxjs'; import type { EventRecord, Hash, SignedBlock } from '@polkadot/types/interfaces'; -import type { ApiInterfaceRx } from '../../types'; +import type { DeriveApi } from '../types'; import { combineLatest, map, switchMap } from 'rxjs'; @@ -14,7 +14,7 @@ interface Result { events: EventRecord[]; } -export function events (instanceId: string, api: ApiInterfaceRx): (at: Hash) => Observable { +export function events (instanceId: string, api: DeriveApi): (at: Hash) => Observable { return memo(instanceId, (blockHash: Hash) => combineLatest([ api.rpc.chain.getBlock(blockHash), @@ -24,7 +24,7 @@ export function events (instanceId: string, api: ApiInterfaceRx): (at: Hash) => ) ) ]).pipe( - map(([block, events]): Result => ({ block, events })) + map(([block, events]) => ({ block, events })) ) ); } diff --git a/packages/api/src/derive/tx/index.ts b/packages/api-derive/src/tx/index.ts similarity index 100% rename from packages/api/src/derive/tx/index.ts rename to packages/api-derive/src/tx/index.ts diff --git a/packages/api/src/derive/tx/signingInfo.ts b/packages/api-derive/src/tx/signingInfo.ts similarity index 81% rename from packages/api/src/derive/tx/signingInfo.ts rename to packages/api-derive/src/tx/signingInfo.ts index abdf485281..d290448056 100644 --- a/packages/api/src/derive/tx/signingInfo.ts +++ b/packages/api-derive/src/tx/signingInfo.ts @@ -4,7 +4,7 @@ import type { Observable } from 'rxjs'; import type { Header, Index } from '@polkadot/types/interfaces'; import type { AnyNumber, Codec, IExtrinsicEra } from '@polkadot/types/types'; -import type { ApiInterfaceRx } from '../../types'; +import type { DeriveApi } from '../types'; import { combineLatest, map, of, switchMap } from 'rxjs'; @@ -18,19 +18,19 @@ interface Result { nonce: Index; } -function latestNonce (api: ApiInterfaceRx, address: string): Observable { +function latestNonce (api: DeriveApi, address: string): Observable { return api.derive.balances.account(address).pipe( map(({ accountNonce }) => accountNonce) ); } -function nextNonce (api: ApiInterfaceRx, address: string): Observable { +function nextNonce (api: DeriveApi, address: string): Observable { return api.rpc.system?.accountNextIndex ? api.rpc.system.accountNextIndex(address) : latestNonce(api, address); } -function signingHeader (api: ApiInterfaceRx): Observable
{ +function signingHeader (api: DeriveApi): Observable
{ return combineLatest([ api.rpc.chain.getHeader().pipe( switchMap((header) => @@ -58,7 +58,7 @@ function signingHeader (api: ApiInterfaceRx): Observable
{ ); } -export function signingInfo (_instanceId: string, api: ApiInterfaceRx): (address: string, nonce?: AnyNumber | Codec, era?: IExtrinsicEra | number) => Observable { +export function signingInfo (_instanceId: string, api: DeriveApi): (address: string, nonce?: AnyNumber | Codec, era?: IExtrinsicEra | number) => Observable { // no memo, we want to do this fresh on each run return (address: string, nonce?: AnyNumber | Codec, era?: IExtrinsicEra | number): Observable => combineLatest([ @@ -78,7 +78,11 @@ export function signingInfo (_instanceId: string, api: ApiInterfaceRx): (address mortalLength: Math.min( api.consts.system?.blockHashCount?.toNumber() || FALLBACK_MAX_HASH_COUNT, MORTAL_PERIOD - .div(api.consts.babe?.expectedBlockTime || api.consts.timestamp?.minimumPeriod.muln(2) || FALLBACK_PERIOD) + .div( + api.consts.babe?.expectedBlockTime || + api.consts.timestamp?.minimumPeriod.muln(2) || + FALLBACK_PERIOD + ) .iadd(MAX_FINALITY_LAG) .toNumber() ), diff --git a/packages/api/src/derive/type/HeaderExtended.ts b/packages/api-derive/src/type/HeaderExtended.ts similarity index 100% rename from packages/api/src/derive/type/HeaderExtended.ts rename to packages/api-derive/src/type/HeaderExtended.ts diff --git a/packages/api/src/derive/type/SignedBlockExtended.ts b/packages/api-derive/src/type/SignedBlockExtended.ts similarity index 100% rename from packages/api/src/derive/type/SignedBlockExtended.ts rename to packages/api-derive/src/type/SignedBlockExtended.ts diff --git a/packages/api/src/derive/type/index.ts b/packages/api-derive/src/type/index.ts similarity index 100% rename from packages/api/src/derive/type/index.ts rename to packages/api-derive/src/type/index.ts diff --git a/packages/api/src/derive/type/types.ts b/packages/api-derive/src/type/types.ts similarity index 100% rename from packages/api/src/derive/type/types.ts rename to packages/api-derive/src/type/types.ts diff --git a/packages/api/src/derive/type/util.ts b/packages/api-derive/src/type/util.ts similarity index 100% rename from packages/api/src/derive/type/util.ts rename to packages/api-derive/src/type/util.ts diff --git a/packages/api-derive/src/types.ts b/packages/api-derive/src/types.ts index 89cabdfa62..7d4fdf01e0 100644 --- a/packages/api-derive/src/types.ts +++ b/packages/api-derive/src/types.ts @@ -1,4 +1,98 @@ // Copyright 2017-2021 @polkadot/api-derive authors & contributors // SPDX-License-Identifier: Apache-2.0 -export * from '@polkadot/api/derive/types'; +import '@polkadot/api-augment/augment'; + +import type { ApiInterfaceRx } from '@polkadot/api-base/types'; +import type { u32 } from '@polkadot/types'; +import type { Balance, BlockNumber, BountyIndex, Hash, Proposal, ProposalIndex, SetIndex, Votes } from '@polkadot/types/interfaces'; +import type { PalletBountiesBounty, PalletTreasuryProposal } from '@polkadot/types/lookup'; +import type { BN } from '@polkadot/util'; +import type { ExactDerive } from './derive'; + +export * from './accounts/types'; +export * from './balances/types'; +export * from './council/types'; +export * from './crowdloan/types'; +export * from './democracy/types'; +export * from './elections/types'; +export * from './parachains/types'; +export * from './session/types'; +export * from './society/types'; +export * from './staking/types'; +export * from './type/types'; + +export interface DeriveApi extends ApiInterfaceRx { + derive: ExactDerive; +} + +export interface DeriveContractFees { + callBaseFee: BN; + contractFee: BN; + creationFee: BN; + rentByteFee: BN; + rentDepositOffset: BN; + surchargeReward: BN; + tombstoneDeposit: BN; + transactionBaseFee: BN; + transactionByteFee: BN; + transferFee: BN; +} + +export interface DeriveCollectiveProposal { + hash: Hash; + proposal: Proposal; + votes: Votes | null; +} + +export interface DeriveFees { + creationFee: Balance; + existentialDeposit: Balance; + transactionBaseFee: Balance; + transactionByteFee: Balance; + transferFee: Balance; +} + +export interface DeriveHeartbeatAuthor { + blockCount: u32; + hasMessage: boolean; + isOnline: boolean; +} + +export type DeriveHeartbeats = Record; + +export interface RecentlyOffline { + blockNumber: BlockNumber; + count: BN; +} + +export type DeriveRecentlyOffline = Record; + +export interface DeriveTreasuryProposal { + council: DeriveCollectiveProposal[]; + id: ProposalIndex; + proposal: PalletTreasuryProposal; +} + +export interface DeriveTreasuryProposals { + approvals: DeriveTreasuryProposal[]; + proposalCount: ProposalIndex; + proposals: DeriveTreasuryProposal[]; +} + +export interface VoterPosition { + globalIndex: BN; + index: BN; + setIndex: SetIndex; +} + +export type DeriveVoterPositions = Record; + +export interface DeriveBounty { + bounty: PalletBountiesBounty; + description: string; + index: BountyIndex; + proposals: DeriveCollectiveProposal[]; +} + +export type DeriveBounties = DeriveBounty[]; diff --git a/packages/api/src/derive/util/approvalFlagToBools.spec.ts b/packages/api-derive/src/util/approvalFlagToBools.spec.ts similarity index 100% rename from packages/api/src/derive/util/approvalFlagToBools.spec.ts rename to packages/api-derive/src/util/approvalFlagToBools.spec.ts diff --git a/packages/api/src/derive/util/approvalFlagsToBools.ts b/packages/api-derive/src/util/approvalFlagsToBools.ts similarity index 100% rename from packages/api/src/derive/util/approvalFlagsToBools.ts rename to packages/api-derive/src/util/approvalFlagsToBools.ts diff --git a/packages/api/src/derive/util/cache.ts b/packages/api-derive/src/util/cache.ts similarity index 100% rename from packages/api/src/derive/util/cache.ts rename to packages/api-derive/src/util/cache.ts diff --git a/packages/api/src/derive/util/cacheImpl.ts b/packages/api-derive/src/util/cacheImpl.ts similarity index 100% rename from packages/api/src/derive/util/cacheImpl.ts rename to packages/api-derive/src/util/cacheImpl.ts diff --git a/packages/api/src/derive/util/first.ts b/packages/api-derive/src/util/first.ts similarity index 59% rename from packages/api/src/derive/util/first.ts rename to packages/api-derive/src/util/first.ts index f7f539590f..3ac17eb9fd 100644 --- a/packages/api/src/derive/util/first.ts +++ b/packages/api-derive/src/util/first.ts @@ -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 { map } from 'rxjs'; @@ -12,8 +12,8 @@ export function firstObservable (obs: Observable): Observable { return obs.pipe(map(([a]) => a)); } -export function firstMemo (fn: (api: ApiInterfaceRx, ...args: A) => Observable): (instanceId: string, api: ApiInterfaceRx) => (...args: A) => Observable { - return (instanceId: string, api: ApiInterfaceRx) => +export function firstMemo (fn: (api: DeriveApi, ...args: A) => Observable): (instanceId: string, api: DeriveApi) => (...args: A) => Observable { + return (instanceId: string, api: DeriveApi) => memo(instanceId, (...args: A) => firstObservable(fn(api, ...args)) ); diff --git a/packages/api/src/derive/util/index.ts b/packages/api-derive/src/util/index.ts similarity index 100% rename from packages/api/src/derive/util/index.ts rename to packages/api-derive/src/util/index.ts diff --git a/packages/api/src/derive/util/lazy.ts b/packages/api-derive/src/util/lazy.ts similarity index 100% rename from packages/api/src/derive/util/lazy.ts rename to packages/api-derive/src/util/lazy.ts diff --git a/packages/api/src/derive/util/types.ts b/packages/api-derive/src/util/types.ts similarity index 100% rename from packages/api/src/derive/util/types.ts rename to packages/api-derive/src/util/types.ts diff --git a/packages/api-derive/tsconfig.json b/packages/api-derive/tsconfig.json index d54281408d..45c215d503 100644 --- a/packages/api-derive/tsconfig.json +++ b/packages/api-derive/tsconfig.json @@ -5,7 +5,15 @@ "outDir": "./build", "rootDir": "./src" }, + "exclude": [ + "**/test/*", + "**/*.spec.ts" + ], "references": [ - { "path": "../api" } + { "path": "../api-augment" }, + { "path": "../api-base" }, + { "path": "../rpc-core" }, + { "path": "../types" }, + { "path": "../types-codec" } ] } diff --git a/packages/api-derive/tsconfig.spec.json b/packages/api-derive/tsconfig.spec.json new file mode 100644 index 0000000000..4670dfd676 --- /dev/null +++ b/packages/api-derive/tsconfig.spec.json @@ -0,0 +1,22 @@ +{ + "extends": "../../tsconfig.base.json", + "compilerOptions": { + "baseUrl": "..", + "outDir": "./build", + "rootDir": "./src", + "emitDeclarationOnly": false, + "noEmit": true + }, + "include": [ + "**/test/*", + "**/*.spec.ts" + ], + "references": [ + { "path": "../api" }, + { "path": "../api-augment" }, + { "path": "../api-base" }, + { "path": "../api-derive" }, + { "path": "../types" }, + { "path": "../types-codec" } + ] +} diff --git a/packages/api/src/base/Decorate.ts b/packages/api/src/base/Decorate.ts index b6bf29655e..c80d3ffee9 100644 --- a/packages/api/src/base/Decorate.ts +++ b/packages/api/src/base/Decorate.ts @@ -2,28 +2,28 @@ // SPDX-License-Identifier: Apache-2.0 import type { Observable } from 'rxjs'; +import type { DeriveCustom } from '@polkadot/api-derive'; import type { RpcInterface } from '@polkadot/rpc-core/types'; import type { Option, Raw, StorageKey, Text, u64 } from '@polkadot/types'; import type { Call, Hash, RuntimeVersion } from '@polkadot/types/interfaces'; import type { DecoratedMeta } from '@polkadot/types/metadata/decorate/types'; import type { StorageEntry } from '@polkadot/types/primitive/types'; import type { AnyFunction, AnyTuple, CallFunction, Codec, DefinitionRpc, DefinitionRpcSub, DetectCodec, IMethod, IStorageKey, Registry, RegistryError, RegistryTypes } from '@polkadot/types/types'; -import type { DeriveCustom } from '../derive'; import type { SubmittableExtrinsic } from '../submittable/types'; import type { ApiDecoration, ApiInterfaceRx, ApiOptions, ApiTypes, AugmentedQuery, DecoratedErrors, DecoratedEvents, DecoratedRpc, DecorateMethod, GenericStorageEntryFunction, PaginationOptions, QueryableConsts, QueryableStorage, QueryableStorageEntry, QueryableStorageEntryAt, QueryableStorageMulti, QueryableStorageMultiArg, SubmittableExtrinsicFunction, SubmittableExtrinsics } from '../types'; import type { VersionedRegistry } from './types'; import { BehaviorSubject, combineLatest, from, map, of, switchMap, tap, toArray } from 'rxjs'; +import { getAvailableDerives } from '@polkadot/api-derive'; import { memo, RpcCore } from '@polkadot/rpc-core'; import { WsProvider } from '@polkadot/rpc-provider'; import { expandMetadata, Metadata, TypeRegistry, unwrapStorageType } from '@polkadot/types'; import { arrayChunk, arrayFlatten, assert, BN, BN_ZERO, compactStripLength, lazyMethod, lazyMethods, logger, objectSpread, u8aToHex } from '@polkadot/util'; -import { ExactDerive, getAvailableDerives } from '../derive'; import { createSubmittable } from '../submittable'; import { augmentObject } from '../util/augmentObject'; -import { decorateDeriveSections, DeriveAllSections } from '../util/decorate'; +import { AllDerives, decorateDeriveSections } from '../util/decorate'; import { extractStorageArgs } from '../util/validate'; import { Events } from './Events'; import { findCall, findError } from './find'; @@ -733,17 +733,17 @@ export abstract class Decorate extends Events { ); } - protected _decorateDeriveRx (decorateMethod: DecorateMethod): DeriveAllSections<'rxjs', ExactDerive> { + protected _decorateDeriveRx (decorateMethod: DecorateMethod): AllDerives<'rxjs'> { const specName = this._runtimeVersion?.specName.toString(); // Pull in derive from api-derive const available = getAvailableDerives(this.#instanceId, this._rx, objectSpread({}, this._options.derives, this._options.typesBundle?.spec?.[specName || '']?.derives)); - return decorateDeriveSections<'rxjs', ExactDerive>(decorateMethod, available); + return decorateDeriveSections<'rxjs'>(decorateMethod, available); } - protected _decorateDerive (decorateMethod: DecorateMethod): DeriveAllSections { - return decorateDeriveSections(decorateMethod, this._rx.derive); + protected _decorateDerive (decorateMethod: DecorateMethod): AllDerives { + return decorateDeriveSections(decorateMethod, this._rx.derive); } /** diff --git a/packages/api/src/checkTypes.manual.ts b/packages/api/src/checkTypes.manual.ts index 0fcae3e267..3b85925a17 100644 --- a/packages/api/src/checkTypes.manual.ts +++ b/packages/api/src/checkTypes.manual.ts @@ -3,10 +3,10 @@ // Simple non-runnable checks to test type definitions in the editor itself +import type { HeaderExtended } from '@polkadot/api-derive/types'; import type { StorageKey } from '@polkadot/types'; import type { AccountId, Balance, DispatchErrorModule, Event, Header, Index } from '@polkadot/types/interfaces'; import type { AnyTuple, IExtrinsic, IMethod } from '@polkadot/types/types'; -import type { HeaderExtended } from './derive/types'; import { ApiPromise } from '@polkadot/api'; import { createTestPairs, TestKeyringMap } from '@polkadot/keyring/testingPairs'; diff --git a/packages/api/src/derive/index.ts b/packages/api/src/derive/index.ts deleted file mode 100644 index a28ea8534b..0000000000 --- a/packages/api/src/derive/index.ts +++ /dev/null @@ -1,130 +0,0 @@ -// Copyright 2017-2021 @polkadot/api-derive authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -import type { AnyFunction } from '@polkadot/types/types'; -import type { ApiInterfaceRx } from '../types'; -import type { DeriveCustom, ExactDerive } from './derive'; - -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 = { - 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: ApiInterfaceRx, 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: ApiInterfaceRx, derives: DeriveCustom): ExactDerive { - const result: Record> = {}; - 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: ApiInterfaceRx, custom: DeriveCustom = {}): ExactDerive { - return { - ...injectFunctions(instanceId, api, derive as DeriveCustom), - ...injectFunctions(instanceId, api, custom) - }; -} diff --git a/packages/api/src/derive/types.ts b/packages/api/src/derive/types.ts deleted file mode 100644 index ce3b648a55..0000000000 --- a/packages/api/src/derive/types.ts +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright 2017-2021 @polkadot/api-derive authors & contributors -// SPDX-License-Identifier: Apache-2.0 - -import type { u32 } from '@polkadot/types'; -import type { Balance, BlockNumber, BountyIndex, Hash, Proposal, ProposalIndex, SetIndex, Votes } from '@polkadot/types/interfaces'; -import type { PalletBountiesBounty, PalletTreasuryProposal } from '@polkadot/types/lookup'; -import type { BN } from '@polkadot/util'; - -export * from './accounts/types'; -export * from './balances/types'; -export * from './council/types'; -export * from './crowdloan/types'; -export * from './democracy/types'; -export * from './elections/types'; -export * from './parachains/types'; -export * from './session/types'; -export * from './society/types'; -export * from './staking/types'; -export * from './type/types'; - -export interface DeriveContractFees { - callBaseFee: BN; - contractFee: BN; - creationFee: BN; - rentByteFee: BN; - rentDepositOffset: BN; - surchargeReward: BN; - tombstoneDeposit: BN; - transactionBaseFee: BN; - transactionByteFee: BN; - transferFee: BN; -} - -export interface DeriveCollectiveProposal { - hash: Hash; - proposal: Proposal; - votes: Votes | null; -} - -export interface DeriveFees { - creationFee: Balance; - existentialDeposit: Balance; - transactionBaseFee: Balance; - transactionByteFee: Balance; - transferFee: Balance; -} - -export interface DeriveHeartbeatAuthor { - blockCount: u32; - hasMessage: boolean; - isOnline: boolean; -} - -export type DeriveHeartbeats = Record; - -export interface RecentlyOffline { - blockNumber: BlockNumber; - count: BN; -} - -export type DeriveRecentlyOffline = Record; - -export interface DeriveTreasuryProposal { - council: DeriveCollectiveProposal[]; - id: ProposalIndex; - proposal: PalletTreasuryProposal; -} - -export interface DeriveTreasuryProposals { - approvals: DeriveTreasuryProposal[]; - proposalCount: ProposalIndex; - proposals: DeriveTreasuryProposal[]; -} - -export interface VoterPosition { - globalIndex: BN; - index: BN; - setIndex: SetIndex; -} - -export type DeriveVoterPositions = Record; - -export interface DeriveBounty { - bounty: PalletBountiesBounty; - description: string; - index: BountyIndex; - proposals: DeriveCollectiveProposal[]; -} - -export type DeriveBounties = DeriveBounty[]; diff --git a/packages/api/src/detectPackage.ts b/packages/api/src/detectPackage.ts index 36719df4e3..3b8fa1bfb9 100644 --- a/packages/api/src/detectPackage.ts +++ b/packages/api/src/detectPackage.ts @@ -1,6 +1,7 @@ // Copyright 2017-2021 @polkadot/api authors & contributors // SPDX-License-Identifier: Apache-2.0 +import { packageInfo as deriveInfo } from '@polkadot/api-derive/packageInfo'; import { packageInfo as coreInfo } from '@polkadot/rpc-core/packageInfo'; import { packageInfo as providerInfo } from '@polkadot/rpc-provider/packageInfo'; import { packageInfo as typesInfo } from '@polkadot/types/packageInfo'; @@ -11,4 +12,4 @@ import { detectPackage } from '@polkadot/util'; import { packageInfo } from './packageInfo'; -detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [coreInfo, providerInfo, typesInfo, codecInfo, createInfo, knownInfo]); +detectPackage(packageInfo, typeof __dirname !== 'undefined' && __dirname, [deriveInfo, coreInfo, providerInfo, typesInfo, codecInfo, createInfo, knownInfo]); diff --git a/packages/api/src/types.ts b/packages/api/src/types.ts index 4f7ef4e720..49c3689e3c 100644 --- a/packages/api/src/types.ts +++ b/packages/api/src/types.ts @@ -1,39 +1,37 @@ // Copyright 2017-2021 @polkadot/api authors & contributors // SPDX-License-Identifier: Apache-2.0 -import '@polkadot/api-augment'; +import '@polkadot/api-augment/augment'; -import type { Observable } from 'rxjs'; -import type { QueryableConsts } from '@polkadot/api/types/consts'; -import type { DecoratedErrors } from '@polkadot/api/types/errors'; -import type { DecoratedEvents } from '@polkadot/api/types/events'; -import type { QueryableStorage } from '@polkadot/api/types/storage'; -import type { SubmittableExtrinsics } from '@polkadot/api/types/submittable'; -import type { ApiTypes, DecoratedRpc, QueryableStorageMulti } from '@polkadot/api-base/types'; -import type { RpcInterface } from '@polkadot/rpc-core/types'; +import type { QueryableConsts } from '@polkadot/api-augment/consts'; +import type { DecoratedErrors } from '@polkadot/api-augment/errors'; +import type { DecoratedEvents } from '@polkadot/api-augment/events'; +import type { QueryableStorage } from '@polkadot/api-augment/query'; +import type { SubmittableExtrinsics } from '@polkadot/api-augment/tx'; +import type { ApiInterfaceRx as ApiInterfaceBase, ApiTypes, QueryableStorageMulti } from '@polkadot/api-base/types'; +import type { DeriveCustom } from '@polkadot/api-derive'; import type { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types'; import type { ExtDef } from '@polkadot/types/extrinsic/signedExtensions/types'; -import type { Hash, RuntimeVersion } from '@polkadot/types/interfaces'; -import type { Metadata } from '@polkadot/types/metadata'; +import type { Hash } from '@polkadot/types/interfaces'; import type { CallFunction, DefinitionRpc, DefinitionRpcSub, RegisteredTypes, Registry, RegistryError, SignatureOptions, Signer } from '@polkadot/types/types'; import type { BN } from '@polkadot/util'; import type { HexString } from '@polkadot/util/types'; import type { ApiBase } from './base'; -import type { DeriveCustom, ExactDerive } from './derive'; -import type { DeriveAllSections } from './util/decorate'; +import type { AllDerives } from './util/decorate'; export * from '@polkadot/api-base/types'; -export * from '@polkadot/api/types/consts'; -export * from '@polkadot/api/types/errors'; -export * from '@polkadot/api/types/events'; -export * from '@polkadot/api/types/storage'; -export * from '@polkadot/api/types/submittable'; -export * from '@polkadot/rpc-core/types'; export { Signer, SignerResult } from '@polkadot/types/types'; export { ApiBase } from './base'; +export type { DecoratedErrors, DecoratedEvents, QueryableConsts, QueryableStorage, SubmittableExtrinsics }; + +// A smaller interface of ApiRx, used in derive and in SubmittableExtrinsic +export interface ApiInterfaceRx extends ApiInterfaceBase { + derive: AllDerives<'rxjs'>; +} + export interface ApiOptions extends RegisteredTypes { /** * @description Add custom derives to be injected @@ -83,25 +81,6 @@ export interface ApiOptions extends RegisteredTypes { throwOnUnknown?: boolean; } -// A smaller interface of ApiRx, used in derive and in SubmittableExtrinsic -export interface ApiInterfaceRx { - consts: QueryableConsts<'rxjs'>; - // TODO This needs to be typed correctly - derive: DeriveAllSections<'rxjs', ExactDerive>; - extrinsicType: number; - genesisHash?: Hash; - hasSubscriptions: boolean; - registry: Registry; - runtimeMetadata: Metadata; - runtimeVersion: RuntimeVersion; - query: QueryableStorage<'rxjs'>; - queryAt: (blockHash: Uint8Array | string, knownVersion?: RuntimeVersion) => Observable>; - queryMulti: QueryableStorageMulti<'rxjs'>; - rpc: DecoratedRpc<'rxjs', RpcInterface>; - tx: SubmittableExtrinsics<'rxjs'>; - signer?: Signer; -} - export type ApiInterfaceEvents = ProviderInterfaceEmitted | 'ready'; export interface SignerOptions extends SignatureOptions { diff --git a/packages/api/src/util/decorate.ts b/packages/api/src/util/decorate.ts index 1fc0e38c3c..b446c53b60 100644 --- a/packages/api/src/util/decorate.ts +++ b/packages/api/src/util/decorate.ts @@ -1,10 +1,11 @@ // Copyright 2017-2021 @polkadot/api authors & contributors // SPDX-License-Identifier: Apache-2.0 +import type { ExactDerive } from '@polkadot/api-derive'; import type { AnyFunction } from '@polkadot/types/types'; import type { ApiTypes, DecorateMethod, MethodResult } from '../types'; -import { lazyDeriveSection } from '../derive'; +import { lazyDeriveSection } from '@polkadot/api-derive'; type AnyDeriveSection = Record; @@ -17,14 +18,14 @@ type DeriveSection = }; // Exact typings for all sections `api.derive.*.*` -export type DeriveAllSections = { - [S in keyof AllSections]: DeriveSection +export type AllDerives = { + [S in keyof ExactDerive]: DeriveSection }; /** * This is a section decorator which keeps all type information. */ -export function decorateDeriveSections (decorateMethod: DecorateMethod, derives: AnyDerive): DeriveAllSections { +export function decorateDeriveSections (decorateMethod: DecorateMethod, derives: AnyDerive): AllDerives { const getKeys = (s: string) => Object.keys(derives[s]); @@ -38,5 +39,5 @@ export function decorateDeriveSections; + return result as AllDerives; } diff --git a/packages/api/tsconfig.json b/packages/api/tsconfig.json index 1e85d24407..8caca70230 100644 --- a/packages/api/tsconfig.json +++ b/packages/api/tsconfig.json @@ -12,6 +12,7 @@ "references": [ { "path": "../api-augment" }, { "path": "../api-base" }, + { "path": "../api-derive" }, { "path": "../rpc-core" }, { "path": "../rpc-provider" }, { "path": "../types" }, diff --git a/packages/rpc-core/src/cached.spec.ts b/packages/rpc-core/src/cached.spec.ts index 4bbdcc9fea..bc1658391b 100644 --- a/packages/rpc-core/src/cached.spec.ts +++ b/packages/rpc-core/src/cached.spec.ts @@ -91,9 +91,8 @@ describe('Cached Observables', (): void => { it('creates different observables for different methods but same arguments', (): void => { // params do not match here - // eslint-disable-next-line @typescript-eslint/no-unsafe-assignment,@typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-member-access - const observable1 = (rpc.chain).subscribeNewHeads([123]); - const observable2 = rpc.state.subscribeStorage([123]); + const observable1 = rpc.chain.getHeader('123'); + const observable2 = rpc.chain.getBlockHash('123'); expect(observable2).not.toBe(observable1); }); diff --git a/packages/rpc-provider/src/mock/index.ts b/packages/rpc-provider/src/mock/index.ts index 91fb8971a0..9133ddb65d 100644 --- a/packages/rpc-provider/src/mock/index.ts +++ b/packages/rpc-provider/src/mock/index.ts @@ -68,6 +68,7 @@ export class MockProvider implements ProviderInterface { state_getRuntimeVersion: () => this.registry.createType('RuntimeVersion').toHex(), state_getStorage: (storage: MockStateDb, [key]: string[]) => u8aToHex(storage[key]), system_chain: () => 'mockChain', + system_health: () => ({}), system_name: () => 'mockClient', system_properties: () => ({ ss58Format: 42 }), system_upgradedToTripleRefCount: () => this.registry.createType('bool', true), diff --git a/packages/typegen/src/generate/consts.ts b/packages/typegen/src/generate/consts.ts index 99ea11ebc6..a734622b9c 100644 --- a/packages/typegen/src/generate/consts.ts +++ b/packages/typegen/src/generate/consts.ts @@ -85,7 +85,7 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, // Call `generateForMeta()` with current static metadata /** @internal */ -export function generateDefaultConsts (dest = 'packages/api-augment/src/consts.ts', data?: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void { +export function generateDefaultConsts (dest = 'packages/api-augment/src/augment/consts.ts', data?: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void { const { metadata } = initMeta(data, extraTypes); return generateForMeta(metadata, dest, extraTypes, isStrict, customLookupDefinitions); diff --git a/packages/typegen/src/generate/errors.ts b/packages/typegen/src/generate/errors.ts index f1a8461e2e..87289a65e2 100644 --- a/packages/typegen/src/generate/errors.ts +++ b/packages/typegen/src/generate/errors.ts @@ -48,7 +48,7 @@ function generateForMeta (meta: Metadata, dest: string, isStrict: boolean): void // Call `generateForMeta()` with current static metadata /** @internal */ -export function generateDefaultErrors (dest = 'packages/api-augment/src/errors.ts', data?: HexString, extraTypes: ExtraTypes = {}, isStrict = false): void { +export function generateDefaultErrors (dest = 'packages/api-augment/src/augment/errors.ts', data?: HexString, extraTypes: ExtraTypes = {}, isStrict = false): void { const { metadata } = initMeta(data, extraTypes); return generateForMeta(metadata, dest, isStrict); diff --git a/packages/typegen/src/generate/events.ts b/packages/typegen/src/generate/events.ts index 59074c2ab3..0929debd89 100644 --- a/packages/typegen/src/generate/events.ts +++ b/packages/typegen/src/generate/events.ts @@ -77,7 +77,7 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: ExtraTypes, // Call `generateForMeta()` with current static metadata /** @internal */ -export function generateDefaultEvents (dest = 'packages/api-augment/src/events.ts', data?: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void { +export function generateDefaultEvents (dest = 'packages/api-augment/src/augment/events.ts', data?: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void { const { metadata } = initMeta(data, extraTypes); return generateForMeta(metadata, dest, extraTypes, isStrict, customLookupDefinitions); diff --git a/packages/typegen/src/generate/query.ts b/packages/typegen/src/generate/query.ts index 9da95e0ad1..4aa5e9fe96 100644 --- a/packages/typegen/src/generate/query.ts +++ b/packages/typegen/src/generate/query.ts @@ -134,7 +134,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr // Call `generateForMeta()` with current static metadata /** @internal */ -export function generateDefaultQuery (dest = 'packages/api-augment/src/query.ts', data?: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void { +export function generateDefaultQuery (dest = 'packages/api-augment/src/augment/query.ts', data?: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void { const { metadata, registry } = initMeta(data, extraTypes); return generateForMeta(registry, metadata, dest, extraTypes, isStrict, customLookupDefinitions); diff --git a/packages/typegen/src/generate/rpc.ts b/packages/typegen/src/generate/rpc.ts index 97f35f1429..a74e832ed0 100644 --- a/packages/typegen/src/generate/rpc.ts +++ b/packages/typegen/src/generate/rpc.ts @@ -143,7 +143,7 @@ export function generateRpcTypes (registry: TypeRegistry, importDefinitions: Rec }); } -export function generateDefaultRpc (dest = 'packages/api-augment/src/rpc.ts', extraTypes: ExtraTypes = {}): void { +export function generateDefaultRpc (dest = 'packages/api-augment/src/augment/rpc.ts', extraTypes: ExtraTypes = {}): void { const { registry } = initMeta(undefined, extraTypes); generateRpcTypes( diff --git a/packages/typegen/src/generate/tx.ts b/packages/typegen/src/generate/tx.ts index f5ed8aa401..a1ccf00100 100644 --- a/packages/typegen/src/generate/tx.ts +++ b/packages/typegen/src/generate/tx.ts @@ -119,7 +119,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr // Call `generateForMeta()` with current static metadata /** @internal */ -export function generateDefaultTx (dest = 'packages/api-augment/src/tx.ts', data?: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void { +export function generateDefaultTx (dest = 'packages/api-augment/src/augment/tx.ts', data?: HexString, extraTypes: ExtraTypes = {}, isStrict = false, customLookupDefinitions?: Definitions): void { const { metadata, registry } = initMeta(data, extraTypes); return generateForMeta(registry, metadata, dest, extraTypes, isStrict, customLookupDefinitions); diff --git a/packages/typegen/src/templates/consts.hbs b/packages/typegen/src/templates/consts.hbs index 9fd15ef89f..0520b2b64c 100644 --- a/packages/typegen/src/templates/consts.hbs +++ b/packages/typegen/src/templates/consts.hbs @@ -2,7 +2,7 @@ {{{ importsRelative }}} -declare module '@polkadot/api/types/consts' { +declare module '@polkadot/api-augment/consts' { {{{ importsPackage }}} export interface AugmentedConsts { diff --git a/packages/typegen/src/templates/errors.hbs b/packages/typegen/src/templates/errors.hbs index 40ff1c90a2..f6985299af 100644 --- a/packages/typegen/src/templates/errors.hbs +++ b/packages/typegen/src/templates/errors.hbs @@ -2,7 +2,7 @@ {{{ importsRelative }}} -declare module '@polkadot/api/types/errors' { +declare module '@polkadot/api-augment/errors' { {{{ importsPackage }}} export interface AugmentedErrors { diff --git a/packages/typegen/src/templates/events.hbs b/packages/typegen/src/templates/events.hbs index 68b009b272..fb0bb3e5f6 100644 --- a/packages/typegen/src/templates/events.hbs +++ b/packages/typegen/src/templates/events.hbs @@ -2,7 +2,7 @@ {{{ importsRelative }}} -declare module '@polkadot/api/types/events' { +declare module '@polkadot/api-augment/events' { {{{ importsPackage }}} export interface AugmentedEvents { diff --git a/packages/typegen/src/templates/query.hbs b/packages/typegen/src/templates/query.hbs index 8e6b8ea96d..8c8a40ff9a 100644 --- a/packages/typegen/src/templates/query.hbs +++ b/packages/typegen/src/templates/query.hbs @@ -2,7 +2,7 @@ {{{ importsRelative }}} -declare module '@polkadot/api/types/storage' { +declare module '@polkadot/api-augment/query' { {{{ importsPackage }}} export interface AugmentedQueries { diff --git a/packages/typegen/src/templates/tx.hbs b/packages/typegen/src/templates/tx.hbs index 5df57fc784..3c46bd4b4d 100644 --- a/packages/typegen/src/templates/tx.hbs +++ b/packages/typegen/src/templates/tx.hbs @@ -2,7 +2,7 @@ {{{ importsRelative }}} -declare module '@polkadot/api/types/submittable' { +declare module '@polkadot/api-augment/tx' { {{{ importsPackage }}} export interface AugmentedSubmittables { diff --git a/tsconfig.full.json b/tsconfig.full.json new file mode 100644 index 0000000000..5739c52b56 --- /dev/null +++ b/tsconfig.full.json @@ -0,0 +1,12 @@ +{ + "extends": "./tsconfig.base.json", + "exclude": [ + "build/**/*", + "**/build/**/*" + ], + "compilerOptions": { + "composite": false, + "baseUrl": "./packages", + "outDir": "./build" + } +} diff --git a/yarn.lock b/yarn.lock index bcb89c76c8..14cbf7727b 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1908,6 +1908,11 @@ __metadata: dependencies: "@babel/runtime": ^7.16.5 "@polkadot/api": 6.12.2-12 + "@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 languageName: unknown linkType: soft