postchain-client 2.0.4 → 2.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 (109) hide show
  1. package/README.md +9 -7
  2. package/built/cjs/index.js +235 -118
  3. package/built/cjs/index.js.map +1 -1
  4. package/built/esm/index.js +19045 -17598
  5. package/built/esm/index.js.map +1 -1
  6. package/built/mocks/handlers.d.ts +8 -8
  7. package/built/mocks/handlers.js +4 -2
  8. package/built/mocks/handlers.js.map +1 -1
  9. package/built/mocks/servers.d.ts +1 -1
  10. package/built/resources/testData.d.ts +1 -2
  11. package/built/src/ICCF/IccfProofTxMaterialBuilder.d.ts +0 -1
  12. package/built/src/ICCF/IccfProofTxMaterialBuilder.js +3 -2
  13. package/built/src/ICCF/IccfProofTxMaterialBuilder.js.map +1 -1
  14. package/built/src/ICCF/error.d.ts +0 -1
  15. package/built/src/ICCF/interfaces.d.ts +0 -1
  16. package/built/src/ICCF/types.d.ts +0 -1
  17. package/built/src/ICCF/utils.d.ts +0 -1
  18. package/built/src/ICCF/utils.js +3 -1
  19. package/built/src/ICCF/utils.js.map +1 -1
  20. package/built/src/blockchainClient/blockchainClient.js +10 -10
  21. package/built/src/blockchainClient/blockchainClient.js.map +1 -1
  22. package/built/src/blockchainClient/errors.d.ts +0 -1
  23. package/built/src/blockchainClient/failoverStrategies.d.ts +5 -4
  24. package/built/src/blockchainClient/failoverStrategies.js +93 -55
  25. package/built/src/blockchainClient/failoverStrategies.js.map +1 -1
  26. package/built/src/blockchainClient/httpUtil.d.ts +0 -1
  27. package/built/src/blockchainClient/httpUtil.js +7 -2
  28. package/built/src/blockchainClient/httpUtil.js.map +1 -1
  29. package/built/src/blockchainClient/interface.d.ts +0 -1
  30. package/built/src/blockchainClient/nodeManager.d.ts +10 -7
  31. package/built/src/blockchainClient/nodeManager.js +47 -20
  32. package/built/src/blockchainClient/nodeManager.js.map +1 -1
  33. package/built/src/blockchainClient/requestWithFailoverStrategy.d.ts +0 -1
  34. package/built/src/blockchainClient/requestWithFailoverStrategy.js +2 -2
  35. package/built/src/blockchainClient/requestWithFailoverStrategy.js.map +1 -1
  36. package/built/src/blockchainClient/types.d.ts +2 -1
  37. package/built/src/blockchainClient/utils.d.ts +1 -2
  38. package/built/src/blockchainClient/utils.js +20 -15
  39. package/built/src/blockchainClient/utils.js.map +1 -1
  40. package/built/src/blockchainClient/validation/anchoringTransaction.d.ts +6 -7
  41. package/built/src/blockchainClient/validation/blockIdentifier.d.ts +2 -2
  42. package/built/src/blockchainClient/validation/blockIdentifier.js +4 -4
  43. package/built/src/blockchainClient/validation/blockIdentifier.js.map +1 -1
  44. package/built/src/blockchainClient/validation/bufferSchema.d.ts +1 -2
  45. package/built/src/blockchainClient/validation/networkSettings.d.ts +2 -2
  46. package/built/src/blockchainClient/validation/networkSettings.js +2 -2
  47. package/built/src/blockchainClient/validation/networkSettings.js.map +1 -1
  48. package/built/src/blockchainClient/validation/signMethod.d.ts +12 -13
  49. package/built/src/blockchainClient/validation/txRid.d.ts +1 -2
  50. package/built/src/encryption/encryption.d.ts +0 -1
  51. package/built/src/encryption/errors.d.ts +0 -1
  52. package/built/src/encryption/types.d.ts +0 -1
  53. package/built/src/formatter.d.ts +1 -2
  54. package/built/src/formatter.js +3 -4
  55. package/built/src/formatter.js.map +1 -1
  56. package/built/src/gtv/index.d.ts +1 -2
  57. package/built/src/gtv/types.d.ts +0 -1
  58. package/built/src/gtx/gtx.d.ts +0 -1
  59. package/built/src/gtx/gtx.js +2 -1
  60. package/built/src/gtx/gtx.js.map +1 -1
  61. package/built/src/gtx/serialization.d.ts +0 -1
  62. package/built/src/gtx/types.d.ts +0 -1
  63. package/built/src/utils/bufferUtils.d.ts +6 -0
  64. package/built/src/utils/bufferUtils.js +9 -0
  65. package/built/src/utils/bufferUtils.js.map +1 -0
  66. package/built/src/utils/calculateTransactionRid.d.ts +0 -1
  67. package/built/src/utils/decodeTransactionToGtx.d.ts +0 -1
  68. package/built/src/utils/encodeTransaction.d.ts +0 -1
  69. package/built/src/utils/http-utils.d.ts +19 -0
  70. package/built/src/utils/http-utils.js +36 -0
  71. package/built/src/utils/http-utils.js.map +1 -0
  72. package/built/test/common/mocks.d.ts +23 -24
  73. package/built/test/common/setups.d.ts +3 -4
  74. package/built/test/common/signatures.d.ts +9 -10
  75. package/built/test/common/validationMocks.d.ts +2 -3
  76. package/built/test/integration/clientQuery.test.js.map +1 -1
  77. package/built/test/integration/clientSendTransaction.test.js +1 -1
  78. package/built/test/integration/clientSendTransaction.test.js.map +1 -1
  79. package/built/test/integration/createClientIntegration.test.js +5 -21
  80. package/built/test/integration/createClientIntegration.test.js.map +1 -1
  81. package/built/test/integration/failoverStrategiesWithSmartTimeouts.test.d.ts +1 -0
  82. package/built/test/integration/failoverStrategiesWithSmartTimeouts.test.js +140 -0
  83. package/built/test/integration/failoverStrategiesWithSmartTimeouts.test.js.map +1 -0
  84. package/built/test/manual/iccfManually.test.js +2 -2
  85. package/built/test/manual/iccfManually.test.js.map +1 -1
  86. package/built/test/pcctf/helpers.js +2 -2
  87. package/built/test/pcctf/helpers.js.map +1 -1
  88. package/built/test/unit/ICCF/iccf.test.js +7 -4
  89. package/built/test/unit/ICCF/iccf.test.js.map +1 -1
  90. package/built/test/unit/ICCF/iccfProofMaterialBuilder.test.js +2 -2
  91. package/built/test/unit/failoverStrategies.test.js +36 -15
  92. package/built/test/unit/failoverStrategies.test.js.map +1 -1
  93. package/built/test/unit/networkErrorDetection.test.d.ts +1 -0
  94. package/built/test/unit/networkErrorDetection.test.js +433 -0
  95. package/built/test/unit/networkErrorDetection.test.js.map +1 -0
  96. package/built/test/unit/nodeMananger.test.js +3 -2
  97. package/built/test/unit/nodeMananger.test.js.map +1 -1
  98. package/built/test/unit/smartTimeouts.test.d.ts +1 -0
  99. package/built/test/unit/smartTimeouts.test.js +296 -0
  100. package/built/test/unit/smartTimeouts.test.js.map +1 -0
  101. package/built/test/unit/stickyNode.test.js +13 -13
  102. package/built/test/unit/stickyNode.test.js.map +1 -1
  103. package/built/test/unit/universalNodeRecovery.test.d.ts +1 -0
  104. package/built/test/unit/universalNodeRecovery.test.js +283 -0
  105. package/built/test/unit/universalNodeRecovery.test.js.map +1 -0
  106. package/built/umd/index.js +19070 -17625
  107. package/built/umd/index.js.map +1 -1
  108. package/changelog.md +31 -1
  109. package/package.json +11 -8
