Move Event, Address, AccountId, AccountIndex to generic (#1202)

* Move Event, Address, AccountId, AccountIndex to generic

* Move AccountId, AccountIndex, Address & Event to generic

* Move Vote
This commit is contained in:
Jaco Greeff
2019-07-26 16:39:28 +02:00
committed by GitHub
parent 894f07e3c9
commit 02cd1331aa
69 changed files with 247 additions and 246 deletions
@@ -2,13 +2,14 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
import { Observable, of } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { AccountId, AccountIndex, Address } from '@polkadot/types';
import { isU8a } from '@polkadot/util';
import { decodeAddress } from '@polkadot/util-crypto';
import { createType } from '@polkadot/types';
import { idToIndex } from './idToIndex';
import { indexToId } from './indexToId';
import { drr } from '../util/drr';
@@ -37,7 +38,7 @@ export function idAndIndex (api: ApiInterfaceRx): (address?: Address | AccountId
: decodeAddress((address || '').toString());
if (decoded.length === 32) {
const accountId = new AccountId(decoded);
const accountId = createType('AccountId', decoded);
return idToIndex(api)(accountId).pipe(
startWith(undefined),
@@ -46,7 +47,7 @@ export function idAndIndex (api: ApiInterfaceRx): (address?: Address | AccountId
);
}
const accountIndex = new AccountIndex(decoded);
const accountIndex = createType('AccountIndex', decoded);
return indexToId(api)(accountIndex).pipe(
startWith(undefined),
@@ -2,10 +2,11 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, AccountIndex } from '@polkadot/types/interfaces';
import { Observable } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { AccountId, AccountIndex } from '@polkadot/types';
import { indexes, AccountIndexes } from './indexes';
import { drr } from '../util/drr';
@@ -2,11 +2,13 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, AccountIndex } from '@polkadot/types/interfaces';
import { Observable } from 'rxjs';
import { map, startWith } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { ENUMSET_SIZE } from '@polkadot/types/primitive/AccountIndex';
import { AccountId, AccountIndex, Vec } from '@polkadot/types';
import { ENUMSET_SIZE } from '@polkadot/types/primitive/Generic/AccountIndex';
import { createType, ClassOf, Vec } from '@polkadot/types';
import { drr } from '../util/drr';
@@ -26,9 +28,9 @@ import { drr } from '../util/drr';
export function indexToId (api: ApiInterfaceRx): (accountIndex: AccountIndex | string) => Observable<AccountId | undefined> {
return (_accountIndex: AccountIndex | string): Observable<AccountId | undefined> => {
const querySection = api.query.indices || api.query.balances;
const accountIndex = _accountIndex instanceof AccountIndex
const accountIndex = _accountIndex instanceof ClassOf('AccountIndex')
? _accountIndex
: new AccountIndex(_accountIndex);
: createType('AccountIndex', _accountIndex);
return (querySection.enumSet<Vec<AccountId>>(accountIndex.div(ENUMSET_SIZE)))
.pipe(
+5 -3
View File
@@ -2,11 +2,13 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import { AccountId, AccountIndex } from '@polkadot/types/interfaces';
import { Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { ENUMSET_SIZE } from '@polkadot/types/primitive/AccountIndex';
import { AccountId, AccountIndex } from '@polkadot/types';
import { ENUMSET_SIZE } from '@polkadot/types/primitive/Generic/AccountIndex';
import { createType } from '@polkadot/types';
import { drr } from '../util/drr';
@@ -47,7 +49,7 @@ export function indexes (api: ApiInterfaceRx): () => Observable<AccountIndexes>
// 64 (0..63 in first) is [1][0] (the first index value in set 2)
const index = (outerIndex * enumsetSize) + innerIndex;
result[accountId.toString()] = new AccountIndex(index);
result[accountId.toString()] = createType('AccountIndex', index);
});
return result;