@pezkuwi/api 16.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +100 -0
- package/build/augment.d.ts +1 -0
- package/build/base/Decorate.d.ts +143 -0
- package/build/base/Events.d.ts +67 -0
- package/build/base/Getters.d.ts +163 -0
- package/build/base/Init.d.ts +44 -0
- package/build/base/find.d.ts +3 -0
- package/build/base/index.d.ts +47 -0
- package/build/base/types.d.ts +15 -0
- package/build/bundle.d.ts +7 -0
- package/build/index.d.ts +2 -0
- package/build/packageDetect.d.ts +1 -0
- package/build/packageInfo.d.ts +6 -0
- package/build/promise/Api.d.ts +158 -0
- package/build/promise/Combinator.d.ts +12 -0
- package/build/promise/decorateMethod.d.ts +14 -0
- package/build/promise/index.d.ts +2 -0
- package/build/promise/types.d.ts +5 -0
- package/build/rx/Api.d.ts +155 -0
- package/build/rx/decorateMethod.d.ts +3 -0
- package/build/rx/index.d.ts +2 -0
- package/build/submittable/Result.d.ts +31 -0
- package/build/submittable/createClass.d.ts +12 -0
- package/build/submittable/createSubmittable.d.ts +8 -0
- package/build/submittable/index.d.ts +2 -0
- package/build/submittable/types.d.ts +1 -0
- package/build/types/calls.d.ts +1 -0
- package/build/types/consts.d.ts +1 -0
- package/build/types/errors.d.ts +1 -0
- package/build/types/events.d.ts +1 -0
- package/build/types/index.d.ts +114 -0
- package/build/types/storage.d.ts +1 -0
- package/build/types/submittable.d.ts +1 -0
- package/build/util/augmentObject.d.ts +9 -0
- package/build/util/decorate.d.ts +16 -0
- package/build/util/filterEvents.d.ts +6 -0
- package/build/util/index.d.ts +4 -0
- package/build/util/isKeyringPair.d.ts +3 -0
- package/build/util/logging.d.ts +1 -0
- package/build/util/validate.d.ts +3 -0
- package/package.json +46 -0
- package/src/augment.ts +4 -0
- package/src/base/Decorate.ts +1103 -0
- package/src/base/Events.ts +91 -0
- package/src/base/Getters.ts +245 -0
- package/src/base/Init.ts +525 -0
- package/src/base/find.ts +14 -0
- package/src/base/index.ts +85 -0
- package/src/base/types.ts +19 -0
- package/src/bundle.ts +16 -0
- package/src/checkTypes.manual.ts +323 -0
- package/src/index.ts +6 -0
- package/src/mod.ts +4 -0
- package/src/packageDetect.ts +16 -0
- package/src/packageInfo.ts +6 -0
- package/src/promise/Api.ts +214 -0
- package/src/promise/Combinator.ts +91 -0
- package/src/promise/Combinators.spec.ts +109 -0
- package/src/promise/decorateMethod.ts +118 -0
- package/src/promise/index.spec.ts +167 -0
- package/src/promise/index.ts +5 -0
- package/src/promise/types.ts +9 -0
- package/src/rx/Api.ts +186 -0
- package/src/rx/decorateMethod.ts +9 -0
- package/src/rx/index.ts +5 -0
- package/src/submittable/Result.ts +111 -0
- package/src/submittable/createClass.ts +438 -0
- package/src/submittable/createSubmittable.ts +19 -0
- package/src/submittable/index.ts +5 -0
- package/src/submittable/types.ts +4 -0
- package/src/test/SingleAccountSigner.ts +53 -0
- package/src/test/index.ts +5 -0
- package/src/test/logEvents.ts +24 -0
- package/src/types/calls.ts +4 -0
- package/src/types/consts.ts +4 -0
- package/src/types/errors.ts +4 -0
- package/src/types/events.ts +4 -0
- package/src/types/index.ts +137 -0
- package/src/types/storage.ts +4 -0
- package/src/types/submittable.ts +4 -0
- package/src/util/augmentObject.spec.ts +54 -0
- package/src/util/augmentObject.ts +112 -0
- package/src/util/decorate.ts +43 -0
- package/src/util/filterEvents.ts +34 -0
- package/src/util/index.ts +10 -0
- package/src/util/isKeyringPair.ts +11 -0
- package/src/util/logging.ts +6 -0
- package/src/util/validate.spec.ts +72 -0
- package/src/util/validate.ts +36 -0
- package/tsconfig.build.json +25 -0
- package/tsconfig.build.tsbuildinfo +1 -0
- package/tsconfig.spec.json +26 -0
package/README.md
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# @pezkuwi/api
|
|
2
|
+
|
|
3
|
+
The Pezkuwi-JS API provides easy-to-use wrappers around JSONRPC calls that flow from an application to a node. It handles all the encoding and decoding or parameters, provides access to RPC functions and allows for the query of chain state and the submission of transactions.
|
|
4
|
+
|
|
5
|
+
The API wrappers provide a standard interface for use -
|
|
6
|
+
|
|
7
|
+
- A static `.create(<optional ApiOptions>)` that returns an API instance when connected, decorated and ready-to use. ApiOptions can include an optional WsProvider and optional custom type definitions `{ provider: <Optional WsProvider>, types: <Optional RegistryTypes> }`.
|
|
8
|
+
- The above is just a wrapper for `new Api(<optional ApiOptions>) `, exposing the `isReady` getter
|
|
9
|
+
- `api.rpc.<section>.<method>` provides access to actual RPC calls, be it for queries, submission or retrieving chain information
|
|
10
|
+
- [RPC (node interface)](https://pezkuwi.js.org/docs/substrate/rpc)
|
|
11
|
+
- `api.query.<section>.<method>` provides access to chain state queries. These are dynamically populated based on what the runtime provides
|
|
12
|
+
- [Storage chain state (runtime node interface)](https://pezkuwi.js.org/docs/substrate/storage)
|
|
13
|
+
- `api.tx.<section>.<method>` provides the ability to create a transaction, like chain state, this list is populated from a runtime query
|
|
14
|
+
- [Extrinsics (runtime node interface)](https://pezkuwi.js.org/docs/substrate/extrinsics)
|
|
15
|
+
- `api.consts.<section>.<constant>` provides access to the module constants (parameter types).
|
|
16
|
+
- [Constants (runtime node interface)](https://pezkuwi.js.org/docs/substrate/constants)
|
|
17
|
+
|
|
18
|
+
## API Selection
|
|
19
|
+
|
|
20
|
+
There are two flavours of the API provided, one allowing a standard interface via JavaScript Promises and the second provides an Observable wrapper using [RxJS](https://github.com/ReactiveX/rxjs). Depending on your use-case and familiarity, you can choose either (or even both) for your application.
|
|
21
|
+
|
|
22
|
+
- [[ApiPromise]] All interface calls returns Promises, including the static `.create(...)`. Additionally any subscription method uses `(value) => {}` callbacks, returning the value as the subscription is updated.
|
|
23
|
+
- [[ApiRx]] All interface calls return RxJS Observables, including the static `.create(...)`. In the same fashion subscription-based methods return long-running Observables that update with the latest values.
|
|
24
|
+
|
|
25
|
+
## Dynamic by default
|
|
26
|
+
|
|
27
|
+
Substrate (upon which Pezkuwi is built) uses on-chain WASM runtimes, allowing for upgradability. Each runtime defining the actual chain extrinsics (submitted transactions and block intrinsics) as well as available entries in the chain state. Due to this, the API endpoints for queries and transactions are dynamically populated from the running chain.
|
|
28
|
+
|
|
29
|
+
Due to this dynamic nature, this API departs from traditional APIs which only has fixed endpoints, driving use by what is available by the runtime. As a start, this generic nature has a learning curve, although the provided documentation, examples and linked documentation tries to make that experience as seamless as possible.
|
|
30
|
+
|
|
31
|
+
## Installation & import
|
|
32
|
+
|
|
33
|
+
Installation -
|
|
34
|
+
|
|
35
|
+
```
|
|
36
|
+
npm install --save @pezkuwi/api
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
Subscribing to blocks via Promise-based API -
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
import { ApiPromise } from '@pezkuwi/api';
|
|
43
|
+
|
|
44
|
+
// initialise via static create
|
|
45
|
+
const api = await ApiPromise.create();
|
|
46
|
+
|
|
47
|
+
// make a call to retrieve the current network head
|
|
48
|
+
api.rpc.chain.subscribeNewHeads((header) => {
|
|
49
|
+
console.log(`Chain is at #${header.number}`);
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
Subscribing to blocks via RxJS-based API -
|
|
54
|
+
|
|
55
|
+
```javascript
|
|
56
|
+
import { ApiRx } from '@pezkuwi/api';
|
|
57
|
+
|
|
58
|
+
// initialise via static create
|
|
59
|
+
const api = await ApiRx.create().toPromise();
|
|
60
|
+
|
|
61
|
+
// make a call to retrieve the current network head
|
|
62
|
+
api.rpc.chain.subscribeNewHeads().subscribe((header) => {
|
|
63
|
+
console.log(`Chain is at #${header.number}`);
|
|
64
|
+
});
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Registering custom types
|
|
68
|
+
|
|
69
|
+
Additional types used by runtime modules can be added when a new instance of the API is created. This is necessary if the runtime modules use types which are not available in the base Substrate runtime.
|
|
70
|
+
|
|
71
|
+
```javascript
|
|
72
|
+
import { ApiPromise } from '@pezkuwi/api';
|
|
73
|
+
|
|
74
|
+
// initialise via static create and register custom types
|
|
75
|
+
const api = await ApiPromise.create({
|
|
76
|
+
types: {
|
|
77
|
+
CustomTypesExample: {
|
|
78
|
+
"id": "u32",
|
|
79
|
+
"data": "Vec<u8>",
|
|
80
|
+
"deposit": "Balance",
|
|
81
|
+
"owner": "AccountId",
|
|
82
|
+
"application_expiry": "Moment",
|
|
83
|
+
"whitelisted": "bool",
|
|
84
|
+
"challenge_id": "u32"
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## Users
|
|
91
|
+
|
|
92
|
+
Some of the users of the API (let us know if you are missing from the list), include -
|
|
93
|
+
|
|
94
|
+
- [Pezkuwi-JS UI](https://github.com/polkadot-js/apps) A user-interface that allows you to make transactions, query the network or participate in actions on the network such as referendums and staking
|
|
95
|
+
- [KodaDot](https://github.com/vue-polkadot/apps) ([twitter](https://twitter.com/KodaDot)) - Vue.js web wallet, governance dashboard and aspiring performance (lightweight) alternative to original apps, mobile-first.
|
|
96
|
+
- [Polkabot](https://gitlab.com/Polkabot) Polkabot is a Matrix chatbot that keeps an eye on the Pezkuwi network. You can see Polkabot in action in https://matrix.to/#/#polkadot-network-status:matrix.org
|
|
97
|
+
- [Polkawallet.io](https://polkawallet.io) and [Polkawallet (Github)](https://github.com/polkawallet-io/polkawallet-RN/) A mobile wallet for the Pezkuwi network to manage funds and make transactions, available on both Androind and iOS
|
|
98
|
+
- [PolkaStats.io](https://polkastats.io), [PolkaStats frontend GitHub repository](https://github.com/Colm3na/polkastats-v2) and [PolkaStats backend GitHub repository](https://github.com/Colm3na/polkastats-backend-v2) Pezkuwi network statistics (currently Kusama and Alexander). Shows network information and staking details from validators and intentions.
|
|
99
|
+
- [Pezkuwi API Server (GitHub)](https://github.com/SimplyVC/polkadot_api_server) A lightweight server for querying Pezkuwi nodes from any language, built primarily as a backend for [PANIC for Pezkuwi (GitHub)](https://github.com/SimplyVC/panic_polkadot/), a validator monitoring and alerting tool.
|
|
100
|
+
- [Identity Registrar #1 from Chevdor on Westend, Kusama and Pezkuwi](https://www.chevdor.com/tags/registrar/)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import '@pezkuwi/api-augment';
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import type { Observable } from 'rxjs';
|
|
2
|
+
import type { AugmentedCall, QueryableCalls } from '@pezkuwi/api-base/types';
|
|
3
|
+
import type { RpcInterface } from '@pezkuwi/rpc-core/types';
|
|
4
|
+
import type { Metadata, Text, Vec } from '@pezkuwi/types';
|
|
5
|
+
import type { Hash, RuntimeApiMethodMetadataV16, RuntimeVersion } from '@pezkuwi/types/interfaces';
|
|
6
|
+
import type { DecoratedMeta } from '@pezkuwi/types/metadata/decorate/types';
|
|
7
|
+
import type { AnyFunction, Codec, DefinitionCall, DefinitionCallNamed, DefinitionRpc, DefinitionRpcSub, DefinitionsCall, DefinitionsCallEntry, DetectCodec, Registry, RegistryTypes } from '@pezkuwi/types/types';
|
|
8
|
+
import type { HexString } from '@pezkuwi/util/types';
|
|
9
|
+
import type { ApiDecoration, ApiInterfaceRx, ApiOptions, ApiTypes, DecoratedErrors, DecoratedEvents, DecoratedRpc, DecorateMethod, QueryableConsts, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics } from '../types/index.js';
|
|
10
|
+
import type { AllDerives } from '../util/decorate.js';
|
|
11
|
+
import type { VersionedRegistry } from './types.js';
|
|
12
|
+
import { BehaviorSubject } from 'rxjs';
|
|
13
|
+
import { RpcCore } from '@pezkuwi/rpc-core';
|
|
14
|
+
import { BN } from '@pezkuwi/util';
|
|
15
|
+
import { Events } from './Events.js';
|
|
16
|
+
interface FullDecoration<ApiType extends ApiTypes> {
|
|
17
|
+
createdAt?: Uint8Array | undefined;
|
|
18
|
+
decoratedApi: ApiDecoration<ApiType>;
|
|
19
|
+
decoratedMeta: DecoratedMeta;
|
|
20
|
+
}
|
|
21
|
+
export declare abstract class Decorate<ApiType extends ApiTypes> extends Events {
|
|
22
|
+
#private;
|
|
23
|
+
protected __phantom: BN;
|
|
24
|
+
protected _type: ApiTypes;
|
|
25
|
+
protected _call: QueryableCalls<ApiType>;
|
|
26
|
+
protected _consts: QueryableConsts<ApiType>;
|
|
27
|
+
protected _derive?: ReturnType<Decorate<ApiType>['_decorateDerive']>;
|
|
28
|
+
protected _errors: DecoratedErrors<ApiType>;
|
|
29
|
+
protected _events: DecoratedEvents<ApiType>;
|
|
30
|
+
protected _extrinsics?: SubmittableExtrinsics<ApiType>;
|
|
31
|
+
protected _extrinsicType: number;
|
|
32
|
+
protected _genesisHash?: Hash;
|
|
33
|
+
protected _isConnected: BehaviorSubject<boolean>;
|
|
34
|
+
protected _isReady: boolean;
|
|
35
|
+
protected _query: QueryableStorage<ApiType>;
|
|
36
|
+
protected _queryMulti?: QueryableStorageMulti<ApiType>;
|
|
37
|
+
protected _rpc?: DecoratedRpc<ApiType, RpcInterface>;
|
|
38
|
+
protected _rpcCore: RpcCore & RpcInterface;
|
|
39
|
+
protected _runtimeMap: Record<HexString, string>;
|
|
40
|
+
protected _runtimeChain?: Text;
|
|
41
|
+
protected _runtimeMetadata?: Metadata;
|
|
42
|
+
protected _runtimeVersion?: RuntimeVersion;
|
|
43
|
+
protected _rx: ApiInterfaceRx;
|
|
44
|
+
protected readonly _options: ApiOptions;
|
|
45
|
+
/**
|
|
46
|
+
* This is the one and only method concrete children classes need to implement.
|
|
47
|
+
* It's a higher-order function, which takes one argument
|
|
48
|
+
* `method: Method extends (...args: any[]) => Observable<any>`
|
|
49
|
+
* (and one optional `options`), and should return the user facing method.
|
|
50
|
+
* For example:
|
|
51
|
+
* - For ApiRx, `decorateMethod` should just be identity, because the input
|
|
52
|
+
* function is already an Observable
|
|
53
|
+
* - For ApiPromise, `decorateMethod` should return a function that takes all
|
|
54
|
+
* the parameters from `method`, adds an optional `callback` argument, and
|
|
55
|
+
* returns a Promise.
|
|
56
|
+
*
|
|
57
|
+
* We could easily imagine other user-facing interfaces, which are simply
|
|
58
|
+
* implemented by transforming the Observable to Stream/Iterator/Kefir/Bacon
|
|
59
|
+
* via `decorateMethod`.
|
|
60
|
+
*/
|
|
61
|
+
protected _decorateMethod: DecorateMethod<ApiType>;
|
|
62
|
+
/**
|
|
63
|
+
* @description Create an instance of the class
|
|
64
|
+
*
|
|
65
|
+
* @param options Options object to create API instance or a Provider instance
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* <BR>
|
|
69
|
+
*
|
|
70
|
+
* ```javascript
|
|
71
|
+
* import Api from '@pezkuwi/api/promise';
|
|
72
|
+
*
|
|
73
|
+
* const api = new Api().isReady();
|
|
74
|
+
*
|
|
75
|
+
* api.rpc.subscribeNewHeads((header) => {
|
|
76
|
+
* console.log(`new block #${header.number.toNumber()}`);
|
|
77
|
+
* });
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
constructor(options: ApiOptions, type: ApiTypes, decorateMethod: DecorateMethod<ApiType>);
|
|
81
|
+
abstract at(blockHash: Uint8Array | string, knownVersion?: RuntimeVersion): Promise<ApiDecoration<ApiType>>;
|
|
82
|
+
/**
|
|
83
|
+
* @description Return the current used registry
|
|
84
|
+
*/
|
|
85
|
+
get registry(): Registry;
|
|
86
|
+
/**
|
|
87
|
+
* @description Creates an instance of a type as registered
|
|
88
|
+
*/
|
|
89
|
+
createType<T extends Codec = Codec, K extends string = string>(type: K, ...params: unknown[]): DetectCodec<T, K>;
|
|
90
|
+
/**
|
|
91
|
+
* @description Register additional user-defined of chain-specific types in the type registry
|
|
92
|
+
*/
|
|
93
|
+
registerTypes(types?: RegistryTypes): void;
|
|
94
|
+
/**
|
|
95
|
+
* @returns `true` if the API operates with subscriptions
|
|
96
|
+
*/
|
|
97
|
+
get hasSubscriptions(): boolean;
|
|
98
|
+
/**
|
|
99
|
+
* @returns `true` if the API decorate multi-key queries
|
|
100
|
+
*/
|
|
101
|
+
get supportMulti(): boolean;
|
|
102
|
+
protected _emptyDecorated(registry: Registry, blockHash?: Uint8Array): ApiDecoration<ApiType>;
|
|
103
|
+
protected _createDecorated(registry: VersionedRegistry<ApiType>, fromEmpty: boolean, decoratedApi: ApiDecoration<ApiType> | null, blockHash?: Uint8Array): FullDecoration<ApiType>;
|
|
104
|
+
protected _injectMetadata(registry: VersionedRegistry<ApiType>, fromEmpty?: boolean): void;
|
|
105
|
+
/**
|
|
106
|
+
* @deprecated
|
|
107
|
+
* backwards compatible endpoint for metadata injection, may be removed in the future (However, it is still useful for testing injection)
|
|
108
|
+
*/
|
|
109
|
+
injectMetadata(metadata: Metadata, fromEmpty?: boolean, registry?: Registry): void;
|
|
110
|
+
private _decorateFunctionMeta;
|
|
111
|
+
protected _filterRpc(methods: string[], additional: Record<string, Record<string, DefinitionRpc | DefinitionRpcSub>>): void;
|
|
112
|
+
protected _filterRpcMethods(exposed: string[]): void;
|
|
113
|
+
private _rpcSubmitter;
|
|
114
|
+
protected _decorateRpc<ApiType extends ApiTypes>(rpc: RpcCore & RpcInterface, decorateMethod: DecorateMethod<ApiType>, input?: Partial<DecoratedRpc<ApiType, RpcInterface>>): DecoratedRpc<ApiType, RpcInterface>;
|
|
115
|
+
protected _addRuntimeDef(result: DefinitionsCall, additional?: DefinitionsCall): void;
|
|
116
|
+
protected _getRuntimeDefs(registry: Registry, specName: Text, chain?: Text | string): [string, DefinitionsCallEntry[]][];
|
|
117
|
+
protected _getMethods(registry: Registry, methods: Vec<RuntimeApiMethodMetadataV16>): Record<string, DefinitionCall>;
|
|
118
|
+
protected _getRuntimeDefsViaMetadata(registry: Registry): [string, DefinitionsCallEntry[]][];
|
|
119
|
+
protected _decorateCalls<ApiType extends ApiTypes>({ registry, runtimeVersion: { apis, specName, specVersion } }: VersionedRegistry<any>, decorateMethod: DecorateMethod<ApiType>, blockHash?: Uint8Array | string | null): QueryableCalls<ApiType>;
|
|
120
|
+
protected _decorateCall<ApiType extends ApiTypes>(registry: Registry, def: DefinitionCallNamed, stateCall: (method: string, bytes: Uint8Array) => Observable<Codec>, decorateMethod: DecorateMethod<ApiType>): AugmentedCall<ApiType>;
|
|
121
|
+
protected _decorateMulti<ApiType extends ApiTypes>(decorateMethod: DecorateMethod<ApiType>): QueryableStorageMulti<ApiType>;
|
|
122
|
+
protected _decorateMultiAt<ApiType extends ApiTypes>(atApi: ApiDecoration<ApiType>, decorateMethod: DecorateMethod<ApiType>, blockHash: Uint8Array | string): QueryableStorageMulti<ApiType>;
|
|
123
|
+
protected _decorateExtrinsics<ApiType extends ApiTypes>({ tx }: DecoratedMeta, decorateMethod: DecorateMethod<ApiType>): SubmittableExtrinsics<ApiType>;
|
|
124
|
+
private _decorateExtrinsicEntry;
|
|
125
|
+
protected _decorateStorage<ApiType extends ApiTypes>({ query, registry }: DecoratedMeta, decorateMethod: DecorateMethod<ApiType>, blockHash?: Uint8Array): QueryableStorage<ApiType>;
|
|
126
|
+
private _decorateStorageEntry;
|
|
127
|
+
private _decorateStorageEntryAt;
|
|
128
|
+
private _queueStorage;
|
|
129
|
+
private _decorateStorageCall;
|
|
130
|
+
private _retrieveMulti;
|
|
131
|
+
private _retrieveMapKeys;
|
|
132
|
+
private _retrieveMapKeysPaged;
|
|
133
|
+
private _retrieveMapEntries;
|
|
134
|
+
private _retrieveMapEntriesPaged;
|
|
135
|
+
protected _decorateDeriveRx(decorateMethod: DecorateMethod<ApiType>): AllDerives<'rxjs'>;
|
|
136
|
+
protected _decorateDerive(decorateMethod: DecorateMethod<ApiType>): AllDerives<ApiType>;
|
|
137
|
+
/**
|
|
138
|
+
* Put the `this.onCall` function of ApiRx here, because it is needed by
|
|
139
|
+
* `api._rx`.
|
|
140
|
+
*/
|
|
141
|
+
protected _rxDecorateMethod: <Method extends AnyFunction>(method: Method) => Method;
|
|
142
|
+
}
|
|
143
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { ApiInterfaceEvents } from '../types/index.js';
|
|
2
|
+
export declare class Events {
|
|
3
|
+
#private;
|
|
4
|
+
protected emit(type: ApiInterfaceEvents, ...args: unknown[]): boolean;
|
|
5
|
+
/**
|
|
6
|
+
* @description Attach an eventemitter handler to listen to a specific event
|
|
7
|
+
*
|
|
8
|
+
* @param type The type of event to listen to. Available events are `connected`, `disconnected`, `ready` and `error`
|
|
9
|
+
* @param handler The callback to be called when the event fires. Depending on the event type, it could fire with additional arguments.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* <BR>
|
|
13
|
+
*
|
|
14
|
+
* ```javascript
|
|
15
|
+
* api.on('connected', (): void => {
|
|
16
|
+
* console.log('API has been connected to the endpoint');
|
|
17
|
+
* });
|
|
18
|
+
*
|
|
19
|
+
* api.on('disconnected', (): void => {
|
|
20
|
+
* console.log('API has been disconnected from the endpoint');
|
|
21
|
+
* });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
on(type: ApiInterfaceEvents, handler: (...args: any[]) => any): this;
|
|
25
|
+
/**
|
|
26
|
+
* @description Remove the given eventemitter handler
|
|
27
|
+
*
|
|
28
|
+
* @param type The type of event the callback was attached to. Available events are `connected`, `disconnected`, `ready` and `error`
|
|
29
|
+
* @param handler The callback to unregister.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* <BR>
|
|
33
|
+
*
|
|
34
|
+
* ```javascript
|
|
35
|
+
* const handler = (): void => {
|
|
36
|
+
* console.log('Connected !);
|
|
37
|
+
* };
|
|
38
|
+
*
|
|
39
|
+
* // Start listening
|
|
40
|
+
* api.on('connected', handler);
|
|
41
|
+
*
|
|
42
|
+
* // Stop listening
|
|
43
|
+
* api.off('connected', handler);
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
46
|
+
off(type: ApiInterfaceEvents, handler: (...args: any[]) => any): this;
|
|
47
|
+
/**
|
|
48
|
+
* @description Attach an one-time eventemitter handler to listen to a specific event
|
|
49
|
+
*
|
|
50
|
+
* @param type The type of event to listen to. Available events are `connected`, `disconnected`, `ready` and `error`
|
|
51
|
+
* @param handler The callback to be called when the event fires. Depending on the event type, it could fire with additional arguments.
|
|
52
|
+
*
|
|
53
|
+
* @example
|
|
54
|
+
* <BR>
|
|
55
|
+
*
|
|
56
|
+
* ```javascript
|
|
57
|
+
* api.once('connected', (): void => {
|
|
58
|
+
* console.log('API has been connected to the endpoint');
|
|
59
|
+
* });
|
|
60
|
+
*
|
|
61
|
+
* api.once('disconnected', (): void => {
|
|
62
|
+
* console.log('API has been disconnected from the endpoint');
|
|
63
|
+
* });
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
once(type: ApiInterfaceEvents, handler: (...args: any[]) => any): this;
|
|
67
|
+
}
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import type { RpcCoreStats, RpcInterface } from '@pezkuwi/rpc-core/types';
|
|
2
|
+
import type { Text } from '@pezkuwi/types';
|
|
3
|
+
import type { Hash, RuntimeVersion } from '@pezkuwi/types/interfaces';
|
|
4
|
+
import type { Metadata } from '@pezkuwi/types/metadata';
|
|
5
|
+
import type { CallFunction, RegistryError } from '@pezkuwi/types/types';
|
|
6
|
+
import type { ApiDecoration, ApiInterfaceRx, ApiTypes, DecoratedErrors, DecoratedEvents, DecoratedRpc, QueryableCalls, QueryableConsts, QueryableStorage, QueryableStorageMulti, SubmittableExtrinsics } from '../types/index.js';
|
|
7
|
+
import { Init } from './Init.js';
|
|
8
|
+
export declare abstract class Getters<ApiType extends ApiTypes> extends Init<ApiType> implements ApiDecoration<ApiType> {
|
|
9
|
+
/**
|
|
10
|
+
* @description Runtime call interfaces (currently untyped, only decorated via API options)
|
|
11
|
+
*/
|
|
12
|
+
get call(): QueryableCalls<ApiType>;
|
|
13
|
+
/**
|
|
14
|
+
* @description Contains the parameter types (constants) of all modules.
|
|
15
|
+
*
|
|
16
|
+
* The values are instances of the appropriate type and are accessible using `section`.`constantName`,
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* <BR>
|
|
20
|
+
*
|
|
21
|
+
* ```javascript
|
|
22
|
+
* console.log(api.consts.democracy.enactmentPeriod.toString())
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
get consts(): QueryableConsts<ApiType>;
|
|
26
|
+
/**
|
|
27
|
+
* @description Derived results that are injected into the API, allowing for combinations of various query results.
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* <BR>
|
|
31
|
+
*
|
|
32
|
+
* ```javascript
|
|
33
|
+
* api.derive.chain.bestNumber((number) => {
|
|
34
|
+
* console.log('best number', number);
|
|
35
|
+
* });
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
get derive(): ReturnType<Getters<ApiType>['_decorateDerive']>;
|
|
39
|
+
/**
|
|
40
|
+
* @description Errors from metadata
|
|
41
|
+
*/
|
|
42
|
+
get errors(): DecoratedErrors<ApiType>;
|
|
43
|
+
/**
|
|
44
|
+
* @description Events from metadata
|
|
45
|
+
*/
|
|
46
|
+
get events(): DecoratedEvents<ApiType>;
|
|
47
|
+
/**
|
|
48
|
+
* @description Returns the version of extrinsics in-use on this chain
|
|
49
|
+
*/
|
|
50
|
+
get extrinsicVersion(): number;
|
|
51
|
+
/**
|
|
52
|
+
* @description Contains the genesis Hash of the attached chain. Apart from being useful to determine the actual chain, it can also be used to sign immortal transactions.
|
|
53
|
+
*/
|
|
54
|
+
get genesisHash(): Hash;
|
|
55
|
+
/**
|
|
56
|
+
* @description true is the underlying provider is connected
|
|
57
|
+
*/
|
|
58
|
+
get isConnected(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* @description The library information name & version (from package.json)
|
|
61
|
+
*/
|
|
62
|
+
get libraryInfo(): string;
|
|
63
|
+
/**
|
|
64
|
+
* @description Contains all the chain state modules and their subsequent methods in the API. These are attached dynamically from the runtime metadata.
|
|
65
|
+
*
|
|
66
|
+
* All calls inside the namespace, is denoted by `section`.`method` and may take an optional query parameter. As an example, `api.query.timestamp.now()` (current block timestamp) does not take parameters, while `api.query.system.account(<accountId>)` (retrieving the associated nonce & balances for an account), takes the `AccountId` as a parameter.
|
|
67
|
+
*
|
|
68
|
+
* @example
|
|
69
|
+
* <BR>
|
|
70
|
+
*
|
|
71
|
+
* ```javascript
|
|
72
|
+
* api.query.system.account(<accountId>, ([nonce, balance]) => {
|
|
73
|
+
* console.log('new free balance', balance.free, 'new nonce', nonce);
|
|
74
|
+
* });
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
get query(): QueryableStorage<ApiType>;
|
|
78
|
+
/**
|
|
79
|
+
* @description Allows for the querying of multiple storage entries and the combination thereof into a single result. This is a very optimal way to make multiple queries since it only makes a single connection to the node and retrieves the data over one subscription.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* <BR>
|
|
83
|
+
*
|
|
84
|
+
* ```javascript
|
|
85
|
+
* const unsub = await api.queryMulti(
|
|
86
|
+
* [
|
|
87
|
+
* // you can include the storage without any parameters
|
|
88
|
+
* api.query.balances.totalIssuance,
|
|
89
|
+
* // or you can pass parameters to the storage query
|
|
90
|
+
* [api.query.system.account, '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY']
|
|
91
|
+
* ],
|
|
92
|
+
* ([existential, [, { free }]]) => {
|
|
93
|
+
* console.log(`You have ${free.sub(existential)} more than the existential deposit`);
|
|
94
|
+
*
|
|
95
|
+
* unsub();
|
|
96
|
+
* }
|
|
97
|
+
* );
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
get queryMulti(): QueryableStorageMulti<ApiType>;
|
|
101
|
+
/**
|
|
102
|
+
* @description Contains all the raw rpc sections and their subsequent methods in the API as defined by the jsonrpc interface definitions. Unlike the dynamic `api.query` and `api.tx` sections, these methods are fixed (although extensible with node upgrades) and not determined by the runtime.
|
|
103
|
+
*
|
|
104
|
+
* RPC endpoints available here allow for the query of chain, node and system information, in addition to providing interfaces for the raw queries of state (using known keys) and the submission of transactions.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* <BR>
|
|
108
|
+
*
|
|
109
|
+
* ```javascript
|
|
110
|
+
* api.rpc.chain.subscribeNewHeads((header) => {
|
|
111
|
+
* console.log('new header', header);
|
|
112
|
+
* });
|
|
113
|
+
* ```
|
|
114
|
+
*/
|
|
115
|
+
get rpc(): DecoratedRpc<ApiType, RpcInterface>;
|
|
116
|
+
/**
|
|
117
|
+
* @description Contains the chain information for the current node.
|
|
118
|
+
*/
|
|
119
|
+
get runtimeChain(): Text;
|
|
120
|
+
/**
|
|
121
|
+
* @description Yields the current attached runtime metadata. Generally this is only used to construct extrinsics & storage, but is useful for current runtime inspection.
|
|
122
|
+
*/
|
|
123
|
+
get runtimeMetadata(): Metadata;
|
|
124
|
+
/**
|
|
125
|
+
* @description Contains the version information for the current runtime.
|
|
126
|
+
*/
|
|
127
|
+
get runtimeVersion(): RuntimeVersion;
|
|
128
|
+
/**
|
|
129
|
+
* @description The underlying Rx API interface
|
|
130
|
+
*/
|
|
131
|
+
get rx(): Pick<ApiInterfaceRx, 'tx' | 'rpc' | 'query' | 'call'>;
|
|
132
|
+
/**
|
|
133
|
+
* @description Returns the underlying provider stats
|
|
134
|
+
*/
|
|
135
|
+
get stats(): RpcCoreStats | undefined;
|
|
136
|
+
/**
|
|
137
|
+
* @description The type of this API instance, either 'rxjs' or 'promise'
|
|
138
|
+
*/
|
|
139
|
+
get type(): ApiTypes;
|
|
140
|
+
/**
|
|
141
|
+
* @description Contains all the extrinsic modules and their subsequent methods in the API. It allows for the construction of transactions and the submission thereof. These are attached dynamically from the runtime metadata.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* <BR>
|
|
145
|
+
*
|
|
146
|
+
* ```javascript
|
|
147
|
+
* api.tx.balances
|
|
148
|
+
* .transferAllowDeath(<recipientId>, <balance>)
|
|
149
|
+
* .signAndSend(<keyPair>, ({status}) => {
|
|
150
|
+
* console.log('tx status', status.asFinalized.toHex());
|
|
151
|
+
* });
|
|
152
|
+
* ```
|
|
153
|
+
*/
|
|
154
|
+
get tx(): SubmittableExtrinsics<ApiType>;
|
|
155
|
+
/**
|
|
156
|
+
* @description Finds the definition for a specific [[CallFunction]] based on the index supplied
|
|
157
|
+
*/
|
|
158
|
+
findCall(callIndex: Uint8Array | string): CallFunction;
|
|
159
|
+
/**
|
|
160
|
+
* @description Finds the definition for a specific [[RegistryError]] based on the index supplied
|
|
161
|
+
*/
|
|
162
|
+
findError(errorIndex: Uint8Array | string): RegistryError;
|
|
163
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { RuntimeVersion } from '@pezkuwi/types/interfaces';
|
|
2
|
+
import type { ApiDecoration, ApiOptions, ApiTypes, DecorateMethod } from '../types/index.js';
|
|
3
|
+
import type { VersionedRegistry } from './types.js';
|
|
4
|
+
import { Decorate } from './Decorate.js';
|
|
5
|
+
export declare abstract class Init<ApiType extends ApiTypes> extends Decorate<ApiType> {
|
|
6
|
+
#private;
|
|
7
|
+
constructor(options: ApiOptions, type: ApiTypes, decorateMethod: DecorateMethod<ApiType>);
|
|
8
|
+
/**
|
|
9
|
+
* @description Decorates a registry based on the runtime version
|
|
10
|
+
*/
|
|
11
|
+
private _initRegistry;
|
|
12
|
+
/**
|
|
13
|
+
* @description Returns the default versioned registry
|
|
14
|
+
*/
|
|
15
|
+
private _getDefaultRegistry;
|
|
16
|
+
/**
|
|
17
|
+
* @description Returns a decorated API instance at a specific point in time
|
|
18
|
+
*/
|
|
19
|
+
at(blockHash: Uint8Array | string, knownVersion?: RuntimeVersion): Promise<ApiDecoration<ApiType>>;
|
|
20
|
+
private _createBlockRegistry;
|
|
21
|
+
private _cacheBlockRegistryProgress;
|
|
22
|
+
private _getBlockRegistryViaVersion;
|
|
23
|
+
private _getBlockRegistryViaHash;
|
|
24
|
+
/**
|
|
25
|
+
* @description Sets up a registry based on the block hash defined
|
|
26
|
+
*/
|
|
27
|
+
getBlockRegistry(blockHash: Uint8Array, knownVersion?: RuntimeVersion): Promise<VersionedRegistry<ApiType>>;
|
|
28
|
+
protected _loadMeta(): Promise<boolean>;
|
|
29
|
+
private _metaFromSource;
|
|
30
|
+
private _subscribeUpdates;
|
|
31
|
+
private _metaFromChain;
|
|
32
|
+
private _initFromMeta;
|
|
33
|
+
/**
|
|
34
|
+
* @internal
|
|
35
|
+
*
|
|
36
|
+
* Tries to use runtime api calls to retrieve metadata. This ensures the api initializes with the latest metadata.
|
|
37
|
+
* If the runtime call is not there it will use the rpc method.
|
|
38
|
+
*/
|
|
39
|
+
private _retrieveMetadata;
|
|
40
|
+
private _subscribeHealth;
|
|
41
|
+
private _unsubscribeHealth;
|
|
42
|
+
private _unsubscribeUpdates;
|
|
43
|
+
protected _unsubscribe(): void;
|
|
44
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import type { CallFunction, Registry, RegistryError } from '@pezkuwi/types/types';
|
|
2
|
+
export declare function findCall(registry: Registry, callIndex: Uint8Array | string): CallFunction;
|
|
3
|
+
export declare function findError(registry: Registry, errorIndex: Uint8Array | string): RegistryError;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { SignerPayloadRawBase } from '@pezkuwi/types/types';
|
|
2
|
+
import type { ApiOptions, ApiTypes, DecorateMethod, Signer } from '../types/index.js';
|
|
3
|
+
import { Getters } from './Getters.js';
|
|
4
|
+
interface KeyringSigner {
|
|
5
|
+
sign(message: Uint8Array): Uint8Array;
|
|
6
|
+
}
|
|
7
|
+
interface SignerRawOptions {
|
|
8
|
+
signer?: Signer;
|
|
9
|
+
}
|
|
10
|
+
export declare abstract class ApiBase<ApiType extends ApiTypes> extends Getters<ApiType> {
|
|
11
|
+
/**
|
|
12
|
+
* @description Create an instance of the class
|
|
13
|
+
*
|
|
14
|
+
* @param options Options object to create API instance or a Provider instance
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* <BR>
|
|
18
|
+
*
|
|
19
|
+
* ```javascript
|
|
20
|
+
* import Api from '@pezkuwi/api/promise';
|
|
21
|
+
*
|
|
22
|
+
* const api = new Api().isReady();
|
|
23
|
+
*
|
|
24
|
+
* api.rpc.subscribeNewHeads((header) => {
|
|
25
|
+
* console.log(`new block #${header.number.toNumber()}`);
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
29
|
+
constructor(options: ApiOptions, type: ApiTypes, decorateMethod: DecorateMethod<ApiType>);
|
|
30
|
+
/**
|
|
31
|
+
* @description Connect from the underlying provider, halting all network traffic
|
|
32
|
+
*/
|
|
33
|
+
connect(): Promise<void>;
|
|
34
|
+
/**
|
|
35
|
+
* @description Disconnect from the underlying provider, halting all network traffic
|
|
36
|
+
*/
|
|
37
|
+
disconnect(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* @description Set an external signer which will be used to sign extrinsic when account passed in is not KeyringPair
|
|
40
|
+
*/
|
|
41
|
+
setSigner(signer: Signer | undefined): void;
|
|
42
|
+
/**
|
|
43
|
+
* @description Signs a raw signer payload, string or Uint8Array
|
|
44
|
+
*/
|
|
45
|
+
sign(address: KeyringSigner | string, data: SignerPayloadRawBase, { signer }?: SignerRawOptions): Promise<string>;
|
|
46
|
+
}
|
|
47
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Metadata } from '@pezkuwi/types';
|
|
2
|
+
import type { RuntimeVersionPartial } from '@pezkuwi/types/interfaces';
|
|
3
|
+
import type { DecoratedMeta } from '@pezkuwi/types/metadata/decorate/types';
|
|
4
|
+
import type { Registry } from '@pezkuwi/types/types';
|
|
5
|
+
import type { ApiDecoration, ApiTypes } from '../types/index.js';
|
|
6
|
+
export interface VersionedRegistry<ApiType extends ApiTypes> {
|
|
7
|
+
counter: number;
|
|
8
|
+
decoratedApi?: ApiDecoration<ApiType>;
|
|
9
|
+
decoratedMeta?: DecoratedMeta;
|
|
10
|
+
isDefault?: boolean;
|
|
11
|
+
lastBlockHash?: Uint8Array | null;
|
|
12
|
+
metadata: Metadata;
|
|
13
|
+
registry: Registry;
|
|
14
|
+
runtimeVersion: RuntimeVersionPartial;
|
|
15
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import '@pezkuwi/rpc-augment';
|
|
2
|
+
export { Keyring } from '@pezkuwi/keyring';
|
|
3
|
+
export { HttpProvider, ScProvider, WsProvider } from '@pezkuwi/rpc-provider';
|
|
4
|
+
export { packageInfo } from './packageInfo.js';
|
|
5
|
+
export { SubmittableResult } from './submittable/index.js';
|
|
6
|
+
export * from './promise/index.js';
|
|
7
|
+
export * from './rx/index.js';
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|