/// import type { RpcInterface } from '@polkadot/rpc-core/types'; import type { Text } from '@polkadot/types'; import type { Hash, RuntimeVersion } from '@polkadot/types/interfaces'; import type { DecoratedMeta } from '@polkadot/types/metadata/decorate/types'; import type { AnyFunction, Codec, DefinitionRpc, DefinitionRpcSub, DetectCodec, Registry, RegistryTypes } from '@polkadot/types/types'; import type { ApiDecoration, ApiInterfaceRx, ApiOptions, ApiTypes, DecoratedErrors, DecoratedEvents, DecoratedRpc, DecorateMethod, QueryableConsts, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics } from '../types'; import type { VersionedRegistry } from './types'; import { BehaviorSubject } from 'rxjs'; import { RpcCore } from '@polkadot/rpc-core'; import { Metadata } from '@polkadot/types'; import { BN } from '@polkadot/util'; import { AllDerives } from '../util/decorate'; import { Events } from './Events'; interface FullDecoration { decoratedApi: ApiDecoration; decoratedMeta: DecoratedMeta; } export declare abstract class Decorate extends Events { #private; protected __phantom: BN; protected _consts: QueryableConsts; protected _derive?: ReturnType['_decorateDerive']>; protected _errors: DecoratedErrors; protected _events: DecoratedEvents; protected _extrinsics?: SubmittableExtrinsics; protected _extrinsicType: number; protected _genesisHash?: Hash; protected _isConnected: BehaviorSubject; protected _isReady: boolean; protected readonly _options: ApiOptions; protected _query: QueryableStorage; protected _queryMulti?: QueryableStorageMulti; protected _rpc?: DecoratedRpc; protected _rpcCore: RpcCore & RpcInterface; protected _runtimeChain?: Text; protected _runtimeMetadata?: Metadata; protected _runtimeVersion?: RuntimeVersion; protected _rx: ApiInterfaceRx; protected _type: ApiTypes; /** * This is the one and only method concrete children classes need to implement. * It's a higher-order function, which takes one argument * `method: Method extends (...args: any[]) => Observable` * (and one optional `options`), and should return the user facing method. * For example: * - For ApiRx, `decorateMethod` should just be identity, because the input * function is already an Observable * - For ApiPromise, `decorateMethod` should return a function that takes all * the parameters from `method`, adds an optional `callback` argument, and * returns a Promise. * * We could easily imagine other user-facing interfaces, which are simply * implemented by transforming the Observable to Stream/Iterator/Kefir/Bacon * via `decorateMethod`. */ protected _decorateMethod: DecorateMethod; /** * @description Create an instance of the class * * @param options Options object to create API instance or a Provider instance * * @example *
* * ```javascript * import Api from '@polkadot/api/promise'; * * const api = new Api().isReady(); * * api.rpc.subscribeNewHeads((header) => { * console.log(`new block #${header.number.toNumber()}`); * }); * ``` */ constructor(options: ApiOptions, type: ApiTypes, decorateMethod: DecorateMethod); abstract at(blockHash: Uint8Array | string, knownVersion?: RuntimeVersion): Promise>; /** * @description Return the current used registry */ get registry(): Registry; /** * @description Creates an instance of a type as registered */ createType(type: K, ...params: unknown[]): DetectCodec; /** * @description Register additional user-defined of chain-specific types in the type registry */ registerTypes(types?: RegistryTypes): void; /** * @returns `true` if the API operates with subscriptions */ get hasSubscriptions(): boolean; /** * @returns `true` if the API decorate multi-key queries */ get supportMulti(): boolean; protected _emptyDecorated(registry: Registry, blockHash?: Uint8Array): ApiDecoration; protected _createDecorated(registry: VersionedRegistry, fromEmpty: boolean, decoratedApi: ApiDecoration | null, blockHash?: Uint8Array): FullDecoration; protected _injectMetadata(registry: VersionedRegistry, fromEmpty?: boolean): void; /** * @deprecated * backwards compatible endpoint for metadata injection, may be removed in the future (However, it is still useful for testing injection) */ injectMetadata(metadata: Metadata, fromEmpty?: boolean, registry?: Registry): void; private _decorateFunctionMeta; protected _filterRpc(methods: string[], additional: Record>): void; protected _filterRpcMethods(exposed: string[]): void; protected _decorateRpc(rpc: RpcCore & RpcInterface, decorateMethod: DecorateMethod, input?: Partial>): DecoratedRpc; protected _decorateMulti(decorateMethod: DecorateMethod): QueryableStorageMulti; protected _decorateMultiAt(atApi: ApiDecoration, decorateMethod: DecorateMethod, blockHash: Uint8Array | string): QueryableStorageMulti; protected _decorateExtrinsics({ tx }: DecoratedMeta, decorateMethod: DecorateMethod): SubmittableExtrinsics; private _decorateExtrinsicEntry; protected _decorateStorage({ query, registry }: DecoratedMeta, decorateMethod: DecorateMethod, blockHash?: Uint8Array): QueryableStorage; private _decorateStorageEntry; private _decorateStorageEntryAt; private _decorateStorageCall; private _decorateStorageRange; private _retrieveMulti; private _retrieveMapKeys; private _retrieveMapKeysPaged; private _retrieveMapEntries; private _retrieveMapEntriesPaged; protected _decorateDeriveRx(decorateMethod: DecorateMethod): AllDerives<'rxjs'>; protected _decorateDerive(decorateMethod: DecorateMethod): AllDerives; /** * Put the `this.onCall` function of ApiRx here, because it is needed by * `api._rx`. */ protected _rxDecorateMethod: (method: Method) => Method; } export {};