UNPKG

6.51 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.Getters = void 0;
7
8var _util = require("@polkadot/util");
9
10var _packageInfo = require("../packageInfo");
11
12var _find = require("./find");
13
14var _Init = require("./Init");
15
16// Copyright 2017-2022 @polkadot/api authors & contributors
17// SPDX-License-Identifier: Apache-2.0
18function assertResult(value) {
19 return (0, _util.assertReturn)(value, 'Api needs to be initialized before using, listen on \'ready\'');
20}
21
22class Getters extends _Init.Init {
23 /**
24 * @description Contains the parameter types (constants) of all modules.
25 *
26 * The values are instances of the appropriate type and are accessible using `section`.`constantName`,
27 *
28 * @example
29 * <BR>
30 *
31 * ```javascript
32 * console.log(api.consts.democracy.enactmentPeriod.toString())
33 * ```
34 */
35 get consts() {
36 return assertResult(this._consts);
37 }
38 /**
39 * @description Derived results that are injected into the API, allowing for combinations of various query results.
40 *
41 * @example
42 * <BR>
43 *
44 * ```javascript
45 * api.derive.chain.bestNumber((number) => {
46 * console.log('best number', number);
47 * });
48 * ```
49 */
50
51
52 get derive() {
53 return assertResult(this._derive);
54 }
55 /**
56 * @description Errors from metadata
57 */
58
59
60 get errors() {
61 return assertResult(this._errors);
62 }
63 /**
64 * @description Events from metadata
65 */
66
67
68 get events() {
69 return assertResult(this._events);
70 }
71 /**
72 * @description Returns the version of extrinsics in-use on this chain
73 */
74
75
76 get extrinsicVersion() {
77 return this._extrinsicType;
78 }
79 /**
80 * @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.
81 */
82
83
84 get genesisHash() {
85 return assertResult(this._genesisHash);
86 }
87 /**
88 * @description true is the underlying provider is connected
89 */
90
91
92 get isConnected() {
93 return this._isConnected.getValue();
94 }
95 /**
96 * @description The library information name & version (from package.json)
97 */
98
99
100 get libraryInfo() {
101 return `${_packageInfo.packageInfo.name} v${_packageInfo.packageInfo.version}`;
102 }
103 /**
104 * @description Contains all the chain state modules and their subsequent methods in the API. These are attached dynamically from the runtime metadata.
105 *
106 * 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.
107 *
108 * @example
109 * <BR>
110 *
111 * ```javascript
112 * api.query.system.account(<accountId>, ([nonce, balance]) => {
113 * console.log('new free balance', balance.free, 'new nonce', nonce);
114 * });
115 * ```
116 */
117
118
119 get query() {
120 return assertResult(this._query);
121 }
122 /**
123 * @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.
124 *
125 * @example
126 * <BR>
127 *
128 * ```javascript
129 * const unsub = await api.queryMulti(
130 * [
131 * // you can include the storage without any parameters
132 * api.query.balances.totalIssuance,
133 * // or you can pass parameters to the storage query
134 * [api.query.system.account, '5GrwvaEF5zXb26Fz9rcQpDWS57CtERHpNehXCPcNoHGKutQY']
135 * ],
136 * ([existential, [, { free }]]) => {
137 * console.log(`You have ${free.sub(existential)} more than the existential deposit`);
138 *
139 * unsub();
140 * }
141 * );
142 * ```
143 */
144
145
146 get queryMulti() {
147 return assertResult(this._queryMulti);
148 }
149 /**
150 * @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.
151 *
152 * 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.
153 *
154 * @example
155 * <BR>
156 *
157 * ```javascript
158 * api.rpc.chain.subscribeNewHeads((header) => {
159 * console.log('new header', header);
160 * });
161 * ```
162 */
163
164
165 get rpc() {
166 return assertResult(this._rpc);
167 }
168 /**
169 * @description Contains the chain information for the current node.
170 */
171
172
173 get runtimeChain() {
174 return assertResult(this._runtimeChain);
175 }
176 /**
177 * @description Yields the current attached runtime metadata. Generally this is only used to construct extrinsics & storage, but is useful for current runtime inspection.
178 */
179
180
181 get runtimeMetadata() {
182 return assertResult(this._runtimeMetadata);
183 }
184 /**
185 * @description Contains the version information for the current runtime.
186 */
187
188
189 get runtimeVersion() {
190 return assertResult(this._runtimeVersion);
191 }
192 /**
193 * @description The underlying Rx API interface
194 */
195
196
197 get rx() {
198 return assertResult(this._rx);
199 }
200 /**
201 * @description The type of this API instance, either 'rxjs' or 'promise'
202 */
203
204
205 get type() {
206 return this._type;
207 }
208 /**
209 * @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.
210 *
211 * @example
212 * <BR>
213 *
214 * ```javascript
215 * api.tx.balances
216 * .transfer(<recipientId>, <balance>)
217 * .signAndSend(<keyPair>, ({status}) => {
218 * console.log('tx status', status.asFinalized.toHex());
219 * });
220 * ```
221 */
222
223
224 get tx() {
225 return assertResult(this._extrinsics);
226 }
227 /**
228 * @description Finds the definition for a specific [[CallFunction]] based on the index supplied
229 */
230
231
232 findCall(callIndex) {
233 return (0, _find.findCall)(this.registry, callIndex);
234 }
235 /**
236 * @description Finds the definition for a specific [[RegistryError]] based on the index supplied
237 */
238
239
240 findError(errorIndex) {
241 return (0, _find.findError)(this.registry, errorIndex);
242 }
243
244}
245
246exports.Getters = Getters;
\No newline at end of file