postchain-client 1.0.2 → 1.1.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.
Files changed (98) hide show
  1. package/README.md +30 -49
  2. package/built/cjs/index.js +2571 -0
  3. package/built/cjs/index.js.map +1 -0
  4. package/built/esm/index.js +29927 -0
  5. package/built/esm/index.js.map +1 -0
  6. package/built/index.js +21 -3
  7. package/built/index.js.map +1 -0
  8. package/built/src/chromia/chromiaClientProvider.js +35 -0
  9. package/built/src/chromia/chromiaClientProvider.js.map +1 -0
  10. package/built/src/chromia/errors.js +6 -0
  11. package/built/src/chromia/errors.js.map +1 -0
  12. package/built/src/chromia/interfaces.js +2 -0
  13. package/built/src/chromia/interfaces.js.map +1 -0
  14. package/built/src/encryption/encryption.js +105 -0
  15. package/built/src/encryption/encryption.js.map +1 -0
  16. package/built/src/encryption/errors.js +11 -0
  17. package/built/src/encryption/errors.js.map +1 -0
  18. package/built/src/encryption/types.js +2 -0
  19. package/built/src/encryption/types.js.map +1 -0
  20. package/built/src/formatter.d.ts +2 -0
  21. package/built/src/formatter.js +119 -0
  22. package/built/src/formatter.js.map +1 -0
  23. package/built/src/gtv/definition.js +20 -0
  24. package/built/src/gtv/definition.js.map +1 -0
  25. package/built/src/gtv/index.d.ts +1 -0
  26. package/built/src/gtv/index.js +11 -0
  27. package/built/src/gtv/index.js.map +1 -0
  28. package/built/src/gtv/types.d.ts +2 -3
  29. package/built/src/gtv/types.js +2 -0
  30. package/built/src/gtv/types.js.map +1 -0
  31. package/built/src/gtx/errors.js +26 -0
  32. package/built/src/gtx/errors.js.map +1 -0
  33. package/built/src/gtx/gtx.d.ts +1 -1
  34. package/built/src/gtx/gtx.js +115 -0
  35. package/built/src/gtx/gtx.js.map +1 -0
  36. package/built/src/gtx/gtxclient.js +77 -0
  37. package/built/src/gtx/gtxclient.js.map +1 -0
  38. package/built/src/gtx/index.js +5 -0
  39. package/built/src/gtx/index.js.map +1 -0
  40. package/built/src/gtx/interfaces.js +2 -0
  41. package/built/src/gtx/interfaces.js.map +1 -0
  42. package/built/src/gtx/serialization.d.ts +3 -2
  43. package/built/src/gtx/serialization.js +95 -0
  44. package/built/src/gtx/serialization.js.map +1 -0
  45. package/built/src/gtx/types.d.ts +10 -1
  46. package/built/src/gtx/types.js +2 -0
  47. package/built/src/gtx/types.js.map +1 -0
  48. package/built/src/logger.d.ts +2 -1
  49. package/built/src/logger.js +53 -0
  50. package/built/src/logger.js.map +1 -0
  51. package/built/src/merkle/binarytree.d.ts +137 -0
  52. package/built/src/merkle/binarytree.js +146 -0
  53. package/built/src/merkle/binarytree.js.map +1 -0
  54. package/built/src/merkle/binarytreefactory.d.ts +86 -0
  55. package/built/src/merkle/binarytreefactory.js +235 -0
  56. package/built/src/merkle/binarytreefactory.js.map +1 -0
  57. package/built/src/merkle/merkleHelper.js +109 -0
  58. package/built/src/merkle/merkleHelper.js.map +1 -0
  59. package/built/src/merkle/merklehashcalculator.d.ts +35 -0
  60. package/built/src/merkle/merklehashcalculator.js +71 -0
  61. package/built/src/merkle/merklehashcalculator.js.map +1 -0
  62. package/built/src/merkle/path.d.ts +155 -0
  63. package/built/src/merkle/path.js +306 -0
  64. package/built/src/merkle/path.js.map +1 -0
  65. package/built/src/merkle/proof/merklehashcarrier.d.ts +17 -0
  66. package/built/src/merkle/proof/merklehashcarrier.js +23 -0
  67. package/built/src/merkle/proof/merklehashcarrier.js.map +1 -0
  68. package/built/src/merkle/proof/merklehashsummaryfactory.d.ts +53 -0
  69. package/built/src/merkle/proof/merklehashsummaryfactory.js +81 -0
  70. package/built/src/merkle/proof/merklehashsummaryfactory.js.map +1 -0
  71. package/built/src/merkle/proof/merkleproof.d.ts +35 -0
  72. package/built/src/merkle/proof/merkleproof.js +59 -0
  73. package/built/src/merkle/proof/merkleproof.js.map +1 -0
  74. package/built/src/merkle/proof/merkleprooftree.d.ts +130 -0
  75. package/built/src/merkle/proof/merkleprooftree.js +116 -0
  76. package/built/src/merkle/proof/merkleprooftree.js.map +1 -0
  77. package/built/src/merkle/proof/merkleprooftreefactory.d.ts +47 -0
  78. package/built/src/merkle/proof/merkleprooftreefactory.js +121 -0
  79. package/built/src/merkle/proof/merkleprooftreefactory.js.map +1 -0
  80. package/built/src/merkle/types.js +2 -0
  81. package/built/src/merkle/types.js.map +1 -0
  82. package/built/src/restclient/errors.js +54 -0
  83. package/built/src/restclient/errors.js.map +1 -0
  84. package/built/src/restclient/interfaces.d.ts +2 -1
  85. package/built/src/restclient/interfaces.js +2 -0
  86. package/built/src/restclient/interfaces.js.map +1 -0
  87. package/built/src/restclient/restclient.js +309 -0
  88. package/built/src/restclient/restclient.js.map +1 -0
  89. package/built/src/restclient/restclientutil.d.ts +4 -0
  90. package/built/src/restclient/restclientutil.js +137 -0
  91. package/built/src/restclient/restclientutil.js.map +1 -0
  92. package/built/src/restclient/types.d.ts +4 -0
  93. package/built/src/restclient/types.js +13 -0
  94. package/built/src/restclient/types.js.map +1 -0
  95. package/built/umd/index.js +29931 -0
  96. package/built/umd/index.js.map +1 -0
  97. package/package.json +30 -17
  98. package/built/index.js.LICENSE.txt +0 -657
