UNPKG

6.83 kBTypeScriptView Raw
1/// <reference types="bn.js" />
2import type { RpcInterface } from '@polkadot/rpc-core/types';
3import type { Text } from '@polkadot/types';
4import type { Hash, RuntimeVersion } from '@polkadot/types/interfaces';
5import type { DecoratedMeta } from '@polkadot/types/metadata/decorate/types';
6import type { AnyFunction, Codec, DefinitionRpc, DefinitionRpcSub, DetectCodec, Registry, RegistryTypes } from '@polkadot/types/types';
7import type { ApiDecoration, ApiInterfaceRx, ApiOptions, ApiTypes, DecoratedErrors, DecoratedEvents, DecoratedRpc, DecorateMethod, QueryableConsts, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics } from '../types';
8import type { VersionedRegistry } from './types';
9import { BehaviorSubject } from 'rxjs';
10import { RpcCore } from '@polkadot/rpc-core';
11import { Metadata } from '@polkadot/types';
12import { BN } from '@polkadot/util';
13import { AllDerives } from '../util/decorate';
14import { Events } from './Events';
15interface FullDecoration<ApiType extends ApiTypes> {
16 decoratedApi: ApiDecoration<ApiType>;
17 decoratedMeta: DecoratedMeta;
18}
19export declare abstract class Decorate<ApiType extends ApiTypes> extends Events {
20 #private;
21 protected __phantom: BN;
22 protected _consts: QueryableConsts<ApiType>;
23 protected _derive?: ReturnType<Decorate<ApiType>['_decorateDerive']>;
24 protected _errors: DecoratedErrors<ApiType>;
25 protected _events: DecoratedEvents<ApiType>;
26 protected _extrinsics?: SubmittableExtrinsics<ApiType>;
27 protected _extrinsicType: number;
28 protected _genesisHash?: Hash;
29 protected _isConnected: BehaviorSubject<boolean>;
30 protected _isReady: boolean;
31 protected readonly _options: ApiOptions;
32 protected _query: QueryableStorage<ApiType>;
33 protected _queryMulti?: QueryableStorageMulti<ApiType>;
34 protected _rpc?: DecoratedRpc<ApiType, RpcInterface>;
35 protected _rpcCore: RpcCore & RpcInterface;
36 protected _runtimeChain?: Text;
37 protected _runtimeMetadata?: Metadata;
38 protected _runtimeVersion?: RuntimeVersion;
39 protected _rx: ApiInterfaceRx;
40 protected _type: ApiTypes;
41 /**
42 * This is the one and only method concrete children classes need to implement.
43 * It's a higher-order function, which takes one argument
44 * `method: Method extends (...args: any[]) => Observable<any>`
45 * (and one optional `options`), and should return the user facing method.
46 * For example:
47 * - For ApiRx, `decorateMethod` should just be identity, because the input
48 * function is already an Observable
49 * - For ApiPromise, `decorateMethod` should return a function that takes all
50 * the parameters from `method`, adds an optional `callback` argument, and
51 * returns a Promise.
52 *
53 * We could easily imagine other user-facing interfaces, which are simply
54 * implemented by transforming the Observable to Stream/Iterator/Kefir/Bacon
55 * via `decorateMethod`.
56 */
57 protected _decorateMethod: DecorateMethod<ApiType>;
58 /**
59 * @description Create an instance of the class
60 *
61 * @param options Options object to create API instance or a Provider instance
62 *
63 * @example
64 * <BR>
65 *
66 * ```javascript
67 * import Api from '@polkadot/api/promise';
68 *
69 * const api = new Api().isReady();
70 *
71 * api.rpc.subscribeNewHeads((header) => {
72 * console.log(`new block #${header.number.toNumber()}`);
73 * });
74 * ```
75 */
76 constructor(options: ApiOptions, type: ApiTypes, decorateMethod: DecorateMethod<ApiType>);
77 abstract at(blockHash: Uint8Array | string, knownVersion?: RuntimeVersion): Promise<ApiDecoration<ApiType>>;
78 /**
79 * @description Return the current used registry
80 */
81 get registry(): Registry;
82 /**
83 * @description Creates an instance of a type as registered
84 */
85 createType<T extends Codec = Codec, K extends string = string>(type: K, ...params: unknown[]): DetectCodec<T, K>;
86 /**
87 * @description Register additional user-defined of chain-specific types in the type registry
88 */
89 registerTypes(types?: RegistryTypes): void;
90 /**
91 * @returns `true` if the API operates with subscriptions
92 */
93 get hasSubscriptions(): boolean;
94 /**
95 * @returns `true` if the API decorate multi-key queries
96 */
97 get supportMulti(): boolean;
98 protected _emptyDecorated(registry: Registry, blockHash?: Uint8Array): ApiDecoration<ApiType>;
99 protected _createDecorated(registry: VersionedRegistry<ApiType>, fromEmpty: boolean, decoratedApi: ApiDecoration<ApiType> | null, blockHash?: Uint8Array): FullDecoration<ApiType>;
100 protected _injectMetadata(registry: VersionedRegistry<ApiType>, fromEmpty?: boolean): void;
101 /**
102 * @deprecated
103 * backwards compatible endpoint for metadata injection, may be removed in the future (However, it is still useful for testing injection)
104 */
105 injectMetadata(metadata: Metadata, fromEmpty?: boolean, registry?: Registry): void;
106 private _decorateFunctionMeta;
107 protected _filterRpc(methods: string[], additional: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>): void;
108 protected _filterRpcMethods(exposed: string[]): void;
109 protected _decorateRpc<ApiType extends ApiTypes>(rpc: RpcCore & RpcInterface, decorateMethod: DecorateMethod<ApiType>, input?: Partial<DecoratedRpc<ApiType, RpcInterface>>): DecoratedRpc<ApiType, RpcInterface>;
110 protected _decorateMulti<ApiType extends ApiTypes>(decorateMethod: DecorateMethod<ApiType>): QueryableStorageMulti<ApiType>;
111 protected _decorateMultiAt<ApiType extends ApiTypes>(atApi: ApiDecoration<ApiType>, decorateMethod: DecorateMethod<ApiType>, blockHash: Uint8Array | string): QueryableStorageMulti<ApiType>;
112 protected _decorateExtrinsics<ApiType extends ApiTypes>({ tx }: DecoratedMeta, decorateMethod: DecorateMethod<ApiType>): SubmittableExtrinsics<ApiType>;
113 private _decorateExtrinsicEntry;
114 protected _decorateStorage<ApiType extends ApiTypes>({ query, registry }: DecoratedMeta, decorateMethod: DecorateMethod<ApiType>, blockHash?: Uint8Array): QueryableStorage<ApiType>;
115 private _decorateStorageEntry;
116 private _decorateStorageEntryAt;
117 private _decorateStorageCall;
118 private _decorateStorageRange;
119 private _retrieveMulti;
120 private _retrieveMapKeys;
121 private _retrieveMapKeysPaged;
122 private _retrieveMapEntries;
123 private _retrieveMapEntriesPaged;
124 protected _decorateDeriveRx(decorateMethod: DecorateMethod<ApiType>): AllDerives<'rxjs'>;
125 protected _decorateDerive(decorateMethod: DecorateMethod<ApiType>): AllDerives<ApiType>;
126 /**
127 * Put the `this.onCall` function of ApiRx here, because it is needed by
128 * `api._rx`.
129 */
130 protected _rxDecorateMethod: <Method extends AnyFunction>(method: Method) => Method;
131}
132export {};