diff --git a/packages/api-derive/src/contracts/fees.ts b/packages/api-derive/src/contracts/fees.ts index 8bae4eaeb8..556821b381 100644 --- a/packages/api-derive/src/contracts/fees.ts +++ b/packages/api-derive/src/contracts/fees.ts @@ -11,8 +11,26 @@ import { map } from 'rxjs/operators'; import { drr } from '../util/drr'; +type ResultV2 = [BN, BN, BN, BN, BN, BN, BN, BN, BN, BN]; + const ZERO = new BN(0); +// parse the result +function parseResult ([callBaseFee, contractFee, createBaseFee, creationFee, rentByteFee, rentDepositOffset, tombstoneDeposit, transactionBaseFee, transactionByteFee, transferFee]: ResultV2): DerivedContractFees { + return { + callBaseFee, + contractFee, + createBaseFee, + creationFee, + rentByteFee, + rentDepositOffset, + tombstoneDeposit, + transactionBaseFee, + transactionByteFee, + transferFee + }; +} + // Only for 1.0 support. rentByteFee, rentDepositOffset, tombstoneDeposit are not available in substrate 1.0. // TODO remove this once 1.0 support is dropped function queryV1 (api: ApiInterfaceRx): Observable { @@ -27,24 +45,19 @@ function queryV1 (api: ApiInterfaceRx): Observable { api.query.contract.transferFee ]) as unknown as Observable ).pipe( - map(([callBaseFee, contractFee, createBaseFee, creationFee, transactionBaseFee, transactionByteFee, transferFee]): DerivedContractFees => ({ - callBaseFee, - contractFee, - createBaseFee, - creationFee, - rentByteFee: ZERO, - rentDepositOffset: ZERO, - tombstoneDeposit: ZERO, - transactionBaseFee, - transactionByteFee, - transferFee - } as unknown as DerivedContractFees)), + map(([callBaseFee, contractFee, createBaseFee, creationFee, transactionBaseFee, transactionByteFee, transferFee]): DerivedContractFees => + // We've done this on purpose, i.e. so we can just copy the name/order from the parse above and + // see gaps, in this case those are filled with `ZERO` + parseResult([ + callBaseFee, contractFee, createBaseFee, creationFee, ZERO, ZERO, ZERO, transactionBaseFee, transactionByteFee, transferFee + ]) + ), drr() ); } // query via query (early v2, non-current, support to be dropped]) -function queryQuery (api: ApiInterfaceRx): Observable { +function queryQuery (api: ApiInterfaceRx): Observable { const queryBase = api.query.contracts || api.query.contract; return api.queryMulti([ @@ -58,11 +71,11 @@ function queryQuery (api: ApiInterfaceRx): Observable { queryBase.transactionBaseFee, queryBase.transactionByteFee, queryBase.transferFee - ]) as unknown as Observable; + ]) as unknown as Observable; } // query via constants (current applicable path) -function queryConstants (api: ApiInterfaceRx): Observable { +function queryConstants (api: ApiInterfaceRx): Observable { return of([ api.consts.contracts.callBaseFee, api.consts.contracts.contractFee, @@ -74,7 +87,7 @@ function queryConstants (api: ApiInterfaceRx): Observable { api.consts.contracts.transactionBaseFee, api.consts.contracts.transactionByteFee, api.consts.contracts.transferFee - ]) as unknown as Observable; + ]) as unknown as Observable; } /** @@ -101,19 +114,11 @@ export function fees (api: ApiInterfaceRx): () => Observable ({ - callBaseFee, - contractFee, - createBaseFee, - creationFee, - rentByteFee, - rentDepositOffset, - tombstoneDeposit, - transactionBaseFee, - transactionByteFee, - transferFee - } as unknown as DerivedContractFees) + map(([callBaseFee, contractFee, createBaseFee, creationFee, rentByteFee, rentDepositOffset, tombstoneDeposit, transactionBaseFee, transactionByteFee, transferFee]): DerivedContractFees => + // We've done this on purpose, i.e. so we can just copy the name/order from the parse above and see gaps + parseResult([ + callBaseFee, contractFee, createBaseFee, creationFee, rentByteFee, rentDepositOffset, tombstoneDeposit, transactionBaseFee, transactionByteFee, transferFee + ]) ), drr() ); diff --git a/packages/api-derive/src/staking/controllers.ts b/packages/api-derive/src/staking/controllers.ts index 07b018c239..7ef4f91e33 100644 --- a/packages/api-derive/src/staking/controllers.ts +++ b/packages/api-derive/src/staking/controllers.ts @@ -3,6 +3,7 @@ // of the Apache-2.0 license. See the LICENSE file for details. import { AccountId } from '@polkadot/types/interfaces'; +import { Codec } from '@polkadot/types/types'; import { Observable, combineLatest, of } from 'rxjs'; import { switchMap } from 'rxjs/operators'; @@ -16,7 +17,8 @@ import { drr } from '../util/drr'; */ export function controllers (api: ApiInterfaceRx): () => Observable<[AccountId[], Option[]]> { return (): Observable<[AccountId[], Option[]]> => - (api.query.staking.validators() as any as Observable<[AccountId[], any]>) + api.query.staking + .validators<[AccountId[]] & Codec>() .pipe( switchMap(([stashIds]): Observable<[AccountId[], Option[]]> => combineLatest([