@@ -0,0 +1,309 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ import { ResponseStatus, Method, } from "./types";
12
+ import * as logger from "../logger";
13
+ import { EmptyListOfUrlsException, LostMessageError, SerializedTransactionFormatException, TxRejectedError, UnexpectedResponseError, UnexpectedStatusError, UnvalidTxRidException, } from "./errors";
14
+ import { toBuffer, toQueryObjectGTV } from "../formatter";
15
+ import { requestWithRetry } from "./restclientutil";
16
+ import { encodeValue } from "../gtx/serialization";
17
+ export function createRestClient(endpointPool, blockchainRID, maxSockets = 10, pollingInterval = 500, failOverConfig) {
18
+ validateInput(endpointPool, failOverConfig);
19
+ return {
20
+ config: {
21
+ endpointPool: endpointPool,
22
+ pool: { maxSockets },
23
+ pollingInterval,
24
+ attemptsPerEndpoint: (failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptsPerEndpoint) || 3,
25
+ attemptInterval: (failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptInterval) || 500,
26
+ },
27
+ /**
28
+ * Retrieves the client message with the specified double-sha256 hash
29
+ * @param txRID the id of the transaction
30
+ * @param callback parameters (error, serializedMessage) if first
31
+ * parameter is not null, an error occurred.
32
+ * If first parameter is null, then the second parameter is a buffer
33
+ * with the serialized client message. If no such client message exists,
34
+ * the callback will be called with (null, null).
35
+ */
36
+ getTransaction: function (txRID, callback) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ if (!validTxRID(txRID)) {
39
+ callback(new UnvalidTxRidException(txRID), null);
40
+ }
41
+ else {
42
+ const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, "tx/" + blockchainRID + "/" + txRID.toString("hex"), this.config);
43
+ handleGetResponse(error, statusCode, statusCode === 200 ? toBuffer(rspBody.tx) : rspBody, callback);
44
+ }
45
+ });
46
+ },
47
+ /**
48
+ * Sends a transaction to postchain for inclusion in a block.
49
+ * Use status() to monitor progress once this transaction is
50
+ * posted.
51
+ *
52
+ * @param serializedTransaction The transaction (a buffer) to send
53
+ * @param callback taking parameter (error, responseObject) if error is null
54
+ * then resonseObject is also null. If error is not null, then responseObject
55
+ * is an object with the string property 'error'
56
+ */
57
+ postTransaction: function (serializedTransaction, callback) {
58
+ return __awaiter(this, void 0, void 0, function* () {
59
+ if (!Buffer.isBuffer(serializedTransaction)) {
60
+ throw new SerializedTransactionFormatException();
61
+ }
62
+ const transactionObject = {
63
+ tx: serializedTransaction.toString("hex"),
64
+ };
65
+ const { error, statusCode, rspBody } = yield requestWithRetry(Method.POST, "tx/" + blockchainRID, this.config, transactionObject);
66
+ handlePostResponse(error, statusCode, rspBody, callback);
67
+ });
68
+ },
69
+ /**
70
+ * Retrieves a confirmation proof for a client message with the specified double-sha256
71
+ * hash.
72
+ * @param txRID the id of the transaction
73
+ * @param callback parameters (error, responseObjectProof) if first
74
+ * parameter is not null, an error occurred.
75
+ * If first parameter is null, then the second parameter is an object
76
+ * like the following:
77
+ *
78
+ * {hash: messageHashBuffer,
79
+ * blockHeader: blockHeaderBuffer,
80
+ * signatures: [{pubKey: pubKeyBuffer, signature: sigBuffer}, ...],
81
+ * merklePath: [{side: <0|1>, hash: <hash buffer level n-1>},
82
+ * ...
83
+ * {side: <0|1>, hash: <hash buffer level 1>}]}
84
+ *
85
+ * If no such client message exists, the callback will be called with (null, null).
86
+ *
87
+ * The proof object can be validated using
88
+ * postchain-common.util.validateMerklePath(proof.merklePath, proof.hash,
89
+ * proof.blockHeader.slice(32, 64))
90
+ *
91
+ * The signatures must be validated agains some know trusted source for valid signers
92
+ * at this specific block height.
93
+ */
94
+ getConfirmationProof: function (txRID, callback) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ if (!validTxRID(txRID)) {
97
+ callback(new UnvalidTxRidException(txRID), null);
98
+ }
99
+ else {
100
+ const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, "tx/" +
101
+ blockchainRID +
102
+ "/" +
103
+ txRID.toString("hex") +
104
+ "/confirmationProof", this.config);
105
+ const confirmationProof = {
106
+ hash: undefined,
107
+ blockHeader: undefined,
108
+ signatures: [],
109
+ merklePath: [],
110
+ };
111
+ if (statusCode === 200 || statusCode === 503) {
112
+ confirmationProof.hash = toBuffer(rspBody.hash);
113
+ confirmationProof.blockHeader = toBuffer(rspBody.blockHeader);
114
+ if (rspBody.signatures) {
115
+ confirmationProof.signatures = rspBody.signatures.map((item) => ({
116
+ pubKey: toBuffer(item.pubKey),
117
+ signature: toBuffer(item.signature),
118
+ }));
119
+ }
120
+ if (rspBody.merklePath) {
121
+ confirmationProof.merklePath = rspBody.merklePath.map((item) => {
122
+ return { side: item.side, hash: toBuffer(item.hash) };
123
+ });
124
+ }
125
+ }
126
+ handleGetResponse(error, statusCode, confirmationProof, callback);
127
+ }
128
+ });
129
+ },
130
+ /**
131
+ * Queries the status of a certain transaction.
132
+ * @param txRID the id of the transaction
133
+ * @param callback taking parameters (error, responseBody). If error is null
134
+ * then responseBody is an object on the form
135
+ * { status: '<confirmed|waiting|rejected|unknown>' }
136
+ * If error is not null, then responseBody
137
+ * is an object with the string property 'error'
138
+ */
139
+ status: function (txRID, callback) {
140
+ return __awaiter(this, void 0, void 0, function* () {
141
+ if (!validTxRID(txRID)) {
142
+ callback(new UnvalidTxRidException(txRID), null);
143
+ }
144
+ else {
145
+ const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, "tx/" + blockchainRID + "/" + txRID.toString("hex") + "/status", this.config);
146
+ handleGetResponse(error, statusCode, rspBody, callback);
147
+ }
148
+ });
149
+ },
150
+ /**
151
+ * Interfaces the query enpoint of the Rell backend. Returns either a resolved or rejected promise.
152
+ * @param queryObject an object that must contain a "type" and follows this pattern: { type: "nameOfQuery", arg1: argValue1, arg2: argvalue2 }
153
+ */
154
+ query: function (queryObject) {
155
+ return __awaiter(this, void 0, void 0, function* () {
156
+ // eslint-disable-next-line no-async-promise-executor
157
+ return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
158
+ const callback = (error, result) => {
159
+ if (error) {
160
+ reject(error);
161
+ }
162
+ else {
163
+ resolve(result);
164
+ }
165
+ };
166
+ const { error, statusCode, rspBody } = yield requestWithRetry(Method.POST, `query_gtv/${blockchainRID}`, this.config, encodeValue(toQueryObjectGTV(queryObject)));
167
+ handlePostResponse(error, statusCode, rspBody, callback);
168
+ }));
169
+ });
170
+ },
171
+ /**
172
+ * Polls for status while waiting for response; confirmed, rejected or unknown. Returns either a resolved or rejected promise.
173
+ * @param txRID the id of the transaction
174
+ */
175
+ waitConfirmation(txRID) {
176
+ return new Promise((resolve, reject) => {
177
+ this.status(txRID, (error, result) => {
178
+ if (error) {
179
+ reject(error);
180
+ }
181
+ else {
182
+ const status = result.status;
183
+ switch (status) {
184
+ case ResponseStatus.Confirmed:
185
+ resolve(null);
186
+ break;
187
+ case ResponseStatus.Rejected:
188
+ reject(new TxRejectedError(result.rejectReason));
189
+ break;
190
+ case ResponseStatus.Unknown:
191
+ reject(new LostMessageError());
192
+ break;
193
+ case ResponseStatus.Waiting:
194
+ setTimeout(() => this.waitConfirmation(txRID).then(resolve, reject), this.config.pollingInterval);
195
+ break;
196
+ default:
197
+ logger.error(status);
198
+ reject(new UnexpectedResponseError());
199
+ }
200
+ }
201
+ });
202
+ });
203
+ },
204
+ /**
205
+ * Posts a transaction and polls for status while waiting for status response; confirmed, rejected or unknown. Returns either a resolved or rejected promise.
206
+ * @param serializedTransaction The transaction (a buffer) to send
207
+ * @param txRID the id of the transaction
208
+ * @param validate true if the transaction needs to be validated
209
+ */
210
+ postAndWaitConfirmation(serializedTransaction, txRID, validate) {
211
+ if (validate === true) {
212
+ return Promise.reject("Automatic validation is not yet implemented");
213
+ }
214
+ return new Promise((resolve, reject) => {
215
+ this.postTransaction(serializedTransaction, (error) => {
216
+ if (error)
217
+ reject(error);
218
+ else {
219
+ setTimeout(() => this.waitConfirmation(txRID).then(resolve, reject), 1011);
220
+ }
221
+ });
222
+ });
223
+ },
224
+ /**
225
+ * Returns a string array with the endpoints hosting the dApp the client
226
+ * is connected to
227
+ */
228
+ getEndpointPool() {
229
+ return this.config.endpointPool;
230
+ },
231
+ };
232
+ }
233
+ /**
234
+ * Validates that txRID is a Buffer of 32 bytes.
235
+ * @param txRID A buffer of 32 bytes
236
+ */
237
+ function validTxRID(txRID) {
238
+ if (txRID.length != 32) {
239
+ const error = new UnvalidTxRidException(txRID);
240
+ logger.error(error.toString());
241
+ return false;
242
+ }
243
+ return true;
244
+ }
245
+ function validateInput(endpointPool, failOverConfig) {
246
+ if (!endpointPool.length) {
247
+ throw new EmptyListOfUrlsException();
248
+ }
249
+ if ((failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptsPerEndpoint) < 1) {
250
+ logger.debug("Attempts can not be 0 or below, setting it to 1");
251
+ failOverConfig.attemptsPerEndpoint = 1;
252
+ }
253
+ }
254
+ /**
255
+ * @param error response error
256
+ * @param statusCode response status code
257
+ * @param responseObject the responsebody from the server
258
+ * @param callback the callback function to propagate the error and response back to the caller
259
+ */
260
+ function handleGetResponse(error, statusCode, responseObject, callback) {
261
+ try {
262
+ logger.debug(`error: ${error}, status code: ${statusCode}, response body: ${JSON.stringify(responseObject)}`);
263
+ if (error) {
264
+ callback(error, null);
265
+ }
266
+ else if (statusCode === 404) {
267
+ logger.error("404 received");
268
+ callback(null, null);
269
+ }
270
+ else if (statusCode != 200) {
271
+ callback(new UnexpectedStatusError(statusCode), responseObject);
272
+ }
273
+ else {
274
+ callback(null, responseObject);
275
+ }
276
+ }
277
+ catch (error) {
278
+ logger.error("restclient.handleGetResponse(): Failed to call callback function " +
279
+ error);
280
+ }
281
+ }
282
+ /**
283
+ * @param error response error
284
+ * @param statusCode response status code
285
+ * @param responseObject the responsebody from the server
286
+ * @param callback the callback function to propagate the error and response back to the caller
287
+ */
288
+ function handlePostResponse(error, statusCode, responseObject, callback) {
289
+ logger.debug(`error: ${error}, status code: ${statusCode}, response body: ${JSON.stringify(responseObject)}`);
290
+ try {
291
+ if (error) {
292
+ logger.error(`In restclient post(). ${error}`);
293
+ callback(error);
294
+ }
295
+ else if (statusCode != 200) {
296
+ logger.error(`Unexpected status code from server: ${statusCode}`);
297
+ callback(new UnexpectedStatusError(statusCode), responseObject);
298
+ }
299
+ else {
300
+ logger.info(`Calling responseCallback with responseObject: ${JSON.stringify(responseObject)}`);
301
+ callback(null, responseObject);
302
+ }
303
+ }
304
+ catch (error) {
305
+ logger.error("restclient.handlePostResponse(): Failed to call callback function " +
306
+ error);
307
+ }
308
+ }
309
+ //# sourceMappingURL=restclient.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restclient.js","sourceRoot":"","sources":["../../../src/restclient/restclient.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;;;;;;;;;AACb,OAAO,EAGL,cAAc,EAId,MAAM,GACP,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AACpC,OAAO,EACL,wBAAwB,EACxB,gBAAgB,EAChB,oCAAoC,EACpC,eAAe,EACf,uBAAuB,EACvB,qBAAqB,EACrB,qBAAqB,GACtB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAC1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAInD,MAAM,UAAU,gBAAgB,CAC9B,YAA+B,EAC/B,aAAqB,EACrB,UAAU,GAAG,EAAE,EACf,eAAe,GAAG,GAAG,EACrB,cAA+B;IAE/B,aAAa,CAAC,YAAY,EAAE,cAAc,CAAC,CAAC;IAE5C,OAAO;QACL,MAAM,EAAE;YACN,YAAY,EAAE,YAAY;YAC1B,IAAI,EAAE,EAAE,UAAU,EAAE;YACpB,eAAe;YACf,mBAAmB,EAAE,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,mBAAmB,KAAI,CAAC;YAC7D,eAAe,EAAE,CAAA,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,eAAe,KAAI,GAAG;SACxD;QAED;;;;;;;;WAQG;QACH,cAAc,EAAE,UACd,KAAa,EACb,QAA2D;;gBAE3D,IAAI,CAAC,UAAU,CAAC,KAAK,CAAC,EAAE;oBACtB,QAAQ,CAAC,IAAI,qBAAqB,CAAC,KAAK,CAAC,EAAE,IAAI,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ACd,MAAM,CAAC,KAAK,CACV,oEAAoE;YAClE,KAAK,CACR,CAAC;KACH;AACH,CAAC"}
@@ -1,3 +1,7 @@
1
+ /// <reference types="node" />
2
+ import { RestClientConfig, PostRequestObjects, Method, ResponseObject } from "./types";
1
3
  export declare function getBrid(urlBase: string, chainId: number): Promise<string>;
