Add contract fees (#875)
This commit is contained in:
@@ -16,12 +16,8 @@ export function fees (api: ApiInterface$Rx) {
|
||||
return (combineLatest([
|
||||
api.query.balances.creationFee(),
|
||||
api.query.balances.existentialDeposit(),
|
||||
api.query.fees
|
||||
? api.query.fees.transactionBaseFee()
|
||||
: api.query.balances.transactionBaseFee(),
|
||||
api.query.fees
|
||||
? api.query.fees.transactionByteFee()
|
||||
: api.query.balances.transactionByteFee(),
|
||||
api.query.balances.transactionBaseFee(),
|
||||
api.query.balances.transactionByteFee(),
|
||||
api.query.balances.transferFee()
|
||||
]) as any as Observable<[BN, BN, BN, BN, BN]>).pipe(
|
||||
map(([creationFee, existentialDeposit, transactionBaseFee, transactionByteFee, transferFee]) => ({
|
||||
@@ -32,6 +28,6 @@ export function fees (api: ApiInterface$Rx) {
|
||||
transferFee
|
||||
})),
|
||||
drr()
|
||||
) ;
|
||||
);
|
||||
};
|
||||
}
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
import { ApiInterface$Rx, QueryableStorageFunctionBase } from '@polkadot/api/types';
|
||||
import { Codec } from '@polkadot/types/types';
|
||||
import { DerivedContractFees } from '../types';
|
||||
|
||||
import BN from 'bn.js';
|
||||
import { Observable, combineLatest, of } from 'rxjs';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { drr } from '../util/drr';
|
||||
|
||||
// TODO The contracts API is still in flux, so some of these may disappear or re-appear or get replaced. Instead of
|
||||
// failing here, do best effort - if something does not exist, return 0 for the specific value. Should be removed
|
||||
// when actually stable and no more changes expected
|
||||
function nonexistentZero (fn: QueryableStorageFunctionBase<Observable<Codec>, Observable<Codec>>): Observable<BN> {
|
||||
return fn
|
||||
? fn() as any as Observable<BN>
|
||||
: of(new BN(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the balances for all intentions and their nominators
|
||||
*/
|
||||
export function fees (api: ApiInterface$Rx) {
|
||||
// TODO Once we have muti support for disjointed queries, add here (so we make a single
|
||||
// query for all these to the node).
|
||||
return (): Observable<DerivedContractFees> => {
|
||||
return (combineLatest([
|
||||
nonexistentZero(api.query.contract.callBaseFee),
|
||||
nonexistentZero(api.query.contract.contractFee),
|
||||
nonexistentZero(api.query.contract.createBaseFee),
|
||||
nonexistentZero(api.query.contract.creationFee),
|
||||
nonexistentZero(api.query.contract.rentByteFee),
|
||||
nonexistentZero(api.query.contract.rentDepositOffset),
|
||||
nonexistentZero(api.query.contract.transactionBaseFee),
|
||||
nonexistentZero(api.query.contract.transactionByteFee),
|
||||
nonexistentZero(api.query.contract.transferFee),
|
||||
nonexistentZero(api.query.contract.tombstoneDeposit)
|
||||
]) as any as Observable<Array<BN>>).pipe(
|
||||
map(([callBaseFee, contractFee, createBaseFee, creationFee, rentByteFee, rentDepositOffset, transactionBaseFee, transactionByteFee, transferFee, tombstoneDeposit]) => {
|
||||
return {
|
||||
callBaseFee,
|
||||
contractFee,
|
||||
createBaseFee,
|
||||
creationFee,
|
||||
rentByteFee,
|
||||
rentDepositOffset,
|
||||
transactionBaseFee,
|
||||
transactionByteFee,
|
||||
transferFee,
|
||||
tombstoneDeposit
|
||||
};
|
||||
}),
|
||||
drr()
|
||||
);
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
// Copyright 2017-2019 @polkadot/api-derive authors & contributors
|
||||
// This software may be modified and distributed under the terms
|
||||
// of the Apache-2.0 license. See the LICENSE file for details.
|
||||
|
||||
export * from './fees';
|
||||
@@ -8,6 +8,7 @@ import { ApiInterface$Rx } from '@plugnet/api/types';
|
||||
import * as accounts from './accounts';
|
||||
import * as balances from './balances';
|
||||
import * as chain from './chain';
|
||||
import * as contract from './contract';
|
||||
import * as democracy from './democracy';
|
||||
import * as session from './session';
|
||||
import * as staking from './staking';
|
||||
@@ -37,6 +38,7 @@ export interface Derive {
|
||||
accounts: ReturnTypes<typeof accounts>;
|
||||
balances: ReturnTypes<typeof balances>;
|
||||
chain: ReturnTypes<typeof chain>;
|
||||
contract: ReturnTypes<typeof contract>;
|
||||
democracy: ReturnTypes<typeof democracy>;
|
||||
session: ReturnTypes<typeof session>;
|
||||
staking: ReturnTypes<typeof staking>;
|
||||
|
||||
@@ -32,3 +32,16 @@ export type DerivedReferendumVote = {
|
||||
balance: Balance,
|
||||
vote: Vote
|
||||
};
|
||||
|
||||
export type DerivedContractFees = {
|
||||
callBaseFee: BN,
|
||||
contractFee: BN,
|
||||
createBaseFee: BN,
|
||||
creationFee: BN,
|
||||
rentByteFee: BN,
|
||||
rentDepositOffset: BN,
|
||||
transactionBaseFee: BN,
|
||||
transactionByteFee: BN,
|
||||
transferFee: BN,
|
||||
tombstoneDeposit: BN
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user