import { Constants, Storage } from "../../metadata/Decorated/types"; import { RpcInterface } from "../../rpc-core/types"; import { InterfaceRegistry } from "../../types/interfaceRegistry"; import { Hash, RuntimeVersion } from "../../types/interfaces"; import { AnyFunction, InterfaceTypes, ModulesWithCalls, Registry, RegistryTypes } from "../../types/types"; import { ApiInterfaceRx, ApiOptions, ApiTypes, DecorateMethod, DecoratedRpc, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics } from '../types'; import BN from 'bn.js'; import { BehaviorSubject } from 'rxjs'; import { ExactDerive } from "../../api-derive"; import RpcCore from "../../rpc-core"; import { Metadata } from "../../types"; import { DeriveAllSections } from '../util/decorate'; import Events from './Events'; export default abstract class Decorate extends Events { readonly registry: Registry; protected __phantom: BN; protected _consts?: Constants; protected _derive?: ReturnType['decorateDerive']>; 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; protected _runtimeMetadata?: Metadata; protected _runtimeVersion?: RuntimeVersion; protected _rx: Partial; 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 createType(type: K, ...params: any[]): InterfaceRegistry[K]; abstract registerTypes(types?: RegistryTypes): void; /** * @returns `true` if the API operates with subscriptions */ get hasSubscriptions(): boolean; private decorateFunctionMeta; protected filterRpc(): Promise; protected filterRpcMethods(methods: string[]): void; protected decorateRpc(rpc: RpcCore, decorateMethod: DecorateMethod): DecoratedRpc; protected decorateMulti(decorateMethod: DecorateMethod): QueryableStorageMulti; protected decorateExtrinsics(extrinsics: ModulesWithCalls, decorateMethod: DecorateMethod): SubmittableExtrinsics; private decorateExtrinsicEntry; protected decorateStorage(storage: Storage, decorateMethod: DecorateMethod): QueryableStorage; private decorateStorageEntry; private decorateStorageLinked; private retrieveMapEntries; protected decorateDeriveRx(decorateMethod: DecorateMethod): DeriveAllSections<'rxjs', ExactDerive>; protected decorateDerive(decorateMethod: DecorateMethod): DeriveAllSections; /** * Put the `this.onCall` function of ApiRx here, because it is needed by * `api._rx`. */ protected rxDecorateMethod: (method: Method) => Method; }