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