Remove derive memos (#1538)

* Remove derive memos

* Remove outer memo

* Over-eager replace
This commit is contained in:
Jaco Greeff
2019-11-03 11:38:36 +01:00
committed by GitHub
parent 0e037de1b1
commit 506b042f8c
44 changed files with 273 additions and 305 deletions
+1 -1
View File
@@ -32,6 +32,6 @@
"@polkadot/types": "^0.96.0-beta.23" "@polkadot/types": "^0.96.0-beta.23"
}, },
"devDependencies": { "devDependencies": {
"@polkadot/keyring": "^1.6.1" "@polkadot/keyring": "^1.7.0-beta.1"
} }
} }
@@ -13,7 +13,7 @@ import { createType } from '@polkadot/types';
import { idToIndex } from './idToIndex'; import { idToIndex } from './idToIndex';
import { indexToId } from './indexToId'; import { indexToId } from './indexToId';
import { drr, memo } from '../util'; import { drr } from '../util';
interface Calls { interface Calls {
idToIndexCall (accountId: string | AccountId): Observable<AccountIndex | undefined>; idToIndexCall (accountId: string | AccountId): Observable<AccountIndex | undefined>;
@@ -60,13 +60,12 @@ function retrieve (address: Address | AccountId | AccountIndex | string | null |
* }); * });
* ``` * ```
*/ */
export const idAndIndex = memo((api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | string | null) => Observable<AccountIdAndIndex> => { export function idAndIndex (api: ApiInterfaceRx): (address?: Address | AccountId | AccountIndex | string | null) => Observable<AccountIdAndIndex> {
const calls = { const calls = {
idToIndexCall: idToIndex(api), idToIndexCall: idToIndex(api),
indexToIdCall: indexToId(api) indexToIdCall: indexToId(api)
}; };
return memo((address?: Address | AccountId | AccountIndex | string | null): Observable<AccountIdAndIndex> => return (address?: Address | AccountId | AccountIndex | string | null): Observable<AccountIdAndIndex> =>
retrieve(address, calls).pipe(drr()) retrieve(address, calls).pipe(drr());
); }
}, true);
@@ -9,7 +9,7 @@ import { map, startWith } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types'; import { ApiInterfaceRx } from '@polkadot/api/types';
import { indexes, AccountIndexes } from './indexes'; import { indexes, AccountIndexes } from './indexes';
import { drr, memo } from '../util'; import { drr } from '../util';
/** /**
* @name idToIndex * @name idToIndex
@@ -25,16 +25,15 @@ import { drr, memo } from '../util';
* }); * });
* ``` * ```
*/ */
export const idToIndex = memo((api: ApiInterfaceRx): (accountId: AccountId | string) => Observable<AccountIndex | undefined> => { export function idToIndex (api: ApiInterfaceRx): (accountId: AccountId | string) => Observable<AccountIndex | undefined> {
const indexesCall = indexes(api); const indexesCall = indexes(api);
return memo((accountId: AccountId | string): Observable<AccountIndex | undefined> => return (accountId: AccountId | string): Observable<AccountIndex | undefined> =>
indexesCall().pipe( indexesCall().pipe(
startWith({}), startWith({}),
map((indexes: AccountIndexes): AccountIndex | undefined => map((indexes: AccountIndexes): AccountIndex | undefined =>
(indexes || {})[accountId.toString()] (indexes || {})[accountId.toString()]
), ),
drr() drr()
) );
); }
}, true);
+14 -15
View File
@@ -10,7 +10,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
import { ENUMSET_SIZE } from '@polkadot/types/primitive/Generic/AccountIndex'; import { ENUMSET_SIZE } from '@polkadot/types/primitive/Generic/AccountIndex';
import { createType, ClassOf, Vec } from '@polkadot/types'; import { createType, ClassOf, Vec } from '@polkadot/types';
import { drr, memo } from '../util'; import { drr } from '../util';
/** /**
* @name indexToId * @name indexToId
@@ -25,21 +25,20 @@ import { drr, memo } from '../util';
* }); * });
* ``` * ```
*/ */
export const indexToId = memo((api: ApiInterfaceRx): (accountIndex: AccountIndex | string) => Observable<AccountId | undefined> => { export function indexToId (api: ApiInterfaceRx): (accountIndex: AccountIndex | string) => Observable<AccountId | undefined> {
return memo((_accountIndex: AccountIndex | string): Observable<AccountId | undefined> => { const querySection = api.query.indices || api.query.balances;
const querySection = api.query.indices || api.query.balances;
return (_accountIndex: AccountIndex | string): Observable<AccountId | undefined> => {
const accountIndex = _accountIndex instanceof ClassOf('AccountIndex') const accountIndex = _accountIndex instanceof ClassOf('AccountIndex')
? _accountIndex ? _accountIndex
: createType('AccountIndex', _accountIndex); : createType('AccountIndex', _accountIndex);
return querySection return querySection.enumSet<Vec<AccountId>>(accountIndex.div(ENUMSET_SIZE)).pipe(
.enumSet<Vec<AccountId>>(accountIndex.div(ENUMSET_SIZE)) startWith([]),
.pipe( map((accounts): AccountId | undefined =>
startWith([]), (accounts || [])[accountIndex.mod(ENUMSET_SIZE).toNumber()]
map((accounts): AccountId | undefined => ),
(accounts || [])[accountIndex.mod(ENUMSET_SIZE).toNumber()] drr()
), );
drr() };
); }
});
}, true);
+24 -27
View File
@@ -10,7 +10,7 @@ import { map, switchMap } from 'rxjs/operators';
import { ENUMSET_SIZE } from '@polkadot/types/primitive/Generic/AccountIndex'; import { ENUMSET_SIZE } from '@polkadot/types/primitive/Generic/AccountIndex';
import { createType } from '@polkadot/types'; import { createType } from '@polkadot/types';
import { drr, memo } from '../util'; import { drr } from '../util';
export type AccountIndexes = Record<string, AccountIndex>; export type AccountIndexes = Record<string, AccountIndex>;
@@ -31,31 +31,28 @@ const enumsetSize = ENUMSET_SIZE.toNumber();
* }); * });
* ``` * ```
*/ */
export const indexes = memo((api: ApiInterfaceRx): () => Observable<AccountIndexes> => { export function indexes (api: ApiInterfaceRx): () => Observable<AccountIndexes> {
return memo((): Observable<AccountIndexes> => { return (): Observable<AccountIndexes> =>
return api.query.indices api.query.indices.nextEnumSet<AccountIndex>().pipe(
.nextEnumSet<AccountIndex>() // use the nextEnumSet (which is a counter of the number of sets) to construct
.pipe( // a range of values to query [0, 1, 2, ...]. Retrieve the full enum set for the
// use the nextEnumSet (which is a counter of the number of sets) to construct // specific index - each query can return up to ENUMSET_SIZE (64) records, each
// a range of values to query [0, 1, 2, ...]. Retrieve the full enum set for the // containing an AccountId
// specific index - each query can return up to ENUMSET_SIZE (64) records, each switchMap((next: AccountIndex): Observable<any> =>
// containing an AccountId api.query.indices.enumSet.multi([...Array(next.toNumber() + 1).keys()]) as Observable<any>
switchMap((next: AccountIndex): Observable<any> => ),
api.query.indices.enumSet.multi([...Array(next.toNumber() + 1).keys()]) as Observable<any> map((all: (AccountId[] | undefined)[]): AccountIndexes =>
), (all || []).reduce((result, list, outerIndex): AccountIndexes => {
map((all: (AccountId[] | undefined)[]): AccountIndexes => (list || []).forEach((accountId, innerIndex): void => {
(all || []).reduce((result, list, outerIndex): AccountIndexes => { // re-create the index based on position 0 is [0][0] and likewise
(list || []).forEach((accountId, innerIndex): void => { // 64 (0..63 in first) is [1][0] (the first index value in set 2)
// re-create the index based on position 0 is [0][0] and likewise const index = (outerIndex * enumsetSize) + innerIndex;
// 64 (0..63 in first) is [1][0] (the first index value in set 2)
const index = (outerIndex * enumsetSize) + innerIndex;
result[accountId.toString()] = createType('AccountIndex', index); result[accountId.toString()] = createType('AccountIndex', index);
}); });
return result; return result;
}, {} as AccountIndexes)), }, {} as AccountIndexes)),
drr() drr()
); );
}); }
}, true);
+9 -10
View File
@@ -12,7 +12,7 @@ import { map, switchMap } from 'rxjs/operators';
import { Bytes, Option, u32 } from '@polkadot/types'; import { Bytes, Option, u32 } from '@polkadot/types';
import { u8aToString } from '@polkadot/util'; import { u8aToString } from '@polkadot/util';
import { drr, memo } from '../util'; import { drr } from '../util';
import { idAndIndex } from './idAndIndex'; import { idAndIndex } from './idAndIndex';
function retrieveNick (api: ApiInterfaceRx): (accountId?: AccountId) => Observable<Option<[Bytes, Balance] & Codec> | undefined> { function retrieveNick (api: ApiInterfaceRx): (accountId?: AccountId) => Observable<Option<[Bytes, Balance] & Codec> | undefined> {
@@ -26,18 +26,18 @@ function retrieveNick (api: ApiInterfaceRx): (accountId?: AccountId) => Observab
* @name info * @name info
* @description Returns aux. info with regards to an account, current that includes the accountId, accountIndex and nickname * @description Returns aux. info with regards to an account, current that includes the accountId, accountIndex and nickname
*/ */
export const info = memo((api: ApiInterfaceRx): (address?: AccountIndex | AccountId | Address | string | null) => Observable<DeriveAccountInfo> => { export function info (api: ApiInterfaceRx): (address?: AccountIndex | AccountId | Address | string | null) => Observable<DeriveAccountInfo> {
const idAndIndexCall = idAndIndex(api); const idAndIndexCall = idAndIndex(api);
const nickCall = retrieveNick(api); const nickCall = retrieveNick(api);
return memo((address?: AccountIndex | AccountId | Address | string | null): Observable<DeriveAccountInfo> => return (address?: AccountIndex | AccountId | Address | string | null): Observable<DeriveAccountInfo> =>
idAndIndexCall(address).pipe( idAndIndexCall(address).pipe(
switchMap(([accountId, accountIndex]): Observable<[DeriveAccountInfo, Option<[Bytes, Balance] & Codec>?]> => { switchMap(([accountId, accountIndex]): Observable<[DeriveAccountInfo, Option<[Bytes, Balance] & Codec>?]> =>
return combineLatest([ combineLatest([
of({ accountId, accountIndex }), of({ accountId, accountIndex }),
nickCall(accountId) nickCall(accountId)
]); ])
}), ),
map(([{ accountId, accountIndex }, nameOf]): DeriveAccountInfo => ({ map(([{ accountId, accountIndex }, nameOf]): DeriveAccountInfo => ({
accountId, accountId,
accountIndex, accountIndex,
@@ -46,6 +46,5 @@ export const info = memo((api: ApiInterfaceRx): (address?: AccountIndex | Accoun
: undefined : undefined
})), })),
drr() drr()
) );
); }
}, true);
+5 -5
View File
@@ -14,7 +14,7 @@ import { bnMax } from '@polkadot/util';
import { info } from '../accounts/info'; import { info } from '../accounts/info';
import { bestNumber } from '../chain/bestNumber'; import { bestNumber } from '../chain/bestNumber';
import { DerivedBalances } from '../types'; import { DerivedBalances } from '../types';
import { drr, memo } from '../util'; import { drr } from '../util';
type ResultBalance = [Balance, Balance, BalanceLock[], Option<VestingSchedule>]; type ResultBalance = [Balance, Balance, BalanceLock[], Option<VestingSchedule>];
type Result = [AccountId, BlockNumber, ResultBalance, Index]; type Result = [AccountId, BlockNumber, ResultBalance, Index];
@@ -77,11 +77,11 @@ function queryBalances (api: ApiInterfaceRx, accountId: AccountId): Observable<R
* }); * });
* ``` * ```
*/ */
export const all = memo((api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable<DerivedBalances> => { export function all (api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable<DerivedBalances> {
const bestNumberCall = bestNumber(api); const bestNumberCall = bestNumber(api);
const infoCall = info(api); const infoCall = info(api);
return memo((address: AccountIndex | AccountId | Address | string): Observable<DerivedBalances> => { return (address: AccountIndex | AccountId | Address | string): Observable<DerivedBalances> => {
return infoCall(address).pipe( return infoCall(address).pipe(
switchMap(({ accountId }): Observable<Result> => switchMap(({ accountId }): Observable<Result> =>
(accountId (accountId
@@ -102,5 +102,5 @@ export const all = memo((api: ApiInterfaceRx): (address: AccountIndex | AccountI
map(calcBalances), map(calcBalances),
drr() drr()
); );
}); };
}, true); }
+10 -10
View File
@@ -9,7 +9,7 @@ import { DerivedFees } from '../types';
import { Observable, of } from 'rxjs'; import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { drr, memo } from '../util'; import { drr } from '../util';
type Result = [Balance, Balance, Balance, Balance, Balance]; type Result = [Balance, Balance, Balance, Balance, Balance];
@@ -51,13 +51,13 @@ function queryV1 (api: ApiInterfaceRx): Observable<Result> {
* }); * });
* ``` * ```
*/ */
export const fees = memo((api: ApiInterfaceRx): () => Observable<DerivedFees> => { export function fees (api: ApiInterfaceRx): () => Observable<DerivedFees> {
return memo((): Observable<DerivedFees> => { const query = api.consts.balances
return ( ? queryV2
api.consts.balances : queryV1;
? queryV2(api)
: queryV1(api) return (): Observable<DerivedFees> => {
).pipe( return query(api).pipe(
map(([creationFee, existentialDeposit, transferFee, transactionBaseFee, transactionByteFee]): DerivedFees => ({ map(([creationFee, existentialDeposit, transferFee, transactionBaseFee, transactionByteFee]): DerivedFees => ({
creationFee, creationFee,
existentialDeposit, existentialDeposit,
@@ -67,5 +67,5 @@ export const fees = memo((api: ApiInterfaceRx): () => Observable<DerivedFees> =>
})), })),
drr() drr()
); );
}); };
}, true); }
@@ -8,11 +8,11 @@ import { combineLatest, Observable, of } from 'rxjs';
import { ApiInterfaceRx } from '@polkadot/api/types'; import { ApiInterfaceRx } from '@polkadot/api/types';
import { DerivedBalances } from '../types'; import { DerivedBalances } from '../types';
import { drr, memo } from '../util'; import { drr } from '../util';
import { all } from './all'; import { all } from './all';
export const votingBalances = memo((api: ApiInterfaceRx): (addresses?: (AccountId | AccountIndex | Address | string)[]) => Observable<DerivedBalances[]> => { export function votingBalances (api: ApiInterfaceRx): (addresses?: (AccountId | AccountIndex | Address | string)[]) => Observable<DerivedBalances[]> {
return memo((addresses?: (AccountId | AccountIndex | Address | string)[]): Observable<DerivedBalances[]> => { return (addresses?: (AccountId | AccountIndex | Address | string)[]): Observable<DerivedBalances[]> => {
return ( return (
!addresses || !addresses.length !addresses || !addresses.length
? of([] as DerivedBalances[]) ? of([] as DerivedBalances[])
@@ -20,5 +20,5 @@ export const votingBalances = memo((api: ApiInterfaceRx): (addresses?: (AccountI
).pipe( ).pipe(
drr() drr()
); );
}); };
}, true); }
@@ -11,13 +11,13 @@ import { Vec } from '@polkadot/types';
import { info } from '../accounts/info'; import { info } from '../accounts/info';
import { DerivedBalances } from '../types'; import { DerivedBalances } from '../types';
import { drr, memo } from '../util'; import { drr } from '../util';
import { votingBalances } from './votingBalances'; import { votingBalances } from './votingBalances';
export const votingBalancesNominatorsFor = memo((api: ApiInterfaceRx): (address: AccountId | AccountIndex | Address | string) => Observable<DerivedBalances[]> => { export function votingBalancesNominatorsFor (api: ApiInterfaceRx): (address: AccountId | AccountIndex | Address | string) => Observable<DerivedBalances[]> {
const infoCall = info(api); const infoCall = info(api);
return memo((address: AccountId | AccountIndex | Address | string): Observable<DerivedBalances[]> => { return (address: AccountId | AccountIndex | Address | string): Observable<DerivedBalances[]> => {
return infoCall(address).pipe( return infoCall(address).pipe(
switchMap(({ accountId }): Observable<AccountId[]> => switchMap(({ accountId }): Observable<AccountId[]> =>
accountId accountId
@@ -27,5 +27,5 @@ export const votingBalancesNominatorsFor = memo((api: ApiInterfaceRx): (address:
switchMap(votingBalances(api)), switchMap(votingBalances(api)),
drr() drr()
); );
}); };
}, true); }
+5 -6
View File
@@ -8,7 +8,7 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types'; import { ApiInterfaceRx } from '@polkadot/api/types';
import { drr, memo } from '../util'; import { drr } from '../util';
/** /**
* @name bestNumber * @name bestNumber
@@ -22,11 +22,10 @@ import { drr, memo } from '../util';
* }); * });
* ``` * ```
*/ */
export const bestNumber = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => { export function bestNumber (api: ApiInterfaceRx): () => Observable<BlockNumber> {
return memo((): Observable<BlockNumber> => return (): Observable<BlockNumber> =>
api.rpc.chain.subscribeNewHeads().pipe( api.rpc.chain.subscribeNewHeads().pipe(
map((header): BlockNumber => header.number.unwrap()), map((header): BlockNumber => header.number.unwrap()),
drr() drr()
) );
); }
}, true);
@@ -8,7 +8,7 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types'; import { ApiInterfaceRx } from '@polkadot/api/types';
import { drr, memo } from '../util'; import { drr } from '../util';
/** /**
* @name bestNumberFinalized * @name bestNumberFinalized
@@ -23,11 +23,10 @@ import { drr, memo } from '../util';
* }); * });
* ``` * ```
*/ */
export const bestNumberFinalized = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => { export function bestNumberFinalized (api: ApiInterfaceRx): () => Observable<BlockNumber> {
return memo((): Observable<BlockNumber> => return (): Observable<BlockNumber> =>
api.rpc.chain.subscribeFinalizedHeads().pipe( api.rpc.chain.subscribeFinalizedHeads().pipe(
map((header): BlockNumber => header.number.unwrap()), map((header): BlockNumber => header.number.unwrap()),
drr() drr()
) );
); }
}, true);
@@ -9,7 +9,7 @@ import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types'; import { ApiInterfaceRx } from '@polkadot/api/types';
import { createType } from '@polkadot/types'; import { createType } from '@polkadot/types';
import { drr, memo } from '../util'; import { drr } from '../util';
import { bestNumber } from './bestNumber'; import { bestNumber } from './bestNumber';
import { bestNumberFinalized } from './bestNumberFinalized'; import { bestNumberFinalized } from './bestNumberFinalized';
@@ -26,11 +26,11 @@ import { bestNumberFinalized } from './bestNumberFinalized';
* }); * });
* ``` * ```
*/ */
export const bestNumberLag = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => { export function bestNumberLag (api: ApiInterfaceRx): () => Observable<BlockNumber> {
const bestNumberCall = bestNumber(api); const bestNumberCall = bestNumber(api);
const bestNumberFinalizedCall = bestNumberFinalized(api); const bestNumberFinalizedCall = bestNumberFinalized(api);
return memo((): Observable<BlockNumber> => return (): Observable<BlockNumber> =>
combineLatest([ combineLatest([
bestNumberCall(), bestNumberCall(),
bestNumberFinalizedCall() bestNumberFinalizedCall()
@@ -39,6 +39,5 @@ export const bestNumberLag = memo((api: ApiInterfaceRx): () => Observable<BlockN
createType('BlockNumber', bestNumber.sub(bestNumberFinalized)) createType('BlockNumber', bestNumber.sub(bestNumberFinalized))
), ),
drr() drr()
) );
); }
}, true);
+5 -6
View File
@@ -11,7 +11,7 @@ import { catchError, map } from 'rxjs/operators';
import { Vec } from '@polkadot/types'; import { Vec } from '@polkadot/types';
import { HeaderExtended } from '../type'; import { HeaderExtended } from '../type';
import { drr, memo } from '../util'; import { drr } from '../util';
/** /**
* @name bestNumberFinalized * @name bestNumberFinalized
@@ -27,8 +27,8 @@ import { drr, memo } from '../util';
* console.log(`block #${number} was authored by ${author}`); * console.log(`block #${number} was authored by ${author}`);
* ``` * ```
*/ */
export const getHeader = memo((api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<HeaderExtended | undefined> => { export function getHeader (api: ApiInterfaceRx): (hash: Uint8Array | string) => Observable<HeaderExtended | undefined> {
return memo((hash: Uint8Array | string): Observable<HeaderExtended | undefined> => return (hash: Uint8Array | string): Observable<HeaderExtended | undefined> =>
combineLatest([ combineLatest([
api.rpc.chain.getHeader(hash), api.rpc.chain.getHeader(hash),
api.query.session.validators.at(hash) as Observable<Vec<AccountId>> api.query.session.validators.at(hash) as Observable<Vec<AccountId>>
@@ -43,6 +43,5 @@ export const getHeader = memo((api: ApiInterfaceRx): (hash: Uint8Array | string)
of() of()
), ),
drr() drr()
) );
); }
}, true);
@@ -10,7 +10,7 @@ import { map } from 'rxjs/operators';
import { Vec } from '@polkadot/types'; import { Vec } from '@polkadot/types';
import { HeaderExtended } from '../type'; import { HeaderExtended } from '../type';
import { drr, memo } from '../util'; import { drr } from '../util';
/** /**
* @name subscribeNewHeads * @name subscribeNewHeads
@@ -25,8 +25,8 @@ import { drr, memo } from '../util';
* }); * });
* ``` * ```
*/ */
export const subscribeNewHeads = memo((api: ApiInterfaceRx): () => Observable<HeaderExtended> => { export function subscribeNewHeads (api: ApiInterfaceRx): () => Observable<HeaderExtended> {
return memo((): Observable<HeaderExtended> => return (): Observable<HeaderExtended> =>
combineLatest([ combineLatest([
api.rpc.chain.subscribeNewHeads(), api.rpc.chain.subscribeNewHeads(),
api.query.session.validators<Vec<AccountId>>() api.query.session.validators<Vec<AccountId>>()
@@ -35,6 +35,5 @@ export const subscribeNewHeads = memo((api: ApiInterfaceRx): () => Observable<He
new HeaderExtended(header, validators) new HeaderExtended(header, validators)
), ),
drr() drr()
) );
); }
}, true);
+5 -5
View File
@@ -9,7 +9,7 @@ import BN from 'bn.js';
import { Observable, of } from 'rxjs'; import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { drr, memo } from '../util'; import { drr } from '../util';
type ResultV2 = [BN, BN, BN, BN, BN, BN, BN, BN, BN, BN]; type ResultV2 = [BN, BN, BN, BN, BN, BN, BN, BN, BN, BN];
@@ -103,8 +103,8 @@ function queryConstants (api: ApiInterfaceRx): Observable<ResultV2> {
* }); * });
* ``` * ```
*/ */
export const fees = memo((api: ApiInterfaceRx): () => Observable<DerivedContractFees> => { export function fees (api: ApiInterfaceRx): () => Observable<DerivedContractFees> {
return memo((): Observable<DerivedContractFees> => { return (): Observable<DerivedContractFees> => {
if (api.query.contract && !api.query.contract.rentByteFee) { if (api.query.contract && !api.query.contract.rentByteFee) {
return queryV1(api); return queryV1(api);
} }
@@ -122,5 +122,5 @@ export const fees = memo((api: ApiInterfaceRx): () => Observable<DerivedContract
), ),
drr() drr()
); );
}); };
}, true); }
@@ -12,7 +12,7 @@ import { Option } from '@polkadot/types';
import { isNull } from '@polkadot/util'; import { isNull } from '@polkadot/util';
import { ReferendumInfoExtended } from '../type'; import { ReferendumInfoExtended } from '../type';
import { drr, memo } from '../util'; import { drr } from '../util';
export function constructInfo (index: BN | number, optionInfo?: Option<ReferendumInfo>): Option<ReferendumInfoExtended> { export function constructInfo (index: BN | number, optionInfo?: Option<ReferendumInfo>): Option<ReferendumInfoExtended> {
const info = optionInfo const info = optionInfo
@@ -27,8 +27,8 @@ export function constructInfo (index: BN | number, optionInfo?: Option<Referendu
); );
} }
export const referendumInfo = memo((api: ApiInterfaceRx): (index: BN | number) => Observable<Option<ReferendumInfoExtended>> => { export function referendumInfo (api: ApiInterfaceRx): (index: BN | number) => Observable<Option<ReferendumInfoExtended>> {
return memo((index: BN | number): Observable<Option<ReferendumInfoExtended>> => { return (index: BN | number): Observable<Option<ReferendumInfoExtended>> => {
return (api.query.democracy.referendumInfoOf<Option<ReferendumInfo>>(index)) return (api.query.democracy.referendumInfoOf<Option<ReferendumInfo>>(index))
.pipe( .pipe(
map((optionInfo): Option<ReferendumInfoExtended> => map((optionInfo): Option<ReferendumInfoExtended> =>
@@ -36,5 +36,5 @@ export const referendumInfo = memo((api: ApiInterfaceRx): (index: BN | number) =
), ),
drr() drr()
); );
}); };
}, true); }
@@ -11,11 +11,11 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
import { Option, Vec } from '@polkadot/types'; import { Option, Vec } from '@polkadot/types';
import { ReferendumInfoExtended } from '../type'; import { ReferendumInfoExtended } from '../type';
import { drr, memo } from '../util'; import { drr } from '../util';
import { constructInfo } from './referendumInfo'; import { constructInfo } from './referendumInfo';
export const referendumInfos = memo((api: ApiInterfaceRx): (ids?: (BN | number)[]) => Observable<Option<ReferendumInfoExtended>[]> => { export function referendumInfos (api: ApiInterfaceRx): (ids?: (BN | number)[]) => Observable<Option<ReferendumInfoExtended>[]> {
return memo((ids: (BN | number)[] = []): Observable<Option<ReferendumInfoExtended>[]> => { return (ids: (BN | number)[] = []): Observable<Option<ReferendumInfoExtended>[]> => {
return ( return (
!ids || !ids.length !ids || !ids.length
? of([] as Option<ReferendumInfo>[]) ? of([] as Option<ReferendumInfo>[])
@@ -28,5 +28,5 @@ export const referendumInfos = memo((api: ApiInterfaceRx): (ids?: (BN | number)[
), ),
drr() drr()
); );
}); };
}, true); }
@@ -11,16 +11,16 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
import { Vec, createType } from '@polkadot/types'; import { Vec, createType } from '@polkadot/types';
import { DerivedBalances, DerivedReferendumVote } from '../types'; import { DerivedBalances, DerivedReferendumVote } from '../types';
import { drr, memo } from '../util'; import { drr } from '../util';
import { votes } from './votes'; import { votes } from './votes';
import { votingBalances } from '../balances/votingBalances'; import { votingBalances } from '../balances/votingBalances';
export const referendumVotesFor = memo((api: ApiInterfaceRx): (referendumId: BN | number) => Observable<DerivedReferendumVote[]> => { export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | number) => Observable<DerivedReferendumVote[]> {
const votesCall = votes(api); const votesCall = votes(api);
const votingBalancesCall = votingBalances(api); const votingBalancesCall = votingBalances(api);
return memo((referendumId: BN | number): Observable<DerivedReferendumVote[]> => return (referendumId: BN | number): Observable<DerivedReferendumVote[]> =>
(api.query.democracy.votersFor<Vec<AccountId>>(referendumId)).pipe( api.query.democracy.votersFor<Vec<AccountId>>(referendumId).pipe(
switchMap((votersFor): Observable<[Vec<AccountId>, Vote[], DerivedBalances[]]> => switchMap((votersFor): Observable<[Vec<AccountId>, Vote[], DerivedBalances[]]> =>
combineLatest([ combineLatest([
of(votersFor), of(votersFor),
@@ -36,6 +36,5 @@ export const referendumVotesFor = memo((api: ApiInterfaceRx): (referendumId: BN
} as unknown as DerivedReferendumVote)) } as unknown as DerivedReferendumVote))
), ),
drr() drr()
) );
); }
}, true);
@@ -11,17 +11,17 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
import { Option } from '@polkadot/types'; import { Option } from '@polkadot/types';
import { ReferendumInfoExtended } from '../type'; import { ReferendumInfoExtended } from '../type';
import { drr, memo } from '../util'; import { drr } from '../util';
import { referendumInfos } from './referendumInfos'; import { referendumInfos } from './referendumInfos';
export const referendums = memo((api: ApiInterfaceRx): () => Observable<Option<ReferendumInfoExtended>[]> => { export function referendums (api: ApiInterfaceRx): () => Observable<Option<ReferendumInfoExtended>[]> {
const referendumInfosCall = referendumInfos(api); const referendumInfosCall = referendumInfos(api);
return memo((): Observable<Option<ReferendumInfoExtended>[]> => return (): Observable<Option<ReferendumInfoExtended>[]> =>
(api.queryMulti([ api.queryMulti<[ReferendumIndex, ReferendumIndex]>([
api.query.democracy.nextTally, api.query.democracy.nextTally,
api.query.democracy.referendumCount api.query.democracy.referendumCount
]) as Observable<[ReferendumIndex?, ReferendumIndex?]>).pipe( ]).pipe(
switchMap(([nextTally, referendumCount]): Observable<Option<ReferendumInfoExtended>[]> => switchMap(([nextTally, referendumCount]): Observable<Option<ReferendumInfoExtended>[]> =>
referendumCount && nextTally && referendumCount.gt(nextTally) && referendumCount.gtn(0) referendumCount && nextTally && referendumCount.gt(nextTally) && referendumCount.gtn(0)
? referendumInfosCall( ? referendumInfosCall(
@@ -32,6 +32,5 @@ export const referendums = memo((api: ApiInterfaceRx): () => Observable<Option<R
: of([]) : of([])
), ),
drr() drr()
) );
); }
}, true);
+5 -5
View File
@@ -9,10 +9,10 @@ import { Observable, of } from 'rxjs';
import { ApiInterfaceRx } from '@polkadot/api/types'; import { ApiInterfaceRx } from '@polkadot/api/types';
import { Vec } from '@polkadot/types'; import { Vec } from '@polkadot/types';
import { drr, memo } from '../util'; import { drr } from '../util';
export const votes = memo((api: ApiInterfaceRx): (referendumId: BN, accountIds?: AccountId[]) => Observable<Vote[]> => { export function votes (api: ApiInterfaceRx): (referendumId: BN, accountIds?: AccountId[]) => Observable<Vote[]> {
return memo((referendumId: BN, accountIds: AccountId[] = []): Observable<Vote[]> => { return (referendumId: BN, accountIds: AccountId[] = []): Observable<Vote[]> => {
return (( return ((
!accountIds || !accountIds.length !accountIds || !accountIds.length
? of([]) ? of([])
@@ -22,5 +22,5 @@ export const votes = memo((api: ApiInterfaceRx): (referendumId: BN, accountIds?:
) )
) )
) as Observable<Vec<Vote>>).pipe(drr()); ) as Observable<Vec<Vote>>).pipe(drr());
}); };
}, true); }
@@ -9,7 +9,7 @@ import { Observable } from 'rxjs';
import { Vec } from '@polkadot/types'; import { Vec } from '@polkadot/types';
import { switchMap, map } from 'rxjs/operators'; import { switchMap, map } from 'rxjs/operators';
import { approvalFlagsToBools } from '../util/approvalFlagsToBools'; import { approvalFlagsToBools } from '../util/approvalFlagsToBools';
import { drr, memo } from '../util'; import { drr } from '../util';
/** /**
* @name approvalsOf * @name approvalsOf
@@ -23,8 +23,8 @@ import { drr, memo } from '../util';
* }); * });
* ``` * ```
*/ */
export const approvalsOf = memo((api: ApiInterfaceRx): (who: AccountId) => Observable<boolean[][]> => { export function approvalsOf (api: ApiInterfaceRx): (who: AccountId) => Observable<boolean[][]> {
return memo((who: AccountId | string): Observable<boolean[][]> => return (who: AccountId | string): Observable<boolean[][]> =>
api.query.elections.nextVoterSet<SetIndex>().pipe( api.query.elections.nextVoterSet<SetIndex>().pipe(
switchMap((nextVoterSet: SetIndex): Observable<Vec<ApprovalFlag>[]> => switchMap((nextVoterSet: SetIndex): Observable<Vec<ApprovalFlag>[]> =>
api.query.elections.approvalsOf.multi( api.query.elections.approvalsOf.multi(
@@ -39,6 +39,5 @@ export const approvalsOf = memo((api: ApiInterfaceRx): (who: AccountId) => Obser
) )
), ),
drr() drr()
) );
); }
}, true);
@@ -11,7 +11,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
import { Vec } from '@polkadot/types'; import { Vec } from '@polkadot/types';
import { approvalFlagsToBools } from '../util/approvalFlagsToBools'; import { approvalFlagsToBools } from '../util/approvalFlagsToBools';
import { drr, memo } from '../util'; import { drr } from '../util';
/** /**
* @name approvalsOfAt * @name approvalsOfAt
@@ -25,11 +25,10 @@ import { drr, memo } from '../util';
* }); * });
* ``` * ```
*/ */
export const approvalsOfAt = memo((api: ApiInterfaceRx): (who: AccountId, at: SetIndex) => Observable<boolean[]> => { export function approvalsOfAt (api: ApiInterfaceRx): (who: AccountId, at: SetIndex) => Observable<boolean[]> {
return memo((who: AccountId | string, at: SetIndex | BN | number): Observable<boolean[]> => return (who: AccountId | string, at: SetIndex | BN | number): Observable<boolean[]> =>
api.query.elections.approvalsOf<Vec<ApprovalFlag>>([who.toString(), at]).pipe( api.query.elections.approvalsOf<Vec<ApprovalFlag>>([who.toString(), at]).pipe(
map((flags: Vec<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags)), map((flags: Vec<ApprovalFlag>): boolean[] => approvalFlagsToBools(flags)),
drr() drr()
) );
); }
}, true);
+5 -6
View File
@@ -11,7 +11,7 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
import { createType, Vec, u32 } from '@polkadot/types'; import { createType, Vec, u32 } from '@polkadot/types';
import { DerivedElectionsInfo } from '../types'; import { DerivedElectionsInfo } from '../types';
import { drr, memo } from '../util'; import { drr } from '../util';
type ResultElectionsInner = [u32, u32, Vec<[AccountId, BlockNumber] & Codec>, SetIndex, BlockNumber, VoteIndex, SetIndex]; type ResultElectionsInner = [u32, u32, Vec<[AccountId, BlockNumber] & Codec>, SetIndex, BlockNumber, VoteIndex, SetIndex];
type ResultElections = [Vec<AccountId>, ResultElectionsInner]; type ResultElections = [Vec<AccountId>, ResultElectionsInner];
@@ -89,10 +89,9 @@ function queryPhragmen (api: ApiInterfaceRx): Observable<DerivedElectionsInfo> {
* }); * });
* ``` * ```
*/ */
export const info = memo((api: ApiInterfaceRx): () => Observable<DerivedElectionsInfo> => { export function info (api: ApiInterfaceRx): () => Observable<DerivedElectionsInfo> {
return memo((): Observable<DerivedElectionsInfo> => { return (): Observable<DerivedElectionsInfo> =>
return api.query.electionsPhragmen api.query.electionsPhragmen
? queryPhragmen(api) ? queryPhragmen(api)
: queryElections(api); : queryElections(api);
}); }
}, true);
@@ -11,7 +11,7 @@ import BN from 'bn.js';
import { of, combineLatest, Observable } from 'rxjs'; import { of, combineLatest, Observable } from 'rxjs';
import { switchMap, map } from 'rxjs/operators'; import { switchMap, map } from 'rxjs/operators';
import { drr, memo } from '../util'; import { drr } from '../util';
/** /**
* @name voterPositions * @name voterPositions
@@ -26,8 +26,8 @@ import { drr, memo } from '../util';
* }); * });
* ``` * ```
*/ */
export const voterPositions = memo((api: ApiInterfaceRx): () => Observable<DerivedVoterPositions> => { export function voterPositions (api: ApiInterfaceRx): () => Observable<DerivedVoterPositions> {
return memo((): Observable<DerivedVoterPositions> => return (): Observable<DerivedVoterPositions> =>
api.query.elections.nextVoterSet<SetIndex>().pipe( api.query.elections.nextVoterSet<SetIndex>().pipe(
switchMap((nextVoterSet: SetIndex): Observable<[BN, Vec<Option<AccountId>>[]]> => combineLatest( switchMap((nextVoterSet: SetIndex): Observable<[BN, Vec<Option<AccountId>>[]]> => combineLatest(
of(api.consts.elections.voterSetSize) as any as Observable<BN>, of(api.consts.elections.voterSetSize) as any as Observable<BN>,
@@ -54,6 +54,5 @@ export const voterPositions = memo((api: ApiInterfaceRx): () => Observable<Deriv
}, {}); }, {});
}), }),
drr() drr()
) );
); }
}, true);
+12 -14
View File
@@ -10,7 +10,7 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { createType, Vec } from '@polkadot/types'; import { createType, Vec } from '@polkadot/types';
import { drr, memo } from '../util'; import { drr } from '../util';
import { voterPositions } from './voterPositions'; import { voterPositions } from './voterPositions';
/** /**
@@ -25,21 +25,19 @@ import { voterPositions } from './voterPositions';
* }); * });
* ``` * ```
*/ */
export const voters = memo((api: ApiInterfaceRx): () => Observable<Vec<AccountId>> => { export function voters (api: ApiInterfaceRx): () => Observable<Vec<AccountId>> {
const voterPositionsCall = voterPositions(api); const voterPositionsCall = voterPositions(api);
return memo((): Observable<Vec<AccountId>> => return (): Observable<Vec<AccountId>> =>
voterPositionsCall().pipe( voterPositionsCall().pipe(
map( map((voterPositions: DerivedVoterPositions): Vec<AccountId> =>
(voterPositions: DerivedVoterPositions): Vec<AccountId> => createType(
createType( 'Vec<AccountId>',
'Vec<AccountId>', Object.entries(voterPositions)
Object.entries(voterPositions) .sort((a, b): number => a[1].globalIndex.cmp(b[1].globalIndex))
.sort((a, b): 0 | 1 | -1 => a[1].globalIndex.cmp(b[1].globalIndex)) .map(([accountId]): AccountId => createType('AccountId', accountId))
.map(([accountId]): AccountId => createType('AccountId', accountId)) )
)
), ),
drr() drr()
) );
); }
}, true);
@@ -11,15 +11,15 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
import { Bytes, Option, u32 } from '@polkadot/types'; import { Bytes, Option, u32 } from '@polkadot/types';
import { overview as stakingOverview } from '../staking'; import { overview as stakingOverview } from '../staking';
import { drr, memo } from '../util'; import { drr } from '../util';
/** /**
* @description Return a boolean array indicating whether the passed accounts had received heartbeats in the current session * @description Return a boolean array indicating whether the passed accounts had received heartbeats in the current session
*/ */
export const receivedHeartbeats = memo((api: ApiInterfaceRx): () => Observable<DerivedHeartbeats> => { export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable<DerivedHeartbeats> {
const stakingOverviewvCall = stakingOverview(api); const stakingOverviewvCall = stakingOverview(api);
return memo((): Observable<DerivedHeartbeats> => { return (): Observable<DerivedHeartbeats> => {
return api.query.imOnline && api.query.imOnline.receivedHeartbeats && api.query.imOnline.authoredBlocks return api.query.imOnline && api.query.imOnline.receivedHeartbeats && api.query.imOnline.authoredBlocks
? stakingOverviewvCall().pipe( ? stakingOverviewvCall().pipe(
switchMap(({ currentIndex, validators }): Observable<[AccountId[], Option<Bytes>[], u32[]]> => switchMap(({ currentIndex, validators }): Observable<[AccountId[], Option<Bytes>[], u32[]]> =>
@@ -42,5 +42,5 @@ export const receivedHeartbeats = memo((api: ApiInterfaceRx): () => Observable<D
drr() drr()
) )
: of({}); : of({});
}); };
}, true); }
+5 -6
View File
@@ -8,16 +8,15 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types'; import { ApiInterfaceRx } from '@polkadot/api/types';
import { drr, memo } from '../util'; import { drr } from '../util';
import { info } from './info'; import { info } from './info';
export const eraLength = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => { export function eraLength (api: ApiInterfaceRx): () => Observable<BlockNumber> {
const infoCall = info(api); const infoCall = info(api);
return memo((): Observable<BlockNumber> => return (): Observable<BlockNumber> =>
infoCall().pipe( infoCall().pipe(
map(({ eraLength }): BlockNumber => eraLength), map(({ eraLength }): BlockNumber => eraLength),
drr() drr()
) );
); }
}, true);
@@ -8,16 +8,15 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types'; import { ApiInterfaceRx } from '@polkadot/api/types';
import { drr, memo } from '../util'; import { drr } from '../util';
import { info } from './info'; import { info } from './info';
export const eraProgress = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => { export function eraProgress (api: ApiInterfaceRx): () => Observable<BlockNumber> {
const infoCall = info(api); const infoCall = info(api);
return memo((): Observable<BlockNumber> => return (): Observable<BlockNumber> =>
infoCall().pipe( infoCall().pipe(
map(({ eraProgress }): BlockNumber => eraProgress), map(({ eraProgress }): BlockNumber => eraProgress),
drr() drr()
) );
); }
}, true);
+5 -6
View File
@@ -10,10 +10,10 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { u32 } from '@polkadot/types'; import { u32 } from '@polkadot/types';
import { drr, memo } from '../util'; import { drr } from '../util';
export const indexes = memo((api: ApiInterfaceRx): () => Observable<DeriveSessionIndexes> => { export function indexes (api: ApiInterfaceRx): () => Observable<DeriveSessionIndexes> {
return memo((): Observable<DeriveSessionIndexes> => return (): Observable<DeriveSessionIndexes> =>
api.queryMulti<[SessionIndex, EraIndex, u32]>([ api.queryMulti<[SessionIndex, EraIndex, u32]>([
api.query.session.currentIndex, api.query.session.currentIndex,
api.query.staking.currentEra, api.query.staking.currentEra,
@@ -23,6 +23,5 @@ export const indexes = memo((api: ApiInterfaceRx): () => Observable<DeriveSessio
currentIndex, currentEra, validatorCount currentIndex, currentEra, validatorCount
})), })),
drr() drr()
) );
); }
}, true);
+13 -16
View File
@@ -10,7 +10,7 @@ import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types'; import { ApiInterfaceRx } from '@polkadot/api/types';
import { Option, u64, createType } from '@polkadot/types'; import { Option, u64, createType } from '@polkadot/types';
import { drr, memo } from '../util'; import { drr } from '../util';
import { bestNumber } from '../chain'; import { bestNumber } from '../chain';
import { indexes } from './indexes'; import { indexes } from './indexes';
@@ -88,8 +88,7 @@ function infoV1 (api: ApiInterfaceRx, { bestNumberCall, indexesCall }: Calls): O
api.query.staking.sessionsPerEra api.query.staking.sessionsPerEra
]) ])
]).pipe( ]).pipe(
map(createDerivedV1), map(createDerivedV1)
drr()
); );
} }
@@ -101,8 +100,7 @@ function infoLatestAura (api: ApiInterfaceRx, { indexesCall }: Calls): Observabl
indexes, indexes,
[createType('u64', 1), createType('u64', 1), createType('u64', 1), createType('SessionIndex', 1)] [createType('u64', 1), createType('u64', 1), createType('u64', 1), createType('SessionIndex', 1)]
]) ])
), )
drr()
); );
} }
@@ -122,25 +120,24 @@ function infoLatestBabe (api: ApiInterfaceRx, { indexesCall }: Calls): Observabl
indexes, indexes,
slots slots
]) ])
), )
drr()
); );
} }
/** /**
* @description Retrieves all the session and era info and calculates specific values on it as the length of the session and eras * @description Retrieves all the session and era info and calculates specific values on it as the length of the session and eras
*/ */
export const info = memo((api: ApiInterfaceRx): () => Observable<DerivedSessionInfo> => { export function info (api: ApiInterfaceRx): () => Observable<DerivedSessionInfo> {
const calls = { const calls = {
bestNumberCall: bestNumber(api), bestNumberCall: bestNumber(api),
indexesCall: indexes(api) indexesCall: indexes(api)
}; };
const query = api.consts.staking
? api.consts.babe
? infoLatestBabe // 2.x with Babe
: infoLatestAura // 2.x with Aura (not all info there)
: infoV1;
return memo((): Observable<DerivedSessionInfo> => { return (): Observable<DerivedSessionInfo> =>
return api.consts.staking query(api, calls).pipe(drr());
? api.consts.babe }
? infoLatestBabe(api, calls) // 2.x with Babe
: infoLatestAura(api, calls) // 2.x with Aura (not all info there)
: infoV1(api, calls); // 1.x
});
}, true);
@@ -8,16 +8,15 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types'; import { ApiInterfaceRx } from '@polkadot/api/types';
import { drr, memo } from '../util'; import { drr } from '../util';
import { info } from './info'; import { info } from './info';
export const sessionProgress = memo((api: ApiInterfaceRx): () => Observable<BlockNumber> => { export function sessionProgress (api: ApiInterfaceRx): () => Observable<BlockNumber> {
const infoCall = info(api); const infoCall = info(api);
return memo((): Observable<BlockNumber> => return (): Observable<BlockNumber> =>
infoCall().pipe( infoCall().pipe(
map(({ sessionProgress }): BlockNumber => sessionProgress), map(({ sessionProgress }): BlockNumber => sessionProgress),
drr() drr()
) );
); }
}, true);
@@ -10,13 +10,13 @@ import { Observable, combineLatest, of } from 'rxjs';
import { switchMap } from 'rxjs/operators'; import { switchMap } from 'rxjs/operators';
import { Option } from '@polkadot/types'; import { Option } from '@polkadot/types';
import { drr, memo } from '../util'; import { drr } from '../util';
/** /**
* @description From the list of stash accounts, retrieve the list of controllers * @description From the list of stash accounts, retrieve the list of controllers
*/ */
export const controllers = memo((api: ApiInterfaceRx): () => Observable<[AccountId[], Option<AccountId>[]]> => { export function controllers (api: ApiInterfaceRx): () => Observable<[AccountId[], Option<AccountId>[]]> {
return memo((): Observable<[AccountId[], Option<AccountId>[]]> => return (): Observable<[AccountId[], Option<AccountId>[]]> =>
api.query.staking.validators<[AccountId[]] & Codec>().pipe( api.query.staking.validators<[AccountId[]] & Codec>().pipe(
switchMap(([stashIds]): Observable<[AccountId[], Option<AccountId>[]]> => switchMap(([stashIds]): Observable<[AccountId[], Option<AccountId>[]]> =>
combineLatest([ combineLatest([
@@ -28,6 +28,5 @@ export const controllers = memo((api: ApiInterfaceRx): () => Observable<[Account
]) ])
), ),
drr() drr()
) );
); }
}, true);
+5 -5
View File
@@ -18,7 +18,7 @@ import { isUndefined } from '@polkadot/util';
import { bestNumber } from '../chain/bestNumber'; import { bestNumber } from '../chain/bestNumber';
import { eraLength } from '../session/eraLength'; import { eraLength } from '../session/eraLength';
import { recentlyOffline } from './recentlyOffline'; import { recentlyOffline } from './recentlyOffline';
import { drr, memo } from '../util'; import { drr } from '../util';
interface Calls { interface Calls {
bestNumberCall (): Observable<BlockNumber>; bestNumberCall (): Observable<BlockNumber>;
@@ -224,18 +224,18 @@ function retrieveV2 (api: ApiInterfaceRx, calls: Calls, stashId: AccountId): Obs
/** /**
* @description From a stash, retrieve the controllerId and fill in all the relevant staking details * @description From a stash, retrieve the controllerId and fill in all the relevant staking details
*/ */
export const info = memo((api: ApiInterfaceRx): (_accountId: Uint8Array | string) => Observable<DerivedStaking> => { export function info (api: ApiInterfaceRx): (_accountId: Uint8Array | string) => Observable<DerivedStaking> {
const calls = { const calls = {
eraLengthCall: eraLength(api), eraLengthCall: eraLength(api),
bestNumberCall: bestNumber(api), bestNumberCall: bestNumber(api),
recentlyOfflineCall: recentlyOffline(api) recentlyOfflineCall: recentlyOffline(api)
}; };
return memo((_accountId: Uint8Array | string): Observable<DerivedStaking> => { return (_accountId: Uint8Array | string): Observable<DerivedStaking> => {
const accountId = createType('AccountId', _accountId); const accountId = createType('AccountId', _accountId);
return api.consts.session return api.consts.session
? retrieveV2(api, calls, accountId) ? retrieveV2(api, calls, accountId)
: retrieveV1(api, calls, accountId); : retrieveV1(api, calls, accountId);
}); };
}, true); }
+9 -10
View File
@@ -11,7 +11,7 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { Option, Vec } from '@polkadot/types'; import { Option, Vec } from '@polkadot/types';
import { drr, memo } from '../util'; import { drr } from '../util';
// NOTE Unused ATM, preparing for V2-only // NOTE Unused ATM, preparing for V2-only
@@ -52,15 +52,14 @@ function retrieveV2 (api: ApiInterfaceRx, stashId: AccountId): Observable<Result
]); ]);
} }
export const infoStash = memo((api: ApiInterfaceRx): (stashId: AccountId) => Observable<DerivedStakingStash> => { export function infoStash (api: ApiInterfaceRx): (stashId: AccountId) => Observable<DerivedStakingStash> {
return memo((stashId: AccountId): Observable<DerivedStakingStash> => { const query = api.consts.session
return ( ? retrieveV2
api.consts.session : retrieveV1;
? retrieveV2(api, stashId)
: retrieveV1(api, stashId) return (stashId: AccountId): Observable<DerivedStakingStash> =>
).pipe( query(api, stashId).pipe(
map((result): DerivedStakingStash => parse(stashId, result)), map((result): DerivedStakingStash => parse(stashId, result)),
drr() drr()
); );
}); }
}, true);
+5 -6
View File
@@ -10,16 +10,16 @@ import { Observable, combineLatest, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators'; import { map, switchMap } from 'rxjs/operators';
import { createType, Vec } from '@polkadot/types'; import { createType, Vec } from '@polkadot/types';
import { drr, memo } from '../util'; import { drr } from '../util';
import { indexes as sessionIndexes } from '../session'; import { indexes as sessionIndexes } from '../session';
/** /**
* @description Retrieve the staking overview, including elected and points earned * @description Retrieve the staking overview, including elected and points earned
*/ */
export const overview = memo((api: ApiInterfaceRx): () => Observable<DerivedStakingOverview> => { export function overview (api: ApiInterfaceRx): () => Observable<DerivedStakingOverview> {
const sessionIndexesCall = sessionIndexes(api); const sessionIndexesCall = sessionIndexes(api);
return memo((): Observable<DerivedStakingOverview> => return (): Observable<DerivedStakingOverview> =>
combineLatest([ combineLatest([
sessionIndexesCall(), sessionIndexesCall(),
api.queryMulti<[Vec<AccountId>, Vec<AccountId>]>([ api.queryMulti<[Vec<AccountId>, Vec<AccountId>]>([
@@ -40,6 +40,5 @@ export const overview = memo((api: ApiInterfaceRx): () => Observable<DerivedStak
currentElected, currentEra, currentIndex, eraPoints, validators, validatorCount currentElected, currentEra, currentIndex, eraPoints, validators, validatorCount
})), })),
drr() drr()
) );
); }
}, true);
@@ -11,7 +11,7 @@ import { map } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types'; import { ApiInterfaceRx } from '@polkadot/api/types';
import { DerivedRecentlyOffline } from '../types'; import { DerivedRecentlyOffline } from '../types';
import { drr, memo } from '../util'; import { drr } from '../util';
type OfflineResult = [AccountId, BlockNumber, BN][] & Codec; type OfflineResult = [AccountId, BlockNumber, BN][] & Codec;
@@ -35,8 +35,8 @@ function expandDerived (recentlyOffline: OfflineResult): DerivedRecentlyOffline
/** /**
* @description Retrieve a keyed record of accounts recently reported to be offline * @description Retrieve a keyed record of accounts recently reported to be offline
*/ */
export const recentlyOffline = memo((api: ApiInterfaceRx): () => Observable<DerivedRecentlyOffline> => { export function recentlyOffline (api: ApiInterfaceRx): () => Observable<DerivedRecentlyOffline> {
return memo((): Observable<DerivedRecentlyOffline> => return (): Observable<DerivedRecentlyOffline> =>
( (
// TODO recentlyOffline has been dropped for 2.x and replaced, figure out the // TODO recentlyOffline has been dropped for 2.x and replaced, figure out the
// replacement as actually use and implement it // replacement as actually use and implement it
@@ -46,6 +46,5 @@ export const recentlyOffline = memo((api: ApiInterfaceRx): () => Observable<Deri
).pipe( ).pipe(
map(expandDerived), map(expandDerived),
drr() drr()
) );
); }
}, true);
@@ -8,19 +8,18 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
import { Observable } from 'rxjs'; import { Observable } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { drr, memo } from '../util'; import { drr } from '../util';
import { overview } from './overview'; import { overview } from './overview';
/** /**
* @description Retrieve latest list of validators * @description Retrieve latest list of validators
*/ */
export const validators = memo((api: ApiInterfaceRx): () => Observable<AccountId[]> => { export function validators (api: ApiInterfaceRx): () => Observable<AccountId[]> {
const overviewCall = overview(api); const overviewCall = overview(api);
return memo((): Observable<AccountId[]> => return (): Observable<AccountId[]> =>
overviewCall().pipe( overviewCall().pipe(
map(({ validators }): AccountId[] => validators), map(({ validators }): AccountId[] => validators),
drr() drr()
) );
); }
}, true);
+3 -3
View File
@@ -28,10 +28,10 @@
"dependencies": { "dependencies": {
"@babel/runtime": "^7.6.3", "@babel/runtime": "^7.6.3",
"@polkadot/types": "^0.96.0-beta.23", "@polkadot/types": "^0.96.0-beta.23",
"@polkadot/util": "^1.6.1", "@polkadot/util": "^1.7.0-beta.1",
"@polkadot/util-crypto": "^1.6.1" "@polkadot/util-crypto": "^1.7.0-beta.1"
}, },
"devDependencies": { "devDependencies": {
"@polkadot/keyring": "^1.6.1" "@polkadot/keyring": "^1.7.0-beta.1"
} }
} }
+3 -3
View File
@@ -29,13 +29,13 @@
"@babel/runtime": "^7.6.3", "@babel/runtime": "^7.6.3",
"@polkadot/api-derive": "^0.96.0-beta.23", "@polkadot/api-derive": "^0.96.0-beta.23",
"@polkadot/api-metadata": "^0.96.0-beta.23", "@polkadot/api-metadata": "^0.96.0-beta.23",
"@polkadot/keyring": "^1.6.1", "@polkadot/keyring": "^1.7.0-beta.1",
"@polkadot/rpc-core": "^0.96.0-beta.23", "@polkadot/rpc-core": "^0.96.0-beta.23",
"@polkadot/rpc-provider": "^0.96.0-beta.23", "@polkadot/rpc-provider": "^0.96.0-beta.23",
"@polkadot/types": "^0.96.0-beta.23", "@polkadot/types": "^0.96.0-beta.23",
"@polkadot/util-crypto": "^1.6.1" "@polkadot/util-crypto": "^1.7.0-beta.1"
}, },
"devDependencies": { "devDependencies": {
"@polkadot/keyring": "^1.6.1" "@polkadot/keyring": "^1.7.0-beta.1"
} }
} }
+1 -1
View File
@@ -30,7 +30,7 @@
"@polkadot/jsonrpc": "^0.96.0-beta.23", "@polkadot/jsonrpc": "^0.96.0-beta.23",
"@polkadot/rpc-provider": "^0.96.0-beta.23", "@polkadot/rpc-provider": "^0.96.0-beta.23",
"@polkadot/types": "^0.96.0-beta.23", "@polkadot/types": "^0.96.0-beta.23",
"@polkadot/util": "^1.6.1", "@polkadot/util": "^1.7.0-beta.1",
"rxjs": "^6.5.3" "rxjs": "^6.5.3"
} }
} }
+3 -3
View File
@@ -28,15 +28,15 @@
"dependencies": { "dependencies": {
"@babel/runtime": "^7.6.3", "@babel/runtime": "^7.6.3",
"@polkadot/api-metadata": "^0.96.0-beta.23", "@polkadot/api-metadata": "^0.96.0-beta.23",
"@polkadot/util": "^1.6.1", "@polkadot/util": "^1.7.0-beta.1",
"@polkadot/util-crypto": "^1.6.1", "@polkadot/util-crypto": "^1.7.0-beta.1",
"@types/nock": "^11.1.0", "@types/nock": "^11.1.0",
"eventemitter3": "^4.0.0", "eventemitter3": "^4.0.0",
"isomorphic-fetch": "^2.2.1", "isomorphic-fetch": "^2.2.1",
"websocket": "^1.0.30" "websocket": "^1.0.30"
}, },
"devDependencies": { "devDependencies": {
"@polkadot/keyring": "^1.6.1", "@polkadot/keyring": "^1.7.0-beta.1",
"mock-socket": "^9.0.2", "mock-socket": "^9.0.2",
"nock": "^11.4.0" "nock": "^11.4.0"
} }
+3 -3
View File
@@ -27,12 +27,12 @@
"homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme", "homepage": "https://github.com/polkadot-js/api/tree/master/packages/types#readme",
"dependencies": { "dependencies": {
"@babel/runtime": "^7.6.3", "@babel/runtime": "^7.6.3",
"@polkadot/util": "^1.6.1", "@polkadot/util": "^1.7.0-beta.1",
"@polkadot/util-crypto": "^1.6.1", "@polkadot/util-crypto": "^1.7.0-beta.1",
"@types/memoizee": "^0.4.3", "@types/memoizee": "^0.4.3",
"memoizee": "^0.4.14" "memoizee": "^0.4.14"
}, },
"devDependencies": { "devDependencies": {
"@polkadot/keyring": "^1.6.1" "@polkadot/keyring": "^1.7.0-beta.1"
} }
} }
+15 -15
View File
@@ -1835,14 +1835,14 @@
typescript "^3.6.4" typescript "^3.6.4"
vuepress "^1.2.0" vuepress "^1.2.0"
"@polkadot/keyring@^1.6.1": "@polkadot/keyring@^1.7.0-beta.1":
version "1.6.1" version "1.7.0-beta.1"
resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-1.6.1.tgz#35966afba142b647b31767e3a349652947c57a90" resolved "https://registry.yarnpkg.com/@polkadot/keyring/-/keyring-1.7.0-beta.1.tgz#b57e006b0233d5ec7630876b1bc282c63aceab37"
integrity sha512-ortPbweoaANKTKZR0JDbO796U6B3JGjj87yZD+ghlFRUWjMjlbP+LOWnfNyXHcI87yxNC23nK3YDv1KCl0eDUQ== integrity sha512-Twh21/kDHy6duT7PCeMKQv/rw0oHD/qSs6Hu3VYTItGXjtQqTntYYT0aRDfY5n3LHJl5uAHfDiqJBm3pCUhgxg==
dependencies: dependencies:
"@babel/runtime" "^7.6.3" "@babel/runtime" "^7.6.3"
"@polkadot/util" "^1.6.1" "@polkadot/util" "^1.7.0-beta.1"
"@polkadot/util-crypto" "^1.6.1" "@polkadot/util-crypto" "^1.7.0-beta.1"
"@polkadot/ts@^0.1.83": "@polkadot/ts@^0.1.83":
version "0.1.83" version "0.1.83"
@@ -1851,13 +1851,13 @@
dependencies: dependencies:
"@types/chrome" "^0.0.91" "@types/chrome" "^0.0.91"
"@polkadot/util-crypto@^1.6.1": "@polkadot/util-crypto@^1.7.0-beta.1":
version "1.6.1" version "1.7.0-beta.1"
resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-1.6.1.tgz#6d924c5eaecbf98f971da1aac69fb60b17a4bf55" resolved "https://registry.yarnpkg.com/@polkadot/util-crypto/-/util-crypto-1.7.0-beta.1.tgz#e0a6b7725b74aacad5e74524d148fa70f2aa2634"
integrity sha512-Dbo5qsIGKO82HpkysFKh9GDY0w6O6tX9h5HPRDy4KIaTaCo3H5QTmxit+hPU9n3PIHsxGhnyPq8q1i2wD/iWYQ== integrity sha512-T5XW8aQLAkikLtbn4+pPhiX6F+5yz9o+3/+Fwbpd6mpfzq608fY7tZyqFKPglulRtKHRTauaqYpbqqFMGpVmRQ==
dependencies: dependencies:
"@babel/runtime" "^7.6.3" "@babel/runtime" "^7.6.3"
"@polkadot/util" "^1.6.1" "@polkadot/util" "^1.7.0-beta.1"
"@polkadot/wasm-crypto" "^0.14.1" "@polkadot/wasm-crypto" "^0.14.1"
"@types/bip39" "^2.4.2" "@types/bip39" "^2.4.2"
"@types/bs58" "^4.0.0" "@types/bs58" "^4.0.0"
@@ -1873,10 +1873,10 @@
tweetnacl "^1.0.1" tweetnacl "^1.0.1"
xxhashjs "^0.2.2" xxhashjs "^0.2.2"
"@polkadot/util@^1.6.1": "@polkadot/util@^1.7.0-beta.1":
version "1.6.1" version "1.7.0-beta.1"
resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-1.6.1.tgz#8110c12a1670e564c5d6a1c19347cbb0dba8a3ce" resolved "https://registry.yarnpkg.com/@polkadot/util/-/util-1.7.0-beta.1.tgz#a3528b357548d7b916edded02b1d6e9db180ade7"
integrity sha512-uKRfapAXwZMcWQ24MdV+zg8jrYtidbKxJhUbq0G77Yy27d45OID8d+JcI3Q+d6d2pmC/h733iSeCqdiLYCKqMw== integrity sha512-5n0A+DgA8odmnft8bZm8o62Oly2ZmbAou3DWmu6AWrkjGrCUN1To95GBd10OwsH3sYh1iO0ZuZg8VlFJuaoKOw==
dependencies: dependencies:
"@babel/runtime" "^7.6.3" "@babel/runtime" "^7.6.3"
"@types/bn.js" "^4.11.5" "@types/bn.js" "^4.11.5"