Some non-functionality readability cleanups (#1295)

* Some non-functionality readability cleanups

* Small Address cleanups
This commit is contained in:
Jaco Greeff
2019-08-11 21:45:16 +02:00
committed by GitHub
parent ddc5f40a27
commit 07b89e759c
7 changed files with 79 additions and 74 deletions
+27 -17
View File
@@ -11,6 +11,31 @@ import { map } from 'rxjs/operators';
import { drr } from '../util/drr';
type Result = [BN, BN, BN, BN, BN];
function querySubtrateV2 (api: ApiInterfaceRx): Observable<Result> {
return of([
// get values from api.const for substrate versions post spec_version: 101
// https://github.com/paritytech/substrate/pull/2883/files#diff-5e5e1c3aec9ddfde0a9054d062ab3db9R131
api.consts.balances.creationFee,
api.consts.balances.existentialDeposit,
api.consts.balances.transactionBaseFee,
api.consts.balances.transactionByteFee,
api.consts.balances.transferFee
]) as any as Observable<Result>;
}
function querySubtrateV1 (api: ApiInterfaceRx): Observable<Result> {
return api.queryMulti([
// Support older versions and get values from storage
api.query.balances.creationFee,
api.query.balances.existentialDeposit,
api.query.balances.transactionBaseFee,
api.query.balances.transactionByteFee,
api.query.balances.transferFee
]) as any as Observable<Result>;
}
/**
* @name fees
* @returns An object containing the combined results of the storage queries for
@@ -28,23 +53,8 @@ export function fees (api: ApiInterfaceRx): () => Observable<DerivedFees> {
return (): Observable<DerivedFees> => {
return (
api.consts.balances
? of([
// get values from api.const for substrate versions post spec_version: 101
// https://github.com/paritytech/substrate/pull/2883/files#diff-5e5e1c3aec9ddfde0a9054d062ab3db9R131
api.consts.balances.creationFee,
api.consts.balances.existentialDeposit,
api.consts.balances.transactionBaseFee,
api.consts.balances.transactionByteFee,
api.consts.balances.transferFee
]) as any as Observable<[BN, BN, BN, BN, BN]>
: api.queryMulti([
// Support older versions and get values from storage
api.query.balances.creationFee,
api.query.balances.existentialDeposit,
api.query.balances.transactionBaseFee,
api.query.balances.transactionByteFee,
api.query.balances.transferFee
]) as any as Observable<[BN, BN, BN, BN, BN]>
? querySubtrateV2(api)
: querySubtrateV1(api)
).pipe(
map(([creationFee, existentialDeposit, transactionBaseFee, transactionByteFee, transferFee]): DerivedFees => ({
creationFee,
+9 -9
View File
@@ -21,7 +21,6 @@ const ZERO = new BN(0);
// internal helper to just split the logic - take all inputs, do the calculations and combine
function createDerived0to94 ([bestNumber, [currentIndex, _lastLengthChange, sessionLength, lastEraLengthChange, sessionsPerEra]]: Result0to94): DerivedSessionInfo {
const eraLength = sessionLength.mul(sessionsPerEra);
const lastLengthChange = _lastLengthChange
? _lastLengthChange.unwrapOr(ZERO)
: ZERO;
@@ -32,15 +31,14 @@ function createDerived0to94 ([bestNumber, [currentIndex, _lastLengthChange, sess
const currentEra = (currentIndex)
.sub(lastEraLengthChange)
.mod(sessionsPerEra);
const eraProgress = currentEra
.mul(sessionLength)
.add(sessionProgress);
return {
currentEra,
currentIndex,
eraLength,
eraProgress,
eraLength: sessionLength.mul(sessionsPerEra),
eraProgress: currentEra
.mul(sessionLength)
.add(sessionProgress),
isEpoch: false,
lastEraLengthChange,
lastLengthChange,
@@ -52,15 +50,17 @@ function createDerived0to94 ([bestNumber, [currentIndex, _lastLengthChange, sess
function createDerived ([[epochDuration, sessionsPerEra], [currentSlot, epochIndex, epochStartSlot, currentIndex, currentEra]]: Result): DerivedSessionInfo {
const sessionProgress = currentSlot.sub(epochStartSlot);
const eraLength = sessionsPerEra.mul(epochDuration);
const eraProgress = epochIndex.mod(sessionsPerEra).mul(epochDuration).add(sessionProgress);
const eraProgress = epochIndex
.mod(sessionsPerEra)
.mul(epochDuration)
.add(sessionProgress);
// FIXME This alwasy assumes Babe, as per the substrate defaults - at least for
// aura the `isEpoch` should be false
return {
currentEra,
currentIndex,
eraLength,
eraLength: sessionsPerEra.mul(epochDuration),
eraProgress,
isEpoch: true,
lastEraLengthChange: ZERO,
@@ -50,9 +50,7 @@ export default class HeaderExtended extends _Header {
// extract author from the seal (pre substrate 1.0, backwards compat)
if (sitem) {
this._author = sessionValidators[
sitem.asSealV0[0].modn(sessionValidators.length)
];
this._author = sessionValidators[sitem.asSealV0[0].modn(sessionValidators.length)];
}
}
}