Remove derive {Struct,Vector}Any (new typing magic) (#1019)

* Remove derive {Struct,Vector}Any (new typing magic)

* Import ordering

* Small lint fix
This commit is contained in:
Jaco Greeff
2019-06-17 10:41:32 +02:00
committed by GitHub
parent 683ed396c2
commit 22bf06e6e0
11 changed files with 57 additions and 73 deletions
+3 -3
View File
@@ -5,7 +5,7 @@
import { combineLatest, of, Observable } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId, AccountIndex, Address, Balance, BalanceLock, BlockNumber, Index, StructAny, Option, VestingSchedule } from '@polkadot/types';
import { AccountId, AccountIndex, Address, Balance, BalanceLock, BlockNumber, Index, Option, VestingSchedule } from '@polkadot/types';
import { bnMax } from '@polkadot/util';
import { idAndIndex } from '../accounts/idAndIndex';
@@ -44,7 +44,7 @@ function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalan
// (most probably due to movements from stash -> controller -> free)
const availableBalance = bnMax(ZERO, vestedBalance.sub(lockedBalance));
return new StructAny({
return {
accountId,
accountNonce,
availableBalance,
@@ -53,7 +53,7 @@ function calcBalances ([accountId = EMPTY_ACCOUNT, bestNumber = ZERO, [freeBalan
reservedBalance,
vestedBalance,
votingBalance: freeBalance.add(reservedBalance)
}) as DerivedBalances;
} as DerivedBalances;
}
/**
+7 -9
View File
@@ -8,7 +8,6 @@ import { DerivedFees } from '../types';
import BN from 'bn.js';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { StructAny } from '@polkadot/types';
import { drr } from '../util/drr';
@@ -34,14 +33,13 @@ export function fees (api: ApiInterface$Rx) {
api.query.balances.transactionByteFee,
api.query.balances.transferFee
]) as any as Observable<[BN, BN, BN, BN, BN]>).pipe(
map(([creationFee, existentialDeposit, transactionBaseFee, transactionByteFee, transferFee]) =>
new StructAny({
creationFee,
existentialDeposit,
transactionBaseFee,
transactionByteFee,
transferFee
}) as DerivedFees),
map(([creationFee, existentialDeposit, transactionBaseFee, transactionByteFee, transferFee]) => ({
creationFee,
existentialDeposit,
transactionBaseFee,
transactionByteFee,
transferFee
} as DerivedFees)),
drr()
);
};
@@ -3,24 +3,20 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import { combineLatest, Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId, AccountIndex, Address, VectorAny } from '@polkadot/types';
import { AccountId, AccountIndex, Address } from '@polkadot/types';
import { DerivedBalances } from '../types';
import { drr } from '../util/drr';
import { all } from './all';
export function votingBalances (api: ApiInterface$Rx) {
return (addresses?: Array<AccountId | AccountIndex | Address | string>): Observable<VectorAny<DerivedBalances>> => {
return (addresses?: Array<AccountId | AccountIndex | Address | string>): Observable<Array<DerivedBalances>> => {
return (
!addresses || !addresses.length
? of([] as Array<DerivedBalances>)
: combineLatest(addresses.map(all(api)))
).pipe(
map((balances) =>
new VectorAny(...balances)
),
drr()
);
};
@@ -5,7 +5,7 @@
import { Observable, of } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId, AccountIndex, Address, Vector, VectorAny } from '@polkadot/types';
import { AccountId, AccountIndex, Address, Vector } from '@polkadot/types';
import { idAndIndex } from '../accounts/idAndIndex';
import { DerivedBalances } from '../types';
@@ -13,7 +13,7 @@ import { drr } from '../util/drr';
import { votingBalances } from './votingBalances';
export function votingBalancesNominatorsFor (api: ApiInterface$Rx) {
return (address: AccountId | AccountIndex | Address | string): Observable<VectorAny<DerivedBalances>> => {
return (address: AccountId | AccountIndex | Address | string): Observable<Array<DerivedBalances>> => {
return idAndIndex(api)(address).pipe(
switchMap(([accountId]) =>
accountId
+12 -15
View File
@@ -8,7 +8,6 @@ import { DerivedContractFees } from '../types';
import BN from 'bn.js';
import { Observable } from 'rxjs';
import { map } from 'rxjs/operators';
import { StructAny } from '@polkadot/types';
import { drr } from '../util/drr';
@@ -29,20 +28,18 @@ export function fees (api: ApiInterface$Rx) {
api.query.contract.transferFee,
api.query.contract.tombstoneDeposit
]) as any as Observable<Array<BN>>).pipe(
map(([callBaseFee, contractFee, createBaseFee, creationFee, rentByteFee, rentDepositOffset, transactionBaseFee, transactionByteFee, transferFee, tombstoneDeposit]) =>
new StructAny({
callBaseFee,
contractFee,
createBaseFee,
creationFee,
rentByteFee,
rentDepositOffset,
transactionBaseFee,
transactionByteFee,
transferFee,
tombstoneDeposit
}) as DerivedContractFees
),
map(([callBaseFee, contractFee, createBaseFee, creationFee, rentByteFee, rentDepositOffset, transactionBaseFee, transactionByteFee, transferFee, tombstoneDeposit]) => ({
callBaseFee,
contractFee,
createBaseFee,
creationFee,
rentByteFee,
rentDepositOffset,
transactionBaseFee,
transactionByteFee,
transferFee,
tombstoneDeposit
} as DerivedContractFees)),
drr()
);
};
@@ -6,24 +6,22 @@ import BN from 'bn.js';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { Option, ReferendumInfo, VectorAny } from '@polkadot/types';
import { Option, ReferendumInfo, Vector } from '@polkadot/types';
import { ReferendumInfoExtended } from '../type';
import { drr } from '../util/drr';
import { constructInfo } from './referendumInfo';
export function referendumInfos (api: ApiInterface$Rx) {
return (ids: Array<BN | number> = []): Observable<VectorAny<Option<ReferendumInfoExtended>>> => {
return (ids: Array<BN | number> = []): Observable<Array<Option<ReferendumInfoExtended>>> => {
return (
!ids || !ids.length
? of([] as Array<Option<ReferendumInfo>>)
: api.query.democracy.referendumInfoOf.multi(ids) as Observable<VectorAny<Option<ReferendumInfo>>>
: api.query.democracy.referendumInfoOf.multi(ids) as Observable<Vector<Option<ReferendumInfo>>>
).pipe(
map((infos) =>
new VectorAny(
...ids.map((id, index) =>
constructInfo(id, infos[index])
)
ids.map((id, index) =>
constructInfo(id, infos[index])
)
),
drr()
@@ -6,7 +6,7 @@ import BN from 'bn.js';
import { combineLatest, Observable, of } from 'rxjs';
import { map, switchMap } from 'rxjs/operators';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId, Balance, StructAny, Vector, VectorAny, Vote } from '@polkadot/types';
import { AccountId, Balance, Vector, Vote } from '@polkadot/types';
import { DerivedReferendumVote } from '../types';
import { drr } from '../util/drr';
@@ -14,7 +14,7 @@ import { votes } from './votes';
import { votingBalances } from '../balances/votingBalances';
export function referendumVotesFor (api: ApiInterface$Rx) {
return (referendumId: BN | number): Observable<VectorAny<DerivedReferendumVote>> =>
return (referendumId: BN | number): Observable<Array<DerivedReferendumVote>> =>
(api.query.democracy.votersFor<Vector<AccountId>>(referendumId)).pipe(
switchMap((votersFor) =>
combineLatest([
@@ -24,17 +24,12 @@ export function referendumVotesFor (api: ApiInterface$Rx) {
])
),
map(([votersFor, votes, balances]) =>
new VectorAny(
...votersFor.map((accountId, index): DerivedReferendumVote =>
new StructAny({
accountId,
balance: balances[index].votingBalance || new Balance(0),
vote: votes[index] || new Vote(0)
}) as DerivedReferendumVote
)
)
votersFor.map((accountId, index): DerivedReferendumVote => ({
accountId,
balance: balances[index].votingBalance || new Balance(0),
vote: votes[index] || new Vote(0)
} as DerivedReferendumVote))
),
drr()
);
}
+7 -7
View File
@@ -5,18 +5,18 @@
import BN from 'bn.js';
import { Observable, of } from 'rxjs';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { AccountId, VectorAny, Vote } from '@polkadot/types';
import { AccountId, Vector, Vote } from '@polkadot/types';
import { drr } from '../util/drr';
export function votes (api: ApiInterface$Rx) {
return (referendumId: BN, accountIds: Array<AccountId> = []): Observable<VectorAny<Vote>> => {
return (
return (referendumId: BN, accountIds: Array<AccountId> = []): Observable<Array<Vote>> => {
return ((
!accountIds || !accountIds.length
? of(new VectorAny<Vote>())
? of([])
: api.query.democracy.voteOf.multi(
accountIds.map(accountId => [referendumId, accountId])
) as Observable<VectorAny<Vote>>
).pipe(drr());
accountIds.map((accountId) => [referendumId, accountId])
)
) as Observable<Vector<Vote>>).pipe(drr());
};
}
+5 -5
View File
@@ -8,7 +8,7 @@ import BN from 'bn.js';
import { Observable, combineLatest, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { ApiInterface$Rx } from '@polkadot/api/types';
import { BlockNumber, Option, StructAny } from '@polkadot/types';
import { BlockNumber, Option } from '@polkadot/types';
import { drr } from '../util/drr';
import { bestNumber } from '../chain';
@@ -35,7 +35,7 @@ function createDerived0_94 ([bestNumber, [currentIndex, _lastLengthChange, sessi
.mul(sessionLength)
.add(sessionProgress);
return new StructAny({
return {
currentEra,
currentIndex,
eraLength,
@@ -45,13 +45,13 @@ function createDerived0_94 ([bestNumber, [currentIndex, _lastLengthChange, sessi
sessionLength,
sessionsPerEra,
sessionProgress
}) as DerivedSessionInfo;
} as DerivedSessionInfo;
}
function createDerived ([sessionsPerEra, [currentIndex, currentEra]]: Result): DerivedSessionInfo {
const eraProgress = (currentIndex).mod(sessionsPerEra);
return new StructAny({
return {
currentEra,
currentIndex,
eraLength: ZERO,
@@ -61,7 +61,7 @@ function createDerived ([sessionsPerEra, [currentIndex, currentEra]]: Result): D
sessionLength: ZERO,
sessionsPerEra,
sessionProgress: ZERO
}) as DerivedSessionInfo;
} as DerivedSessionInfo;
}
/**
+1 -1
View File
@@ -13,8 +13,8 @@ import { AccountId, BlockNumber, Exposure, Keys, Option, RewardDestination, Sess
import { isUndefined } from '@polkadot/util';
import { bestNumber } from '../chain/bestNumber';
import { drr } from '../util/drr';
import { eraLength } from '../session/eraLength';
import { drr } from '../util/drr';
function calculateUnlocking (stakingLedger: StakingLedger | undefined, eraLength: BN, bestNumber: BlockNumber): DerivedUnlocking | undefined {
if (isUndefined(stakingLedger)) {
+6 -6
View File
@@ -3,9 +3,9 @@
// of the Apache-2.0 license. See the LICENSE file for details.
import BN from 'bn.js';
import { AccountId, Balance, Exposure, Index, RewardDestination, StakingLedger, StructAny, ValidatorPrefs, Vote } from '@polkadot/types';
import { AccountId, Balance, Exposure, Index, RewardDestination, StakingLedger, ValidatorPrefs, Vote } from '@polkadot/types';
export interface DerivedBalances extends StructAny {
export interface DerivedBalances {
accountId: AccountId;
accountNonce: Index;
freeBalance: BN;
@@ -20,7 +20,7 @@ export type DerivedBalancesMap = {
[index: string]: DerivedBalances
};
export interface DerivedContractFees extends StructAny {
export interface DerivedContractFees {
callBaseFee: BN;
contractFee: BN;
createBaseFee: BN;
@@ -33,7 +33,7 @@ export interface DerivedContractFees extends StructAny {
tombstoneDeposit: BN;
}
export interface DerivedFees extends StructAny {
export interface DerivedFees {
creationFee: BN;
existentialDeposit: BN;
transactionBaseFee: BN;
@@ -41,13 +41,13 @@ export interface DerivedFees extends StructAny {
transferFee: BN;
}
export interface DerivedReferendumVote extends StructAny {
export interface DerivedReferendumVote {
accountId: AccountId;
balance: Balance;
vote: Vote;
}
export interface DerivedSessionInfo extends StructAny {
export interface DerivedSessionInfo {
currentEra: BN;
currentIndex: BN;
eraLength: BN;