Use tsconfig references (#4328)

* Use tsconfig references

* Move types-known (temp until lower-level split)

* Sources

* Adjust

* tesconfig.eslint.json

* Bumps

* AdjustAdjust

* Linting passing... a start...

* Adjust

* Merge derive

* Merge

* api-contract-support

* It builds?

* compare locations
This commit is contained in:
Jaco
2021-12-14 12:04:50 +02:00
committed by GitHub
parent cbb5a021a0
commit 736fd536f9
292 changed files with 1675 additions and 1273 deletions
-13
View File
@@ -1,13 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import { BN } from '@polkadot/util';
export const FALLBACK_MAX_HASH_COUNT = 250;
// default here to 5 min eras, adjusted based on the actual blocktime
export const FALLBACK_PERIOD = new BN(6 * 1000);
export const MAX_FINALITY_LAG = new BN(5);
export const MORTAL_PERIOD = new BN(5 * 60 * 1000);
-30
View File
@@ -1,30 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { EventRecord, Hash, SignedBlock } from '@polkadot/types/interfaces';
import { combineLatest, map, switchMap } from 'rxjs';
import { memo } from '../util';
interface Result {
block: SignedBlock;
events: EventRecord[];
}
export function events (instanceId: string, api: ApiInterfaceRx): (at: Hash) => Observable<Result> {
return memo(instanceId, (blockHash: Hash) =>
combineLatest([
api.rpc.chain.getBlock(blockHash),
api.queryAt(blockHash).pipe(
switchMap((queryAt) =>
queryAt.system.events()
)
)
]).pipe(
map(([block, events]): Result => ({ block, events }))
)
);
}
-5
View File
@@ -1,5 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
export * from './events';
export * from './signingInfo';
-88
View File
@@ -1,88 +0,0 @@
// Copyright 2017-2021 @polkadot/api-derive authors & contributors
// SPDX-License-Identifier: Apache-2.0
import type { Observable } from 'rxjs';
import type { ApiInterfaceRx } from '@polkadot/api/types';
import type { Header, Index } from '@polkadot/types/interfaces';
import type { AnyNumber, Codec, IExtrinsicEra } from '@polkadot/types/types';
import { combineLatest, map, of, switchMap } from 'rxjs';
import { isNumber, isUndefined } from '@polkadot/util';
import { FALLBACK_MAX_HASH_COUNT, FALLBACK_PERIOD, MAX_FINALITY_LAG, MORTAL_PERIOD } from './constants';
interface Result {
header: Header | null;
mortalLength: number;
nonce: Index;
}
function latestNonce (api: ApiInterfaceRx, address: string): Observable<Index> {
return api.derive.balances.account(address).pipe(
map(({ accountNonce }) => accountNonce)
);
}
function nextNonce (api: ApiInterfaceRx, address: string): Observable<Index> {
return api.rpc.system?.accountNextIndex
? api.rpc.system.accountNextIndex(address)
: latestNonce(api, address);
}
function signingHeader (api: ApiInterfaceRx): Observable<Header> {
return combineLatest([
api.rpc.chain.getHeader().pipe(
switchMap((header) =>
// check for chains at genesis (until block 1 is produced, e.g. 6s), since
// we do need to allow transactions at chain start (also dev/seal chains)
header.parentHash.isEmpty
? of(header)
// in the case of the current block, we use the parent to minimize the
// impact of forks on the system, but not completely remove it
: api.rpc.chain.getHeader(header.parentHash)
)
),
api.rpc.chain.getFinalizedHead().pipe(
switchMap((hash) =>
api.rpc.chain.getHeader(hash)
)
)
]).pipe(
map(([current, finalized]) =>
// determine the hash to use, current when lag > max, else finalized
current.number.unwrap().sub(finalized.number.unwrap()).gt(MAX_FINALITY_LAG)
? current
: finalized
)
);
}
export function signingInfo (_instanceId: string, api: ApiInterfaceRx): (address: string, nonce?: AnyNumber | Codec, era?: IExtrinsicEra | number) => Observable<Result> {
// no memo, we want to do this fresh on each run
return (address: string, nonce?: AnyNumber | Codec, era?: IExtrinsicEra | number): Observable<Result> =>
combineLatest([
// retrieve nonce if none was specified
isUndefined(nonce)
? latestNonce(api, address)
: nonce === -1
? nextNonce(api, address)
: of(api.registry.createType('Index', nonce)),
// if no era (create) or era > 0 (mortal), do block retrieval
(isUndefined(era) || (isNumber(era) && era > 0))
? signingHeader(api)
: of(null)
]).pipe(
map(([nonce, header]) => ({
header,
mortalLength: Math.min(
api.consts.system?.blockHashCount?.toNumber() || FALLBACK_MAX_HASH_COUNT,
MORTAL_PERIOD
.div(api.consts.babe?.expectedBlockTime || api.consts.timestamp?.minimumPeriod.muln(2) || FALLBACK_PERIOD)
.iadd(MAX_FINALITY_LAG)
.toNumber()
),
nonce
}))
);
}