4
+ export declare function requestWithRetry(method: Method, path: string, config: RestClientConfig, postObject?: PostRequestObjects | Buffer): Promise<ResponseObject>;
5
+ export declare function handleRequest(method: Method, path: string, endpoint: string, postObject?: PostRequestObjects | Buffer): Promise<ResponseObject>;
2
6
  export declare function nextEndpoint(endpointPool: readonly string[]): string;
3
7
  export declare const sleep: (ms: number) => Promise<unknown>;
@@ -0,0 +1,137 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import * as logger from "../logger";
11
+ import { decodeValue } from "../gtx/serialization";
12
+ import { GetBridFromChainException } from "./errors";
13
+ import { Method, } from "./types";
14
+ export function getBrid(urlBase, chainId) {
15
+ if (chainId >= 0) {
16
+ const url = `${urlBase}/brid/iid_${chainId}`;
17
+ return fetch(url).then((response) => {
18
+ if (response.ok)
19
+ return response.text();
20
+ throw new GetBridFromChainException(chainId, response.statusText);
21
+ });
22
+ }
23
+ else {
24
+ const url = `${urlBase}/_debug`;
25
+ return fetch(url).then((response) => {
26
+ if (response.ok)
27
+ return response
28
+ .json()
29
+ .then((json) => json.blockchain[json.blockchain.length - 1].brid);
30
+ throw new GetBridFromChainException(chainId, response.statusText);
31
+ });
32
+ }
33
+ }
34
+ export function requestWithRetry(method, path, config, postObject) {
35
+ return __awaiter(this, void 0, void 0, function* () {
36
+ let statusCode, rspBody, error;
37
+ const noRetryStatusCodes = [200, 400, 409, 500];
38
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
39
+ for (const _endpoint of config.endpointPool) {
40
+ const endpoint = nextEndpoint(config.endpointPool);
41
+ for (let attempt = 0; attempt < config.attemptsPerEndpoint; attempt++) {
42
+ ({ error, statusCode, rspBody } = yield handleRequest(method, path, endpoint, postObject));
43
+ if (noRetryStatusCodes.includes(statusCode)) {
44
+ return { error, statusCode, rspBody };
45
+ }
46
+ if (statusCode == 503) {
47
+ break;
48
+ }
49
+ logger.info(`${method} request failed on ${endpoint}. Attempt: ${attempt + 1} / ${config.attemptsPerEndpoint}`);
50
+ yield sleep(config.attemptInterval);
51
+ }
52
+ }
53
+ return { error, statusCode, rspBody };
54
+ });
55
+ }
56
+ export function handleRequest(method, path, endpoint, postObject) {
57
+ return __awaiter(this, void 0, void 0, function* () {
58
+ if (method == Method.GET) {
59
+ return yield get(path, endpoint);
60
+ }
61
+ else {
62
+ return yield post(path, endpoint, postObject);
63
+ }
64
+ });
65
+ }
66
+ /**
67
+ * Sends request to get data from a given API endpoint.
68
+ * @param path API endpoint of Rell backend
69
+ * @param endpoint
70
+ */
71
+ function get(path, endpoint) {
72
+ return __awaiter(this, void 0, void 0, function* () {
73
+ logger.debug("GET URL " + new URL(path, endpoint).href);
74
+ try {
75
+ const response = yield fetch(new URL(path, endpoint).href);
76
+ if (response.status == 404) {
77
+ return { error: null, statusCode: response.status, rspBody: null };
78
+ }
79
+ const rspBody = yield response.json();
80
+ return { error: null, statusCode: response.status, rspBody };
81
+ }
82
+ catch (error) {
83
+ logger.error(error.message);
84
+ return { error, statusCode: null, rspBody: null };
85
+ }
86
+ });
87
+ }
88
+ /**
89
+ * Sends request to post data to a given API endpoint.
90
+ * @param path API endpoint of Rell backend
91
+ * @param endpoint
92
+ * @param requestBody request body
93
+ */
94
+ function post(path, endpoint, requestBody) {
95
+ return __awaiter(this, void 0, void 0, function* () {
96
+ logger.debug("POST URL " + new URL(path, endpoint).href);
97
+ logger.debug("POST body " + JSON.stringify(requestBody));
98
+ if (Buffer.isBuffer(requestBody)) {
99
+ try {
100
+ const requestOptions = {
101
+ method: "post",
102
+ body: requestBody,
103
+ };
104
+ const response = yield fetch(new URL(path, endpoint).href, requestOptions);
105
+ return {
106
+ error: null,
107
+ statusCode: response.status,
108
+ rspBody: decodeValue(Buffer.from(yield response.arrayBuffer())),
109
+ };
110
+ }
111
+ catch (error) {
112
+ return { error, statusCode: null, rspBody: null };
113
+ }
114
+ }
115
+ else {
116
+ try {
117
+ const response = yield fetch(new URL(path, endpoint).href, {
118
+ method: "post",
119
+ body: JSON.stringify(requestBody),
120
+ });
121
+ return {
122
+ error: null,
123
+ statusCode: response.status,
124
+ rspBody: yield response.json(),
125
+ };
126
+ }
127
+ catch (error) {
128
+ return { error, statusCode: null, rspBody: null };
129
+ }
130
+ }
131
+ });
132
+ }
133
+ export function nextEndpoint(endpointPool) {
134
+ return endpointPool[Math.floor(Math.random() * endpointPool.length)];
135
+ }
136
+ export const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
137
+ //# sourceMappingURL=restclientutil.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"restclientutil.js","sourceRoot":"","sources":["../../../src/restclient/restclientutil.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,KAAK,MAAM,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AACnD,OAAO,EAAE,yBAAyB,EAAE,MAAM,UAAU,CAAC;AACrD,OAAO,EAGL,MAAM,GAEP,MAAM,SAAS,CAAC;AAEjB,MAAM,UAAU,OAAO,CAAC,OAAe,EAAE,OAAe;IACtD,IAAI,OAAO,IAAI,CAAC,EAAE;QAChB,MAAM,GAAG,GAAG,GAAG,OAAO,aAAa,OAAO,EAAE,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AE,OAAO,EAAE,IAAI,EAAE,CAAC;aACnD;SACF;aAAM;YACL,IAAI;gBACF,MAAM,QAAQ,GAAG,MAAM,KAAK,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC,IAAI,EAAE;oBACzD,MAAM,EAAE,MAAM;oBACd,IAAI,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC;iBAClC,CAAC,CAAC;gBACH,OAAO;oBACL,KAAK,EAAE,IAAI;oBACX,UAAU,EAAE,QAAQ,CAAC,MAAM;oBAC3B,OAAO,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE;iBAC/B,CAAC;aACH;YAAC,OAAO,KAAK,EAAE;gBACd,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC;aACnD;SACF;IACH,CAAC;CAAA;AACD,MAAM,UAAU,YAAY,CAAC,YAA+B;IAC1D,OAAO,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,GAAG,YAAY,CAAC,MAAM,CAAC,CAAC,CAAC;AACvE,CAAC;AACD,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,EAAU,EAAE,EAAE,CAAC,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC"}
@@ -24,6 +24,10 @@ export type QueryObject = {
24
24
  type: string;
25
25
  [arg: string]: RawGtv;
26
26
  };
