postchain-client 2.1.2 → 2.1.3
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.
- package/built/cjs/index.js +3433 -2559
- package/built/cjs/index.js.map +1 -1
- package/built/esm/index.js +4616 -3293
- package/built/esm/index.js.map +1 -1
- package/built/index.js +108 -30
- package/built/index.js.map +1 -1
- package/built/mocks/handlers.js +70 -67
- package/built/mocks/handlers.js.map +1 -1
- package/built/mocks/servers.d.ts +1 -1
- package/built/mocks/servers.js +6 -3
- package/built/mocks/servers.js.map +1 -1
- package/built/resources/testData.js +14 -11
- package/built/resources/testData.js.map +1 -1
- package/built/src/ICCF/IccfProofTxMaterialBuilder.js +35 -29
- package/built/src/ICCF/IccfProofTxMaterialBuilder.js.map +1 -1
- package/built/src/ICCF/error.js +21 -11
- package/built/src/ICCF/error.js.map +1 -1
- package/built/src/ICCF/interfaces.js +2 -1
- package/built/src/ICCF/types.js +2 -1
- package/built/src/ICCF/utils.js +50 -40
- package/built/src/ICCF/utils.js.map +1 -1
- package/built/src/blockchainClient/blockchainClient.js +180 -141
- package/built/src/blockchainClient/blockchainClient.js.map +1 -1
- package/built/src/blockchainClient/clientStub.js +19 -16
- package/built/src/blockchainClient/clientStub.js.map +1 -1
- package/built/src/blockchainClient/enums.js +15 -12
- package/built/src/blockchainClient/enums.js.map +1 -1
- package/built/src/blockchainClient/errors.js +30 -15
- package/built/src/blockchainClient/errors.js.map +1 -1
- package/built/src/blockchainClient/failoverStrategies.js +75 -30
- package/built/src/blockchainClient/failoverStrategies.js.map +1 -1
- package/built/src/blockchainClient/httpUtil.js +45 -9
- package/built/src/blockchainClient/httpUtil.js.map +1 -1
- package/built/src/blockchainClient/interface.js +2 -1
- package/built/src/blockchainClient/nodeManager.js +41 -3
- package/built/src/blockchainClient/nodeManager.js.map +1 -1
- package/built/src/blockchainClient/requestWithFailoverStrategy.js +15 -12
- package/built/src/blockchainClient/requestWithFailoverStrategy.js.map +1 -1
- package/built/src/blockchainClient/types.js +2 -1
- package/built/src/blockchainClient/utils.js +205 -137
- package/built/src/blockchainClient/utils.js.map +1 -1
- package/built/src/blockchainClient/validation/anchoringTransaction.js +11 -8
- package/built/src/blockchainClient/validation/anchoringTransaction.js.map +1 -1
- package/built/src/blockchainClient/validation/blockIdentifier.js +10 -6
- package/built/src/blockchainClient/validation/blockIdentifier.js.map +1 -1
- package/built/src/blockchainClient/validation/bufferSchema.js +6 -3
- package/built/src/blockchainClient/validation/bufferSchema.js.map +1 -1
- package/built/src/blockchainClient/validation/merkleHash.js +10 -6
- package/built/src/blockchainClient/validation/merkleHash.js.map +1 -1
- package/built/src/blockchainClient/validation/networkSettings.js +35 -30
- package/built/src/blockchainClient/validation/networkSettings.js.map +1 -1
- package/built/src/blockchainClient/validation/rawGtx.js +18 -15
- package/built/src/blockchainClient/validation/rawGtx.js.map +1 -1
- package/built/src/blockchainClient/validation/requests.js +108 -87
- package/built/src/blockchainClient/validation/requests.js.map +1 -1
- package/built/src/blockchainClient/validation/signMethod.d.ts +8 -8
- package/built/src/blockchainClient/validation/signMethod.js +15 -11
- package/built/src/blockchainClient/validation/signMethod.js.map +1 -1
- package/built/src/blockchainClient/validation/transactionStatusReponse.js +11 -8
- package/built/src/blockchainClient/validation/transactionStatusReponse.js.map +1 -1
- package/built/src/blockchainClient/validation/txRid.d.ts +1 -1
- package/built/src/blockchainClient/validation/txRid.js +10 -6
- package/built/src/blockchainClient/validation/txRid.js.map +1 -1
- package/built/src/blockchainClient/validation/validation.types.js +2 -1
- package/built/src/customError/index.js +5 -1
- package/built/src/customError/index.js.map +1 -1
- package/built/src/encryption/encryption.js +74 -27
- package/built/src/encryption/encryption.js.map +1 -1
- package/built/src/encryption/errors.js +7 -2
- package/built/src/encryption/errors.js.map +1 -1
- package/built/src/encryption/types.js +2 -1
- package/built/src/formatter.js +38 -22
- package/built/src/formatter.js.map +1 -1
- package/built/src/gtv/definition.js +9 -6
- package/built/src/gtv/definition.js.map +1 -1
- package/built/src/gtv/index.js +44 -6
- package/built/src/gtv/index.js.map +1 -1
- package/built/src/gtv/types.js +2 -1
- package/built/src/gtx/errors.js +14 -6
- package/built/src/gtx/errors.js.map +1 -1
- package/built/src/gtx/gtx.js +92 -41
- package/built/src/gtx/gtx.js.map +1 -1
- package/built/src/gtx/index.js +39 -2
- package/built/src/gtx/index.js.map +1 -1
- package/built/src/gtx/serialization.js +26 -18
- package/built/src/gtx/serialization.js.map +1 -1
- package/built/src/gtx/types.js +2 -1
- package/built/src/logger.js +19 -9
- package/built/src/logger.js.map +1 -1
- package/built/src/promiEvent/promiEventEmitter.js +7 -3
- package/built/src/promiEvent/promiEventEmitter.js.map +1 -1
- package/built/src/promiEvent/promiEvents.js +6 -2
- package/built/src/promiEvent/promiEvents.js.map +1 -1
- package/built/src/utils/bufferUtils.js +6 -3
- package/built/src/utils/bufferUtils.js.map +1 -1
- package/built/src/utils/calculateTransactionRid.js +8 -5
- package/built/src/utils/calculateTransactionRid.js.map +1 -1
- package/built/src/utils/constants.js +4 -1
- package/built/src/utils/constants.js.map +1 -1
- package/built/src/utils/decodeTransactionToGtx.js +41 -5
- package/built/src/utils/decodeTransactionToGtx.js.map +1 -1
- package/built/src/utils/dump.js +13 -9
- package/built/src/utils/dump.js.map +1 -1
- package/built/src/utils/encodeTransaction.js +6 -3
- package/built/src/utils/encodeTransaction.js.map +1 -1
- package/built/src/utils/http-utils.js +17 -7
- package/built/src/utils/http-utils.js.map +1 -1
- package/built/test/common/mocks.js +147 -111
- package/built/test/common/mocks.js.map +1 -1
- package/built/test/common/serializationtestobjects.js +13 -7
- package/built/test/common/serializationtestobjects.js.map +1 -1
- package/built/test/common/setups.d.ts +1 -1
- package/built/test/common/setups.js +95 -46
- package/built/test/common/setups.js.map +1 -1
- package/built/test/common/signatures.js +47 -7
- package/built/test/common/signatures.js.map +1 -1
- package/built/test/common/testData.js +4 -1
- package/built/test/common/testData.js.map +1 -1
- package/built/test/common/validationMocks.js +52 -49
- package/built/test/common/validationMocks.js.map +1 -1
- package/built/test/integration/clientGetBlockInfo.test.js +4 -2
- package/built/test/integration/clientGetBlockInfo.test.js.map +1 -1
- package/built/test/integration/clientGetRejectedTransactions.test.js +9 -7
- package/built/test/integration/clientGetRejectedTransactions.test.js.map +1 -1
- package/built/test/integration/clientGetTransaction.test.js +8 -6
- package/built/test/integration/clientGetTransaction.test.js.map +1 -1
- package/built/test/integration/clientGetTransactionStatus.test.js +51 -16
- package/built/test/integration/clientGetTransactionStatus.test.js.map +1 -1
- package/built/test/integration/clientGetWaitingTransaction.test.js +13 -11
- package/built/test/integration/clientGetWaitingTransaction.test.js.map +1 -1
- package/built/test/integration/clientGetWaitingTransactions.test.js +9 -7
- package/built/test/integration/clientGetWaitingTransactions.test.js.map +1 -1
- package/built/test/integration/clientIntegration.test.js +12 -10
- package/built/test/integration/clientIntegration.test.js.map +1 -1
- package/built/test/integration/clientQuery.test.js +61 -26
- package/built/test/integration/clientQuery.test.js.map +1 -1
- package/built/test/integration/clientSendTransaction.test.js +23 -21
- package/built/test/integration/clientSendTransaction.test.js.map +1 -1
- package/built/test/integration/clientSignAndSendUniqueTransaction.test.js +23 -21
- package/built/test/integration/clientSignAndSendUniqueTransaction.test.js.map +1 -1
- package/built/test/integration/clientSignTransaction.test.js +24 -22
- package/built/test/integration/clientSignTransaction.test.js.map +1 -1
- package/built/test/integration/clientUtils.test.js +12 -10
- package/built/test/integration/clientUtils.test.js.map +1 -1
- package/built/test/integration/createClientIntegration.test.js +28 -26
- package/built/test/integration/createClientIntegration.test.js.map +1 -1
- package/built/test/integration/encodeTransaction.test.js +10 -8
- package/built/test/integration/encodeTransaction.test.js.map +1 -1
- package/built/test/integration/failoverStrategiesWithSmartTimeouts.test.js +45 -10
- package/built/test/integration/failoverStrategiesWithSmartTimeouts.test.js.map +1 -1
- package/built/test/integration/getTransactionsInfo.test.js +15 -13
- package/built/test/integration/getTransactionsInfo.test.js.map +1 -1
- package/built/test/integration/signAndSendUniqueTransaction.test.js +16 -14
- package/built/test/integration/signAndSendUniqueTransaction.test.js.map +1 -1
- package/built/test/integrationChromiaNetwork/createIccfProofTx.test.js +24 -22
- package/built/test/integrationChromiaNetwork/createIccfProofTx.test.js.map +1 -1
- package/built/test/integrationChromiaNetwork/getAnchoringStatusForBlockRid.test.js +15 -13
- package/built/test/integrationChromiaNetwork/getAnchoringStatusForBlockRid.test.js.map +1 -1
- package/built/test/integrationChromiaNetwork/getTransactionConfirmationLevel.test.js +10 -8
- package/built/test/integrationChromiaNetwork/getTransactionConfirmationLevel.test.js.map +1 -1
- package/built/test/integrationChromiaNetwork/getTransactionStatus.test.js +16 -14
- package/built/test/integrationChromiaNetwork/getTransactionStatus.test.js.map +1 -1
- package/built/test/integrationChromiaNetwork/isBlockAnchored.test.js +16 -14
- package/built/test/integrationChromiaNetwork/isBlockAnchored.test.js.map +1 -1
- package/built/test/integrationChromiaNetwork/merkleHashIntegration.test.js +21 -19
- package/built/test/integrationChromiaNetwork/merkleHashIntegration.test.js.map +1 -1
- package/built/test/integrationChromiaNetwork/nodeDiscovery.test.js +15 -10
- package/built/test/integrationChromiaNetwork/nodeDiscovery.test.js.map +1 -1
- package/built/test/integrationChromiaNetwork/requestWithFailoverStrategy.test.js +74 -36
- package/built/test/integrationChromiaNetwork/requestWithFailoverStrategy.test.js.map +1 -1
- package/built/test/integrationChromiaNetwork/signAndSendUniqueTransaction.test.js +17 -15
- package/built/test/integrationChromiaNetwork/signAndSendUniqueTransaction.test.js.map +1 -1
- package/built/test/manual/iccfManually.test.js +59 -24
- package/built/test/manual/iccfManually.test.js.map +1 -1
- package/built/test/pcctf/getSuites.test.js +27 -25
- package/built/test/pcctf/getSuites.test.js.map +1 -1
- package/built/test/pcctf/helpers.js +38 -23
- package/built/test/pcctf/helpers.js.map +1 -1
- package/built/test/unit/ICCF/iccf.test.js +77 -75
- package/built/test/unit/ICCF/iccf.test.js.map +1 -1
- package/built/test/unit/ICCF/iccfProofMaterialBuilder.test.js +93 -58
- package/built/test/unit/ICCF/iccfProofMaterialBuilder.test.js.map +1 -1
- package/built/test/unit/blockchainClient/client.getRejectedTransactions.test.js +12 -10
- package/built/test/unit/blockchainClient/client.getRejectedTransactions.test.js.map +1 -1
- package/built/test/unit/blockchainClient/client.getWaitingTransaction.test.js +14 -12
- package/built/test/unit/blockchainClient/client.getWaitingTransaction.test.js.map +1 -1
- package/built/test/unit/blockchainClient/client.getWaitingTransactions.test.js +10 -8
- package/built/test/unit/blockchainClient/client.getWaitingTransactions.test.js.map +1 -1
- package/built/test/unit/blockchainClient/client.test.js +89 -54
- package/built/test/unit/blockchainClient/client.test.js.map +1 -1
- package/built/test/unit/blockchainClient/clientCustomStatusCodes.test.js +26 -24
- package/built/test/unit/blockchainClient/clientCustomStatusCodes.test.js.map +1 -1
- package/built/test/unit/blockchainClient/getAnchoringStatusForBlockRid.test.js +52 -17
- package/built/test/unit/blockchainClient/getAnchoringStatusForBlockRid.test.js.map +1 -1
- package/built/test/unit/blockchainClient/getSystemAnchoringTransactionConfirmation.test.js +46 -11
- package/built/test/unit/blockchainClient/getSystemAnchoringTransactionConfirmation.test.js.map +1 -1
- package/built/test/unit/blockchainClient/getTransactionConfirmationLevel.test.js +64 -29
- package/built/test/unit/blockchainClient/getTransactionConfirmationLevel.test.js.map +1 -1
- package/built/test/unit/blockchainClient/sendTransaction.test.js +191 -156
- package/built/test/unit/blockchainClient/sendTransaction.test.js.map +1 -1
- package/built/test/unit/blockchainClient/setMerkleVersion.test.js +15 -13
- package/built/test/unit/blockchainClient/setMerkleVersion.test.js.map +1 -1
- package/built/test/unit/blockchainClient/signAndSendUniqueTransactionPromiEvents.test.js +21 -19
- package/built/test/unit/blockchainClient/signAndSendUniqueTransactionPromiEvents.test.js.map +1 -1
- package/built/test/unit/blockchainClient/statusPollIntervals.test.js +45 -10
- package/built/test/unit/blockchainClient/statusPollIntervals.test.js.map +1 -1
- package/built/test/unit/blockchainClient/util.test.js +66 -31
- package/built/test/unit/blockchainClient/util.test.js.map +1 -1
- package/built/test/unit/decodeTransactionToGtx.test.js +6 -4
- package/built/test/unit/decodeTransactionToGtx.test.js.map +1 -1
- package/built/test/unit/dump.test.js +6 -4
- package/built/test/unit/dump.test.js.map +1 -1
- package/built/test/unit/encryption/encryption.test.js +26 -24
- package/built/test/unit/encryption/encryption.test.js.map +1 -1
- package/built/test/unit/failoverStrategies.test.js +114 -79
- package/built/test/unit/failoverStrategies.test.js.map +1 -1
- package/built/test/unit/failoverStrategies.timeout.test.js +90 -55
- package/built/test/unit/failoverStrategies.timeout.test.js.map +1 -1
- package/built/test/unit/formatter.test.js +23 -21
- package/built/test/unit/formatter.test.js.map +1 -1
- package/built/test/unit/gtv/gtvHash.test.js +13 -11
- package/built/test/unit/gtv/gtvHash.test.js.map +1 -1
- package/built/test/unit/gtx/checkGTXSignature.test.js +18 -16
- package/built/test/unit/gtx/checkGTXSignature.test.js.map +1 -1
- package/built/test/unit/gtx/newSignatureProvider.test.js +14 -12
- package/built/test/unit/gtx/newSignatureProvider.test.js.map +1 -1
- package/built/test/unit/gtx/serialization.test.js +47 -42
- package/built/test/unit/gtx/serialization.test.js.map +1 -1
- package/built/test/unit/httpUtil.test.js +13 -11
- package/built/test/unit/httpUtil.test.js.map +1 -1
- package/built/test/unit/httpUtil.timeout.test.js +12 -10
- package/built/test/unit/httpUtil.timeout.test.js.map +1 -1
- package/built/test/unit/logger.test.js +42 -40
- package/built/test/unit/logger.test.js.map +1 -1
- package/built/test/unit/networkErrorDetection.test.js +39 -37
- package/built/test/unit/networkErrorDetection.test.js.map +1 -1
- package/built/test/unit/nodeMananger.test.js +19 -17
- package/built/test/unit/nodeMananger.test.js.map +1 -1
- package/built/test/unit/setOrdering.test.js +7 -5
- package/built/test/unit/setOrdering.test.js.map +1 -1
- package/built/test/unit/smartTimeouts.test.js +20 -18
- package/built/test/unit/smartTimeouts.test.js.map +1 -1
- package/built/test/unit/stickyNode.test.js +19 -17
- package/built/test/unit/stickyNode.test.js.map +1 -1
- package/built/test/unit/universalNodeRecovery.test.js +54 -19
- package/built/test/unit/universalNodeRecovery.test.js.map +1 -1
- package/built/test/unit/validation/anchoringTransaction.test.js +12 -10
- package/built/test/unit/validation/anchoringTransaction.test.js.map +1 -1
- package/built/test/unit/validation/blockIdentifier.test.js +10 -8
- package/built/test/unit/validation/blockIdentifier.test.js.map +1 -1
- package/built/test/unit/validation/bufferSchema.test.js +8 -6
- package/built/test/unit/validation/bufferSchema.test.js.map +1 -1
- package/built/test/unit/validation/networkSettings.test.js +14 -12
- package/built/test/unit/validation/networkSettings.test.js.map +1 -1
- package/built/test/unit/validation/rawGtx.test.js +24 -22
- package/built/test/unit/validation/rawGtx.test.js.map +1 -1
- package/built/test/unit/validation/requests.test.js +56 -54
- package/built/test/unit/validation/requests.test.js.map +1 -1
- package/built/test/unit/validation/signMethod.test.js +11 -9
- package/built/test/unit/validation/signMethod.test.js.map +1 -1
- package/built/test/unit/validation/statusObject.test.js +21 -19
- package/built/test/unit/validation/statusObject.test.js.map +1 -1
- package/built/test/unit/validation/txRid.test.js +10 -8
- package/built/test/unit/validation/txRid.test.js.map +1 -1
- package/built/umd/index.js +4625 -3372
- package/built/umd/index.js.map +1 -1
- package/changelog.md +5 -4
- package/package.json +2 -2
|
@@ -1,3 +1,37 @@
|
|
|
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
1
35
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
36
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
37
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -7,35 +41,61 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
41
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
42
|
});
|
|
9
43
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.sleep = exports.getUrlsFromEndpoints = exports.createEndpointObjects = exports.defaultFailoverConfig = exports.isKeyPair = exports.formatBlockInfoResponse = exports.formatTransactionInfoResponse = exports.handlePostResponsePromisified = exports.callbackPromiseBuilder = void 0;
|
|
46
|
+
exports.getClientConfigFromSettings = getClientConfigFromSettings;
|
|
47
|
+
exports.getMerkleHashVersionFromDapp = getMerkleHashVersionFromDapp;
|
|
48
|
+
exports.validTxRid = validTxRid;
|
|
49
|
+
exports.nodeDiscovery = nodeDiscovery;
|
|
50
|
+
exports.getBlockchainApiUrls = getBlockchainApiUrls;
|
|
51
|
+
exports.convertToRellOperation = convertToRellOperation;
|
|
52
|
+
exports.getSerializedGTX = getSerializedGTX;
|
|
53
|
+
exports.getGTXFromBufferOrTransactionOrOperation = getGTXFromBufferOrTransactionOrOperation;
|
|
54
|
+
exports.formatRejectedTransactionFromResponse = formatRejectedTransactionFromResponse;
|
|
55
|
+
exports.getSystemClient = getSystemClient;
|
|
56
|
+
exports.getSystemAnchoringChain = getSystemAnchoringChain;
|
|
57
|
+
exports.awaitDappConfirmation = awaitDappConfirmation;
|
|
58
|
+
exports.awaitClusterAnchoringChainConfirmation = awaitClusterAnchoringChainConfirmation;
|
|
59
|
+
exports.handleDappConfirmations = handleDappConfirmations;
|
|
60
|
+
exports.handleSystemConfirmations = handleSystemConfirmations;
|
|
61
|
+
exports.getAnchoringClientAndSystemChainRid = getAnchoringClientAndSystemChainRid;
|
|
62
|
+
exports.getSystemAnchoringTransaction = getSystemAnchoringTransaction;
|
|
63
|
+
exports.setStatusPolling = setStatusPolling;
|
|
64
|
+
exports.setRetryTransactionPolling = setRetryTransactionPolling;
|
|
65
|
+
exports.linkPromiEvents = linkPromiEvents;
|
|
66
|
+
exports.handleGetResponse = handleGetResponse;
|
|
67
|
+
exports.handlePostResponse = handlePostResponse;
|
|
68
|
+
exports.getBlockchainRidFromIid = getBlockchainRidFromIid;
|
|
69
|
+
exports.convertToPrintable = convertToPrintable;
|
|
70
|
+
const buffer_1 = require("buffer");
|
|
71
|
+
const logger = __importStar(require("../logger"));
|
|
72
|
+
const errors_1 = require("./errors");
|
|
73
|
+
const gtxTool = __importStar(require("../gtx/gtx"));
|
|
74
|
+
const errors_2 = require("./errors");
|
|
75
|
+
const formatter_1 = require("../formatter");
|
|
76
|
+
const blockchainClient_1 = require("./blockchainClient");
|
|
77
|
+
const enums_1 = require("./enums");
|
|
78
|
+
const nodeManager_1 = require("./nodeManager");
|
|
79
|
+
const anchoringTransaction_1 = require("./validation/anchoringTransaction");
|
|
80
|
+
const error_1 = require("../ICCF/error");
|
|
81
|
+
const IccfProofTxMaterialBuilder_1 = require("../ICCF/IccfProofTxMaterialBuilder");
|
|
82
|
+
const utils_1 = require("../ICCF/utils");
|
|
83
|
+
const requests_1 = require("./validation/requests");
|
|
84
|
+
const encodeTransaction_1 = require("../utils/encodeTransaction");
|
|
85
|
+
const merkleHash_1 = require("./validation/merkleHash");
|
|
86
|
+
const requestWithFailoverStrategy_1 = require("./requestWithFailoverStrategy");
|
|
87
|
+
const constants_1 = require("../utils/constants");
|
|
88
|
+
const http_utils_1 = require("../utils/http-utils");
|
|
89
|
+
function getClientConfigFromSettings(settings) {
|
|
30
90
|
return __awaiter(this, void 0, void 0, function* () {
|
|
31
91
|
var _a, _b, _c, _d, _e, _f, _g, _h, _j;
|
|
32
92
|
const nodeUrlPoolToUse = yield getNodeUrlsFromSettings(settings);
|
|
33
93
|
if (nodeUrlPoolToUse === null || nodeUrlPoolToUse.length === 0) {
|
|
34
94
|
const id = (_b = (_a = settings.blockchainRid) !== null && _a !== void 0 ? _a : settings.blockchainIid) !== null && _b !== void 0 ? _b : "Unknown";
|
|
35
|
-
throw new BlockchainUrlUndefinedException(id);
|
|
95
|
+
throw new errors_2.BlockchainUrlUndefinedException(id);
|
|
36
96
|
}
|
|
37
|
-
const endpointPool = createEndpointObjects(nodeUrlPoolToUse);
|
|
38
|
-
const nodeManager = createNodeManager({
|
|
97
|
+
const endpointPool = (0, exports.createEndpointObjects)(nodeUrlPoolToUse);
|
|
98
|
+
const nodeManager = (0, nodeManager_1.createNodeManager)({
|
|
39
99
|
nodeUrls: nodeUrlPoolToUse,
|
|
40
100
|
useStickyNode: (_c = settings.useStickyNode) !== null && _c !== void 0 ? _c : false,
|
|
41
101
|
unavailableDuration: (_d = settings.failOverConfig) === null || _d === void 0 ? void 0 : _d.unreachableDuration,
|
|
@@ -50,12 +110,12 @@ export function getClientConfigFromSettings(settings) {
|
|
|
50
110
|
nodeManager,
|
|
51
111
|
endpointPool,
|
|
52
112
|
chainId: settings.blockchainIid,
|
|
53
|
-
merkleHashVersion: (_a = settings.merkleHashVersion) !== null && _a !== void 0 ? _a : MERKLE_HASH_VERSIONS.UNSET,
|
|
113
|
+
merkleHashVersion: (_a = settings.merkleHashVersion) !== null && _a !== void 0 ? _a : constants_1.MERKLE_HASH_VERSIONS.UNSET,
|
|
54
114
|
connectTimeout: settings.connectTimeout,
|
|
55
115
|
responseTimeout: settings.responseTimeout,
|
|
56
116
|
});
|
|
57
117
|
}
|
|
58
|
-
throw new MissingBlockchainIdentifierError();
|
|
118
|
+
throw new errors_2.MissingBlockchainIdentifierError();
|
|
59
119
|
}))();
|
|
60
120
|
const directoryChainRid = yield (() => __awaiter(this, void 0, void 0, function* () {
|
|
61
121
|
var _a;
|
|
@@ -67,7 +127,7 @@ export function getClientConfigFromSettings(settings) {
|
|
|
67
127
|
nodeManager,
|
|
68
128
|
endpointPool,
|
|
69
129
|
chainId: directoryChainIid,
|
|
70
|
-
merkleHashVersion: (_a = settings.merkleHashVersion) !== null && _a !== void 0 ? _a : MERKLE_HASH_VERSIONS.UNSET,
|
|
130
|
+
merkleHashVersion: (_a = settings.merkleHashVersion) !== null && _a !== void 0 ? _a : constants_1.MERKLE_HASH_VERSIONS.UNSET,
|
|
71
131
|
connectTimeout: settings.connectTimeout,
|
|
72
132
|
responseTimeout: settings.responseTimeout,
|
|
73
133
|
});
|
|
@@ -76,50 +136,50 @@ export function getClientConfigFromSettings(settings) {
|
|
|
76
136
|
endpointPool,
|
|
77
137
|
nodeManager: nodeManager,
|
|
78
138
|
blockchainRid: blockchainRidToUse,
|
|
79
|
-
merkleHashVersion: (_e = settings.merkleHashVersion) !== null && _e !== void 0 ? _e : MERKLE_HASH_VERSIONS.UNSET,
|
|
139
|
+
merkleHashVersion: (_e = settings.merkleHashVersion) !== null && _e !== void 0 ? _e : constants_1.MERKLE_HASH_VERSIONS.UNSET,
|
|
80
140
|
dappStatusPolling: setStatusPolling(settings.dappStatusPolling),
|
|
81
141
|
clusterAnchoringStatusPolling: setStatusPolling(settings.clusterAnchoringStatusPolling),
|
|
82
142
|
systemAnchoringStatusPolling: setStatusPolling(settings.systemAnchoringStatusPolling),
|
|
83
143
|
retryTransactionPolling: setRetryTransactionPolling(settings.retryTransactionPolling),
|
|
84
|
-
failoverStrategy: ((_f = settings.failOverConfig) === null || _f === void 0 ? void 0 : _f.strategy) || defaultFailoverConfig.strategy,
|
|
85
|
-
attemptsPerEndpoint: ((_g = settings.failOverConfig) === null || _g === void 0 ? void 0 : _g.attemptsPerEndpoint) || defaultFailoverConfig.attemptsPerEndpoint,
|
|
86
|
-
attemptInterval: ((_h = settings.failOverConfig) === null || _h === void 0 ? void 0 : _h.attemptInterval) || defaultFailoverConfig.attemptInterval,
|
|
87
|
-
unreachableDuration: ((_j = settings.failOverConfig) === null || _j === void 0 ? void 0 : _j.unreachableDuration) || defaultFailoverConfig.unreachableDuration,
|
|
144
|
+
failoverStrategy: ((_f = settings.failOverConfig) === null || _f === void 0 ? void 0 : _f.strategy) || exports.defaultFailoverConfig.strategy,
|
|
145
|
+
attemptsPerEndpoint: ((_g = settings.failOverConfig) === null || _g === void 0 ? void 0 : _g.attemptsPerEndpoint) || exports.defaultFailoverConfig.attemptsPerEndpoint,
|
|
146
|
+
attemptInterval: ((_h = settings.failOverConfig) === null || _h === void 0 ? void 0 : _h.attemptInterval) || exports.defaultFailoverConfig.attemptInterval,
|
|
147
|
+
unreachableDuration: ((_j = settings.failOverConfig) === null || _j === void 0 ? void 0 : _j.unreachableDuration) || exports.defaultFailoverConfig.unreachableDuration,
|
|
88
148
|
directoryChainRid: settings.directoryChainRid || directoryChainRid,
|
|
89
149
|
connectTimeout: settings.connectTimeout,
|
|
90
150
|
responseTimeout: settings.responseTimeout,
|
|
91
151
|
};
|
|
92
152
|
});
|
|
93
153
|
}
|
|
94
|
-
|
|
154
|
+
function getMerkleHashVersionFromDapp(config) {
|
|
95
155
|
return __awaiter(this, void 0, void 0, function* () {
|
|
96
156
|
var _a;
|
|
97
157
|
try {
|
|
98
|
-
const response = yield requestWithFailoverStrategy(Method.GET, `/config/${config.blockchainRid}/features`, config, undefined, false, (_a = config.connectTimeout) !== null && _a !== void 0 ? _a : config.responseTimeout);
|
|
99
|
-
const validatedResponse = validateMerkleHash(response.rspBody);
|
|
158
|
+
const response = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_1.Method.GET, `/config/${config.blockchainRid}/features`, config, undefined, false, (_a = config.connectTimeout) !== null && _a !== void 0 ? _a : config.responseTimeout);
|
|
159
|
+
const validatedResponse = (0, merkleHash_1.validateMerkleHash)(response.rspBody);
|
|
100
160
|
return validatedResponse.merkle_hash_version;
|
|
101
161
|
}
|
|
102
162
|
catch (error) {
|
|
103
163
|
console.warn("MERKLE_HASH_WARNING: version not found or endpoint unreachable", error);
|
|
104
|
-
return MERKLE_HASH_VERSIONS.ONE;
|
|
164
|
+
return constants_1.MERKLE_HASH_VERSIONS.ONE;
|
|
105
165
|
}
|
|
106
166
|
});
|
|
107
167
|
}
|
|
108
|
-
|
|
168
|
+
function validTxRid(txRID) {
|
|
109
169
|
if (txRID.length != 32) {
|
|
110
|
-
const error = new InvalidTxRidException(txRID);
|
|
170
|
+
const error = new errors_1.InvalidTxRidException(txRID);
|
|
111
171
|
logger.error(error.toString());
|
|
112
172
|
return false;
|
|
113
173
|
}
|
|
114
174
|
return true;
|
|
115
175
|
}
|
|
116
|
-
|
|
176
|
+
function nodeDiscovery(_a) {
|
|
117
177
|
return __awaiter(this, arguments, void 0, function* ({ nodeManager, directoryEndpointPool, failOverConfig, blockchainRid, blockchainIid, connectTimeout, responseTimeout, }) {
|
|
118
178
|
if (directoryEndpointPool.length === 0) {
|
|
119
|
-
throw new DirectoryNodeUrlPoolException();
|
|
179
|
+
throw new errors_2.DirectoryNodeUrlPoolException();
|
|
120
180
|
}
|
|
121
181
|
if (!blockchainRid && blockchainIid === undefined) {
|
|
122
|
-
throw new MissingBlockchainIdentifierError();
|
|
182
|
+
throw new errors_2.MissingBlockchainIdentifierError();
|
|
123
183
|
}
|
|
124
184
|
const directoryIid = 0;
|
|
125
185
|
const directoryBRID = yield getBlockchainRidFromIid({
|
|
@@ -144,16 +204,16 @@ export function nodeDiscovery(_a) {
|
|
|
144
204
|
responseTimeout,
|
|
145
205
|
});
|
|
146
206
|
}
|
|
147
|
-
throw new MissingBlockchainIdentifierError();
|
|
207
|
+
throw new errors_2.MissingBlockchainIdentifierError();
|
|
148
208
|
}))();
|
|
149
|
-
const D1Client = yield createClient({
|
|
150
|
-
nodeUrlPool: getUrlsFromEndpoints(directoryEndpointPool),
|
|
209
|
+
const D1Client = yield (0, blockchainClient_1.createClient)({
|
|
210
|
+
nodeUrlPool: (0, exports.getUrlsFromEndpoints)(directoryEndpointPool),
|
|
151
211
|
blockchainRid: directoryBRID,
|
|
152
212
|
});
|
|
153
|
-
return yield getBlockchainApiUrls(D1Client, ensureBuffer(blockchainRidToUse));
|
|
213
|
+
return yield getBlockchainApiUrls(D1Client, (0, formatter_1.ensureBuffer)(blockchainRidToUse));
|
|
154
214
|
});
|
|
155
215
|
}
|
|
156
|
-
|
|
216
|
+
function getBlockchainApiUrls(directoryClient, blockchainRid) {
|
|
157
217
|
return __awaiter(this, void 0, void 0, function* () {
|
|
158
218
|
const queryObject = {
|
|
159
219
|
name: "cm_get_blockchain_api_urls",
|
|
@@ -162,7 +222,7 @@ export function getBlockchainApiUrls(directoryClient, blockchainRid) {
|
|
|
162
222
|
return yield directoryClient.query(queryObject);
|
|
163
223
|
});
|
|
164
224
|
}
|
|
165
|
-
|
|
225
|
+
function convertToRellOperation(operations) {
|
|
166
226
|
return operations.map(operation => {
|
|
167
227
|
var _a;
|
|
168
228
|
return {
|
|
@@ -171,20 +231,20 @@ export function convertToRellOperation(operations) {
|
|
|
171
231
|
};
|
|
172
232
|
});
|
|
173
233
|
}
|
|
174
|
-
|
|
175
|
-
const gtxBytes = encodeTransaction(gtx);
|
|
176
|
-
if (!Buffer.isBuffer(gtxBytes)) {
|
|
177
|
-
throw new SerializedTransactionFormatException();
|
|
234
|
+
function getSerializedGTX(gtx) {
|
|
235
|
+
const gtxBytes = (0, encodeTransaction_1.encodeTransaction)(gtx);
|
|
236
|
+
if (!buffer_1.Buffer.isBuffer(gtxBytes)) {
|
|
237
|
+
throw new errors_1.SerializedTransactionFormatException();
|
|
178
238
|
}
|
|
179
239
|
return gtxBytes;
|
|
180
240
|
}
|
|
181
|
-
|
|
182
|
-
if (Buffer.isBuffer(transaction)) {
|
|
241
|
+
function getGTXFromBufferOrTransactionOrOperation(transaction, blockchainRid) {
|
|
242
|
+
if (buffer_1.Buffer.isBuffer(transaction)) {
|
|
183
243
|
return gtxTool.deserialize(transaction);
|
|
184
244
|
}
|
|
185
245
|
else if ("operations" in transaction) {
|
|
186
246
|
return {
|
|
187
|
-
blockchainRid: ensureBuffer(blockchainRid),
|
|
247
|
+
blockchainRid: (0, formatter_1.ensureBuffer)(blockchainRid),
|
|
188
248
|
operations: convertToRellOperation(transaction.operations),
|
|
189
249
|
signers: transaction.signers,
|
|
190
250
|
signatures: [],
|
|
@@ -192,17 +252,17 @@ export function getGTXFromBufferOrTransactionOrOperation(transaction, blockchain
|
|
|
192
252
|
}
|
|
193
253
|
else if ("name" in transaction) {
|
|
194
254
|
return {
|
|
195
|
-
blockchainRid: ensureBuffer(blockchainRid),
|
|
255
|
+
blockchainRid: (0, formatter_1.ensureBuffer)(blockchainRid),
|
|
196
256
|
operations: convertToRellOperation([transaction]),
|
|
197
257
|
signers: [],
|
|
198
258
|
signatures: [],
|
|
199
259
|
};
|
|
200
260
|
}
|
|
201
261
|
else {
|
|
202
|
-
throw new InvalidTransactionFormatException();
|
|
262
|
+
throw new errors_2.InvalidTransactionFormatException();
|
|
203
263
|
}
|
|
204
264
|
}
|
|
205
|
-
|
|
265
|
+
const callbackPromiseBuilder = (reject, resolve, callback) => {
|
|
206
266
|
return (error, result) => {
|
|
207
267
|
var _a;
|
|
208
268
|
if (error) {
|
|
@@ -215,7 +275,8 @@ export const callbackPromiseBuilder = (reject, resolve, callback) => {
|
|
|
215
275
|
}
|
|
216
276
|
};
|
|
217
277
|
};
|
|
218
|
-
|
|
278
|
+
exports.callbackPromiseBuilder = callbackPromiseBuilder;
|
|
279
|
+
const handlePostResponsePromisified = (error, statusCode, rspBody) => {
|
|
219
280
|
return new Promise((resolve, reject) => {
|
|
220
281
|
handlePostResponse(error, statusCode, rspBody, _error => {
|
|
221
282
|
if (_error) {
|
|
@@ -227,75 +288,79 @@ export const handlePostResponsePromisified = (error, statusCode, rspBody) => {
|
|
|
227
288
|
});
|
|
228
289
|
});
|
|
229
290
|
};
|
|
291
|
+
exports.handlePostResponsePromisified = handlePostResponsePromisified;
|
|
230
292
|
function ensureArray(input) {
|
|
231
293
|
if (typeof input === "string") {
|
|
232
294
|
return [input];
|
|
233
295
|
}
|
|
234
296
|
return input;
|
|
235
297
|
}
|
|
236
|
-
|
|
298
|
+
const formatTransactionInfoResponse = (transactionInfoResponse) => {
|
|
237
299
|
return {
|
|
238
|
-
blockRid: toBuffer(transactionInfoResponse.blockRID),
|
|
300
|
+
blockRid: (0, formatter_1.toBuffer)(transactionInfoResponse.blockRID),
|
|
239
301
|
blockHeight: transactionInfoResponse.blockHeight,
|
|
240
|
-
blockHeader: toBuffer(transactionInfoResponse.blockHeader),
|
|
241
|
-
witness: toBuffer(transactionInfoResponse.witness),
|
|
302
|
+
blockHeader: (0, formatter_1.toBuffer)(transactionInfoResponse.blockHeader),
|
|
303
|
+
witness: (0, formatter_1.toBuffer)(transactionInfoResponse.witness),
|
|
242
304
|
timestamp: transactionInfoResponse.timestamp,
|
|
243
|
-
txRid: toBuffer(transactionInfoResponse.txRID),
|
|
244
|
-
txHash: toBuffer(transactionInfoResponse.txHash),
|
|
245
|
-
txData: toBuffer(transactionInfoResponse.txData),
|
|
305
|
+
txRid: (0, formatter_1.toBuffer)(transactionInfoResponse.txRID),
|
|
306
|
+
txHash: (0, formatter_1.toBuffer)(transactionInfoResponse.txHash),
|
|
307
|
+
txData: (0, formatter_1.toBuffer)(transactionInfoResponse.txData),
|
|
246
308
|
};
|
|
247
309
|
};
|
|
248
|
-
|
|
310
|
+
exports.formatTransactionInfoResponse = formatTransactionInfoResponse;
|
|
311
|
+
const formatBlockInfoResponse = (blockInfoResponse) => {
|
|
249
312
|
return {
|
|
250
|
-
rid: toBuffer(blockInfoResponse.rid),
|
|
251
|
-
prevBlockRid: toBuffer(blockInfoResponse.prevBlockRID),
|
|
252
|
-
header: toBuffer(blockInfoResponse.header),
|
|
313
|
+
rid: (0, formatter_1.toBuffer)(blockInfoResponse.rid),
|
|
314
|
+
prevBlockRid: (0, formatter_1.toBuffer)(blockInfoResponse.prevBlockRID),
|
|
315
|
+
header: (0, formatter_1.toBuffer)(blockInfoResponse.header),
|
|
253
316
|
transactions: blockInfoResponse.transactions.map(formatTransaction),
|
|
254
317
|
height: blockInfoResponse.height,
|
|
255
|
-
witness: toBuffer(blockInfoResponse.witness),
|
|
318
|
+
witness: (0, formatter_1.toBuffer)(blockInfoResponse.witness),
|
|
256
319
|
witnesses: blockInfoResponse.witnesses.map(witness => {
|
|
257
|
-
return toBuffer(witness);
|
|
320
|
+
return (0, formatter_1.toBuffer)(witness);
|
|
258
321
|
}),
|
|
259
322
|
timestamp: blockInfoResponse.timestamp,
|
|
260
323
|
};
|
|
261
324
|
};
|
|
325
|
+
exports.formatBlockInfoResponse = formatBlockInfoResponse;
|
|
262
326
|
const formatTransaction = (transaction) => {
|
|
263
327
|
const formattedTransaction = {
|
|
264
|
-
rid: toBuffer(transaction.rid),
|
|
265
|
-
hash: toBuffer(transaction.hash),
|
|
328
|
+
rid: (0, formatter_1.toBuffer)(transaction.rid),
|
|
329
|
+
hash: (0, formatter_1.toBuffer)(transaction.hash),
|
|
266
330
|
};
|
|
267
331
|
if (transaction.data !== undefined) {
|
|
268
|
-
formattedTransaction.data = toBuffer(transaction.data);
|
|
332
|
+
formattedTransaction.data = (0, formatter_1.toBuffer)(transaction.data);
|
|
269
333
|
}
|
|
270
334
|
return formattedTransaction;
|
|
271
335
|
};
|
|
272
|
-
|
|
336
|
+
function formatRejectedTransactionFromResponse(rejectedTransactionResponse) {
|
|
273
337
|
return {
|
|
274
|
-
txRid: toBuffer(rejectedTransactionResponse.txRID),
|
|
338
|
+
txRid: (0, formatter_1.toBuffer)(rejectedTransactionResponse.txRID),
|
|
275
339
|
rejectReason: rejectedTransactionResponse.rejectReason,
|
|
276
340
|
rejectTimestamp: rejectedTransactionResponse.rejectTimestamp,
|
|
277
341
|
};
|
|
278
342
|
}
|
|
279
|
-
|
|
343
|
+
const isKeyPair = (keypair) => {
|
|
280
344
|
return (typeof keypair === "object" &&
|
|
281
345
|
keypair !== null &&
|
|
282
346
|
"privKey" in keypair &&
|
|
283
347
|
"pubKey" in keypair &&
|
|
284
|
-
keypair.privKey instanceof Buffer &&
|
|
285
|
-
keypair.pubKey instanceof Buffer);
|
|
348
|
+
keypair.privKey instanceof buffer_1.Buffer &&
|
|
349
|
+
keypair.pubKey instanceof buffer_1.Buffer);
|
|
286
350
|
};
|
|
351
|
+
exports.isKeyPair = isKeyPair;
|
|
287
352
|
function getNodeUrlsFromSettings(settings) {
|
|
288
353
|
return __awaiter(this, void 0, void 0, function* () {
|
|
289
354
|
var _a;
|
|
290
355
|
if (settings.directoryNodeUrlPool) {
|
|
291
356
|
// If directoryNodeUrlPool is provided, use nodeDiscovery
|
|
292
|
-
const nodeManager = createNodeManager({
|
|
357
|
+
const nodeManager = (0, nodeManager_1.createNodeManager)({
|
|
293
358
|
nodeUrls: ensureArray(settings.directoryNodeUrlPool),
|
|
294
359
|
unavailableDuration: (_a = settings.failOverConfig) === null || _a === void 0 ? void 0 : _a.unreachableDuration,
|
|
295
360
|
});
|
|
296
361
|
const discoveredNodes = yield nodeDiscovery({
|
|
297
362
|
nodeManager,
|
|
298
|
-
directoryEndpointPool: createEndpointObjects(ensureArray(settings.directoryNodeUrlPool)),
|
|
363
|
+
directoryEndpointPool: (0, exports.createEndpointObjects)(ensureArray(settings.directoryNodeUrlPool)),
|
|
299
364
|
failOverConfig: settings.failOverConfig,
|
|
300
365
|
blockchainRid: settings.blockchainRid,
|
|
301
366
|
blockchainIid: settings.blockchainIid,
|
|
@@ -318,15 +383,15 @@ function getNodeUrlsFromSettings(settings) {
|
|
|
318
383
|
}
|
|
319
384
|
});
|
|
320
385
|
}
|
|
321
|
-
|
|
386
|
+
function getSystemClient(directoryNodeUrlPool, directoryChainRid) {
|
|
322
387
|
return __awaiter(this, void 0, void 0, function* () {
|
|
323
|
-
return yield createClient({
|
|
388
|
+
return yield (0, blockchainClient_1.createClient)({
|
|
324
389
|
directoryNodeUrlPool,
|
|
325
390
|
blockchainRid: directoryChainRid,
|
|
326
391
|
});
|
|
327
392
|
});
|
|
328
393
|
}
|
|
329
|
-
|
|
394
|
+
function getSystemAnchoringChain(directoryClient) {
|
|
330
395
|
return __awaiter(this, void 0, void 0, function* () {
|
|
331
396
|
try {
|
|
332
397
|
const queryObject = {
|
|
@@ -334,64 +399,66 @@ export function getSystemAnchoringChain(directoryClient) {
|
|
|
334
399
|
};
|
|
335
400
|
const systemAnchoringChain = yield directoryClient.query(queryObject);
|
|
336
401
|
if (!systemAnchoringChain) {
|
|
337
|
-
throw new SystemChainException("Directory chain client must be provided.");
|
|
402
|
+
throw new error_1.SystemChainException("Directory chain client must be provided.");
|
|
338
403
|
}
|
|
339
404
|
return systemAnchoringChain;
|
|
340
405
|
}
|
|
341
406
|
catch (error) {
|
|
342
|
-
throw new SystemChainException(error.message);
|
|
407
|
+
throw new error_1.SystemChainException(error.message);
|
|
343
408
|
}
|
|
344
409
|
});
|
|
345
410
|
}
|
|
346
|
-
|
|
347
|
-
strategy: FailoverStrategy.AbortOnError,
|
|
411
|
+
exports.defaultFailoverConfig = {
|
|
412
|
+
strategy: enums_1.FailoverStrategy.AbortOnError,
|
|
348
413
|
attemptsPerEndpoint: 3,
|
|
349
414
|
attemptInterval: 500,
|
|
350
415
|
unreachableDuration: 30000,
|
|
351
416
|
};
|
|
352
|
-
|
|
417
|
+
const createEndpointObjects = (endpointPoolUrls) => {
|
|
353
418
|
const endpoints = endpointPoolUrls.map(endpointUrl => {
|
|
354
419
|
return { url: endpointUrl, whenAvailable: 0 };
|
|
355
420
|
});
|
|
356
421
|
return endpoints;
|
|
357
422
|
};
|
|
358
|
-
|
|
423
|
+
exports.createEndpointObjects = createEndpointObjects;
|
|
424
|
+
const getUrlsFromEndpoints = (endpointPool) => {
|
|
359
425
|
return endpointPool.map(endpoint => endpoint.url);
|
|
360
426
|
};
|
|
361
|
-
|
|
427
|
+
exports.getUrlsFromEndpoints = getUrlsFromEndpoints;
|
|
428
|
+
function awaitDappConfirmation(txRID, dappStatusPolling, getTransactionStatus) {
|
|
362
429
|
return __awaiter(this, void 0, void 0, function* () {
|
|
363
430
|
var _a;
|
|
364
431
|
let lastKnownResult = null;
|
|
365
432
|
for (let i = 0; i < dappStatusPolling.count; i++) {
|
|
366
433
|
lastKnownResult = yield getTransactionStatus(txRID);
|
|
367
|
-
if (lastKnownResult.status === ResponseStatus.Confirmed) {
|
|
434
|
+
if (lastKnownResult.status === enums_1.ResponseStatus.Confirmed) {
|
|
368
435
|
return lastKnownResult;
|
|
369
436
|
}
|
|
370
|
-
else if (lastKnownResult.status === ResponseStatus.Rejected) {
|
|
371
|
-
throw new TxRejectedError((_a = lastKnownResult.rejectReason) !== null && _a !== void 0 ? _a : "");
|
|
437
|
+
else if (lastKnownResult.status === enums_1.ResponseStatus.Rejected) {
|
|
438
|
+
throw new errors_1.TxRejectedError((_a = lastKnownResult.rejectReason) !== null && _a !== void 0 ? _a : "");
|
|
372
439
|
}
|
|
373
|
-
yield sleep(dappStatusPolling.interval);
|
|
440
|
+
yield (0, exports.sleep)(dappStatusPolling.interval);
|
|
374
441
|
}
|
|
375
442
|
throw new Error(`Retry count exceeded. Confirmation not received. Last transaction status: ${lastKnownResult === null || lastKnownResult === void 0 ? void 0 : lastKnownResult.status}`);
|
|
376
443
|
});
|
|
377
444
|
}
|
|
378
|
-
|
|
445
|
+
function awaitClusterAnchoringChainConfirmation(txRID, clusterAnchoringStatusPolling, getClusterAnchoringTransactionConfirmation) {
|
|
379
446
|
return __awaiter(this, void 0, void 0, function* () {
|
|
380
447
|
var _a;
|
|
381
448
|
let clusterAnchoringConfirmation;
|
|
382
449
|
for (let i = 0; i < clusterAnchoringStatusPolling.count; i++) {
|
|
383
450
|
clusterAnchoringConfirmation = yield getClusterAnchoringTransactionConfirmation(txRID);
|
|
384
|
-
const anchoringTransactionValidaiton = AnchoringTransactionSchema.safeParse(clusterAnchoringConfirmation);
|
|
451
|
+
const anchoringTransactionValidaiton = anchoringTransaction_1.AnchoringTransactionSchema.safeParse(clusterAnchoringConfirmation);
|
|
385
452
|
if (anchoringTransactionValidaiton.success) {
|
|
386
453
|
return {
|
|
387
|
-
status: AnchoringStatus.ClusterAnchored,
|
|
454
|
+
status: enums_1.AnchoringStatus.ClusterAnchored,
|
|
388
455
|
clusterAnchoredTx: anchoringTransactionValidaiton.data,
|
|
389
456
|
};
|
|
390
457
|
}
|
|
391
458
|
else if (!anchoringTransactionValidaiton.success) {
|
|
392
|
-
throw new TxRejectedError((_a = AnchoringStatus.FailedAnchoring) !== null && _a !== void 0 ? _a : "");
|
|
459
|
+
throw new errors_1.TxRejectedError((_a = enums_1.AnchoringStatus.FailedAnchoring) !== null && _a !== void 0 ? _a : "");
|
|
393
460
|
}
|
|
394
|
-
yield sleep(clusterAnchoringStatusPolling.interval);
|
|
461
|
+
yield (0, exports.sleep)(clusterAnchoringStatusPolling.interval);
|
|
395
462
|
}
|
|
396
463
|
// TS issue. This could be fixed by implementing new retry strategy
|
|
397
464
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
@@ -399,70 +466,70 @@ export function awaitClusterAnchoringChainConfirmation(txRID, clusterAnchoringSt
|
|
|
399
466
|
return clusterAnchoringConfirmation;
|
|
400
467
|
});
|
|
401
468
|
}
|
|
402
|
-
|
|
469
|
+
function handleDappConfirmations(transactionRid, doStatusPolling, confirmationLevel, promiEvent, dappStatusPolling, getTransactionStatus, client) {
|
|
403
470
|
return __awaiter(this, void 0, void 0, function* () {
|
|
404
471
|
var _a, _b;
|
|
405
472
|
const transactionReceipt = {
|
|
406
|
-
status: ResponseStatus.Pending,
|
|
473
|
+
status: enums_1.ResponseStatus.Pending,
|
|
407
474
|
statusCode: null,
|
|
408
475
|
transactionRid: transactionRid,
|
|
409
476
|
node: (_a = client.config.nodeManager.lastUsedNode) === null || _a === void 0 ? void 0 : _a.url,
|
|
410
477
|
};
|
|
411
|
-
promiEvent.emit(TransactionEvent.DappReceived, transactionReceipt);
|
|
412
|
-
if (doStatusPolling === false || confirmationLevel === ChainConfirmationLevel.None) {
|
|
478
|
+
promiEvent.emit(enums_1.TransactionEvent.DappReceived, transactionReceipt);
|
|
479
|
+
if (doStatusPolling === false || confirmationLevel === enums_1.ChainConfirmationLevel.None) {
|
|
413
480
|
return transactionReceipt;
|
|
414
481
|
}
|
|
415
482
|
const dappConfirmationStatus = yield awaitDappConfirmation(transactionRid, dappStatusPolling, getTransactionStatus);
|
|
416
483
|
transactionReceipt.statusCode = dappConfirmationStatus.statusCode;
|
|
417
484
|
transactionReceipt.status = dappConfirmationStatus.status;
|
|
418
485
|
transactionReceipt.node = (_b = client.config.nodeManager.lastUsedNode) === null || _b === void 0 ? void 0 : _b.url;
|
|
419
|
-
promiEvent.emit(TransactionEvent.DappConfirmed, transactionReceipt);
|
|
420
|
-
if (confirmationLevel === ChainConfirmationLevel.Dapp) {
|
|
486
|
+
promiEvent.emit(enums_1.TransactionEvent.DappConfirmed, transactionReceipt);
|
|
487
|
+
if (confirmationLevel === enums_1.ChainConfirmationLevel.Dapp) {
|
|
421
488
|
return transactionReceipt;
|
|
422
489
|
}
|
|
423
490
|
return transactionReceipt;
|
|
424
491
|
});
|
|
425
492
|
}
|
|
426
|
-
|
|
493
|
+
function handleSystemConfirmations(transactionReceipt, confirmationLevel, promiEvent, statusPollingConfig, anchoringClient, systemAnchoringChainBrid, getClusterAnchoringTransactionConfirmation, getSystemAnchoringTransactionConfirmation) {
|
|
427
494
|
return __awaiter(this, void 0, void 0, function* () {
|
|
428
495
|
const clusterAnchoringChainConfirmation = yield awaitClusterAnchoringChainConfirmation(transactionReceipt.transactionRid, statusPollingConfig.clusterAnchoringStatusPolling, getClusterAnchoringTransactionConfirmation);
|
|
429
496
|
transactionReceipt.status = clusterAnchoringChainConfirmation.status;
|
|
430
497
|
transactionReceipt.clusterAnchoredTx = clusterAnchoringChainConfirmation.clusterAnchoredTx;
|
|
431
498
|
transactionReceipt.clusterAnchoringClientBrid = anchoringClient.config.blockchainRid;
|
|
432
|
-
promiEvent.emit(TransactionEvent.ClusterAnchoringConfirmation, transactionReceipt);
|
|
433
|
-
if (confirmationLevel === ChainConfirmationLevel.ClusterAnchoring) {
|
|
499
|
+
promiEvent.emit(enums_1.TransactionEvent.ClusterAnchoringConfirmation, transactionReceipt);
|
|
500
|
+
if (confirmationLevel === enums_1.ChainConfirmationLevel.ClusterAnchoring) {
|
|
434
501
|
return transactionReceipt;
|
|
435
502
|
}
|
|
436
503
|
const systemAnchoringConfirmation = yield getSystemAnchoringTransactionConfirmation(clusterAnchoringChainConfirmation.clusterAnchoredTx.txRid, anchoringClient, systemAnchoringChainBrid);
|
|
437
504
|
if (!systemAnchoringConfirmation) {
|
|
438
505
|
return transactionReceipt;
|
|
439
506
|
}
|
|
440
|
-
transactionReceipt.status = AnchoringStatus.SystemAnchored;
|
|
507
|
+
transactionReceipt.status = enums_1.AnchoringStatus.SystemAnchored;
|
|
441
508
|
transactionReceipt.systemAnchoredTx = systemAnchoringConfirmation;
|
|
442
509
|
transactionReceipt.systemAnchoringClientBrid = systemAnchoringChainBrid;
|
|
443
|
-
promiEvent.emit(TransactionEvent.SystemAnchoringConfirmation, transactionReceipt);
|
|
444
|
-
if (confirmationLevel === ChainConfirmationLevel.SystemAnchoring) {
|
|
510
|
+
promiEvent.emit(enums_1.TransactionEvent.SystemAnchoringConfirmation, transactionReceipt);
|
|
511
|
+
if (confirmationLevel === enums_1.ChainConfirmationLevel.SystemAnchoring) {
|
|
445
512
|
return transactionReceipt;
|
|
446
513
|
}
|
|
447
514
|
return transactionReceipt;
|
|
448
515
|
});
|
|
449
516
|
}
|
|
450
|
-
|
|
517
|
+
function getAnchoringClientAndSystemChainRid(client) {
|
|
451
518
|
return __awaiter(this, void 0, void 0, function* () {
|
|
452
|
-
const directoryClient = yield getSystemClient(getUrlsFromEndpoints(client.config.endpointPool), client.config.directoryChainRid);
|
|
453
|
-
const anchoringClient = yield getAnchoringClient(directoryClient, client.config.blockchainRid);
|
|
519
|
+
const directoryClient = yield getSystemClient((0, exports.getUrlsFromEndpoints)(client.config.endpointPool), client.config.directoryChainRid);
|
|
520
|
+
const anchoringClient = yield (0, IccfProofTxMaterialBuilder_1.getAnchoringClient)(directoryClient, client.config.blockchainRid);
|
|
454
521
|
const systemAnchoringChainRidBuffer = yield getSystemAnchoringChain(directoryClient);
|
|
455
522
|
const systemAnchoringChainBridString = systemAnchoringChainRidBuffer.toString("hex");
|
|
456
523
|
return { anchoringClient, systemAnchoringChainBridString };
|
|
457
524
|
});
|
|
458
525
|
}
|
|
459
|
-
|
|
526
|
+
function getSystemAnchoringTransaction(dappClientEndpointPool, anchoredTxRid, anchoringClient, systemAnchoringChainRid, systemAnchoringStatusPolling, merkleHashVersion) {
|
|
460
527
|
return __awaiter(this, void 0, void 0, function* () {
|
|
461
|
-
const systemAnchoringChainClient = yield getSystemClient(getUrlsFromEndpoints(dappClientEndpointPool), systemAnchoringChainRid);
|
|
528
|
+
const systemAnchoringChainClient = yield getSystemClient((0, exports.getUrlsFromEndpoints)(dappClientEndpointPool), systemAnchoringChainRid);
|
|
462
529
|
const clusterAnchoringProof = yield anchoringClient.getConfirmationProof(anchoredTxRid);
|
|
463
|
-
const clusterBlockRid = calculateBlockRID(clusterAnchoringProof, merkleHashVersion);
|
|
464
|
-
const systemAnchoringTransactionConfirmation = yield awaitGetAnchoringTransactionForBlockRid(systemAnchoringChainClient, toBuffer(anchoringClient.config.blockchainRid), clusterBlockRid, systemAnchoringStatusPolling);
|
|
465
|
-
const systemAnchoringTransactionValidation = AnchoringTransactionSchema.safeParse(systemAnchoringTransactionConfirmation);
|
|
530
|
+
const clusterBlockRid = (0, utils_1.calculateBlockRID)(clusterAnchoringProof, merkleHashVersion);
|
|
531
|
+
const systemAnchoringTransactionConfirmation = yield (0, utils_1.awaitGetAnchoringTransactionForBlockRid)(systemAnchoringChainClient, (0, formatter_1.toBuffer)(anchoringClient.config.blockchainRid), clusterBlockRid, systemAnchoringStatusPolling);
|
|
532
|
+
const systemAnchoringTransactionValidation = anchoringTransaction_1.AnchoringTransactionSchema.safeParse(systemAnchoringTransactionConfirmation);
|
|
466
533
|
if (!systemAnchoringTransactionValidation.success) {
|
|
467
534
|
return null;
|
|
468
535
|
}
|
|
@@ -479,22 +546,22 @@ export function getSystemAnchoringTransaction(dappClientEndpointPool, anchoredTx
|
|
|
479
546
|
* @returns - Returns a complete `StatusPolling` configuration object, with default values for any missing properties
|
|
480
547
|
* of the provided partial configuration
|
|
481
548
|
*/
|
|
482
|
-
|
|
549
|
+
function setStatusPolling(statusPolling) {
|
|
483
550
|
var _a, _b;
|
|
484
551
|
return {
|
|
485
552
|
interval: (_a = statusPolling === null || statusPolling === void 0 ? void 0 : statusPolling.interval) !== null && _a !== void 0 ? _a : 500,
|
|
486
553
|
count: (_b = statusPolling === null || statusPolling === void 0 ? void 0 : statusPolling.count) !== null && _b !== void 0 ? _b : 20,
|
|
487
554
|
};
|
|
488
555
|
}
|
|
489
|
-
|
|
556
|
+
function setRetryTransactionPolling(statusPolling) {
|
|
490
557
|
var _a, _b;
|
|
491
558
|
return {
|
|
492
559
|
interval: (_a = statusPolling === null || statusPolling === void 0 ? void 0 : statusPolling.interval) !== null && _a !== void 0 ? _a : 500,
|
|
493
560
|
count: (_b = statusPolling === null || statusPolling === void 0 ? void 0 : statusPolling.count) !== null && _b !== void 0 ? _b : 3,
|
|
494
561
|
};
|
|
495
562
|
}
|
|
496
|
-
|
|
497
|
-
const transactionEvents = Object.values(TransactionEvent).filter((event) => typeof event === "string");
|
|
563
|
+
function linkPromiEvents(event1, event2) {
|
|
564
|
+
const transactionEvents = Object.values(enums_1.TransactionEvent).filter((event) => typeof event === "string");
|
|
498
565
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
499
566
|
const forwardEvent = (eventName) => (receipt) => event2.emit(eventName, receipt);
|
|
500
567
|
for (const eventName of transactionEvents) {
|
|
@@ -507,7 +574,7 @@ export function linkPromiEvents(event1, event2) {
|
|
|
507
574
|
* @param responseObject the responsebody from the server
|
|
508
575
|
* @param callback the callback function to propagate the error and response back to the caller
|
|
509
576
|
*/
|
|
510
|
-
|
|
577
|
+
function handleGetResponse(error, statusCode, responseObject, callback) {
|
|
511
578
|
try {
|
|
512
579
|
const responseObjectPrintable = convertToPrintable(responseObject);
|
|
513
580
|
logger.debug(`error: ${error}, status code: ${statusCode}, response body: ${responseObjectPrintable}`);
|
|
@@ -515,7 +582,7 @@ export function handleGetResponse(error, statusCode, responseObject, callback) {
|
|
|
515
582
|
return callback(error, null);
|
|
516
583
|
}
|
|
517
584
|
if (statusCode !== 200) {
|
|
518
|
-
return callback(new UnexpectedStatusError(statusCode !== null && statusCode !== void 0 ? statusCode : 400, responseObjectPrintable), null);
|
|
585
|
+
return callback(new errors_1.UnexpectedStatusError(statusCode !== null && statusCode !== void 0 ? statusCode : 400, responseObjectPrintable), null);
|
|
519
586
|
}
|
|
520
587
|
return callback(null, responseObject);
|
|
521
588
|
}
|
|
@@ -530,7 +597,7 @@ export function handleGetResponse(error, statusCode, responseObject, callback) {
|
|
|
530
597
|
* @param responseObject the responsebody from the server
|
|
531
598
|
* @param callback the callback function to propagate the error and response back to the caller
|
|
532
599
|
*/
|
|
533
|
-
|
|
600
|
+
function handlePostResponse(error, statusCode, responseObject, callback) {
|
|
534
601
|
var _a;
|
|
535
602
|
const responseObjectPrintable = convertToPrintable(responseObject);
|
|
536
603
|
logger.debug(`error: ${error}, status code: ${statusCode}, response body: ${responseObjectPrintable}`);
|
|
@@ -539,7 +606,7 @@ export function handlePostResponse(error, statusCode, responseObject, callback)
|
|
|
539
606
|
logger.error(`In client post(). ${error}`);
|
|
540
607
|
callback(error, null);
|
|
541
608
|
}
|
|
542
|
-
else if (!statusCode || !isSuccessfulStatusCode(statusCode)) {
|
|
609
|
+
else if (!statusCode || !(0, http_utils_1.isSuccessfulStatusCode)(statusCode)) {
|
|
543
610
|
let errorMessage = `Unexpected status code from server. Code: ${statusCode}.`;
|
|
544
611
|
const errorMessageInResponseBody = !!responseObject && typeof responseObject === "object" && "error" in responseObject
|
|
545
612
|
? (_a = responseObject.error) === null || _a === void 0 ? void 0 : _a.toString()
|
|
@@ -548,7 +615,7 @@ export function handlePostResponse(error, statusCode, responseObject, callback)
|
|
|
548
615
|
errorMessage += ` Message: ${responseObjectPrintable}.`;
|
|
549
616
|
}
|
|
550
617
|
logger.error(errorMessage);
|
|
551
|
-
callback(new UnexpectedStatusError(statusCode !== null && statusCode !== void 0 ? statusCode : 400, errorMessageInResponseBody || responseObjectPrintable), responseObject);
|
|
618
|
+
callback(new errors_1.UnexpectedStatusError(statusCode !== null && statusCode !== void 0 ? statusCode : 400, errorMessageInResponseBody || responseObjectPrintable), responseObject);
|
|
552
619
|
}
|
|
553
620
|
else {
|
|
554
621
|
logger.info(`Calling responseCallback with responseObject: ${responseObjectPrintable}`);
|
|
@@ -559,10 +626,10 @@ export function handlePostResponse(error, statusCode, responseObject, callback)
|
|
|
559
626
|
logger.error(`client.handlePostResponse(): Failed to call callback function ${error}`);
|
|
560
627
|
}
|
|
561
628
|
}
|
|
562
|
-
|
|
629
|
+
function getBlockchainRidFromIid(_a) {
|
|
563
630
|
return __awaiter(this, arguments, void 0, function* ({ endpointPool, chainId, failOverConfig = {}, nodeManager, connectTimeout, responseTimeout, }) {
|
|
564
631
|
var _b;
|
|
565
|
-
const mergedFailOverConfig = Object.assign(Object.assign({}, defaultFailoverConfig), failOverConfig);
|
|
632
|
+
const mergedFailOverConfig = Object.assign(Object.assign({}, exports.defaultFailoverConfig), failOverConfig);
|
|
566
633
|
const config = {
|
|
567
634
|
endpointPool,
|
|
568
635
|
nodeManager,
|
|
@@ -574,26 +641,27 @@ export function getBlockchainRidFromIid(_a) {
|
|
|
574
641
|
attemptsPerEndpoint: mergedFailOverConfig.attemptsPerEndpoint,
|
|
575
642
|
attemptInterval: mergedFailOverConfig.attemptInterval,
|
|
576
643
|
unreachableDuration: mergedFailOverConfig.unreachableDuration,
|
|
577
|
-
merkleHashVersion: MERKLE_HASH_VERSIONS.UNSET,
|
|
644
|
+
merkleHashVersion: constants_1.MERKLE_HASH_VERSIONS.UNSET,
|
|
578
645
|
connectTimeout,
|
|
579
646
|
responseTimeout,
|
|
580
647
|
};
|
|
581
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `/brid/iid_${chainId}`, config, undefined, false, (_b = config.connectTimeout) !== null && _b !== void 0 ? _b : config.responseTimeout);
|
|
582
|
-
const blockchainRid = isString(rspBody);
|
|
648
|
+
const { error, statusCode, rspBody } = yield (0, requestWithFailoverStrategy_1.requestWithFailoverStrategy)(enums_1.Method.GET, `/brid/iid_${chainId}`, config, undefined, false, (_b = config.connectTimeout) !== null && _b !== void 0 ? _b : config.responseTimeout);
|
|
649
|
+
const blockchainRid = (0, requests_1.isString)(rspBody);
|
|
583
650
|
if (!blockchainRid) {
|
|
584
651
|
throw error;
|
|
585
652
|
}
|
|
586
653
|
if (error) {
|
|
587
|
-
throw new GetBridFromChainException(chainId, error.message);
|
|
654
|
+
throw new errors_1.GetBridFromChainException(chainId, error.message);
|
|
588
655
|
}
|
|
589
656
|
else if (statusCode !== 200) {
|
|
590
|
-
throw new GetBridFromChainException(chainId, blockchainRid);
|
|
657
|
+
throw new errors_1.GetBridFromChainException(chainId, blockchainRid);
|
|
591
658
|
}
|
|
592
659
|
return blockchainRid;
|
|
593
660
|
});
|
|
594
661
|
}
|
|
595
|
-
|
|
596
|
-
|
|
662
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
663
|
+
exports.sleep = sleep;
|
|
664
|
+
function convertToPrintable(responseObject) {
|
|
597
665
|
if (typeof responseObject === "bigint") {
|
|
598
666
|
return `${responseObject}n`;
|
|
599
667
|
}
|