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