Create AccountIndex from number (#304)

This commit is contained in:
Jaco Greeff
2018-10-15 22:54:16 +02:00
committed by GitHub
parent 5638a0cd1f
commit 1b7640fb9f
4 changed files with 51 additions and 13 deletions
+2 -2
View File
@@ -29,8 +29,8 @@ export default class ApiCombined extends ApiCalls {
: new BN(0);
return this.combine(
Array(lastIndex.toNumber()).map((_, i): Observable<Array<AccountId> | undefined> =>
this.getAccountEnumSet(i)
Array(lastIndex.div(ENUMSET_SIZE).toNumber()).map((_, i): Observable<Array<AccountId> | undefined> =>
this.getAccountEnumSet(i * ENUMSET_SIZE.toNumber())
),
(...all: Array<Array<AccountId> | undefined>) => {
return all.reduce((result, list = [], outerIndex: number) => {
+3 -9
View File
@@ -9,9 +9,7 @@ import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import storage from '@polkadot/storage/static';
import { AccountId, AccountIndex, Balance, bool as Bool, BlockNumber, Index, Moment, Perbill, PropIndex, ReferendumIndex, u32 } from '@polkadot/types/index';
import { ENUMSET_SIZE } from '@polkadot/types/AccountIndex';
import { Tuple, U8a, Vector } from '@polkadot/types/codec';
import bnToU8a from '@polkadot/util/bn/toU8a';
import { Tuple, Vector } from '@polkadot/types/codec';
import ApiBase from './Base';
import { RxProposal, RxProposalDeposits, RxReferendum } from './classes';
@@ -48,12 +46,8 @@ export default class ApiQueries extends ApiBase {
return this.rawStorage(storage.democracy.nextTally);
}
getAccountEnumSet = (_index: AccountIndex | BN | number): Observable<Array<AccountId> | undefined> => {
const index = _index instanceof AccountIndex
? _index.toBn().div(ENUMSET_SIZE)
: _index;
return this.rawStorage(storage.balances.enumSet, new U8a(bnToU8a(index, 32, true)));
getAccountEnumSet = (index: AccountIndex | BN | number): Observable<Array<AccountId> | undefined> => {
return this.rawStorage(storage.balances.enumSet, index);
}
nextAccountEnumSet = (): Observable<AccountIndex | undefined> => {