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