Add derive functions (#564)
* Add drr * Update headers * Lint * Copy other functions * Account indexes * accountIndexToId * accountIdAndIndex * Fees * votingBalance * votingBalances * votingBalancesNominatorsFor * validatingBalance * validatingBalances * bestNumberFinalised * eraLength * Add drr * eraProgress * votes * referendumInfos * referendumVotesFor * referendums * Clean code * Add tests * Fix lint * Fix bug eraProgress * Fix bug fees * combineLatest without array * Fix lint
This commit is contained in:
@@ -7,6 +7,8 @@ import { filter, map } from 'rxjs/operators';
|
||||
import ApiRx from '@polkadot/api/rx';
|
||||
import { BlockNumber, Header } from '@polkadot/types/index';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
/**
|
||||
* Get the latest block number.
|
||||
*/
|
||||
@@ -15,6 +17,7 @@ export function bestNumber (api: ApiRx) {
|
||||
api.rpc.chain.subscribeNewHead()
|
||||
.pipe(
|
||||
filter((header: Header) => header && !!header.blockNumber),
|
||||
map(({ blockNumber }: Header) => blockNumber)
|
||||
map(({ blockNumber }: Header) => blockNumber),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { Observable } from 'rxjs';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import ApiRx from '@polkadot/api/rx';
|
||||
import { BlockNumber, Header } from '@polkadot/types/index';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
/**
|
||||
* Get the latest finalised block number.
|
||||
*/
|
||||
export function bestNumberFinalised (api: ApiRx) {
|
||||
return (): Observable<BlockNumber> =>
|
||||
api.rpc.chain.subscribeFinalisedHeads()
|
||||
.pipe(
|
||||
filter((header: Header) => header && !!header.blockNumber),
|
||||
map(({ blockNumber }: Header) => blockNumber),
|
||||
drr()
|
||||
);
|
||||
}
|
||||
@@ -3,3 +3,4 @@
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export * from './bestNumber';
|
||||
export * from './bestNumberFinalised';
|
||||
|
||||
Reference in New Issue
Block a user