Use asyncScheduler for all derives (#2043)
This commit is contained in:
@@ -7,7 +7,6 @@ import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { createType } from '@polkadot/types';
|
||||
import { isU8a } from '@polkadot/util';
|
||||
import { decodeAddress } from '@polkadot/util-crypto';
|
||||
|
||||
@@ -23,14 +22,14 @@ function retrieve (api: ApiInterfaceRx, address: Address | AccountId | AccountIn
|
||||
: decodeAddress((address || '').toString());
|
||||
|
||||
if (decoded.length === 32) {
|
||||
const accountId = createType(api.registry, 'AccountId', decoded);
|
||||
const accountId = api.registry.createType('AccountId', decoded);
|
||||
|
||||
return api.derive.accounts.idToIndex(accountId).pipe(
|
||||
map((accountIndex): AccountIdAndIndex => [accountId, accountIndex])
|
||||
);
|
||||
}
|
||||
|
||||
const accountIndex = createType(api.registry, 'AccountIndex', decoded);
|
||||
const accountIndex = api.registry.createType('AccountIndex', decoded);
|
||||
|
||||
return api.derive.accounts.indexToId(accountIndex).pipe(
|
||||
map((accountId): AccountIdAndIndex => [accountId, accountIndex])
|
||||
|
||||
@@ -9,14 +9,14 @@ import { Observable, of } from 'rxjs';
|
||||
import { map, startWith } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/generic/AccountIndex';
|
||||
import { Option, Vec, createType } from '@polkadot/types';
|
||||
import { Option, Vec } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function queryEnumSet (api: ApiInterfaceRx, _accountIndex: AccountIndex | string): Observable<AccountId | undefined> {
|
||||
const accountIndex = _accountIndex instanceof api.registry.createClass('AccountIndex')
|
||||
? _accountIndex
|
||||
: createType(api.registry, 'AccountIndex', _accountIndex);
|
||||
: api.registry.createType('AccountIndex', _accountIndex);
|
||||
|
||||
return api.query.indices.enumSet<Vec<AccountId>>(accountIndex.div(ENUMSET_SIZE)).pipe(
|
||||
startWith([]),
|
||||
|
||||
@@ -9,7 +9,7 @@ import { AccountIndexes } from '../types';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, startWith, switchMap } from 'rxjs/operators';
|
||||
import { ENUMSET_SIZE } from '@polkadot/types/generic/AccountIndex';
|
||||
import { Vec, createType } from '@polkadot/types';
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -31,7 +31,7 @@ function queryEnumSet (api: ApiInterfaceRx): Observable<AccountIndexes> {
|
||||
// 64 (0..63 in first) is [1][0] (the first index value in set 2)
|
||||
const index = (outerIndex * enumsetSize) + innerIndex;
|
||||
|
||||
indexes[accountId.toString()] = createType(api.registry, 'AccountIndex', index);
|
||||
indexes[accountId.toString()] = api.registry.createType('AccountIndex', index);
|
||||
});
|
||||
|
||||
return indexes;
|
||||
|
||||
@@ -7,8 +7,8 @@ import { AccountId, AccountIndex, Address, Balance, Registration } from '@polkad
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
import { DeriveAccountInfo, DeriveAccountRegistration } from '../types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
import { Bytes, Data, Option, u32 } from '@polkadot/types';
|
||||
import { u8aToString } from '@polkadot/util';
|
||||
|
||||
@@ -86,6 +86,7 @@ function retrieveIdentity (api: ApiInterfaceRx, accountId?: AccountId): Observab
|
||||
])
|
||||
: of([undefined, undefined])
|
||||
) as Observable<[Option<Registration> | undefined, Option<ITuple<[AccountId, Data]>> | undefined]>).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap(([identityOfOpt, superOfOpt]): Observable<[Option<Registration> | undefined, [AccountId, Data] | undefined]> => {
|
||||
if (identityOfOpt?.isSome) {
|
||||
// this identity has something set
|
||||
@@ -103,6 +104,7 @@ function retrieveIdentity (api: ApiInterfaceRx, accountId?: AccountId): Observab
|
||||
// nothing of value returned
|
||||
return of([undefined, undefined]);
|
||||
}),
|
||||
observeOn(asyncScheduler),
|
||||
map(([identityOfOpt, superOf]): DeriveAccountRegistration =>
|
||||
extractIdentity(identityOfOpt, superOf)
|
||||
)
|
||||
@@ -116,6 +118,7 @@ function retrieveIdentity (api: ApiInterfaceRx, accountId?: AccountId): Observab
|
||||
export function info (api: ApiInterfaceRx): (address?: AccountIndex | AccountId | Address | string | null) => Observable<DeriveAccountInfo> {
|
||||
return memo((address?: AccountIndex | AccountId | Address | string | null): Observable<DeriveAccountInfo> =>
|
||||
api.derive.accounts.idAndIndex(address).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap(([accountId, accountIndex]): Observable<[Partial<DeriveAccountInfo>, DeriveAccountRegistration, string?]> =>
|
||||
combineLatest([
|
||||
of({ accountId, accountIndex }),
|
||||
@@ -123,6 +126,7 @@ export function info (api: ApiInterfaceRx): (address?: AccountIndex | AccountId
|
||||
retrieveNick(api, accountId)
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([{ accountId, accountIndex }, identity, nickname]): DeriveAccountInfo => ({
|
||||
accountId, accountIndex, identity, nickname
|
||||
}))
|
||||
|
||||
@@ -6,10 +6,9 @@ import { AccountId, AccountData, AccountIndex, AccountInfo, Address, Balance, In
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
import { DerivedBalancesAccount } from '../types';
|
||||
|
||||
import { combineLatest, of, Observable } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -23,7 +22,7 @@ function calcBalances (api: ApiInterfaceRx, [accountId, [freeBalance, reservedBa
|
||||
frozenFee,
|
||||
frozenMisc,
|
||||
reservedBalance,
|
||||
votingBalance: createType(api.registry, 'Balance', freeBalance.add(reservedBalance))
|
||||
votingBalance: api.registry.createType('Balance', freeBalance.add(reservedBalance))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -35,7 +34,7 @@ function queryBalancesFree (api: ApiInterfaceRx, accountId: AccountId): Observab
|
||||
[api.query.system.accountNonce, accountId]
|
||||
]).pipe(
|
||||
map(([freeBalance, reservedBalance, accountNonce]): Result =>
|
||||
[freeBalance, reservedBalance, createType(api.registry, 'Balance'), createType(api.registry, 'Balance'), accountNonce]
|
||||
[freeBalance, reservedBalance, api.registry.createType('Balance'), api.registry.createType('Balance'), accountNonce]
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -83,6 +82,7 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable<Re
|
||||
export function account (api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable<DerivedBalancesAccount> {
|
||||
return memo((address: AccountIndex | AccountId | Address | string): Observable<DerivedBalancesAccount> =>
|
||||
api.derive.accounts.info(address).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap(({ accountId }): Observable<[AccountId, Result]> =>
|
||||
(accountId
|
||||
? combineLatest([
|
||||
@@ -93,9 +93,10 @@ export function account (api: ApiInterfaceRx): (address: AccountIndex | AccountI
|
||||
? queryBalancesAccount(api, accountId)
|
||||
: queryBalancesFree(api, accountId)
|
||||
])
|
||||
: of([createType(api.registry, 'AccountId'), [createType(api.registry, 'Balance'), createType(api.registry, 'Balance'), createType(api.registry, 'Balance'), createType(api.registry, 'Balance'), createType(api.registry, 'Index')]])
|
||||
: of([api.registry.createType('AccountId'), [api.registry.createType('Balance'), api.registry.createType('Balance'), api.registry.createType('Balance'), api.registry.createType('Balance'), api.registry.createType('Index')]])
|
||||
)
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map((result): DerivedBalancesAccount => calcBalances(api, result))
|
||||
));
|
||||
}
|
||||
|
||||
@@ -6,10 +6,10 @@ import { AccountId, AccountIndex, Address, Balance, BalanceLock, BalanceLockTo21
|
||||
import { DerivedBalancesAccount, DerivedBalancesAll } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { combineLatest, of, Observable } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Option, Vec, createType } from '@polkadot/types';
|
||||
import { Option, Vec } from '@polkadot/types';
|
||||
import { bnMax } from '@polkadot/util';
|
||||
|
||||
import { memo } from '../util';
|
||||
@@ -18,7 +18,7 @@ type ResultBalance = [VestingInfo | null, (BalanceLock | BalanceLockTo212)[]];
|
||||
type Result = [DerivedBalancesAccount, BlockNumber, ResultBalance];
|
||||
|
||||
function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBalance, frozenFee, frozenMisc, reservedBalance, votingBalance }, bestNumber, [vesting, locks]]: Result): DerivedBalancesAll {
|
||||
let lockedBalance = createType(api.registry, 'Balance');
|
||||
let lockedBalance = api.registry.createType('Balance');
|
||||
let lockedBreakdown: (BalanceLock | BalanceLockTo212)[] = [];
|
||||
let allLocked = false;
|
||||
|
||||
@@ -32,16 +32,16 @@ function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBala
|
||||
|
||||
// get the maximum of the locks according to https://github.com/paritytech/substrate/blob/master/srml/balances/src/lib.rs#L699
|
||||
if (notAll.length) {
|
||||
lockedBalance = createType(api.registry, 'Balance', bnMax(...notAll.map(({ amount }): Balance => amount)));
|
||||
lockedBalance = api.registry.createType('Balance', bnMax(...notAll.map(({ amount }): Balance => amount)));
|
||||
}
|
||||
}
|
||||
|
||||
// Calculate the vesting balances,
|
||||
// - offset = balance locked at startingBlock
|
||||
// - perBlock is the unlock amount
|
||||
const { locked: vestingTotal, perBlock, startingBlock } = vesting || createType(api.registry, 'VestingInfo');
|
||||
const { locked: vestingTotal, perBlock, startingBlock } = vesting || api.registry.createType('VestingInfo');
|
||||
const isStarted = bestNumber.gt(startingBlock);
|
||||
const vestedBalance = createType(api.registry, 'Balance', isStarted ? perBlock.mul(bestNumber.sub(startingBlock)) : 0);
|
||||
const vestedBalance = api.registry.createType('Balance', isStarted ? perBlock.mul(bestNumber.sub(startingBlock)) : 0);
|
||||
const isVesting = isStarted && vestedBalance.lt(vestingTotal);
|
||||
|
||||
// The available balance & vested has an interplay here
|
||||
@@ -53,7 +53,7 @@ function calcBalances (api: ApiInterfaceRx, [{ accountId, accountNonce, freeBala
|
||||
// ""
|
||||
const floating = freeBalance.sub(lockedBalance);
|
||||
const extraReceived = isVesting ? freeBalance.sub(vestingTotal) : new BN(0);
|
||||
const availableBalance = createType(api.registry, 'Balance', allLocked ? 0 : bnMax(new BN(0), isVesting && floating.gt(vestedBalance) ? vestedBalance.add(extraReceived) : floating));
|
||||
const availableBalance = api.registry.createType('Balance', allLocked ? 0 : bnMax(new BN(0), isVesting && floating.gt(vestedBalance) ? vestedBalance.add(extraReceived) : floating));
|
||||
|
||||
return {
|
||||
accountId,
|
||||
@@ -84,7 +84,7 @@ function queryOld (api: ApiInterfaceRx, accountId: AccountId): Observable<Result
|
||||
if (optVesting.isSome) {
|
||||
const { offset: locked, perBlock, startingBlock } = optVesting.unwrap();
|
||||
|
||||
vestingNew = createType(api.registry, 'VestingInfo', { locked, perBlock, startingBlock });
|
||||
vestingNew = api.registry.createType('VestingInfo', { locked, perBlock, startingBlock });
|
||||
}
|
||||
|
||||
return [vestingNew, locks];
|
||||
@@ -102,7 +102,7 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable<Re
|
||||
])
|
||||
: api.query.balances.locks(accountId).pipe(
|
||||
map((locks): [Vec<BalanceLock>, Option<VestingInfo>] =>
|
||||
[locks, createType(api.registry, 'Option<VestingInfo>')]
|
||||
[locks, api.registry.createType('Option<VestingInfo>')]
|
||||
)
|
||||
)
|
||||
).pipe(
|
||||
@@ -130,6 +130,7 @@ function queryCurrent (api: ApiInterfaceRx, accountId: AccountId): Observable<Re
|
||||
export function all (api: ApiInterfaceRx): (address: AccountIndex | AccountId | Address | string) => Observable<DerivedBalancesAll> {
|
||||
return memo((address: AccountIndex | AccountId | Address | string): Observable<DerivedBalancesAll> =>
|
||||
api.derive.balances.account(address).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((account): Observable<Result> =>
|
||||
(!account.accountId.isEmpty
|
||||
? combineLatest([
|
||||
@@ -139,9 +140,10 @@ export function all (api: ApiInterfaceRx): (address: AccountIndex | AccountId |
|
||||
? queryCurrent(api, account.accountId)
|
||||
: queryOld(api, account.accountId)
|
||||
])
|
||||
: of([account, createType(api.registry, 'BlockNumber'), [null, createType(api.registry, 'Vec<BalanceLock>')]])
|
||||
: of([account, api.registry.createType('BlockNumber'), [null, api.registry.createType('Vec<BalanceLock>')]])
|
||||
)
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map((result): DerivedBalancesAll => calcBalances(api, result))
|
||||
));
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import { DerivedFees } from '../types';
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -29,13 +28,13 @@ export function fees (api: ApiInterfaceRx): () => Observable<DerivedFees> {
|
||||
return memo((): Observable<DerivedFees> =>
|
||||
of([
|
||||
// deprecated - remove
|
||||
(api.consts.balances?.creationFee as Balance) || createType(api.registry, 'Balance'),
|
||||
(api.consts.balances?.transferFee as Balance) || createType(api.registry, 'Balance'),
|
||||
(api.consts.balances?.creationFee as Balance) || api.registry.createType('Balance'),
|
||||
(api.consts.balances?.transferFee as Balance) || api.registry.createType('Balance'),
|
||||
|
||||
// current
|
||||
(api.consts.balances?.existentialDeposit as Balance) || createType(api.registry, 'Balance'),
|
||||
(api.consts.transactionPayment?.transactionBaseFee as Balance) || createType(api.registry, 'Balance'),
|
||||
(api.consts.transactionPayment?.transactionByteFee as Balance) || createType(api.registry, 'Balance')
|
||||
(api.consts.balances?.existentialDeposit as Balance) || api.registry.createType('Balance'),
|
||||
(api.consts.transactionPayment?.transactionBaseFee as Balance) || api.registry.createType('Balance'),
|
||||
(api.consts.transactionPayment?.transactionByteFee as Balance) || api.registry.createType('Balance')
|
||||
]).pipe(
|
||||
map(([creationFee, transferFee, existentialDeposit, transactionBaseFee, transactionByteFee]): DerivedFees => ({
|
||||
creationFee,
|
||||
|
||||
@@ -5,7 +5,8 @@
|
||||
import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
|
||||
import { DerivedBalancesAccount } from '../types';
|
||||
|
||||
import { combineLatest, Observable, of } from 'rxjs';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { observeOn } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
@@ -16,7 +17,8 @@ export function votingBalances (api: ApiInterfaceRx): (addresses?: (AccountId |
|
||||
? of([] as DerivedBalancesAccount[])
|
||||
: combineLatest(
|
||||
addresses.map((accountId): Observable<DerivedBalancesAccount> =>
|
||||
api.derive.balances.account(accountId))
|
||||
)
|
||||
api.derive.balances.account(accountId)
|
||||
)
|
||||
).pipe(observeOn(asyncScheduler))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
|
||||
import { BlockNumber } from '@polkadot/types/interfaces';
|
||||
|
||||
import { Observable, combineLatest } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest } from 'rxjs';
|
||||
import { map, observeOn } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -30,8 +29,9 @@ export function bestNumberLag (api: ApiInterfaceRx): () => Observable<BlockNumbe
|
||||
api.derive.chain.bestNumber(),
|
||||
api.derive.chain.bestNumberFinalized()
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
map(([bestNumber, bestNumberFinalized]): BlockNumber =>
|
||||
createType(api.registry, 'BlockNumber', bestNumber.sub(bestNumberFinalized))
|
||||
api.registry.createType('BlockNumber', bestNumber.sub(bestNumberFinalized))
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { catchError, map } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { catchError, map, observeOn } from 'rxjs/operators';
|
||||
|
||||
import { HeaderExtended } from '../type';
|
||||
import { memo } from '../util';
|
||||
@@ -32,6 +32,7 @@ export function getHeader (api: ApiInterfaceRx): (hash: Uint8Array | string) =>
|
||||
? api.query.session.validators.at(hash)
|
||||
: of([])
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
map(([header, validators]): HeaderExtended =>
|
||||
new HeaderExtended(api.registry, header, validators)
|
||||
),
|
||||
|
||||
@@ -4,8 +4,8 @@
|
||||
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn } from 'rxjs/operators';
|
||||
|
||||
import { HeaderExtended } from '../type';
|
||||
import { memo } from '../util';
|
||||
@@ -31,6 +31,7 @@ export function subscribeNewHeads (api: ApiInterfaceRx): () => Observable<Header
|
||||
? api.query.session.validators()
|
||||
: of([])
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
map(([header, validators]): HeaderExtended =>
|
||||
new HeaderExtended(api.registry, header, validators)
|
||||
)
|
||||
|
||||
@@ -6,8 +6,8 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Hash, Proposal, Votes } from '@polkadot/types/interfaces';
|
||||
import { DerivedCollectiveProposal } from '../types';
|
||||
|
||||
import { combineLatest, Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
import { Option } from '@polkadot/types';
|
||||
|
||||
type Result = [Hash[], Option<Proposal>[], Option<Votes>[]];
|
||||
@@ -30,6 +30,7 @@ export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalC
|
||||
return (): Observable<DerivedCollectiveProposal[]> =>
|
||||
api.query[section]?.proposals
|
||||
? api.query[section].proposals().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((hashes: Hash[]): Observable<Result> =>
|
||||
hashes.length
|
||||
? combineLatest([
|
||||
@@ -39,6 +40,7 @@ export function proposals (api: ApiInterfaceRx, section: 'council' | 'technicalC
|
||||
])
|
||||
: of([[], [], []])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(parse)
|
||||
)
|
||||
: of([] as DerivedCollectiveProposal[]);
|
||||
|
||||
@@ -8,7 +8,6 @@ import { DerivedContractFees } from '../types';
|
||||
import BN from 'bn.js';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -18,8 +17,8 @@ type ResultV2 = [BN, BN, BN, BN, BN, BN, BN, BN, BN];
|
||||
function queryConstants (api: ApiInterfaceRx): Observable<ResultV2> {
|
||||
return of([
|
||||
// deprecated
|
||||
api.consts.contracts.creationFee || createType(api.registry, 'Balance'),
|
||||
api.consts.contracts.transferFee || createType(api.registry, 'Balance'),
|
||||
api.consts.contracts.creationFee || api.registry.createType('Balance'),
|
||||
api.consts.contracts.transferFee || api.registry.createType('Balance'),
|
||||
|
||||
// current
|
||||
api.consts.contracts.callBaseFee,
|
||||
|
||||
@@ -6,10 +6,10 @@ import { AccountId, Balance, BlockNumber, Hash, PropIndex, Proposal } from '@pol
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
import { DeriveProposal } from '../types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Bytes, Option, Vec, createType } from '@polkadot/types';
|
||||
import { Bytes, Option, Vec } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -37,7 +37,7 @@ function parse (api: ApiInterfaceRx, { depositors, proposals, preimages }: Resul
|
||||
// we could end up in a situation where the proposal is non-decodable, e.g. after an upgrade
|
||||
if (preimage) {
|
||||
try {
|
||||
proposal = createType(api.registry, 'Proposal', preimage[0].toU8a(true));
|
||||
proposal = api.registry.createType('Proposal', preimage[0].toU8a(true));
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
@@ -65,6 +65,7 @@ export function proposals (api: ApiInterfaceRx): () => Observable<DeriveProposal
|
||||
return memo((): Observable<DeriveProposal[]> =>
|
||||
api.query.democracy?.publicProps && api.query.democracy?.preimages
|
||||
? api.query.democracy.publicProps<Proposals>().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((proposals) =>
|
||||
combineLatest([
|
||||
of(proposals),
|
||||
@@ -74,6 +75,7 @@ export function proposals (api: ApiInterfaceRx): () => Observable<DeriveProposal
|
||||
proposals.map(([index]): PropIndex => index))
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([proposals, preimages, depositors]): DeriveProposal[] =>
|
||||
parse(api, { depositors, proposals, preimages })
|
||||
)
|
||||
|
||||
@@ -10,7 +10,7 @@ import BN from 'bn.js';
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Option, createType } from '@polkadot/types';
|
||||
import { Option } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -25,11 +25,11 @@ function constructInfo (api: ApiInterfaceRx, index: BN | number, _info: Option<R
|
||||
}
|
||||
|
||||
return {
|
||||
index: createType(api.registry, 'PropIndex', index),
|
||||
index: api.registry.createType('PropIndex', index),
|
||||
info,
|
||||
hash: info.proposalHash,
|
||||
proposal: preImage
|
||||
? createType(api.registry, 'Proposal', preImage[0].toU8a(true))
|
||||
? api.registry.createType('Proposal', preImage[0].toU8a(true))
|
||||
: undefined,
|
||||
preimage: preImage
|
||||
? {
|
||||
|
||||
@@ -6,8 +6,8 @@ import { ReferendumInfo } from '@polkadot/types/interfaces/democracy';
|
||||
import { DerivedReferendum } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Option } from '@polkadot/types';
|
||||
|
||||
@@ -21,13 +21,15 @@ export function referendumInfos (api: ApiInterfaceRx): (ids?: (BN | number)[]) =
|
||||
? of([] as Option<ReferendumInfo>[])
|
||||
: api.query.democracy.referendumInfoOf.multi<Option<ReferendumInfo>>(ids)
|
||||
).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((infos): Observable<(DerivedReferendum | null)[]> =>
|
||||
combineLatest(
|
||||
...ids.map((id, index): Observable<DerivedReferendum | null> =>
|
||||
ids.map((id, index): Observable<DerivedReferendum | null> =>
|
||||
retrieveInfo(api, id, infos[index])
|
||||
)
|
||||
)
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map((infos): DerivedReferendum[] =>
|
||||
infos.filter((referendum): referendum is DerivedReferendum => !!referendum)
|
||||
)
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
import { AccountId, Vote } from '@polkadot/types/interfaces';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { combineLatest, Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Vec, createType } from '@polkadot/types';
|
||||
import { Vec } from '@polkadot/types';
|
||||
|
||||
import { DerivedBalancesAccount, DerivedReferendumVote } from '../types';
|
||||
import { memo } from '../util';
|
||||
@@ -16,6 +16,7 @@ import { memo } from '../util';
|
||||
export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | number) => Observable<DerivedReferendumVote[]> {
|
||||
return memo((referendumId: BN | number): Observable<DerivedReferendumVote[]> =>
|
||||
api.query.democracy.votersFor<Vec<AccountId>>(referendumId).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((votersFor): Observable<[Vec<AccountId>, Vote[], DerivedBalancesAccount[]]> =>
|
||||
combineLatest([
|
||||
of(votersFor),
|
||||
@@ -23,11 +24,12 @@ export function referendumVotesFor (api: ApiInterfaceRx): (referendumId: BN | nu
|
||||
api.derive.balances.votingBalances(votersFor)
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([votersFor, votes, balances]): DerivedReferendumVote[] =>
|
||||
votersFor.map((accountId, index): DerivedReferendumVote => ({
|
||||
accountId,
|
||||
balance: balances[index].votingBalance || createType(api.registry, 'Balance'),
|
||||
vote: votes[index] || createType(api.registry, 'Vote')
|
||||
balance: balances[index].votingBalance || api.registry.createType('Balance'),
|
||||
vote: votes[index] || api.registry.createType('Vote')
|
||||
} as DerivedReferendumVote))
|
||||
)
|
||||
));
|
||||
|
||||
@@ -8,7 +8,7 @@ import { ITuple } from '@polkadot/types/types';
|
||||
import { Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { createType, Vec, u32 } from '@polkadot/types';
|
||||
import { Vec, u32 } from '@polkadot/types';
|
||||
|
||||
import { DerivedElectionsInfo } from '../types';
|
||||
import { memo } from '../util';
|
||||
@@ -28,12 +28,12 @@ function queryElections (api: ApiInterfaceRx): Observable<DerivedElectionsInfo>
|
||||
]).pipe(
|
||||
map(([councilMembers, candidates, members, runnersUp]): DerivedElectionsInfo => ({
|
||||
candidates,
|
||||
candidateCount: createType(api.registry, 'u32', candidates.length),
|
||||
candidateCount: api.registry.createType('u32', candidates.length),
|
||||
candidacyBond: api.consts[section].candidacyBond as Balance,
|
||||
desiredSeats: api.consts[section].desiredMembers as u32,
|
||||
members: members.length
|
||||
? members.sort(sortAccounts)
|
||||
: councilMembers.map((accountId): [AccountId, Balance] => [accountId, createType(api.registry, 'Balance')]),
|
||||
: councilMembers.map((accountId): [AccountId, Balance] => [accountId, api.registry.createType('Balance')]),
|
||||
runnersUp: runnersUp.sort(sortAccounts),
|
||||
termDuration: api.consts[section].termDuration as BlockNumber,
|
||||
votingBond: api.consts[section].votingBond as Balance
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
import { AccountId } from '@polkadot/types/interfaces';
|
||||
import { DerivedHeartbeats } from '../types';
|
||||
|
||||
import { of, Observable, combineLatest } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, of, combineLatest } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { Bytes, Option, u32 } from '@polkadot/types';
|
||||
|
||||
@@ -19,6 +19,7 @@ export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable<Deriv
|
||||
return memo((): Observable<DerivedHeartbeats> =>
|
||||
api.query.imOnline?.receivedHeartbeats
|
||||
? api.derive.staking.overview().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap(({ currentIndex, validators }): Observable<[AccountId[], Option<Bytes>[], u32[]]> =>
|
||||
combineLatest([
|
||||
of(validators),
|
||||
@@ -28,6 +29,7 @@ export function receivedHeartbeats (api: ApiInterfaceRx): () => Observable<Deriv
|
||||
validators.map((address) => [currentIndex, address]))
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([validators, heartbeats, numBlocks]): DerivedHeartbeats =>
|
||||
validators.reduce((result: DerivedHeartbeats, validator, index): DerivedHeartbeats => ({
|
||||
...result,
|
||||
|
||||
@@ -9,7 +9,6 @@ import { Active, DidUpdate, Heads, ParaInfoResult, PendingSwap, RelayDispatchQue
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { createType } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -92,7 +91,7 @@ export function info (api: ApiInterfaceRx): (id: ParaId | number) => Observable<
|
||||
])
|
||||
.pipe(
|
||||
map((result: Result): DeriveParachainFull | null =>
|
||||
parse(createType(api.registry, 'ParaId', id), result)
|
||||
parse(api.registry.createType('ParaId', id), result)
|
||||
)
|
||||
)
|
||||
: of(null)
|
||||
|
||||
@@ -6,8 +6,8 @@ import { ParaId } from '@polkadot/types/interfaces';
|
||||
import { DeriveParachain, DeriveParachainInfo } from '../types';
|
||||
import { DidUpdate, ParaInfoResult, PendingSwap, RelayDispatchQueueSize } from './types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
@@ -38,6 +38,7 @@ export function overview (api: ApiInterfaceRx): () => Observable<DeriveParachain
|
||||
return memo((): Observable<DeriveParachain[]> =>
|
||||
api.query.registrar?.parachains && api.query.parachains
|
||||
? api.query.registrar.parachains<ParaId[]>().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((paraIds) =>
|
||||
combineLatest([
|
||||
of(paraIds),
|
||||
@@ -47,6 +48,7 @@ export function overview (api: ApiInterfaceRx): () => Observable<DeriveParachain
|
||||
api.query.parachains.relayDispatchQueueSize.multi<RelayDispatchQueueSize>(paraIds)
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map((result: Result): DeriveParachain[] =>
|
||||
parse(result)
|
||||
)
|
||||
|
||||
@@ -8,7 +8,7 @@ import { DeriveSessionIndexes } from '../types';
|
||||
|
||||
import { Observable, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { createType, Option, u32 } from '@polkadot/types';
|
||||
import { Option, u32 } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -34,7 +34,7 @@ function queryNoActive (api: ApiInterfaceRx): Observable<Result> {
|
||||
]).pipe(
|
||||
map(([currentEra, currentIndex, validatorCount]): Result => [
|
||||
currentEra,
|
||||
createType(api.registry, 'Option<Moment>'),
|
||||
api.registry.createType('Option<Moment>'),
|
||||
currentEra,
|
||||
currentIndex,
|
||||
validatorCount
|
||||
@@ -56,7 +56,7 @@ function query (api: ApiInterfaceRx): Observable<Result> {
|
||||
return [
|
||||
activeEra,
|
||||
activeEraStart,
|
||||
currentEra.unwrapOr(createType(api.registry, 'EraIndex')),
|
||||
currentEra.unwrapOr(api.registry.createType('EraIndex')),
|
||||
currentIndex,
|
||||
validatorCount
|
||||
];
|
||||
@@ -67,11 +67,11 @@ function query (api: ApiInterfaceRx): Observable<Result> {
|
||||
// empty set when none is available
|
||||
function empty (api: ApiInterfaceRx): Observable<Result> {
|
||||
return of([
|
||||
createType(api.registry, 'EraIndex'),
|
||||
createType(api.registry, 'Option<Moment>'),
|
||||
createType(api.registry, 'EraIndex'),
|
||||
createType(api.registry, 'SessionIndex', 1),
|
||||
createType(api.registry, 'u32')
|
||||
api.registry.createType('EraIndex'),
|
||||
api.registry.createType('Option<Moment>'),
|
||||
api.registry.createType('EraIndex'),
|
||||
api.registry.createType('SessionIndex', 1),
|
||||
api.registry.createType('u32')
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -5,10 +5,10 @@
|
||||
import { SessionIndex } from '@polkadot/types/interfaces';
|
||||
import { DerivedSessionInfo, DeriveSessionIndexes } from '../types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { createType, Option, u64 } from '@polkadot/types';
|
||||
import { Option, u64 } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -27,12 +27,12 @@ function createDerived (api: ApiInterfaceRx, [[hasBabe, epochDuration, sessionsP
|
||||
activeEraStart,
|
||||
currentEra,
|
||||
currentIndex,
|
||||
eraLength: createType(api.registry, 'BlockNumber', sessionsPerEra.mul(epochDuration)),
|
||||
eraProgress: createType(api.registry, 'BlockNumber', eraProgress),
|
||||
eraLength: api.registry.createType('BlockNumber', sessionsPerEra.mul(epochDuration)),
|
||||
eraProgress: api.registry.createType('BlockNumber', eraProgress),
|
||||
isEpoch: hasBabe,
|
||||
sessionLength: epochDuration,
|
||||
sessionsPerEra,
|
||||
sessionProgress: createType(api.registry, 'BlockNumber', sessionProgress),
|
||||
sessionProgress: api.registry.createType('BlockNumber', sessionProgress),
|
||||
validatorCount
|
||||
};
|
||||
}
|
||||
@@ -43,15 +43,15 @@ function queryAura (api: ApiInterfaceRx): Observable<DerivedSessionInfo> {
|
||||
createDerived(api, [
|
||||
[
|
||||
false,
|
||||
createType(api.registry, 'u64', 1),
|
||||
api.consts.staking?.sessionsPerEra || createType(api.registry, 'SessionIndex', 1)
|
||||
api.registry.createType('u64', 1),
|
||||
api.consts.staking?.sessionsPerEra || api.registry.createType('SessionIndex', 1)
|
||||
],
|
||||
indexes,
|
||||
[
|
||||
createType(api.registry, 'u64', 1),
|
||||
createType(api.registry, 'u64', 1),
|
||||
createType(api.registry, 'u64', 1),
|
||||
createType(api.registry, 'SessionIndex', 1)
|
||||
api.registry.createType('u64', 1),
|
||||
api.registry.createType('u64', 1),
|
||||
api.registry.createType('u64', 1),
|
||||
api.registry.createType('SessionIndex', 1)
|
||||
]
|
||||
])
|
||||
)
|
||||
@@ -60,6 +60,7 @@ function queryAura (api: ApiInterfaceRx): Observable<DerivedSessionInfo> {
|
||||
|
||||
function queryBabe (api: ApiInterfaceRx): Observable<[DeriveSessionIndexes, ResultSlotsFlat]> {
|
||||
return api.derive.session.indexes().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((indexes): Observable<[DeriveSessionIndexes, ResultSlots]> =>
|
||||
combineLatest([
|
||||
of(indexes),
|
||||
@@ -71,8 +72,9 @@ function queryBabe (api: ApiInterfaceRx): Observable<[DeriveSessionIndexes, Resu
|
||||
])
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([indexes, [currentSlot, epochIndex, genesisSlot, optStartIndex]]): [DeriveSessionIndexes, ResultSlotsFlat] => [
|
||||
indexes, [currentSlot, epochIndex, genesisSlot, optStartIndex.unwrapOr(createType(api.registry, 'SessionIndex', 1))]
|
||||
indexes, [currentSlot, epochIndex, genesisSlot, optStartIndex.unwrapOr(api.registry.createType('SessionIndex', 1))]
|
||||
])
|
||||
);
|
||||
}
|
||||
@@ -99,6 +101,7 @@ export function info (api: ApiInterfaceRx): () => Observable<DerivedSessionInfo>
|
||||
? queryBabe(api) // 2.x with Babe
|
||||
: queryBabeNoHistory(api)
|
||||
).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
map(([indexes, slots]: [DeriveSessionIndexes, ResultSlotsFlat]): DerivedSessionInfo =>
|
||||
createDerived(api, [
|
||||
[true, api.consts.babe.epochDuration, api.consts.staking.sessionsPerEra],
|
||||
|
||||
@@ -7,8 +7,8 @@ import { AccountId, BalanceOf, Bid, BidKind } from '@polkadot/types/interfaces';
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
import { DeriveSocietyCandidate } from '../types';
|
||||
|
||||
import { combineLatest, of, Observable } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
import { Option, Vec } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
@@ -22,6 +22,7 @@ type Result = [Bid[], ResultSuspend[]]
|
||||
export function candidates (api: ApiInterfaceRx): () => Observable<DeriveSocietyCandidate[]> {
|
||||
return memo((): Observable<DeriveSocietyCandidate[]> =>
|
||||
api.query.society.candidates<Vec<Bid>>().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((candidates: Vec<Bid>): Observable<Result> =>
|
||||
combineLatest([
|
||||
of(candidates),
|
||||
@@ -29,6 +30,7 @@ export function candidates (api: ApiInterfaceRx): () => Observable<DeriveSociety
|
||||
candidates.map(({ who }): AccountId => who))
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([candidates, suspended]: Result): DeriveSocietyCandidate[] =>
|
||||
candidates.map(({ who, kind, value }, index) => ({
|
||||
accountId: who,
|
||||
|
||||
@@ -6,8 +6,8 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId } from '@polkadot/types/interfaces';
|
||||
import { DeriveSocietyMember } from '../types';
|
||||
|
||||
import { combineLatest, Observable } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest } from 'rxjs';
|
||||
import { observeOn, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -17,10 +17,13 @@ import { memo } from '../util';
|
||||
export function members (api: ApiInterfaceRx): () => Observable<DeriveSocietyMember[]> {
|
||||
return memo((): Observable<DeriveSocietyMember[]> =>
|
||||
api.query.society.members<AccountId[]>().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((members): Observable<DeriveSocietyMember[]> =>
|
||||
combineLatest(members.map((accountId): Observable<DeriveSocietyMember> =>
|
||||
api.derive.society.member(accountId)
|
||||
))
|
||||
combineLatest(
|
||||
members.map((accountId): Observable<DeriveSocietyMember> =>
|
||||
api.derive.society.member(accountId)
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
@@ -7,9 +7,8 @@ import { Balance, BlockNumber, StakingLedger, UnlockChunk } from '@polkadot/type
|
||||
import { DerivedSessionInfo, DerivedStakingAccount, DerivedStakingQuery, DerivedUnlocking } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { combineLatest, Observable } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { createType } from '@polkadot/types';
|
||||
import { Observable, asyncScheduler, combineLatest } from 'rxjs';
|
||||
import { map, observeOn } from 'rxjs/operators';
|
||||
|
||||
import { isUndefined } from '@polkadot/util';
|
||||
|
||||
@@ -33,7 +32,7 @@ function remainingBlocks (api: ApiInterfaceRx, era: BN, sessionInfo: DerivedSess
|
||||
const remaining = era.sub(sessionInfo.currentEra);
|
||||
|
||||
// on the Rust side the current-era >= era-for-unlock (removal done on >)
|
||||
return createType(api.registry, 'BlockNumber', remaining.gtn(0)
|
||||
return api.registry.createType('BlockNumber', remaining.gtn(0)
|
||||
? remaining
|
||||
.subn(1)
|
||||
.mul(sessionInfo.eraLength)
|
||||
@@ -58,7 +57,7 @@ function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger |
|
||||
// group the unlock chunks that have the same era and sum their values
|
||||
const groupedResult = groupByEra(unlockingChunks);
|
||||
const results = Object.entries(groupedResult).map(([eraString, value]): DerivedUnlocking => ({
|
||||
value: createType(api.registry, 'Balance', value),
|
||||
value: api.registry.createType('Balance', value),
|
||||
remainingBlocks: remainingBlocks(api, new BN(eraString), sessionInfo)
|
||||
}));
|
||||
|
||||
@@ -67,10 +66,10 @@ function calculateUnlocking (api: ApiInterfaceRx, stakingLedger: StakingLedger |
|
||||
|
||||
function redeemableSum (api: ApiInterfaceRx, stakingLedger: StakingLedger | undefined, sessionInfo: DerivedSessionInfo): Balance {
|
||||
if (isUndefined(stakingLedger)) {
|
||||
return createType(api.registry, 'Balance');
|
||||
return api.registry.createType('Balance');
|
||||
}
|
||||
|
||||
return createType(api.registry, 'Balance', stakingLedger.unlocking.reduce((total, { era, value }): BN => {
|
||||
return api.registry.createType('Balance', stakingLedger.unlocking.reduce((total, { era, value }): BN => {
|
||||
return remainingBlocks(api, era.unwrap(), sessionInfo).eqn(0)
|
||||
? total.add(value.unwrap())
|
||||
: total;
|
||||
@@ -94,6 +93,7 @@ export function account (api: ApiInterfaceRx): (accountId: Uint8Array | string)
|
||||
api.derive.session.info(),
|
||||
api.derive.staking.query(accountId)
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
map(([sessionInfo, query]: [DerivedSessionInfo, DerivedStakingQuery]) =>
|
||||
parseResult(api, sessionInfo, query))
|
||||
));
|
||||
|
||||
@@ -6,8 +6,8 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId, ValidatorPrefs } from '@polkadot/types/interfaces';
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { observeOn, switchMap } from 'rxjs/operators';
|
||||
import { Option, Vec } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
@@ -20,6 +20,7 @@ type DeriveControllers = [AccountId[], Option<AccountId>[]];
|
||||
export function controllers (api: ApiInterfaceRx): () => Observable<DeriveControllers> {
|
||||
return memo((): Observable<[AccountId[], Option<AccountId>[]]> =>
|
||||
api.query.staking.validators<ITuple<[Vec<AccountId>, Vec<ValidatorPrefs>]>>().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap(([stashIds]): Observable<DeriveControllers> =>
|
||||
combineLatest([
|
||||
of(stashIds),
|
||||
@@ -28,6 +29,7 @@ export function controllers (api: ApiInterfaceRx): () => Observable<DeriveContro
|
||||
? of([])
|
||||
: api.query.staking.bonded.multi<Option<AccountId>>(stashIds)
|
||||
])
|
||||
)
|
||||
),
|
||||
observeOn(asyncScheduler)
|
||||
));
|
||||
}
|
||||
|
||||
@@ -6,22 +6,26 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId } from '@polkadot/types/interfaces';
|
||||
import { DerivedStakingQuery, DerivedStakingElected } from '../types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
export function electedInfo (api: ApiInterfaceRx): () => Observable<DerivedStakingElected> {
|
||||
return memo((): Observable<DerivedStakingElected> =>
|
||||
api.derive.staking.validators().pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap(({ nextElected }): Observable<[AccountId[], DerivedStakingQuery[]]> =>
|
||||
combineLatest([
|
||||
of(nextElected),
|
||||
combineLatest(nextElected.map((accountId): Observable<DerivedStakingQuery> =>
|
||||
api.derive.staking.query(accountId)
|
||||
))
|
||||
combineLatest(
|
||||
nextElected.map((accountId): Observable<DerivedStakingQuery> =>
|
||||
api.derive.staking.query(accountId)
|
||||
)
|
||||
)
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([nextElected, info]): DerivedStakingElected => ({
|
||||
info,
|
||||
nextElected
|
||||
|
||||
@@ -7,8 +7,8 @@ import { EraIndex, Exposure } from '@polkadot/types/interfaces';
|
||||
import { DeriveEraExposure, DeriveEraNominatorExposure, DeriveEraValidatorExposure } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap, take } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap, take } from 'rxjs/operators';
|
||||
import { StorageKey } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
@@ -38,6 +38,7 @@ function mapStakers (era: EraIndex, stakers: KeysAndExposures): DeriveEraExposur
|
||||
export function eraExposure (api: ApiInterfaceRx): (era: EraIndex) => Observable<DeriveEraExposure> {
|
||||
return memo((era: EraIndex): Observable<DeriveEraExposure> =>
|
||||
api.query.staking.erasStakersClipped.entries(era).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
take(1),
|
||||
map((stakers) => mapStakers(era, stakers))
|
||||
)
|
||||
@@ -47,9 +48,12 @@ export function eraExposure (api: ApiInterfaceRx): (era: EraIndex) => Observable
|
||||
export function erasExposure (api: ApiInterfaceRx): (withActive?: boolean | BN | number) => Observable<DeriveEraExposure[]> {
|
||||
return memo((withActive?: boolean | BN | number): Observable<DeriveEraExposure[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((eras): Observable<DeriveEraExposure[]> =>
|
||||
eras.length
|
||||
? combineLatest(eras.map((era) => api.derive.staking.eraExposure(era)))
|
||||
? combineLatest(
|
||||
eras.map((era) => api.derive.staking.eraExposure(era))
|
||||
)
|
||||
: of([])
|
||||
)
|
||||
)
|
||||
|
||||
@@ -7,8 +7,8 @@ import { EraIndex, EraRewardPoints } from '@polkadot/types/interfaces';
|
||||
import { DeriveEraPoints, DeriveEraValPoints } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -25,6 +25,7 @@ function mapValidators ({ individual }: EraRewardPoints): DeriveEraValPoints {
|
||||
export function erasPoints (api: ApiInterfaceRx): (withActive?: boolean | BN | number) => Observable<DeriveEraPoints[]> {
|
||||
return memo((withActive?: boolean | number): Observable<DeriveEraPoints[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((eras): Observable<[EraIndex[], EraRewardPoints[]]> =>
|
||||
combineLatest([
|
||||
of(eras),
|
||||
@@ -33,6 +34,7 @@ export function erasPoints (api: ApiInterfaceRx): (withActive?: boolean | BN | n
|
||||
: of([])
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([eras, points]): DeriveEraPoints[] =>
|
||||
eras.map((era, index): DeriveEraPoints => ({
|
||||
era,
|
||||
|
||||
@@ -7,8 +7,8 @@ import { Balance, EraIndex } from '@polkadot/types/interfaces';
|
||||
import { DeriveEraRewards } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
import { Option } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
@@ -16,6 +16,7 @@ import { memo } from '../util';
|
||||
export function erasRewards (api: ApiInterfaceRx): (withActive?: boolean | BN | number) => Observable<DeriveEraRewards[]> {
|
||||
return memo((withActive?: boolean | BN | number): Observable<DeriveEraRewards[]> =>
|
||||
api.derive.staking.erasHistoric(withActive).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((eras): Observable<[EraIndex[], Option<Balance>[]]> =>
|
||||
combineLatest([
|
||||
of(eras),
|
||||
@@ -24,6 +25,7 @@ export function erasRewards (api: ApiInterfaceRx): (withActive?: boolean | BN |
|
||||
: of([])
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([eras, rewards]): DeriveEraRewards[] =>
|
||||
eras.map((era, index): DeriveEraRewards => ({
|
||||
era,
|
||||
|
||||
@@ -6,20 +6,19 @@ import { AccountId, EraIndex, EraPoints, EraRewardPoints, RewardPoint } from '@p
|
||||
import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { DerivedStakingOverview } from '../types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { createType } from '@polkadot/types';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
function retrievePointsPrev (api: ApiInterfaceRx, activeEra: EraIndex, currentElected: AccountId[]): Observable<EraRewardPoints> {
|
||||
return api.query.staking.currentEraPointsEarned<EraPoints>(activeEra).pipe(
|
||||
map(({ individual, total }): EraRewardPoints =>
|
||||
createType(api.registry, 'EraRewardPoints', {
|
||||
api.registry.createType('EraRewardPoints', {
|
||||
total,
|
||||
individual: new Map<AccountId, RewardPoint>(
|
||||
individual
|
||||
.map((points): RewardPoint => createType(api.registry, 'RewardPoint', points))
|
||||
.map((points): RewardPoint => api.registry.createType('RewardPoint', points))
|
||||
.map((points, index): [AccountId, RewardPoint] => [currentElected[index], points])
|
||||
)
|
||||
})
|
||||
@@ -36,6 +35,7 @@ export function overview (api: ApiInterfaceRx): () => Observable<DerivedStakingO
|
||||
api.derive.session.indexes(),
|
||||
api.derive.staking.validators()
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap(([indexes, { nextElected, validators }]) =>
|
||||
combineLatest([
|
||||
of({ ...indexes, nextElected, validators }),
|
||||
@@ -43,9 +43,10 @@ export function overview (api: ApiInterfaceRx): () => Observable<DerivedStakingO
|
||||
? api.query.staking.erasRewardPoints<EraRewardPoints>(indexes.activeEra)
|
||||
: api.query.staking.currentEraPointsEarned
|
||||
? retrievePointsPrev(api, indexes.activeEra, nextElected)
|
||||
: of(createType(api.registry, 'EraRewardPoints'))
|
||||
: of(api.registry.createType('EraRewardPoints'))
|
||||
])
|
||||
),
|
||||
observeOn(asyncScheduler),
|
||||
map(([info, eraPoints]): DerivedStakingOverview => ({
|
||||
...info, eraPoints
|
||||
}))
|
||||
|
||||
@@ -7,9 +7,9 @@ import { AccountId, Exposure, Keys, Nominations, RewardDestination, ValidatorPre
|
||||
import { ITuple } from '@polkadot/types/types';
|
||||
import { DerivedStakingQuery } from '../types';
|
||||
|
||||
import { combineLatest, Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { createType, Option, Vec } from '@polkadot/types';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
import { Option, Vec } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -80,7 +80,7 @@ function retrieveController (api: ApiInterfaceRx, stashId: AccountId, [queuedKey
|
||||
*/
|
||||
export function query (api: ApiInterfaceRx): (accountId: Uint8Array | string) => Observable<DerivedStakingQuery> {
|
||||
return memo((accountId: Uint8Array | string): Observable<DerivedStakingQuery> => {
|
||||
const stashId = createType(api.registry, 'AccountId', accountId);
|
||||
const stashId = api.registry.createType('AccountId', accountId);
|
||||
|
||||
return combineLatest([
|
||||
api.query.session.queuedKeys<Vec<ITuple<[AccountId, Keys]>>>(),
|
||||
@@ -88,6 +88,7 @@ export function query (api: ApiInterfaceRx): (accountId: Uint8Array | string) =>
|
||||
? retrieveCurr(api, stashId)
|
||||
: retrievePrev(api, stashId)
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap((result): Observable<DerivedStakingQuery> =>
|
||||
retrieveController(api, stashId, result)
|
||||
)
|
||||
|
||||
@@ -7,8 +7,8 @@ import { Balance } from '@polkadot/types/interfaces';
|
||||
import { DeriveEraPoints, DeriveEraRewards, DeriveStakerExposure, DeriveStakerReward } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest } from 'rxjs';
|
||||
import { map, observeOn } from 'rxjs/operators';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -67,6 +67,7 @@ export function stakerRewards (api: ApiInterfaceRx): (accountId: Uint8Array | st
|
||||
api.derive.staking.erasRewards(startEra),
|
||||
api.derive.staking.stakerExposure(stakerId, startEra)
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
map((result): DeriveStakerReward[] =>
|
||||
parseRewards(api, stakerId, result)
|
||||
)
|
||||
|
||||
@@ -6,8 +6,8 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { AccountId } from '@polkadot/types/interfaces';
|
||||
import { DeriveStakingValidators } from '../types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap, take } from 'rxjs/operators';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap, take } from 'rxjs/operators';
|
||||
import { StorageKey } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
@@ -45,6 +45,7 @@ export function validators (api: ApiInterfaceRx): () => Observable<DeriveStaking
|
||||
? api.derive.staking.nextElected()
|
||||
: of([])
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
map(([validators, nextElected]): DeriveStakingValidators => ({
|
||||
nextElected: nextElected.length
|
||||
? nextElected
|
||||
|
||||
@@ -6,9 +6,9 @@ import { ApiInterfaceRx } from '@polkadot/api/types';
|
||||
import { ProposalIndex, TreasuryProposal } from '@polkadot/types/interfaces';
|
||||
import { DerivedCollectiveProposals, DerivedTreasuryProposal, DerivedTreasuryProposals } from '../types';
|
||||
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { createType, Option } from '@polkadot/types';
|
||||
import { Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap } from 'rxjs/operators';
|
||||
import { Option } from '@polkadot/types';
|
||||
|
||||
import { memo } from '../util';
|
||||
|
||||
@@ -55,7 +55,7 @@ function retrieveProposals (api: ApiInterfaceRx, proposalCount: ProposalIndex, a
|
||||
const isApproval = approvalIds.some((id): boolean => id.eqn(index));
|
||||
|
||||
if (!isApproval) {
|
||||
proposalIds.push(createType(api.registry, 'ProposalIndex', index));
|
||||
proposalIds.push(api.registry.createType('ProposalIndex', index));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,6 +65,7 @@ function retrieveProposals (api: ApiInterfaceRx, proposalCount: ProposalIndex, a
|
||||
api.query.treasury.proposals.multi<Option<TreasuryProposal>>(allIds),
|
||||
api.derive.council.proposals()
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
map(([allProposals, councilProposals]: [Option<TreasuryProposal>[], DerivedCollectiveProposals]): DerivedTreasuryProposals =>
|
||||
parseResult(api, { allIds, allProposals, approvalIds, councilProposals, proposalCount })
|
||||
)
|
||||
@@ -81,13 +82,14 @@ export function proposals (api: ApiInterfaceRx): () => Observable<DerivedTreasur
|
||||
api.query.treasury.proposalCount(),
|
||||
api.query.treasury.approvals()
|
||||
]).pipe(
|
||||
observeOn(asyncScheduler),
|
||||
switchMap(([proposalCount, approvalIds]: [ProposalIndex, ProposalIndex[]]) =>
|
||||
retrieveProposals(api, proposalCount, approvalIds)
|
||||
)
|
||||
)
|
||||
: of({
|
||||
approvals: [],
|
||||
proposalCount: createType(api.registry, 'ProposalIndex'),
|
||||
proposalCount: api.registry.createType('ProposalIndex'),
|
||||
proposals: []
|
||||
} as DerivedTreasuryProposals)
|
||||
);
|
||||
|
||||
@@ -10,8 +10,8 @@ import { SubmittableExtrinsic } from '../submittable/types';
|
||||
import { ApiInterfaceRx, ApiOptions, ApiTypes, DecorateMethod, DecoratedRpc, DecoratedRpcSection, QueryableModuleStorage, QueryableStorage, QueryableStorageEntry, QueryableStorageMulti, QueryableStorageMultiArg, SubmittableExtrinsicFunction, SubmittableExtrinsics, SubmittableModuleExtrinsics } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { BehaviorSubject, Observable, combineLatest, of } from 'rxjs';
|
||||
import { map, switchMap, take } from 'rxjs/operators';
|
||||
import { BehaviorSubject, Observable, asyncScheduler, combineLatest, of } from 'rxjs';
|
||||
import { map, observeOn, switchMap, take } from 'rxjs/operators';
|
||||
import decorateDerive, { ExactDerive } from '@polkadot/api-derive';
|
||||
import { memo } from '@polkadot/api-derive/util';
|
||||
import DecoratedMeta from '@polkadot/metadata/Decorated';
|
||||
@@ -460,7 +460,10 @@ export default abstract class Decorate<ApiType extends ApiTypes> extends Events
|
||||
// Since we have a default constructed key, we have Option<Raw> as the result
|
||||
// Don't keep the subscription here active, retrieve and get out of Dodge
|
||||
// TODO Once we have a multiple key RPC available, use that via fallback
|
||||
this._rpcCore.state.subscribeStorage<Option<Raw>[]>(keys).pipe(take(1))
|
||||
this._rpcCore.state.subscribeStorage<Option<Raw>[]>(keys).pipe(
|
||||
take(1),
|
||||
observeOn(asyncScheduler)
|
||||
)
|
||||
])
|
||||
),
|
||||
map(([keys, values]): [StorageKey, Codec][] =>
|
||||
|
||||
Reference in New Issue
Block a user