@tezos-x/octez.js-rpc 0.9.0

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.
@@ -0,0 +1,1085 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
17
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
18
+ return new (P || (P = Promise))(function (resolve, reject) {
19
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
20
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
21
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
22
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
23
+ });
24
+ };
25
+ var __rest = (this && this.__rest) || function (s, e) {
26
+ var t = {};
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
+ t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
+ t[p[i]] = s[p[i]];
33
+ }
34
+ return t;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ exports.RpcClient = exports.VERSION = exports.OpKind = exports.RpcClientCache = exports.defaultRPCOptions = exports.defaultChain = exports.castToBigNumber = void 0;
38
+ /**
39
+ * @packageDocumentation
40
+ * @module @tezos-x/octez.js-rpc
41
+ */
42
+ const octez_js_http_utils_1 = require("@tezos-x/octez.js-http-utils");
43
+ const bignumber_js_1 = require("bignumber.js");
44
+ const rpc_client_interface_1 = require("./rpc-client-interface");
45
+ const utils_1 = require("./utils/utils");
46
+ const octez_js_utils_1 = require("@tezos-x/octez.js-utils");
47
+ const octez_js_core_1 = require("@tezos-x/octez.js-core");
48
+ var utils_2 = require("./utils/utils");
49
+ Object.defineProperty(exports, "castToBigNumber", { enumerable: true, get: function () { return utils_2.castToBigNumber; } });
50
+ var rpc_client_interface_2 = require("./rpc-client-interface");
51
+ Object.defineProperty(exports, "defaultChain", { enumerable: true, get: function () { return rpc_client_interface_2.defaultChain; } });
52
+ Object.defineProperty(exports, "defaultRPCOptions", { enumerable: true, get: function () { return rpc_client_interface_2.defaultRPCOptions; } });
53
+ var rpc_cache_1 = require("./rpc-client-modules/rpc-cache");
54
+ Object.defineProperty(exports, "RpcClientCache", { enumerable: true, get: function () { return rpc_cache_1.RpcClientCache; } });
55
+ __exportStar(require("./types"), exports);
56
+ var opkind_1 = require("./opkind");
57
+ Object.defineProperty(exports, "OpKind", { enumerable: true, get: function () { return opkind_1.OpKind; } });
58
+ var version_1 = require("./version");
59
+ Object.defineProperty(exports, "VERSION", { enumerable: true, get: function () { return version_1.VERSION; } });
60
+ /***
61
+ * @description RpcClient allows interaction with Tezos network through an rpc node
62
+ */
63
+ class RpcClient {
64
+ /**
65
+ *
66
+ * @param url rpc root url
67
+ * @param chain chain (default main)
68
+ * @param httpBackend Http backend that issue http request.
69
+ * You can override it by providing your own if you which to hook in the request/response
70
+ *
71
+ * @example new RpcClient('https://rpc.tzbeta.net/', 'main') this will use https://rpc.tzbeta.net//chains/main
72
+ */
73
+ constructor(url, chain = rpc_client_interface_1.defaultChain, httpBackend = new octez_js_http_utils_1.HttpBackend()) {
74
+ this.url = url;
75
+ this.chain = chain;
76
+ this.httpBackend = httpBackend;
77
+ }
78
+ createURL(path) {
79
+ // Trim trailing slashes because it is assumed to be included in path
80
+ // the regex solution is prone to ReDoS. Please see: https://stackoverflow.com/questions/6680825/return-string-without-trailing-slash#comment124306698_6680877
81
+ // We also got a CodeQL error for the regex based solution
82
+ let rootUrl = this.url;
83
+ while (rootUrl.endsWith('/')) {
84
+ rootUrl = rootUrl.slice(0, -1);
85
+ }
86
+ return `${rootUrl}${path}`;
87
+ }
88
+ validateAddress(address) {
89
+ const addressValidation = (0, octez_js_utils_1.validateAddress)(address);
90
+ if (addressValidation !== octez_js_utils_1.ValidationResult.VALID) {
91
+ throw new octez_js_core_1.InvalidAddressError(address, addressValidation);
92
+ }
93
+ }
94
+ validateContract(address) {
95
+ const addressValidation = (0, octez_js_utils_1.validateContractAddress)(address);
96
+ if (addressValidation !== octez_js_utils_1.ValidationResult.VALID) {
97
+ throw new octez_js_core_1.InvalidContractAddressError(address, addressValidation);
98
+ }
99
+ }
100
+ /**
101
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
102
+ * @description Get the block's hash, its unique identifier.
103
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-hash
104
+ */
105
+ getBlockHash() {
106
+ return __awaiter(this, arguments, void 0, function* ({ block } = rpc_client_interface_1.defaultRPCOptions) {
107
+ const hash = yield this.httpBackend.createRequest({
108
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/hash`),
109
+ method: 'GET',
110
+ });
111
+ return hash;
112
+ });
113
+ }
114
+ /**
115
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
116
+ * @description List the ancestors of the given block which, if referred to as the branch in an operation header, are recent enough for that operation to be included in the current block.
117
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-live-blocks
118
+ */
119
+ getLiveBlocks() {
120
+ return __awaiter(this, arguments, void 0, function* ({ block } = rpc_client_interface_1.defaultRPCOptions) {
121
+ const blocks = yield this.httpBackend.createRequest({
122
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/live_blocks`),
123
+ method: 'GET',
124
+ });
125
+ return blocks;
126
+ });
127
+ }
128
+ /**
129
+ * @param address address from which we want to retrieve the spendable balance
130
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
131
+ * @description The spendable balance of a contract (in mutez), also known as liquid balance. Corresponds to tez owned by the contract that are neither staked, nor in unstaked requests, nor in frozen bonds. Identical to the 'spendable' RPC.
132
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id-balance
133
+ */
134
+ getBalance(address_1) {
135
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
136
+ this.validateAddress(address);
137
+ const balance = yield this.httpBackend.createRequest({
138
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}/balance`),
139
+ method: 'GET',
140
+ });
141
+ return new bignumber_js_1.default(balance);
142
+ });
143
+ }
144
+ /**
145
+ * @param address address from which we want to retrieve the spendable balance
146
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
147
+ * @description The spendable balance of a contract (in mutez), also known as liquid balance. Corresponds to tez owned by the contract that are neither staked, nor in unstaked requests, nor in frozen bonds. Identical to the 'balance' RPC.
148
+ */
149
+ getSpendable(address_1) {
150
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
151
+ this.validateAddress(address);
152
+ const balance = yield this.httpBackend.createRequest({
153
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}/spendable`),
154
+ method: 'GET',
155
+ });
156
+ return new bignumber_js_1.default(balance);
157
+ });
158
+ }
159
+ /**
160
+ * @param address address from which we want to retrieve balance and frozen bonds
161
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
162
+ * @description The sum (in mutez) of the spendable balance and frozen bonds of a contract. Corresponds to the contract's full balance from which staked funds and unstake requests have been excluded. Identical to the 'spendable_and_frozen_bonds' RPC.
163
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id-full-balance
164
+ */
165
+ getBalanceAndFrozenBonds(address_1) {
166
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
167
+ this.validateAddress(address);
168
+ const balance = yield this.httpBackend.createRequest({
169
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}/balance_and_frozen_bonds`),
170
+ method: 'GET',
171
+ });
172
+ return new bignumber_js_1.default(balance);
173
+ });
174
+ }
175
+ /**
176
+ * @param address address from which we want to retrieve spendable and frozen bonds
177
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
178
+ * @description The sum (in mutez) of the spendable balance and frozen bonds of a contract. Corresponds to the contract's full balance from which staked funds and unstake requests have been excluded. Identical to the 'balance_and_frozen_bonds' RPC.
179
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id-full-balance
180
+ */
181
+ getSpendableAndFrozenBonds(address_1) {
182
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
183
+ this.validateAddress(address);
184
+ const balance = yield this.httpBackend.createRequest({
185
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}/spendable_and_frozen_bonds`),
186
+ method: 'GET',
187
+ });
188
+ return new bignumber_js_1.default(balance);
189
+ });
190
+ }
191
+ /**
192
+ * @param address address from which we want to retrieve the full balance
193
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
194
+ * @description Access the full balance of a contract, including frozen bonds and stake.
195
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id-full-balance
196
+ */
197
+ getFullBalance(address_1) {
198
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
199
+ this.validateAddress(address);
200
+ const balance = yield this.httpBackend.createRequest({
201
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}/full_balance`),
202
+ method: 'GET',
203
+ });
204
+ return new bignumber_js_1.default(balance);
205
+ });
206
+ }
207
+ /**
208
+ * @param address address from which we want to retrieve the staked balance
209
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
210
+ * @description Access the staked balance of a contract. Returns None if the contract is originated, or neither delegated nor a delegate.
211
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id-staked-balance
212
+ */
213
+ getStakedBalance(address_1) {
214
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
215
+ this.validateAddress(address);
216
+ const balance = yield this.httpBackend.createRequest({
217
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}/staked_balance`),
218
+ method: 'GET',
219
+ });
220
+ return new bignumber_js_1.default(balance);
221
+ });
222
+ }
223
+ /**
224
+ * @param address address from which we want to retrieve the unstaked finalizable balance
225
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
226
+ * @description Access the balance of a contract that was requested for an unstake operation, and is no longer frozen, which means it will appear in the spendable balance of the contract after any stake/unstake/finalize_unstake operation. Returns None if the contract is originated.
227
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id-unstaked-finalizable-balance
228
+ */
229
+ getUnstakedFinalizableBalance(address_1) {
230
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
231
+ this.validateAddress(address);
232
+ const balance = yield this.httpBackend.createRequest({
233
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}/unstaked_finalizable_balance`),
234
+ method: 'GET',
235
+ });
236
+ return new bignumber_js_1.default(balance);
237
+ });
238
+ }
239
+ /**
240
+ * @param address address from which we want to retrieve the unstaked frozen balance
241
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
242
+ * @description Access the balance of a contract that was requested for an unstake operation, but is still frozen for the duration of the slashing period. Returns None if the contract is originated.
243
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id-unstaked-frozen-balance
244
+ */
245
+ getUnstakedFrozenBalance(address_1) {
246
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
247
+ this.validateAddress(address);
248
+ const balance = yield this.httpBackend.createRequest({
249
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}/unstaked_frozen_balance`),
250
+ method: 'GET',
251
+ });
252
+ return new bignumber_js_1.default(balance);
253
+ });
254
+ }
255
+ /**
256
+ * @param address address from which we want to retrieve the unstaked requests
257
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
258
+ * @description Access the unstake requests of the contract. The requests that appear in the finalizable field can be finalized, which means that the contract can transfer these (no longer frozen) funds to their spendable balance with a [finalize_unstake] operation call. Returns null if there is no unstake request pending.
259
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id-unstake-requests
260
+ */
261
+ getUnstakeRequests(address_1) {
262
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
263
+ this.validateAddress(address);
264
+ const response = yield this.httpBackend.createRequest({
265
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}/unstake_requests`),
266
+ method: 'GET',
267
+ });
268
+ return response === null
269
+ ? null
270
+ : {
271
+ finalizable: response.finalizable.map((_a) => {
272
+ var { amount } = _a, rest = __rest(_a, ["amount"]);
273
+ const castedToBigNumber = (0, utils_1.castToBigNumber)({ amount }, ['amount']);
274
+ return Object.assign(Object.assign({}, rest), { amount: castedToBigNumber.amount });
275
+ }),
276
+ unfinalizable: {
277
+ delegate: response.unfinalizable.delegate,
278
+ requests: response.unfinalizable.requests.map(({ amount, cycle }) => {
279
+ const castedToBigNumber = (0, utils_1.castToBigNumber)({ amount }, ['amount']);
280
+ return {
281
+ cycle,
282
+ amount: castedToBigNumber.amount,
283
+ };
284
+ }),
285
+ },
286
+ };
287
+ });
288
+ }
289
+ /**
290
+ * @param address contract address from which we want to retrieve the storage
291
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
292
+ * @description Access the data of the contract.
293
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id-storage
294
+ */
295
+ getStorage(address_1) {
296
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
297
+ this.validateContract(address);
298
+ return this.httpBackend.createRequest({
299
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}/storage`),
300
+ method: 'GET',
301
+ });
302
+ });
303
+ }
304
+ /**
305
+ * @param address contract address from which we want to retrieve the script
306
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
307
+ * @description Access the code and data of the contract.
308
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id-script
309
+ */
310
+ getScript(address_1) {
311
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
312
+ this.validateContract(address);
313
+ return this.httpBackend.createRequest({
314
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}/script`),
315
+ method: 'GET',
316
+ });
317
+ });
318
+ }
319
+ /**
320
+ * @param address contract address from which we want to retrieve the script
321
+ * @param unparsingMode default is { unparsing_mode: "Readable" }
322
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
323
+ * @description Access the script of the contract and normalize it using the requested unparsing mode.
324
+ */
325
+ getNormalizedScript(address_1) {
326
+ return __awaiter(this, arguments, void 0, function* (address, unparsingMode = { unparsing_mode: 'Readable' }, { block } = rpc_client_interface_1.defaultRPCOptions) {
327
+ this.validateContract(address);
328
+ return this.httpBackend.createRequest({
329
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}/script/normalized`),
330
+ method: 'POST',
331
+ }, unparsingMode);
332
+ });
333
+ }
334
+ /**
335
+ * @param address contract address from which we want to retrieve
336
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
337
+ * @description Access the complete status of a contract.
338
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id
339
+ */
340
+ getContract(address_1) {
341
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
342
+ this.validateAddress(address);
343
+ const contractResponse = yield this.httpBackend.createRequest({
344
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}`),
345
+ method: 'GET',
346
+ });
347
+ return Object.assign(Object.assign({}, contractResponse), { balance: new bignumber_js_1.default(contractResponse.balance) });
348
+ });
349
+ }
350
+ /**
351
+ * @param address contract address from which we want to retrieve the manager
352
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
353
+ * @description Access the manager of an implicit contract
354
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id-manager-key
355
+ */
356
+ getManagerKey(address_1) {
357
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
358
+ this.validateAddress(address);
359
+ return this.httpBackend.createRequest({
360
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}/manager_key`),
361
+ method: 'GET',
362
+ });
363
+ });
364
+ }
365
+ /**
366
+ * @param address contract address from which we want to retrieve the delegate (baker)
367
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
368
+ * @description Access the delegate of a contract, if any
369
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id-delegate
370
+ */
371
+ getDelegate(address_1) {
372
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
373
+ this.validateAddress(address);
374
+ let delegate;
375
+ try {
376
+ delegate = yield this.httpBackend.createRequest({
377
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${address}/delegate`),
378
+ method: 'GET',
379
+ });
380
+ }
381
+ catch (ex) {
382
+ if (ex instanceof octez_js_http_utils_1.HttpResponseError && ex.status === octez_js_http_utils_1.STATUS_CODE.NOT_FOUND) {
383
+ delegate = null;
384
+ }
385
+ else {
386
+ throw ex;
387
+ }
388
+ }
389
+ return delegate;
390
+ });
391
+ }
392
+ /**
393
+ * @param id Big Map ID
394
+ * @param expr Expression hash to query (A b58check encoded Blake2b hash of the expression (The expression can be packed using the pack_data method))
395
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
396
+ * @description Access the value associated with a key in a big map.
397
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-big-maps-big-map-id-script-expr
398
+ */
399
+ getBigMapExpr(id_1, expr_1) {
400
+ return __awaiter(this, arguments, void 0, function* (id, expr, { block } = rpc_client_interface_1.defaultRPCOptions) {
401
+ return this.httpBackend.createRequest({
402
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/big_maps/${id}/${expr}`),
403
+ method: 'GET',
404
+ });
405
+ });
406
+ }
407
+ /**
408
+ * @param args contains optional query arguments (active, inactive, with_minimal_stake, without_minimal_stake)
409
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
410
+ * @description Lists all registered delegates by default with query arguments to filter unneeded values.
411
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-delegates-pkh
412
+ */
413
+ getAllDelegates() {
414
+ return __awaiter(this, arguments, void 0, function* (args = {}, { block } = rpc_client_interface_1.defaultRPCOptions) {
415
+ return yield this.httpBackend.createRequest({
416
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/delegates`),
417
+ method: 'GET',
418
+ query: args,
419
+ });
420
+ });
421
+ }
422
+ /**
423
+ * @param address delegate address which we want to retrieve
424
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
425
+ * @description Everything about a delegate
426
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-delegates-pkh
427
+ */
428
+ getDelegates(address_1) {
429
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
430
+ this.validateAddress(address);
431
+ const response = yield this.httpBackend.createRequest({
432
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/delegates/${address}`),
433
+ method: 'GET',
434
+ });
435
+ const castedResponse = (0, utils_1.castToBigNumber)(response, [
436
+ 'balance',
437
+ 'full_balance',
438
+ 'current_frozen_deposits',
439
+ 'frozen_deposits',
440
+ 'frozen_balance',
441
+ 'frozen_deposits_limit',
442
+ 'staking_balance',
443
+ 'delegated_balance',
444
+ 'voting_power',
445
+ 'total_delegated_stake',
446
+ 'staking_denominator',
447
+ ]);
448
+ if (response.frozen_balance_by_cycle) {
449
+ return Object.assign(Object.assign(Object.assign({}, response), castedResponse), { frozen_balance_by_cycle: response.frozen_balance_by_cycle.map((_a) => {
450
+ var { deposit, deposits, fees, rewards } = _a, rest = __rest(_a, ["deposit", "deposits", "fees", "rewards"]);
451
+ const castedToBigNumber = (0, utils_1.castToBigNumber)({ deposit, deposits, fees, rewards }, [
452
+ 'deposit',
453
+ 'deposits',
454
+ 'fees',
455
+ 'rewards',
456
+ ]);
457
+ return Object.assign(Object.assign({}, rest), { deposit: castedToBigNumber.deposit, deposits: castedToBigNumber.deposits, fees: castedToBigNumber.fees, rewards: castedToBigNumber.rewards });
458
+ }) });
459
+ }
460
+ else {
461
+ return Object.assign(Object.assign({}, response), castedResponse);
462
+ }
463
+ });
464
+ }
465
+ /**
466
+ * @param address delegate address which we want to retrieve
467
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
468
+ * @description Returns the delegate info (e.g. voting power) found in the listings of the current voting period
469
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-delegates-pkh-voting-info
470
+ */
471
+ getVotingInfo(address_1) {
472
+ return __awaiter(this, arguments, void 0, function* (address, { block } = rpc_client_interface_1.defaultRPCOptions) {
473
+ this.validateAddress(address);
474
+ return yield this.httpBackend.createRequest({
475
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/delegates/${address}/voting_info`),
476
+ method: 'GET',
477
+ });
478
+ });
479
+ }
480
+ /**
481
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
482
+ * @description All constants
483
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-constants
484
+ */
485
+ getConstants() {
486
+ return __awaiter(this, arguments, void 0, function* ({ block } = rpc_client_interface_1.defaultRPCOptions) {
487
+ const response = yield this.httpBackend.createRequest({
488
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/constants`),
489
+ method: 'GET',
490
+ });
491
+ const castedResponse = (0, utils_1.castToBigNumber)(response, [
492
+ 'time_between_blocks',
493
+ 'hard_gas_limit_per_operation',
494
+ 'hard_gas_limit_per_block',
495
+ 'proof_of_work_threshold',
496
+ 'tokens_per_roll',
497
+ 'seed_nonce_revelation_tip',
498
+ 'block_security_deposit',
499
+ 'endorsement_security_deposit',
500
+ 'block_reward',
501
+ 'endorsement_reward',
502
+ 'cost_per_byte',
503
+ 'hard_storage_limit_per_operation',
504
+ 'test_chain_duration',
505
+ 'baking_reward_per_endorsement',
506
+ 'delay_per_missing_endorsement',
507
+ 'minimal_block_delay',
508
+ 'liquidity_baking_subsidy',
509
+ 'cache_layout',
510
+ 'baking_reward_fixed_portion',
511
+ 'baking_reward_bonus_per_slot',
512
+ 'endorsing_reward_per_slot',
513
+ 'double_baking_punishment',
514
+ 'delay_increment_per_round',
515
+ 'tx_rollup_commitment_bond',
516
+ 'vdf_difficulty',
517
+ 'sc_rollup_stake_amount',
518
+ 'minimal_stake',
519
+ ]);
520
+ return Object.assign(Object.assign({}, response), castedResponse);
521
+ });
522
+ }
523
+ /**
524
+ * @param options contains generic configuration for rpc calls to specified block (default to head) and version.
525
+ * @description All the information about a block
526
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id
527
+ * @example getBlock() will default to `/main/chains/block/head?version=1`
528
+ * @example getBlock({ block: 'head~2' }) will return an offset of 2 from head blocks
529
+ * @example getBlock({ block: 'BL8fTiWcSxWCjiMVnDkbh6EuhqVPZzgWheJ2dqwrxYRm9AephXh~2' }) will return an offset of 2 blocks from given block hash..
530
+ */
531
+ getBlock() {
532
+ return __awaiter(this, arguments, void 0, function* ({ block, version } = rpc_client_interface_1.defaultRPCOptions) {
533
+ const requestOptions = {
534
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}`),
535
+ method: 'GET',
536
+ };
537
+ if (version !== undefined) {
538
+ requestOptions.query = { version };
539
+ }
540
+ return yield this.httpBackend.createRequest(requestOptions);
541
+ });
542
+ }
543
+ /**
544
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
545
+ * @description The whole block header
546
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-header
547
+ */
548
+ getBlockHeader() {
549
+ return __awaiter(this, arguments, void 0, function* ({ block } = rpc_client_interface_1.defaultRPCOptions) {
550
+ const response = yield this.httpBackend.createRequest({
551
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/header`),
552
+ method: 'GET',
553
+ });
554
+ return response;
555
+ });
556
+ }
557
+ /**
558
+ * @param options contains generic configuration for rpc calls to specified block (default to head) and version
559
+ * @description All the metadata associated to the block
560
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-metadata
561
+ */
562
+ getBlockMetadata() {
563
+ return __awaiter(this, arguments, void 0, function* ({ block, version, } = rpc_client_interface_1.defaultRPCOptions) {
564
+ const requestOptions = {
565
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/metadata`),
566
+ method: 'GET',
567
+ };
568
+ if (version !== undefined) {
569
+ requestOptions.query = { version };
570
+ }
571
+ return yield this.httpBackend.createRequest(requestOptions);
572
+ });
573
+ }
574
+ /**
575
+ * @param args contains optional query arguments (level, cycle, delegate, consensus_key, and max_round)
576
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
577
+ * @description Retrieves the list of delegates allowed to bake a block.
578
+ * @see https://gitlab.com/tezos/tezos/-/blob/master/docs/api/alpha-openapi.json
579
+ */
580
+ getBakingRights() {
581
+ return __awaiter(this, arguments, void 0, function* (args = {}, { block } = rpc_client_interface_1.defaultRPCOptions) {
582
+ const response = yield this.httpBackend.createRequest({
583
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/helpers/baking_rights`),
584
+ method: 'GET',
585
+ query: args,
586
+ });
587
+ return response;
588
+ });
589
+ }
590
+ /**
591
+ * @param args contains optional query arguments (level, cycle, delegate, and consensus_key)
592
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
593
+ * @description Retrieves the delegates allowed to attest a block
594
+ * @see https://gitlab.com/tezos/tezos/-/blob/master/docs/api/alpha-openapi.json
595
+ */
596
+ getAttestationRights() {
597
+ return __awaiter(this, arguments, void 0, function* (args = {}, { block } = rpc_client_interface_1.defaultRPCOptions) {
598
+ const response = yield this.httpBackend.createRequest({
599
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/helpers/attestation_rights`),
600
+ method: 'GET',
601
+ query: args,
602
+ });
603
+ return response;
604
+ });
605
+ }
606
+ /**
607
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
608
+ * @description Ballots casted so far during a voting period
609
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-votes-ballot-list
610
+ */
611
+ getBallotList() {
612
+ return __awaiter(this, arguments, void 0, function* ({ block } = rpc_client_interface_1.defaultRPCOptions) {
613
+ const response = yield this.httpBackend.createRequest({
614
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/votes/ballot_list`),
615
+ method: 'GET',
616
+ });
617
+ return response;
618
+ });
619
+ }
620
+ /**
621
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
622
+ * @description Sum of ballots casted so far during a voting period
623
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-votes-ballots
624
+ */
625
+ getBallots() {
626
+ return __awaiter(this, arguments, void 0, function* ({ block } = rpc_client_interface_1.defaultRPCOptions) {
627
+ const response = yield this.httpBackend.createRequest({
628
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/votes/ballots`),
629
+ method: 'GET',
630
+ });
631
+ const casted = (0, utils_1.castToBigNumber)(response, ['yay', 'nay', 'pass']);
632
+ return casted;
633
+ });
634
+ }
635
+ /**
636
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
637
+ * @description Current proposal under evaluation.
638
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-votes-current-proposal
639
+ */
640
+ getCurrentProposal() {
641
+ return __awaiter(this, arguments, void 0, function* ({ block, } = rpc_client_interface_1.defaultRPCOptions) {
642
+ const response = yield this.httpBackend.createRequest({
643
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/votes/current_proposal`),
644
+ method: 'GET',
645
+ });
646
+ return response;
647
+ });
648
+ }
649
+ /**
650
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
651
+ * @description Current expected quorum.
652
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-votes-current-quorum
653
+ */
654
+ getCurrentQuorum() {
655
+ return __awaiter(this, arguments, void 0, function* ({ block, } = rpc_client_interface_1.defaultRPCOptions) {
656
+ const response = yield this.httpBackend.createRequest({
657
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/votes/current_quorum`),
658
+ method: 'GET',
659
+ });
660
+ return response;
661
+ });
662
+ }
663
+ /**
664
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
665
+ * @description List of delegates with their voting power
666
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-votes-listings
667
+ */
668
+ getVotesListings() {
669
+ return __awaiter(this, arguments, void 0, function* ({ block, } = rpc_client_interface_1.defaultRPCOptions) {
670
+ const response = yield this.httpBackend.createRequest({
671
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/votes/listings`),
672
+ method: 'GET',
673
+ });
674
+ response.map((item) => {
675
+ if (item.voting_power) {
676
+ item.voting_power = new bignumber_js_1.default(item.voting_power);
677
+ }
678
+ return item;
679
+ });
680
+ return response;
681
+ });
682
+ }
683
+ /**
684
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
685
+ * @description List of proposals with number of supporters
686
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-votes-proposals
687
+ */
688
+ getProposals() {
689
+ return __awaiter(this, arguments, void 0, function* ({ block } = rpc_client_interface_1.defaultRPCOptions) {
690
+ const response = yield this.httpBackend.createRequest({
691
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/votes/proposals`),
692
+ method: 'GET',
693
+ });
694
+ response.map((item) => {
695
+ return (item[1] = new bignumber_js_1.default(item[1]));
696
+ });
697
+ return response;
698
+ });
699
+ }
700
+ /**
701
+ * @param data operation contents to forge
702
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
703
+ * @description Forge an operation returning the unsigned bytes
704
+ * @see https://gitlab.com/tezos/tezos/-/blob/master/docs/api/alpha-openapi.json
705
+ */
706
+ forgeOperations(data_1) {
707
+ return __awaiter(this, arguments, void 0, function* (data, { block } = rpc_client_interface_1.defaultRPCOptions) {
708
+ return this.httpBackend.createRequest({
709
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/helpers/forge/operations`),
710
+ method: 'POST',
711
+ }, data);
712
+ });
713
+ }
714
+ /**
715
+ * @param signedOpBytes signed bytes to inject
716
+ * @description Inject an operation in node and broadcast it and return the ID of the operation
717
+ * @see https://tezos.gitlab.io/shell/rpc.html#post-injection-operation
718
+ */
719
+ injectOperation(signedOpBytes) {
720
+ return __awaiter(this, void 0, void 0, function* () {
721
+ return this.httpBackend.createRequest({
722
+ url: this.createURL(`/injection/operation`),
723
+ method: 'POST',
724
+ }, signedOpBytes);
725
+ });
726
+ }
727
+ /**
728
+ * @param ops Operations to apply
729
+ * @param options contains generic configuration for rpc calls to specified block and version
730
+ * @description Simulate the application of the operations with the context of the given block and return the result of each operation application
731
+ * @see https://tezos.gitlab.io/active/rpc.html#post-block-id-helpers-preapply-operations
732
+ */
733
+ preapplyOperations(ops_1) {
734
+ return __awaiter(this, arguments, void 0, function* (ops, { block, version } = rpc_client_interface_1.defaultRPCOptions) {
735
+ const requestOptions = {
736
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/helpers/preapply/operations`),
737
+ method: 'POST',
738
+ };
739
+ if (version !== undefined) {
740
+ requestOptions.query = { version };
741
+ }
742
+ return yield this.httpBackend.createRequest(requestOptions, ops);
743
+ });
744
+ }
745
+ /**
746
+ * @param contract address of the contract we want to get the entrypoints of
747
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
748
+ * @description Return the list of entrypoints of the contract
749
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id-entrypoints
750
+ * @version 005_PsBABY5H
751
+ */
752
+ getEntrypoints(contract_1) {
753
+ return __awaiter(this, arguments, void 0, function* (contract, { block } = rpc_client_interface_1.defaultRPCOptions) {
754
+ this.validateContract(contract);
755
+ const contractResponse = yield this.httpBackend.createRequest({
756
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${contract}/entrypoints`),
757
+ method: 'GET',
758
+ });
759
+ return contractResponse;
760
+ });
761
+ }
762
+ /**
763
+ * @param op Operation to simulate
764
+ * @param options contains generic configuration for rpc calls to specified block and version
765
+ * @description Simulate running an operation at some future moment (based on the number of blocks given in the `latency` argument), and return the operation application result.
766
+ * @see https://gitlab.com/tezos/tezos/-/blob/master/docs/api/alpha-openapi.json
767
+ */
768
+ simulateOperation(op_1) {
769
+ return __awaiter(this, arguments, void 0, function* (op, { block, version } = rpc_client_interface_1.defaultRPCOptions) {
770
+ const requestOptions = {
771
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/helpers/scripts/simulate_operation`),
772
+ method: 'POST',
773
+ };
774
+ if (version !== undefined) {
775
+ requestOptions.query = { version };
776
+ }
777
+ return yield this.httpBackend.createRequest(requestOptions, op);
778
+ });
779
+ }
780
+ /**
781
+ * @param code Code to run
782
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
783
+ * @description Run a Michelson script in the current context
784
+ * @see https://gitlab.com/tezos/tezos/-/blob/master/docs/api/alpha-openapi.json
785
+ */
786
+ runCode(code_1) {
787
+ return __awaiter(this, arguments, void 0, function* (code, { block } = rpc_client_interface_1.defaultRPCOptions) {
788
+ const response = yield this.httpBackend.createRequest({
789
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/helpers/scripts/run_code`),
790
+ method: 'POST',
791
+ }, code);
792
+ return response;
793
+ });
794
+ }
795
+ /**
796
+ * @param viewScriptParams Parameters of the script view to run
797
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
798
+ * @description Simulate a call to a michelson view
799
+ * @see https://gitlab.com/tezos/tezos/-/blob/master/docs/api/alpha-openapi.json
800
+ */
801
+ runScriptView(_a, _b) {
802
+ return __awaiter(this, void 0, void 0, function* () {
803
+ var { unparsing_mode = 'Readable' } = _a, rest = __rest(_a, ["unparsing_mode"]);
804
+ var _c = _b === void 0 ? rpc_client_interface_1.defaultRPCOptions : _b, block = _c.block;
805
+ return this.httpBackend.createRequest({
806
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/helpers/scripts/run_script_view`),
807
+ method: 'POST',
808
+ }, Object.assign({ unparsing_mode }, rest));
809
+ });
810
+ }
811
+ /**
812
+ * @param viewParams Parameters of the view to run
813
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
814
+ * @description Simulate a call to a view following the TZIP-4 standard.
815
+ * @see https://gitlab.com/tezos/tezos/-/blob/master/docs/api/alpha-openapi.json
816
+ */
817
+ runView(_a, _b) {
818
+ return __awaiter(this, void 0, void 0, function* () {
819
+ var { unparsing_mode = 'Readable' } = _a, rest = __rest(_a, ["unparsing_mode"]);
820
+ var _c = _b === void 0 ? rpc_client_interface_1.defaultRPCOptions : _b, block = _c.block;
821
+ return this.httpBackend.createRequest({
822
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/helpers/scripts/run_view`),
823
+ method: 'POST',
824
+ }, Object.assign({ unparsing_mode }, rest));
825
+ });
826
+ }
827
+ getChainId() {
828
+ return __awaiter(this, void 0, void 0, function* () {
829
+ return this.httpBackend.createRequest({
830
+ url: this.createURL(`/chains/${this.chain}/chain_id`),
831
+ method: 'GET',
832
+ });
833
+ });
834
+ }
835
+ /**
836
+ * @param data Data to pack
837
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
838
+ * @description Computes the serialized version of a data expression using the same algorithm as script instruction PACK
839
+ * Note: You should always verify the packed bytes before signing or requesting that they be signed when using the RPC to pack.
840
+ * This precaution helps protect you and your applications users from RPC nodes that have been compromised.
841
+ * A node that is operated by a bad actor, or compromised by a bad actor could return a fully formed operation that does not correspond to the input provided to the RPC endpoint.
842
+ * A safer solution to pack and sign data would be to use the `packDataBytes` function available in the `@tezos-x/octez.js-michel-codec` package.
843
+ * @example packData({ data: { string: "test" }, type: { prim: "string" } })
844
+ * @see https://gitlab.com/tezos/tezos/-/blob/master/docs/api/alpha-openapi.json
845
+ */
846
+ packData(data_1) {
847
+ return __awaiter(this, arguments, void 0, function* (data, { block } = rpc_client_interface_1.defaultRPCOptions) {
848
+ const _a = yield this.httpBackend.createRequest({
849
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/helpers/scripts/pack_data`),
850
+ method: 'POST',
851
+ }, data), { gas } = _a, rest = __rest(_a, ["gas"]);
852
+ let formattedGas = gas;
853
+ const tryBigNumber = new bignumber_js_1.default(gas || '');
854
+ if (!tryBigNumber.isNaN()) {
855
+ formattedGas = tryBigNumber;
856
+ }
857
+ return Object.assign({ gas: formattedGas }, rest);
858
+ });
859
+ }
860
+ /**
861
+ *
862
+ * @description Return rpc root url
863
+ */
864
+ getRpcUrl() {
865
+ return this.url;
866
+ }
867
+ /**
868
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
869
+ * @description Returns the voting period (index, kind, starting position) and related information (position, remaining) of the interrogated block
870
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-votes-current-period
871
+ */
872
+ getCurrentPeriod() {
873
+ return __awaiter(this, arguments, void 0, function* ({ block, } = rpc_client_interface_1.defaultRPCOptions) {
874
+ const response = yield this.httpBackend.createRequest({
875
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/votes/current_period`),
876
+ method: 'GET',
877
+ });
878
+ return response;
879
+ });
880
+ }
881
+ /**
882
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
883
+ * @description Returns the voting period (index, kind, starting position) and related information (position, remaining) of the next block.Useful to craft operations that will be valid in the next block
884
+ * @example getSuccessorPeriod() will default to successor voting period for /main/chains/block/head.
885
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-votes-successor-period
886
+ */
887
+ getSuccessorPeriod() {
888
+ return __awaiter(this, arguments, void 0, function* ({ block, } = rpc_client_interface_1.defaultRPCOptions) {
889
+ const response = yield this.httpBackend.createRequest({
890
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/votes/successor_period`),
891
+ method: 'GET',
892
+ });
893
+ return response;
894
+ });
895
+ }
896
+ /**
897
+ * @param id Sapling state ID
898
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
899
+ * @description Returns the root and a diff of a state starting from an optional offset which is zero by default
900
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-sapling-sapling-state-id-get-diff
901
+ */
902
+ getSaplingDiffById(id_1) {
903
+ return __awaiter(this, arguments, void 0, function* (id, { block } = rpc_client_interface_1.defaultRPCOptions) {
904
+ return this.httpBackend.createRequest({
905
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/sapling/${id}/get_diff`),
906
+ method: 'GET',
907
+ });
908
+ });
909
+ }
910
+ /**
911
+ * @param contract address of the contract we want to get the sapling diff
912
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
913
+ * @description Returns the root and a diff of a state starting from an optional offset which is zero by default
914
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-contracts-contract-id-single-sapling-get-diff
915
+ */
916
+ getSaplingDiffByContract(contract_1) {
917
+ return __awaiter(this, arguments, void 0, function* (contract, { block } = rpc_client_interface_1.defaultRPCOptions) {
918
+ return this.httpBackend.createRequest({
919
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${contract}/single_sapling_get_diff`),
920
+ method: 'GET',
921
+ });
922
+ });
923
+ }
924
+ /**
925
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
926
+ * @description get current and next protocol
927
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-protocols
928
+ */
929
+ getProtocols() {
930
+ return __awaiter(this, arguments, void 0, function* ({ block } = rpc_client_interface_1.defaultRPCOptions) {
931
+ return this.httpBackend.createRequest({
932
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/protocols`),
933
+ method: 'GET',
934
+ });
935
+ });
936
+ }
937
+ /**
938
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
939
+ * @description get current and next protocol
940
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-protocols
941
+ */
942
+ getProtocolActivations() {
943
+ return __awaiter(this, arguments, void 0, function* (protocol = '') {
944
+ if (protocol) {
945
+ const protocolValidation = (0, octez_js_utils_1.validateProtocol)(protocol);
946
+ if (protocolValidation !== octez_js_utils_1.ValidationResult.VALID) {
947
+ throw new octez_js_utils_1.InvalidProtocolHashError(protocol, protocolValidation);
948
+ }
949
+ }
950
+ return this.httpBackend.createRequest({
951
+ url: this.createURL(`/chains/${this.chain}/protocols/${protocol}`),
952
+ method: 'GET',
953
+ });
954
+ });
955
+ }
956
+ /**
957
+ * @param contract address of the contract we want to retrieve storage information of
958
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
959
+ * @description Access the used storage space of the contract
960
+ * @see https://gitlab.com/tezos/tezos/-/blob/master/docs/api/alpha-openapi.json
961
+ */
962
+ getStorageUsedSpace(contract_1) {
963
+ return __awaiter(this, arguments, void 0, function* (contract, { block } = rpc_client_interface_1.defaultRPCOptions) {
964
+ return this.httpBackend.createRequest({
965
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${contract}/storage/used_space`),
966
+ method: 'GET',
967
+ });
968
+ });
969
+ }
970
+ /**
971
+ * @param contract address of the contract we want to retrieve storage information of
972
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
973
+ * @description Access the paid storage space of the contract
974
+ * @see https://gitlab.com/tezos/tezos/-/blob/master/docs/api/alpha-openapi.json
975
+ */
976
+ getStoragePaidSpace(contract_1) {
977
+ return __awaiter(this, arguments, void 0, function* (contract, { block } = rpc_client_interface_1.defaultRPCOptions) {
978
+ return this.httpBackend.createRequest({
979
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${contract}/storage/paid_space`),
980
+ method: 'GET',
981
+ });
982
+ });
983
+ }
984
+ /**
985
+ * @param contract implicit or originated address we want to retrieve ticket balance of
986
+ * @param ticket object to specify a ticket by ticketer, content type and content
987
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
988
+ * @description Access the contract's balance of ticket with specified ticketer, content type, and content.
989
+ * @example ticket { ticketer: 'address', content_type: { prim: "string" }, content: { string: 'ticket1' } }
990
+ * @see https://tezos.gitlab.io/protocols/016_mumbai.html#rpc-changes
991
+ */
992
+ getTicketBalance(contract_1, ticket_1) {
993
+ return __awaiter(this, arguments, void 0, function* (contract, ticket, { block } = rpc_client_interface_1.defaultRPCOptions) {
994
+ return this.httpBackend.createRequest({
995
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${contract}/ticket_balance`),
996
+ method: 'POST',
997
+ }, ticket);
998
+ });
999
+ }
1000
+ /**
1001
+ * @param contract originated address we want to retrieve ticket balances of
1002
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
1003
+ * @description Access the complete list of tickets owned by the given contract by scanning the contract's storage.
1004
+ * @see https://tezos.gitlab.io/protocols/016_mumbai.html#rpc-changes
1005
+ */
1006
+ getAllTicketBalances(contract_1) {
1007
+ return __awaiter(this, arguments, void 0, function* (contract, { block } = rpc_client_interface_1.defaultRPCOptions) {
1008
+ return this.httpBackend.createRequest({
1009
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/contracts/${contract}/all_ticket_balances`),
1010
+ method: 'GET',
1011
+ });
1012
+ });
1013
+ }
1014
+ /**
1015
+ * @description Returns the cycle at which the launch of the Adaptive Issuance feature is set to happen. A result of null means that the feature is not yet set to launch.
1016
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
1017
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-adaptive-issuance-launch-cycle
1018
+ */
1019
+ getAdaptiveIssuanceLaunchCycle() {
1020
+ return __awaiter(this, arguments, void 0, function* ({ block, } = rpc_client_interface_1.defaultRPCOptions) {
1021
+ return this.httpBackend.createRequest({
1022
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/adaptive_issuance_launch_cycle`),
1023
+ method: 'GET',
1024
+ });
1025
+ });
1026
+ }
1027
+ /**
1028
+ * @description List the prevalidated operations in mempool (accessibility of mempool depends on each rpc endpoint)
1029
+ * @param args has 5 optional properties
1030
+ * @default args { version: '2', validated: true, refused: true, outdated, true, branchRefused: true, branchDelayed: true, validationPass: undefined, source: undefined, operationHash: undefined }
1031
+ * @see https://gitlab.com/tezos/tezos/-/blob/master/docs/api/tallinn-mempool-openapi-rc.json
1032
+ */
1033
+ getPendingOperations() {
1034
+ return __awaiter(this, arguments, void 0, function* (args = {}) {
1035
+ return this.httpBackend.createRequest({
1036
+ url: this.createURL(`/chains/${this.chain}/mempool/pending_operations`),
1037
+ method: 'GET',
1038
+ query: args,
1039
+ });
1040
+ });
1041
+ }
1042
+ /**
1043
+ * @param delegate delegate address which we want to retrieve active staking parameters
1044
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
1045
+ * @description Returns the currently active staking parameters for the given delegate
1046
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-delegates-pkh-active-staking-parameters
1047
+ */
1048
+ getActiveStakingParameters(delegate_1) {
1049
+ return __awaiter(this, arguments, void 0, function* (delegate, { block } = rpc_client_interface_1.defaultRPCOptions) {
1050
+ return yield this.httpBackend.createRequest({
1051
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/delegates/${delegate}/active_staking_parameters`),
1052
+ method: 'GET',
1053
+ });
1054
+ });
1055
+ }
1056
+ /**
1057
+ * @param delegate delegate address which we want to retrieve pending staking parameters
1058
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
1059
+ * @description Returns the pending values for the given delegate's staking parameters
1060
+ * @see https://tezos.gitlab.io/active/rpc.html#get-block-id-context-delegates-pkh-pending-staking-parameters
1061
+ */
1062
+ getPendingStakingParameters(delegate_1) {
1063
+ return __awaiter(this, arguments, void 0, function* (delegate, { block } = rpc_client_interface_1.defaultRPCOptions) {
1064
+ return yield this.httpBackend.createRequest({
1065
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/delegates/${delegate}/pending_staking_parameters`),
1066
+ method: 'GET',
1067
+ });
1068
+ });
1069
+ }
1070
+ /**
1071
+ * @param destination address to retrieve the index for
1072
+ * @param options contains generic configuration for rpc calls to specified block (default to head)
1073
+ * @description Returns the index assigned to the address if it was indexed by the opcode INDEX_ADDRESS, otherwise returns null
1074
+ * @see https://octez.tezos.com/docs/alpha/rpc.html#get-block-id-context-destination-destination-id-index
1075
+ */
1076
+ getDestinationIndex(destination_1) {
1077
+ return __awaiter(this, arguments, void 0, function* (destination, { block } = rpc_client_interface_1.defaultRPCOptions) {
1078
+ return yield this.httpBackend.createRequest({
1079
+ url: this.createURL(`/chains/${this.chain}/blocks/${block}/context/destination/${destination}/index`),
1080
+ method: 'GET',
1081
+ });
1082
+ });
1083
+ }
1084
+ }
1085
+ exports.RpcClient = RpcClient;