27
+ export type QueryObjectGTV = [name: string, args: Arg];
28
+ export type Arg = {
29
+ [arg: string]: RawGtv;
30
+ };
27
31
  export type ServerReturnProof = {
28
32
  hash: string;
29
33
  blockHeader: string;
@@ -0,0 +1,13 @@
1
+ export var ResponseStatus;
2
+ (function (ResponseStatus) {
3
+ ResponseStatus["Confirmed"] = "confirmed";
4
+ ResponseStatus["Rejected"] = "rejected";
5
+ ResponseStatus["Unknown"] = "unknown";
6
+ ResponseStatus["Waiting"] = "waiting";
7
+ })(ResponseStatus || (ResponseStatus = {}));
8
+ export var Method;
9
+ (function (Method) {
10
+ Method["GET"] = "get";
11
+ Method["POST"] = "post";
12
+ })(Method || (Method = {}));
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/restclient/types.ts"],"names":[],"mappings":"AA+CA,MAAM,CAAN,IAAY,cAKX;AALD,WAAY,cAAc;IACxB,yCAAuB,CAAA;IACvB,uCAAqB,CAAA;IACrB,qCAAmB,CAAA;IACnB,qCAAmB,CAAA;AACrB,CAAC,EALW,cAAc,KAAd,cAAc,QAKzB;AA4BD,MAAM,CAAN,IAAY,MAGX;AAHD,WAAY,MAAM;IAChB,qBAAW,CAAA;IACX,uBAAa,CAAA;AACf,CAAC,EAHW,MAAM,KAAN,MAAM,QAGjB"}