Extend type generation (#1783)

* Cleanup type overrides

* Generate (with catch-all removal)

* Progress

* Re-gen tx types

* Remove unneeded option check

* Linting updates

* Update CHANGELOG (cleanups as per comments)
This commit is contained in:
Jaco Greeff
2020-01-31 15:34:06 +01:00
committed by GitHub
parent 982665c337
commit 4aa5693906
34 changed files with 1053 additions and 795 deletions
+3 -1
View File
@@ -4,6 +4,8 @@ exclude_patterns:
- "**/*.test.js"
- "**/*.test.ts"
- "docs/**/*.js"
- "packages/api/src/query.types.ts"
- "packages/api/src/types/augment/consts.ts"
- "packages/api/src/types/augment/query.ts"
- "packages/api/src/types/augment/tx.ts"
- "packages/types/src/interfaces/"
- "packages/types/src/scripts/"
+11 -6
View File
@@ -1,3 +1,8 @@
# 1.1.0-beta.x
- Add typings for `api.tx.*.*` - the `polkadot-types-from-chain` now also generates these
- Remove additional V1-only derives `(staking.recentlyOffline`, `balances.nominatorsFor`)
# 1.0.1
- **Breaking change** Drop support for Substrate v1 chain in all derives
@@ -6,15 +11,15 @@
- Add `polkadot-types-from-chain` & `polkadot-types-from-defs` TypeScript generators to `@polkadot/types`
- Only decorate derives where relevant parent `api.query.*` is available
- Support `.entries(arg?: any)` lookups on DoubleMaps (in addition to previously supported maps)
- Remove un-deployed support for v11 metadata (this was decided against on Substrate)
- Allow v9 metadata to parse even in cases where it was wrongly deployed pre-v10
- Allow type-aliasses on a per-module basis (e.g. `Judgement` in identity as well as society)
- Allow type-aliases on a per-module basis (e.g. `Judgement` in identity as well as society)
- Allow passing `{ signer }` to both `api.tx.*` and `api.sign` (in addition to `api.setSigner`)
- Add derives for the society module
- Don't map empy tuples, e.. `()` to `Null`, rather keep them empty
- Add lookups to the metadata erros via `findMetaError`
- Update metadata and types for the lastest Substrate & Polkadot versions
- Support metadata V11 as per lastest Substrate
- Don't map empty tuples, e.. `()` to `Null`, rather keep them empty
- Add lookups to the metadata errors via `findMetaError`
- Update metadata and types for the latest Substrate & Polkadot versions
- Support metadata V11 as per latest Substrate
- Remove support for un-deployed metadata
- Remove old known types for Substrate V1
# 0.100.1
@@ -6,7 +6,6 @@ import { all } from './all';
export * from './fees';
export * from './votingBalances';
export * from './votingBalancesNominatorsFor';
const votingBalance = all;
@@ -1,27 +0,0 @@
// Copyright 2017-2020 @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 { AccountId, AccountIndex, Address } from '@polkadot/types/interfaces';
import { DerivedBalances } from '../types';
import { Observable, of } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { ApiInterfaceRx } from '@polkadot/api/types';
import { Vec } from '@polkadot/types';
import { memo } from '../util';
export function votingBalancesNominatorsFor (api: ApiInterfaceRx): (address: AccountId | AccountIndex | Address | string) => Observable<DerivedBalances[]> {
return memo((address: AccountId | AccountIndex | Address | string): Observable<DerivedBalances[]> =>
api.derive.accounts.info(address).pipe(
switchMap(({ accountId }): Observable<AccountId[]> =>
accountId
? api.query.staking.nominatorsFor<Vec<AccountId>>(accountId)
: of([] as AccountId[])
),
switchMap((accounts): Observable<DerivedBalances[]> =>
api.derive.balances.votingBalances(accounts)
)
));
}
+5 -13
View File
@@ -11,16 +11,13 @@ import { map } from 'rxjs/operators';
import { memo } from '../util';
type ResultV2 = [BN, BN, BN, BN, BN, BN, BN, BN, BN, BN];
const ZERO = new BN(0);
type ResultV2 = [BN, BN, BN, BN, BN, BN, BN, BN, BN];
// parse the result
function parseResult ([callBaseFee, contractFee, createBaseFee, creationFee, rentByteFee, rentDepositOffset, tombstoneDeposit, transactionBaseFee, transactionByteFee, transferFee]: ResultV2): DerivedContractFees {
function parseResult ([callBaseFee, contractFee, creationFee, rentByteFee, rentDepositOffset, tombstoneDeposit, transactionBaseFee, transactionByteFee, transferFee]: ResultV2): DerivedContractFees {
return {
callBaseFee,
contractFee,
createBaseFee,
creationFee,
rentByteFee,
rentDepositOffset,
@@ -36,7 +33,6 @@ function queryConstants (api: ApiInterfaceRx): Observable<ResultV2> {
return of([
api.consts.contracts.callBaseFee,
api.consts.contracts.contractFee,
api.consts.contracts.createBaseFee,
api.consts.contracts.creationFee,
api.consts.contracts.rentByteFee,
api.consts.contracts.rentDepositOffset,
@@ -62,15 +58,11 @@ function queryConstants (api: ApiInterfaceRx): Observable<ResultV2> {
*/
export function fees (api: ApiInterfaceRx): () => Observable<DerivedContractFees> {
return memo((): Observable<DerivedContractFees> => {
return (
api.consts.contracts
? queryConstants(api)
: of([ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO, ZERO])
).pipe(
map(([callBaseFee, contractFee, createBaseFee, creationFee, rentByteFee, rentDepositOffset, tombstoneDeposit, transactionBaseFee, transactionByteFee, transferFee]): DerivedContractFees =>
return queryConstants(api).pipe(
map(([callBaseFee, contractFee, 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
callBaseFee, contractFee, creationFee, rentByteFee, rentDepositOffset, tombstoneDeposit, transactionBaseFee, transactionByteFee, transferFee
])
)
);
-2
View File
@@ -45,7 +45,6 @@ describe('derive', (): void => {
testFunction(api)('balances', 'fees', []);
testFunction(api)('balances', 'votingBalance', []);
testFunction(api)('balances', 'votingBalances', []);
testFunction(api)('balances', 'votingBalancesNominatorsFor', []);
testFunction(api)('chain', 'bestNumber', []);
testFunction(api)('chain', 'bestNumberFinalized', []);
@@ -62,7 +61,6 @@ describe('derive', (): void => {
testFunction(api)('session', 'sessionProgress', []);
testFunction(api)('staking', 'account', []);
testFunction(api)('staking', 'recentlyOffline', []);
testFunction(api)('staking', 'controllers', []);
});
-1
View File
@@ -7,5 +7,4 @@ export * from './controllers';
export * from './electedInfo';
export * from './overview';
export * from './query';
export * from './recentlyOffline';
export * from './validators';
@@ -1,49 +0,0 @@
// Copyright 2017-2020 @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 { ApiInterfaceRx } from '@polkadot/api/types';
import { AccountId, BlockNumber } from '@polkadot/types/interfaces';
import { ITuple } from '@polkadot/types/types';
import { DerivedRecentlyOffline } from '../types';
import { Observable, of } from 'rxjs';
import { map } from 'rxjs/operators';
import { Vec, u32 } from '@polkadot/types';
import { memo } from '../util';
type OfflineResult = Vec<ITuple<[AccountId, BlockNumber, u32]>>;
function expandDerived (recentlyOffline: OfflineResult): DerivedRecentlyOffline {
return recentlyOffline.reduce((result: DerivedRecentlyOffline, [accountId, blockNumber, count]): DerivedRecentlyOffline => {
const key = accountId.toString();
if (!result[key]) {
result[key] = [];
}
result[key].push({
blockNumber,
count
});
return result;
}, {});
}
/**
* @description Retrieve a keyed record of accounts recently reported to be offline
*/
export function recentlyOffline (api: ApiInterfaceRx): () => Observable<DerivedRecentlyOffline> {
return memo((): Observable<DerivedRecentlyOffline> =>
(
// TODO recentlyOffline has been dropped for 2.x and replaced, figure out the
// replacement as actually use and implement it
api.query.staking.recentlyOffline
? api.query.staking.recentlyOffline<OfflineResult>()
: of([] as unknown as OfflineResult)
).pipe(
map(expandDerived)
));
}
-1
View File
@@ -49,7 +49,6 @@ export type DerivedBalancesMap = Record<string, DerivedBalances>;
export interface DerivedContractFees {
callBaseFee: BN;
contractFee: BN;
createBaseFee: BN;
creationFee: BN;
rentByteFee: BN;
rentDepositOffset: BN;
+1 -1
View File
@@ -35,7 +35,7 @@ async function derive (api: ApiPromise): Promise<void> {
}
async function query (api: ApiPromise, keyring: TestKeyringMap): Promise<void> {
const intentions = await api.query.staking.intentions();
const intentions = await api.query.staking.bonded();
console.log('intentions:', intentions);
// api.query.*.* is well-typed
-261
View File
@@ -1,261 +0,0 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
import { Observable } from 'rxjs';
import { Option, Raw, Vec } from '@polkadot/types/codec';
import { Bytes, Data, bool, u32, u64 } from '@polkadot/types';
import { AccountId, AccountIndex, Balance, BalanceOf, BlockNumber, Hash, Index, KeyTypeId, Moment, Perbill, ValidatorId, Weight } from '@polkadot/types/interfaces/runtime';
import { UncleEntryItem } from '@polkadot/types/interfaces/authorship';
import { BabeAuthorityWeight, MaybeVrf } from '@polkadot/types/interfaces/babe';
import { BalanceLock, VestingSchedule } from '@polkadot/types/interfaces/balances';
import { ProposalIndex, Votes } from '@polkadot/types/interfaces/collective';
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
import { CodeHash, ContractInfo, Gas, PrefabWasmModule, Schedule } from '@polkadot/types/interfaces/contracts';
import { Conviction, PropIndex, Proposal, ReferendumIndex, ReferendumInfo } from '@polkadot/types/interfaces/democracy';
import { Vote, VoteThreshold } from '@polkadot/types/interfaces/elections';
import { AuthorityList, SetId, StoredPendingChange, StoredState } from '@polkadot/types/interfaces/grandpa';
import { RegistrarInfo, Registration } from '@polkadot/types/interfaces/identity';
import { AuthIndex } from '@polkadot/types/interfaces/imOnline';
import { Kind, OffenceDetails, OpaqueTimeSlot, ReportIdOf } from '@polkadot/types/interfaces/offences';
import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
import { Keys, SessionIndex } from '@polkadot/types/interfaces/session';
import { Bid, BidKind, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
import { EraIndex, EraPoints, Exposure, Forcing, MomentOf, Nominations, RewardDestination, SlashingSpans, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
import { DigestOf, EventIndex, EventRecord } from '@polkadot/types/interfaces/system';
import { OpenTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
import { Multisig } from '@polkadot/types/interfaces/utility';
import { ITuple } from '@polkadot/types/types';
declare module '@polkadot/api/types' {
export interface QueryableStorageExact<ApiType> {
system: {
[index: string]: QueryableStorageEntry<ApiType>;
accountNonce: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Index>> & QueryableStorageEntry<ApiType>;
extrinsicCount: StorageEntryExact<ApiType, () => Observable<Option<u32>>> & QueryableStorageEntry<ApiType>;
allExtrinsicsWeight: StorageEntryExact<ApiType, () => Observable<Option<Weight>>> & QueryableStorageEntry<ApiType>;
allExtrinsicsLen: StorageEntryExact<ApiType, () => Observable<Option<u32>>> & QueryableStorageEntry<ApiType>;
blockHash: StorageEntryExact<ApiType, (arg: BlockNumber | Uint8Array | number | string) => Observable<Hash>> & QueryableStorageEntry<ApiType>;
extrinsicData: StorageEntryExact<ApiType, (arg: u32 | Uint8Array | number | string) => Observable<Bytes>> & QueryableStorageEntry<ApiType>;
number: StorageEntryExact<ApiType, () => Observable<BlockNumber>> & QueryableStorageEntry<ApiType>;
parentHash: StorageEntryExact<ApiType, () => Observable<Hash>> & QueryableStorageEntry<ApiType>;
extrinsicsRoot: StorageEntryExact<ApiType, () => Observable<Hash>> & QueryableStorageEntry<ApiType>;
digest: StorageEntryExact<ApiType, () => Observable<DigestOf>> & QueryableStorageEntry<ApiType>;
events: StorageEntryExact<ApiType, () => Observable<Vec<EventRecord>>> & QueryableStorageEntry<ApiType>;
eventCount: StorageEntryExact<ApiType, () => Observable<EventIndex>> & QueryableStorageEntry<ApiType>;
eventTopics: StorageEntryExact<ApiType, (arg: Hash | Uint8Array | string) => Observable<Vec<ITuple<[BlockNumber, EventIndex]>>>> & QueryableStorageEntry<ApiType>;
};
utility: {
[index: string]: QueryableStorageEntry<ApiType>;
multisigs: StorageEntryExact<ApiType, (key1: AccountId | Uint8Array | string, key2: Raw | Uint8Array | string) => Observable<Option<Multisig>>> & QueryableStorageEntry<ApiType>;
};
babe: {
[index: string]: QueryableStorageEntry<ApiType>;
epochIndex: StorageEntryExact<ApiType, () => Observable<u64>> & QueryableStorageEntry<ApiType>;
authorities: StorageEntryExact<ApiType, () => Observable<Vec<ITuple<[AuthorityId, BabeAuthorityWeight]>>>> & QueryableStorageEntry<ApiType>;
genesisSlot: StorageEntryExact<ApiType, () => Observable<u64>> & QueryableStorageEntry<ApiType>;
currentSlot: StorageEntryExact<ApiType, () => Observable<u64>> & QueryableStorageEntry<ApiType>;
randomness: StorageEntryExact<ApiType, () => Observable<Raw>> & QueryableStorageEntry<ApiType>;
nextRandomness: StorageEntryExact<ApiType, () => Observable<Raw>> & QueryableStorageEntry<ApiType>;
segmentIndex: StorageEntryExact<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
underConstruction: StorageEntryExact<ApiType, (arg: u32 | Uint8Array | number | string) => Observable<Vec<Raw>>> & QueryableStorageEntry<ApiType>;
initialized: StorageEntryExact<ApiType, () => Observable<Option<MaybeVrf>>> & QueryableStorageEntry<ApiType>;
};
timestamp: {
[index: string]: QueryableStorageEntry<ApiType>;
now: StorageEntryExact<ApiType, () => Observable<Moment>> & QueryableStorageEntry<ApiType>;
didUpdate: StorageEntryExact<ApiType, () => Observable<bool>> & QueryableStorageEntry<ApiType>;
};
authorship: {
[index: string]: QueryableStorageEntry<ApiType>;
uncles: StorageEntryExact<ApiType, () => Observable<Vec<UncleEntryItem>>> & QueryableStorageEntry<ApiType>;
author: StorageEntryExact<ApiType, () => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
didSetUncles: StorageEntryExact<ApiType, () => Observable<bool>> & QueryableStorageEntry<ApiType>;
};
indices: {
[index: string]: QueryableStorageEntry<ApiType>;
nextEnumSet: StorageEntryExact<ApiType, () => Observable<AccountIndex>> & QueryableStorageEntry<ApiType>;
enumSet: StorageEntryExact<ApiType, (arg: AccountIndex | Uint8Array | number | string) => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
};
balances: {
[index: string]: QueryableStorageEntry<ApiType>;
totalIssuance: StorageEntryExact<ApiType, () => Observable<Balance>> & QueryableStorageEntry<ApiType>;
vesting: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Option<VestingSchedule>>> & QueryableStorageEntry<ApiType>;
freeBalance: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Balance>> & QueryableStorageEntry<ApiType>;
reservedBalance: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Balance>> & QueryableStorageEntry<ApiType>;
locks: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Vec<BalanceLock>>> & QueryableStorageEntry<ApiType>;
};
transactionPayment: {
[index: string]: QueryableStorageEntry<ApiType>;
nextFeeMultiplier: StorageEntryExact<ApiType, () => Observable<Multiplier>> & QueryableStorageEntry<ApiType>;
};
staking: {
[index: string]: QueryableStorageEntry<ApiType>;
validatorCount: StorageEntryExact<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
minimumValidatorCount: StorageEntryExact<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
invulnerables: StorageEntryExact<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
bonded: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
ledger: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Option<StakingLedger>>> & QueryableStorageEntry<ApiType>;
payee: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<RewardDestination>> & QueryableStorageEntry<ApiType>;
validators: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<ValidatorPrefs>> & QueryableStorageEntry<ApiType>;
nominators: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Option<Nominations>>> & QueryableStorageEntry<ApiType>;
stakers: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Exposure>> & QueryableStorageEntry<ApiType>;
currentElected: StorageEntryExact<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
currentEra: StorageEntryExact<ApiType, () => Observable<EraIndex>> & QueryableStorageEntry<ApiType>;
currentEraStart: StorageEntryExact<ApiType, () => Observable<MomentOf>> & QueryableStorageEntry<ApiType>;
currentEraStartSessionIndex: StorageEntryExact<ApiType, () => Observable<SessionIndex>> & QueryableStorageEntry<ApiType>;
currentEraPointsEarned: StorageEntryExact<ApiType, () => Observable<EraPoints>> & QueryableStorageEntry<ApiType>;
slotStake: StorageEntryExact<ApiType, () => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
forceEra: StorageEntryExact<ApiType, () => Observable<Forcing>> & QueryableStorageEntry<ApiType>;
slashRewardFraction: StorageEntryExact<ApiType, () => Observable<Perbill>> & QueryableStorageEntry<ApiType>;
canceledSlashPayout: StorageEntryExact<ApiType, () => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
unappliedSlashes: StorageEntryExact<ApiType, (arg: EraIndex | Uint8Array | number | string) => Observable<Vec<UnappliedSlash>>> & QueryableStorageEntry<ApiType>;
bondedEras: StorageEntryExact<ApiType, () => Observable<Vec<ITuple<[EraIndex, SessionIndex]>>>> & QueryableStorageEntry<ApiType>;
validatorSlashInEra: StorageEntryExact<ApiType, (key1: EraIndex | Uint8Array | number | string, key2: AccountId | Uint8Array | string) => Observable<Option<ITuple<[Perbill, BalanceOf]>>>> & QueryableStorageEntry<ApiType>;
nominatorSlashInEra: StorageEntryExact<ApiType, (key1: EraIndex | Uint8Array | number | string, key2: AccountId | Uint8Array | string) => Observable<Option<BalanceOf>>> & QueryableStorageEntry<ApiType>;
slashingSpans: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Option<SlashingSpans>>> & QueryableStorageEntry<ApiType>;
spanSlash: StorageEntryExact<ApiType, (arg: ITuple<[AccountId, SpanIndex]>) => Observable<SpanRecord>> & QueryableStorageEntry<ApiType>;
earliestUnappliedSlash: StorageEntryExact<ApiType, () => Observable<Option<EraIndex>>> & QueryableStorageEntry<ApiType>;
storageVersion: StorageEntryExact<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
};
session: {
[index: string]: QueryableStorageEntry<ApiType>;
validators: StorageEntryExact<ApiType, () => Observable<Vec<ValidatorId>>> & QueryableStorageEntry<ApiType>;
currentIndex: StorageEntryExact<ApiType, () => Observable<SessionIndex>> & QueryableStorageEntry<ApiType>;
queuedChanged: StorageEntryExact<ApiType, () => Observable<bool>> & QueryableStorageEntry<ApiType>;
queuedKeys: StorageEntryExact<ApiType, () => Observable<Vec<ITuple<[ValidatorId, Keys]>>>> & QueryableStorageEntry<ApiType>;
disabledValidators: StorageEntryExact<ApiType, () => Observable<Vec<u32>>> & QueryableStorageEntry<ApiType>;
nextKeys: StorageEntryExact<ApiType, (key1: Bytes | Uint8Array | string, key2: ValidatorId | Uint8Array | string) => Observable<Option<Keys>>> & QueryableStorageEntry<ApiType>;
keyOwner: StorageEntryExact<ApiType, (key1: Bytes | Uint8Array | string, key2: ITuple<[KeyTypeId, Bytes]>) => Observable<Option<ValidatorId>>> & QueryableStorageEntry<ApiType>;
};
democracy: {
[index: string]: QueryableStorageEntry<ApiType>;
publicPropCount: StorageEntryExact<ApiType, () => Observable<PropIndex>> & QueryableStorageEntry<ApiType>;
publicProps: StorageEntryExact<ApiType, () => Observable<Vec<ITuple<[PropIndex, Hash, AccountId]>>>> & QueryableStorageEntry<ApiType>;
preimages: StorageEntryExact<ApiType, (arg: Hash | Uint8Array | string) => Observable<Option<ITuple<[Bytes, AccountId, BalanceOf, BlockNumber]>>>> & QueryableStorageEntry<ApiType>;
depositOf: StorageEntryExact<ApiType, (arg: PropIndex | Uint8Array | number | string) => Observable<Option<ITuple<[BalanceOf, Vec<AccountId>]>>>> & QueryableStorageEntry<ApiType>;
referendumCount: StorageEntryExact<ApiType, () => Observable<ReferendumIndex>> & QueryableStorageEntry<ApiType>;
lowestUnbaked: StorageEntryExact<ApiType, () => Observable<ReferendumIndex>> & QueryableStorageEntry<ApiType>;
referendumInfoOf: StorageEntryExact<ApiType, (arg: ReferendumIndex | Uint8Array | number | string) => Observable<Option<ReferendumInfo>>> & QueryableStorageEntry<ApiType>;
dispatchQueue: StorageEntryExact<ApiType, () => Observable<Vec<ITuple<[BlockNumber, Hash, ReferendumIndex]>>>> & QueryableStorageEntry<ApiType>;
votersFor: StorageEntryExact<ApiType, (arg: ReferendumIndex | Uint8Array | number | string) => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
voteOf: StorageEntryExact<ApiType, (arg: ITuple<[ReferendumIndex, AccountId]>) => Observable<Vote>> & QueryableStorageEntry<ApiType>;
proxy: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
delegations: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<ITuple<[AccountId, Conviction]>>> & QueryableStorageEntry<ApiType>;
lastTabledWasExternal: StorageEntryExact<ApiType, () => Observable<bool>> & QueryableStorageEntry<ApiType>;
nextExternal: StorageEntryExact<ApiType, () => Observable<Option<ITuple<[Hash, VoteThreshold]>>>> & QueryableStorageEntry<ApiType>;
blacklist: StorageEntryExact<ApiType, (arg: Hash | Uint8Array | string) => Observable<Option<ITuple<[BlockNumber, Vec<AccountId>]>>>> & QueryableStorageEntry<ApiType>;
cancellations: StorageEntryExact<ApiType, (arg: Hash | Uint8Array | string) => Observable<bool>> & QueryableStorageEntry<ApiType>;
};
council: {
[index: string]: QueryableStorageEntry<ApiType>;
proposals: StorageEntryExact<ApiType, () => Observable<Vec<Hash>>> & QueryableStorageEntry<ApiType>;
proposalOf: StorageEntryExact<ApiType, (arg: Hash | Uint8Array | string) => Observable<Option<Proposal>>> & QueryableStorageEntry<ApiType>;
voting: StorageEntryExact<ApiType, (arg: Hash | Uint8Array | string) => Observable<Option<Votes>>> & QueryableStorageEntry<ApiType>;
proposalCount: StorageEntryExact<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
members: StorageEntryExact<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
};
technicalCommittee: {
[index: string]: QueryableStorageEntry<ApiType>;
proposals: StorageEntryExact<ApiType, () => Observable<Vec<Hash>>> & QueryableStorageEntry<ApiType>;
proposalOf: StorageEntryExact<ApiType, (arg: Hash | Uint8Array | string) => Observable<Option<Proposal>>> & QueryableStorageEntry<ApiType>;
voting: StorageEntryExact<ApiType, (arg: Hash | Uint8Array | string) => Observable<Option<Votes>>> & QueryableStorageEntry<ApiType>;
proposalCount: StorageEntryExact<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
members: StorageEntryExact<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
};
elections: {
[index: string]: QueryableStorageEntry<ApiType>;
members: StorageEntryExact<ApiType, () => Observable<Vec<ITuple<[AccountId, BalanceOf]>>>> & QueryableStorageEntry<ApiType>;
runnersUp: StorageEntryExact<ApiType, () => Observable<Vec<ITuple<[AccountId, BalanceOf]>>>> & QueryableStorageEntry<ApiType>;
electionRounds: StorageEntryExact<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
votesOf: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
stakeOf: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
candidates: StorageEntryExact<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
};
technicalMembership: {
[index: string]: QueryableStorageEntry<ApiType>;
members: StorageEntryExact<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
};
grandpa: {
[index: string]: QueryableStorageEntry<ApiType>;
authorities: StorageEntryExact<ApiType, () => Observable<AuthorityList>> & QueryableStorageEntry<ApiType>;
state: StorageEntryExact<ApiType, () => Observable<StoredState>> & QueryableStorageEntry<ApiType>;
pendingChange: StorageEntryExact<ApiType, () => Observable<Option<StoredPendingChange>>> & QueryableStorageEntry<ApiType>;
nextForced: StorageEntryExact<ApiType, () => Observable<Option<BlockNumber>>> & QueryableStorageEntry<ApiType>;
stalled: StorageEntryExact<ApiType, () => Observable<Option<ITuple<[BlockNumber, BlockNumber]>>>> & QueryableStorageEntry<ApiType>;
currentSetId: StorageEntryExact<ApiType, () => Observable<SetId>> & QueryableStorageEntry<ApiType>;
setIdSession: StorageEntryExact<ApiType, (arg: SetId | Uint8Array | number | string) => Observable<Option<SessionIndex>>> & QueryableStorageEntry<ApiType>;
};
treasury: {
[index: string]: QueryableStorageEntry<ApiType>;
proposalCount: StorageEntryExact<ApiType, () => Observable<ProposalIndex>> & QueryableStorageEntry<ApiType>;
proposals: StorageEntryExact<ApiType, (arg: ProposalIndex | Uint8Array | number | string) => Observable<Option<TreasuryProposal>>> & QueryableStorageEntry<ApiType>;
approvals: StorageEntryExact<ApiType, () => Observable<Vec<ProposalIndex>>> & QueryableStorageEntry<ApiType>;
tips: StorageEntryExact<ApiType, (arg: Hash | Uint8Array | string) => Observable<Option<OpenTip>>> & QueryableStorageEntry<ApiType>;
reasons: StorageEntryExact<ApiType, (arg: Hash | Uint8Array | string) => Observable<Option<Bytes>>> & QueryableStorageEntry<ApiType>;
};
contracts: {
[index: string]: QueryableStorageEntry<ApiType>;
gasSpent: StorageEntryExact<ApiType, () => Observable<Gas>> & QueryableStorageEntry<ApiType>;
currentSchedule: StorageEntryExact<ApiType, () => Observable<Schedule>> & QueryableStorageEntry<ApiType>;
pristineCode: StorageEntryExact<ApiType, (arg: CodeHash | Uint8Array | string) => Observable<Option<Bytes>>> & QueryableStorageEntry<ApiType>;
codeStorage: StorageEntryExact<ApiType, (arg: CodeHash | Uint8Array | string) => Observable<Option<PrefabWasmModule>>> & QueryableStorageEntry<ApiType>;
accountCounter: StorageEntryExact<ApiType, () => Observable<u64>> & QueryableStorageEntry<ApiType>;
contractInfoOf: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Option<ContractInfo>>> & QueryableStorageEntry<ApiType>;
gasPrice: StorageEntryExact<ApiType, () => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
};
sudo: {
[index: string]: QueryableStorageEntry<ApiType>;
key: StorageEntryExact<ApiType, () => Observable<AccountId>> & QueryableStorageEntry<ApiType>;
};
imOnline: {
[index: string]: QueryableStorageEntry<ApiType>;
gossipAt: StorageEntryExact<ApiType, () => Observable<BlockNumber>> & QueryableStorageEntry<ApiType>;
keys: StorageEntryExact<ApiType, () => Observable<Vec<AuthorityId>>> & QueryableStorageEntry<ApiType>;
receivedHeartbeats: StorageEntryExact<ApiType, (key1: SessionIndex | Uint8Array | number | string, key2: AuthIndex | Uint8Array | number | string) => Observable<Option<Bytes>>> & QueryableStorageEntry<ApiType>;
authoredBlocks: StorageEntryExact<ApiType, (key1: SessionIndex | Uint8Array | number | string, key2: ValidatorId | Uint8Array | string) => Observable<u32>> & QueryableStorageEntry<ApiType>;
};
offences: {
[index: string]: QueryableStorageEntry<ApiType>;
reports: StorageEntryExact<ApiType, (arg: ReportIdOf | Uint8Array | string) => Observable<Option<OffenceDetails>>> & QueryableStorageEntry<ApiType>;
concurrentReportsIndex: StorageEntryExact<ApiType, (key1: Kind | Uint8Array | string, key2: OpaqueTimeSlot | Uint8Array | string) => Observable<Vec<ReportIdOf>>> & QueryableStorageEntry<ApiType>;
reportsByKindIndex: StorageEntryExact<ApiType, (arg: Kind | Uint8Array | string) => Observable<Bytes>> & QueryableStorageEntry<ApiType>;
};
randomnessCollectiveFlip: {
[index: string]: QueryableStorageEntry<ApiType>;
randomMaterial: StorageEntryExact<ApiType, () => Observable<Vec<Hash>>> & QueryableStorageEntry<ApiType>;
};
identity: {
[index: string]: QueryableStorageEntry<ApiType>;
identityOf: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Option<Registration>>> & QueryableStorageEntry<ApiType>;
superOf: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Option<ITuple<[AccountId, Data]>>>> & QueryableStorageEntry<ApiType>;
subsOf: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<ITuple<[BalanceOf, Vec<AccountId>]>>> & QueryableStorageEntry<ApiType>;
registrars: StorageEntryExact<ApiType, () => Observable<Vec<Option<RegistrarInfo>>>> & QueryableStorageEntry<ApiType>;
};
society: {
[index: string]: QueryableStorageEntry<ApiType>;
founder: StorageEntryExact<ApiType, () => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
rules: StorageEntryExact<ApiType, () => Observable<Option<Hash>>> & QueryableStorageEntry<ApiType>;
candidates: StorageEntryExact<ApiType, () => Observable<Vec<Bid>>> & QueryableStorageEntry<ApiType>;
suspendedCandidates: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Option<ITuple<[BalanceOf, BidKind]>>>> & QueryableStorageEntry<ApiType>;
pot: StorageEntryExact<ApiType, () => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
head: StorageEntryExact<ApiType, () => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
members: StorageEntryExact<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
suspendedMembers: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<bool>> & QueryableStorageEntry<ApiType>;
bids: StorageEntryExact<ApiType, () => Observable<Vec<Bid>>> & QueryableStorageEntry<ApiType>;
vouching: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Option<VouchingStatus>>> & QueryableStorageEntry<ApiType>;
payouts: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Vec<ITuple<[BlockNumber, BalanceOf]>>>> & QueryableStorageEntry<ApiType>;
strikes: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<StrikeCount>> & QueryableStorageEntry<ApiType>;
votes: StorageEntryExact<ApiType, (key1: AccountId | Uint8Array | string, key2: AccountId | Uint8Array | string) => Observable<Option<SocietyVote>>> & QueryableStorageEntry<ApiType>;
defender: StorageEntryExact<ApiType, () => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
defenderVotes: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Option<SocietyVote>>> & QueryableStorageEntry<ApiType>;
maxMembers: StorageEntryExact<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
};
recovery: {
[index: string]: QueryableStorageEntry<ApiType>;
recoverable: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Option<RecoveryConfig>>> & QueryableStorageEntry<ApiType>;
activeRecoveries: StorageEntryExact<ApiType, (key1: AccountId | Uint8Array | string, key2: AccountId | Uint8Array | string) => Observable<Option<ActiveRecovery>>> & QueryableStorageEntry<ApiType>;
recovered: StorageEntryExact<ApiType, (arg: AccountId | Uint8Array | string) => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
};
}
}
-283
View File
@@ -1,283 +0,0 @@
// Copyright 2017-2020 @polkadot/api authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// These two files add module augmentation so that `api.{query,consts}.*.*`
// get typed. Import them to make these types effective.
import './consts.types';
import './query.types';
import { Constants } from '@polkadot/metadata/Decorated/types';
import { UserRpc } from '@polkadot/rpc-core/types';
import { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
import { AnyFunction, Callback, CallFunction, Codec, CodecArg, RegistryTypes, SignatureOptions, SignerPayloadJSON, SignerPayloadRaw, Registry } from '@polkadot/types/types';
import { SubmittableResultImpl, SubmittableExtrinsic } from './submittable/types';
import { DeriveAllSections } from './util/decorate';
import BN from 'bn.js';
import { Observable } from 'rxjs';
import { DeriveCustom, ExactDerive } from '@polkadot/api-derive';
import { RpcInterface } from '@polkadot/rpc-core/jsonrpc.types';
import { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
import { Metadata, u64 } from '@polkadot/types';
import StorageKey, { StorageEntry } from '@polkadot/types/primitive/StorageKey';
import ApiBase from './base';
export * from './submittable/types';
// Prepend an element V onto the beginning of a tuple T.
// Cons<1, [2,3,4]> is [1,2,3,4]
type Cons<V, T extends any[]> = ((v: V, ...t: T) => void) extends ((...r: infer R) => void)
? R
: never;
// Append an element V onto the end of a tuple T
// Push<[1,2,3],4> is [1,2,3,4]
// note that this DOES NOT PRESERVE optionality/readonly in tuples.
// So unfortunately Push<[1, 2?, 3?], 4> is [1,2|undefined,3|undefined,4]
type Push<T extends any[], V> = (
(
Cons<any, Required<T>> extends infer R
? { [K in keyof R]: K extends keyof T ? T[K] : V }
: never
) extends infer P
? P extends any[] ? P : never
: never
);
// Returns the inner type of an Observable
export type ObsInnerType<O extends Observable<any>> = O extends Observable<infer U> ? U : never;
export type UnsubscribePromise = Promise<() => void>;
// In the abstract `decorateMethod` in Base.ts, we can also pass in some meta-
// information. This describes it.
export interface DecorateMethodOptions {
methodName?: string;
}
export type DecorateMethod<ApiType extends ApiTypes> = <Method extends (...args: any[]) => Observable<any>>(method: Method, options?: DecorateMethodOptions) => any;
// Here are the return types of these parts of the api:
// - api.query.*.*: no exact typings
// - api.tx.*.*: SubmittableExtrinsic<ApiType extends ApiTypes>
// - api.derive.*.*: MethodResult<ApiType, F>
// - api.rpc.*.*: no exact typings (for now, FIXME: should be MethodResult<ApiType, F>, like in derive)
// These are the types that don't lose type information (used for api.derive.*)
// Also use these for api.rpc.* https://github.com/polkadot-js/api/issues/1009
export interface RxResult<F extends AnyFunction> {
(...args: Parameters<F>): Observable<ObsInnerType<ReturnType<F>>>;
<T>(...args: Parameters<F>): Observable<T>;
}
export interface PromiseResult<F extends AnyFunction> {
(...args: Parameters<F>): Promise<ObsInnerType<ReturnType<F>>>;
(...args: Push<Parameters<F>, Callback<ObsInnerType<ReturnType<F>>>>): UnsubscribePromise;
<T extends Codec | Codec[]>(...args: Parameters<F>): Promise<T>;
<T extends Codec | Codec[]>(...args: Push<Parameters<F>, Callback<T>>): UnsubscribePromise;
}
// FIXME The day TS has higher-kinded types, we can remove this hardcoded stuff
export type PromiseOrObs<ApiType extends ApiTypes, T> = ApiType extends 'rxjs'
? Observable<T>
: Promise<T>
// FIXME The day TS has higher-kinded types, we can remove this hardcoded stuff
export type MethodResult<ApiType extends ApiTypes, F extends AnyFunction> = ApiType extends 'rxjs'
? RxResult<F>
: PromiseResult<F>;
export type DecoratedRpcSection<ApiType extends ApiTypes, Section> = {
[Method in keyof Section]: Section[Method] extends AnyFunction
? MethodResult<ApiType, Section[Method]>
: never
}
export type DecoratedRpc<ApiType extends ApiTypes, AllSections> = {
[Section in keyof AllSections]: DecoratedRpcSection<ApiType, AllSections[Section]>
}
interface StorageEntryObservableMulti {
<T extends Codec>(args: (CodecArg[] | CodecArg)[]): Observable<T[]>;
}
interface StorageEntryPromiseMulti {
<T extends Codec>(args: (CodecArg[] | CodecArg)[]): Promise<T[]>;
<T extends Codec>(args: (CodecArg[] | CodecArg)[], callback: Callback<T[]>): UnsubscribePromise;
}
export interface StorageEntryBase<ApiType extends ApiTypes, F extends AnyFunction> {
at: (hash: Hash | Uint8Array | string, ...args: Parameters<F>) => PromiseOrObs<ApiType, ObsInnerType<ReturnType<F>>>;
creator: StorageEntry;
entries: () => PromiseOrObs<ApiType, [StorageKey, ObsInnerType<ReturnType<F>>][]>;
hash: (...args: Parameters<F>) => PromiseOrObs<ApiType, Hash>;
key: (...args: Parameters<F>) => string;
size: (...args: Parameters<F>) => PromiseOrObs<ApiType, u64>;
multi: ApiType extends 'rxjs' ? StorageEntryObservableMulti : StorageEntryPromiseMulti;
}
export interface StorageEntryPromiseOverloads {
(arg1?: CodecArg, arg2?: CodecArg): Promise<Codec>;
<T extends Codec>(arg1?: CodecArg, arg2?: CodecArg): Promise<T>;
<T extends Codec>(callback: Callback<T>): UnsubscribePromise;
<T extends Codec>(arg: CodecArg, callback: Callback<T>): UnsubscribePromise;
<T extends Codec>(arg1: CodecArg, arg2: CodecArg, callback: Callback<T>): UnsubscribePromise;
}
export type StorageEntryExact<ApiType extends ApiTypes, F extends AnyFunction> = MethodResult<ApiType, F> & StorageEntryBase<ApiType, F>
// This is the most generic typings we can have for a storage entry function
type GenericStorageEntryFunction = (arg1?: CodecArg, arg2?: CodecArg) => Observable<Codec>
export type QueryableStorageEntry<ApiType extends ApiTypes> =
ApiType extends 'rxjs'
? StorageEntryExact<'rxjs', GenericStorageEntryFunction>
: StorageEntryExact<'promise', GenericStorageEntryFunction> & StorageEntryPromiseOverloads;
export interface QueryableModuleStorage<ApiType extends ApiTypes> {
[index: string]: QueryableStorageEntry<ApiType>;
}
export type QueryableStorageMultiArg<ApiType extends ApiTypes> =
QueryableStorageEntry<ApiType> |
[QueryableStorageEntry<ApiType>, ...CodecArg[]];
export interface QueryableStorageMultiBase<ApiType extends ApiTypes> {
<T extends Codec[]>(calls: QueryableStorageMultiArg<ApiType>[]): Observable<T>;
}
export interface QueryableStorageMultiPromise<ApiType extends ApiTypes> {
<T extends Codec[]>(calls: QueryableStorageMultiArg<ApiType>[], callback: Callback<T>): UnsubscribePromise;
}
export type QueryableStorageMulti<ApiType extends ApiTypes> =
ApiType extends 'rxjs'
? QueryableStorageMultiBase<ApiType>
: QueryableStorageMultiPromise<ApiType>;
// QueryableStorageExact will hold the exact typed api.query.*.* generated from
// metadata. For now it's empty, it's ready to be module augmented.
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface QueryableStorageExact<ApiType extends ApiTypes> { }
export interface QueryableStorage<ApiType extends ApiTypes> extends QueryableStorageExact<ApiType> {
[index: string]: QueryableModuleStorage<ApiType>;
}
export interface SubmittableExtrinsicFunction<ApiType extends ApiTypes> extends CallFunction {
(...params: CodecArg[]): SubmittableExtrinsic<ApiType>;
}
export interface SubmittableModuleExtrinsics<ApiType extends ApiTypes> {
[index: string]: SubmittableExtrinsicFunction<ApiType>;
}
export interface SubmittableExtrinsics<ApiType extends ApiTypes> {
(extrinsic: Uint8Array | string): SubmittableExtrinsic<ApiType>;
[index: string]: SubmittableModuleExtrinsics<ApiType>;
}
export interface ApiOptions {
/**
* @description Add custom derives to be injected
*/
derives?: DeriveCustom;
/**
* @description prebundles is a map of 'genesis hash and runtime spec version' as key to metadata's hex string
* if genesis hash and runtime spec version matches, then use metadata, else fetch it from chain
*/
metadata?: Record<string, string>;
/**
* @description Transport Provider from rpc-provider. If not specified, it will default to
* connecting to a WsProvider connecting localhost with the default port, i.e. `ws://127.0.0.1:9944`
*/
provider?: ProviderInterface;
/**
* @description A type registry to use along with this instance
*/
registry?: Registry;
/**
* @description User-defined RPC methods
*/
rpc?: UserRpc;
/**
* @description An external signer which will be used to sign extrinsic when account passed in is not KeyringPair
*/
signer?: Signer;
/**
* @description The source object to use for runtime information (only used when cloning)
*/
source?: ApiBase<any>;
/**
* @description Additional types used by runtime modules. This is nessusary if the runtime modules
* uses types not available in the base Substrate runtime.
*/
types?: RegistryTypes;
/**
* @description Additional types that are injected based on the chain we are connecting to. There are keyed by the chain, i.e. `{ 'Kusama CC1': { ... } }`
*/
typesChain?: Record<string, RegistryTypes>;
/**
* @description Additional types that are injected based on the type of node we are connecting to, as set via specName in the runtime version. There are keyed by the node, i.e. `{ 'edgeware': { ... } }`
*/
typesSpec?: Record<string, RegistryTypes>;
}
// A smaller interface of ApiRx, used in derive and in SubmittableExtrinsic
export interface ApiInterfaceRx {
consts: Constants;
// TODO This needs to be typed correctly
derive: DeriveAllSections<'rxjs', ExactDerive>;
extrinsicType: number;
genesisHash: Hash;
hasSubscriptions: boolean;
registry: Registry;
runtimeMetadata: Metadata;
runtimeVersion: RuntimeVersion;
query: QueryableStorage<'rxjs'>;
queryMulti: QueryableStorageMulti<'rxjs'>;
rpc: DecoratedRpc<'rxjs', RpcInterface>;
tx: SubmittableExtrinsics<'rxjs'>;
signer?: Signer;
}
export type ApiInterfaceEvents = ProviderInterfaceEmitted | 'ready';
export type ApiTypes = 'promise' | 'rxjs';
export interface SignerOptions extends SignatureOptions {
blockNumber: BN;
genesisHash: Hash;
}
export interface SignerResult {
/**
* @description The id for this request
*/
id: number;
/**
* @description The resulting signature in hex
*/
signature: string;
}
export interface Signer {
/**
* @description signs an extrinsic payload from a serialized form
*/
signPayload?: (payload: SignerPayloadJSON) => Promise<SignerResult>;
/**
* @description signs a raw payload, only the bytes data as supplied
*/
signRaw?: (raw: SignerPayloadRaw) => Promise<SignerResult>;
/**
* @description Receives an update for the extrinsic signed by a `signer.sign`
*/
update?: (id: number, status: Hash | SubmittableResultImpl) => void;
}
export { ApiBase };
@@ -6,41 +6,33 @@ import { Balance, BalanceOf, BlockNumber, Moment, Percent, Permill } from '@polk
import { Gas } from '@polkadot/types/interfaces/contracts';
import { SessionIndex } from '@polkadot/types/interfaces/session';
import { EraIndex } from '@polkadot/types/interfaces/staking';
import { Codec } from '@polkadot/types/types';
declare module '@polkadot/metadata/Decorated/types' {
export interface Constants {
babe: {
[index: string]: Codec;
epochDuration: u64 & ConstantCodec;
expectedBlockTime: Moment & ConstantCodec;
};
timestamp: {
[index: string]: Codec;
minimumPeriod: Moment & ConstantCodec;
};
balances: {
[index: string]: Codec;
existentialDeposit: Balance & ConstantCodec;
transferFee: Balance & ConstantCodec;
creationFee: Balance & ConstantCodec;
};
transactionPayment: {
[index: string]: Codec;
transactionBaseFee: BalanceOf & ConstantCodec;
transactionByteFee: BalanceOf & ConstantCodec;
};
staking: {
[index: string]: Codec;
sessionsPerEra: SessionIndex & ConstantCodec;
bondingDuration: EraIndex & ConstantCodec;
};
session: {
[index: string]: Codec;
dedupKeyPrefix: Bytes & ConstantCodec;
};
democracy: {
[index: string]: Codec;
enactmentPeriod: BlockNumber & ConstantCodec;
launchPeriod: BlockNumber & ConstantCodec;
votingPeriod: BlockNumber & ConstantCodec;
@@ -50,7 +42,6 @@ declare module '@polkadot/metadata/Decorated/types' {
preimageByteDeposit: BalanceOf & ConstantCodec;
};
elections: {
[index: string]: Codec;
candidacyBond: BalanceOf & ConstantCodec;
votingBond: BalanceOf & ConstantCodec;
desiredMembers: u32 & ConstantCodec;
@@ -58,12 +49,10 @@ declare module '@polkadot/metadata/Decorated/types' {
termDuration: BlockNumber & ConstantCodec;
};
finalityTracker: {
[index: string]: Codec;
windowSize: BlockNumber & ConstantCodec;
reportLatency: BlockNumber & ConstantCodec;
};
treasury: {
[index: string]: Codec;
proposalBond: Permill & ConstantCodec;
proposalBondMinimum: BalanceOf & ConstantCodec;
spendPeriod: BlockNumber & ConstantCodec;
@@ -74,7 +63,6 @@ declare module '@polkadot/metadata/Decorated/types' {
tipReportDepositPerByte: BalanceOf & ConstantCodec;
};
contracts: {
[index: string]: Codec;
signedClaimHandicap: BlockNumber & ConstantCodec;
tombstoneDeposit: BalanceOf & ConstantCodec;
storageSizeOffset: u32 & ConstantCodec;
@@ -93,7 +81,6 @@ declare module '@polkadot/metadata/Decorated/types' {
blockGasLimit: Gas & ConstantCodec;
};
society: {
[index: string]: Codec;
candidateDeposit: BalanceOf & ConstantCodec;
wrongSideDeduction: BalanceOf & ConstantCodec;
maxStrikes: u32 & ConstantCodec;
+7
View File
@@ -0,0 +1,7 @@
// Copyright 2017-2020 @polkadot/api 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 './consts';
import './query';
import './tx';
+236
View File
@@ -0,0 +1,236 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
import { Observable } from 'rxjs';
import { Option, Raw, Vec } from '@polkadot/types/codec';
import { Bytes, Data, bool, u32, u64 } from '@polkadot/types';
import { AccountId, AccountIndex, Balance, BalanceOf, BlockNumber, Hash, Index, KeyTypeId, Moment, Perbill, ValidatorId, Weight } from '@polkadot/types/interfaces/runtime';
import { UncleEntryItem } from '@polkadot/types/interfaces/authorship';
import { BabeAuthorityWeight, MaybeVrf } from '@polkadot/types/interfaces/babe';
import { BalanceLock, VestingSchedule } from '@polkadot/types/interfaces/balances';
import { ProposalIndex, Votes } from '@polkadot/types/interfaces/collective';
import { AuthorityId } from '@polkadot/types/interfaces/consensus';
import { CodeHash, ContractInfo, Gas, PrefabWasmModule, Schedule } from '@polkadot/types/interfaces/contracts';
import { Conviction, PropIndex, Proposal, ReferendumIndex, ReferendumInfo } from '@polkadot/types/interfaces/democracy';
import { Vote, VoteThreshold } from '@polkadot/types/interfaces/elections';
import { AuthorityList, SetId, StoredPendingChange, StoredState } from '@polkadot/types/interfaces/grandpa';
import { RegistrarInfo, Registration } from '@polkadot/types/interfaces/identity';
import { AuthIndex } from '@polkadot/types/interfaces/imOnline';
import { Kind, OffenceDetails, OpaqueTimeSlot, ReportIdOf } from '@polkadot/types/interfaces/offences';
import { ActiveRecovery, RecoveryConfig } from '@polkadot/types/interfaces/recovery';
import { Keys, SessionIndex } from '@polkadot/types/interfaces/session';
import { Bid, BidKind, SocietyVote, StrikeCount, VouchingStatus } from '@polkadot/types/interfaces/society';
import { EraIndex, EraPoints, Exposure, Forcing, MomentOf, Nominations, RewardDestination, SlashingSpans, SpanIndex, SpanRecord, StakingLedger, UnappliedSlash, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
import { DigestOf, EventIndex, EventRecord } from '@polkadot/types/interfaces/system';
import { OpenTip, TreasuryProposal } from '@polkadot/types/interfaces/treasury';
import { Multiplier } from '@polkadot/types/interfaces/txpayment';
import { Multisig } from '@polkadot/types/interfaces/utility';
import { AnyNumber, ITuple } from '@polkadot/types/types';
declare module '@polkadot/api/types/storage' {
export interface AugmentedQueries<ApiType> {
system: {
accountNonce: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Index>> & QueryableStorageEntry<ApiType>;
extrinsicCount: AugmentedQuery<ApiType, () => Observable<Option<u32>>> & QueryableStorageEntry<ApiType>;
allExtrinsicsWeight: AugmentedQuery<ApiType, () => Observable<Option<Weight>>> & QueryableStorageEntry<ApiType>;
allExtrinsicsLen: AugmentedQuery<ApiType, () => Observable<Option<u32>>> & QueryableStorageEntry<ApiType>;
blockHash: AugmentedQuery<ApiType, (arg: BlockNumber | AnyNumber | Uint8Array) => Observable<Hash>> & QueryableStorageEntry<ApiType>;
extrinsicData: AugmentedQuery<ApiType, (arg: u32 | AnyNumber | Uint8Array) => Observable<Bytes>> & QueryableStorageEntry<ApiType>;
number: AugmentedQuery<ApiType, () => Observable<BlockNumber>> & QueryableStorageEntry<ApiType>;
parentHash: AugmentedQuery<ApiType, () => Observable<Hash>> & QueryableStorageEntry<ApiType>;
extrinsicsRoot: AugmentedQuery<ApiType, () => Observable<Hash>> & QueryableStorageEntry<ApiType>;
digest: AugmentedQuery<ApiType, () => Observable<DigestOf>> & QueryableStorageEntry<ApiType>;
events: AugmentedQuery<ApiType, () => Observable<Vec<EventRecord>>> & QueryableStorageEntry<ApiType>;
eventCount: AugmentedQuery<ApiType, () => Observable<EventIndex>> & QueryableStorageEntry<ApiType>;
eventTopics: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Vec<ITuple<[BlockNumber, EventIndex]>>>> & QueryableStorageEntry<ApiType>;
};
utility: {
multisigs: AugmentedQuery<ApiType, (key1: AccountId | string | Uint8Array, key2: Raw | string | Uint8Array) => Observable<Option<Multisig>>> & QueryableStorageEntry<ApiType>;
};
babe: {
epochIndex: AugmentedQuery<ApiType, () => Observable<u64>> & QueryableStorageEntry<ApiType>;
authorities: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[AuthorityId, BabeAuthorityWeight]>>>> & QueryableStorageEntry<ApiType>;
genesisSlot: AugmentedQuery<ApiType, () => Observable<u64>> & QueryableStorageEntry<ApiType>;
currentSlot: AugmentedQuery<ApiType, () => Observable<u64>> & QueryableStorageEntry<ApiType>;
randomness: AugmentedQuery<ApiType, () => Observable<Raw>> & QueryableStorageEntry<ApiType>;
nextRandomness: AugmentedQuery<ApiType, () => Observable<Raw>> & QueryableStorageEntry<ApiType>;
segmentIndex: AugmentedQuery<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
underConstruction: AugmentedQuery<ApiType, (arg: u32 | AnyNumber | Uint8Array) => Observable<Vec<Raw>>> & QueryableStorageEntry<ApiType>;
initialized: AugmentedQuery<ApiType, () => Observable<Option<MaybeVrf>>> & QueryableStorageEntry<ApiType>;
};
timestamp: {
now: AugmentedQuery<ApiType, () => Observable<Moment>> & QueryableStorageEntry<ApiType>;
didUpdate: AugmentedQuery<ApiType, () => Observable<bool>> & QueryableStorageEntry<ApiType>;
};
authorship: {
uncles: AugmentedQuery<ApiType, () => Observable<Vec<UncleEntryItem>>> & QueryableStorageEntry<ApiType>;
author: AugmentedQuery<ApiType, () => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
didSetUncles: AugmentedQuery<ApiType, () => Observable<bool>> & QueryableStorageEntry<ApiType>;
};
indices: {
nextEnumSet: AugmentedQuery<ApiType, () => Observable<AccountIndex>> & QueryableStorageEntry<ApiType>;
enumSet: AugmentedQuery<ApiType, (arg: AccountIndex | AnyNumber | Uint8Array) => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
};
balances: {
totalIssuance: AugmentedQuery<ApiType, () => Observable<Balance>> & QueryableStorageEntry<ApiType>;
vesting: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<VestingSchedule>>> & QueryableStorageEntry<ApiType>;
freeBalance: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Balance>> & QueryableStorageEntry<ApiType>;
reservedBalance: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Balance>> & QueryableStorageEntry<ApiType>;
locks: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Vec<BalanceLock>>> & QueryableStorageEntry<ApiType>;
};
transactionPayment: {
nextFeeMultiplier: AugmentedQuery<ApiType, () => Observable<Multiplier>> & QueryableStorageEntry<ApiType>;
};
staking: {
validatorCount: AugmentedQuery<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
minimumValidatorCount: AugmentedQuery<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
invulnerables: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
bonded: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
ledger: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<StakingLedger>>> & QueryableStorageEntry<ApiType>;
payee: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<RewardDestination>> & QueryableStorageEntry<ApiType>;
validators: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ValidatorPrefs>> & QueryableStorageEntry<ApiType>;
nominators: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<Nominations>>> & QueryableStorageEntry<ApiType>;
stakers: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Exposure>> & QueryableStorageEntry<ApiType>;
currentElected: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
currentEra: AugmentedQuery<ApiType, () => Observable<EraIndex>> & QueryableStorageEntry<ApiType>;
currentEraStart: AugmentedQuery<ApiType, () => Observable<MomentOf>> & QueryableStorageEntry<ApiType>;
currentEraStartSessionIndex: AugmentedQuery<ApiType, () => Observable<SessionIndex>> & QueryableStorageEntry<ApiType>;
currentEraPointsEarned: AugmentedQuery<ApiType, () => Observable<EraPoints>> & QueryableStorageEntry<ApiType>;
slotStake: AugmentedQuery<ApiType, () => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
forceEra: AugmentedQuery<ApiType, () => Observable<Forcing>> & QueryableStorageEntry<ApiType>;
slashRewardFraction: AugmentedQuery<ApiType, () => Observable<Perbill>> & QueryableStorageEntry<ApiType>;
canceledSlashPayout: AugmentedQuery<ApiType, () => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
unappliedSlashes: AugmentedQuery<ApiType, (arg: EraIndex | AnyNumber | Uint8Array) => Observable<Vec<UnappliedSlash>>> & QueryableStorageEntry<ApiType>;
bondedEras: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[EraIndex, SessionIndex]>>>> & QueryableStorageEntry<ApiType>;
validatorSlashInEra: AugmentedQuery<ApiType, (key1: EraIndex | AnyNumber | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Option<ITuple<[Perbill, BalanceOf]>>>> & QueryableStorageEntry<ApiType>;
nominatorSlashInEra: AugmentedQuery<ApiType, (key1: EraIndex | AnyNumber | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Option<BalanceOf>>> & QueryableStorageEntry<ApiType>;
slashingSpans: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<SlashingSpans>>> & QueryableStorageEntry<ApiType>;
spanSlash: AugmentedQuery<ApiType, (arg: ITuple<[AccountId, SpanIndex]>) => Observable<SpanRecord>> & QueryableStorageEntry<ApiType>;
earliestUnappliedSlash: AugmentedQuery<ApiType, () => Observable<Option<EraIndex>>> & QueryableStorageEntry<ApiType>;
storageVersion: AugmentedQuery<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
};
session: {
validators: AugmentedQuery<ApiType, () => Observable<Vec<ValidatorId>>> & QueryableStorageEntry<ApiType>;
currentIndex: AugmentedQuery<ApiType, () => Observable<SessionIndex>> & QueryableStorageEntry<ApiType>;
queuedChanged: AugmentedQuery<ApiType, () => Observable<bool>> & QueryableStorageEntry<ApiType>;
queuedKeys: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[ValidatorId, Keys]>>>> & QueryableStorageEntry<ApiType>;
disabledValidators: AugmentedQuery<ApiType, () => Observable<Vec<u32>>> & QueryableStorageEntry<ApiType>;
nextKeys: AugmentedQuery<ApiType, (key1: Bytes | string | Uint8Array, key2: ValidatorId | string | Uint8Array) => Observable<Option<Keys>>> & QueryableStorageEntry<ApiType>;
keyOwner: AugmentedQuery<ApiType, (key1: Bytes | string | Uint8Array, key2: ITuple<[KeyTypeId, Bytes]>) => Observable<Option<ValidatorId>>> & QueryableStorageEntry<ApiType>;
};
democracy: {
publicPropCount: AugmentedQuery<ApiType, () => Observable<PropIndex>> & QueryableStorageEntry<ApiType>;
publicProps: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[PropIndex, Hash, AccountId]>>>> & QueryableStorageEntry<ApiType>;
preimages: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<ITuple<[Bytes, AccountId, BalanceOf, BlockNumber]>>>> & QueryableStorageEntry<ApiType>;
depositOf: AugmentedQuery<ApiType, (arg: PropIndex | AnyNumber | Uint8Array) => Observable<Option<ITuple<[BalanceOf, Vec<AccountId>]>>>> & QueryableStorageEntry<ApiType>;
referendumCount: AugmentedQuery<ApiType, () => Observable<ReferendumIndex>> & QueryableStorageEntry<ApiType>;
lowestUnbaked: AugmentedQuery<ApiType, () => Observable<ReferendumIndex>> & QueryableStorageEntry<ApiType>;
referendumInfoOf: AugmentedQuery<ApiType, (arg: ReferendumIndex | AnyNumber | Uint8Array) => Observable<Option<ReferendumInfo>>> & QueryableStorageEntry<ApiType>;
dispatchQueue: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[BlockNumber, Hash, ReferendumIndex]>>>> & QueryableStorageEntry<ApiType>;
votersFor: AugmentedQuery<ApiType, (arg: ReferendumIndex | AnyNumber | Uint8Array) => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
voteOf: AugmentedQuery<ApiType, (arg: ITuple<[ReferendumIndex, AccountId]>) => Observable<Vote>> & QueryableStorageEntry<ApiType>;
proxy: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
delegations: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ITuple<[AccountId, Conviction]>>> & QueryableStorageEntry<ApiType>;
lastTabledWasExternal: AugmentedQuery<ApiType, () => Observable<bool>> & QueryableStorageEntry<ApiType>;
nextExternal: AugmentedQuery<ApiType, () => Observable<Option<ITuple<[Hash, VoteThreshold]>>>> & QueryableStorageEntry<ApiType>;
blacklist: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<ITuple<[BlockNumber, Vec<AccountId>]>>>> & QueryableStorageEntry<ApiType>;
cancellations: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<bool>> & QueryableStorageEntry<ApiType>;
};
council: {
proposals: AugmentedQuery<ApiType, () => Observable<Vec<Hash>>> & QueryableStorageEntry<ApiType>;
proposalOf: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<Proposal>>> & QueryableStorageEntry<ApiType>;
voting: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<Votes>>> & QueryableStorageEntry<ApiType>;
proposalCount: AugmentedQuery<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
members: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
};
technicalCommittee: {
proposals: AugmentedQuery<ApiType, () => Observable<Vec<Hash>>> & QueryableStorageEntry<ApiType>;
proposalOf: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<Proposal>>> & QueryableStorageEntry<ApiType>;
voting: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<Votes>>> & QueryableStorageEntry<ApiType>;
proposalCount: AugmentedQuery<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
members: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
};
elections: {
members: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[AccountId, BalanceOf]>>>> & QueryableStorageEntry<ApiType>;
runnersUp: AugmentedQuery<ApiType, () => Observable<Vec<ITuple<[AccountId, BalanceOf]>>>> & QueryableStorageEntry<ApiType>;
electionRounds: AugmentedQuery<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
votesOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
stakeOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
candidates: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
};
technicalMembership: {
members: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
};
grandpa: {
authorities: AugmentedQuery<ApiType, () => Observable<AuthorityList>> & QueryableStorageEntry<ApiType>;
state: AugmentedQuery<ApiType, () => Observable<StoredState>> & QueryableStorageEntry<ApiType>;
pendingChange: AugmentedQuery<ApiType, () => Observable<Option<StoredPendingChange>>> & QueryableStorageEntry<ApiType>;
nextForced: AugmentedQuery<ApiType, () => Observable<Option<BlockNumber>>> & QueryableStorageEntry<ApiType>;
stalled: AugmentedQuery<ApiType, () => Observable<Option<ITuple<[BlockNumber, BlockNumber]>>>> & QueryableStorageEntry<ApiType>;
currentSetId: AugmentedQuery<ApiType, () => Observable<SetId>> & QueryableStorageEntry<ApiType>;
setIdSession: AugmentedQuery<ApiType, (arg: SetId | AnyNumber | Uint8Array) => Observable<Option<SessionIndex>>> & QueryableStorageEntry<ApiType>;
};
treasury: {
proposalCount: AugmentedQuery<ApiType, () => Observable<ProposalIndex>> & QueryableStorageEntry<ApiType>;
proposals: AugmentedQuery<ApiType, (arg: ProposalIndex | AnyNumber | Uint8Array) => Observable<Option<TreasuryProposal>>> & QueryableStorageEntry<ApiType>;
approvals: AugmentedQuery<ApiType, () => Observable<Vec<ProposalIndex>>> & QueryableStorageEntry<ApiType>;
tips: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<OpenTip>>> & QueryableStorageEntry<ApiType>;
reasons: AugmentedQuery<ApiType, (arg: Hash | string | Uint8Array) => Observable<Option<Bytes>>> & QueryableStorageEntry<ApiType>;
};
contracts: {
gasSpent: AugmentedQuery<ApiType, () => Observable<Gas>> & QueryableStorageEntry<ApiType>;
currentSchedule: AugmentedQuery<ApiType, () => Observable<Schedule>> & QueryableStorageEntry<ApiType>;
pristineCode: AugmentedQuery<ApiType, (arg: CodeHash | string | Uint8Array) => Observable<Option<Bytes>>> & QueryableStorageEntry<ApiType>;
codeStorage: AugmentedQuery<ApiType, (arg: CodeHash | string | Uint8Array) => Observable<Option<PrefabWasmModule>>> & QueryableStorageEntry<ApiType>;
accountCounter: AugmentedQuery<ApiType, () => Observable<u64>> & QueryableStorageEntry<ApiType>;
contractInfoOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<ContractInfo>>> & QueryableStorageEntry<ApiType>;
gasPrice: AugmentedQuery<ApiType, () => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
};
sudo: {
key: AugmentedQuery<ApiType, () => Observable<AccountId>> & QueryableStorageEntry<ApiType>;
};
imOnline: {
gossipAt: AugmentedQuery<ApiType, () => Observable<BlockNumber>> & QueryableStorageEntry<ApiType>;
keys: AugmentedQuery<ApiType, () => Observable<Vec<AuthorityId>>> & QueryableStorageEntry<ApiType>;
receivedHeartbeats: AugmentedQuery<ApiType, (key1: SessionIndex | AnyNumber | Uint8Array, key2: AuthIndex | AnyNumber | Uint8Array) => Observable<Option<Bytes>>> & QueryableStorageEntry<ApiType>;
authoredBlocks: AugmentedQuery<ApiType, (key1: SessionIndex | AnyNumber | Uint8Array, key2: ValidatorId | string | Uint8Array) => Observable<u32>> & QueryableStorageEntry<ApiType>;
};
offences: {
reports: AugmentedQuery<ApiType, (arg: ReportIdOf | string | Uint8Array) => Observable<Option<OffenceDetails>>> & QueryableStorageEntry<ApiType>;
concurrentReportsIndex: AugmentedQuery<ApiType, (key1: Kind | string | Uint8Array, key2: OpaqueTimeSlot | string | Uint8Array) => Observable<Vec<ReportIdOf>>> & QueryableStorageEntry<ApiType>;
reportsByKindIndex: AugmentedQuery<ApiType, (arg: Kind | string | Uint8Array) => Observable<Bytes>> & QueryableStorageEntry<ApiType>;
};
randomnessCollectiveFlip: {
randomMaterial: AugmentedQuery<ApiType, () => Observable<Vec<Hash>>> & QueryableStorageEntry<ApiType>;
};
identity: {
identityOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<Registration>>> & QueryableStorageEntry<ApiType>;
superOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<ITuple<[AccountId, Data]>>>> & QueryableStorageEntry<ApiType>;
subsOf: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<ITuple<[BalanceOf, Vec<AccountId>]>>> & QueryableStorageEntry<ApiType>;
registrars: AugmentedQuery<ApiType, () => Observable<Vec<Option<RegistrarInfo>>>> & QueryableStorageEntry<ApiType>;
};
society: {
founder: AugmentedQuery<ApiType, () => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
rules: AugmentedQuery<ApiType, () => Observable<Option<Hash>>> & QueryableStorageEntry<ApiType>;
candidates: AugmentedQuery<ApiType, () => Observable<Vec<Bid>>> & QueryableStorageEntry<ApiType>;
suspendedCandidates: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<ITuple<[BalanceOf, BidKind]>>>> & QueryableStorageEntry<ApiType>;
pot: AugmentedQuery<ApiType, () => Observable<BalanceOf>> & QueryableStorageEntry<ApiType>;
head: AugmentedQuery<ApiType, () => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
members: AugmentedQuery<ApiType, () => Observable<Vec<AccountId>>> & QueryableStorageEntry<ApiType>;
suspendedMembers: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<bool>> & QueryableStorageEntry<ApiType>;
bids: AugmentedQuery<ApiType, () => Observable<Vec<Bid>>> & QueryableStorageEntry<ApiType>;
vouching: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<VouchingStatus>>> & QueryableStorageEntry<ApiType>;
payouts: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Vec<ITuple<[BlockNumber, BalanceOf]>>>> & QueryableStorageEntry<ApiType>;
strikes: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<StrikeCount>> & QueryableStorageEntry<ApiType>;
votes: AugmentedQuery<ApiType, (key1: AccountId | string | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Option<SocietyVote>>> & QueryableStorageEntry<ApiType>;
defender: AugmentedQuery<ApiType, () => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
defenderVotes: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<SocietyVote>>> & QueryableStorageEntry<ApiType>;
maxMembers: AugmentedQuery<ApiType, () => Observable<u32>> & QueryableStorageEntry<ApiType>;
};
recovery: {
recoverable: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<RecoveryConfig>>> & QueryableStorageEntry<ApiType>;
activeRecoveries: AugmentedQuery<ApiType, (key1: AccountId | string | Uint8Array, key2: AccountId | string | Uint8Array) => Observable<Option<ActiveRecovery>>> & QueryableStorageEntry<ApiType>;
recovered: AugmentedQuery<ApiType, (arg: AccountId | string | Uint8Array) => Observable<Option<AccountId>>> & QueryableStorageEntry<ApiType>;
};
}
}
+194
View File
@@ -0,0 +1,194 @@
// Auto-generated via `yarn polkadot-types-from-defs`, do not edit
/* eslint-disable @typescript-eslint/no-empty-interface */
import { SubmittableExtrinsic } from '@polkadot/api/submittable/types';
import { Compact, Option, Raw, Vec } from '@polkadot/types/codec';
import { Bytes, Data, IdentityFields, bool, u16, u32, u64 } from '@polkadot/types';
import { AccountId, Address, Balance, BalanceOf, BlockNumber, Call, ChangesTrieConfiguration, Hash, Header, KeyValue, Moment, Signature } from '@polkadot/types/interfaces/runtime';
import { MemberCount, ProposalIndex } from '@polkadot/types/interfaces/collective';
import { CodeHash, Gas, Schedule } from '@polkadot/types/interfaces/contracts';
import { Conviction, PropIndex, Proposal, ReferendumIndex } from '@polkadot/types/interfaces/democracy';
import { Vote } from '@polkadot/types/interfaces/elections';
import { IdentityInfo, IdentityJudgement, RegistrarIndex } from '@polkadot/types/interfaces/identity';
import { Heartbeat } from '@polkadot/types/interfaces/imOnline';
import { Keys } from '@polkadot/types/interfaces/session';
import { SocietyJudgement } from '@polkadot/types/interfaces/society';
import { EraIndex, RewardDestination, ValidatorPrefs } from '@polkadot/types/interfaces/staking';
import { Key } from '@polkadot/types/interfaces/system';
import { Timepoint } from '@polkadot/types/interfaces/utility';
import { AnyNumber, CallFunction, ITuple } from '@polkadot/types/types';
declare module '@polkadot/api/types/submittable' {
export interface AugmentedSubmittables<ApiType> {
system: {
fillBlock: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
remark: AugmentedSubmittable<ApiType, (remark: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
setHeapPages: AugmentedSubmittable<ApiType, (pages: u64 | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
setCode: AugmentedSubmittable<ApiType, (code: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
setCodeWithoutChecks: AugmentedSubmittable<ApiType, (code: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
setChangesTrieConfig: AugmentedSubmittable<ApiType, (changesTrieConfig: Option<ChangesTrieConfiguration> | null | object | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
setStorage: AugmentedSubmittable<ApiType, (items: Vec<KeyValue> | (KeyValue)[]) => SubmittableExtrinsic<ApiType> & CallFunction>;
killStorage: AugmentedSubmittable<ApiType, (keys: Vec<Key> | (Key | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType> & CallFunction>;
killPrefix: AugmentedSubmittable<ApiType, (prefix: Key | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
utility: {
batch: AugmentedSubmittable<ApiType, (calls: Vec<Call> | (Call | object | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType> & CallFunction>;
asSub: AugmentedSubmittable<ApiType, (index: u16 | AnyNumber | Uint8Array, call: Call | object | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
asMulti: AugmentedSubmittable<ApiType, (threshold: u16 | AnyNumber | Uint8Array, otherSignatories: Vec<AccountId> | (AccountId | string | Uint8Array)[], maybeTimepoint: Option<Timepoint> | null | object | string | Uint8Array, call: Call | object | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
approveAsMulti: AugmentedSubmittable<ApiType, (threshold: u16 | AnyNumber | Uint8Array, otherSignatories: Vec<AccountId> | (AccountId | string | Uint8Array)[], maybeTimepoint: Option<Timepoint> | null | object | string | Uint8Array, callHash: Raw | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
cancelAsMulti: AugmentedSubmittable<ApiType, (threshold: u16 | AnyNumber | Uint8Array, otherSignatories: Vec<AccountId> | (AccountId | string | Uint8Array)[], timepoint: Timepoint | object | string | Uint8Array, callHash: Raw | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
timestamp: {
set: AugmentedSubmittable<ApiType, (now: Compact<Moment> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
authorship: {
setUncles: AugmentedSubmittable<ApiType, (newUncles: Vec<Header> | (Header | object | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
balances: {
transfer: AugmentedSubmittable<ApiType, (dest: Address, value: Compact<Balance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
setBalance: AugmentedSubmittable<ApiType, (who: Address, newFree: Compact<Balance> | AnyNumber | Uint8Array, newReserved: Compact<Balance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
forceTransfer: AugmentedSubmittable<ApiType, (source: Address, dest: Address, value: Compact<Balance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
transferKeepAlive: AugmentedSubmittable<ApiType, (dest: Address, value: Compact<Balance> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
staking: {
bond: AugmentedSubmittable<ApiType, (controller: Address, value: Compact<BalanceOf> | AnyNumber | Uint8Array, payee: RewardDestination) => SubmittableExtrinsic<ApiType> & CallFunction>;
bondExtra: AugmentedSubmittable<ApiType, (maxAdditional: Compact<BalanceOf> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
unbond: AugmentedSubmittable<ApiType, (value: Compact<BalanceOf> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
withdrawUnbonded: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
validate: AugmentedSubmittable<ApiType, (prefs: ValidatorPrefs | object | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
nominate: AugmentedSubmittable<ApiType, (targets: Vec<Address> | (Address)[]) => SubmittableExtrinsic<ApiType> & CallFunction>;
chill: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
setPayee: AugmentedSubmittable<ApiType, (payee: RewardDestination) => SubmittableExtrinsic<ApiType> & CallFunction>;
setController: AugmentedSubmittable<ApiType, (controller: Address) => SubmittableExtrinsic<ApiType> & CallFunction>;
setValidatorCount: AugmentedSubmittable<ApiType, (updated: Compact<u32> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
forceNoEras: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
forceNewEra: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
setInvulnerables: AugmentedSubmittable<ApiType, (validators: Vec<AccountId> | (AccountId | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType> & CallFunction>;
forceUnstake: AugmentedSubmittable<ApiType, (stash: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
forceNewEraAlways: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
cancelDeferredSlash: AugmentedSubmittable<ApiType, (era: EraIndex | AnyNumber | Uint8Array, slashIndices: Vec<u32> | (u32 | AnyNumber | Uint8Array)[]) => SubmittableExtrinsic<ApiType> & CallFunction>;
rebond: AugmentedSubmittable<ApiType, (value: Compact<BalanceOf> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
session: {
setKeys: AugmentedSubmittable<ApiType, (keys: Keys, proof: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
democracy: {
propose: AugmentedSubmittable<ApiType, (proposalHash: Hash | string | Uint8Array, value: Compact<BalanceOf> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
second: AugmentedSubmittable<ApiType, (proposal: Compact<PropIndex> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
vote: AugmentedSubmittable<ApiType, (refIndex: Compact<ReferendumIndex> | AnyNumber | Uint8Array, vote: Vote | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
proxyVote: AugmentedSubmittable<ApiType, (refIndex: Compact<ReferendumIndex> | AnyNumber | Uint8Array, vote: Vote | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
emergencyCancel: AugmentedSubmittable<ApiType, (refIndex: ReferendumIndex | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
externalPropose: AugmentedSubmittable<ApiType, (proposalHash: Hash | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
externalProposeMajority: AugmentedSubmittable<ApiType, (proposalHash: Hash | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
externalProposeDefault: AugmentedSubmittable<ApiType, (proposalHash: Hash | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
fastTrack: AugmentedSubmittable<ApiType, (proposalHash: Hash | string | Uint8Array, votingPeriod: BlockNumber | AnyNumber | Uint8Array, delay: BlockNumber | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
vetoExternal: AugmentedSubmittable<ApiType, (proposalHash: Hash | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
cancelReferendum: AugmentedSubmittable<ApiType, (refIndex: Compact<ReferendumIndex> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
cancelQueued: AugmentedSubmittable<ApiType, (which: ReferendumIndex | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
setProxy: AugmentedSubmittable<ApiType, (proxy: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
resignProxy: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
removeProxy: AugmentedSubmittable<ApiType, (proxy: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
delegate: AugmentedSubmittable<ApiType, (to: AccountId | string | Uint8Array, conviction: Conviction) => SubmittableExtrinsic<ApiType> & CallFunction>;
undelegate: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
clearPublicProposals: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
notePreimage: AugmentedSubmittable<ApiType, (encodedProposal: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
noteImminentPreimage: AugmentedSubmittable<ApiType, (encodedProposal: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
reapPreimage: AugmentedSubmittable<ApiType, (proposalHash: Hash | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
council: {
setMembers: AugmentedSubmittable<ApiType, (newMembers: Vec<AccountId> | (AccountId | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType> & CallFunction>;
execute: AugmentedSubmittable<ApiType, (proposal: Proposal | object | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
propose: AugmentedSubmittable<ApiType, (threshold: Compact<MemberCount> | AnyNumber | Uint8Array, proposal: Proposal | object | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
vote: AugmentedSubmittable<ApiType, (proposal: Hash | string | Uint8Array, index: Compact<ProposalIndex> | AnyNumber | Uint8Array, approve: bool) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
technicalCommittee: {
setMembers: AugmentedSubmittable<ApiType, (newMembers: Vec<AccountId> | (AccountId | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType> & CallFunction>;
execute: AugmentedSubmittable<ApiType, (proposal: Proposal | object | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
propose: AugmentedSubmittable<ApiType, (threshold: Compact<MemberCount> | AnyNumber | Uint8Array, proposal: Proposal | object | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
vote: AugmentedSubmittable<ApiType, (proposal: Hash | string | Uint8Array, index: Compact<ProposalIndex> | AnyNumber | Uint8Array, approve: bool) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
elections: {
vote: AugmentedSubmittable<ApiType, (votes: Vec<AccountId> | (AccountId | string | Uint8Array)[], value: Compact<BalanceOf> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
removeVoter: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
reportDefunctVoter: AugmentedSubmittable<ApiType, (target: Address) => SubmittableExtrinsic<ApiType> & CallFunction>;
submitCandidacy: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
renounceCandidacy: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
removeMember: AugmentedSubmittable<ApiType, (who: Address) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
technicalMembership: {
addMember: AugmentedSubmittable<ApiType, (who: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
removeMember: AugmentedSubmittable<ApiType, (who: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
swapMember: AugmentedSubmittable<ApiType, (remove: AccountId | string | Uint8Array, add: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
resetMembers: AugmentedSubmittable<ApiType, (members: Vec<AccountId> | (AccountId | string | Uint8Array)[]) => SubmittableExtrinsic<ApiType> & CallFunction>;
changeKey: AugmentedSubmittable<ApiType, (updated: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
finalityTracker: {
finalHint: AugmentedSubmittable<ApiType, (hint: Compact<BlockNumber> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
grandpa: {
reportMisbehavior: AugmentedSubmittable<ApiType, (report: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
treasury: {
proposeSpend: AugmentedSubmittable<ApiType, (value: Compact<BalanceOf> | AnyNumber | Uint8Array, beneficiary: Address) => SubmittableExtrinsic<ApiType> & CallFunction>;
rejectProposal: AugmentedSubmittable<ApiType, (proposalId: Compact<ProposalIndex> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
approveProposal: AugmentedSubmittable<ApiType, (proposalId: Compact<ProposalIndex> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
reportAwesome: AugmentedSubmittable<ApiType, (reason: Bytes | string | Uint8Array, who: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
retractTip: AugmentedSubmittable<ApiType, (hash: Hash | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
tipNew: AugmentedSubmittable<ApiType, (reason: Bytes | string | Uint8Array, who: AccountId | string | Uint8Array, tipValue: BalanceOf | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
tip: AugmentedSubmittable<ApiType, (hash: Hash | string | Uint8Array, tipValue: BalanceOf | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
closeTip: AugmentedSubmittable<ApiType, (hash: Hash | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
contracts: {
updateSchedule: AugmentedSubmittable<ApiType, (schedule: Schedule | object | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
putCode: AugmentedSubmittable<ApiType, (gasLimit: Compact<Gas> | AnyNumber | Uint8Array, code: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
call: AugmentedSubmittable<ApiType, (dest: Address, value: Compact<BalanceOf> | AnyNumber | Uint8Array, gasLimit: Compact<Gas> | AnyNumber | Uint8Array, data: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
instantiate: AugmentedSubmittable<ApiType, (endowment: Compact<BalanceOf> | AnyNumber | Uint8Array, gasLimit: Compact<Gas> | AnyNumber | Uint8Array, codeHash: CodeHash | string | Uint8Array, data: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
claimSurcharge: AugmentedSubmittable<ApiType, (dest: AccountId | string | Uint8Array, auxSender: Option<AccountId> | null | object | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
sudo: {
sudo: AugmentedSubmittable<ApiType, (proposal: Proposal | object | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
setKey: AugmentedSubmittable<ApiType, (updated: Address) => SubmittableExtrinsic<ApiType> & CallFunction>;
sudoAs: AugmentedSubmittable<ApiType, (who: Address, proposal: Proposal | object | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
imOnline: {
heartbeat: AugmentedSubmittable<ApiType, (heartbeat: Heartbeat | object | string | Uint8Array, signature: Signature | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
identity: {
addRegistrar: AugmentedSubmittable<ApiType, (account: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
setIdentity: AugmentedSubmittable<ApiType, (info: IdentityInfo | object | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
setSubs: AugmentedSubmittable<ApiType, (subs: Vec<ITuple<[AccountId, Data]>> | ([AccountId | string | Uint8Array, Data])[]) => SubmittableExtrinsic<ApiType> & CallFunction>;
clearIdentity: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
requestJudgement: AugmentedSubmittable<ApiType, (regIndex: Compact<RegistrarIndex> | AnyNumber | Uint8Array, maxFee: Compact<BalanceOf> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
cancelRequest: AugmentedSubmittable<ApiType, (regIndex: RegistrarIndex | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
setFee: AugmentedSubmittable<ApiType, (index: Compact<RegistrarIndex> | AnyNumber | Uint8Array, fee: Compact<BalanceOf> | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
setAccountId: AugmentedSubmittable<ApiType, (index: Compact<RegistrarIndex> | AnyNumber | Uint8Array, updated: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
setFields: AugmentedSubmittable<ApiType, (index: Compact<RegistrarIndex> | AnyNumber | Uint8Array, fields: IdentityFields) => SubmittableExtrinsic<ApiType> & CallFunction>;
provideJudgement: AugmentedSubmittable<ApiType, (regIndex: Compact<RegistrarIndex> | AnyNumber | Uint8Array, target: Address, judgement: IdentityJudgement) => SubmittableExtrinsic<ApiType> & CallFunction>;
killIdentity: AugmentedSubmittable<ApiType, (target: Address) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
society: {
bid: AugmentedSubmittable<ApiType, (value: BalanceOf | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
unbid: AugmentedSubmittable<ApiType, (pos: u32 | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
vouch: AugmentedSubmittable<ApiType, (who: AccountId | string | Uint8Array, value: BalanceOf | AnyNumber | Uint8Array, tip: BalanceOf | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
unvouch: AugmentedSubmittable<ApiType, (pos: u32 | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
vote: AugmentedSubmittable<ApiType, (candidate: Address, approve: bool) => SubmittableExtrinsic<ApiType> & CallFunction>;
defenderVote: AugmentedSubmittable<ApiType, (approve: bool) => SubmittableExtrinsic<ApiType> & CallFunction>;
payout: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
found: AugmentedSubmittable<ApiType, (founder: AccountId | string | Uint8Array, maxMembers: u32 | AnyNumber | Uint8Array, rules: Bytes | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
unfound: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
judgeSuspendedMember: AugmentedSubmittable<ApiType, (who: AccountId | string | Uint8Array, forgive: bool) => SubmittableExtrinsic<ApiType> & CallFunction>;
judgeSuspendedCandidate: AugmentedSubmittable<ApiType, (who: AccountId | string | Uint8Array, judgement: SocietyJudgement) => SubmittableExtrinsic<ApiType> & CallFunction>;
setMaxMembers: AugmentedSubmittable<ApiType, (max: u32 | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
};
recovery: {
asRecovered: AugmentedSubmittable<ApiType, (account: AccountId | string | Uint8Array, call: Call | object | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
setRecovered: AugmentedSubmittable<ApiType, (lost: AccountId | string | Uint8Array, rescuer: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
createRecovery: AugmentedSubmittable<ApiType, (friends: Vec<AccountId> | (AccountId | string | Uint8Array)[], threshold: u16 | AnyNumber | Uint8Array, delayPeriod: BlockNumber | AnyNumber | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
initiateRecovery: AugmentedSubmittable<ApiType, (account: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
vouchRecovery: AugmentedSubmittable<ApiType, (lost: AccountId | string | Uint8Array, rescuer: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
claimRecovery: AugmentedSubmittable<ApiType, (account: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
closeRecovery: AugmentedSubmittable<ApiType, (rescuer: AccountId | string | Uint8Array) => SubmittableExtrinsic<ApiType> & CallFunction>;
removeRecovery: AugmentedSubmittable<ApiType, () => SubmittableExtrinsic<ApiType> & CallFunction>;
};
}
}
+70
View File
@@ -0,0 +1,70 @@
// Copyright 2017-2020 @polkadot/api 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 { Observable } from 'rxjs';
import { AnyFunction, Callback, Codec } from '@polkadot/types/types';
// Prepend an element V onto the beginning of a tuple T.
// Cons<1, [2,3,4]> is [1,2,3,4]
type Cons<V, T extends any[]> = ((v: V, ...t: T) => void) extends ((...r: infer R) => void)
? R
: never;
// Append an element V onto the end of a tuple T
// Push<[1,2,3],4> is [1,2,3,4]
// note that this DOES NOT PRESERVE optionality/readonly in tuples.
// So unfortunately Push<[1, 2?, 3?], 4> is [1,2|undefined,3|undefined,4]
type Push<T extends any[], V> = (
(
Cons<any, Required<T>> extends infer R
? { [K in keyof R]: K extends keyof T ? T[K] : V }
: never
) extends infer P
? P extends any[] ? P : never
: never
);
export type ApiTypes = 'promise' | 'rxjs';
// Returns the inner type of an Observable
export type ObsInnerType<O extends Observable<any>> = O extends Observable<infer U> ? U : never;
export type UnsubscribePromise = Promise<() => void>;
// FIXME The day TS has higher-kinded types, we can remove this hardcoded stuff
export type PromiseOrObs<ApiType extends ApiTypes, T> = ApiType extends 'rxjs'
? Observable<T>
: Promise<T>;
// Here are the return types of these parts of the api:
// - api.query.*.*: no exact typings
// - api.tx.*.*: SubmittableExtrinsic<ApiType extends ApiTypes>
// - api.derive.*.*: MethodResult<ApiType, F>
// - api.rpc.*.*: no exact typings (for now, FIXME: should be MethodResult<ApiType, F>, like in derive)
// These are the types that don't lose type information (used for api.derive.*)
// Also use these for api.rpc.* https://github.com/polkadot-js/api/issues/1009
export interface RxResult<F extends AnyFunction> {
(...args: Parameters<F>): Observable<ObsInnerType<ReturnType<F>>>;
<T>(...args: Parameters<F>): Observable<T>;
}
export interface PromiseResult<F extends AnyFunction> {
(...args: Parameters<F>): Promise<ObsInnerType<ReturnType<F>>>;
(...args: Push<Parameters<F>, Callback<ObsInnerType<ReturnType<F>>>>): UnsubscribePromise;
<T extends Codec | Codec[]>(...args: Parameters<F>): Promise<T>;
<T extends Codec | Codec[]>(...args: Push<Parameters<F>, Callback<T>>): UnsubscribePromise;
}
// FIXME The day TS has higher-kinded types, we can remove this hardcoded stuff
export type MethodResult<ApiType extends ApiTypes, F extends AnyFunction> = ApiType extends 'rxjs'
? RxResult<F>
: PromiseResult<F>;
// In the abstract `decorateMethod` in Base.ts, we can also pass in some meta-
// information. This describes it.
export interface DecorateMethodOptions {
methodName?: string;
}
export type DecorateMethod<ApiType extends ApiTypes> = <Method extends (...args: any[]) => Observable<any>>(method: Method, options?: DecorateMethodOptions) => any;
+131
View File
@@ -0,0 +1,131 @@
// Copyright 2017-2020 @polkadot/api authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
// Module augmentation so that `api.{consts,query,tx}.*.*` work
import './augment';
import BN from 'bn.js';
import { DeriveCustom, ExactDerive } from '@polkadot/api-derive';
import { Constants } from '@polkadot/metadata/Decorated/types';
import { RpcInterface } from '@polkadot/rpc-core/jsonrpc.types';
import { UserRpc } from '@polkadot/rpc-core/types';
import { Metadata } from '@polkadot/types';
import { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
import { RegistryTypes, SignatureOptions, SignerPayloadJSON, SignerPayloadRaw, Registry } from '@polkadot/types/types';
import ApiBase from '../base';
import { SubmittableResultImpl } from '../submittable/types';
import { DeriveAllSections } from '../util/decorate';
import { DecoratedRpc } from './rpc';
import { QueryableStorage, QueryableStorageMulti } from './storage';
import { SubmittableExtrinsics } from './submittable';
import { ProviderInterface, ProviderInterfaceEmitted } from '@polkadot/rpc-provider/types';
export * from '../submittable/types';
export * from './base';
export * from './rpc';
export * from './storage';
export * from './submittable';
export interface ApiOptions {
/**
* @description Add custom derives to be injected
*/
derives?: DeriveCustom;
/**
* @description prebundles is a map of 'genesis hash and runtime spec version' as key to metadata's hex string
* if genesis hash and runtime spec version matches, then use metadata, else fetch it from chain
*/
metadata?: Record<string, string>;
/**
* @description Transport Provider from rpc-provider. If not specified, it will default to
* connecting to a WsProvider connecting localhost with the default port, i.e. `ws://127.0.0.1:9944`
*/
provider?: ProviderInterface;
/**
* @description A type registry to use along with this instance
*/
registry?: Registry;
/**
* @description User-defined RPC methods
*/
rpc?: UserRpc;
/**
* @description An external signer which will be used to sign extrinsic when account passed in is not KeyringPair
*/
signer?: Signer;
/**
* @description The source object to use for runtime information (only used when cloning)
*/
source?: ApiBase<any>;
/**
* @description Additional types used by runtime modules. This is nessusary if the runtime modules
* uses types not available in the base Substrate runtime.
*/
types?: RegistryTypes;
/**
* @description Additional types that are injected based on the chain we are connecting to. There are keyed by the chain, i.e. `{ 'Kusama CC1': { ... } }`
*/
typesChain?: Record<string, RegistryTypes>;
/**
* @description Additional types that are injected based on the type of node we are connecting to, as set via specName in the runtime version. There are keyed by the node, i.e. `{ 'edgeware': { ... } }`
*/
typesSpec?: Record<string, RegistryTypes>;
}
// A smaller interface of ApiRx, used in derive and in SubmittableExtrinsic
export interface ApiInterfaceRx {
consts: Constants;
// TODO This needs to be typed correctly
derive: DeriveAllSections<'rxjs', ExactDerive>;
extrinsicType: number;
genesisHash: Hash;
hasSubscriptions: boolean;
registry: Registry;
runtimeMetadata: Metadata;
runtimeVersion: RuntimeVersion;
query: QueryableStorage<'rxjs'>;
queryMulti: QueryableStorageMulti<'rxjs'>;
rpc: DecoratedRpc<'rxjs', RpcInterface>;
tx: SubmittableExtrinsics<'rxjs'>;
signer?: Signer;
}
export type ApiInterfaceEvents = ProviderInterfaceEmitted | 'ready';
export interface SignerOptions extends SignatureOptions {
blockNumber: BN;
genesisHash: Hash;
}
export interface SignerResult {
/**
* @description The id for this request
*/
id: number;
/**
* @description The resulting signature in hex
*/
signature: string;
}
export interface Signer {
/**
* @description signs an extrinsic payload from a serialized form
*/
signPayload?: (payload: SignerPayloadJSON) => Promise<SignerResult>;
/**
* @description signs a raw payload, only the bytes data as supplied
*/
signRaw?: (raw: SignerPayloadRaw) => Promise<SignerResult>;
/**
* @description Receives an update for the extrinsic signed by a `signer.sign`
*/
update?: (id: number, status: Hash | SubmittableResultImpl) => void;
}
export { ApiBase };
+17
View File
@@ -0,0 +1,17 @@
// Copyright 2017-2020 @polkadot/api 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 { AnyFunction } from '@polkadot/types/types';
import { ApiTypes, MethodResult } from './base';
export type DecoratedRpcSection<ApiType extends ApiTypes, Section> = {
[Method in keyof Section]: Section[Method] extends AnyFunction
? MethodResult<ApiType, Section[Method]>
: never
}
export type DecoratedRpc<ApiType extends ApiTypes, AllSections> = {
[Section in keyof AllSections]: DecoratedRpcSection<ApiType, AllSections[Section]>
}
+76
View File
@@ -0,0 +1,76 @@
// Copyright 2017-2020 @polkadot/api 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 { Observable } from 'rxjs';
import { u64 } from '@polkadot/types';
import { Hash } from '@polkadot/types/interfaces';
import { AnyFunction, Callback, Codec, CodecArg } from '@polkadot/types/types';
import StorageKey, { StorageEntry } from '@polkadot/types/primitive/StorageKey';
import { ApiTypes, MethodResult, ObsInnerType, PromiseOrObs, UnsubscribePromise } from './base';
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface AugmentedQueries<ApiType extends ApiTypes> { }
export type AugmentedQuery<ApiType extends ApiTypes, F extends AnyFunction> = MethodResult<ApiType, F> & StorageEntryBase<ApiType, F>
// This is the most generic typings we can have for a storage entry function
type GenericStorageEntryFunction = (arg1?: CodecArg, arg2?: CodecArg) => Observable<Codec>
export type QueryableStorageEntry<ApiType extends ApiTypes> =
ApiType extends 'rxjs'
? AugmentedQuery<'rxjs', GenericStorageEntryFunction>
: AugmentedQuery<'promise', GenericStorageEntryFunction> & StorageEntryPromiseOverloads;
export interface StorageEntryBase<ApiType extends ApiTypes, F extends AnyFunction> {
at: (hash: Hash | Uint8Array | string, ...args: Parameters<F>) => PromiseOrObs<ApiType, ObsInnerType<ReturnType<F>>>;
creator: StorageEntry;
entries: () => PromiseOrObs<ApiType, [StorageKey, ObsInnerType<ReturnType<F>>][]>;
hash: (...args: Parameters<F>) => PromiseOrObs<ApiType, Hash>;
key: (...args: Parameters<F>) => string;
size: (...args: Parameters<F>) => PromiseOrObs<ApiType, u64>;
multi: ApiType extends 'rxjs' ? StorageEntryObservableMulti : StorageEntryPromiseMulti;
}
interface StorageEntryObservableMulti {
<T extends Codec>(args: (CodecArg[] | CodecArg)[]): Observable<T[]>;
}
interface StorageEntryPromiseMulti {
<T extends Codec>(args: (CodecArg[] | CodecArg)[]): Promise<T[]>;
<T extends Codec>(args: (CodecArg[] | CodecArg)[], callback: Callback<T[]>): UnsubscribePromise;
}
export interface StorageEntryPromiseOverloads {
(arg1?: CodecArg, arg2?: CodecArg): Promise<Codec>;
<T extends Codec>(arg1?: CodecArg, arg2?: CodecArg): Promise<T>;
<T extends Codec>(callback: Callback<T>): UnsubscribePromise;
<T extends Codec>(arg: CodecArg, callback: Callback<T>): UnsubscribePromise;
<T extends Codec>(arg1: CodecArg, arg2: CodecArg, callback: Callback<T>): UnsubscribePromise;
}
export interface QueryableModuleStorage<ApiType extends ApiTypes> {
[index: string]: QueryableStorageEntry<ApiType>;
}
export type QueryableStorageMultiArg<ApiType extends ApiTypes> =
QueryableStorageEntry<ApiType> |
[QueryableStorageEntry<ApiType>, ...CodecArg[]];
export interface QueryableStorageMultiBase<ApiType extends ApiTypes> {
<T extends Codec[]>(calls: QueryableStorageMultiArg<ApiType>[]): Observable<T>;
}
export interface QueryableStorageMultiPromise<ApiType extends ApiTypes> {
<T extends Codec[]>(calls: QueryableStorageMultiArg<ApiType>[], callback: Callback<T>): UnsubscribePromise;
}
export type QueryableStorageMulti<ApiType extends ApiTypes> =
ApiType extends 'rxjs'
? QueryableStorageMultiBase<ApiType>
: QueryableStorageMultiPromise<ApiType>;
export interface QueryableStorage<ApiType extends ApiTypes> extends AugmentedQueries<ApiType> {
[index: string]: QueryableModuleStorage<ApiType>;
}
+26
View File
@@ -0,0 +1,26 @@
// Copyright 2017-2020 @polkadot/api 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 { AnyFunction, CallFunction, CodecArg } from '@polkadot/types/types';
import { SubmittableExtrinsic } from '../submittable/types';
import { ApiTypes, MethodResult } from './base';
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface AugmentedSubmittables<ApiType extends ApiTypes> { }
export type AugmentedSubmittable<ApiType extends ApiTypes, F extends AnyFunction> = MethodResult<ApiType, F> & SubmittableExtrinsicFunction<ApiType>
export interface SubmittableExtrinsicFunction<ApiType extends ApiTypes> extends CallFunction {
(...params: CodecArg[]): SubmittableExtrinsic<ApiType>;
}
export interface SubmittableModuleExtrinsics<ApiType extends ApiTypes> {
[index: string]: SubmittableExtrinsicFunction<ApiType>;
}
export interface SubmittableExtrinsics<ApiType extends ApiTypes> extends AugmentedSubmittables<ApiType> {
(extrinsic: Uint8Array | string): SubmittableExtrinsic<ApiType>;
[index: string]: SubmittableModuleExtrinsics<ApiType>;
}
+21 -21
View File
@@ -7,51 +7,51 @@ import { Bytes, H256, Metadata, StorageData, StorageKey, Text, u32, u64 } from '
import { AccountId, BlockNumber, Extrinsic, Hash, Header, Index, SignedBlock } from '@polkadot/types/interfaces/runtime';
import { ContractCallRequest, ContractExecResult } from '@polkadot/types/interfaces/contracts';
import { BlockHash, ChainProperties, ExtrinsicOrHash, ExtrinsicStatus, Health, NetworkState, PeerInfo, RpcMethods, RuntimeDispatchInfo, RuntimeVersion, StorageChangeSet } from '@polkadot/types/interfaces/rpc';
import { Codec, IExtrinsic } from '@polkadot/types/types';
import { AnyNumber, Codec, IExtrinsic } from '@polkadot/types/types';
export interface RpcInterface {
account: {
nextIndex(accountId: AccountId | Uint8Array | string): Observable<Index>;
nextIndex(accountId: AccountId | string | Uint8Array): Observable<Index>;
};
author: {
insertKey(keyType: Text | string, suri: Text | string, publicKey: Bytes | Uint8Array | string): Observable<Bytes>;
insertKey(keyType: Text | string, suri: Text | string, publicKey: Bytes | string | Uint8Array): Observable<Bytes>;
pendingExtrinsics(): Observable<Vec<Extrinsic>>;
removeExtrinsic(bytesOrHash: (ExtrinsicOrHash)[]): Observable<Vec<Hash>>;
removeExtrinsic(bytesOrHash: Vec<ExtrinsicOrHash> | (ExtrinsicOrHash)[]): Observable<Vec<Hash>>;
rotateKeys(): Observable<Bytes>;
submitAndWatchExtrinsic(extrinsic: IExtrinsic): Observable<ExtrinsicStatus>;
submitExtrinsic(extrinsic: IExtrinsic): Observable<Hash>;
};
chain: {
getBlock(hash?: BlockHash | Uint8Array | string): Observable<SignedBlock>;
getBlockHash(blockNumber?: BlockNumber | Uint8Array | number | string): Observable<BlockHash>;
getBlock(hash?: BlockHash | string | Uint8Array): Observable<SignedBlock>;
getBlockHash(blockNumber?: BlockNumber | AnyNumber | Uint8Array): Observable<BlockHash>;
getFinalizedHead(): Observable<BlockHash>;
getHeader(hash?: BlockHash | Uint8Array | string): Observable<Header>;
getHeader(hash?: BlockHash | string | Uint8Array): Observable<Header>;
subscribeFinalizedHeads(): Observable<Header>;
subscribeNewHeads(): Observable<Header>;
};
contracts: {
call(callRequest: ContractCallRequest, at?: BlockHash | Uint8Array | string): Observable<ContractExecResult>;
getStorage(address: AccountId | Uint8Array | string, key: H256 | Uint8Array | string, at?: BlockHash | Uint8Array | string): Observable<Option<Bytes>>;
call(callRequest: ContractCallRequest | object | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<ContractExecResult>;
getStorage(address: AccountId | string | Uint8Array, key: H256 | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<Option<Bytes>>;
};
payment: {
queryInfo(extrinsic: Bytes | Uint8Array | string, at?: BlockHash | Uint8Array | string): Observable<RuntimeDispatchInfo>;
queryInfo(extrinsic: Bytes | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<RuntimeDispatchInfo>;
};
rpc: {
methods(): Observable<RpcMethods>;
};
state: {
call(method: Text | string, data: Bytes | Uint8Array | string, at?: BlockHash | Uint8Array | string): Observable<Bytes>;
getChildKeys(childStorageKey: any, childDefinition: any, childType: u32 | Uint8Array | number | string, key: any, at?: BlockHash | Uint8Array | string): Observable<Vec<StorageKey>>;
getChildStorage(childStorageKey: any, childDefinition: any, childType: u32 | Uint8Array | number | string, key: any, at?: BlockHash | Uint8Array | string): Observable<StorageData>;
getChildStorageHash(childStorageKey: any, childDefinition: any, childType: u32 | Uint8Array | number | string, key: any, at?: BlockHash | Uint8Array | string): Observable<Hash>;
getChildStorageSize(childStorageKey: any, childDefinition: any, childType: u32 | Uint8Array | number | string, key: any, at?: BlockHash | Uint8Array | string): Observable<u64>;
getKeys(key: any, at?: BlockHash | Uint8Array | string): Observable<Vec<StorageKey>>;
getMetadata(at?: BlockHash | Uint8Array | string): Observable<Metadata>;
getRuntimeVersion(at?: BlockHash | Uint8Array | string): Observable<RuntimeVersion>;
call(method: Text | string, data: Bytes | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<Bytes>;
getChildKeys(childStorageKey: StorageKey | any, childDefinition: StorageKey | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | any, at?: BlockHash | string | Uint8Array): Observable<Vec<StorageKey>>;
getChildStorage(childStorageKey: StorageKey | any, childDefinition: StorageKey | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | any, at?: BlockHash | string | Uint8Array): Observable<StorageData>;
getChildStorageHash(childStorageKey: StorageKey | any, childDefinition: StorageKey | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | any, at?: BlockHash | string | Uint8Array): Observable<Hash>;
getChildStorageSize(childStorageKey: StorageKey | any, childDefinition: StorageKey | any, childType: u32 | AnyNumber | Uint8Array, key: StorageKey | any, at?: BlockHash | string | Uint8Array): Observable<u64>;
getKeys(key: StorageKey | any, at?: BlockHash | string | Uint8Array): Observable<Vec<StorageKey>>;
getMetadata(at?: BlockHash | string | Uint8Array): Observable<Metadata>;
getRuntimeVersion(at?: BlockHash | string | Uint8Array): Observable<RuntimeVersion>;
getStorage<T = Codec>(key: any, block?: Hash | Uint8Array | string): Observable<T>;
getStorageHash(key: any, at?: BlockHash | Uint8Array | string): Observable<Hash>;
getStorageSize(key: any, at?: BlockHash | Uint8Array | string): Observable<u64>;
queryStorage(keys: (any)[], startBlock: Hash | Uint8Array | string, at?: BlockHash | Uint8Array | string): Observable<Vec<StorageChangeSet>>;
getStorageHash(key: StorageKey | any, at?: BlockHash | string | Uint8Array): Observable<Hash>;
getStorageSize(key: StorageKey | any, at?: BlockHash | string | Uint8Array): Observable<u64>;
queryStorage(keys: Vec<StorageKey> | (StorageKey | any)[], startBlock: Hash | string | Uint8Array, at?: BlockHash | string | Uint8Array): Observable<Vec<StorageChangeSet>>;
subscribeRuntimeVersion(): Observable<RuntimeVersion>;
subscribeStorage<T = Codec[]>(keys: any[]): Observable<T>;
};
@@ -95,7 +95,7 @@ function hasWrapper (type: string, [start, end]: [string, string, TypeDefInfo, a
return false;
}
assert(type.endsWith(end), `Expected '${start}' closing with '${end}'`);
assert(type.endsWith(end), `Expected '${start}' closing with '${end}' on ${type}`);
return true;
}
@@ -14,41 +14,33 @@ import { createImportCode, createImports, FOOTER, HEADER, indent, setImports, Ty
// Generate types for one module
/** @internal */
function generateModule (allDefs: object, modul: ModuleMetadataLatest, imports: TypeImports): string[] {
if (!modul.constants.length) {
function generateModule (allDefs: object, { constants, name }: ModuleMetadataLatest, imports: TypeImports): string[] {
if (!constants.length) {
return [];
}
setImports(allDefs, imports, ['Codec']);
// NOTE Not removing this concat yet, first see the fallout (needs: setImports(allDefs, imports, ['Codec']);)
return [indent(4)(`${stringCamelCase(name.toString())}: {`)]
// .concat(indent(6)('[index: string]: Codec;'))
.concat(constants.map((constant): string => {
setImports(allDefs, imports, [constant.type.toString()]);
return [indent(4)(`${stringCamelCase(modul.name.toString())}: {`)]
.concat(indent(6)('[index: string]: Codec;'))
.concat(
modul.constants
.map((constant): string => {
setImports(allDefs, imports, [constant.type.toString()]);
return indent(6)(`${stringCamelCase(constant.name.toString())}: ${constant.type} & ConstantCodec;`);
})
)
return indent(6)(`${stringCamelCase(constant.name.toString())}: ${constant.type} & ConstantCodec;`);
}))
.concat([indent(4)('};')]);
}
// Generate `packages/api/src/consts.types.ts` for a particular
// metadata
/** @internal */
function generateForMeta (meta: Metadata, dest: string, extraTypes: Record<string, Record<string, object>>): void {
console.log(`Writing ${dest}`);
console.log(`${dest}\n\tGenerating`);
const allTypes: Record<string, Record<string, object>> = { '@polkadot/types/interfaces': defaultDefs, ...extraTypes };
const imports = createImports(allTypes);
const allDefs = Object.entries(allTypes).reduce((defs, [, obj]) => {
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [key]: value }), defs);
}, {});
const body = meta.asLatest.modules.reduce((acc, modul): string[] => {
const storageEntries = generateModule(allDefs, modul, imports);
return acc.concat(storageEntries);
const body = meta.asLatest.modules.reduce((acc, mod): string[] => {
return acc.concat(generateModule(allDefs, mod, imports));
}, [] as string[]);
const header = createImportCode(HEADER, [
{
@@ -74,6 +66,8 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: Record<strin
].join('\n');
const interfaceEnd = `\n${indent(2)('}')}\n}`;
console.log('\tWriting');
fs.writeFileSync(
dest,
header
@@ -83,11 +77,13 @@ function generateForMeta (meta: Metadata, dest: string, extraTypes: Record<strin
.concat(FOOTER)
, { flag: 'w' }
);
console.log('');
}
// Call `generateForMeta()` with current static metadata
/** @internal */
export default function generateConsts (dest = 'packages/api/src/consts.types.ts', data = staticData, extraTypes: Record<string, Record<string, object>> = {}): void {
export default function generateConsts (dest = 'packages/api/src/types/augment/consts.ts', data = staticData, extraTypes: Record<string, Record<string, object>> = {}): void {
const registry = new TypeRegistry();
return generateForMeta(new Metadata(registry, data), dest, extraTypes);
@@ -7,14 +7,7 @@ import fs from 'fs';
import Raw from '../../codec/Raw';
import * as defaultDefinitions from '../../interfaces/definitions';
import * as defaultPrimitives from '../../primitive';
import {
createImportCode, createImports,
FOOTER,
getDerivedTypes,
HEADER,
indent,
setImports
} from '../util';
import { FOOTER, HEADER, createImportCode, createImports, getDerivedTypes, indent, setImports } from '../util';
const primitiveClasses = {
...defaultPrimitives,
@@ -23,7 +16,7 @@ const primitiveClasses = {
/** @internal */
export function generateInterfaceRegistry (importDefinitions: { [importPath: string]: object }, output: string): void {
console.log(`Writing ${output}`);
console.log(`${output}\n\tGenerating`);
Object.entries(importDefinitions).reduce((acc, def) => Object.assign(acc, def), {} as object);
@@ -72,11 +65,15 @@ export function generateInterfaceRegistry (importDefinitions: { [importPath: str
const interfaceStart = 'export interface InterfaceRegistry {';
const interfaceEnd = '\n}';
console.log('\tWriting');
fs.writeFileSync(
output,
header.concat(interfaceStart).concat(primitives).concat(srml).concat(interfaceEnd).concat(FOOTER)
, { flag: 'w' }
);
console.log('');
}
// Generate `packages/types/src/interfaceRegistry.ts`, the registry of all interfaces
@@ -12,7 +12,7 @@ import { stringLowerFirst } from '@polkadot/util';
import { Metadata } from '../..';
import { TypeRegistry } from '../../codec';
import { createImportCode, createImports, FOOTER, formatType, getSimilarTypes, HEADER, indent, setImports, TypeImports } from '../util';
import { FOOTER, HEADER, TypeImports, createImportCode, createImports, formatType, getSimilarTypes, indent, setImports } from '../util';
// If the StorageEntry returns T, output `Option<T>` if the modifier is optional
/** @internal */
@@ -73,34 +73,32 @@ function generateEntry (allDefs: object, registry: Registry, storageEntry: Stora
const [args, returnType] = entrySignature(allDefs, registry, storageEntry, imports);
return [
`${stringLowerFirst(storageEntry.name.toString())}: StorageEntryExact<ApiType, (${args}) => Observable<${returnType}>> & QueryableStorageEntry<ApiType>;`
`${stringLowerFirst(storageEntry.name.toString())}: AugmentedQuery<ApiType, (${args}) => Observable<${returnType}>> & QueryableStorageEntry<ApiType>;`
];
}
// Generate types for one module
/** @internal */
function generateModule (allDefs: object, registry: Registry, modul: ModuleMetadataLatest, imports: TypeImports): string[] {
if (modul.storage.isNone) {
function generateModule (allDefs: object, registry: Registry, { name, storage }: ModuleMetadataLatest, imports: TypeImports): string[] {
if (storage.isNone) {
return [];
}
return [indent(4)(`${stringLowerFirst(modul.name.toString())}: {`)]
.concat(indent(6)('[index: string]: QueryableStorageEntry<ApiType>;'))
.concat(
modul.storage.unwrap().items
.reduce((acc, storageEntry): string[] => {
return acc.concat(generateEntry(allDefs, registry, storageEntry, imports).map(indent(6)));
}, [] as string[])
.join('\n')
)
// NOTE Not removing this concat yet, first see the fallout
return [indent(4)(`${stringLowerFirst(name.toString())}: {`)]
// .concat(indent(6)('[index: string]: QueryableStorageEntry<ApiType>;'))
.concat(storage.unwrap()
.items
.reduce((acc, storageEntry): string[] => {
return acc.concat(generateEntry(allDefs, registry, storageEntry, imports).map(indent(6)));
}, [] as string[])
.join('\n'))
.concat([indent(4)('};')]);
}
// Generate `packages/api/src/query.types.ts` for a particular
// metadata
/** @internal */
function generateForMeta (registry: Registry, meta: Metadata, dest: string, extraTypes: Record<string, Record<string, object>>): void {
console.log(`Writing ${dest}`);
console.log(`${dest}\n\tGenerating`);
const allTypes: Record<string, Record<string, object>> = { '@polkadot/types/interfaces': defaultDefs, ...extraTypes };
const imports = createImports(allTypes);
@@ -108,9 +106,7 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [key]: value }), defs);
}, {});
const body = meta.asLatest.modules.reduce((acc, mod): string[] => {
const storageEntries = generateModule(allDefs, registry, mod, imports);
return acc.concat(storageEntries);
return acc.concat(generateModule(allDefs, registry, mod, imports));
}, [] as string[]);
const header = createImportCode(HEADER, [
{
@@ -135,11 +131,13 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
}
]);
const interfaceStart = [
"declare module '@polkadot/api/types' {",
indent(2)('export interface QueryableStorageExact<ApiType> {\n')
"declare module '@polkadot/api/types/storage' {",
indent(2)('export interface AugmentedQueries<ApiType> {\n')
].join('\n');
const interfaceEnd = `\n${indent(2)('}')}\n}`;
console.log('\tWriting');
fs.writeFileSync(
dest,
header
@@ -149,11 +147,13 @@ function generateForMeta (registry: Registry, meta: Metadata, dest: string, extr
.concat(FOOTER)
, { flag: 'w' }
);
console.log('');
}
// Call `generateForMeta()` with current static metadata
/** @internal */
export default function generateQuery (dest = 'packages/api/src/query.types.ts', data = staticData, extraTypes: Record<string, Record<string, object>> = {}): void {
export default function generateQuery (dest = 'packages/api/src/types/augment/query.ts', data = staticData, extraTypes: Record<string, Record<string, object>> = {}): void {
const registry = new TypeRegistry();
return generateForMeta(registry, new Metadata(registry, data), dest, extraTypes);
@@ -9,10 +9,9 @@ import * as definitions from '../../interfaces/definitions';
import { TypeRegistry } from '../../codec/create';
import { createImportCode, createImports, FOOTER, getSimilarTypes, HEADER, setImports } from '../util';
// Generate `packages/rpc-core/jsonrpc.types.ts`
/** @internal */
export default function generateRpcTypes (dest = 'packages/rpc-core/src/jsonrpc.types.ts'): void {
console.log(`Writing ${dest}`);
console.log(`${dest}\n\tGenerating`);
const registry = new TypeRegistry();
const imports = createImports({ '@polkadot/types/interfaces': definitions });
@@ -77,9 +76,13 @@ export default function generateRpcTypes (dest = 'packages/rpc-core/src/jsonrpc.
const interfaceStart = 'export interface RpcInterface {\n';
const interfaceEnd = '\n}';
console.log('\tWriting');
fs.writeFileSync(
dest,
header.concat(interfaceStart).concat(body).concat(interfaceEnd).concat(FOOTER)
, { flag: 'w' }
);
console.log('');
}
@@ -194,32 +194,28 @@ function generateTsDefFor (importDefinitions: { [importPath: string]: object },
}))
]);
Object.entries(imports.localTypes).forEach(([moduleName, typeMap]): void => {
const types = Object.keys(typeMap).sort();
if (types.length) {
console.log(`\timport { ${types.join(', ')} } from '../${moduleName}'`);
}
});
fs.writeFileSync(path.join(outputDir, defName, 'types.ts'), header.concat(sortedDefs).concat(FOOTER), { flag: 'w' });
fs.writeFileSync(path.join(outputDir, defName, 'index.ts'), HEADER.concat('export * from \'./types\';').concat(FOOTER), { flag: 'w' });
}
/** @internal */
export function generateTsDef (importDefinitions: { [importPath: string]: object }, outputDir: string, generatingPackage: string): void {
console.log(`${outputDir}\n\tGenerating`);
const definitions = importDefinitions[generatingPackage];
Object.entries(definitions).forEach(([defName, obj]): void => {
console.log(`Extracting interfaces for ${defName}`);
console.log(`\tExtracting interfaces for ${defName}`);
generateTsDefFor(importDefinitions, defName, obj, outputDir);
});
console.log(`Writing ${outputDir}`);
console.log('\tWriting');
fs.writeFileSync(path.join(outputDir, 'types.ts'), HEADER.concat(Object.keys(definitions).map((moduleName): string => `export * from './${moduleName}/types';`).join('\n')).concat(FOOTER), { flag: 'w' });
fs.writeFileSync(path.join(outputDir, 'index.ts'), HEADER.concat('export * from \'./types\';').concat(FOOTER), { flag: 'w' });
console.log('');
}
/** @internal */
+122
View File
@@ -0,0 +1,122 @@
// Copyright 2017-2020 @polkadot/types 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 { ModuleMetadataLatest } from '../../interfaces/metadata';
import * as defaultDefs from '../../interfaces/definitions';
import { Registry } from '../../types';
import fs from 'fs';
import staticData from '@polkadot/metadata/Metadata/static';
import { Text } from '@polkadot/types';
import { stringCamelCase } from '@polkadot/util';
import { Metadata, TypeRegistry } from '../..';
import { FOOTER, HEADER, TypeImports, createImportCode, createImports, formatType, getSimilarTypes, indent, setImports } from '../util';
const MAPPED_NAMES: Record<string, string> = {
new: 'updated'
};
function mapName (_name: Text): string {
const name = stringCamelCase(_name.toString());
return MAPPED_NAMES[name] || name;
}
// Generate types for one module
/** @internal */
// eslint-disable-next-line @typescript-eslint/no-unused-vars
function generateModule (registry: Registry, allDefs: object, { calls, name }: ModuleMetadataLatest, imports: TypeImports): string[] {
const allCalls = calls.unwrapOr(null);
if (!allCalls?.length) {
return [];
}
setImports(allDefs, imports, ['CallFunction', 'SubmittableExtrinsic']);
// NOTE Not removing this concat yet, first see the fallout
return [indent(4)(`${stringCamelCase(name.toString())}: {`)]
// .concat(indent(6)('[index: string]: Codec;'))
.concat(allCalls.map(({ args, name }): string => {
const params = args.map(({ name, type }): string => {
const typeStr = type.toString();
const similarTypes = getSimilarTypes(allDefs, registry, typeStr, imports).map((type): string =>
type.startsWith('(')
? type
: formatType(allDefs, type, imports)
);
setImports(allDefs, imports, [...similarTypes.filter((type): boolean => !type.startsWith('(')), typeStr]);
return `${mapName(name)}: ${similarTypes.join(' | ')}`;
});
return indent(6)(`${stringCamelCase(name.toString())}: AugmentedSubmittable<ApiType, (${params.join(', ')}) => SubmittableExtrinsic<ApiType> & CallFunction>;`);
}))
.concat([indent(4)('};')]);
}
/** @internal */
function generateForMeta (registry: Registry, meta: Metadata, dest: string, extraTypes: Record<string, Record<string, object>>): void {
console.log(`${dest}\n\tGenerating`);
const allTypes: Record<string, Record<string, object>> = { '@polkadot/types/interfaces': defaultDefs, ...extraTypes };
const imports = createImports(allTypes);
const allDefs = Object.entries(allTypes).reduce((defs, [, obj]) => {
return Object.entries(obj).reduce((defs, [key, value]) => ({ ...defs, [key]: value }), defs);
}, {});
const body = meta.asLatest.modules.reduce((acc, mod): string[] => {
return acc.concat(generateModule(registry, allDefs, mod, imports));
}, [] as string[]);
const header = createImportCode(HEADER, [
{
file: '@polkadot/api/submittable/types',
types: ['SubmittableExtrinsic']
},
{
file: '@polkadot/types/codec',
types: Object.keys(imports.codecTypes).filter((name): boolean => name !== 'Tuple')
},
{
file: '@polkadot/types',
types: Object.keys(imports.primitiveTypes)
},
...Object.keys(imports.localTypes).map((moduleName): { file: string; types: string[] } => ({
file: `${imports.moduleToPackage[moduleName]}/${moduleName}`,
types: Object.keys(imports.localTypes[moduleName])
})),
{
file: '@polkadot/types/types',
types: Object.keys(imports.typesTypes)
}
]);
const interfaceStart = [
"declare module '@polkadot/api/types/submittable' {",
indent(2)('export interface AugmentedSubmittables<ApiType> {\n')
].join('\n');
const interfaceEnd = `\n${indent(2)('}')}\n}`;
console.log('\tWriting');
fs.writeFileSync(
dest,
header
.concat(interfaceStart)
.concat(body.join('\n'))
.concat(interfaceEnd)
.concat(FOOTER)
, { flag: 'w' }
);
console.log('');
}
// Call `generateForMeta()` with current static metadata
/** @internal */
export default function generateTx (dest = 'packages/api/src/types/augment/tx.ts', data = staticData, extraTypes: Record<string, Record<string, object>> = {}): void {
const registry = new TypeRegistry();
return generateForMeta(registry, new Metadata(registry, data), dest, extraTypes);
}
+13 -14
View File
@@ -2,19 +2,18 @@
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
import generateConstsTypes from './generateTypes/consts';
import generateInterfaceRegistry from './generateTypes/interfaceRegistry';
import generateQueryTypes from './generateTypes/query';
import generateRpcTypes from './generateTypes/rpc';
import generateTsDef from './generateTypes/tsDef';
import generateConstsTypes from './generate/consts';
import generateInterfaceRegistry from './generate/interfaceRegistry';
import generateQueryTypes from './generate/query';
import generateRpcTypes from './generate/rpc';
import generateTsDef from './generate/tsDef';
import generateTxTypes from './generate/tx';
/** @internal */
function main (): void {
generateConstsTypes();
generateInterfaceRegistry();
generateQueryTypes();
generateRpcTypes();
generateTsDef();
}
generateInterfaceRegistry();
main();
generateConstsTypes();
generateQueryTypes();
generateTxTypes();
generateRpcTypes();
generateTsDef();
@@ -23,12 +23,13 @@ if (typeof WebSocket === 'undefined') {
const path = require('path');
const yargs = require('yargs');
const { formatNumber } = require('@polkadot/util');
const generateConst = require('./generateTypes/consts').default;
const generateQuery = require('./generateTypes/query').default;
const generateConst = require('./generate/consts').default;
const generateQuery = require('./generate/query').default;
const generateTx = require('./generate/tx').default;
const { endpoint, output, package } = yargs.strict().options({
endpoint: {
description: 'The endpoint to connect to, e.g. wss://kusama-rpc.polkadot.io',
description: 'The endpoint to connect to, e.g. wss://kusama-rpc.polkadot.io or relative file to JSON output',
type: 'string',
required: true
},
@@ -43,6 +44,20 @@ const { endpoint, output, package } = yargs.strict().options({
}).argv;
let websocket = null;
function generate (metaHex) {
console.log(`Generating from metadata, ${formatNumber((metaHex.length - 2) / 2)} bytes`);
const extraTypes = package
? { [package]: require(path.join(process.cwd(), output, 'definitions')) }
: {};
generateConst(path.join(process.cwd(), output, 'augment.consts.ts'), metaHex, extraTypes);
generateQuery(path.join(process.cwd(), output, 'augment.query.ts'), metaHex, extraTypes);
generateTx(path.join(process.cwd(), output, 'augment.tx.ts'), metaHex, extraTypes);
process.exit(0);
}
function onSocketClose (event) {
console.error(`${endpoint} disconnected, code: '${event.code}' reason: '${event.reason}'`);
@@ -64,22 +79,15 @@ function onSocketOpen () {
}
function onSocketMessage (message) {
const data = JSON.parse(message.data);
const metaHex = data.result;
const extraTypes = package
? { [package]: require(path.join(process.cwd(), output, 'definitions')) }
: {};
console.log(`Received metadata, ${formatNumber((metaHex.length - 2) / 2)} bytes`);
generateConst(path.join(process.cwd(), output, 'consts.types.ts'), metaHex, extraTypes);
generateQuery(path.join(process.cwd(), output, 'query.types.ts'), metaHex, extraTypes);
process.exit(0);
generate(JSON.parse(message.data).result);
}
websocket = new WebSocket(endpoint);
websocket.onclose = onSocketClose;
websocket.onerror = onSocketError;
websocket.onmessage = onSocketMessage;
websocket.onopen = onSocketOpen;
if (endpoint.startsWith('wss://') || endpoint.startsWith('ws://')) {
websocket = new WebSocket(endpoint);
websocket.onclose = onSocketClose;
websocket.onerror = onSocketError;
websocket.onmessage = onSocketMessage;
websocket.onopen = onSocketOpen;
} else {
generate(require(path.join(process.cwd(), endpoint)).result);
}
+33 -15
View File
@@ -8,6 +8,9 @@ import { Constructor, Registry } from '../../types';
import { isChildClass, isCompactEncodable } from './class';
import { ClassOfUnsafe, getTypeDef } from '../../codec/create';
import AbstractInt from '../../codec/AbstractInt';
import Compact from '../../codec/Compact';
import Option from '../../codec/Option';
import Struct from '../../codec/Struct';
import Vec from '../../codec/Vec';
import { formatType } from './formatting';
import { setImports, TypeImports } from './imports';
@@ -49,7 +52,7 @@ export function getDerivedTypes (definitions: object, type: string, primitiveNam
}
// Make types a little bit more flexible
// - if param instanceof AbstractInt, then param: u64 | Uint8array | string | number
// - if param instanceof AbstractInt, then param: u64 | Uint8array | AnyNumber
// etc
/** @internal */
export function getSimilarTypes (definitions: object, registry: Registry, type: string, imports: TypeImports): string[] {
@@ -58,24 +61,39 @@ export function getSimilarTypes (definitions: object, registry: Registry, type:
if (type === 'Extrinsic') {
setImports(definitions, imports, ['IExtrinsic']);
return ['IExtrinsic'];
} else if (type === 'StorageKey') {
// FIXME This is a hack, it's hard to correctly type StorageKeys in the
// current state
return ['StorageKey', 'any'];
}
if (isChildClass(Vec, ClassOfUnsafe(registry, type))) {
return [`(${getSimilarTypes(definitions, registry, ((getTypeDef(type).sub) as TypeDef).type, imports).join(' | ')})[]`];
const instance = ClassOfUnsafe(registry, type);
if (isChildClass(Vec, instance)) {
const subDef = (getTypeDef(type).sub) as TypeDef;
if (subDef.info === TypeDefInfo.Plain) {
possibleTypes.push(`(${getSimilarTypes(definitions, registry, subDef.type, imports).join(' | ')})[]`);
} else if (subDef.info === TypeDefInfo.Tuple) {
const subs = (subDef.sub as TypeDef[]).map(({ type }): string =>
getSimilarTypes(definitions, registry, type, imports).join(' | ')
);
possibleTypes.push(`([${subs.join(', ')}])[]`);
} else {
throw new Error(`Unhandled subtype in Vec, ${JSON.stringify(subDef)}`);
}
}
// FIXME This is a hack, it's hard to correctly type StorageKeys in the
// current state
if (type === 'StorageKey') {
return ['any'];
}
// Cannot get isChildClass of abstract class, but it works
if (isChildClass(AbstractInt as unknown as Constructor<any>, ClassOfUnsafe(registry, type))) {
possibleTypes.push('Uint8Array', 'number', 'string');
} else if (isChildClass(Uint8Array, ClassOfUnsafe(registry, type))) {
possibleTypes.push('Uint8Array', 'string');
} else if (isChildClass(String, ClassOfUnsafe(registry, type))) {
if (isChildClass(AbstractInt as unknown as Constructor<any>, instance) || isChildClass(Compact, instance)) {
possibleTypes.push('AnyNumber', 'Uint8Array');
} else if (isChildClass(Struct, instance)) {
possibleTypes.push('object', 'string', 'Uint8Array');
} else if (isChildClass(Option, instance)) {
possibleTypes.push('null', 'object', 'string', 'Uint8Array');
} else if (isChildClass(Uint8Array, instance)) {
possibleTypes.push('string', 'Uint8Array');
} else if (isChildClass(String, instance)) {
possibleTypes.push('string');
}
@@ -102,6 +102,7 @@ function formatVec (inner: string): string {
/** @internal */
export function formatType (definitions: object, type: string | TypeDef, imports: TypeImports): string {
let typeDef: TypeDef;
if (typeof type === 'string') {
typeDef = getTypeDef(type);
} else {
+1 -1
View File
@@ -35,7 +35,7 @@ export function setImports (allDefs: object, imports: TypeImports, types: string
types.forEach((type): void => {
if (ignoredTypes.includes(type)) {
// do nothing
} else if (['Codec', 'IExtrinsic', 'ITuple'].includes(type)) {
} else if (['AnyNumber', 'CallFunction', 'Codec', 'IExtrinsic', 'ITuple'].includes(type)) {
typesTypes[type] = true;
} else if ((codecClasses as any)[type]) {
codecTypes[type] = true;