@@ -106,6 +106,14 @@ function isRawGtx(value) {
106
106
  return result.success;
107
107
  }
108
108
 
109
+ /**
110
+ * Type guard to check if a value is a Buffer instance.
111
+ * Works correctly with Buffer imported from the 'buffer' package.
112
+ */
113
+ function isBuffer(value) {
114
+ return buffer.Buffer.isBuffer(value);
115
+ }
116
+
109
117
  function pgBytes(buffer$1) {
110
118
  if (!buffer.Buffer.isBuffer(buffer$1)) {
111
119
  throw new PgBytesInputException(buffer$1);
@@ -143,12 +151,10 @@ class PgBytesInputException extends Error {
143
151
  }
144
152
  }
145
153
  function ensureBuffer(value) {
146
- if (value instanceof buffer.Buffer) {
154
+ if (isBuffer(value)) {
147
155
  return value;
148
156
  }
149
- else {
150
- return toBuffer(value);
151
- }
157
+ return toBuffer(value);
152
158
  }
153
159
  function ensureString(value) {
154
160
  if (typeof value === "string") {
@@ -615,7 +621,7 @@ function gtxToRawGtx(gtx) {
615
621
  }
616
622
  function sign(gtx, privOrSigProv, merkleHashVersion, pubKey) {
617
623
  return __awaiter$9(this, void 0, void 0, function* () {
618
- if (privOrSigProv instanceof buffer.Buffer) {
624
+ if (isBuffer(privOrSigProv)) {
619
625
  const digestToSign = getDigestToSign(gtx, merkleHashVersion);
620
626
  const signature = signDigest(digestToSign, privOrSigProv);
621
627
  return addSignature(pubKey || makeKeyPair(privOrSigProv).pubKey, signature, gtx);
@@ -1024,6 +1030,21 @@ var Method;
1024
1030
  Method["POST"] = "post";
1025
1031
  })(Method || (Method = {}));
1026
1032
 
1033
+ class NetworkNode {
1034
+ constructor(url) {
1035
+ this.availabilityDate = 0;
1036
+ this.url = url;
1037
+ }
1038
+ isAvailable() {
1039
+ return Date.now() >= this.availabilityDate;
1040
+ }
1041
+ makeUnavailable(duration) {
1042
+ this.availabilityDate = Date.now() + duration;
1043
+ }
1044
+ makeAvailable() {
1045
+ this.availabilityDate = 0;
1046
+ }
1047
+ }
1027
1048
  const shuffleArray = (array) => {
1028
1049
  const shuffledArray = [...array];
1029
1050
  for (let i = shuffledArray.length - 1; i > 0; i--) {
@@ -1033,20 +1054,34 @@ const shuffleArray = (array) => {
1033
1054
  return shuffledArray;
1034
1055
  };
1035
1056
  const createNodeManager = ({ nodeUrls, useStickyNode = false, unavailableDuration = 5000, }) => {
1036
- const nodes = nodeUrls.map(url => ({
1037
- url,
1038
- whenAvailable: 0,
1039
- isAvailable: true,
1040
- }));
1057
+ const nodes = nodeUrls.map(url => new NetworkNode(url));
1041
1058
  return {
1042
1059
  nodes,
1043
1060
  stickedNode: null,
1044
1061
  useStickyNode: useStickyNode,
1045
1062
  lastUsedNode: null,
1046
- getAvailableNodes() {
1047
- const shuffledAvailableNodes = shuffleArray(this.nodes.filter((node) => node.isAvailable));
1063
+ getAvailableNodes(customRecoveryThreshold) {
1064
+ const availableNodes = this.nodes.filter((node) => node.isAvailable());
1065
+ if (this.nodes.length >= 3) {
1066
+ // Default to conservative threshold (2x formula) if no custom threshold provided
1067
+ const recoveryThreshold = customRecoveryThreshold !== null && customRecoveryThreshold !== void 0 ? customRecoveryThreshold : this.nodes.length - Math.floor((2 * (this.nodes.length - 1)) / 3);
1068
+ if (availableNodes.length < recoveryThreshold) {
1069
+ debug(`Auto-recovery: ${availableNodes.length} < ${recoveryThreshold} nodes (${this.nodes.length} total)`);
1070
+ const previousStickyUrl = this.stickedNode;
1071
+ this.makeAllNodesAvailable();
1072
+ if (this.useStickyNode && previousStickyUrl) {
1073
+ if (previousStickyUrl) {
1074
+ this.setStickyNode(previousStickyUrl);
1075
+ info(`Sticky node preserved during recovery: ${previousStickyUrl}`);
1076
+ }
1077
+ }
1078
+ const updatedAvailableNodes = this.nodes.filter((node) => node.isAvailable());
1079
+ return shuffleArray(updatedAvailableNodes);
1080
+ }
1081
+ }
1082
+ const shuffledAvailableNodes = shuffleArray(availableNodes);
1048
1083
  // set sticky node as the first node, and then shuffle the rest
1049
- if (useStickyNode && this.stickedNode && this.stickedNode.isAvailable) {
1084
+ if (useStickyNode && this.stickedNode && this.stickedNode.isAvailable()) {
1050
1085
  const nodesWithoutSticky = shuffledAvailableNodes.filter(node => node !== this.stickedNode);
1051
1086
  return [this.stickedNode, ...nodesWithoutSticky];
1052
1087
  }
@@ -1066,7 +1101,7 @@ const createNodeManager = ({ nodeUrls, useStickyNode = false, unavailableDuratio
1066
1101
  const index = Math.floor(Math.random() * nodes.length);
1067
1102
  const node = nodes[index];
1068
1103
  this.lastUsedNode = node;
1069
- if (!useStickyNode) {
1104
+ if (!this.useStickyNode) {
1070
1105
  return node;
1071
1106
  }
1072
1107
  if (!this.stickedNode) {
@@ -1077,21 +1112,18 @@ const createNodeManager = ({ nodeUrls, useStickyNode = false, unavailableDuratio
1077
1112
  return this.stickedNode;
1078
1113
  },
1079
1114
  makeAllNodesAvailable() {
1080
- this.nodes = this.nodes.map((node) => {
1081
- return Object.assign(Object.assign({}, node), { isAvailable: true, whenAvailable: 0 });
1082
- });
1115
+ for (const node of this.nodes) {
1116
+ node.makeAvailable();
1117
+ }
1083
1118
  },
1084
- makeNodeUnavailable(nodeUrl) {
1119
+ makeNodeUnavailable(nodeUrl, duration = unavailableDuration) {
1085
1120
  if (this.stickedNode && this.stickedNode.url === nodeUrl) {
1086
1121
  this.stickedNode = null;
1087
1122
  }
1088
- const updatedNodes = this.nodes.map((node) => {
1089
- if (node.url === nodeUrl) {
1090
- return Object.assign(Object.assign({}, node), { isAvailable: false, whenAvailable: Date.now() + unavailableDuration });
1091
- }
1092
- return node;
1093
- });
1094
- this.nodes = updatedNodes;
1123
+ const invalidNode = this.nodes.find((node) => node.url === nodeUrl);
1124
+ if (!invalidNode)
1125
+ return;
1126
+ invalidNode.makeUnavailable(duration);
1095
1127
  },
1096
1128
  };
1097
1129
  };
@@ -1385,7 +1417,7 @@ function post(path, endpoint, requestBody) {
1385
1417
  try {
1386
1418
  const requestOptions = {
1387
1419
  method: "post",
1388
- body: requestBody,
1420
+ body: new Uint8Array(requestBody),
1389
1421
  headers: {
1390
1422
  Accept: "application/octet-stream",
1391
1423
  "Content-Type": "application/octet-stream",
@@ -1434,9 +1466,14 @@ function constructBufferResponseBody(response) {
1434
1466
  });
1435
1467
  }
1436
1468
  function createResponseObject(error, statusCode, rspBody, transactionTimestamp) {
1469
+ let finalStatusCode = statusCode;
1470
+ // Handle browser network errors as a specific status code for smart timeout logic
1471
+ if (error && !statusCode && !rspBody) {
1472
+ finalStatusCode = 502; // Treat as Bad Gateway for timeout purposes
1473
+ }
1437
1474
  const responseObject = {
1438
1475
  error,
1439
- statusCode,
1476
+ statusCode: finalStatusCode,
1440
1477
  rspBody,
1441
1478
  };
1442
1479
  if (transactionTimestamp) {
@@ -1445,6 +1482,42 @@ function createResponseObject(error, statusCode, rspBody, transactionTimestamp)
1445
1482
  return responseObject;
1446
1483
  }
1447
1484
 
1485
+ function isQueryNotFoundError(error) {
1486
+ return (typeof error === "object" &&
1487
+ error !== null &&
1488
+ "code" in error &&
1489
+ error.code === "QUERY_NOT_FOUND");
1490
+ }
1491
+ function isHttpStatusError(error) {
1492
+ return (typeof error === "object" &&
1493
+ error !== null &&
1494
+ "status" in error &&
1495
+ typeof error.status === "number");
1496
+ }
1497
+ function isNetworkError(error) {
1498
+ return (typeof error === "object" && error !== null && "code" in error && typeof error.code === "string");
1499
+ }
1500
+ function isRetriableClientError(response) {
1501
+ if (typeof response === "object" && response !== null) {
1502
+ // Check error field first
1503
+ if ("error" in response && isQueryNotFoundError(response.error)) {
1504
+ return false;
1505
+ }
1506
+ // Check rspBody if no error
1507
+ if ("rspBody" in response && isQueryNotFoundError(response.rspBody)) {
1508
+ return false;
1509
+ }
1510
+ }
1511
+ return true;
1512
+ }
1513
+ const isClientErrorStatusCode = (status) => {
1514
+ return status >= 400 && status < 500;
1515
+ };
1516
+ const isServerErrorStatusCode = (status) => {
1517
+ return status >= 500 && status < 600;
1518
+ };
1519
+ const isSuccessfulStatusCode = (statusCode) => statusCode >= 200 && statusCode < 300;
1520
+
1448
1521
  var __awaiter$7 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
1449
1522
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
1450
1523
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -1454,28 +1527,49 @@ var __awaiter$7 = (undefined && undefined.__awaiter) || function (thisArg, _argu
1454
1527
  step((generator = generator.apply(thisArg, _arguments || [])).next());
1455
1528
  });
1456
1529
  };
1457
- const isSuccessfullRequest = (statusCode) => statusCode >= 200 && statusCode < 300;
1458
- const hasClientError = (statusCode) => statusCode >= 400 && statusCode < 500;
1459
- const hasServerError = (statusCode) => statusCode >= 500 && statusCode < 600;
1460
- function abortOnError({ method, path, config, postObject, }) {
1461
- return __awaiter$7(this, void 0, void 0, function* () {
1530
+ function getUnreachableDuration(statusCode, error) {
1531
+ if (isNetworkError(error)) {
1532
+ const { code } = error;
1533
+ if (code === "ENOTFOUND")
1534
+ return 5 * 60 * 1000;
1535
+ if (code === "ECONNREFUSED")
1536
+ return 5 * 60 * 1000;
1537
+ }
1538
+ const status = isHttpStatusError(error) ? error.status : statusCode;
1539
+ switch (status) {
1540
+ case 500:
1541
+ return 10 * 1000; // Server restart: 10s
1542
+ case 502:
1543
+ return 30 * 1000; // Gateway: 30s
1544
+ case 503:
1545
+ return 2 * 1000; // Load: 2s
1546
+ case 504:
1547
+ return 60 * 1000; // Timeout: 60s
1548
+ default:
1549
+ return 5 * 1000;
1550
+ }
1551
+ }
1552
+ function abortOnError(_a) {
1553
+ return __awaiter$7(this, arguments, void 0, function* ({ method, path, config, postObject, }) {
1462
1554
  return yield retryRequest({
1463
1555
  method,
1464
1556
  path,
1465
1557
  config,
1466
1558
  postObject,
1467
- validateStatusCode: statuscode => !hasServerError(statuscode),
1559
+ useNextNodeOnError: false,
1560
+ recoveryThreshold: config.recoveryThreshold, // Use user config or let nodeManager use default
1468
1561
  });
1469
1562
  });
1470
1563
  }
1471
- function tryNextOnError({ method, path, config, postObject, }) {
1472
- return __awaiter$7(this, void 0, void 0, function* () {
1564
+ function tryNextOnError(_a) {
1565
+ return __awaiter$7(this, arguments, void 0, function* ({ method, path, config, postObject, }) {
1473
1566
  return yield retryRequest({
1474
1567
  method,
1475
1568
  path,
1476
1569
  config,
1477
1570
  postObject,
1478
- validateStatusCode: statusCode => !hasClientError(statusCode) && !hasServerError(statusCode),
1571
+ useNextNodeOnError: true,
1572
+ recoveryThreshold: config.recoveryThreshold,
1479
1573
  });
1480
1574
  });
1481
1575
  }
@@ -1485,59 +1579,57 @@ const errorMessages = {
1485
1579
  function calculateBftMajorityThreshold(endpointPoolLength) {
1486
1580
  return endpointPoolLength - (endpointPoolLength - 1) / 3;
1487
1581
  }
1488
- function queryMajority({ method, path, config, postObject, }) {
1489
- return __awaiter$7(this, void 0, void 0, function* () {
1582
+ function queryMajority(_a) {
1583
+ return __awaiter$7(this, arguments, void 0, function* ({ method, path, config, postObject, }) {
1584
+ var _b;
1490
1585
  // Set up constants
1491
1586
  const bftMajorityThreshold = calculateBftMajorityThreshold(config.endpointPool.length);
1492
1587
  const failureThreshold = config.endpointPool.length - bftMajorityThreshold + 1;
1493
1588
  const { nodeManager } = config;
1494
1589
  const timeout = 15000;
1495
- const availableNodes = nodeManager.getAvailableNodes();
1496
- // If the available nodes are less than bfthMajorityThreshold, set all nodes as reachable again.
1497
- if (availableNodes.length < bftMajorityThreshold) {
1498
- nodeManager.makeAllNodesAvailable();
1499
- }
1590
+ const availableNodes = nodeManager.getAvailableNodes((_b = config.recoveryThreshold) !== null && _b !== void 0 ? _b : bftMajorityThreshold);
1500
1591
  const outcomes = [];
1501
- const promises = nodeManager.getAvailableNodes().map(node => {
1502
- return handleRequest(method, path, node.url, postObject)
1503
- .then(response => {
1592
+ const promises = availableNodes.map((node) => __awaiter$7(this, void 0, void 0, function* () {
1593
+ try {
1594
+ const response = yield handleRequest(method, path, node.url, postObject);
1504
1595
  const { statusCode } = response;
1505
- if (statusCode && isSuccessfullRequest(statusCode)) {
1596
+ if (statusCode && isSuccessfulStatusCode(statusCode)) {
1506
1597
  outcomes.push({ type: "SUCCESS", result: response });
1507
1598
  }
1508
1599
  else {
1509
- if (statusCode && hasServerError(statusCode)) {
1510
- nodeManager.makeNodeUnavailable(node.url);
1600
+ if (statusCode && isServerErrorStatusCode(statusCode)) {
1601
+ const duration = getUnreachableDuration(statusCode, response.error);
1602
+ nodeManager.makeNodeUnavailable(node.url, duration);
1511
1603
  }
1512
1604
  outcomes.push({ type: "FAILURE", result: response });
1513
1605
  }
1514
1606
  return response;
1515
- })
1516
- .catch((error) => {
1607
+ }
1608
+ catch (error) {
1517
1609
  outcomes.push({ type: "ERROR", result: error });
1518
1610
  return error;
1519
- });
1520
- });
1611
+ }
1612
+ }));
1521
1613
  let remainingPromises = promises;
1522
1614
  // Wait for the necessary majority of outcomes to come back or for the timeout to be reached, whichever comes first.
1523
1615
  for (let i = 0; i < bftMajorityThreshold; i++) {
1524
1616
  remainingPromises = yield racePromisesWithTimeout(remainingPromises, timeout);
1525
1617
  }
1526
1618
  // Evaluate the outcomes
1527
- const successfullOutcomes = outcomes.filter(outcome => outcome.type === "SUCCESS");
1619
+ const successfulOutcomes = outcomes.filter(outcome => outcome.type === "SUCCESS");
1528
1620
  const failureOutcomes = outcomes.filter(outcome => outcome.type === "FAILURE");
1529
1621
  const errorOutcomes = outcomes.filter(outcome => outcome.type === "ERROR");
1530
1622
  // group all of the same responses together into groups and count each groups size
1531
- const groupedSuccessfullResponses = groupResponses(successfullOutcomes);
1623
+ const groupedSuccessfulResponses = groupResponses(successfulOutcomes);
1532
1624
  // validate the responses
1533
1625
  // eslint-disable-next-line no-constant-condition
1534
1626
  while (true) {
1535
- // Successfull majority response was found
1536
- if (groupedSuccessfullResponses.maxNumberOfEqualResponses() >= bftMajorityThreshold) {
1537
- if (groupedSuccessfullResponses.numberOfDistinctResponses() > 1) {
1627
+ // Successful majority response was found
1628
+ if (groupedSuccessfulResponses.maxNumberOfEqualResponses() >= bftMajorityThreshold) {
1629
+ if (groupedSuccessfulResponses.numberOfDistinctResponses() > 1) {
1538
1630
  warning(`Got disagreeing responses, but could still reach BFT majority`);
1539
1631
  }
1540
- return groupedSuccessfullResponses.majorityResponse();
1632
+ return groupedSuccessfulResponses.majorityResponse();
1541
1633
  }
1542
1634
  // Too many failures or errors to be able to reach a consensus
1543
1635
  // If the number of failures and errors is greater than the failure threshold, return first failure, if any, otherwise throw the first error.
@@ -1558,22 +1650,24 @@ function queryMajority({ method, path, config, postObject, }) {
1558
1650
  }
1559
1651
  });
1560
1652
  }
1561
- function singleEndpoint({ method, path, config, postObject, }) {
1562
- return __awaiter$7(this, void 0, void 0, function* () {
1653
+ function singleEndpoint(_a) {
1654
+ return __awaiter$7(this, arguments, void 0, function* ({ method, path, config, postObject, }) {
1563
1655
  let statusCode = null;
1564
1656
  let rspBody = null;
1565
1657
  let error = null;
1566
1658
  let transactionTimestamp = undefined;
1567
1659
  const endpoint = config.nodeManager.getNode();
1568
1660
  if (!endpoint) {
1569
- throw new Error("Cannot get endpoint. Node not found!");
1661
+ throw new Error("No nodes available after recovery attempt. Check node configuration.");
1570
1662
  }
1571
1663
  for (let attempt = 0; attempt < config.attemptsPerEndpoint; attempt++) {
1572
1664
  const response = yield handleRequest(method, path, endpoint.url, postObject);
1573
1665
  if (response) {
1574
1666
  ({ error, statusCode, rspBody, transactionTimestamp } = response);
1575
1667
  }
1576
- const isError = statusCode ? hasServerError(statusCode) || hasClientError(statusCode) : false;
1668
+ const isError = statusCode
1669
+ ? isClientErrorStatusCode(statusCode) || isServerErrorStatusCode(statusCode)
1670
+ : false;
1577
1671
  if (!isError && !error) {
1578
1672
  return { error, statusCode, rspBody, transactionTimestamp };
1579
1673
  }
@@ -1583,38 +1677,54 @@ function singleEndpoint({ method, path, config, postObject, }) {
1583
1677
  return { error, statusCode, rspBody, transactionTimestamp };
1584
1678
  });
1585
1679
  }
1586
- function retryRequest({ method, path, config, postObject, validateStatusCode, }) {
1587
- var _a, _b, _c;
1588
- return __awaiter$7(this, void 0, void 0, function* () {
1680
+ function retryRequest(_a) {
1681
+ return __awaiter$7(this, arguments, void 0, function* ({ method, path, config, postObject, useNextNodeOnError, recoveryThreshold, }) {
1682
+ var _b, _c, _d;
1589
1683
  let statusCode = null;
1590
1684
  let rspBody = null;
1591
1685
  let error = null;
1592
1686
  let transactionTimestamp = undefined;
1593
1687
  const { nodeManager } = config;
1594
- const availableNodes = nodeManager.getAvailableNodes();
1595
- for (const endpoint of availableNodes) {
1688
+ const availableNodes = nodeManager.getAvailableNodes(recoveryThreshold);
1689
+ for (const node of availableNodes) {
1596
1690
  for (let attempt = 0; attempt < config.attemptsPerEndpoint; attempt++) {
1597
- const response = yield handleRequest(method, path, endpoint.url, postObject);
1598
- error = (_a = response === null || response === void 0 ? void 0 : response.error) !== null && _a !== void 0 ? _a : null;
1599
- statusCode = (_b = response === null || response === void 0 ? void 0 : response.statusCode) !== null && _b !== void 0 ? _b : null;
1600
- rspBody = (_c = response === null || response === void 0 ? void 0 : response.rspBody) !== null && _c !== void 0 ? _c : null;
1691
+ const response = yield handleRequest(method, path, node.url, postObject);
1692
+ error = (_b = response === null || response === void 0 ? void 0 : response.error) !== null && _b !== void 0 ? _b : null;
1693
+ statusCode = (_c = response === null || response === void 0 ? void 0 : response.statusCode) !== null && _c !== void 0 ? _c : null;
1694
+ rspBody = (_d = response === null || response === void 0 ? void 0 : response.rspBody) !== null && _d !== void 0 ? _d : null;
1601
1695
  transactionTimestamp = response === null || response === void 0 ? void 0 : response.transactionTimestamp;
1602
- const isStatusCodeValid = statusCode ? validateStatusCode(statusCode) : false;
1603
- const isServerError = statusCode ? hasServerError(statusCode) : false;
1604
- if (isStatusCodeValid && !error) {
1696
+ const isServerError = !!statusCode && isServerErrorStatusCode(statusCode);
1697
+ const isClientError = !!statusCode && isClientErrorStatusCode(statusCode);
1698
+ if (!isServerError && !isClientError && statusCode) {
1605
1699
  // Find a way to have this handled more elegantly in the node manager.
1606
- nodeManager.lastUsedNode = endpoint;
1607
- if (nodeManager.stickedNode !== endpoint) {
1608
- nodeManager.setStickyNode(endpoint);
1700
+ nodeManager.lastUsedNode = node;
1701
+ if (nodeManager.stickedNode !== node) {
1702
+ node.makeAvailable();
1703
+ nodeManager.setStickyNode(node);
1609
1704
  }
1610
1705
  return { error, statusCode, rspBody, transactionTimestamp };
1611
1706
  }
1612
1707
  if (isServerError) {
1613
- // nodeManager.makeNodeUnavailable(endpoint.url);
1614
- info(`server error on ${endpoint.url}`);
1708
+ const duration = getUnreachableDuration(statusCode !== null && statusCode !== void 0 ? statusCode : undefined, response.error);
1709
+ nodeManager.makeNodeUnavailable(node.url, duration);
1710
+ info(`request failed with server error on ${node.url} trying next node`);
1711
+ break;
1712
+ }
1713
+ if (isClientError) {
1714
+ if (!useNextNodeOnError || !isRetriableClientError(response)) {
1715
+ return { error, statusCode, rspBody, transactionTimestamp };
1716
+ }
1717
+ if (!nodeManager.useStickyNode) {
1718
+ info(`request failed client error on ${node.url} trying next node`);
1719
+ break;
1720
+ }
1721
+ // Otherwise continue with next attempt for this node
1722
+ }
1723
+ info(`${method} request failed on ${node.url}. Attempt: ${attempt + 1} / ${config.attemptsPerEndpoint}`);
1724
+ // if statement is workaround for test utils
1725
+ if (config.attemptInterval > 0) {
1726
+ yield sleep(config.attemptInterval);
1615
1727
  }
1616
- info(`${method} request failed on ${endpoint.url}. Attempt: ${attempt + 1} / ${config.attemptsPerEndpoint}`);
1617
- yield sleep(config.attemptInterval);
1618
1728
  }
1619
1729
  }
1620
1730
  return { error, statusCode, rspBody, transactionTimestamp };
@@ -1701,8 +1811,8 @@ var __awaiter$6 = (undefined && undefined.__awaiter) || function (thisArg, _argu
1701
1811
  step((generator = generator.apply(thisArg, _arguments || [])).next());
1702
1812
  });
1703
1813
  };
1704
- function requestWithFailoverStrategy(method, path, config, postObject, forceSingleEndpoint = false) {
1705
- return __awaiter$6(this, void 0, void 0, function* () {
1814
+ function requestWithFailoverStrategy(method_1, path_1, config_1, postObject_1) {
1815
+ return __awaiter$6(this, arguments, void 0, function* (method, path, config, postObject, forceSingleEndpoint = false) {
1706
1816
  switch (config.failoverStrategy) {
1707
1817
  case exports.FailoverStrategy.AbortOnError:
1708
1818
  return yield abortOnError({ method, path, config, postObject });
@@ -1731,8 +1841,8 @@ var __awaiter$5 = (undefined && undefined.__awaiter) || function (thisArg, _argu
1731
1841
  });
1732
1842
  };
1733
1843
  function getClientConfigFromSettings(settings) {
1734
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1735
1844
  return __awaiter$5(this, void 0, void 0, function* () {
1845
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
1736
1846
  const nodeUrlPoolToUse = yield getNodeUrlsFromSettings(settings);
1737
1847
  if (nodeUrlPoolToUse === null || nodeUrlPoolToUse.length === 0) {
1738
1848
  const id = (_b = (_a = settings.blockchainRid) !== null && _a !== void 0 ? _a : settings.blockchainIid) !== null && _b !== void 0 ? _b : "Unknown";
@@ -1745,7 +1855,7 @@ function getClientConfigFromSettings(settings) {
1745
1855
  unavailableDuration: (_d = settings.failOverConfig) === null || _d === void 0 ? void 0 : _d.unreachableDuration,
1746
1856
  });
1747
1857
  const blockchainRidToUse = yield (() => __awaiter$5(this, void 0, void 0, function* () {
1748
- var _k;
1858
+ var _a;
1749
1859
  if (settings.blockchainRid) {
1750
1860
  return settings.blockchainRid;
1751
1861
  }
@@ -1754,13 +1864,13 @@ function getClientConfigFromSettings(settings) {
1754
1864
  nodeManager,
1755
1865
  endpointPool,
1756
1866
  chainId: settings.blockchainIid,
1757
- merkleHashVersion: (_k = settings.merkleHashVersion) !== null && _k !== void 0 ? _k : MERKLE_HASH_VERSIONS.UNSET,
1867
+ merkleHashVersion: (_a = settings.merkleHashVersion) !== null && _a !== void 0 ? _a : MERKLE_HASH_VERSIONS.UNSET,
1758
1868
  });
1759
1869
  }
1760
1870
  throw new MissingBlockchainIdentifierError();
1761
1871
  }))();
1762
1872
  const directoryChainRid = yield (() => __awaiter$5(this, void 0, void 0, function* () {
1763
- var _l;
1873
+ var _a;
1764
1874
  if (settings.directoryChainRid) {
1765
1875
  return settings.directoryChainRid;
1766
1876
  }
@@ -1769,7 +1879,7 @@ function getClientConfigFromSettings(settings) {
1769
1879
  nodeManager,
1770
1880
  endpointPool,
1771
1881
  chainId: directoryChainIid,
1772
- merkleHashVersion: (_l = settings.merkleHashVersion) !== null && _l !== void 0 ? _l : MERKLE_HASH_VERSIONS.UNSET,
1882
+ merkleHashVersion: (_a = settings.merkleHashVersion) !== null && _a !== void 0 ? _a : MERKLE_HASH_VERSIONS.UNSET,
1773
1883
  });
1774
1884
  }))();
1775
1885
  return {
@@ -1802,8 +1912,8 @@ function getMerkleHashVersionFromDapp(config) {
1802
1912
  }
1803
1913
  });
1804
1914
  }
1805
- function nodeDiscovery({ nodeManager, directoryEndpointPool, failOverConfig, blockchainRid, blockchainIid, }) {
1806
- return __awaiter$5(this, void 0, void 0, function* () {
1915
+ function nodeDiscovery(_a) {
1916
+ return __awaiter$5(this, arguments, void 0, function* ({ nodeManager, directoryEndpointPool, failOverConfig, blockchainRid, blockchainIid, }) {
1807
1917
  if (directoryEndpointPool.length === 0) {
1808
1918
  throw new DirectoryNodeUrlPoolException();
1809
1919
  }
@@ -1970,8 +2080,8 @@ const isKeyPair = (keypair) => {
1970
2080
  keypair.pubKey instanceof buffer.Buffer);
1971
2081
  };
1972
2082
  function getNodeUrlsFromSettings(settings) {
1973
- var _a;
1974
2083
  return __awaiter$5(this, void 0, void 0, function* () {
2084
+ var _a;
1975
2085
  if (settings.directoryNodeUrlPool) {
1976
2086
  // If directoryNodeUrlPool is provided, use nodeDiscovery
1977
2087
  const nodeManager = createNodeManager({
@@ -2042,8 +2152,8 @@ const getUrlsFromEndpoints = (endpointPool) => {
2042
2152
  return endpointPool.map(endpoint => endpoint.url);
2043
2153
  };
2044
2154
  function awaitDappConfirmation(txRID, dappStatusPolling, getTransactionStatus) {
2045
- var _a;
2046
2155
  return __awaiter$5(this, void 0, void 0, function* () {
2156
+ var _a;
2047
2157
  let lastKnownResult = null;
2048
2158
  for (let i = 0; i < dappStatusPolling.count; i++) {
2049
2159
  lastKnownResult = yield getTransactionStatus(txRID);
@@ -2059,8 +2169,8 @@ function awaitDappConfirmation(txRID, dappStatusPolling, getTransactionStatus) {
2059
2169
  });
2060
2170
  }
2061
2171
  function awaitClusterAnchoringChainConfirmation(txRID, clusterAnchoringStatusPolling, getClusterAnchoringTransactionConfirmation) {
2062
- var _a;
2063
2172
  return __awaiter$5(this, void 0, void 0, function* () {
2173
+ var _a;
2064
2174
  let clusterAnchoringConfirmation;
2065
2175
  for (let i = 0; i < clusterAnchoringStatusPolling.count; i++) {
2066
2176
  clusterAnchoringConfirmation = yield getClusterAnchoringTransactionConfirmation(txRID);
@@ -2083,8 +2193,8 @@ function awaitClusterAnchoringChainConfirmation(txRID, clusterAnchoringStatusPol
2083
2193
  });
2084
2194
  }
2085
2195
  function handleDappConfirmations(transactionRid, doStatusPolling, confirmationLevel, promiEvent, dappStatusPolling, getTransactionStatus, client) {
2086
- var _a, _b;
2087
2196
  return __awaiter$5(this, void 0, void 0, function* () {
2197
+ var _a, _b;
2088
2198
  const transactionReceipt = {
2089
2199
  status: exports.ResponseStatus.Pending,
2090
2200
  statusCode: null,
@@ -2214,6 +2324,7 @@ function handleGetResponse(error$1, statusCode, responseObject, callback) {
2214
2324
  * @param callback the callback function to propagate the error and response back to the caller
2215
2325
  */
2216
2326
  function handlePostResponse(error$1, statusCode, responseObject, callback) {
2327
+ var _a;
2217
2328
  const responseObjectPrintable = convertToPrintable(responseObject);
2218
2329
  debug(`error: ${error$1}, status code: ${statusCode}, response body: ${responseObjectPrintable}`);
2219
2330
  try {
@@ -2221,13 +2332,16 @@ function handlePostResponse(error$1, statusCode, responseObject, callback) {
2221
2332
  error(`In client post(). ${error$1}`);
2222
2333
  callback(error$1, null);
2223
2334
  }
2224
- else if (statusCode != 200) {
2335
+ else if (!statusCode || !isSuccessfulStatusCode(statusCode)) {
2225
2336
  let errorMessage = `Unexpected status code from server. Code: ${statusCode}.`;
2337
+ const errorMessageInResponseBody = !!responseObject && typeof responseObject === "object" && "error" in responseObject
2338
+ ? (_a = responseObject.error) === null || _a === void 0 ? void 0 : _a.toString()
2339
+ : "";
2226
2340
  if (responseObjectPrintable) {
2227
2341
  errorMessage += ` Message: ${responseObjectPrintable}.`;
2228
2342
  }
2229
2343
  error(errorMessage);
2230
- callback(new UnexpectedStatusError(statusCode !== null && statusCode !== void 0 ? statusCode : 400, responseObjectPrintable), responseObject);
2344
+ callback(new UnexpectedStatusError(statusCode !== null && statusCode !== void 0 ? statusCode : 400, errorMessageInResponseBody || responseObjectPrintable), responseObject);
2231
2345
  }
2232
2346
  else {
2233
2347
  info(`Calling responseCallback with responseObject: ${responseObjectPrintable}`);
@@ -2238,8 +2352,8 @@ function handlePostResponse(error$1, statusCode, responseObject, callback) {
2238
2352
  error(`client.handlePostResponse(): Failed to call callback function ${error$1}`);
2239
2353
  }
2240
2354
  }
2241
- function getBlockchainRidFromIid({ endpointPool, chainId, failOverConfig = {}, nodeManager, }) {
2242
- return __awaiter$5(this, void 0, void 0, function* () {
2355
+ function getBlockchainRidFromIid(_a) {
2356
+ return __awaiter$5(this, arguments, void 0, function* ({ endpointPool, chainId, failOverConfig = {}, nodeManager, }) {
2243
2357
  const mergedFailOverConfig = Object.assign(Object.assign({}, defaultFailoverConfig), failOverConfig);
2244
2358
  const config = {
2245
2359
  endpointPool,
@@ -2371,10 +2485,11 @@ function calculateBlockRID(decodedTxProof, merkleHashVersion) {
2371
2485
  }
2372
2486
  // fetch tx from txRID and verifies with secp256k1.ecdsaVerify that txRID and signer creates signatures that are on the blockchain transaction
2373
2487
  function fetchAndVerifyTransaction(sourceClient, txToProveRID, proofHash, txToProveSigners) {
2374
- var _a, _b, _c;
2375
2488
  return __awaiter$4(this, void 0, void 0, function* () {
2489
+ var _a, _b, _c;
2376
2490
  const rawTx = yield sourceClient.getTransaction(txToProveRID);
2377
2491
  const txGtv = decodeValue(rawTx);
2492
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2378
2493
  const fetchedTxHash = gtvHash2(txGtv, sourceClient.config.merkleHashVersion);
2379
2494
  if (buffer.Buffer.compare(fetchedTxHash, proofHash)) {
2380
2495
  // We received another hash for tx RID than what was included in proof
@@ -2385,6 +2500,7 @@ function fetchAndVerifyTransaction(sourceClient, txToProveRID, proofHash, txToPr
2385
2500
  if (txToProveSigners.length != ((_a = fetchedTx.signatures) === null || _a === void 0 ? void 0 : _a.length)) {
2386
2501
  throw new DifferentNumberOfSignersException((_c = (_b = fetchedTx.signatures) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0, txToProveSigners.length);
2387
2502
  }
2503
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2388
2504
  const txRID = getDigestToSign(fetchedTx, sourceClient.config.merkleHashVersion);
2389
2505
  if (buffer.Buffer.compare(txRID, ensureBuffer(txToProveRID))) {
2390
2506
  throw new ProofRidException();
@@ -2451,8 +2567,8 @@ var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _argu
2451
2567
  * @param {string} nodeIdentifierURL - The URL of the node to use.
2452
2568
  * @returns {Promise<IccfProof>} A promise that resolves to an ICCF proof object containing the ICCF proof transaction.
2453
2569
  */
2454
- function createIccfProofTx(directoryClient, txToProveRid, txToProveHash, txToProveSigners, sourceBlockchainRid, targetBlockchainRid, iccfTxSigners = [], forceIntraNetworkIccfOperation = false, merkleHashVersion, nodeIdentifierURL) {
2455
- return __awaiter$3(this, void 0, void 0, function* () {
2570
+ function createIccfProofTx(directoryClient_1, txToProveRid_1, txToProveHash_1, txToProveSigners_1, sourceBlockchainRid_1, targetBlockchainRid_1) {
2571
+ return __awaiter$3(this, arguments, void 0, function* (directoryClient, txToProveRid, txToProveHash, txToProveSigners, sourceBlockchainRid, targetBlockchainRid, iccfTxSigners = [], forceIntraNetworkIccfOperation = false, merkleHashVersion, nodeIdentifierURL) {
2456
2572
  let clientConfiguredToSource;
2457
2573
  if (!nodeIdentifierURL) {
2458
2574
  clientConfiguredToSource = yield createClient({
@@ -2519,6 +2635,7 @@ function getBlockAnchoringTransaction(sourceClient, anchoringClient, txRid, txPr
2519
2635
  if (!confirmationProof) {
2520
2636
  throw Error("Confirmation proof not found");
2521
2637
  }
2638
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
2522
2639
  const blockRid = calculateBlockRID(confirmationProof, sourceClient.config.merkleHashVersion);
2523
2640
  const blockchainRid = sourceClient.config.blockchainRid;
2524
2641
  const anchoringTxResponse = yield awaitGetAnchoringTransactionForBlockRid(anchoringClient, toBuffer(blockchainRid), blockRid, sourceClient.config.clusterAnchoringStatusPolling);
@@ -2695,8 +2812,8 @@ const isBlockIdentifierValid = (blockIdentifier, options) => {
2695
2812
  return { success };
2696
2813
  }
2697
2814
  const { error } = ctx;
2698
- const isInvalidInputType = error.issues.some(({ code }) => code === "invalid_union");
2699
- const isInvalidStringLength = error.issues.some(({ message }) => message === WRONG_STRING_LENGTH);
2815
+ const isInvalidInputType = error === null || error === void 0 ? void 0 : error.issues.some(({ code }) => code === "invalid_union");
2816
+ const isInvalidStringLength = error === null || error === void 0 ? void 0 : error.issues.some(({ message }) => message === WRONG_STRING_LENGTH);
2700
2817
  const message = (() => {
2701
2818
  if (isInvalidInputType) {
2702
2819
  return `Invalid "blockIdentifier" type. Expected string or number, but received ${typeof blockIdentifier}.`;
@@ -2704,7 +2821,7 @@ const isBlockIdentifierValid = (blockIdentifier, options) => {
2704
2821
  if (isInvalidStringLength) {
2705
2822
  return "Parameter 'blockIdentifier' does not have the correct format (64-character hexadecimal string).";
2706
2823
  }
2707
- return error.issues.map(issue => issue.message).join(", ");
2824
+ return error === null || error === void 0 ? void 0 : error.issues.map(issue => issue.message).join(", ");
2708
2825
  })();
2709
2826
  if (throwOnError) {
2710
2827
  throw new Error(message);
@@ -2712,7 +2829,7 @@ const isBlockIdentifierValid = (blockIdentifier, options) => {
2712
2829
  return {
2713
2830
  success,
2714
2831
  error,
2715
- message: error.issues.map(issue => issue.message).join(", "),
2832
+ message: error === null || error === void 0 ? void 0 : error.issues.map(issue => issue.message).join(", "),
2716
2833
  };
2717
2834
  };
2718
2835
 
@@ -2784,8 +2901,8 @@ const validateRestNetworkSettings = (networkSettings, options) => {
2784
2901
  const { throwOnError = false } = options || {};
2785
2902
  const restNetworkSettingsValidationContext = RestNetworkSettingsSchema.safeParse(networkSettings);
2786
2903
  if ("error" in restNetworkSettingsValidationContext) {
2787
- const { error: { issues }, } = restNetworkSettingsValidationContext;
2788
- const errorMessage = issues.map(({ message, path }) => `${path[0]}: ${message}`).join(", ");
2904
+ const { error: { issues } = {} } = restNetworkSettingsValidationContext;
2905
+ const errorMessage = issues === null || issues === void 0 ? void 0 : issues.map(({ message, path }) => `${path[0]}: ${message}`).join(", ");
2789
2906
  if (throwOnError) {
2790
2907
  throw new Error(errorMessage);
2791
2908
  }
@@ -3082,8 +3199,8 @@ function createClient(settings) {
3082
3199
  _transaction.operations = [..._transaction.operations, noOperation];
3083
3200
  return _transaction;
3084
3201
  },
3085
- getTransactionsInfo(limit = 25, beforeTime, callback, afterTime, signerPubKey) {
3086
- return __awaiter$1(this, void 0, void 0, function* () {
3202
+ getTransactionsInfo() {
3203
+ return __awaiter$1(this, arguments, void 0, function* (limit = 25, beforeTime, callback, afterTime, signerPubKey) {
3087
3204
  const beforeTimeQueryParam = beforeTime ? `&before-time=${beforeTime.getTime()}` : "";
3088
3205
  const afterTimeQueryParam = afterTime ? `&after-time=${afterTime.getTime()}` : "";
3089
3206
  const signerQueryParam = signerPubKey ? `&signer=${signerPubKey}` : "";
@@ -3140,8 +3257,8 @@ function createClient(settings) {
3140
3257
  });
3141
3258
  },
3142
3259
  getTransactionConfirmationLevel(transactionRid, callback) {
3143
- var _a;
3144
3260
  return __awaiter$1(this, void 0, void 0, function* () {
3261
+ var _a;
3145
3262
  try {
3146
3263
  const client = this;
3147
3264
  const dappConfirmation = yield client.getTransactionStatus(transactionRid);
@@ -3202,8 +3319,8 @@ function createClient(settings) {
3202
3319
  });
3203
3320
  });
3204
3321
  },
3205
- getBlockInfo(blockIdentifier, txs = false, callback) {
3206
- return __awaiter$1(this, void 0, void 0, function* () {
3322
+ getBlockInfo(blockIdentifier_1) {
3323
+ return __awaiter$1(this, arguments, void 0, function* (blockIdentifier, txs = false, callback) {
3207
3324
  isBlockIdentifierValid(blockIdentifier, { throwOnError: true });
3208
3325
  const queryString = typeof blockIdentifier === "string" ? blockIdentifier : `height/${blockIdentifier}`;
3209
3326
  const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `blocks/${config.blockchainRid}/${queryString}?txs=${txs}`, config);
@@ -3215,8 +3332,8 @@ function createClient(settings) {
3215
3332
  });
3216
3333
  });
3217
3334
  },
3218
- getLatestBlock(txs = false, callback) {
3219
- return __awaiter$1(this, void 0, void 0, function* () {
3335
+ getLatestBlock() {
3336
+ return __awaiter$1(this, arguments, void 0, function* (txs = false, callback) {
3220
3337
  const shouldIncludeFullTransaction = txs ? `&txs=${txs}` : "";
3221
3338
  const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `blocks/${config.blockchainRid}?limit=1${shouldIncludeFullTransaction}`, config, undefined, true);
3222
3339
  const indexOfLatestBlock = 0;
@@ -3228,8 +3345,8 @@ function createClient(settings) {
3228
3345
  });
3229
3346
  });
3230
3347
  },
3231
- getBlocks({ limit, beforeTime, afterTime, beforeHeight, afterHeight, excludeEmpty, txs, callback, } = {}) {
3232
- return __awaiter$1(this, void 0, void 0, function* () {
3348
+ getBlocks() {
3349
+ return __awaiter$1(this, arguments, void 0, function* ({ limit, beforeTime, afterTime, beforeHeight, afterHeight, excludeEmpty, txs, callback, } = {}) {
3233
3350
  const searchValues = {
3234
3351
  limit,
3235
3352
  txs,
@@ -3423,8 +3540,8 @@ function createClient(settings) {
3423
3540
  });
3424
3541
  }
3425
3542
  function createStickyNodeClient(client) {
3426
- var _a;
3427
3543
  return __awaiter$1(this, void 0, void 0, function* () {
3544
+ var _a;
3428
3545
  if (!client.config.nodeManager.lastUsedNode) {
3429
3546
  throw new Error("No last used node found; cannot create sticky node client");
3430
3547
  }