postchain-client 1.19.1 → 1.20.1
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 +1592 -1350
- package/built/cjs/index.js.map +1 -1
- package/built/esm/index.js +915 -673
- package/built/esm/index.js.map +1 -1
- package/built/index.d.ts +5 -5
- package/built/index.js +3 -3
- package/built/index.js.map +1 -1
- package/built/mocks/handlers.js +4 -0
- package/built/mocks/handlers.js.map +1 -1
- package/built/src/ICCF/IccfProofTxMaterialBuilder.d.ts +1 -1
- package/built/src/ICCF/IccfProofTxMaterialBuilder.js +11 -14
- package/built/src/ICCF/IccfProofTxMaterialBuilder.js.map +1 -1
- package/built/src/ICCF/error.js.map +1 -1
- package/built/src/ICCF/utils.d.ts +2 -1
- package/built/src/ICCF/utils.js +24 -0
- package/built/src/ICCF/utils.js.map +1 -1
- package/built/src/blockchainClient/blockchainClient.js +160 -90
- package/built/src/blockchainClient/blockchainClient.js.map +1 -1
- package/built/src/blockchainClient/clientStub.js +16 -0
- package/built/src/blockchainClient/clientStub.js.map +1 -1
- package/built/src/blockchainClient/enums.d.ts +13 -0
- package/built/src/blockchainClient/enums.js +15 -0
- package/built/src/blockchainClient/enums.js.map +1 -1
- package/built/src/blockchainClient/errors.js.map +1 -1
- package/built/src/blockchainClient/interface.d.ts +41 -10
- package/built/src/blockchainClient/types.d.ts +14 -4
- package/built/src/blockchainClient/utils.d.ts +12 -3
- package/built/src/blockchainClient/utils.js +129 -15
- package/built/src/blockchainClient/utils.js.map +1 -1
- package/built/src/blockchainClient/validation/anchoringTransaction.d.ts +15 -0
- package/built/src/blockchainClient/validation/anchoringTransaction.js +14 -0
- package/built/src/blockchainClient/validation/anchoringTransaction.js.map +1 -0
- package/built/src/blockchainClient/validation/blockIdentifier.js +3 -5
- package/built/src/blockchainClient/validation/blockIdentifier.js.map +1 -1
- package/built/src/blockchainClient/validation/bufferSchema.js +1 -4
- package/built/src/blockchainClient/validation/bufferSchema.js.map +1 -1
- package/built/src/blockchainClient/validation/networkSettings.js +2 -4
- package/built/src/blockchainClient/validation/networkSettings.js.map +1 -1
- package/built/src/blockchainClient/validation/signMethod.js +1 -4
- package/built/src/blockchainClient/validation/signMethod.js.map +1 -1
- package/built/src/blockchainClient/validation/txRid.js +1 -1
- package/built/src/blockchainClient/validation/txRid.js.map +1 -1
- package/built/src/chromia/chromiaClientProvider.js.map +1 -1
- package/built/src/encryption/encryption.d.ts +2 -1
- package/built/src/encryption/encryption.js +1 -1
- package/built/src/encryption/encryption.js.map +1 -1
- package/built/src/formatter.d.ts +2 -1
- package/built/src/formatter.js +3 -3
- package/built/src/formatter.js.map +1 -1
- package/built/src/gtv/definition.js +2 -0
- package/built/src/gtv/definition.js.map +1 -1
- package/built/src/gtv/index.js +1 -1
- package/built/src/gtv/index.js.map +1 -1
- package/built/src/gtx/errors.js.map +1 -1
- package/built/src/gtx/gtx.js +3 -3
- package/built/src/gtx/gtx.js.map +1 -1
- package/built/src/gtx/gtxclient.js +13 -11
- package/built/src/gtx/gtxclient.js.map +1 -1
- package/built/src/gtx/interfaces.d.ts +4 -3
- package/built/src/gtx/serialization.js +8 -4
- package/built/src/gtx/serialization.js.map +1 -1
- package/built/src/gtx/types.d.ts +1 -5
- package/built/src/logger.js.map +1 -1
- package/built/src/merkle/merklehashcalculator.js +1 -0
- package/built/src/merkle/merklehashcalculator.js.map +1 -1
- package/built/src/merkle/proof/merklehashsummaryfactory.js +1 -0
- package/built/src/merkle/proof/merklehashsummaryfactory.js.map +1 -1
- package/built/src/merkle/proof/merkleprooftree.js +1 -0
- package/built/src/merkle/proof/merkleprooftree.js.map +1 -1
- package/built/src/merkle/proof/merkleprooftreefactory.js +1 -0
- package/built/src/merkle/proof/merkleprooftreefactory.js.map +1 -1
- package/built/src/promiEvent/promiEventEmitter.d.ts +4 -1
- package/built/src/promiEvent/promiEventEmitter.js.map +1 -1
- package/built/src/promiEvent/promiEvents.js.map +1 -1
- package/built/src/restclient/errors.js.map +1 -1
- package/built/src/restclient/failoverStrategies.js +14 -16
- package/built/src/restclient/failoverStrategies.js.map +1 -1
- package/built/src/restclient/httpUtil.js +21 -2
- package/built/src/restclient/httpUtil.js.map +1 -1
- package/built/src/restclient/interfaces.d.ts +2 -1
- package/built/src/restclient/nodeManager.d.ts +2 -2
- package/built/src/restclient/nodeManager.js +3 -3
- package/built/src/restclient/nodeManager.js.map +1 -1
- package/built/src/restclient/restclient.d.ts +2 -2
- package/built/src/restclient/restclient.js +9 -13
- package/built/src/restclient/restclient.js.map +1 -1
- package/built/src/restclient/restclientutil.d.ts +2 -2
- package/built/src/restclient/restclientutil.js +6 -10
- package/built/src/restclient/restclientutil.js.map +1 -1
- package/built/src/restclient/types.d.ts +3 -13
- package/built/src/restclient/types.js +1 -7
- package/built/src/restclient/types.js.map +1 -1
- package/built/src/utils/dump.js +3 -5
- package/built/src/utils/dump.js.map +1 -1
- package/built/src/utils/dump.test.js.map +1 -1
- package/built/test/integration/blockchainClientIntegration.test.js +1323 -0
- package/built/test/integration/blockchainClientIntegration.test.js.map +1 -0
- package/built/test/integration/blockchainClientUtils.test.js +46 -0
- package/built/test/integration/blockchainClientUtils.test.js.map +1 -0
- package/built/test/integration/encodeTransaction.test.js +52 -0
- package/built/test/integration/encodeTransaction.test.js.map +1 -0
- package/built/test/integration/gtxClientIntegration.test.js +334 -0
- package/built/test/integration/gtxClientIntegration.test.js.map +1 -0
- package/built/test/integration/iccfProofTxIntegration.test.d.ts +1 -0
- package/built/test/integration/iccfProofTxIntegration.test.js +116 -0
- package/built/test/integration/iccfProofTxIntegration.test.js.map +1 -0
- package/built/test/integration/merkleIntegration.test.d.ts +1 -0
- package/built/test/integration/merkleIntegration.test.js +137 -0
- package/built/test/integration/merkleIntegration.test.js.map +1 -0
- package/built/test/integration/objectGenerator.d.ts +3 -0
- package/built/test/integration/objectGenerator.js +17 -0
- package/built/test/integration/objectGenerator.js.map +1 -0
- package/built/test/integration/restClientIntegration.test.d.ts +1 -0
- package/built/test/integration/restClientIntegration.test.js +169 -0
- package/built/test/integration/restClientIntegration.test.js.map +1 -0
- package/built/test/integration/testData.d.ts +6 -0
- package/built/test/integration/testData.js +564 -0
- package/built/test/integration/testData.js.map +1 -0
- package/built/test/integrationDevnet/getTransactionConfirmationLevel.test.d.ts +1 -0
- package/built/test/integrationDevnet/getTransactionConfirmationLevel.test.js +75 -0
- package/built/test/integrationDevnet/getTransactionConfirmationLevel.test.js.map +1 -0
- package/built/test/integrationDevnet/signAndSendUniqueTransaction.test.d.ts +1 -0
- package/built/test/integrationDevnet/signAndSendUniqueTransaction.test.js +85 -0
- package/built/test/integrationDevnet/signAndSendUniqueTransaction.test.js.map +1 -0
- package/built/test/manual/chromiaClientProviderManually.test.d.ts +1 -0
- package/built/test/manual/chromiaClientProviderManually.test.js +27 -0
- package/built/test/manual/chromiaClientProviderManually.test.js.map +1 -0
- package/built/test/manual/iccfManually.test.d.ts +1 -0
- package/built/test/manual/iccfManually.test.js +115 -0
- package/built/test/manual/iccfManually.test.js.map +1 -0
- package/built/test/manual/restClientManually.test.d.ts +1 -0
- package/built/test/manual/restClientManually.test.js +52 -0
- package/built/test/manual/restClientManually.test.js.map +1 -0
- package/built/test/unit/ICCF/iccf.test.d.ts +1 -0
- package/built/test/unit/ICCF/iccf.test.js +281 -0
- package/built/test/unit/ICCF/iccf.test.js.map +1 -0
- package/built/test/unit/ICCF/iccfProofMaterialBuilder.test.d.ts +2 -0
- package/built/test/unit/ICCF/iccfProofMaterialBuilder.test.js +379 -0
- package/built/test/unit/ICCF/iccfProofMaterialBuilder.test.js.map +1 -0
- package/built/test/unit/ICCF/util.d.ts +6 -0
- package/built/test/unit/ICCF/util.js +20 -0
- package/built/test/unit/ICCF/util.js.map +1 -0
- package/built/test/unit/blockchainClient/blockchainClient.test.d.ts +1 -0
- package/built/test/unit/blockchainClient/blockchainClient.test.js +65 -0
- package/built/test/unit/blockchainClient/blockchainClient.test.js.map +1 -0
- package/built/test/unit/blockchainClient/clientCustomStatusCodes.test.d.ts +1 -0
- package/built/test/unit/blockchainClient/clientCustomStatusCodes.test.js +66 -0
- package/built/test/unit/blockchainClient/clientCustomStatusCodes.test.js.map +1 -0
- package/built/test/unit/blockchainClient/getSystemAnchoringTransactionConfirmation.test.d.ts +1 -0
- package/built/test/unit/blockchainClient/getSystemAnchoringTransactionConfirmation.test.js +98 -0
- package/built/test/unit/blockchainClient/getSystemAnchoringTransactionConfirmation.test.js.map +1 -0
- package/built/test/unit/blockchainClient/getTransactionConfirmationLevel.test.d.ts +1 -0
- package/built/test/unit/blockchainClient/getTransactionConfirmationLevel.test.js +156 -0
- package/built/test/unit/blockchainClient/getTransactionConfirmationLevel.test.js.map +1 -0
- package/built/test/unit/blockchainClient/helpers/sendTransaction.d.ts +22 -0
- package/built/test/unit/blockchainClient/helpers/sendTransaction.js +34 -0
- package/built/test/unit/blockchainClient/helpers/sendTransaction.js.map +1 -0
- package/built/test/unit/blockchainClient/sendTransaction.test.d.ts +1 -0
- package/built/test/unit/blockchainClient/sendTransaction.test.js +478 -0
- package/built/test/unit/blockchainClient/sendTransaction.test.js.map +1 -0
- package/built/test/unit/blockchainClient/util.test.d.ts +1 -0
- package/built/test/unit/blockchainClient/util.test.js +164 -0
- package/built/test/unit/blockchainClient/util.test.js.map +1 -0
- package/built/test/unit/chromiaClientProvider.test.d.ts +1 -0
- package/built/test/unit/chromiaClientProvider.test.js +72 -0
- package/built/test/unit/chromiaClientProvider.test.js.map +1 -0
- package/built/test/unit/encryption/encryption.test.d.ts +1 -0
- package/built/test/unit/encryption/encryption.test.js +75 -0
- package/built/test/unit/encryption/encryption.test.js.map +1 -0
- package/built/test/unit/failoverStrategies.test.d.ts +1 -0
- package/built/test/unit/failoverStrategies.test.js +427 -0
- package/built/test/unit/failoverStrategies.test.js.map +1 -0
- package/built/test/unit/formatter.test.d.ts +1 -0
- package/built/test/unit/formatter.test.js +102 -0
- package/built/test/unit/formatter.test.js.map +1 -0
- package/built/test/unit/gtv/gtvHash.test.d.ts +1 -0
- package/built/test/unit/gtv/gtvHash.test.js +19 -0
- package/built/test/unit/gtv/gtvHash.test.js.map +1 -0
- package/built/test/unit/gtx/checkGTXSignature.test.d.ts +1 -0
- package/built/test/unit/gtx/checkGTXSignature.test.js +66 -0
- package/built/test/unit/gtx/checkGTXSignature.test.js.map +1 -0
- package/built/test/unit/gtx/gtxClient.test.d.ts +1 -0
- package/built/test/unit/gtx/gtxClient.test.js +97 -0
- package/built/test/unit/gtx/gtxClient.test.js.map +1 -0
- package/built/test/unit/gtx/newSignatureProvider.test.d.ts +1 -0
- package/built/test/unit/gtx/newSignatureProvider.test.js +45 -0
- package/built/test/unit/gtx/newSignatureProvider.test.js.map +1 -0
- package/built/test/unit/gtx/serialization.test.d.ts +1 -0
- package/built/test/unit/gtx/serialization.test.js +267 -0
- package/built/test/unit/gtx/serialization.test.js.map +1 -0
- package/built/test/unit/gtx/serializationtestobjects.d.ts +6 -0
- package/built/test/unit/gtx/serializationtestobjects.js +51 -0
- package/built/test/unit/gtx/serializationtestobjects.js.map +1 -0
- package/built/test/unit/httpUtil.test.d.ts +1 -0
- package/built/test/unit/httpUtil.test.js +46 -0
- package/built/test/unit/httpUtil.test.js.map +1 -0
- package/built/test/unit/logger.test.js +1 -1
- package/built/test/unit/logger.test.js.map +1 -1
- package/built/test/unit/merkle/merkleHelper/merkleHelperTest.d.ts +1 -0
- package/built/test/unit/merkle/merkleHelper/merkleHelperTest.js +87 -0
- package/built/test/unit/merkle/merkleHelper/merkleHelperTest.js.map +1 -0
- package/built/test/unit/nodeMananger.test.d.ts +1 -0
- package/built/test/unit/nodeMananger.test.js +215 -0
- package/built/test/unit/nodeMananger.test.js.map +1 -0
- package/built/test/unit/requestWithFailoverStrategy.test.d.ts +1 -0
- package/built/test/unit/requestWithFailoverStrategy.test.js +139 -0
- package/built/test/unit/requestWithFailoverStrategy.test.js.map +1 -0
- package/built/test/unit/restClient.test.d.ts +1 -0
- package/built/test/unit/restClient.test.js +388 -0
- package/built/test/unit/restClient.test.js.map +1 -0
- package/built/test/unit/restClientUtil.test.d.ts +1 -0
- package/built/test/unit/restClientUtil.test.js +219 -0
- package/built/test/unit/restClientUtil.test.js.map +1 -0
- package/built/test/unit/signatures.d.ts +17 -0
- package/built/test/unit/signatures.js +49 -0
- package/built/test/unit/signatures.js.map +1 -0
- package/built/test/unit/stickyNode.test.d.ts +1 -0
- package/built/test/unit/stickyNode.test.js +123 -0
- package/built/test/unit/stickyNode.test.js.map +1 -0
- package/built/test/unit/validation/anchoringTransaction.test.d.ts +1 -0
- package/built/test/unit/validation/anchoringTransaction.test.js +84 -0
- package/built/test/unit/validation/anchoringTransaction.test.js.map +1 -0
- package/built/test/unit/validation/blockIdentifier.test.d.ts +1 -0
- package/built/{src/blockchainClient → test/unit}/validation/blockIdentifier.test.js +2 -3
- package/built/test/unit/validation/blockIdentifier.test.js.map +1 -0
- package/built/test/unit/validation/bufferSchema.test.d.ts +1 -0
- package/built/test/unit/validation/bufferSchema.test.js +17 -0
- package/built/test/unit/validation/bufferSchema.test.js.map +1 -0
- package/built/test/unit/validation/networkSettings.test.d.ts +1 -0
- package/built/{src/blockchainClient → test/unit}/validation/networkSettings.test.js +1 -1
- package/built/test/unit/validation/networkSettings.test.js.map +1 -0
- package/built/test/unit/validation/signMethod.test.d.ts +1 -0
- package/built/{src/blockchainClient → test/unit}/validation/signMethod.test.js +1 -1
- package/built/test/unit/validation/signMethod.test.js.map +1 -0
- package/built/test/unit/validation/txRid.test.d.ts +1 -0
- package/built/{src/blockchainClient → test/unit}/validation/txRid.test.js +1 -1
- package/built/test/unit/validation/txRid.test.js.map +1 -0
- package/built/umd/index.js +914 -672
- package/built/umd/index.js.map +1 -1
- package/changelog.md +42 -4
- package/package.json +16 -7
- package/built/src/blockchainClient/validation/blockIdentifier.test.js.map +0 -1
- package/built/src/blockchainClient/validation/networkSettings.test.js.map +0 -1
- package/built/src/blockchainClient/validation/signMethod.test.js.map +0 -1
- package/built/src/blockchainClient/validation/txRid.test.js.map +0 -1
- /package/built/{src/blockchainClient/validation/blockIdentifier.test.d.ts → test/integration/blockchainClientIntegration.test.d.ts} +0 -0
- /package/built/{src/blockchainClient/validation/networkSettings.test.d.ts → test/integration/blockchainClientUtils.test.d.ts} +0 -0
- /package/built/{src/blockchainClient/validation/signMethod.test.d.ts → test/integration/encodeTransaction.test.d.ts} +0 -0
- /package/built/{src/blockchainClient/validation/txRid.test.d.ts → test/integration/gtxClientIntegration.test.d.ts} +0 -0
package/built/cjs/index.js
CHANGED
|
@@ -5,8 +5,8 @@ var bn_js = require('bn.js');
|
|
|
5
5
|
var crypto = require('crypto');
|
|
6
6
|
var secp256k1 = require('secp256k1');
|
|
7
7
|
var cloneDeep = require('lodash/cloneDeep');
|
|
8
|
-
var events = require('events');
|
|
9
8
|
var zod = require('zod');
|
|
9
|
+
var events = require('events');
|
|
10
10
|
|
|
11
11
|
function _interopNamespaceDefault(e) {
|
|
12
12
|
var n = Object.create(null);
|
|
@@ -56,6 +56,8 @@ function getAugmentedNamespace(n) {
|
|
|
56
56
|
return a;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
+
/* eslint-disable @typescript-eslint/ban-ts-comment */
|
|
60
|
+
// @ts-nocheck
|
|
59
61
|
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
60
62
|
const asn = require("@chromia/asn1/lib/asn1");
|
|
61
63
|
const ASNDictPair = asn.define("DictPair", function () {
|
|
@@ -189,7 +191,7 @@ function checkGtvType(value) {
|
|
|
189
191
|
return true;
|
|
190
192
|
}
|
|
191
193
|
if (value.constructor === Array) {
|
|
192
|
-
value.map(
|
|
194
|
+
value.map(item => checkGtvType(item));
|
|
193
195
|
return true;
|
|
194
196
|
}
|
|
195
197
|
if (typeof value === "object") {
|
|
@@ -236,14 +238,14 @@ function checkGtxType(value) {
|
|
|
236
238
|
}
|
|
237
239
|
function removeDuplicateSigners(signers) {
|
|
238
240
|
const signersAsString = [];
|
|
239
|
-
signers.forEach(
|
|
241
|
+
signers.forEach(item => {
|
|
240
242
|
const itemAsString = item.toString("hex");
|
|
241
243
|
if (!signersAsString.includes(itemAsString)) {
|
|
242
244
|
signersAsString.push(itemAsString);
|
|
243
245
|
}
|
|
244
246
|
});
|
|
245
247
|
const result = [];
|
|
246
|
-
signersAsString.forEach(
|
|
248
|
+
signersAsString.forEach(item => {
|
|
247
249
|
result.push(require$$0$1.Buffer.from(item, "hex"));
|
|
248
250
|
});
|
|
249
251
|
return result;
|
|
@@ -279,9 +281,13 @@ function encodeValueGtx(rawGtx) {
|
|
|
279
281
|
return encodeValue(rawGtx);
|
|
280
282
|
}
|
|
281
283
|
function decodeValue(bytes) {
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
284
|
+
try {
|
|
285
|
+
const obj = rawGTV.decode(bytes);
|
|
286
|
+
return parseValue(obj);
|
|
287
|
+
}
|
|
288
|
+
catch (error) {
|
|
289
|
+
throw new Error(`Invalid GTV data. ${error}`);
|
|
290
|
+
}
|
|
285
291
|
}
|
|
286
292
|
function decodeValueGtx(bytes) {
|
|
287
293
|
const decodedValue = decodeValue(bytes);
|
|
@@ -349,7 +355,7 @@ function createTypedArg(value) {
|
|
|
349
355
|
if (value.constructor === Array) {
|
|
350
356
|
return {
|
|
351
357
|
type: "array",
|
|
352
|
-
value: value.map(
|
|
358
|
+
value: value.map(item => createTypedArg(item)),
|
|
353
359
|
};
|
|
354
360
|
}
|
|
355
361
|
if (typeof value === "object") {
|
|
@@ -1889,7 +1895,7 @@ function rawGtvToGtx(gtv) {
|
|
|
1889
1895
|
if (!Array.isArray(gtvArray[1])) {
|
|
1890
1896
|
throw new Error("Second element must be an array");
|
|
1891
1897
|
}
|
|
1892
|
-
gtvArray[1].forEach(
|
|
1898
|
+
gtvArray[1].forEach(element => {
|
|
1893
1899
|
if (!Buffer.isBuffer(element)) {
|
|
1894
1900
|
throw new Error("Element must be a buffer");
|
|
1895
1901
|
}
|
|
@@ -1911,14 +1917,14 @@ function rawGtvToGtxBody(gtv) {
|
|
|
1911
1917
|
if (!Array.isArray(array[2])) {
|
|
1912
1918
|
throw new Error("Third element must be an array");
|
|
1913
1919
|
}
|
|
1914
|
-
array[2].forEach(
|
|
1920
|
+
array[2].forEach(element => {
|
|
1915
1921
|
if (!Buffer.isBuffer(element)) {
|
|
1916
1922
|
throw new Error("Element must be a buffer");
|
|
1917
1923
|
}
|
|
1918
1924
|
});
|
|
1919
1925
|
return {
|
|
1920
1926
|
blockchainRid: array[0],
|
|
1921
|
-
operations: array[1].map(
|
|
1927
|
+
operations: array[1].map(element => rawGtvToRellOp(element)),
|
|
1922
1928
|
signers: array[2],
|
|
1923
1929
|
};
|
|
1924
1930
|
}
|
|
@@ -2096,10 +2102,10 @@ function createClient$1(restApiClient, blockchainRid, functionNames) {
|
|
|
2096
2102
|
? `privkey: ${privOrSigProv.toString("hex")}`
|
|
2097
2103
|
: `signature provider [pubKey: ${privOrSigProv.pubKey}]`}`);
|
|
2098
2104
|
if (privOrSigProv instanceof require$$0$1.Buffer) {
|
|
2099
|
-
yield sign(
|
|
2105
|
+
yield sign(gtx$1, privOrSigProv, pubKey);
|
|
2100
2106
|
}
|
|
2101
2107
|
else {
|
|
2102
|
-
yield sign(
|
|
2108
|
+
yield sign(gtx$1, privOrSigProv);
|
|
2103
2109
|
}
|
|
2104
2110
|
});
|
|
2105
2111
|
},
|
|
@@ -2110,28 +2116,31 @@ function createClient$1(restApiClient, blockchainRid, functionNames) {
|
|
|
2110
2116
|
return getDigestToSign(this.gtx);
|
|
2111
2117
|
},
|
|
2112
2118
|
addSignature: function (pubKey, signature) {
|
|
2113
|
-
addSignature(pubKey, signature,
|
|
2119
|
+
addSignature(pubKey, signature, gtx$1);
|
|
2114
2120
|
},
|
|
2115
2121
|
// raw call
|
|
2116
2122
|
addOperation: function (name, ...args) {
|
|
2117
|
-
addTransactionToGtx(name, args,
|
|
2123
|
+
addTransactionToGtx(name, args, gtx$1);
|
|
2118
2124
|
},
|
|
2119
2125
|
postAndWaitConfirmation() {
|
|
2120
|
-
return restApiClient.postAndWaitConfirmation(serialize(
|
|
2126
|
+
return restApiClient.postAndWaitConfirmation(serialize(gtx$1), this.getTxRID());
|
|
2121
2127
|
},
|
|
2122
2128
|
send: function (callback) {
|
|
2123
|
-
const gtxBytes = serialize(
|
|
2129
|
+
const gtxBytes = serialize(gtx$1);
|
|
2124
2130
|
restApiClient.postTransaction(gtxBytes, callback);
|
|
2125
|
-
|
|
2131
|
+
// Todo it seems like an error to set a non nullable parent function's input to null
|
|
2132
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2133
|
+
// @ts-ignore
|
|
2134
|
+
gtx$1 = null;
|
|
2126
2135
|
this.gtxBytes = gtxBytes;
|
|
2127
2136
|
},
|
|
2128
2137
|
encode: function () {
|
|
2129
|
-
return serialize(
|
|
2138
|
+
return serialize(gtx$1);
|
|
2130
2139
|
},
|
|
2131
2140
|
};
|
|
2132
2141
|
}
|
|
2133
2142
|
function addFunctions(req) {
|
|
2134
|
-
functionNames.forEach(
|
|
2143
|
+
functionNames.forEach(functionName => {
|
|
2135
2144
|
req[functionName] = function (...args) {
|
|
2136
2145
|
addTransactionToGtx(functionName, args, this.gtx);
|
|
2137
2146
|
};
|
|
@@ -2141,7 +2150,7 @@ function createClient$1(restApiClient, blockchainRid, functionNames) {
|
|
|
2141
2150
|
newTransaction: function (signers) {
|
|
2142
2151
|
signers = removeDuplicateSigners(signers);
|
|
2143
2152
|
const newGtx = emptyGtx(require$$0$1.Buffer.from(blockchainRid, "hex"));
|
|
2144
|
-
signers.forEach(
|
|
2153
|
+
signers.forEach(signer => addSignerToGtx(signer, newGtx));
|
|
2145
2154
|
const req = transaction(newGtx);
|
|
2146
2155
|
addFunctions(req);
|
|
2147
2156
|
return req;
|
|
@@ -2170,14 +2179,6 @@ var gtxclient = /*#__PURE__*/Object.freeze({
|
|
|
2170
2179
|
createClient: createClient$1
|
|
2171
2180
|
});
|
|
2172
2181
|
|
|
2173
|
-
var ResponseStatus;
|
|
2174
|
-
(function (ResponseStatus) {
|
|
2175
|
-
ResponseStatus["Confirmed"] = "confirmed";
|
|
2176
|
-
ResponseStatus["Rejected"] = "rejected";
|
|
2177
|
-
ResponseStatus["Unknown"] = "unknown";
|
|
2178
|
-
ResponseStatus["Waiting"] = "waiting";
|
|
2179
|
-
})(ResponseStatus || (ResponseStatus = {}));
|
|
2180
|
-
|
|
2181
2182
|
class TxRejectedError extends Error {
|
|
2182
2183
|
constructor(rejectReason) {
|
|
2183
2184
|
super(`Transaction was rejected, ${rejectReason}`);
|
|
@@ -2318,7 +2319,7 @@ function post(path, endpoint, requestBody) {
|
|
|
2318
2319
|
return {
|
|
2319
2320
|
error: null,
|
|
2320
2321
|
statusCode: response.status,
|
|
2321
|
-
rspBody:
|
|
2322
|
+
rspBody: yield constructBufferPostResponseBody(response),
|
|
2322
2323
|
};
|
|
2323
2324
|
}
|
|
2324
2325
|
catch (error) {
|
|
@@ -2330,11 +2331,15 @@ function post(path, endpoint, requestBody) {
|
|
|
2330
2331
|
const response = yield fetch(new URL(path, endpoint).href, {
|
|
2331
2332
|
method: "post",
|
|
2332
2333
|
body: JSON.stringify(requestBody),
|
|
2334
|
+
headers: {
|
|
2335
|
+
Accept: "application/json",
|
|
2336
|
+
"Content-Type": "application/json",
|
|
2337
|
+
},
|
|
2333
2338
|
});
|
|
2334
2339
|
return {
|
|
2335
2340
|
error: null,
|
|
2336
2341
|
statusCode: response.status,
|
|
2337
|
-
rspBody: yield response
|
|
2342
|
+
rspBody: yield constructBufferPostResponseBody(response),
|
|
2338
2343
|
};
|
|
2339
2344
|
}
|
|
2340
2345
|
catch (error) {
|
|
@@ -2343,6 +2348,21 @@ function post(path, endpoint, requestBody) {
|
|
|
2343
2348
|
}
|
|
2344
2349
|
});
|
|
2345
2350
|
}
|
|
2351
|
+
function constructBufferPostResponseBody(response) {
|
|
2352
|
+
return __awaiter$a(this, void 0, void 0, function* () {
|
|
2353
|
+
const contentType = response.headers.get("content-type");
|
|
2354
|
+
if (contentType === "application/octet-stream") {
|
|
2355
|
+
const responseBuffer = yield response.arrayBuffer();
|
|
2356
|
+
const buffer = require$$0$1.Buffer.from(responseBuffer);
|
|
2357
|
+
return decodeValue(buffer);
|
|
2358
|
+
}
|
|
2359
|
+
if (contentType === "application/json") {
|
|
2360
|
+
return yield response.json();
|
|
2361
|
+
}
|
|
2362
|
+
const responseText = yield response.text();
|
|
2363
|
+
return responseText ? responseText : response.statusText;
|
|
2364
|
+
});
|
|
2365
|
+
}
|
|
2346
2366
|
|
|
2347
2367
|
var __awaiter$9 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2348
2368
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -2363,7 +2383,7 @@ function abortOnError({ method, path, config, postObject, }) {
|
|
|
2363
2383
|
path,
|
|
2364
2384
|
config,
|
|
2365
2385
|
postObject,
|
|
2366
|
-
validateStatusCode:
|
|
2386
|
+
validateStatusCode: statuscode => !hasServerError(statuscode),
|
|
2367
2387
|
});
|
|
2368
2388
|
});
|
|
2369
2389
|
}
|
|
@@ -2374,7 +2394,7 @@ function tryNextOnError({ method, path, config, postObject, }) {
|
|
|
2374
2394
|
path,
|
|
2375
2395
|
config,
|
|
2376
2396
|
postObject,
|
|
2377
|
-
validateStatusCode:
|
|
2397
|
+
validateStatusCode: statusCode => !hasClientError(statusCode) && !hasServerError(statusCode),
|
|
2378
2398
|
});
|
|
2379
2399
|
});
|
|
2380
2400
|
}
|
|
@@ -2394,9 +2414,9 @@ function queryMajority({ method, path, config, postObject, }) {
|
|
|
2394
2414
|
nodeManager.makeAllNodesAvailable();
|
|
2395
2415
|
}
|
|
2396
2416
|
const outcomes = [];
|
|
2397
|
-
const promises = nodeManager.getAvailableNodes().map(
|
|
2417
|
+
const promises = nodeManager.getAvailableNodes().map(node => {
|
|
2398
2418
|
return handleRequest(method, path, node.url, postObject)
|
|
2399
|
-
.then(
|
|
2419
|
+
.then(response => {
|
|
2400
2420
|
const { statusCode } = response;
|
|
2401
2421
|
if (statusCode && isSuccessfullRequest(statusCode)) {
|
|
2402
2422
|
outcomes.push({ type: "SUCCESS", result: response });
|
|
@@ -2420,17 +2440,16 @@ function queryMajority({ method, path, config, postObject, }) {
|
|
|
2420
2440
|
remainingPromises = yield racePromisesWithTimeout(remainingPromises, timeout);
|
|
2421
2441
|
}
|
|
2422
2442
|
// Evaluate the outcomes
|
|
2423
|
-
const successfullOutcomes = outcomes.filter(
|
|
2424
|
-
const failureOutcomes = outcomes.filter(
|
|
2425
|
-
const errorOutcomes = outcomes.filter(
|
|
2443
|
+
const successfullOutcomes = outcomes.filter(outcome => outcome.type === "SUCCESS");
|
|
2444
|
+
const failureOutcomes = outcomes.filter(outcome => outcome.type === "FAILURE");
|
|
2445
|
+
const errorOutcomes = outcomes.filter(outcome => outcome.type === "ERROR");
|
|
2426
2446
|
// group all of the same responses together into groups and count each groups size
|
|
2427
2447
|
const groupedSuccessfullResponses = groupResponses(successfullOutcomes);
|
|
2428
2448
|
// validate the responses
|
|
2429
2449
|
// eslint-disable-next-line no-constant-condition
|
|
2430
2450
|
while (true) {
|
|
2431
2451
|
// Successfull majority response was found
|
|
2432
|
-
if (groupedSuccessfullResponses.maxNumberOfEqualResponses() >=
|
|
2433
|
-
bftMajorityThreshold) {
|
|
2452
|
+
if (groupedSuccessfullResponses.maxNumberOfEqualResponses() >= bftMajorityThreshold) {
|
|
2434
2453
|
if (groupedSuccessfullResponses.numberOfDistinctResponses() > 1) {
|
|
2435
2454
|
warning(`Got disagreeing responses, but could still reach BFT majority`);
|
|
2436
2455
|
}
|
|
@@ -2460,11 +2479,12 @@ function singleEndpoint({ method, path, config, postObject, }) {
|
|
|
2460
2479
|
let statusCode, rspBody, error;
|
|
2461
2480
|
const { nodeManager } = config;
|
|
2462
2481
|
const endpoint = nodeManager.getNode();
|
|
2482
|
+
if (!endpoint) {
|
|
2483
|
+
throw new Error("Cannot get endpoint. Node not found!");
|
|
2484
|
+
}
|
|
2463
2485
|
for (let attempt = 0; attempt < config.attemptsPerEndpoint; attempt++) {
|
|
2464
2486
|
({ error, statusCode, rspBody } = yield handleRequest(method, path, endpoint.url, postObject));
|
|
2465
|
-
const isError = statusCode
|
|
2466
|
-
? hasServerError(statusCode) || hasClientError(statusCode)
|
|
2467
|
-
: false;
|
|
2487
|
+
const isError = statusCode ? hasServerError(statusCode) || hasClientError(statusCode) : false;
|
|
2468
2488
|
if (!isError && !error) {
|
|
2469
2489
|
return { error, statusCode, rspBody };
|
|
2470
2490
|
}
|
|
@@ -2486,9 +2506,7 @@ function retryRequest({ method, path, config, postObject, validateStatusCode, })
|
|
|
2486
2506
|
for (const endpoint of nodeManager.getAvailableNodes()) {
|
|
2487
2507
|
for (let attempt = 0; attempt < config.attemptsPerEndpoint; attempt++) {
|
|
2488
2508
|
({ error, statusCode, rspBody } = yield handleRequest(method, path, endpoint.url, postObject));
|
|
2489
|
-
const isStatusCodeValid = statusCode
|
|
2490
|
-
? validateStatusCode(statusCode)
|
|
2491
|
-
: false;
|
|
2509
|
+
const isStatusCodeValid = statusCode ? validateStatusCode(statusCode) : false;
|
|
2492
2510
|
const isServerError = statusCode ? hasServerError(statusCode) : false;
|
|
2493
2511
|
if (isStatusCodeValid && !error) {
|
|
2494
2512
|
// Find a way to have this handled more elegantly in the node manager.
|
|
@@ -2548,77 +2566,75 @@ class GetTransactionRidException extends CustomError {
|
|
|
2548
2566
|
}
|
|
2549
2567
|
}
|
|
2550
2568
|
|
|
2551
|
-
|
|
2552
|
-
This file is part of web3.js.
|
|
2553
|
-
|
|
2554
|
-
web3.js is free software: you can redistribute it and/or modify
|
|
2555
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
2556
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
2557
|
-
(at your option) any later version.
|
|
2558
|
-
|
|
2559
|
-
web3.js is distributed in the hope that it will be useful,
|
|
2560
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
2561
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
2562
|
-
GNU Lesser General Public License for more details.
|
|
2569
|
+
const BufferSchema = zod.z.union([zod.z.instanceof(Uint8Array), zod.z.instanceof(Buffer)]);
|
|
2563
2570
|
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
on(eventName, fn) {
|
|
2572
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
2573
|
-
this._emitter.on(eventName, fn);
|
|
2574
|
-
}
|
|
2575
|
-
once(eventName, fn) {
|
|
2576
|
-
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
2577
|
-
this._emitter.once(eventName, fn);
|
|
2571
|
+
const TxRidSchema = BufferSchema.refine(x => x.length === 32, "Rid must be 32 bytes long");
|
|
2572
|
+
const isTxRidValid = (rid, options) => {
|
|
2573
|
+
const TxRidValidationContext = TxRidSchema.safeParse(rid);
|
|
2574
|
+
const { throwOnError = false } = options || {};
|
|
2575
|
+
const hasError = "error" in TxRidValidationContext;
|
|
2576
|
+
if (!hasError) {
|
|
2577
|
+
return { success: true };
|
|
2578
2578
|
}
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
|
|
2579
|
+
const validationError = new InvalidTxRidException(rid);
|
|
2580
|
+
if (throwOnError) {
|
|
2581
|
+
throw validationError;
|
|
2582
2582
|
}
|
|
2583
|
-
|
|
2584
|
-
|
|
2583
|
+
return {
|
|
2584
|
+
success: false,
|
|
2585
|
+
error: TxRidValidationContext.error,
|
|
2586
|
+
message: validationError.message,
|
|
2587
|
+
};
|
|
2588
|
+
};
|
|
2589
|
+
|
|
2590
|
+
const AnchoringTransactionSchema = zod.z.object({
|
|
2591
|
+
txRid: zod.z.instanceof(Buffer).superRefine((rid, refCtx) => {
|
|
2592
|
+
const txRidValidation = TxRidSchema.safeParse(rid);
|
|
2593
|
+
if (!txRidValidation.success)
|
|
2594
|
+
txRidValidation.error.issues.forEach(issue => refCtx.addIssue(issue));
|
|
2595
|
+
}),
|
|
2596
|
+
txData: zod.z.instanceof(Buffer).refine(data => data.length > 0, {
|
|
2597
|
+
message: "txData must be a non-empty Buffer",
|
|
2598
|
+
}),
|
|
2599
|
+
txOpIndex: zod.z.number().int().nonnegative({ message: "txOpIndex must be a non-negative integer" }),
|
|
2600
|
+
});
|
|
2601
|
+
|
|
2602
|
+
class MissingTransactionProof extends Error {
|
|
2603
|
+
constructor(proofHash, fetchedTxHash) {
|
|
2604
|
+
super(`Unable to verify source transaction proof,transaction hash in proof ${toString(proofHash)} does not match hash from fetched transaction ${toString(fetchedTxHash)}`);
|
|
2585
2605
|
}
|
|
2586
|
-
|
|
2587
|
-
|
|
2606
|
+
}
|
|
2607
|
+
class DifferentNumberOfSignersException extends Error {
|
|
2608
|
+
constructor(length, comparableLength) {
|
|
2609
|
+
super(`Transaction signatures amount ${length} do not match expected amount of signers ${comparableLength}`);
|
|
2588
2610
|
}
|
|
2589
|
-
|
|
2590
|
-
|
|
2611
|
+
}
|
|
2612
|
+
class SignatureException extends Error {
|
|
2613
|
+
constructor(signer) {
|
|
2614
|
+
super(`Expected signer ${toString(signer)} has not signed source transaction`);
|
|
2591
2615
|
}
|
|
2592
|
-
|
|
2593
|
-
|
|
2616
|
+
}
|
|
2617
|
+
class ProofRidException extends Error {
|
|
2618
|
+
constructor() {
|
|
2619
|
+
super("Unable to verify source transaction proof, got a different transaction from query than we asked for");
|
|
2594
2620
|
}
|
|
2595
|
-
|
|
2596
|
-
|
|
2621
|
+
}
|
|
2622
|
+
class SystemChainException extends Error {
|
|
2623
|
+
constructor(errorMessage) {
|
|
2624
|
+
super(`Query to system chain failed with error: ${errorMessage}`);
|
|
2597
2625
|
}
|
|
2598
|
-
|
|
2599
|
-
|
|
2626
|
+
}
|
|
2627
|
+
class ConfirmationProofException extends Error {
|
|
2628
|
+
constructor(transactionRid) {
|
|
2629
|
+
super(`Unable to fetch confirmation proof for transaction RID: ${toString(transactionRid)}.`);
|
|
2600
2630
|
}
|
|
2601
|
-
|
|
2602
|
-
|
|
2631
|
+
}
|
|
2632
|
+
class BlockAnchoringException extends Error {
|
|
2633
|
+
constructor() {
|
|
2634
|
+
super(`Block is not present in cluster anchoring chain`);
|
|
2603
2635
|
}
|
|
2604
2636
|
}
|
|
2605
2637
|
|
|
2606
|
-
/*
|
|
2607
|
-
This file is part of web3.js.
|
|
2608
|
-
|
|
2609
|
-
web3.js is free software: you can redistribute it and/or modify
|
|
2610
|
-
it under the terms of the GNU Lesser General Public License as published by
|
|
2611
|
-
the Free Software Foundation, either version 3 of the License, or
|
|
2612
|
-
(at your option) any later version.
|
|
2613
|
-
|
|
2614
|
-
web3.js is distributed in the hope that it will be useful,
|
|
2615
|
-
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
2616
|
-
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
2617
|
-
GNU Lesser General Public License for more details.
|
|
2618
|
-
|
|
2619
|
-
You should have received a copy of the GNU Lesser General Public License
|
|
2620
|
-
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
|
2621
|
-
*/
|
|
2622
2638
|
var __awaiter$8 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2623
2639
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2624
2640
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -2628,245 +2644,140 @@ var __awaiter$8 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
2628
2644
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2629
2645
|
});
|
|
2630
2646
|
};
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
}
|
|
2645
|
-
catch(onrejected) {
|
|
2646
|
-
return __awaiter$8(this, void 0, void 0, function* () {
|
|
2647
|
-
return this._promise.catch(onrejected);
|
|
2648
|
-
});
|
|
2649
|
-
}
|
|
2650
|
-
finally(onfinally) {
|
|
2651
|
-
return __awaiter$8(this, void 0, void 0, function* () {
|
|
2652
|
-
return this._promise.finally(onfinally);
|
|
2653
|
-
});
|
|
2654
|
-
}
|
|
2655
|
-
on(eventName, fn) {
|
|
2656
|
-
super.on(eventName, fn);
|
|
2657
|
-
return this;
|
|
2658
|
-
}
|
|
2659
|
-
once(eventName, fn) {
|
|
2660
|
-
super.once(eventName, fn);
|
|
2661
|
-
return this;
|
|
2662
|
-
}
|
|
2647
|
+
function getClusterOfBlockchain(client, blockchainRid) {
|
|
2648
|
+
return __awaiter$8(this, void 0, void 0, function* () {
|
|
2649
|
+
try {
|
|
2650
|
+
const clusterName = yield client.query({
|
|
2651
|
+
name: "cm_get_blockchain_cluster",
|
|
2652
|
+
args: { brid: blockchainRid },
|
|
2653
|
+
});
|
|
2654
|
+
return clusterName;
|
|
2655
|
+
}
|
|
2656
|
+
catch (error) {
|
|
2657
|
+
throw new SystemChainException(error.message);
|
|
2658
|
+
}
|
|
2659
|
+
});
|
|
2663
2660
|
}
|
|
2664
|
-
|
|
2665
|
-
|
|
2666
|
-
|
|
2667
|
-
|
|
2668
|
-
|
|
2669
|
-
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
})(exports.FailoverStrategy || (exports.FailoverStrategy = {}));
|
|
2673
|
-
exports.ResponseStatus = void 0;
|
|
2674
|
-
(function (ResponseStatus) {
|
|
2675
|
-
ResponseStatus["Confirmed"] = "confirmed";
|
|
2676
|
-
ResponseStatus["Rejected"] = "rejected";
|
|
2677
|
-
ResponseStatus["Unknown"] = "unknown";
|
|
2678
|
-
ResponseStatus["Waiting"] = "waiting";
|
|
2679
|
-
})(exports.ResponseStatus || (exports.ResponseStatus = {}));
|
|
2680
|
-
|
|
2681
|
-
const WRONG_STRING_LENGTH = "wrong string length";
|
|
2682
|
-
const BlockIdentifierSchema = zod.z.union([
|
|
2683
|
-
zod.z
|
|
2684
|
-
.string()
|
|
2685
|
-
.refine((val) => /^[0-9a-fA-F]{64}$/.test(val), WRONG_STRING_LENGTH),
|
|
2686
|
-
zod.z.number(),
|
|
2687
|
-
]);
|
|
2688
|
-
const isBlockIdentifierValid = (blockIdentifier, options) => {
|
|
2689
|
-
const ctx = BlockIdentifierSchema.safeParse(blockIdentifier);
|
|
2690
|
-
const { success } = ctx;
|
|
2691
|
-
const hasError = "error" in ctx;
|
|
2692
|
-
const { throwOnError = false } = options || {};
|
|
2693
|
-
if (!hasError) {
|
|
2694
|
-
return { success };
|
|
2695
|
-
}
|
|
2696
|
-
const { error } = ctx;
|
|
2697
|
-
const isInvalidInputType = error.issues.some(({ code }) => code === "invalid_union");
|
|
2698
|
-
const isInvalidStringLength = error.issues.some(({ message }) => message === WRONG_STRING_LENGTH);
|
|
2699
|
-
const message = (() => {
|
|
2700
|
-
if (isInvalidInputType) {
|
|
2701
|
-
return `Invalid "blockIdentifier" type. Expected string or number, but received ${typeof blockIdentifier}.`;
|
|
2661
|
+
function getClusterInfo(client, name) {
|
|
2662
|
+
return __awaiter$8(this, void 0, void 0, function* () {
|
|
2663
|
+
try {
|
|
2664
|
+
const clusterInfo = yield client.query({
|
|
2665
|
+
name: "cm_get_cluster_info",
|
|
2666
|
+
args: { name },
|
|
2667
|
+
});
|
|
2668
|
+
return clusterInfo;
|
|
2702
2669
|
}
|
|
2703
|
-
|
|
2704
|
-
|
|
2670
|
+
catch (error) {
|
|
2671
|
+
throw new SystemChainException(error.message);
|
|
2705
2672
|
}
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2673
|
+
});
|
|
2674
|
+
}
|
|
2675
|
+
function awaitGetAnchoringTransactionForBlockRid(client, blockchainRid, blockRid, statusPollInterval, statusPollCount) {
|
|
2676
|
+
return __awaiter$8(this, void 0, void 0, function* () {
|
|
2677
|
+
let anchoringTransactionResponse = null;
|
|
2678
|
+
for (let i = 0; i < statusPollCount; i++) {
|
|
2679
|
+
anchoringTransactionResponse = yield getAnchoringTransactionForBlockRid(client, blockchainRid, blockRid);
|
|
2680
|
+
if (anchoringTransactionResponse) {
|
|
2681
|
+
const anchoringTransactionValidaiton = AnchoringTransactionSchema.safeParse(anchoringTransactionResponse);
|
|
2682
|
+
if (anchoringTransactionValidaiton.success) {
|
|
2683
|
+
return anchoringTransactionValidaiton.data;
|
|
2684
|
+
}
|
|
2685
|
+
else if (!anchoringTransactionValidaiton.success) {
|
|
2686
|
+
throw new TxRejectedError("Invalid anchoring transaction format");
|
|
2687
|
+
}
|
|
2688
|
+
}
|
|
2689
|
+
yield sleep(statusPollInterval);
|
|
2690
|
+
}
|
|
2691
|
+
return anchoringTransactionResponse;
|
|
2692
|
+
});
|
|
2693
|
+
}
|
|
2694
|
+
function getAnchoringTransactionForBlockRid(client, blockchainRid, blockRid) {
|
|
2695
|
+
return __awaiter$8(this, void 0, void 0, function* () {
|
|
2696
|
+
try {
|
|
2697
|
+
const anchoringTxForBlockRid = yield client.query({
|
|
2698
|
+
name: "get_anchoring_transaction_for_block_rid",
|
|
2699
|
+
args: { blockchain_rid: blockchainRid, block_rid: blockRid },
|
|
2700
|
+
});
|
|
2701
|
+
if (!anchoringTxForBlockRid)
|
|
2702
|
+
return null;
|
|
2703
|
+
return convertToAnchoringTransaction(anchoringTxForBlockRid);
|
|
2704
|
+
}
|
|
2705
|
+
catch (error) {
|
|
2706
|
+
throw new SystemChainException(error.message);
|
|
2707
|
+
}
|
|
2708
|
+
});
|
|
2709
|
+
}
|
|
2710
|
+
function convertToAnchoringTransaction(responseTx) {
|
|
2711
|
+
const { tx_rid, tx_data, tx_op_index } = responseTx;
|
|
2711
2712
|
return {
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2713
|
+
txRid: tx_rid,
|
|
2714
|
+
txData: tx_data,
|
|
2715
|
+
txOpIndex: tx_op_index,
|
|
2715
2716
|
};
|
|
2716
|
-
}
|
|
2717
|
-
|
|
2718
|
-
const
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
blockchainIid: zod.z.number(),
|
|
2722
|
-
}),
|
|
2723
|
-
zod.z.object({
|
|
2724
|
-
blockchainRid: zod.z.string(),
|
|
2725
|
-
blockchainIid: zod.z.undefined(),
|
|
2726
|
-
}),
|
|
2727
|
-
]);
|
|
2728
|
-
const NodeUrlSchema = zod.z.union([
|
|
2729
|
-
zod.z.object({
|
|
2730
|
-
nodeUrlPool: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]),
|
|
2731
|
-
directoryNodeUrlPool: zod.z.undefined(),
|
|
2732
|
-
}),
|
|
2733
|
-
zod.z.object({
|
|
2734
|
-
nodeUrlPool: zod.z.undefined(),
|
|
2735
|
-
directoryNodeUrlPool: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]),
|
|
2736
|
-
}),
|
|
2737
|
-
]);
|
|
2738
|
-
const RestNetworkSettingsSchema = zod.z.object({
|
|
2739
|
-
statusPollingInterval: zod.z.number().optional(),
|
|
2740
|
-
statusPollingCount: zod.z.number().optional(),
|
|
2741
|
-
failOverConfig: zod.z
|
|
2742
|
-
.object({
|
|
2743
|
-
strategy: zod.z.nativeEnum(exports.FailoverStrategy).optional(),
|
|
2744
|
-
attemptsPerEndpoint: zod.z.number().optional(),
|
|
2745
|
-
attemptInterval: zod.z.number().optional(),
|
|
2746
|
-
unreachableDuration: zod.z.number().optional(),
|
|
2747
|
-
})
|
|
2748
|
-
.optional(),
|
|
2749
|
-
});
|
|
2750
|
-
const validateBlockChainIdentifier = (networkSettings, options) => {
|
|
2751
|
-
const { throwOnError = false } = options || {};
|
|
2752
|
-
const identifierValidationContext = IdentifierSchema.safeParse(networkSettings);
|
|
2753
|
-
if ("error" in identifierValidationContext) {
|
|
2754
|
-
const missingBlockchainIdentifierError = new MissingBlockchainIdentifierError();
|
|
2755
|
-
if (throwOnError) {
|
|
2756
|
-
throw missingBlockchainIdentifierError;
|
|
2757
|
-
}
|
|
2758
|
-
return {
|
|
2759
|
-
success: identifierValidationContext.success,
|
|
2760
|
-
error: identifierValidationContext.error,
|
|
2761
|
-
message: missingBlockchainIdentifierError.message,
|
|
2762
|
-
};
|
|
2717
|
+
}
|
|
2718
|
+
function calculateBlockRID(decodedTxProof) {
|
|
2719
|
+
const sourceBlockHeader = decodedTxProof.blockHeader;
|
|
2720
|
+
if (!sourceBlockHeader) {
|
|
2721
|
+
throw new Error("Failed to get blockHeader from confirmation proof");
|
|
2763
2722
|
}
|
|
2764
|
-
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
2772
|
-
|
|
2723
|
+
const decodeSourceBlockRid = decodeValue(sourceBlockHeader);
|
|
2724
|
+
return gtvHash(decodeSourceBlockRid);
|
|
2725
|
+
}
|
|
2726
|
+
// fetch tx from txRID and verifies with secp256k1.ecdsaVerify that txRID and signer creates signatures that are on the blockchain transaction
|
|
2727
|
+
function fetchAndVerifyTransaction(sourceClient, txToProveRID, proofHash, txToProveSigners) {
|
|
2728
|
+
var _a, _b, _c;
|
|
2729
|
+
return __awaiter$8(this, void 0, void 0, function* () {
|
|
2730
|
+
const rawTx = yield sourceClient.getTransaction(txToProveRID);
|
|
2731
|
+
const txGtv = decodeValue(rawTx);
|
|
2732
|
+
const fetchedTxHash = gtvHash(txGtv);
|
|
2733
|
+
if (Buffer.compare(fetchedTxHash, proofHash)) {
|
|
2734
|
+
// We received another hash for tx RID than what was included in proof
|
|
2735
|
+
// Possibly rouge or faulty node(s). Anyway, we need to give up.
|
|
2736
|
+
throw new MissingTransactionProof(proofHash, fetchedTxHash);
|
|
2773
2737
|
}
|
|
2774
|
-
|
|
2775
|
-
|
|
2776
|
-
|
|
2777
|
-
message: missingNodeUrlError.message,
|
|
2778
|
-
};
|
|
2779
|
-
}
|
|
2780
|
-
return { success: true };
|
|
2781
|
-
};
|
|
2782
|
-
const validateRestNetworkSettings = (networkSettings, options) => {
|
|
2783
|
-
const { throwOnError = false } = options || {};
|
|
2784
|
-
const restNetworkSettingsValidationContext = RestNetworkSettingsSchema.safeParse(networkSettings);
|
|
2785
|
-
if ("error" in restNetworkSettingsValidationContext) {
|
|
2786
|
-
const { error: { issues }, } = restNetworkSettingsValidationContext;
|
|
2787
|
-
const errorMessage = issues
|
|
2788
|
-
.map(({ message, path }) => `${path[0]}: ${message}`)
|
|
2789
|
-
.join(", ");
|
|
2790
|
-
if (throwOnError) {
|
|
2791
|
-
throw new Error(errorMessage);
|
|
2738
|
+
const fetchedTx = rawGtvToGtx(txGtv);
|
|
2739
|
+
if (txToProveSigners.length != ((_a = fetchedTx.signatures) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
2740
|
+
throw new DifferentNumberOfSignersException((_c = (_b = fetchedTx.signatures) === null || _b === void 0 ? void 0 : _b.length) !== null && _c !== void 0 ? _c : 0, txToProveSigners.length);
|
|
2792
2741
|
}
|
|
2793
|
-
|
|
2794
|
-
|
|
2795
|
-
|
|
2796
|
-
|
|
2797
|
-
|
|
2798
|
-
|
|
2799
|
-
|
|
2800
|
-
|
|
2801
|
-
|
|
2802
|
-
|
|
2803
|
-
|
|
2804
|
-
|
|
2805
|
-
|
|
2806
|
-
|
|
2807
|
-
|
|
2808
|
-
|
|
2809
|
-
|
|
2810
|
-
|
|
2811
|
-
|
|
2812
|
-
|
|
2813
|
-
|
|
2814
|
-
|
|
2815
|
-
|
|
2816
|
-
|
|
2817
|
-
|
|
2818
|
-
zod.z.instanceof(Uint8Array),
|
|
2819
|
-
zod.z.instanceof(Buffer),
|
|
2820
|
-
]);
|
|
2821
|
-
|
|
2822
|
-
const KeyPairSchema = zod.z.object({
|
|
2823
|
-
privKey: BufferSchema,
|
|
2824
|
-
pubKey: BufferSchema,
|
|
2825
|
-
});
|
|
2826
|
-
const SignatureProviderSchema = zod.z.object({
|
|
2827
|
-
pubKey: BufferSchema,
|
|
2828
|
-
sign: zod.z.function().args(BufferSchema).returns(zod.z.promise(BufferSchema)),
|
|
2829
|
-
});
|
|
2830
|
-
const SignMethodSchema = zod.z.union([
|
|
2831
|
-
KeyPairSchema,
|
|
2832
|
-
SignatureProviderSchema,
|
|
2833
|
-
]);
|
|
2834
|
-
const isSignMethodValid = (signMethod, options) => {
|
|
2835
|
-
const signMethodValidationCtx = SignMethodSchema.safeParse(signMethod);
|
|
2836
|
-
const { throwOnError = false } = options || {};
|
|
2837
|
-
const hasError = "error" in signMethodValidationCtx;
|
|
2838
|
-
if (!hasError) {
|
|
2839
|
-
return { success: true };
|
|
2840
|
-
}
|
|
2841
|
-
const message = "Invalid sign method";
|
|
2842
|
-
if (throwOnError) {
|
|
2843
|
-
throw new Error(message);
|
|
2844
|
-
}
|
|
2845
|
-
return {
|
|
2846
|
-
success: false,
|
|
2847
|
-
error: signMethodValidationCtx.error,
|
|
2848
|
-
message,
|
|
2742
|
+
const txRID = getDigestToSign(fetchedTx);
|
|
2743
|
+
if (Buffer.compare(txRID, txToProveRID)) {
|
|
2744
|
+
throw new ProofRidException();
|
|
2745
|
+
}
|
|
2746
|
+
for (const signer of txToProveSigners) {
|
|
2747
|
+
let hasSignature = false;
|
|
2748
|
+
for (const signature of fetchedTx.signatures) {
|
|
2749
|
+
// verify that txRID (hash of gtxBody) signed by signers equals the signatures from network
|
|
2750
|
+
if (checkDigestSignature(txRID, signer, signature)) {
|
|
2751
|
+
hasSignature = true;
|
|
2752
|
+
break;
|
|
2753
|
+
}
|
|
2754
|
+
}
|
|
2755
|
+
if (!hasSignature)
|
|
2756
|
+
throw new SignatureException(signer);
|
|
2757
|
+
}
|
|
2758
|
+
return { verifiedTx: fetchedTx, verifiedTxHash: fetchedTxHash };
|
|
2759
|
+
});
|
|
2760
|
+
}
|
|
2761
|
+
function composeProofTransactionObject(sourceBlockchainRid, verifiedTxHash, txProof, iccfTxSigners, anchoringTx, anchoringProof, isNetwork = true) {
|
|
2762
|
+
let operationArgs;
|
|
2763
|
+
operationArgs = {
|
|
2764
|
+
sourceBlockchainRid: toBuffer(sourceBlockchainRid),
|
|
2765
|
+
transactionHash: verifiedTxHash,
|
|
2766
|
+
transactionProof: encodeValue(txProof),
|
|
2849
2767
|
};
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
const TxRidSchema = BufferSchema.refine((x) => x.length === 32, "Rid must be 32 bytes long");
|
|
2853
|
-
const isTxRidValid = (rid, options) => {
|
|
2854
|
-
const TxRidValidationContext = TxRidSchema.safeParse(rid);
|
|
2855
|
-
const { throwOnError = false } = options || {};
|
|
2856
|
-
const hasError = "error" in TxRidValidationContext;
|
|
2857
|
-
if (!hasError) {
|
|
2858
|
-
return { success: true };
|
|
2859
|
-
}
|
|
2860
|
-
const validationError = new InvalidTxRidException(rid);
|
|
2861
|
-
if (throwOnError) {
|
|
2862
|
-
throw validationError;
|
|
2768
|
+
if (isNetwork) {
|
|
2769
|
+
operationArgs = Object.assign(Object.assign({}, operationArgs), { transactionData: anchoringTx === null || anchoringTx === void 0 ? void 0 : anchoringTx.txData, transactionIndex: anchoringTx === null || anchoringTx === void 0 ? void 0 : anchoringTx.txOpIndex, anchoringProof: anchoringProof && encodeValue(anchoringProof) });
|
|
2863
2770
|
}
|
|
2864
2771
|
return {
|
|
2865
|
-
|
|
2866
|
-
|
|
2867
|
-
|
|
2772
|
+
operations: [
|
|
2773
|
+
{
|
|
2774
|
+
name: "iccf_proof",
|
|
2775
|
+
args: Object.values(operationArgs),
|
|
2776
|
+
},
|
|
2777
|
+
],
|
|
2778
|
+
signers: iccfTxSigners,
|
|
2868
2779
|
};
|
|
2869
|
-
}
|
|
2780
|
+
}
|
|
2870
2781
|
|
|
2871
2782
|
var __awaiter$7 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2872
2783
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -2877,142 +2788,545 @@ var __awaiter$7 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
2877
2788
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2878
2789
|
});
|
|
2879
2790
|
};
|
|
2880
|
-
|
|
2791
|
+
/**
|
|
2792
|
+
* Creates an ICCF (Inter-Chain Communication Framework) proof transaction.
|
|
2793
|
+
* This function generates a proof that a specific transaction has occurred on the source blockchain
|
|
2794
|
+
* and constructs an ICCF proof transaction that can be posted to the target blockchain.
|
|
2795
|
+
*
|
|
2796
|
+
* @param {IClient} client - The client configured to communicate with the management chain.
|
|
2797
|
+
* @param {Buffer} txToProveRid - The RID of the transaction to be proven.
|
|
2798
|
+
* @param {Buffer} txToProveHash - The hash of the transaction to be proven.
|
|
2799
|
+
* @param {PubKey[]} txToProveSigners - An array of public keys representing signers of the transaction to be proven.
|
|
2800
|
+
* @param {string} sourceBlockchainRid - The RID of the source blockchain.
|
|
2801
|
+
* @param {string} targetBlockchainRid - The RID of the target blockchain.
|
|
2802
|
+
* @param {PubKey[]} iccfTxSigners - An array of public keys representing signers of the ICCF proof transaction (optional, default: []).
|
|
2803
|
+
* @param {boolean} forceIntraNetworkIccfOperation - Whether to force the ICCF operation to be performed within the same network (optional, default: false).
|
|
2804
|
+
* @returns {Promise<IccfProof>} A promise that resolves to an ICCF proof object containing the ICCF proof transaction.
|
|
2805
|
+
*/
|
|
2806
|
+
function createIccfProofTx(client, txToProveRid, txToProveHash, txToProveSigners, sourceBlockchainRid, targetBlockchainRid, iccfTxSigners = [], forceIntraNetworkIccfOperation = false) {
|
|
2881
2807
|
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2882
|
-
|
|
2883
|
-
|
|
2884
|
-
|
|
2885
|
-
|
|
2886
|
-
|
|
2887
|
-
|
|
2888
|
-
|
|
2889
|
-
|
|
2890
|
-
|
|
2891
|
-
|
|
2892
|
-
|
|
2893
|
-
|
|
2894
|
-
|
|
2895
|
-
|
|
2896
|
-
|
|
2897
|
-
|
|
2898
|
-
|
|
2899
|
-
|
|
2900
|
-
|
|
2901
|
-
|
|
2902
|
-
|
|
2903
|
-
|
|
2904
|
-
|
|
2905
|
-
|
|
2906
|
-
|
|
2907
|
-
|
|
2908
|
-
|
|
2909
|
-
|
|
2910
|
-
|
|
2911
|
-
|
|
2912
|
-
|
|
2913
|
-
|
|
2914
|
-
|
|
2915
|
-
|
|
2916
|
-
|
|
2917
|
-
|
|
2918
|
-
|
|
2919
|
-
|
|
2920
|
-
|
|
2921
|
-
|
|
2922
|
-
|
|
2923
|
-
|
|
2924
|
-
|
|
2925
|
-
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
2929
|
-
|
|
2930
|
-
|
|
2931
|
-
|
|
2932
|
-
|
|
2933
|
-
|
|
2934
|
-
|
|
2935
|
-
|
|
2936
|
-
|
|
2937
|
-
|
|
2938
|
-
|
|
2939
|
-
|
|
2940
|
-
|
|
2941
|
-
|
|
2942
|
-
|
|
2943
|
-
|
|
2944
|
-
|
|
2945
|
-
|
|
2946
|
-
|
|
2947
|
-
|
|
2808
|
+
const clientConfiguredToSource = yield createClient({
|
|
2809
|
+
directoryNodeUrlPool: getUrlsFromEndpoints(client.config.endpointPool),
|
|
2810
|
+
blockchainRid: sourceBlockchainRid,
|
|
2811
|
+
});
|
|
2812
|
+
const txProof = yield clientConfiguredToSource.getConfirmationProof(txToProveRid);
|
|
2813
|
+
if (!txProof || !txProof.hash) {
|
|
2814
|
+
throw new ConfirmationProofException(txToProveRid);
|
|
2815
|
+
}
|
|
2816
|
+
const proofHash = txProof.hash;
|
|
2817
|
+
const { verifiedTx, verifiedTxHash } = !txToProveHash.equals(proofHash)
|
|
2818
|
+
? yield fetchAndVerifyTransaction(clientConfiguredToSource, txToProveRid, proofHash, txToProveSigners)
|
|
2819
|
+
: { verifiedTx: null, verifiedTxHash: txToProveHash };
|
|
2820
|
+
const sourceCluster = yield getClusterOfBlockchain(client, toBuffer(sourceBlockchainRid));
|
|
2821
|
+
const targetCluster = yield getClusterOfBlockchain(client, toBuffer(targetBlockchainRid));
|
|
2822
|
+
if (!forceIntraNetworkIccfOperation && sourceCluster === targetCluster) {
|
|
2823
|
+
// intra-cluster
|
|
2824
|
+
const intraClusterProofTx = composeProofTransactionObject(sourceBlockchainRid, verifiedTxHash, txProof, iccfTxSigners, undefined, undefined, false);
|
|
2825
|
+
return { iccfTx: intraClusterProofTx };
|
|
2826
|
+
}
|
|
2827
|
+
else {
|
|
2828
|
+
// intra-network
|
|
2829
|
+
const anchoringClient = yield getAnchoringClient(client, sourceBlockchainRid, sourceCluster);
|
|
2830
|
+
const clusterAnchoredTx = yield getBlockAnchoringTransaction(clientConfiguredToSource, anchoringClient, undefined, txProof);
|
|
2831
|
+
if (!clusterAnchoredTx) {
|
|
2832
|
+
throw new BlockAnchoringException();
|
|
2833
|
+
}
|
|
2834
|
+
const anchoringProof = yield anchoringClient.getConfirmationProof(clusterAnchoredTx.txRid);
|
|
2835
|
+
const intraNetworkProofTx = composeProofTransactionObject(sourceBlockchainRid, verifiedTxHash, txProof, iccfTxSigners, clusterAnchoredTx, anchoringProof);
|
|
2836
|
+
return { iccfTx: intraNetworkProofTx, verifiedTx };
|
|
2837
|
+
}
|
|
2838
|
+
});
|
|
2839
|
+
}
|
|
2840
|
+
/**
|
|
2841
|
+
* Checks whether a given transaction is included in the cluster anchoring chain and returns the
|
|
2842
|
+
* block anchoring transaction. If `txProof` is not provided, it fetches the confirmation proof
|
|
2843
|
+
* using the `sourceClient`.
|
|
2844
|
+
*
|
|
2845
|
+
* @param sourceClient - A client configured to the blockchain where the transaction was made.
|
|
2846
|
+
* @param anchoringClient - The client responsible for querying the anchoring blockchain.
|
|
2847
|
+
* @param txRid - The transaction RID to check for anchoring.
|
|
2848
|
+
* @param txProof - (Optional) The transaction proof for the specified `txRid`.
|
|
2849
|
+
* @returns A Promise that resolves to the anchored transaction response object.
|
|
2850
|
+
*/
|
|
2851
|
+
function getBlockAnchoringTransaction(sourceClient, anchoringClient, txRid, txProof) {
|
|
2852
|
+
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2853
|
+
if (!txRid && !txProof) {
|
|
2854
|
+
throw Error("Missing a txRid or TxProof");
|
|
2855
|
+
}
|
|
2856
|
+
const confirmationProof = txProof !== null && txProof !== void 0 ? txProof : (txRid && (yield sourceClient.getConfirmationProof(txRid)));
|
|
2857
|
+
if (!confirmationProof) {
|
|
2858
|
+
throw Error("Confirmation proof not found");
|
|
2859
|
+
}
|
|
2860
|
+
const blockRid = calculateBlockRID(confirmationProof);
|
|
2861
|
+
const blockchainRid = sourceClient.config.blockchainRid;
|
|
2862
|
+
const anchoringTxResponse = yield awaitGetAnchoringTransactionForBlockRid(anchoringClient, toBuffer(blockchainRid), blockRid, sourceClient.config.statusPollInterval, sourceClient.config.statusPollCount);
|
|
2863
|
+
return anchoringTxResponse;
|
|
2864
|
+
});
|
|
2865
|
+
}
|
|
2866
|
+
/**
|
|
2867
|
+
* Checks whether a given transaction is included in the anchoring blockchain.
|
|
2868
|
+
*
|
|
2869
|
+
* @param sourceClient - A client configured to the blockchain where the transaction was made.
|
|
2870
|
+
* @param anchoringClient - The client responsible for querying the anchoring blockchain.
|
|
2871
|
+
* @param txRid - The transaction RID to check for anchoring.
|
|
2872
|
+
* @param txProof - (Optional) The transaction proof for the specified `txRid`.
|
|
2873
|
+
* @returns A Promise that resolves to `true` if the transaction is anchored, `false` otherwise.
|
|
2874
|
+
*/
|
|
2875
|
+
function isBlockAnchored(sourceClient, anchoringClient, txRid, txProof) {
|
|
2876
|
+
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2877
|
+
return !!(yield getBlockAnchoringTransaction(sourceClient, anchoringClient, txRid, txProof));
|
|
2878
|
+
});
|
|
2879
|
+
}
|
|
2880
|
+
/**
|
|
2881
|
+
* Gets a client configured for the cluster anchoring blockchain of a cluster. Takes a specific
|
|
2882
|
+
* cluster name or blockchain RID to determine the cluster.
|
|
2883
|
+
* @param client - The client configured to communicate with the management chain.
|
|
2884
|
+
* @param dappBlockchainRid - (Optional) The RID of a blockchain which anchoring wants to be checked.
|
|
2885
|
+
* @param cluster - (Optional) The cluster of interest.
|
|
2886
|
+
* @returns A Promise that resolves to the client configured to a cluster anchoring chain.
|
|
2887
|
+
*/
|
|
2888
|
+
function getAnchoringClient(client, dappBlockchainRid, cluster) {
|
|
2889
|
+
return __awaiter$7(this, void 0, void 0, function* () {
|
|
2890
|
+
if (!dappBlockchainRid && !cluster) {
|
|
2891
|
+
throw Error("Missing a dapp blockchainRid or cluster name");
|
|
2892
|
+
}
|
|
2893
|
+
const sourceCluster = cluster !== null && cluster !== void 0 ? cluster : (dappBlockchainRid && (yield getClusterOfBlockchain(client, toBuffer(dappBlockchainRid))));
|
|
2894
|
+
if (!sourceCluster) {
|
|
2895
|
+
throw Error("No cluster could be found");
|
|
2896
|
+
}
|
|
2897
|
+
const sourceClusterInfo = yield getClusterInfo(client, sourceCluster);
|
|
2898
|
+
if (!sourceClusterInfo || !sourceClusterInfo.anchoring_chain) {
|
|
2899
|
+
throw Error("Cluster info could not be found");
|
|
2900
|
+
}
|
|
2901
|
+
const networkSettings = Object.assign(Object.assign({}, client.config), { directoryNodeUrlPool: getUrlsFromEndpoints(client.config.endpointPool), blockchainRid: toString(sourceClusterInfo.anchoring_chain) });
|
|
2902
|
+
const clientConfiguredToAnchoringchain = yield createClient(networkSettings);
|
|
2903
|
+
return clientConfiguredToAnchoringchain;
|
|
2904
|
+
});
|
|
2905
|
+
}
|
|
2906
|
+
|
|
2907
|
+
/*
|
|
2908
|
+
This file is part of web3.js.
|
|
2909
|
+
|
|
2910
|
+
web3.js is free software: you can redistribute it and/or modify
|
|
2911
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
2912
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
2913
|
+
(at your option) any later version.
|
|
2914
|
+
|
|
2915
|
+
web3.js is distributed in the hope that it will be useful,
|
|
2916
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
2917
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
2918
|
+
GNU Lesser General Public License for more details.
|
|
2919
|
+
|
|
2920
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
2921
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
|
2922
|
+
*/
|
|
2923
|
+
class Web3EventEmitter {
|
|
2924
|
+
constructor() {
|
|
2925
|
+
this._emitter = new events.EventEmitter();
|
|
2926
|
+
}
|
|
2927
|
+
on(eventName, fn) {
|
|
2928
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
2929
|
+
this._emitter.on(eventName, fn);
|
|
2930
|
+
}
|
|
2931
|
+
once(eventName, fn) {
|
|
2932
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
2933
|
+
this._emitter.once(eventName, fn);
|
|
2934
|
+
}
|
|
2935
|
+
off(eventName, fn) {
|
|
2936
|
+
// eslint-disable-next-line @typescript-eslint/no-misused-promises
|
|
2937
|
+
this._emitter.off(eventName, fn);
|
|
2938
|
+
}
|
|
2939
|
+
emit(eventName, params) {
|
|
2940
|
+
this._emitter.emit(eventName, params);
|
|
2941
|
+
}
|
|
2942
|
+
listenerCount(eventName) {
|
|
2943
|
+
return this._emitter.listenerCount(eventName);
|
|
2944
|
+
}
|
|
2945
|
+
listeners(eventName) {
|
|
2946
|
+
return this._emitter.listeners(eventName);
|
|
2947
|
+
}
|
|
2948
|
+
eventNames() {
|
|
2949
|
+
return this._emitter.eventNames();
|
|
2950
|
+
}
|
|
2951
|
+
removeAllListeners() {
|
|
2952
|
+
this._emitter.removeAllListeners();
|
|
2953
|
+
}
|
|
2954
|
+
setMaxListenerWarningThreshold(maxListenersWarningThreshold) {
|
|
2955
|
+
this._emitter.setMaxListeners(maxListenersWarningThreshold);
|
|
2956
|
+
}
|
|
2957
|
+
getMaxListeners() {
|
|
2958
|
+
return this._emitter.getMaxListeners();
|
|
2959
|
+
}
|
|
2960
|
+
}
|
|
2961
|
+
|
|
2962
|
+
/*
|
|
2963
|
+
This file is part of web3.js.
|
|
2964
|
+
|
|
2965
|
+
web3.js is free software: you can redistribute it and/or modify
|
|
2966
|
+
it under the terms of the GNU Lesser General Public License as published by
|
|
2967
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
2968
|
+
(at your option) any later version.
|
|
2969
|
+
|
|
2970
|
+
web3.js is distributed in the hope that it will be useful,
|
|
2971
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
2972
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
2973
|
+
GNU Lesser General Public License for more details.
|
|
2974
|
+
|
|
2975
|
+
You should have received a copy of the GNU Lesser General Public License
|
|
2976
|
+
along with web3.js. If not, see <http://www.gnu.org/licenses/>.
|
|
2977
|
+
*/
|
|
2978
|
+
var __awaiter$6 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2979
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
2980
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
2981
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
2982
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
2983
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
2984
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
2985
|
+
});
|
|
2986
|
+
};
|
|
2987
|
+
var _a;
|
|
2988
|
+
class Web3PromiEvent extends Web3EventEmitter {
|
|
2989
|
+
constructor(executor) {
|
|
2990
|
+
super();
|
|
2991
|
+
// public tag to treat object as promise by different libs
|
|
2992
|
+
// eslint-disable-next-line @typescript-eslint/prefer-as-const
|
|
2993
|
+
this[_a] = "Promise";
|
|
2994
|
+
this._promise = new Promise(executor);
|
|
2995
|
+
}
|
|
2996
|
+
then(onfulfilled, onrejected) {
|
|
2997
|
+
return __awaiter$6(this, void 0, void 0, function* () {
|
|
2998
|
+
return this._promise.then(onfulfilled, onrejected);
|
|
2999
|
+
});
|
|
3000
|
+
}
|
|
3001
|
+
catch(onrejected) {
|
|
3002
|
+
return __awaiter$6(this, void 0, void 0, function* () {
|
|
3003
|
+
return this._promise.catch(onrejected);
|
|
3004
|
+
});
|
|
3005
|
+
}
|
|
3006
|
+
finally(onfinally) {
|
|
3007
|
+
return __awaiter$6(this, void 0, void 0, function* () {
|
|
3008
|
+
return this._promise.finally(onfinally);
|
|
3009
|
+
});
|
|
3010
|
+
}
|
|
3011
|
+
on(eventName, fn) {
|
|
3012
|
+
super.on(eventName, fn);
|
|
3013
|
+
return this;
|
|
3014
|
+
}
|
|
3015
|
+
once(eventName, fn) {
|
|
3016
|
+
super.once(eventName, fn);
|
|
3017
|
+
return this;
|
|
3018
|
+
}
|
|
3019
|
+
}
|
|
3020
|
+
_a = Symbol.toStringTag;
|
|
3021
|
+
|
|
3022
|
+
exports.FailoverStrategy = void 0;
|
|
3023
|
+
(function (FailoverStrategy) {
|
|
3024
|
+
FailoverStrategy["AbortOnError"] = "abortOnError";
|
|
3025
|
+
FailoverStrategy["TryNextOnError"] = "tryNextOnError";
|
|
3026
|
+
FailoverStrategy["SingleEndpoint"] = "singleEndpoint";
|
|
3027
|
+
FailoverStrategy["QueryMajority"] = "queryMajority";
|
|
3028
|
+
})(exports.FailoverStrategy || (exports.FailoverStrategy = {}));
|
|
3029
|
+
exports.ResponseStatus = void 0;
|
|
3030
|
+
(function (ResponseStatus) {
|
|
3031
|
+
ResponseStatus["Confirmed"] = "confirmed";
|
|
3032
|
+
ResponseStatus["Rejected"] = "rejected";
|
|
3033
|
+
ResponseStatus["Unknown"] = "unknown";
|
|
3034
|
+
ResponseStatus["Waiting"] = "waiting";
|
|
3035
|
+
})(exports.ResponseStatus || (exports.ResponseStatus = {}));
|
|
3036
|
+
exports.AnchoringStatus = void 0;
|
|
3037
|
+
(function (AnchoringStatus) {
|
|
3038
|
+
AnchoringStatus["NotAnchored"] = "notAnchored";
|
|
3039
|
+
AnchoringStatus["ClusterAnchored"] = "clusterAnchored";
|
|
3040
|
+
AnchoringStatus["SystemAnchored"] = "systemAnchored";
|
|
3041
|
+
AnchoringStatus["FailedAnchoring"] = "failedAnchoring";
|
|
3042
|
+
})(exports.AnchoringStatus || (exports.AnchoringStatus = {}));
|
|
3043
|
+
exports.ChainConfirmationLevel = void 0;
|
|
3044
|
+
(function (ChainConfirmationLevel) {
|
|
3045
|
+
ChainConfirmationLevel["None"] = "none";
|
|
3046
|
+
ChainConfirmationLevel["Dapp"] = "dapp";
|
|
3047
|
+
ChainConfirmationLevel["ClusterAnchoring"] = "clusterAnchoring";
|
|
3048
|
+
ChainConfirmationLevel["SystemAnchoring"] = "systemAnchoring";
|
|
3049
|
+
ChainConfirmationLevel["EvmNetwork"] = "evmNetwork";
|
|
3050
|
+
})(exports.ChainConfirmationLevel || (exports.ChainConfirmationLevel = {}));
|
|
3051
|
+
|
|
3052
|
+
const WRONG_STRING_LENGTH = "wrong string length";
|
|
3053
|
+
const BlockIdentifierSchema = zod.z.union([
|
|
3054
|
+
zod.z.string().refine(val => /^[0-9a-fA-F]{64}$/.test(val), WRONG_STRING_LENGTH),
|
|
3055
|
+
zod.z.number(),
|
|
3056
|
+
]);
|
|
3057
|
+
const isBlockIdentifierValid = (blockIdentifier, options) => {
|
|
3058
|
+
const ctx = BlockIdentifierSchema.safeParse(blockIdentifier);
|
|
3059
|
+
const { success } = ctx;
|
|
3060
|
+
const hasError = "error" in ctx;
|
|
3061
|
+
const { throwOnError = false } = options || {};
|
|
3062
|
+
if (!hasError) {
|
|
3063
|
+
return { success };
|
|
3064
|
+
}
|
|
3065
|
+
const { error } = ctx;
|
|
3066
|
+
const isInvalidInputType = error.issues.some(({ code }) => code === "invalid_union");
|
|
3067
|
+
const isInvalidStringLength = error.issues.some(({ message }) => message === WRONG_STRING_LENGTH);
|
|
3068
|
+
const message = (() => {
|
|
3069
|
+
if (isInvalidInputType) {
|
|
3070
|
+
return `Invalid "blockIdentifier" type. Expected string or number, but received ${typeof blockIdentifier}.`;
|
|
3071
|
+
}
|
|
3072
|
+
if (isInvalidStringLength) {
|
|
3073
|
+
return "Parameter 'blockIdentifier' does not have the correct format (64-character hexadecimal string).";
|
|
3074
|
+
}
|
|
3075
|
+
return error.issues.map(issue => issue.message).join(", ");
|
|
3076
|
+
})();
|
|
3077
|
+
if (throwOnError) {
|
|
3078
|
+
throw new Error(message);
|
|
3079
|
+
}
|
|
3080
|
+
return {
|
|
3081
|
+
success,
|
|
3082
|
+
error,
|
|
3083
|
+
message: error.issues.map(issue => issue.message).join(", "),
|
|
3084
|
+
};
|
|
3085
|
+
};
|
|
3086
|
+
|
|
3087
|
+
const IdentifierSchema = zod.z.union([
|
|
3088
|
+
zod.z.object({
|
|
3089
|
+
blockchainRid: zod.z.undefined(),
|
|
3090
|
+
blockchainIid: zod.z.number(),
|
|
3091
|
+
}),
|
|
3092
|
+
zod.z.object({
|
|
3093
|
+
blockchainRid: zod.z.string(),
|
|
3094
|
+
blockchainIid: zod.z.undefined(),
|
|
3095
|
+
}),
|
|
3096
|
+
]);
|
|
3097
|
+
const NodeUrlSchema = zod.z.union([
|
|
3098
|
+
zod.z.object({
|
|
3099
|
+
nodeUrlPool: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]),
|
|
3100
|
+
directoryNodeUrlPool: zod.z.undefined(),
|
|
3101
|
+
}),
|
|
3102
|
+
zod.z.object({
|
|
3103
|
+
nodeUrlPool: zod.z.undefined(),
|
|
3104
|
+
directoryNodeUrlPool: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]),
|
|
3105
|
+
}),
|
|
3106
|
+
]);
|
|
3107
|
+
const RestNetworkSettingsSchema = zod.z.object({
|
|
3108
|
+
statusPollingInterval: zod.z.number().optional(),
|
|
3109
|
+
statusPollingCount: zod.z.number().optional(),
|
|
3110
|
+
failOverConfig: zod.z
|
|
3111
|
+
.object({
|
|
3112
|
+
strategy: zod.z.nativeEnum(exports.FailoverStrategy).optional(),
|
|
3113
|
+
attemptsPerEndpoint: zod.z.number().optional(),
|
|
3114
|
+
attemptInterval: zod.z.number().optional(),
|
|
3115
|
+
unreachableDuration: zod.z.number().optional(),
|
|
3116
|
+
})
|
|
3117
|
+
.optional(),
|
|
3118
|
+
});
|
|
3119
|
+
const validateBlockChainIdentifier = (networkSettings, options) => {
|
|
3120
|
+
const { throwOnError = false } = options || {};
|
|
3121
|
+
const identifierValidationContext = IdentifierSchema.safeParse(networkSettings);
|
|
3122
|
+
if ("error" in identifierValidationContext) {
|
|
3123
|
+
const missingBlockchainIdentifierError = new MissingBlockchainIdentifierError();
|
|
3124
|
+
if (throwOnError) {
|
|
3125
|
+
throw missingBlockchainIdentifierError;
|
|
3126
|
+
}
|
|
3127
|
+
return {
|
|
3128
|
+
success: identifierValidationContext.success,
|
|
3129
|
+
error: identifierValidationContext.error,
|
|
3130
|
+
message: missingBlockchainIdentifierError.message,
|
|
3131
|
+
};
|
|
3132
|
+
}
|
|
3133
|
+
return { success: true };
|
|
3134
|
+
};
|
|
3135
|
+
const validateNodeUrl = (networkSettings, options) => {
|
|
3136
|
+
const { throwOnError = false } = options || {};
|
|
3137
|
+
const nodeUrlValidationContext = NodeUrlSchema.safeParse(networkSettings);
|
|
3138
|
+
if ("error" in nodeUrlValidationContext) {
|
|
3139
|
+
const missingNodeUrlError = new MissingNodeUrlError();
|
|
3140
|
+
if (throwOnError) {
|
|
3141
|
+
throw missingNodeUrlError;
|
|
3142
|
+
}
|
|
3143
|
+
return {
|
|
3144
|
+
success: nodeUrlValidationContext.success,
|
|
3145
|
+
error: nodeUrlValidationContext.error,
|
|
3146
|
+
message: missingNodeUrlError.message,
|
|
3147
|
+
};
|
|
3148
|
+
}
|
|
3149
|
+
return { success: true };
|
|
3150
|
+
};
|
|
3151
|
+
const validateRestNetworkSettings = (networkSettings, options) => {
|
|
3152
|
+
const { throwOnError = false } = options || {};
|
|
3153
|
+
const restNetworkSettingsValidationContext = RestNetworkSettingsSchema.safeParse(networkSettings);
|
|
3154
|
+
if ("error" in restNetworkSettingsValidationContext) {
|
|
3155
|
+
const { error: { issues }, } = restNetworkSettingsValidationContext;
|
|
3156
|
+
const errorMessage = issues.map(({ message, path }) => `${path[0]}: ${message}`).join(", ");
|
|
3157
|
+
if (throwOnError) {
|
|
3158
|
+
throw new Error(errorMessage);
|
|
3159
|
+
}
|
|
3160
|
+
return {
|
|
3161
|
+
success: restNetworkSettingsValidationContext.success,
|
|
3162
|
+
error: restNetworkSettingsValidationContext.error,
|
|
3163
|
+
message: errorMessage,
|
|
3164
|
+
};
|
|
3165
|
+
}
|
|
3166
|
+
return { success: true };
|
|
3167
|
+
};
|
|
3168
|
+
const isNetworkSettingValid = (networkSettings, options) => {
|
|
3169
|
+
const identifierValidationContext = validateBlockChainIdentifier(networkSettings, options);
|
|
3170
|
+
if ("error" in identifierValidationContext) {
|
|
3171
|
+
return identifierValidationContext;
|
|
3172
|
+
}
|
|
3173
|
+
const nodeUrlValidationContext = validateNodeUrl(networkSettings, options);
|
|
3174
|
+
if ("error" in nodeUrlValidationContext) {
|
|
3175
|
+
return nodeUrlValidationContext;
|
|
3176
|
+
}
|
|
3177
|
+
const restNetworkSettingsValidationContext = validateRestNetworkSettings(networkSettings, options);
|
|
3178
|
+
if ("error" in restNetworkSettingsValidationContext) {
|
|
3179
|
+
return restNetworkSettingsValidationContext;
|
|
3180
|
+
}
|
|
3181
|
+
return { success: true };
|
|
3182
|
+
};
|
|
3183
|
+
|
|
3184
|
+
const KeyPairSchema = zod.z.object({
|
|
3185
|
+
privKey: BufferSchema,
|
|
3186
|
+
pubKey: BufferSchema,
|
|
3187
|
+
});
|
|
3188
|
+
const SignatureProviderSchema = zod.z.object({
|
|
3189
|
+
pubKey: BufferSchema,
|
|
3190
|
+
sign: zod.z.function().args(BufferSchema).returns(zod.z.promise(BufferSchema)),
|
|
3191
|
+
});
|
|
3192
|
+
const SignMethodSchema = zod.z.union([KeyPairSchema, SignatureProviderSchema]);
|
|
3193
|
+
const isSignMethodValid = (signMethod, options) => {
|
|
3194
|
+
const signMethodValidationCtx = SignMethodSchema.safeParse(signMethod);
|
|
3195
|
+
const { throwOnError = false } = options || {};
|
|
3196
|
+
const hasError = "error" in signMethodValidationCtx;
|
|
3197
|
+
if (!hasError) {
|
|
3198
|
+
return { success: true };
|
|
3199
|
+
}
|
|
3200
|
+
const message = "Invalid sign method";
|
|
3201
|
+
if (throwOnError) {
|
|
3202
|
+
throw new Error(message);
|
|
3203
|
+
}
|
|
3204
|
+
return {
|
|
3205
|
+
success: false,
|
|
3206
|
+
error: signMethodValidationCtx.error,
|
|
3207
|
+
message,
|
|
3208
|
+
};
|
|
3209
|
+
};
|
|
3210
|
+
|
|
3211
|
+
var __awaiter$5 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3212
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3213
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
3214
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
3215
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
3216
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
3217
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
3218
|
+
});
|
|
3219
|
+
};
|
|
3220
|
+
function createClient(settings) {
|
|
3221
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3222
|
+
isNetworkSettingValid(settings, { throwOnError: true });
|
|
3223
|
+
const config = yield getClientConfigFromSettings(settings);
|
|
3224
|
+
return {
|
|
3225
|
+
config,
|
|
3226
|
+
query(nameOrQueryObject, args, callback) {
|
|
3227
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3228
|
+
let _name, _args;
|
|
3229
|
+
if (typeof nameOrQueryObject === "string") {
|
|
3230
|
+
_name = nameOrQueryObject;
|
|
3231
|
+
_args = args;
|
|
3232
|
+
}
|
|
3233
|
+
else {
|
|
3234
|
+
_name = nameOrQueryObject === null || nameOrQueryObject === void 0 ? void 0 : nameOrQueryObject.name;
|
|
3235
|
+
_args = nameOrQueryObject === null || nameOrQueryObject === void 0 ? void 0 : nameOrQueryObject.args;
|
|
3236
|
+
}
|
|
3237
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.POST, `query_gtv/${config.blockchainRid}`, config, encodeValue(toQueryObjectGTV(_name, _args)));
|
|
3238
|
+
return new Promise((resolve, reject) => {
|
|
3239
|
+
handlePostResponse(error, statusCode, rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
3240
|
+
});
|
|
3241
|
+
});
|
|
3242
|
+
},
|
|
3243
|
+
signTransaction(transaction, signMethod, callback) {
|
|
3244
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3245
|
+
debug(`Signing transaction with ${!isKeyPair(signMethod) ? "signature provider containing " : ""}pubKey: ${toString(signMethod.pubKey)}`);
|
|
3246
|
+
const gtx$1 = getGTXFromBufferOrTransactionOrOperation(transaction, config.blockchainRid);
|
|
3247
|
+
try {
|
|
3248
|
+
const signedTx = yield (isKeyPair(signMethod)
|
|
3249
|
+
? sign(gtx$1, signMethod.privKey, signMethod.pubKey)
|
|
3250
|
+
: sign(gtx$1, signMethod));
|
|
3251
|
+
const gtxBytes = getSerializedGTX(signedTx);
|
|
3252
|
+
if (typeof callback === "function") {
|
|
3253
|
+
callback(null, gtxBytes);
|
|
3254
|
+
}
|
|
3255
|
+
return gtxBytes;
|
|
3256
|
+
}
|
|
3257
|
+
catch (error) {
|
|
3258
|
+
if (typeof callback === "function") {
|
|
3259
|
+
callback(error, null);
|
|
3260
|
+
}
|
|
3261
|
+
throw new Error(error);
|
|
3262
|
+
}
|
|
3263
|
+
});
|
|
3264
|
+
},
|
|
3265
|
+
sendTransaction(transaction, doStatusPolling = true, callback, confirmationLevel = exports.ChainConfirmationLevel.Dapp) {
|
|
3266
|
+
const promiEvent = new Web3PromiEvent((resolve, reject) => __awaiter$5(this, void 0, void 0, function* () {
|
|
3267
|
+
var _a;
|
|
3268
|
+
try {
|
|
3269
|
+
const gtx$1 = getGTXFromBufferOrTransactionOrOperation(transaction, config.blockchainRid);
|
|
3270
|
+
if (gtx$1.signers.length !== ((_a = gtx$1.signatures) === null || _a === void 0 ? void 0 : _a.length)) {
|
|
3271
|
+
reject(new NumberOfSignersAndSignaturesException());
|
|
3272
|
+
}
|
|
3273
|
+
const gtxBytes = getSerializedGTX(gtx$1);
|
|
3274
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.POST, `tx/${config.blockchainRid}`, config, gtxBytes);
|
|
3275
|
+
const transactionRid = getDigestToSign(gtx$1);
|
|
3276
|
+
try {
|
|
3277
|
+
yield handlePostResponsePromisified(error, statusCode, rspBody);
|
|
3278
|
+
if (typeof callback === "function") {
|
|
3279
|
+
callback(null, {
|
|
3280
|
+
status: exports.ResponseStatus.Waiting,
|
|
3281
|
+
statusCode,
|
|
3282
|
+
transactionRid: transactionRid,
|
|
3283
|
+
});
|
|
3284
|
+
}
|
|
3285
|
+
}
|
|
2948
3286
|
catch (_error) {
|
|
2949
3287
|
if (typeof callback === "function") {
|
|
2950
3288
|
callback(_error, null);
|
|
2951
3289
|
}
|
|
2952
3290
|
return reject(_error);
|
|
2953
3291
|
}
|
|
2954
|
-
const
|
|
2955
|
-
|
|
2956
|
-
statusCode: statusCode,
|
|
2957
|
-
transactionRid: transactionRid,
|
|
2958
|
-
};
|
|
2959
|
-
promiEvent.emit("sent", transactionReceipt);
|
|
2960
|
-
if (doStatusPolling === false) {
|
|
2961
|
-
return resolve(transactionReceipt);
|
|
2962
|
-
}
|
|
2963
|
-
const awaitConfirmation = (txRID) => __awaiter$7(this, void 0, void 0, function* () {
|
|
2964
|
-
var _b;
|
|
2965
|
-
let lastKnownResult;
|
|
2966
|
-
for (let i = 0; i < this.config.statusPollCount; i++) {
|
|
2967
|
-
lastKnownResult = yield this.getTransactionStatus(txRID);
|
|
2968
|
-
if (lastKnownResult.status === exports.ResponseStatus.Confirmed) {
|
|
2969
|
-
return exports.ResponseStatus.Confirmed;
|
|
2970
|
-
}
|
|
2971
|
-
else if (lastKnownResult.status === exports.ResponseStatus.Rejected) {
|
|
2972
|
-
throw new TxRejectedError((_b = lastKnownResult.rejectReason) !== null && _b !== void 0 ? _b : "");
|
|
2973
|
-
}
|
|
2974
|
-
yield sleep(this.config.statusPollInterval);
|
|
2975
|
-
}
|
|
2976
|
-
// TS issue. This could be fixed by implementing new retry strategy
|
|
2977
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
2978
|
-
//@ts-expect-error
|
|
2979
|
-
return lastKnownResult.status;
|
|
2980
|
-
});
|
|
2981
|
-
const confirmationStatus = yield awaitConfirmation(getDigestToSign(gtx$1));
|
|
2982
|
-
resolve({
|
|
2983
|
-
status: confirmationStatus,
|
|
2984
|
-
statusCode: statusCode,
|
|
2985
|
-
transactionRid: transactionRid,
|
|
2986
|
-
});
|
|
3292
|
+
const client = this;
|
|
3293
|
+
resolve(yield handleTransactionConfirmations(transactionRid, doStatusPolling, confirmationLevel, promiEvent, statusCode, config.statusPollInterval, config.statusPollCount, () => client.getTransactionStatus(transactionRid, callback), () => client.getClusterAnchoringTransactionConfirmation(transactionRid, callback), anchoredTxRid => client.getSystemAnchoringTransactionConfirmation(anchoredTxRid, callback)));
|
|
2987
3294
|
}
|
|
2988
3295
|
catch (error) {
|
|
3296
|
+
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
2989
3297
|
reject(error);
|
|
2990
3298
|
}
|
|
2991
3299
|
}));
|
|
2992
3300
|
return promiEvent;
|
|
2993
3301
|
},
|
|
2994
|
-
signAndSendUniqueTransaction(transactionOrOperation, signMethod, doStatusPolling = true, callback =
|
|
3302
|
+
signAndSendUniqueTransaction(transactionOrOperation, signMethod, doStatusPolling = true, callback, confirmationLevel = exports.ChainConfirmationLevel.Dapp) {
|
|
2995
3303
|
isSignMethodValid(signMethod, { throwOnError: true });
|
|
2996
3304
|
const promiEvent = new Web3PromiEvent((resolve, reject) => {
|
|
3305
|
+
const client = this;
|
|
2997
3306
|
const transaction = "name" in transactionOrOperation
|
|
2998
3307
|
? {
|
|
2999
3308
|
operations: [transactionOrOperation],
|
|
3000
3309
|
signers: [signMethod.pubKey],
|
|
3001
3310
|
}
|
|
3002
3311
|
: transactionOrOperation;
|
|
3003
|
-
const hasNop = transaction.operations.some(
|
|
3312
|
+
const hasNop = transaction.operations.some(operation => {
|
|
3004
3313
|
return operation.name === "nop";
|
|
3005
3314
|
});
|
|
3006
|
-
const transactionWithNop = hasNop
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
this.signTransaction(transactionWithNop, signMethod)
|
|
3315
|
+
const transactionWithNop = hasNop ? transaction : client.addNop(transaction);
|
|
3316
|
+
client
|
|
3317
|
+
.signTransaction(transactionWithNop, signMethod)
|
|
3010
3318
|
.then((signedTx) => {
|
|
3011
|
-
const sendTransactionPromiEvent =
|
|
3319
|
+
const sendTransactionPromiEvent = client.sendTransaction(signedTx, doStatusPolling, callback, confirmationLevel);
|
|
3012
3320
|
sendTransactionPromiEvent.on("sent", (receipt) => {
|
|
3013
3321
|
promiEvent.emit("sent", receipt);
|
|
3014
3322
|
});
|
|
3015
|
-
|
|
3323
|
+
sendTransactionPromiEvent
|
|
3324
|
+
.then((receipt) => {
|
|
3325
|
+
resolve(receipt);
|
|
3326
|
+
})
|
|
3327
|
+
.catch((error) => {
|
|
3328
|
+
reject(error);
|
|
3329
|
+
});
|
|
3016
3330
|
})
|
|
3017
3331
|
.catch((error) => {
|
|
3018
3332
|
reject(error);
|
|
@@ -3021,7 +3335,7 @@ function createClient(settings) {
|
|
|
3021
3335
|
return promiEvent;
|
|
3022
3336
|
},
|
|
3023
3337
|
getTransaction(transactionRid, callback) {
|
|
3024
|
-
return __awaiter$
|
|
3338
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3025
3339
|
try {
|
|
3026
3340
|
isTxRidValid(transactionRid, { throwOnError: true });
|
|
3027
3341
|
}
|
|
@@ -3029,14 +3343,14 @@ function createClient(settings) {
|
|
|
3029
3343
|
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
3030
3344
|
throw error;
|
|
3031
3345
|
}
|
|
3032
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `tx/${
|
|
3346
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `tx/${config.blockchainRid}/${transactionRid.toString("hex")}`, config);
|
|
3033
3347
|
return new Promise((resolve, reject) => {
|
|
3034
3348
|
handleGetResponse(error, statusCode, statusCode === 200 ? toBuffer(rspBody.tx) : rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
3035
3349
|
});
|
|
3036
3350
|
});
|
|
3037
3351
|
},
|
|
3038
3352
|
getTransactionStatus(transactionRid, callback) {
|
|
3039
|
-
return __awaiter$
|
|
3353
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3040
3354
|
try {
|
|
3041
3355
|
isTxRidValid(transactionRid, { throwOnError: true });
|
|
3042
3356
|
}
|
|
@@ -3044,7 +3358,7 @@ function createClient(settings) {
|
|
|
3044
3358
|
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
3045
3359
|
throw error;
|
|
3046
3360
|
}
|
|
3047
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `tx/${
|
|
3361
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `tx/${config.blockchainRid}/${transactionRid.toString("hex")}/status`, config);
|
|
3048
3362
|
return new Promise((resolve, reject) => {
|
|
3049
3363
|
handleGetResponse(error, statusCode, rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
3050
3364
|
});
|
|
@@ -3061,7 +3375,7 @@ function createClient(settings) {
|
|
|
3061
3375
|
},
|
|
3062
3376
|
getTransactionRid(transaction) {
|
|
3063
3377
|
try {
|
|
3064
|
-
const gtx$1 = getGTXFromBufferOrTransactionOrOperation(transaction,
|
|
3378
|
+
const gtx$1 = getGTXFromBufferOrTransactionOrOperation(transaction, config.blockchainRid);
|
|
3065
3379
|
return getDigestToSign(gtx$1);
|
|
3066
3380
|
}
|
|
3067
3381
|
catch (e) {
|
|
@@ -3069,21 +3383,17 @@ function createClient(settings) {
|
|
|
3069
3383
|
}
|
|
3070
3384
|
},
|
|
3071
3385
|
getTransactionsInfo(limit = 25, beforeTime, callback) {
|
|
3072
|
-
return __awaiter$
|
|
3073
|
-
const beforeTimeQueryParam = beforeTime
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `transactions/${this.config.blockchainRid}?limit=${limit}${beforeTimeQueryParam}`, this.config);
|
|
3077
|
-
const body = statusCode === 200
|
|
3078
|
-
? rspBody === null || rspBody === void 0 ? void 0 : rspBody.map(formatTransactionInfoResponse)
|
|
3079
|
-
: rspBody;
|
|
3386
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3387
|
+
const beforeTimeQueryParam = beforeTime ? `&before-time=${beforeTime.getTime()}` : "";
|
|
3388
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `transactions/${config.blockchainRid}?limit=${limit}${beforeTimeQueryParam}`, config);
|
|
3389
|
+
const body = statusCode === 200 ? rspBody === null || rspBody === void 0 ? void 0 : rspBody.map(formatTransactionInfoResponse) : rspBody;
|
|
3080
3390
|
return new Promise((resolve, reject) => {
|
|
3081
3391
|
handleGetResponse(error, statusCode, body, callbackPromiseBuilder(reject, resolve, callback));
|
|
3082
3392
|
});
|
|
3083
3393
|
});
|
|
3084
3394
|
},
|
|
3085
3395
|
getTransactionInfo(transactionRid, callback) {
|
|
3086
|
-
return __awaiter$
|
|
3396
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3087
3397
|
try {
|
|
3088
3398
|
isTxRidValid(transactionRid, { throwOnError: true });
|
|
3089
3399
|
}
|
|
@@ -3091,30 +3401,75 @@ function createClient(settings) {
|
|
|
3091
3401
|
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
3092
3402
|
throw error;
|
|
3093
3403
|
}
|
|
3094
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `transactions/${
|
|
3095
|
-
const body = statusCode === 200 && rspBody
|
|
3096
|
-
? formatTransactionInfoResponse(rspBody)
|
|
3097
|
-
: rspBody;
|
|
3404
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `transactions/${config.blockchainRid}/${toString(transactionRid)}`, config);
|
|
3405
|
+
const body = statusCode === 200 && rspBody ? formatTransactionInfoResponse(rspBody) : rspBody;
|
|
3098
3406
|
return new Promise((resolve, reject) => {
|
|
3099
3407
|
handleGetResponse(error, statusCode, body, callbackPromiseBuilder(reject, resolve, callback));
|
|
3100
3408
|
});
|
|
3101
3409
|
});
|
|
3102
3410
|
},
|
|
3411
|
+
getTransactionConfirmationLevel(transactionRid, callback) {
|
|
3412
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3413
|
+
try {
|
|
3414
|
+
const client = this;
|
|
3415
|
+
const dappConfirmation = yield client.getTransactionStatus(transactionRid);
|
|
3416
|
+
const response = {
|
|
3417
|
+
status: dappConfirmation.status,
|
|
3418
|
+
statusCode: 200,
|
|
3419
|
+
transactionRid,
|
|
3420
|
+
};
|
|
3421
|
+
if (dappConfirmation.status === exports.ResponseStatus.Waiting) {
|
|
3422
|
+
return response;
|
|
3423
|
+
}
|
|
3424
|
+
let clusterAnchoringResult = null;
|
|
3425
|
+
if (dappConfirmation.status === exports.ResponseStatus.Confirmed) {
|
|
3426
|
+
clusterAnchoringResult = yield client.getClusterAnchoringTransactionConfirmation(transactionRid);
|
|
3427
|
+
if (clusterAnchoringResult === exports.AnchoringStatus.NotAnchored || !clusterAnchoringResult) {
|
|
3428
|
+
return response;
|
|
3429
|
+
}
|
|
3430
|
+
if (clusterAnchoringResult === exports.AnchoringStatus.FailedAnchoring) {
|
|
3431
|
+
response.status = exports.AnchoringStatus.FailedAnchoring;
|
|
3432
|
+
response.statusCode = 400;
|
|
3433
|
+
return response;
|
|
3434
|
+
}
|
|
3435
|
+
const anchoringTransactionValidation = AnchoringTransactionSchema.safeParse(clusterAnchoringResult);
|
|
3436
|
+
if (!anchoringTransactionValidation.success) {
|
|
3437
|
+
return response;
|
|
3438
|
+
}
|
|
3439
|
+
if (anchoringTransactionValidation.success) {
|
|
3440
|
+
response.status = exports.AnchoringStatus.ClusterAnchored;
|
|
3441
|
+
response.statusCode = 200;
|
|
3442
|
+
response["clusterAnchoredTx"] = anchoringTransactionValidation.data;
|
|
3443
|
+
const systemAnchoringResult = yield client.getSystemAnchoringTransactionConfirmation(anchoringTransactionValidation.data.txRid);
|
|
3444
|
+
if (!systemAnchoringResult) {
|
|
3445
|
+
return response;
|
|
3446
|
+
}
|
|
3447
|
+
response.status = exports.AnchoringStatus.SystemAnchored;
|
|
3448
|
+
response["systemAnchoredTx"] = systemAnchoringResult;
|
|
3449
|
+
return response;
|
|
3450
|
+
}
|
|
3451
|
+
}
|
|
3452
|
+
return response;
|
|
3453
|
+
}
|
|
3454
|
+
catch (error) {
|
|
3455
|
+
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
3456
|
+
throw error;
|
|
3457
|
+
}
|
|
3458
|
+
});
|
|
3459
|
+
},
|
|
3103
3460
|
getTransactionCount(callback) {
|
|
3104
|
-
return __awaiter$
|
|
3105
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `transactions/${
|
|
3461
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3462
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `transactions/${config.blockchainRid}/count`, config, undefined, true);
|
|
3106
3463
|
return new Promise((resolve, reject) => {
|
|
3107
3464
|
handleGetResponse(error, statusCode, statusCode === 200 ? rspBody.transactionsCount : rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
3108
3465
|
});
|
|
3109
3466
|
});
|
|
3110
3467
|
},
|
|
3111
3468
|
getBlockInfo(blockIdentifier, txs = false, callback) {
|
|
3112
|
-
return __awaiter$
|
|
3469
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3113
3470
|
isBlockIdentifierValid(blockIdentifier, { throwOnError: true });
|
|
3114
|
-
const queryString = typeof blockIdentifier === "string"
|
|
3115
|
-
|
|
3116
|
-
: `height/${blockIdentifier}`;
|
|
3117
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `blocks/${this.config.blockchainRid}/${queryString}?txs=${txs}`, this.config);
|
|
3471
|
+
const queryString = typeof blockIdentifier === "string" ? blockIdentifier : `height/${blockIdentifier}`;
|
|
3472
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `blocks/${config.blockchainRid}/${queryString}?txs=${txs}`, config);
|
|
3118
3473
|
return new Promise((resolve, reject) => {
|
|
3119
3474
|
handleGetResponse(error, statusCode, statusCode === 200 && rspBody !== null && rspBody
|
|
3120
3475
|
? formatBlockInfoResponse(rspBody)
|
|
@@ -3123,9 +3478,9 @@ function createClient(settings) {
|
|
|
3123
3478
|
});
|
|
3124
3479
|
},
|
|
3125
3480
|
getLatestBlock(txs = false, callback) {
|
|
3126
|
-
return __awaiter$
|
|
3481
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3127
3482
|
const shouldIncludeFullTransaction = txs ? `&txs=${txs}` : "";
|
|
3128
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `blocks/${
|
|
3483
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `blocks/${config.blockchainRid}?limit=1${shouldIncludeFullTransaction}`, config, undefined, true);
|
|
3129
3484
|
const indexOfLatestBlock = 0;
|
|
3130
3485
|
return new Promise((resolve, reject) => {
|
|
3131
3486
|
handleGetResponse(error, statusCode, statusCode === 200 && rspBody !== null && rspBody
|
|
@@ -3134,8 +3489,8 @@ function createClient(settings) {
|
|
|
3134
3489
|
});
|
|
3135
3490
|
});
|
|
3136
3491
|
},
|
|
3137
|
-
getBlocks({ limit, beforeTime, afterTime, beforeHeight, afterHeight, txs, callback
|
|
3138
|
-
return __awaiter$
|
|
3492
|
+
getBlocks({ limit, beforeTime, afterTime, beforeHeight, afterHeight, txs, callback }) {
|
|
3493
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3139
3494
|
const searchValues = {
|
|
3140
3495
|
limit,
|
|
3141
3496
|
txs,
|
|
@@ -3150,16 +3505,14 @@ function createClient(settings) {
|
|
|
3150
3505
|
searchParams.append(key, value.toString());
|
|
3151
3506
|
}
|
|
3152
3507
|
}
|
|
3153
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `blocks/${
|
|
3508
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `blocks/${config.blockchainRid}?${searchParams}`, config);
|
|
3154
3509
|
return new Promise((resolve, reject) => {
|
|
3155
|
-
handleGetResponse(error, statusCode, statusCode === 200 && rspBody
|
|
3156
|
-
? rspBody.map(formatBlockInfoResponse)
|
|
3157
|
-
: rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
3510
|
+
handleGetResponse(error, statusCode, statusCode === 200 && rspBody ? rspBody.map(formatBlockInfoResponse) : rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
3158
3511
|
});
|
|
3159
3512
|
});
|
|
3160
3513
|
},
|
|
3161
3514
|
getBlocksInfo(limit = 25, beforeTime, beforeHeight, txs, callback) {
|
|
3162
|
-
return __awaiter$
|
|
3515
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3163
3516
|
let filteringQueryParam = "";
|
|
3164
3517
|
if (beforeTime) {
|
|
3165
3518
|
filteringQueryParam = `&before-time=${beforeTime.getTime()}`;
|
|
@@ -3168,16 +3521,14 @@ function createClient(settings) {
|
|
|
3168
3521
|
filteringQueryParam = `&before-height=${beforeHeight}`;
|
|
3169
3522
|
}
|
|
3170
3523
|
const shouldIncludeFullTransaction = txs ? `&txs=${txs}` : "";
|
|
3171
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `blocks/${
|
|
3524
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `blocks/${config.blockchainRid}?limit=${limit}${filteringQueryParam}${shouldIncludeFullTransaction}`, config);
|
|
3172
3525
|
return new Promise((resolve, reject) => {
|
|
3173
|
-
handleGetResponse(error, statusCode, statusCode === 200 && rspBody
|
|
3174
|
-
? rspBody.map(formatBlockInfoResponse)
|
|
3175
|
-
: rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
3526
|
+
handleGetResponse(error, statusCode, statusCode === 200 && rspBody ? rspBody.map(formatBlockInfoResponse) : rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
3176
3527
|
});
|
|
3177
3528
|
});
|
|
3178
3529
|
},
|
|
3179
3530
|
encodeTransaction(transaction) {
|
|
3180
|
-
const gtx$1 = getGTXFromBufferOrTransactionOrOperation(transaction,
|
|
3531
|
+
const gtx$1 = getGTXFromBufferOrTransactionOrOperation(transaction, config.blockchainRid);
|
|
3181
3532
|
return serialize(gtx$1);
|
|
3182
3533
|
},
|
|
3183
3534
|
decodeTransactionToGtx(encodedTransaction) {
|
|
@@ -3186,7 +3537,7 @@ function createClient(settings) {
|
|
|
3186
3537
|
return gtx$1;
|
|
3187
3538
|
},
|
|
3188
3539
|
getClientNodeUrlPool() {
|
|
3189
|
-
return
|
|
3540
|
+
return config.endpointPool.map((endpoint) => endpoint.url);
|
|
3190
3541
|
},
|
|
3191
3542
|
/**
|
|
3192
3543
|
* Retrieves a confirmation proof for a transaction with the specified sha256
|
|
@@ -3213,8 +3564,8 @@ function createClient(settings) {
|
|
|
3213
3564
|
* The signatures must be validated agains some know trusted source for valid signers
|
|
3214
3565
|
* at this specific block height.
|
|
3215
3566
|
*/
|
|
3216
|
-
getConfirmationProof
|
|
3217
|
-
return __awaiter$
|
|
3567
|
+
getConfirmationProof(txRid, callback) {
|
|
3568
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3218
3569
|
try {
|
|
3219
3570
|
isTxRidValid(txRid, { throwOnError: true });
|
|
3220
3571
|
}
|
|
@@ -3222,7 +3573,7 @@ function createClient(settings) {
|
|
|
3222
3573
|
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
3223
3574
|
throw error;
|
|
3224
3575
|
}
|
|
3225
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `tx/${
|
|
3576
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `tx/${config.blockchainRid}/${txRid.toString("hex")}/confirmationProof`, config);
|
|
3226
3577
|
const confirmationProof = {
|
|
3227
3578
|
merkleProofTree: "",
|
|
3228
3579
|
txIndex: 0,
|
|
@@ -3248,13 +3599,70 @@ function createClient(settings) {
|
|
|
3248
3599
|
});
|
|
3249
3600
|
});
|
|
3250
3601
|
},
|
|
3602
|
+
getClusterAnchoringTransactionConfirmation(transactionRid, callback) {
|
|
3603
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3604
|
+
try {
|
|
3605
|
+
isTxRidValid(transactionRid, { throwOnError: true });
|
|
3606
|
+
}
|
|
3607
|
+
catch (error) {
|
|
3608
|
+
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
3609
|
+
throw error;
|
|
3610
|
+
}
|
|
3611
|
+
const client = this;
|
|
3612
|
+
try {
|
|
3613
|
+
let confirmationProof;
|
|
3614
|
+
try {
|
|
3615
|
+
confirmationProof = yield client.getConfirmationProof(transactionRid);
|
|
3616
|
+
}
|
|
3617
|
+
catch (error) {
|
|
3618
|
+
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
3619
|
+
return exports.AnchoringStatus.NotAnchored;
|
|
3620
|
+
}
|
|
3621
|
+
const D1Client = yield getSystemClient(getUrlsFromEndpoints(config.endpointPool), config.directoryChainRid);
|
|
3622
|
+
const anchoringClient = yield getAnchoringClient(D1Client, config.blockchainRid);
|
|
3623
|
+
const anchoringTransaction = yield getBlockAnchoringTransaction(client, anchoringClient, transactionRid, confirmationProof);
|
|
3624
|
+
if (!anchoringTransaction)
|
|
3625
|
+
return exports.AnchoringStatus.NotAnchored;
|
|
3626
|
+
return anchoringTransaction;
|
|
3627
|
+
}
|
|
3628
|
+
catch (error) {
|
|
3629
|
+
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
3630
|
+
return exports.AnchoringStatus.FailedAnchoring;
|
|
3631
|
+
}
|
|
3632
|
+
});
|
|
3633
|
+
},
|
|
3634
|
+
getSystemAnchoringTransactionConfirmation(anchoredTxRid, callback) {
|
|
3635
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3636
|
+
try {
|
|
3637
|
+
isTxRidValid(anchoredTxRid, { throwOnError: true });
|
|
3638
|
+
}
|
|
3639
|
+
catch (error) {
|
|
3640
|
+
callback === null || callback === void 0 ? void 0 : callback(error, null);
|
|
3641
|
+
throw error;
|
|
3642
|
+
}
|
|
3643
|
+
const D1Client = yield getSystemClient(getUrlsFromEndpoints(config.endpointPool), config.directoryChainRid);
|
|
3644
|
+
const systemAnchoringChainRid = yield getSystemAnchoringChain(D1Client);
|
|
3645
|
+
if (!systemAnchoringChainRid)
|
|
3646
|
+
return null;
|
|
3647
|
+
const systemAnchoringChainClient = yield getSystemClient(getUrlsFromEndpoints(config.endpointPool), systemAnchoringChainRid.toString("hex"));
|
|
3648
|
+
const anchoringClient = yield getAnchoringClient(D1Client, config.blockchainRid);
|
|
3649
|
+
const anchoringProof = yield anchoringClient.getConfirmationProof(anchoredTxRid);
|
|
3650
|
+
const blockRid = calculateBlockRID(anchoringProof);
|
|
3651
|
+
const systemAnchoringTransactionConfirmation = yield awaitGetAnchoringTransactionForBlockRid(systemAnchoringChainClient, toBuffer(anchoringClient.config.blockchainRid), blockRid, systemAnchoringChainClient.config.statusPollInterval, systemAnchoringChainClient.config.statusPollCount);
|
|
3652
|
+
const systemAnchoringTransactionValidaiton = AnchoringTransactionSchema.safeParse(systemAnchoringTransactionConfirmation);
|
|
3653
|
+
if (systemAnchoringTransactionValidaiton.success) {
|
|
3654
|
+
return systemAnchoringTransactionValidaiton.data;
|
|
3655
|
+
}
|
|
3656
|
+
return systemAnchoringTransactionConfirmation;
|
|
3657
|
+
});
|
|
3658
|
+
},
|
|
3251
3659
|
/**
|
|
3252
3660
|
* Get app structure. Returns list of app modules in JSON format
|
|
3253
3661
|
* @param callback - leverages error-first pattern and called when promise resolves
|
|
3254
3662
|
*/
|
|
3255
3663
|
getAppStructure(callback) {
|
|
3256
|
-
return __awaiter$
|
|
3257
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `/query/${
|
|
3664
|
+
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3665
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `/query/${config.blockchainRid}?type=rell.get_app_structure`, config);
|
|
3258
3666
|
return new Promise((resolve, reject) => {
|
|
3259
3667
|
handleGetResponse(error, statusCode, rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
3260
3668
|
});
|
|
@@ -3273,19 +3681,19 @@ const shuffleArray = (array) => {
|
|
|
3273
3681
|
return shuffledArray;
|
|
3274
3682
|
};
|
|
3275
3683
|
const createNodeManager = ({ nodeUrls, useStickyNode = false, unavailableDuration = 5000, }) => {
|
|
3276
|
-
const nodes = nodeUrls.map(
|
|
3684
|
+
const nodes = nodeUrls.map(url => ({
|
|
3277
3685
|
url,
|
|
3278
3686
|
whenAvailable: 0,
|
|
3279
3687
|
isAvailable: true,
|
|
3280
3688
|
}));
|
|
3281
3689
|
return {
|
|
3282
|
-
nodes
|
|
3690
|
+
nodes,
|
|
3283
3691
|
stickedNode: null,
|
|
3284
3692
|
getAvailableNodes() {
|
|
3285
3693
|
const shuffledAvailableNodes = shuffleArray(this.nodes.filter((node) => node.isAvailable));
|
|
3286
3694
|
// set sticky node as the first node, and then shuffle the rest
|
|
3287
3695
|
if (useStickyNode && this.stickedNode && this.stickedNode.isAvailable) {
|
|
3288
|
-
const nodesWithoutSticky = shuffledAvailableNodes.filter(
|
|
3696
|
+
const nodesWithoutSticky = shuffledAvailableNodes.filter(node => node !== this.stickedNode);
|
|
3289
3697
|
return [this.stickedNode, ...nodesWithoutSticky];
|
|
3290
3698
|
}
|
|
3291
3699
|
return shuffledAvailableNodes;
|
|
@@ -3329,7 +3737,7 @@ const createNodeManager = ({ nodeUrls, useStickyNode = false, unavailableDuratio
|
|
|
3329
3737
|
};
|
|
3330
3738
|
};
|
|
3331
3739
|
|
|
3332
|
-
var __awaiter$
|
|
3740
|
+
var __awaiter$4 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3333
3741
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3334
3742
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
3335
3743
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -3340,7 +3748,7 @@ var __awaiter$6 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
3340
3748
|
};
|
|
3341
3749
|
function getClientConfigFromSettings(settings) {
|
|
3342
3750
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
3343
|
-
return __awaiter$
|
|
3751
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
3344
3752
|
const nodeUrlPoolToUse = yield getNodeUrlsFromSettings(settings);
|
|
3345
3753
|
if (nodeUrlPoolToUse.length === 0) {
|
|
3346
3754
|
const id = (_b = (_a = settings.blockchainRid) !== null && _a !== void 0 ? _a : settings.blockchainIid) !== null && _b !== void 0 ? _b : "Unknown";
|
|
@@ -3352,7 +3760,7 @@ function getClientConfigFromSettings(settings) {
|
|
|
3352
3760
|
useStickyNode: (_c = settings.useStickyNode) !== null && _c !== void 0 ? _c : false,
|
|
3353
3761
|
unavailableDuration: (_d = settings.failOverConfig) === null || _d === void 0 ? void 0 : _d.unreachableDuration,
|
|
3354
3762
|
});
|
|
3355
|
-
const blockchainRidToUse = yield (() => __awaiter$
|
|
3763
|
+
const blockchainRidToUse = yield (() => __awaiter$4(this, void 0, void 0, function* () {
|
|
3356
3764
|
if (settings.blockchainRid) {
|
|
3357
3765
|
return settings.blockchainRid;
|
|
3358
3766
|
}
|
|
@@ -3365,6 +3773,17 @@ function getClientConfigFromSettings(settings) {
|
|
|
3365
3773
|
}
|
|
3366
3774
|
throw new MissingBlockchainIdentifierError();
|
|
3367
3775
|
}))();
|
|
3776
|
+
const directoryChainRid = yield (() => __awaiter$4(this, void 0, void 0, function* () {
|
|
3777
|
+
if (settings.directoryChainRid) {
|
|
3778
|
+
return settings.directoryChainRid;
|
|
3779
|
+
}
|
|
3780
|
+
const directoryChainIid = 0;
|
|
3781
|
+
return yield getBlockchainRidFromIid({
|
|
3782
|
+
nodeManager,
|
|
3783
|
+
endpointPool,
|
|
3784
|
+
chainId: directoryChainIid,
|
|
3785
|
+
});
|
|
3786
|
+
}))();
|
|
3368
3787
|
return {
|
|
3369
3788
|
endpointPool,
|
|
3370
3789
|
nodeManager: nodeManager,
|
|
@@ -3372,17 +3791,15 @@ function getClientConfigFromSettings(settings) {
|
|
|
3372
3791
|
statusPollInterval: settings.statusPollInterval || 500,
|
|
3373
3792
|
statusPollCount: settings.statusPollCount || 20,
|
|
3374
3793
|
failoverStrategy: ((_e = settings.failOverConfig) === null || _e === void 0 ? void 0 : _e.strategy) || defaultFailoverConfig.strategy,
|
|
3375
|
-
attemptsPerEndpoint: ((_f = settings.failOverConfig) === null || _f === void 0 ? void 0 : _f.attemptsPerEndpoint) ||
|
|
3376
|
-
|
|
3377
|
-
|
|
3378
|
-
|
|
3379
|
-
unreachableDuration: ((_h = settings.failOverConfig) === null || _h === void 0 ? void 0 : _h.unreachableDuration) ||
|
|
3380
|
-
defaultFailoverConfig.unreachableDuration,
|
|
3794
|
+
attemptsPerEndpoint: ((_f = settings.failOverConfig) === null || _f === void 0 ? void 0 : _f.attemptsPerEndpoint) || defaultFailoverConfig.attemptsPerEndpoint,
|
|
3795
|
+
attemptInterval: ((_g = settings.failOverConfig) === null || _g === void 0 ? void 0 : _g.attemptInterval) || defaultFailoverConfig.attemptInterval,
|
|
3796
|
+
unreachableDuration: ((_h = settings.failOverConfig) === null || _h === void 0 ? void 0 : _h.unreachableDuration) || defaultFailoverConfig.unreachableDuration,
|
|
3797
|
+
directoryChainRid: settings.directoryChainRid || directoryChainRid,
|
|
3381
3798
|
};
|
|
3382
3799
|
});
|
|
3383
3800
|
}
|
|
3384
3801
|
function nodeDiscovery({ nodeManager, directoryEndpointPool, failOverConfig, blockchainRid, blockchainIid, }) {
|
|
3385
|
-
return __awaiter$
|
|
3802
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
3386
3803
|
if (directoryEndpointPool.length === 0) {
|
|
3387
3804
|
throw new DirectoryNodeUrlPoolException();
|
|
3388
3805
|
}
|
|
@@ -3396,7 +3813,7 @@ function nodeDiscovery({ nodeManager, directoryEndpointPool, failOverConfig, blo
|
|
|
3396
3813
|
chainId: directoryIid,
|
|
3397
3814
|
failOverConfig,
|
|
3398
3815
|
});
|
|
3399
|
-
const blockchainRidToUse = yield (() => __awaiter$
|
|
3816
|
+
const blockchainRidToUse = yield (() => __awaiter$4(this, void 0, void 0, function* () {
|
|
3400
3817
|
if (blockchainRid) {
|
|
3401
3818
|
return blockchainRid;
|
|
3402
3819
|
}
|
|
@@ -3423,7 +3840,7 @@ function nodeDiscovery({ nodeManager, directoryEndpointPool, failOverConfig, blo
|
|
|
3423
3840
|
});
|
|
3424
3841
|
}
|
|
3425
3842
|
function convertToRellOperation(operations) {
|
|
3426
|
-
return operations.map(
|
|
3843
|
+
return operations.map(operation => {
|
|
3427
3844
|
var _a;
|
|
3428
3845
|
return {
|
|
3429
3846
|
opName: operation.name,
|
|
@@ -3480,7 +3897,7 @@ const callbackPromiseBuilder = (reject, resolve, callback) => {
|
|
|
3480
3897
|
};
|
|
3481
3898
|
const handlePostResponsePromisified = (error, statusCode, rspBody) => {
|
|
3482
3899
|
return new Promise((resolve, reject) => {
|
|
3483
|
-
handlePostResponse(error, statusCode, rspBody,
|
|
3900
|
+
handlePostResponse(error, statusCode, rspBody, _error => {
|
|
3484
3901
|
if (_error) {
|
|
3485
3902
|
reject(_error);
|
|
3486
3903
|
}
|
|
@@ -3516,7 +3933,7 @@ const formatBlockInfoResponse = (blockInfoResponse) => {
|
|
|
3516
3933
|
transactions: blockInfoResponse.transactions.map(formatTransaction),
|
|
3517
3934
|
height: blockInfoResponse.height,
|
|
3518
3935
|
witness: toBuffer(blockInfoResponse.witness),
|
|
3519
|
-
witnesses: blockInfoResponse.witnesses.map(
|
|
3936
|
+
witnesses: blockInfoResponse.witnesses.map(witness => {
|
|
3520
3937
|
return toBuffer(witness);
|
|
3521
3938
|
}),
|
|
3522
3939
|
timestamp: blockInfoResponse.timestamp,
|
|
@@ -3542,7 +3959,7 @@ const isKeyPair = (keypair) => {
|
|
|
3542
3959
|
};
|
|
3543
3960
|
function getNodeUrlsFromSettings(settings) {
|
|
3544
3961
|
var _a;
|
|
3545
|
-
return __awaiter$
|
|
3962
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
3546
3963
|
if (settings.directoryNodeUrlPool) {
|
|
3547
3964
|
// If directoryNodeUrlPool is provided, use nodeDiscovery
|
|
3548
3965
|
const nodeManager = createNodeManager({
|
|
@@ -3554,496 +3971,285 @@ function getNodeUrlsFromSettings(settings) {
|
|
|
3554
3971
|
directoryEndpointPool: createEndpointObjects(ensureArray(settings.directoryNodeUrlPool)),
|
|
3555
3972
|
failOverConfig: settings.failOverConfig,
|
|
3556
3973
|
blockchainRid: settings.blockchainRid,
|
|
3557
|
-
blockchainIid: settings.blockchainIid,
|
|
3558
|
-
});
|
|
3559
|
-
}
|
|
3560
|
-
else if (typeof settings.nodeUrlPool === "string") {
|
|
3561
|
-
// If nodeUrlPool is a string, convert it to an array
|
|
3562
|
-
return [settings.nodeUrlPool];
|
|
3563
|
-
}
|
|
3564
|
-
else if (Array.isArray(settings.nodeUrlPool)) {
|
|
3565
|
-
// If nodeUrlPool is already an array, use it as-is
|
|
3566
|
-
return settings.nodeUrlPool;
|
|
3567
|
-
}
|
|
3568
|
-
else {
|
|
3569
|
-
// Default to an empty array if no valid configuration is provided
|
|
3570
|
-
return [];
|
|
3571
|
-
}
|
|
3572
|
-
});
|
|
3573
|
-
}
|
|
3574
|
-
const defaultFailoverConfig = {
|
|
3575
|
-
strategy: exports.FailoverStrategy.AbortOnError,
|
|
3576
|
-
attemptsPerEndpoint: 3,
|
|
3577
|
-
attemptInterval: 500,
|
|
3578
|
-
unreachableDuration: 30000,
|
|
3579
|
-
};
|
|
3580
|
-
const createEndpointObjects = (endpointPoolUrls) => {
|
|
3581
|
-
const endpoints = endpointPoolUrls.map((endpointUrl) => {
|
|
3582
|
-
return { url: endpointUrl, whenAvailable: 0 };
|
|
3583
|
-
});
|
|
3584
|
-
return endpoints;
|
|
3585
|
-
};
|
|
3586
|
-
const getUrlsFromEndpoints = (endpointPool) => {
|
|
3587
|
-
return endpointPool.map((endpoint) => endpoint.url);
|
|
3588
|
-
};
|
|
3589
|
-
|
|
3590
|
-
var __awaiter$5 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3591
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3592
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
3593
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
3594
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
3595
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
3596
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
3597
|
-
});
|
|
3598
|
-
};
|
|
3599
|
-
function getBlockchainRidFromIid({ endpointPool, chainId, failOverConfig = {}, nodeManager, }) {
|
|
3600
|
-
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3601
|
-
const mergedFailOverConfig = Object.assign(Object.assign({}, defaultFailoverConfig), failOverConfig);
|
|
3602
|
-
const config = {
|
|
3603
|
-
endpointPool,
|
|
3604
|
-
statusPollInterval: 500,
|
|
3605
|
-
nodeManager,
|
|
3606
|
-
statusPollCount: 20,
|
|
3607
|
-
failoverStrategy: mergedFailOverConfig.strategy,
|
|
3608
|
-
attemptsPerEndpoint: mergedFailOverConfig.attemptsPerEndpoint,
|
|
3609
|
-
attemptInterval: mergedFailOverConfig.attemptInterval,
|
|
3610
|
-
unreachableDuration: mergedFailOverConfig.unreachableDuration,
|
|
3611
|
-
};
|
|
3612
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `/brid/iid_${chainId}`, config);
|
|
3613
|
-
if (error) {
|
|
3614
|
-
throw new GetBridFromChainException(chainId, error.message);
|
|
3974
|
+
blockchainIid: settings.blockchainIid,
|
|
3975
|
+
});
|
|
3615
3976
|
}
|
|
3616
|
-
else if (
|
|
3617
|
-
|
|
3977
|
+
else if (typeof settings.nodeUrlPool === "string") {
|
|
3978
|
+
// If nodeUrlPool is a string, convert it to an array
|
|
3979
|
+
return [settings.nodeUrlPool];
|
|
3980
|
+
}
|
|
3981
|
+
else if (Array.isArray(settings.nodeUrlPool)) {
|
|
3982
|
+
// If nodeUrlPool is already an array, use it as-is
|
|
3983
|
+
return settings.nodeUrlPool;
|
|
3984
|
+
}
|
|
3985
|
+
else {
|
|
3986
|
+
// Default to an empty array if no valid configuration is provided
|
|
3987
|
+
return [];
|
|
3618
3988
|
}
|
|
3619
|
-
return rspBody;
|
|
3620
3989
|
});
|
|
3621
3990
|
}
|
|
3622
|
-
function
|
|
3623
|
-
return __awaiter$
|
|
3624
|
-
return
|
|
3625
|
-
|
|
3626
|
-
|
|
3627
|
-
}, timeoutMs);
|
|
3991
|
+
function getSystemClient(directoryNodeUrlPool, directoryChainRid) {
|
|
3992
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
3993
|
+
return yield createClient({
|
|
3994
|
+
directoryNodeUrlPool,
|
|
3995
|
+
blockchainRid: directoryChainRid,
|
|
3628
3996
|
});
|
|
3629
3997
|
});
|
|
3630
3998
|
}
|
|
3631
|
-
|
|
3632
|
-
|
|
3633
|
-
const pendingState = { status: "pending" };
|
|
3634
|
-
for (const p of promises) {
|
|
3635
|
-
promiseList.push(yield Promise.race([p, pendingState]).then((value) => value === pendingState
|
|
3636
|
-
? Object.assign(Object.assign({}, pendingState), { value: p }) : { status: "fulfilled", value }, (reason) => ({ status: "rejected", value: reason })));
|
|
3637
|
-
}
|
|
3638
|
-
return promiseList;
|
|
3639
|
-
});
|
|
3640
|
-
function racePromisesWithTimeout(promises, timeout) {
|
|
3641
|
-
return __awaiter$5(this, void 0, void 0, function* () {
|
|
3642
|
-
let remainingPromises = [];
|
|
3999
|
+
function getSystemAnchoringChain(directoryClient) {
|
|
4000
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
3643
4001
|
try {
|
|
3644
|
-
const
|
|
3645
|
-
|
|
3646
|
-
|
|
3647
|
-
|
|
3648
|
-
|
|
3649
|
-
const indexOfpromiseToRemove = promisesWithState.findIndex((p) => JSON.stringify(p.value) === JSON.stringify(resolvedPromise));
|
|
3650
|
-
// Remove the promise that resolved from the list of promises
|
|
3651
|
-
promisesWithState.splice(indexOfpromiseToRemove, 1);
|
|
3652
|
-
// Remove the state before returning the promises.
|
|
3653
|
-
remainingPromises = promisesWithState.map((p) => p.value);
|
|
3654
|
-
return remainingPromises;
|
|
4002
|
+
const queryObject = {
|
|
4003
|
+
name: "cm_get_system_anchoring_chain",
|
|
4004
|
+
};
|
|
4005
|
+
const systemAnchoringChain = yield directoryClient.query(queryObject);
|
|
4006
|
+
return systemAnchoringChain;
|
|
3655
4007
|
}
|
|
3656
4008
|
catch (error) {
|
|
3657
|
-
|
|
3658
|
-
throw error;
|
|
3659
|
-
}
|
|
3660
|
-
return remainingPromises;
|
|
4009
|
+
throw new SystemChainException(error.message);
|
|
3661
4010
|
}
|
|
3662
4011
|
});
|
|
3663
4012
|
}
|
|
3664
|
-
const
|
|
3665
|
-
|
|
3666
|
-
|
|
3667
|
-
|
|
3668
|
-
|
|
3669
|
-
? { response: acc[key].response, count: acc[key].count + 1 }
|
|
3670
|
-
: { response, count: 1 };
|
|
3671
|
-
return acc;
|
|
3672
|
-
}, {});
|
|
3673
|
-
const distinctResponses = Object.values(responseMap).sort((a, b) => b.count - a.count);
|
|
3674
|
-
// Returns the count of the most common response
|
|
3675
|
-
const maxNumberOfEqualResponses = () => {
|
|
3676
|
-
return distinctResponses.length > 0 ? distinctResponses[0].count : 0;
|
|
3677
|
-
};
|
|
3678
|
-
// Returns the number of distinct responses
|
|
3679
|
-
const numberOfDistinctResponses = () => {
|
|
3680
|
-
return distinctResponses.length;
|
|
3681
|
-
};
|
|
3682
|
-
// Returns the most common response
|
|
3683
|
-
const majorityResponse = () => {
|
|
3684
|
-
return distinctResponses[0].response.result;
|
|
3685
|
-
};
|
|
3686
|
-
return {
|
|
3687
|
-
maxNumberOfEqualResponses,
|
|
3688
|
-
numberOfDistinctResponses,
|
|
3689
|
-
majorityResponse,
|
|
3690
|
-
};
|
|
4013
|
+
const defaultFailoverConfig = {
|
|
4014
|
+
strategy: exports.FailoverStrategy.AbortOnError,
|
|
4015
|
+
attemptsPerEndpoint: 3,
|
|
4016
|
+
attemptInterval: 500,
|
|
4017
|
+
unreachableDuration: 30000,
|
|
3691
4018
|
};
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
|
|
3695
|
-
case exports.FailoverStrategy.AbortOnError:
|
|
3696
|
-
return yield abortOnError({ method, path, config, postObject });
|
|
3697
|
-
case exports.FailoverStrategy.TryNextOnError:
|
|
3698
|
-
return yield tryNextOnError({ method, path, config, postObject });
|
|
3699
|
-
case exports.FailoverStrategy.SingleEndpoint:
|
|
3700
|
-
return yield singleEndpoint({ method, path, config, postObject });
|
|
3701
|
-
case exports.FailoverStrategy.QueryMajority:
|
|
3702
|
-
if (forceSingleEndpoint) {
|
|
3703
|
-
return yield singleEndpoint({ method, path, config, postObject });
|
|
3704
|
-
}
|
|
3705
|
-
return yield queryMajority({ method, path, config, postObject });
|
|
3706
|
-
}
|
|
3707
|
-
});
|
|
3708
|
-
}
|
|
3709
|
-
const sleep = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
3710
|
-
function convertToPrintable(responseObject) {
|
|
3711
|
-
if (typeof responseObject === "bigint") {
|
|
3712
|
-
return `${responseObject}n`;
|
|
3713
|
-
}
|
|
3714
|
-
else if (typeof responseObject === "object") {
|
|
3715
|
-
return JSON.stringify(responseObject, (key, value) => typeof value === "bigint" ? `${value}n` : value);
|
|
3716
|
-
}
|
|
3717
|
-
else {
|
|
3718
|
-
return responseObject;
|
|
3719
|
-
}
|
|
3720
|
-
}
|
|
3721
|
-
const bftMajority = (n) => n - (n - 1) / 3;
|
|
3722
|
-
|
|
3723
|
-
var restclientutil = /*#__PURE__*/Object.freeze({
|
|
3724
|
-
__proto__: null,
|
|
3725
|
-
bftMajority: bftMajority,
|
|
3726
|
-
checkStateOfPromises: checkStateOfPromises,
|
|
3727
|
-
convertToPrintable: convertToPrintable,
|
|
3728
|
-
createTimeoutPromise: createTimeoutPromise,
|
|
3729
|
-
getBlockchainRidFromIid: getBlockchainRidFromIid,
|
|
3730
|
-
groupResponses: groupResponses,
|
|
3731
|
-
racePromisesWithTimeout: racePromisesWithTimeout,
|
|
3732
|
-
requestWithFailoverStrategy: requestWithFailoverStrategy,
|
|
3733
|
-
sleep: sleep
|
|
3734
|
-
});
|
|
3735
|
-
|
|
3736
|
-
var __awaiter$4 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3737
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3738
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
3739
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
3740
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
3741
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
3742
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
4019
|
+
const createEndpointObjects = (endpointPoolUrls) => {
|
|
4020
|
+
const endpoints = endpointPoolUrls.map(endpointUrl => {
|
|
4021
|
+
return { url: endpointUrl, whenAvailable: 0 };
|
|
3743
4022
|
});
|
|
4023
|
+
return endpoints;
|
|
3744
4024
|
};
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
failoverStrategy: (failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.strategy) || exports.FailoverStrategy.AbortOnError,
|
|
3757
|
-
attemptsPerEndpoint: (failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptsPerEndpoint) || 3,
|
|
3758
|
-
attemptInterval: (failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptInterval) || 500,
|
|
3759
|
-
unreachableDuration: unreachableDuration,
|
|
3760
|
-
},
|
|
3761
|
-
getTransaction: function (txRID, callback) {
|
|
3762
|
-
return __awaiter$4(this, void 0, void 0, function* () {
|
|
3763
|
-
if (!isTxRidValid(txRID)) {
|
|
3764
|
-
callback(new InvalidTxRidException(txRID), null);
|
|
3765
|
-
}
|
|
3766
|
-
else {
|
|
3767
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `tx/${blockchainRid}/${txRID.toString("hex")}`, this.config);
|
|
3768
|
-
handleGetResponse(error, statusCode, statusCode === 200 ? toBuffer(rspBody.tx) : rspBody, callback);
|
|
3769
|
-
}
|
|
3770
|
-
});
|
|
3771
|
-
},
|
|
3772
|
-
postTransaction: function (serializedTransaction, callback) {
|
|
3773
|
-
return __awaiter$4(this, void 0, void 0, function* () {
|
|
3774
|
-
if (!require$$0$1.Buffer.isBuffer(serializedTransaction)) {
|
|
3775
|
-
throw new SerializedTransactionFormatException();
|
|
3776
|
-
}
|
|
3777
|
-
const transactionObject = {
|
|
3778
|
-
tx: serializedTransaction.toString("hex"),
|
|
3779
|
-
};
|
|
3780
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.POST, `tx/${blockchainRid}`, this.config, transactionObject);
|
|
3781
|
-
handlePostResponse(error, statusCode, rspBody, callback);
|
|
3782
|
-
});
|
|
3783
|
-
},
|
|
3784
|
-
status: function (txRID, callback) {
|
|
3785
|
-
return __awaiter$4(this, void 0, void 0, function* () {
|
|
3786
|
-
if (!isTxRidValid(txRID)) {
|
|
3787
|
-
callback(new InvalidTxRidException(txRID), null);
|
|
3788
|
-
}
|
|
3789
|
-
else {
|
|
3790
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `tx/${blockchainRid}/${txRID.toString("hex")}/status`, this.config);
|
|
3791
|
-
handleGetResponse(error, statusCode, rspBody, callback);
|
|
3792
|
-
}
|
|
3793
|
-
});
|
|
3794
|
-
},
|
|
3795
|
-
query: function (nameOrQueryObject, queryArguments) {
|
|
3796
|
-
return __awaiter$4(this, void 0, void 0, function* () {
|
|
3797
|
-
// eslint-disable-next-line no-async-promise-executor
|
|
3798
|
-
return new Promise((resolve, reject) => __awaiter$4(this, void 0, void 0, function* () {
|
|
3799
|
-
const callback = (error, result) => {
|
|
3800
|
-
if (error) {
|
|
3801
|
-
reject(error);
|
|
3802
|
-
}
|
|
3803
|
-
else {
|
|
3804
|
-
resolve(result);
|
|
3805
|
-
}
|
|
3806
|
-
};
|
|
3807
|
-
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.POST, `query_gtv/${blockchainRid}`, this.config, encodeValue(toQueryObjectGTV(nameOrQueryObject, queryArguments)));
|
|
3808
|
-
handlePostResponse(error, statusCode, rspBody, callback);
|
|
3809
|
-
}));
|
|
3810
|
-
});
|
|
3811
|
-
},
|
|
3812
|
-
waitConfirmation(txRID) {
|
|
3813
|
-
return new Promise((resolve, reject) => {
|
|
3814
|
-
this.status(txRID, (error$1, result) => {
|
|
3815
|
-
if (error$1) {
|
|
3816
|
-
reject(error$1);
|
|
3817
|
-
}
|
|
3818
|
-
else {
|
|
3819
|
-
const status = result.status;
|
|
3820
|
-
switch (status) {
|
|
3821
|
-
case ResponseStatus.Confirmed:
|
|
3822
|
-
resolve(null);
|
|
3823
|
-
break;
|
|
3824
|
-
case ResponseStatus.Rejected:
|
|
3825
|
-
reject(new TxRejectedError(result.rejectReason));
|
|
3826
|
-
break;
|
|
3827
|
-
case ResponseStatus.Unknown:
|
|
3828
|
-
reject(new LostMessageError());
|
|
3829
|
-
break;
|
|
3830
|
-
case ResponseStatus.Waiting:
|
|
3831
|
-
setTimeout(() => this.waitConfirmation(txRID).then(resolve, reject), this.config.pollingInterval);
|
|
3832
|
-
break;
|
|
3833
|
-
default:
|
|
3834
|
-
error(status);
|
|
3835
|
-
reject(new UnexpectedResponseError());
|
|
3836
|
-
}
|
|
3837
|
-
}
|
|
3838
|
-
});
|
|
3839
|
-
});
|
|
3840
|
-
},
|
|
3841
|
-
postAndWaitConfirmation(serializedTransaction, txRID, validate) {
|
|
3842
|
-
if (validate === true) {
|
|
3843
|
-
return Promise.reject("Automatic validation is not yet implemented");
|
|
4025
|
+
const getUrlsFromEndpoints = (endpointPool) => {
|
|
4026
|
+
return endpointPool.map(endpoint => endpoint.url);
|
|
4027
|
+
};
|
|
4028
|
+
function awaitDappConfirmation(txRID, statusPollInterval, statusPollCount, getTransactionStatus) {
|
|
4029
|
+
var _a;
|
|
4030
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4031
|
+
let lastKnownResult;
|
|
4032
|
+
for (let i = 0; i < statusPollCount; i++) {
|
|
4033
|
+
lastKnownResult = yield getTransactionStatus(txRID);
|
|
4034
|
+
if (lastKnownResult.status === exports.ResponseStatus.Confirmed) {
|
|
4035
|
+
return exports.ResponseStatus.Confirmed;
|
|
3844
4036
|
}
|
|
3845
|
-
|
|
3846
|
-
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
else {
|
|
3850
|
-
setTimeout(() => this.waitConfirmation(txRID).then(resolve, reject), 1011);
|
|
3851
|
-
}
|
|
3852
|
-
});
|
|
3853
|
-
});
|
|
3854
|
-
},
|
|
3855
|
-
getEndpointPool() {
|
|
3856
|
-
return getUrlsFromEndpoints(this.config.endpointPool);
|
|
3857
|
-
},
|
|
3858
|
-
};
|
|
3859
|
-
}
|
|
3860
|
-
function validateInput(endpointPool, failOverConfig) {
|
|
3861
|
-
if (!endpointPool.length) {
|
|
3862
|
-
throw new EmptyListOfUrlsException();
|
|
3863
|
-
}
|
|
3864
|
-
if ((failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptsPerEndpoint) &&
|
|
3865
|
-
failOverConfig.attemptsPerEndpoint < 1) {
|
|
3866
|
-
debug("Attempts can not be 0 or below, setting it to 1");
|
|
3867
|
-
failOverConfig.attemptsPerEndpoint = 1;
|
|
3868
|
-
}
|
|
3869
|
-
}
|
|
3870
|
-
/**
|
|
3871
|
-
* @param error response error
|
|
3872
|
-
* @param statusCode response status code
|
|
3873
|
-
* @param responseObject the responsebody from the server
|
|
3874
|
-
* @param callback the callback function to propagate the error and response back to the caller
|
|
3875
|
-
*/
|
|
3876
|
-
function handleGetResponse(error$1, statusCode, responseObject, callback) {
|
|
3877
|
-
try {
|
|
3878
|
-
const responseObjectPrintable = convertToPrintable(responseObject);
|
|
3879
|
-
debug(`error: ${error$1}, status code: ${statusCode}, response body: ${responseObjectPrintable}`);
|
|
3880
|
-
if (error$1) {
|
|
3881
|
-
return callback(error$1, null);
|
|
4037
|
+
else if (lastKnownResult.status === exports.ResponseStatus.Rejected) {
|
|
4038
|
+
throw new TxRejectedError((_a = lastKnownResult.rejectReason) !== null && _a !== void 0 ? _a : "");
|
|
4039
|
+
}
|
|
4040
|
+
yield sleep(statusPollInterval);
|
|
3882
4041
|
}
|
|
3883
|
-
|
|
3884
|
-
|
|
4042
|
+
// TS issue. This could be fixed by implementing new retry strategy
|
|
4043
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4044
|
+
//@ts-expect-error
|
|
4045
|
+
return lastKnownResult.status;
|
|
4046
|
+
});
|
|
4047
|
+
}
|
|
4048
|
+
function awaitClusterAnchoringChainConfirmation(txRID, statusPollInterval, statusPollCount, getClusterAnchoringTransactionConfirmation) {
|
|
4049
|
+
var _a;
|
|
4050
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4051
|
+
let clusterAnchoringConfirmation;
|
|
4052
|
+
for (let i = 0; i < statusPollCount; i++) {
|
|
4053
|
+
clusterAnchoringConfirmation = yield getClusterAnchoringTransactionConfirmation(txRID);
|
|
4054
|
+
const anchoringTransactionValidaiton = AnchoringTransactionSchema.safeParse(clusterAnchoringConfirmation);
|
|
4055
|
+
if (anchoringTransactionValidaiton.success) {
|
|
4056
|
+
return {
|
|
4057
|
+
status: exports.AnchoringStatus.ClusterAnchored,
|
|
4058
|
+
clusterAnchoredTx: anchoringTransactionValidaiton.data,
|
|
4059
|
+
};
|
|
4060
|
+
}
|
|
4061
|
+
else if (!anchoringTransactionValidaiton.success) {
|
|
4062
|
+
throw new TxRejectedError((_a = exports.AnchoringStatus.FailedAnchoring) !== null && _a !== void 0 ? _a : "");
|
|
4063
|
+
}
|
|
4064
|
+
yield sleep(statusPollInterval);
|
|
3885
4065
|
}
|
|
3886
|
-
|
|
3887
|
-
|
|
3888
|
-
|
|
3889
|
-
|
|
3890
|
-
|
|
3891
|
-
}
|
|
4066
|
+
// TS issue. This could be fixed by implementing new retry strategy
|
|
4067
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
4068
|
+
//@ts-expect-error
|
|
4069
|
+
return clusterAnchoringConfirmation;
|
|
4070
|
+
});
|
|
3892
4071
|
}
|
|
3893
|
-
|
|
3894
|
-
|
|
3895
|
-
|
|
3896
|
-
|
|
3897
|
-
|
|
3898
|
-
|
|
3899
|
-
|
|
3900
|
-
|
|
3901
|
-
|
|
3902
|
-
|
|
3903
|
-
if (error$1) {
|
|
3904
|
-
error(`In restclient post(). ${error$1}`);
|
|
3905
|
-
callback(error$1, null);
|
|
4072
|
+
function handleTransactionConfirmations(transactionRid, doStatusPolling, confirmationLevel, promiEvent, statusCode, statusPollInterval, statusPollCount, getTransactionStatus, getClusterAnchoringTransactionConfirmation, getSystemAnchoringTransactionConfirmation) {
|
|
4073
|
+
return __awaiter$4(this, void 0, void 0, function* () {
|
|
4074
|
+
const transactionReceipt = {
|
|
4075
|
+
status: exports.ResponseStatus.Waiting,
|
|
4076
|
+
statusCode: statusCode,
|
|
4077
|
+
transactionRid: transactionRid,
|
|
4078
|
+
};
|
|
4079
|
+
promiEvent.emit("sent", transactionReceipt);
|
|
4080
|
+
if (doStatusPolling === false || confirmationLevel === exports.ChainConfirmationLevel.None) {
|
|
4081
|
+
return transactionReceipt;
|
|
3906
4082
|
}
|
|
3907
|
-
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
error(errorMessage);
|
|
3913
|
-
callback(new UnexpectedStatusError(statusCode !== null && statusCode !== void 0 ? statusCode : 400, responseObjectPrintable), responseObject);
|
|
4083
|
+
const dappConfirmationStatus = yield awaitDappConfirmation(transactionRid, statusPollInterval, statusPollCount, getTransactionStatus);
|
|
4084
|
+
transactionReceipt.status = dappConfirmationStatus;
|
|
4085
|
+
promiEvent.emit("sent", transactionReceipt);
|
|
4086
|
+
if (confirmationLevel === exports.ChainConfirmationLevel.Dapp) {
|
|
4087
|
+
return transactionReceipt;
|
|
3914
4088
|
}
|
|
3915
|
-
|
|
3916
|
-
|
|
3917
|
-
|
|
4089
|
+
const clusterAnchoringChainConfirmation = yield awaitClusterAnchoringChainConfirmation(transactionRid, statusPollInterval, statusPollCount, getClusterAnchoringTransactionConfirmation);
|
|
4090
|
+
transactionReceipt.status = clusterAnchoringChainConfirmation.status;
|
|
4091
|
+
transactionReceipt["clusterAnchoredTx"] = clusterAnchoringChainConfirmation.clusterAnchoredTx;
|
|
4092
|
+
promiEvent.emit("sent", transactionReceipt);
|
|
4093
|
+
if (confirmationLevel === exports.ChainConfirmationLevel.ClusterAnchoring) {
|
|
4094
|
+
return transactionReceipt;
|
|
3918
4095
|
}
|
|
3919
|
-
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
4096
|
+
const systemAnchoringConfirmation = yield getSystemAnchoringTransactionConfirmation(clusterAnchoringChainConfirmation.clusterAnchoredTx.txRid);
|
|
4097
|
+
if (!systemAnchoringConfirmation) {
|
|
4098
|
+
return transactionReceipt;
|
|
4099
|
+
}
|
|
4100
|
+
transactionReceipt.status = exports.AnchoringStatus.SystemAnchored;
|
|
4101
|
+
transactionReceipt["systemAnchoredTx"] = systemAnchoringConfirmation;
|
|
4102
|
+
promiEvent.emit("sent", transactionReceipt);
|
|
4103
|
+
if (confirmationLevel === exports.ChainConfirmationLevel.SystemAnchoring) {
|
|
4104
|
+
return transactionReceipt;
|
|
4105
|
+
}
|
|
4106
|
+
return transactionReceipt;
|
|
4107
|
+
});
|
|
3923
4108
|
}
|
|
3924
4109
|
|
|
3925
|
-
var
|
|
3926
|
-
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3930
|
-
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
|
|
3934
|
-
|
|
3935
|
-
|
|
3936
|
-
|
|
3937
|
-
|
|
3938
|
-
|
|
3939
|
-
|
|
3940
|
-
|
|
3941
|
-
|
|
3942
|
-
|
|
3943
|
-
|
|
3944
|
-
|
|
3945
|
-
|
|
3946
|
-
|
|
3947
|
-
|
|
3948
|
-
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
var right = calculateRoot(hashes.slice(maxLeavesPerChild), depth + 1, leafDepth);
|
|
3957
|
-
return hashConcat([prefix, left, prefix, right]);
|
|
4110
|
+
var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4111
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4112
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4113
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
4114
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
4115
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
4116
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
4117
|
+
});
|
|
4118
|
+
};
|
|
4119
|
+
function getBlockchainRidFromIid({ endpointPool, chainId, failOverConfig = {}, nodeManager, }) {
|
|
4120
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
4121
|
+
const mergedFailOverConfig = Object.assign(Object.assign({}, defaultFailoverConfig), failOverConfig);
|
|
4122
|
+
const config = {
|
|
4123
|
+
endpointPool,
|
|
4124
|
+
statusPollInterval: 500,
|
|
4125
|
+
nodeManager,
|
|
4126
|
+
statusPollCount: 20,
|
|
4127
|
+
failoverStrategy: mergedFailOverConfig.strategy,
|
|
4128
|
+
attemptsPerEndpoint: mergedFailOverConfig.attemptsPerEndpoint,
|
|
4129
|
+
attemptInterval: mergedFailOverConfig.attemptInterval,
|
|
4130
|
+
unreachableDuration: mergedFailOverConfig.unreachableDuration,
|
|
4131
|
+
};
|
|
4132
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `/brid/iid_${chainId}`, config);
|
|
4133
|
+
if (error) {
|
|
4134
|
+
throw new GetBridFromChainException(chainId, error.message);
|
|
4135
|
+
}
|
|
4136
|
+
else if (statusCode !== 200) {
|
|
4137
|
+
throw new GetBridFromChainException(chainId, rspBody);
|
|
4138
|
+
}
|
|
4139
|
+
return rspBody;
|
|
4140
|
+
});
|
|
3958
4141
|
}
|
|
3959
|
-
function
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
path.push({ side: 1, hash: nonExistingNodeHash });
|
|
3968
|
-
return path;
|
|
3969
|
-
}
|
|
3970
|
-
if (targetIndex < maxLeavesPerChild) {
|
|
3971
|
-
var path = internalMerklePath(hashes.slice(0, maxLeavesPerChild), targetIndex, depth + 1, leafDepth);
|
|
3972
|
-
var right = calculateRoot(hashes.slice(maxLeavesPerChild), depth + 1, leafDepth);
|
|
3973
|
-
path.push({ side: 1, hash: right });
|
|
3974
|
-
}
|
|
3975
|
-
else {
|
|
3976
|
-
var left = calculateRoot(hashes.slice(0, maxLeavesPerChild), depth + 1, leafDepth);
|
|
3977
|
-
var path = internalMerklePath(hashes.slice(maxLeavesPerChild), targetIndex - maxLeavesPerChild, depth + 1, leafDepth);
|
|
3978
|
-
path.push({ side: 0, hash: left });
|
|
3979
|
-
}
|
|
3980
|
-
return path;
|
|
4142
|
+
function createTimeoutPromise(timeoutMs) {
|
|
4143
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
4144
|
+
return new Promise((_, reject) => {
|
|
4145
|
+
setTimeout(() => {
|
|
4146
|
+
reject(new Error("Timeout exceeded"));
|
|
4147
|
+
}, timeoutMs);
|
|
4148
|
+
});
|
|
4149
|
+
});
|
|
3981
4150
|
}
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
* {side: <0|1>, hash: <hash buffer depth 1>}]}
|
|
3988
|
-
*/
|
|
3989
|
-
function merklePath(hashes, target) {
|
|
3990
|
-
if (!hashes || hashes.length == 0) {
|
|
3991
|
-
throw new Error("Cannot make merkle path from empty transaction set");
|
|
3992
|
-
}
|
|
3993
|
-
var index = -1;
|
|
3994
|
-
for (var i = 0; i < hashes.length; i++) {
|
|
3995
|
-
if (hashes[i].equals(target)) {
|
|
3996
|
-
index = i;
|
|
3997
|
-
break;
|
|
3998
|
-
}
|
|
3999
|
-
}
|
|
4000
|
-
if (index === -1) {
|
|
4001
|
-
throw new Error("Target is not in list of hashes");
|
|
4151
|
+
const checkStateOfPromises = (promises) => __awaiter$3(void 0, void 0, void 0, function* () {
|
|
4152
|
+
const promiseList = [];
|
|
4153
|
+
const pendingState = { status: "pending" };
|
|
4154
|
+
for (const p of promises) {
|
|
4155
|
+
promiseList.push(yield Promise.race([p, pendingState]).then(value => value === pendingState ? Object.assign(Object.assign({}, pendingState), { value: p }) : { status: "fulfilled", value }, reason => ({ status: "rejected", value: reason })));
|
|
4002
4156
|
}
|
|
4003
|
-
|
|
4004
|
-
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
|
|
4009
|
-
|
|
4010
|
-
|
|
4011
|
-
|
|
4012
|
-
|
|
4013
|
-
|
|
4014
|
-
|
|
4015
|
-
|
|
4016
|
-
|
|
4017
|
-
* The merkle root is typically taken from a block header.
|
|
4018
|
-
*/
|
|
4019
|
-
function validateMerklePath(path, target, merkleRoot) {
|
|
4020
|
-
let currentHash = target;
|
|
4021
|
-
for (let i = 0; i < path.length; i++) {
|
|
4022
|
-
const item = path[i];
|
|
4023
|
-
const prefix = (i === 0) ? require$$0$1.Buffer.from([1]) : require$$0$1.Buffer.from([0]);
|
|
4024
|
-
if (item.side === 0) {
|
|
4025
|
-
currentHash = hashConcat([prefix, item.hash, prefix, currentHash]);
|
|
4157
|
+
return promiseList;
|
|
4158
|
+
});
|
|
4159
|
+
function racePromisesWithTimeout(promises, timeout) {
|
|
4160
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
4161
|
+
let remainingPromises = [];
|
|
4162
|
+
try {
|
|
4163
|
+
const resolvedPromise = yield Promise.race([createTimeoutPromise(timeout), ...promises]);
|
|
4164
|
+
const promisesWithState = yield checkStateOfPromises(promises);
|
|
4165
|
+
const indexOfpromiseToRemove = promisesWithState.findIndex(p => JSON.stringify(p.value) === JSON.stringify(resolvedPromise));
|
|
4166
|
+
// Remove the promise that resolved from the list of promises
|
|
4167
|
+
promisesWithState.splice(indexOfpromiseToRemove, 1);
|
|
4168
|
+
// Remove the state before returning the promises.
|
|
4169
|
+
remainingPromises = promisesWithState.map(p => p.value);
|
|
4170
|
+
return remainingPromises;
|
|
4026
4171
|
}
|
|
4027
|
-
|
|
4028
|
-
if (
|
|
4029
|
-
|
|
4030
|
-
}
|
|
4031
|
-
else {
|
|
4032
|
-
currentHash = hashConcat([prefix, currentHash, prefix, item.hash]);
|
|
4172
|
+
catch (error) {
|
|
4173
|
+
if (error instanceof Error && error.message === "Timeout exceeded") {
|
|
4174
|
+
throw error;
|
|
4033
4175
|
}
|
|
4176
|
+
return remainingPromises;
|
|
4177
|
+
}
|
|
4178
|
+
});
|
|
4179
|
+
}
|
|
4180
|
+
const stableStringify = (obj) => JSON.stringify(obj, Object.keys(obj).sort());
|
|
4181
|
+
const groupResponses = (responses) => {
|
|
4182
|
+
const responseMap = responses.reduce((acc, response) => {
|
|
4183
|
+
const key = stableStringify(response.result);
|
|
4184
|
+
acc[key] = acc[key]
|
|
4185
|
+
? { response: acc[key].response, count: acc[key].count + 1 }
|
|
4186
|
+
: { response, count: 1 };
|
|
4187
|
+
return acc;
|
|
4188
|
+
}, {});
|
|
4189
|
+
const distinctResponses = Object.values(responseMap).sort((a, b) => b.count - a.count);
|
|
4190
|
+
// Returns the count of the most common response
|
|
4191
|
+
const maxNumberOfEqualResponses = () => {
|
|
4192
|
+
return distinctResponses.length > 0 ? distinctResponses[0].count : 0;
|
|
4193
|
+
};
|
|
4194
|
+
// Returns the number of distinct responses
|
|
4195
|
+
const numberOfDistinctResponses = () => {
|
|
4196
|
+
return distinctResponses.length;
|
|
4197
|
+
};
|
|
4198
|
+
// Returns the most common response
|
|
4199
|
+
const majorityResponse = () => {
|
|
4200
|
+
return distinctResponses[0].response.result;
|
|
4201
|
+
};
|
|
4202
|
+
return {
|
|
4203
|
+
maxNumberOfEqualResponses,
|
|
4204
|
+
numberOfDistinctResponses,
|
|
4205
|
+
majorityResponse,
|
|
4206
|
+
};
|
|
4207
|
+
};
|
|
4208
|
+
function requestWithFailoverStrategy(method, path, config, postObject, forceSingleEndpoint = false) {
|
|
4209
|
+
return __awaiter$3(this, void 0, void 0, function* () {
|
|
4210
|
+
switch (config.failoverStrategy) {
|
|
4211
|
+
case exports.FailoverStrategy.AbortOnError:
|
|
4212
|
+
return yield abortOnError({ method, path, config, postObject });
|
|
4213
|
+
case exports.FailoverStrategy.TryNextOnError:
|
|
4214
|
+
return yield tryNextOnError({ method, path, config, postObject });
|
|
4215
|
+
case exports.FailoverStrategy.SingleEndpoint:
|
|
4216
|
+
return yield singleEndpoint({ method, path, config, postObject });
|
|
4217
|
+
case exports.FailoverStrategy.QueryMajority:
|
|
4218
|
+
if (forceSingleEndpoint) {
|
|
4219
|
+
return yield singleEndpoint({ method, path, config, postObject });
|
|
4220
|
+
}
|
|
4221
|
+
return yield queryMajority({ method, path, config, postObject });
|
|
4034
4222
|
}
|
|
4223
|
+
});
|
|
4224
|
+
}
|
|
4225
|
+
const sleep = (ms) => new Promise(r => setTimeout(r, ms));
|
|
4226
|
+
function convertToPrintable(responseObject) {
|
|
4227
|
+
if (typeof responseObject === "bigint") {
|
|
4228
|
+
return `${responseObject}n`;
|
|
4229
|
+
}
|
|
4230
|
+
else if (typeof responseObject === "object") {
|
|
4231
|
+
return JSON.stringify(responseObject, (key, value) => typeof value === "bigint" ? `${value}n` : value);
|
|
4232
|
+
}
|
|
4233
|
+
else {
|
|
4234
|
+
return responseObject;
|
|
4035
4235
|
}
|
|
4036
|
-
return merkleRoot.equals(currentHash);
|
|
4037
4236
|
}
|
|
4237
|
+
const bftMajority = (n) => n - (n - 1) / 3;
|
|
4038
4238
|
|
|
4039
|
-
var
|
|
4239
|
+
var restclientutil = /*#__PURE__*/Object.freeze({
|
|
4040
4240
|
__proto__: null,
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4241
|
+
bftMajority: bftMajority,
|
|
4242
|
+
checkStateOfPromises: checkStateOfPromises,
|
|
4243
|
+
convertToPrintable: convertToPrintable,
|
|
4244
|
+
createTimeoutPromise: createTimeoutPromise,
|
|
4245
|
+
getBlockchainRidFromIid: getBlockchainRidFromIid,
|
|
4246
|
+
groupResponses: groupResponses,
|
|
4247
|
+
racePromisesWithTimeout: racePromisesWithTimeout,
|
|
4248
|
+
requestWithFailoverStrategy: requestWithFailoverStrategy,
|
|
4249
|
+
sleep: sleep
|
|
4044
4250
|
});
|
|
4045
4251
|
|
|
4046
|
-
var __awaiter$
|
|
4252
|
+
var __awaiter$2 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4047
4253
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4048
4254
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4049
4255
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -4052,309 +4258,306 @@ var __awaiter$3 = (undefined && undefined.__awaiter) || function (thisArg, _argu
|
|
|
4052
4258
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
4053
4259
|
});
|
|
4054
4260
|
};
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
* Provides postchain clients that can be used to communicate with dapps within the chromia network
|
|
4058
|
-
* @param chain0BRID brid of chain0
|
|
4059
|
-
* @param rest rest client configured to node running chain0
|
|
4060
|
-
*/
|
|
4061
|
-
function chromiaClientProvider(chain0BRID, rest) {
|
|
4062
|
-
const chain0Client = createClient$1(rest, chain0BRID, []);
|
|
4261
|
+
function createRestClient(endpointPool, blockchainRid, maxSockets = 10, pollingInterval = 500, failOverConfig, unreachableDuration = 5000, useStickyNode = false) {
|
|
4262
|
+
validateInput(endpointPool, failOverConfig !== null && failOverConfig !== void 0 ? failOverConfig : {});
|
|
4063
4263
|
return {
|
|
4064
|
-
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4071
|
-
|
|
4072
|
-
|
|
4264
|
+
config: {
|
|
4265
|
+
nodeManager: createNodeManager({
|
|
4266
|
+
nodeUrls: endpointPool,
|
|
4267
|
+
useStickyNode,
|
|
4268
|
+
}),
|
|
4269
|
+
endpointPool: createEndpointObjects(endpointPool),
|
|
4270
|
+
pool: { maxSockets },
|
|
4271
|
+
pollingInterval,
|
|
4272
|
+
failoverStrategy: (failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.strategy) || exports.FailoverStrategy.AbortOnError,
|
|
4273
|
+
attemptsPerEndpoint: (failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptsPerEndpoint) || 3,
|
|
4274
|
+
attemptInterval: (failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptInterval) || 500,
|
|
4275
|
+
unreachableDuration: unreachableDuration,
|
|
4276
|
+
},
|
|
4277
|
+
getTransaction: function (txRID, callback) {
|
|
4278
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
4279
|
+
if (!isTxRidValid(txRID)) {
|
|
4280
|
+
callback(new InvalidTxRidException(txRID), null);
|
|
4281
|
+
}
|
|
4282
|
+
else {
|
|
4283
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `tx/${blockchainRid}/${txRID.toString("hex")}`, this.config);
|
|
4284
|
+
handleGetResponse(error, statusCode, statusCode === 200 ? toBuffer(rspBody.tx) : rspBody, callback);
|
|
4073
4285
|
}
|
|
4074
|
-
return createRestClient(baseUrls, dappBRID);
|
|
4075
4286
|
});
|
|
4076
4287
|
},
|
|
4077
|
-
|
|
4078
|
-
|
|
4079
|
-
|
|
4080
|
-
|
|
4081
|
-
|
|
4082
|
-
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4137
|
-
|
|
4138
|
-
|
|
4139
|
-
|
|
4140
|
-
throw new Error("getTransactionRid error");
|
|
4141
|
-
},
|
|
4142
|
-
getTransactionsInfo() {
|
|
4143
|
-
return __awaiter$2(this, void 0, void 0, function* () {
|
|
4144
|
-
return Promise.reject("getTransactionsInfo rejected");
|
|
4145
|
-
});
|
|
4146
|
-
},
|
|
4147
|
-
getTransactionInfo() {
|
|
4148
|
-
return __awaiter$2(this, void 0, void 0, function* () {
|
|
4149
|
-
return Promise.reject("getTransactionInfo rejected");
|
|
4150
|
-
});
|
|
4151
|
-
},
|
|
4152
|
-
getTransactionCount() {
|
|
4153
|
-
return __awaiter$2(this, void 0, void 0, function* () {
|
|
4154
|
-
return Promise.reject("getTransactionCount rejected");
|
|
4155
|
-
});
|
|
4156
|
-
},
|
|
4157
|
-
getBlocks() {
|
|
4158
|
-
return __awaiter$2(this, void 0, void 0, function* () {
|
|
4159
|
-
return Promise.reject("getBlockInfo rejected");
|
|
4160
|
-
});
|
|
4161
|
-
},
|
|
4162
|
-
getBlockInfo() {
|
|
4163
|
-
return __awaiter$2(this, void 0, void 0, function* () {
|
|
4164
|
-
return Promise.reject("getBlockInfo rejected");
|
|
4165
|
-
});
|
|
4166
|
-
},
|
|
4167
|
-
getLatestBlock() {
|
|
4168
|
-
return __awaiter$2(this, void 0, void 0, function* () {
|
|
4169
|
-
return Promise.reject("getLatestBlock rejected");
|
|
4170
|
-
});
|
|
4171
|
-
},
|
|
4172
|
-
getBlocksInfo() {
|
|
4173
|
-
return __awaiter$2(this, void 0, void 0, function* () {
|
|
4174
|
-
return Promise.reject("getBlocksInfo rejected");
|
|
4288
|
+
postTransaction: function (serializedTransaction, callback) {
|
|
4289
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
4290
|
+
if (!require$$0$1.Buffer.isBuffer(serializedTransaction)) {
|
|
4291
|
+
throw new SerializedTransactionFormatException();
|
|
4292
|
+
}
|
|
4293
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.POST, `tx/${blockchainRid}`, this.config, serializedTransaction);
|
|
4294
|
+
handlePostResponse(error, statusCode, rspBody, callback);
|
|
4295
|
+
});
|
|
4296
|
+
},
|
|
4297
|
+
status: function (txRID, callback) {
|
|
4298
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
4299
|
+
if (!isTxRidValid(txRID)) {
|
|
4300
|
+
callback(new InvalidTxRidException(txRID), null);
|
|
4301
|
+
}
|
|
4302
|
+
else {
|
|
4303
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.GET, `tx/${blockchainRid}/${txRID.toString("hex")}/status`, this.config);
|
|
4304
|
+
handleGetResponse(error, statusCode, rspBody, callback);
|
|
4305
|
+
}
|
|
4306
|
+
});
|
|
4307
|
+
},
|
|
4308
|
+
query: function (nameOrQueryObject, queryArguments) {
|
|
4309
|
+
return __awaiter$2(this, void 0, void 0, function* () {
|
|
4310
|
+
// eslint-disable-next-line no-async-promise-executor
|
|
4311
|
+
return new Promise((resolve, reject) => __awaiter$2(this, void 0, void 0, function* () {
|
|
4312
|
+
const callback = (error, result) => {
|
|
4313
|
+
if (error) {
|
|
4314
|
+
reject(error);
|
|
4315
|
+
}
|
|
4316
|
+
else {
|
|
4317
|
+
resolve(result);
|
|
4318
|
+
}
|
|
4319
|
+
};
|
|
4320
|
+
const { error, statusCode, rspBody } = yield requestWithFailoverStrategy(Method.POST, `query_gtv/${blockchainRid}`, this.config, encodeValue(toQueryObjectGTV(nameOrQueryObject, queryArguments)));
|
|
4321
|
+
handlePostResponse(error, statusCode, rspBody, callback);
|
|
4322
|
+
}));
|
|
4323
|
+
});
|
|
4324
|
+
},
|
|
4325
|
+
waitConfirmation(txRID) {
|
|
4326
|
+
return new Promise((resolve, reject) => {
|
|
4327
|
+
this.status(txRID, (error$1, result) => {
|
|
4328
|
+
if (error$1) {
|
|
4329
|
+
reject(error$1);
|
|
4330
|
+
}
|
|
4331
|
+
else {
|
|
4332
|
+
const status = result.status;
|
|
4333
|
+
switch (status) {
|
|
4334
|
+
case exports.ResponseStatus.Confirmed:
|
|
4335
|
+
resolve(null);
|
|
4336
|
+
break;
|
|
4337
|
+
case exports.ResponseStatus.Rejected:
|
|
4338
|
+
reject(new TxRejectedError(result.rejectReason));
|
|
4339
|
+
break;
|
|
4340
|
+
case exports.ResponseStatus.Unknown:
|
|
4341
|
+
reject(new LostMessageError());
|
|
4342
|
+
break;
|
|
4343
|
+
case exports.ResponseStatus.Waiting:
|
|
4344
|
+
setTimeout(() => this.waitConfirmation(txRID).then(resolve, reject), this.config.pollingInterval);
|
|
4345
|
+
break;
|
|
4346
|
+
default:
|
|
4347
|
+
error(status);
|
|
4348
|
+
reject(new UnexpectedResponseError());
|
|
4349
|
+
}
|
|
4350
|
+
}
|
|
4175
4351
|
});
|
|
4176
|
-
}
|
|
4177
|
-
|
|
4178
|
-
|
|
4179
|
-
|
|
4180
|
-
|
|
4181
|
-
|
|
4182
|
-
|
|
4183
|
-
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
|
|
4188
|
-
|
|
4352
|
+
});
|
|
4353
|
+
},
|
|
4354
|
+
postAndWaitConfirmation(serializedTransaction, txRID, validate) {
|
|
4355
|
+
if (validate === true) {
|
|
4356
|
+
return Promise.reject("Automatic validation is not yet implemented");
|
|
4357
|
+
}
|
|
4358
|
+
return new Promise((resolve, reject) => {
|
|
4359
|
+
this.postTransaction(serializedTransaction, error => {
|
|
4360
|
+
if (error)
|
|
4361
|
+
reject(error);
|
|
4362
|
+
else {
|
|
4363
|
+
setTimeout(() => this.waitConfirmation(txRID)
|
|
4364
|
+
.then(() => resolve(null))
|
|
4365
|
+
.catch(reject), 1011);
|
|
4366
|
+
}
|
|
4189
4367
|
});
|
|
4190
|
-
}
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
}
|
|
4195
|
-
}
|
|
4196
|
-
}
|
|
4197
|
-
|
|
4198
|
-
class MissingTransactionProof extends Error {
|
|
4199
|
-
constructor(proofHash, fetchedTxHash) {
|
|
4200
|
-
super(`Unable to verify source transaction proof,transaction hash in proof ${toString(proofHash)} does not match hash from fetched transaction ${toString(fetchedTxHash)}`);
|
|
4201
|
-
}
|
|
4202
|
-
}
|
|
4203
|
-
class DifferentNumberOfSignersException extends Error {
|
|
4204
|
-
constructor(length, comparableLength) {
|
|
4205
|
-
super(`Transaction signatures amount ${length} do not match expected amount of signers ${comparableLength}`);
|
|
4206
|
-
}
|
|
4207
|
-
}
|
|
4208
|
-
class SignatureException extends Error {
|
|
4209
|
-
constructor(signer) {
|
|
4210
|
-
super(`Expected signer ${toString(signer)} has not signed source transaction`);
|
|
4211
|
-
}
|
|
4212
|
-
}
|
|
4213
|
-
class ProofRidException extends Error {
|
|
4214
|
-
constructor() {
|
|
4215
|
-
super("Unable to verify source transaction proof, got a different transaction from query than we asked for");
|
|
4216
|
-
}
|
|
4217
|
-
}
|
|
4218
|
-
class SystemChainException extends Error {
|
|
4219
|
-
constructor(errorMessage) {
|
|
4220
|
-
super(`Query to system chain failed with error: ${errorMessage}`);
|
|
4221
|
-
}
|
|
4368
|
+
});
|
|
4369
|
+
},
|
|
4370
|
+
getEndpointPool() {
|
|
4371
|
+
return getUrlsFromEndpoints(this.config.endpointPool);
|
|
4372
|
+
},
|
|
4373
|
+
};
|
|
4222
4374
|
}
|
|
4223
|
-
|
|
4224
|
-
|
|
4225
|
-
|
|
4375
|
+
function validateInput(endpointPool, failOverConfig) {
|
|
4376
|
+
if (!endpointPool.length) {
|
|
4377
|
+
throw new EmptyListOfUrlsException();
|
|
4226
4378
|
}
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
super(`Block is not present in cluster anchoring chain`);
|
|
4379
|
+
if ((failOverConfig === null || failOverConfig === void 0 ? void 0 : failOverConfig.attemptsPerEndpoint) && failOverConfig.attemptsPerEndpoint < 1) {
|
|
4380
|
+
debug("Attempts can not be 0 or below, setting it to 1");
|
|
4381
|
+
failOverConfig.attemptsPerEndpoint = 1;
|
|
4231
4382
|
}
|
|
4232
4383
|
}
|
|
4233
|
-
|
|
4234
|
-
|
|
4235
|
-
|
|
4236
|
-
|
|
4237
|
-
|
|
4238
|
-
|
|
4239
|
-
|
|
4240
|
-
|
|
4241
|
-
|
|
4242
|
-
};
|
|
4243
|
-
|
|
4244
|
-
|
|
4245
|
-
try {
|
|
4246
|
-
const clusterName = yield client.query({
|
|
4247
|
-
name: "cm_get_blockchain_cluster",
|
|
4248
|
-
args: { brid: blockchainRid },
|
|
4249
|
-
});
|
|
4250
|
-
return clusterName;
|
|
4384
|
+
/**
|
|
4385
|
+
* @param error response error
|
|
4386
|
+
* @param statusCode response status code
|
|
4387
|
+
* @param responseObject the responsebody from the server
|
|
4388
|
+
* @param callback the callback function to propagate the error and response back to the caller
|
|
4389
|
+
*/
|
|
4390
|
+
function handleGetResponse(error$1, statusCode, responseObject, callback) {
|
|
4391
|
+
try {
|
|
4392
|
+
const responseObjectPrintable = convertToPrintable(responseObject);
|
|
4393
|
+
debug(`error: ${error$1}, status code: ${statusCode}, response body: ${responseObjectPrintable}`);
|
|
4394
|
+
if (error$1) {
|
|
4395
|
+
return callback(error$1, null);
|
|
4251
4396
|
}
|
|
4252
|
-
|
|
4253
|
-
|
|
4397
|
+
if (statusCode !== 200) {
|
|
4398
|
+
return callback(new UnexpectedStatusError(statusCode !== null && statusCode !== void 0 ? statusCode : 400, responseObjectPrintable), null);
|
|
4254
4399
|
}
|
|
4255
|
-
|
|
4400
|
+
return callback(null, responseObject);
|
|
4401
|
+
}
|
|
4402
|
+
catch (error$1) {
|
|
4403
|
+
callback(error$1, null);
|
|
4404
|
+
error(`restclient.handleGetResponse(): Failed to call the callback function. ${error$1}`);
|
|
4405
|
+
}
|
|
4256
4406
|
}
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
|
|
4260
|
-
|
|
4261
|
-
|
|
4262
|
-
|
|
4263
|
-
|
|
4264
|
-
|
|
4265
|
-
|
|
4266
|
-
|
|
4267
|
-
|
|
4407
|
+
/**
|
|
4408
|
+
* @param error response error
|
|
4409
|
+
* @param statusCode response status code
|
|
4410
|
+
* @param responseObject the responsebody from the server
|
|
4411
|
+
* @param callback the callback function to propagate the error and response back to the caller
|
|
4412
|
+
*/
|
|
4413
|
+
function handlePostResponse(error$1, statusCode, responseObject, callback) {
|
|
4414
|
+
const responseObjectPrintable = convertToPrintable(responseObject);
|
|
4415
|
+
debug(`error: ${error$1}, status code: ${statusCode}, response body: ${responseObjectPrintable}`);
|
|
4416
|
+
try {
|
|
4417
|
+
if (error$1) {
|
|
4418
|
+
error(`In restclient post(). ${error$1}`);
|
|
4419
|
+
callback(error$1, null);
|
|
4268
4420
|
}
|
|
4269
|
-
|
|
4270
|
-
}
|
|
4271
|
-
|
|
4272
|
-
|
|
4273
|
-
|
|
4274
|
-
|
|
4275
|
-
|
|
4276
|
-
args: { blockchain_rid: blockchainRid, block_rid: blockRid },
|
|
4277
|
-
});
|
|
4278
|
-
return convertToAnchoringTransaction(anchoringTxForBlockRid);
|
|
4421
|
+
else if (statusCode != 200) {
|
|
4422
|
+
let errorMessage = `Unexpected status code from server. Code: ${statusCode}.`;
|
|
4423
|
+
if (responseObjectPrintable) {
|
|
4424
|
+
errorMessage += ` Message: ${responseObjectPrintable}.`;
|
|
4425
|
+
}
|
|
4426
|
+
error(errorMessage);
|
|
4427
|
+
callback(new UnexpectedStatusError(statusCode !== null && statusCode !== void 0 ? statusCode : 400, responseObjectPrintable), responseObject);
|
|
4279
4428
|
}
|
|
4280
|
-
|
|
4281
|
-
|
|
4429
|
+
else {
|
|
4430
|
+
info(`Calling responseCallback with responseObject: ${responseObjectPrintable}`);
|
|
4431
|
+
callback(null, responseObject);
|
|
4282
4432
|
}
|
|
4283
|
-
}
|
|
4433
|
+
}
|
|
4434
|
+
catch (error$1) {
|
|
4435
|
+
error(`restclient.handlePostResponse(): Failed to call callback function ${error$1}`);
|
|
4436
|
+
}
|
|
4284
4437
|
}
|
|
4285
|
-
|
|
4286
|
-
|
|
4287
|
-
|
|
4288
|
-
|
|
4289
|
-
|
|
4290
|
-
|
|
4291
|
-
|
|
4438
|
+
|
|
4439
|
+
var restclient = /*#__PURE__*/Object.freeze({
|
|
4440
|
+
__proto__: null,
|
|
4441
|
+
createRestClient: createRestClient,
|
|
4442
|
+
handleGetResponse: handleGetResponse,
|
|
4443
|
+
handlePostResponse: handlePostResponse
|
|
4444
|
+
});
|
|
4445
|
+
|
|
4446
|
+
var internalNodePrefix = require$$0$1.Buffer.alloc(1, 0);
|
|
4447
|
+
var leafPrefix = require$$0$1.Buffer.alloc(1, 1);
|
|
4448
|
+
var nonExistingNodeHash = require$$0$1.Buffer.alloc(32);
|
|
4449
|
+
function calculateRoot(hashes, depth, leafDepth) {
|
|
4450
|
+
var numTransactions = hashes.length;
|
|
4451
|
+
if (numTransactions === 0) {
|
|
4452
|
+
return require$$0$1.Buffer.alloc(32);
|
|
4453
|
+
}
|
|
4454
|
+
if (depth === undefined) {
|
|
4455
|
+
depth = 0;
|
|
4456
|
+
}
|
|
4457
|
+
if (!leafDepth) {
|
|
4458
|
+
leafDepth = Math.ceil(Math.log2(numTransactions));
|
|
4459
|
+
}
|
|
4460
|
+
if (depth === leafDepth) {
|
|
4461
|
+
return hashes[0];
|
|
4462
|
+
}
|
|
4463
|
+
var maxLeavesPerChild = Math.pow(2, leafDepth - depth - 1);
|
|
4464
|
+
var prefix = depth === leafDepth - 1 ? leafPrefix : internalNodePrefix;
|
|
4465
|
+
if (numTransactions <= maxLeavesPerChild) {
|
|
4466
|
+
var left = calculateRoot(hashes, depth + 1, leafDepth);
|
|
4467
|
+
return hashConcat([prefix, left, nonExistingNodeHash]);
|
|
4468
|
+
}
|
|
4469
|
+
var left = calculateRoot(hashes.slice(0, maxLeavesPerChild), depth + 1, leafDepth);
|
|
4470
|
+
var right = calculateRoot(hashes.slice(maxLeavesPerChild), depth + 1, leafDepth);
|
|
4471
|
+
return hashConcat([prefix, left, prefix, right]);
|
|
4292
4472
|
}
|
|
4293
|
-
function
|
|
4294
|
-
|
|
4295
|
-
if (
|
|
4296
|
-
|
|
4473
|
+
function internalMerklePath(hashes, targetIndex, depth, leafDepth) {
|
|
4474
|
+
var numTransactions = hashes.length;
|
|
4475
|
+
if (depth === leafDepth) {
|
|
4476
|
+
return [];
|
|
4297
4477
|
}
|
|
4298
|
-
|
|
4299
|
-
|
|
4478
|
+
var maxLeavesPerChild = Math.pow(2, leafDepth - depth - 1);
|
|
4479
|
+
if (numTransactions <= maxLeavesPerChild) {
|
|
4480
|
+
var path = internalMerklePath(hashes, targetIndex, depth + 1, leafDepth);
|
|
4481
|
+
path.push({ side: 1, hash: nonExistingNodeHash });
|
|
4482
|
+
return path;
|
|
4483
|
+
}
|
|
4484
|
+
if (targetIndex < maxLeavesPerChild) {
|
|
4485
|
+
var path = internalMerklePath(hashes.slice(0, maxLeavesPerChild), targetIndex, depth + 1, leafDepth);
|
|
4486
|
+
var right = calculateRoot(hashes.slice(maxLeavesPerChild), depth + 1, leafDepth);
|
|
4487
|
+
path.push({ side: 1, hash: right });
|
|
4488
|
+
}
|
|
4489
|
+
else {
|
|
4490
|
+
var left = calculateRoot(hashes.slice(0, maxLeavesPerChild), depth + 1, leafDepth);
|
|
4491
|
+
var path = internalMerklePath(hashes.slice(maxLeavesPerChild), targetIndex - maxLeavesPerChild, depth + 1, leafDepth);
|
|
4492
|
+
path.push({ side: 0, hash: left });
|
|
4493
|
+
}
|
|
4494
|
+
return path;
|
|
4300
4495
|
}
|
|
4301
|
-
|
|
4302
|
-
|
|
4303
|
-
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
if (
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
const txRID = getDigestToSign(fetchedTx);
|
|
4318
|
-
if (Buffer.compare(txRID, txToProveRID)) {
|
|
4319
|
-
throw new ProofRidException();
|
|
4320
|
-
}
|
|
4321
|
-
for (const signer of txToProveSigners) {
|
|
4322
|
-
let hasSignature = false;
|
|
4323
|
-
for (const signature of fetchedTx.signatures) {
|
|
4324
|
-
// verify that txRID (hash of gtxBody) signed by signers equals the signatures from network
|
|
4325
|
-
if (checkDigestSignature(txRID, signer, signature)) {
|
|
4326
|
-
hasSignature = true;
|
|
4327
|
-
break;
|
|
4328
|
-
}
|
|
4329
|
-
}
|
|
4330
|
-
if (!hasSignature)
|
|
4331
|
-
throw new SignatureException(signer);
|
|
4496
|
+
/*
|
|
4497
|
+
* a path looks like this:
|
|
4498
|
+
* {merklePath: [{side: <0|1>, hash: <hash buffer depth n-1>},
|
|
4499
|
+
* {side: <0|1>, hash: <hash buffer depth n-2>},
|
|
4500
|
+
* ...
|
|
4501
|
+
* {side: <0|1>, hash: <hash buffer depth 1>}]}
|
|
4502
|
+
*/
|
|
4503
|
+
function merklePath(hashes, target) {
|
|
4504
|
+
if (!hashes || hashes.length == 0) {
|
|
4505
|
+
throw new Error("Cannot make merkle path from empty transaction set");
|
|
4506
|
+
}
|
|
4507
|
+
var index = -1;
|
|
4508
|
+
for (var i = 0; i < hashes.length; i++) {
|
|
4509
|
+
if (hashes[i].equals(target)) {
|
|
4510
|
+
index = i;
|
|
4511
|
+
break;
|
|
4332
4512
|
}
|
|
4333
|
-
|
|
4334
|
-
|
|
4513
|
+
}
|
|
4514
|
+
if (index === -1) {
|
|
4515
|
+
throw new Error("Target is not in list of hashes");
|
|
4516
|
+
}
|
|
4517
|
+
var leafDepth = Math.ceil(Math.log2(hashes.length));
|
|
4518
|
+
var path = internalMerklePath(hashes, index, 0, leafDepth);
|
|
4519
|
+
return path;
|
|
4335
4520
|
}
|
|
4336
|
-
|
|
4337
|
-
|
|
4338
|
-
|
|
4339
|
-
|
|
4340
|
-
|
|
4341
|
-
|
|
4342
|
-
|
|
4343
|
-
|
|
4344
|
-
|
|
4521
|
+
/**
|
|
4522
|
+
*
|
|
4523
|
+
* @param path The merkle path to validate.
|
|
4524
|
+
* Format [{side: <0|1>, hash: <hash buffer depth n-1>},
|
|
4525
|
+
* {side: <0|1>, hash: <hash buffer depth n-2>},
|
|
4526
|
+
* ...,
|
|
4527
|
+
* {side: <0|1>, hash: <hash buffer depth 1>}]
|
|
4528
|
+
|
|
4529
|
+
* @param target the leaf hash that the path proves belongs in the merkleRoot
|
|
4530
|
+
* @param merkleRoot The merkle root that supposedly contains the target via the supplied path.
|
|
4531
|
+
* The merkle root is typically taken from a block header.
|
|
4532
|
+
*/
|
|
4533
|
+
function validateMerklePath(path, target, merkleRoot) {
|
|
4534
|
+
let currentHash = target;
|
|
4535
|
+
for (let i = 0; i < path.length; i++) {
|
|
4536
|
+
const item = path[i];
|
|
4537
|
+
const prefix = (i === 0) ? require$$0$1.Buffer.from([1]) : require$$0$1.Buffer.from([0]);
|
|
4538
|
+
if (item.side === 0) {
|
|
4539
|
+
currentHash = hashConcat([prefix, item.hash, prefix, currentHash]);
|
|
4540
|
+
}
|
|
4541
|
+
else {
|
|
4542
|
+
if (item.hash.equals(nonExistingNodeHash)) {
|
|
4543
|
+
currentHash = hashConcat([prefix, currentHash, nonExistingNodeHash]);
|
|
4544
|
+
}
|
|
4545
|
+
else {
|
|
4546
|
+
currentHash = hashConcat([prefix, currentHash, prefix, item.hash]);
|
|
4547
|
+
}
|
|
4548
|
+
}
|
|
4345
4549
|
}
|
|
4346
|
-
return
|
|
4347
|
-
operations: [
|
|
4348
|
-
{
|
|
4349
|
-
name: "iccf_proof",
|
|
4350
|
-
args: Object.values(operationArgs),
|
|
4351
|
-
},
|
|
4352
|
-
],
|
|
4353
|
-
signers: iccfTxSigners,
|
|
4354
|
-
};
|
|
4550
|
+
return merkleRoot.equals(currentHash);
|
|
4355
4551
|
}
|
|
4356
4552
|
|
|
4357
|
-
var
|
|
4553
|
+
var merkleHelper = /*#__PURE__*/Object.freeze({
|
|
4554
|
+
__proto__: null,
|
|
4555
|
+
calculateRoot: calculateRoot,
|
|
4556
|
+
merklePath: merklePath,
|
|
4557
|
+
validateMerklePath: validateMerklePath
|
|
4558
|
+
});
|
|
4559
|
+
|
|
4560
|
+
var __awaiter$1 = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4358
4561
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4359
4562
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4360
4563
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
@@ -4364,121 +4567,161 @@ var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _argume
|
|
|
4364
4567
|
});
|
|
4365
4568
|
};
|
|
4366
4569
|
/**
|
|
4367
|
-
*
|
|
4368
|
-
*
|
|
4369
|
-
*
|
|
4370
|
-
*
|
|
4371
|
-
* @param {IClient} client - The client configured to communicate with the management chain.
|
|
4372
|
-
* @param {Buffer} txToProveRid - The RID of the transaction to be proven.
|
|
4373
|
-
* @param {Buffer} txToProveHash - The hash of the transaction to be proven.
|
|
4374
|
-
* @param {PubKey[]} txToProveSigners - An array of public keys representing signers of the transaction to be proven.
|
|
4375
|
-
* @param {string} sourceBlockchainRid - The RID of the source blockchain.
|
|
4376
|
-
* @param {string} targetBlockchainRid - The RID of the target blockchain.
|
|
4377
|
-
* @param {PubKey[]} iccfTxSigners - An array of public keys representing signers of the ICCF proof transaction (optional, default: []).
|
|
4378
|
-
* @param {boolean} forceIntraNetworkIccfOperation - Whether to force the ICCF operation to be performed within the same network (optional, default: false).
|
|
4379
|
-
* @returns {Promise<IccfProof>} A promise that resolves to an ICCF proof object containing the ICCF proof transaction.
|
|
4380
|
-
*/
|
|
4381
|
-
function createIccfProofTx(client, txToProveRid, txToProveHash, txToProveSigners, sourceBlockchainRid, targetBlockchainRid, iccfTxSigners = [], forceIntraNetworkIccfOperation = false) {
|
|
4382
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
4383
|
-
const clientConfiguredToSource = yield createClient({
|
|
4384
|
-
directoryNodeUrlPool: getUrlsFromEndpoints(client.config.endpointPool),
|
|
4385
|
-
blockchainRid: sourceBlockchainRid,
|
|
4386
|
-
});
|
|
4387
|
-
const txProof = yield clientConfiguredToSource.getConfirmationProof(txToProveRid);
|
|
4388
|
-
if (!txProof || !txProof.hash) {
|
|
4389
|
-
throw new ConfirmationProofException(txToProveRid);
|
|
4390
|
-
}
|
|
4391
|
-
const proofHash = txProof.hash;
|
|
4392
|
-
const { verifiedTx, verifiedTxHash } = !txToProveHash.equals(proofHash)
|
|
4393
|
-
? yield fetchAndVerifyTransaction(clientConfiguredToSource, txToProveRid, proofHash, txToProveSigners)
|
|
4394
|
-
: { verifiedTx: null, verifiedTxHash: txToProveHash };
|
|
4395
|
-
const sourceCluster = yield getClusterOfBlockchain(client, toBuffer(sourceBlockchainRid));
|
|
4396
|
-
const targetCluster = yield getClusterOfBlockchain(client, toBuffer(targetBlockchainRid));
|
|
4397
|
-
if (!forceIntraNetworkIccfOperation && sourceCluster === targetCluster) {
|
|
4398
|
-
// intra-cluster
|
|
4399
|
-
const intraClusterProofTx = composeProofTransactionObject(sourceBlockchainRid, verifiedTxHash, txProof, iccfTxSigners, undefined, undefined, false);
|
|
4400
|
-
return { iccfTx: intraClusterProofTx };
|
|
4401
|
-
}
|
|
4402
|
-
else {
|
|
4403
|
-
// intra-network
|
|
4404
|
-
const anchoringClient = yield getAnchoringClient(client, sourceBlockchainRid, sourceCluster);
|
|
4405
|
-
const anchoringTx = yield getBlockAnchoringTransaction(clientConfiguredToSource, anchoringClient, undefined, txProof);
|
|
4406
|
-
const anchoringProof = yield anchoringClient.getConfirmationProof(anchoringTx.txRid);
|
|
4407
|
-
const intraNetworkProofTx = composeProofTransactionObject(sourceBlockchainRid, verifiedTxHash, txProof, iccfTxSigners, anchoringTx, anchoringProof);
|
|
4408
|
-
return { iccfTx: intraNetworkProofTx, verifiedTx };
|
|
4409
|
-
}
|
|
4410
|
-
});
|
|
4411
|
-
}
|
|
4412
|
-
/**
|
|
4413
|
-
* Checks whether a given transaction is included in the cluster anchoring chain and returns the
|
|
4414
|
-
* block anchoring transaction. If `txProof` is not provided, it fetches the confirmation proof
|
|
4415
|
-
* using the `sourceClient`.
|
|
4416
|
-
*
|
|
4417
|
-
* @param sourceClient - A client configured to the blockchain where the transaction was made.
|
|
4418
|
-
* @param anchoringClient - The client responsible for querying the anchoring blockchain.
|
|
4419
|
-
* @param txRid - The transaction RID to check for anchoring.
|
|
4420
|
-
* @param txProof - (Optional) The transaction proof for the specified `txRid`.
|
|
4421
|
-
* @returns A Promise that resolves to the anchored transaction response object.
|
|
4570
|
+
* @deprecated Use the function createClient instead.
|
|
4571
|
+
* Provides postchain clients that can be used to communicate with dapps within the chromia network
|
|
4572
|
+
* @param chain0BRID brid of chain0
|
|
4573
|
+
* @param rest rest client configured to node running chain0
|
|
4422
4574
|
*/
|
|
4423
|
-
function
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
4428
|
-
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
|
|
4432
|
-
|
|
4433
|
-
|
|
4434
|
-
|
|
4435
|
-
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
}
|
|
4575
|
+
function chromiaClientProvider(chain0BRID, rest) {
|
|
4576
|
+
const chain0Client = createClient$1(rest, chain0BRID, []);
|
|
4577
|
+
return {
|
|
4578
|
+
blockchainConnection: function (dappBRID) {
|
|
4579
|
+
return __awaiter$1(this, void 0, void 0, function* () {
|
|
4580
|
+
const queryObject = {
|
|
4581
|
+
type: "cm_get_blockchain_api_urls",
|
|
4582
|
+
blockchain_rid: dappBRID,
|
|
4583
|
+
};
|
|
4584
|
+
const baseUrls = yield chain0Client.query(queryObject);
|
|
4585
|
+
if (!baseUrls.length) {
|
|
4586
|
+
throw new BlockchainUrlUndefinedException(dappBRID);
|
|
4587
|
+
}
|
|
4588
|
+
return createRestClient(baseUrls, dappBRID);
|
|
4589
|
+
});
|
|
4590
|
+
},
|
|
4591
|
+
};
|
|
4440
4592
|
}
|
|
4441
|
-
|
|
4442
|
-
|
|
4443
|
-
|
|
4444
|
-
|
|
4445
|
-
|
|
4446
|
-
|
|
4447
|
-
|
|
4448
|
-
|
|
4449
|
-
|
|
4450
|
-
function
|
|
4451
|
-
|
|
4452
|
-
|
|
4593
|
+
|
|
4594
|
+
var chromiaClientProvider$1 = /*#__PURE__*/Object.freeze({
|
|
4595
|
+
__proto__: null,
|
|
4596
|
+
chromiaClientProvider: chromiaClientProvider
|
|
4597
|
+
});
|
|
4598
|
+
|
|
4599
|
+
var __awaiter = (undefined && undefined.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4600
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4601
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4602
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
4603
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
4604
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
4605
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
4453
4606
|
});
|
|
4454
|
-
}
|
|
4455
|
-
|
|
4456
|
-
* Gets a client configured for the cluster anchoring blockchain of a cluster. Takes a specific
|
|
4457
|
-
* cluster name or blockchain RID to determine the cluster.
|
|
4458
|
-
* @param client - The client configured to communicate with the management chain.
|
|
4459
|
-
* @param dappBlockchainRid - (Optional) The RID of a blockchain which anchoring wants to be checked.
|
|
4460
|
-
* @param cluster - (Optional) The cluster of interest.
|
|
4461
|
-
* @returns A Promise that resolves to the client configured to a cluster anchoring chain.
|
|
4462
|
-
*/
|
|
4463
|
-
function getAnchoringClient(client, dappBlockchainRid, cluster) {
|
|
4607
|
+
};
|
|
4608
|
+
function createStubClient() {
|
|
4464
4609
|
return __awaiter(this, void 0, void 0, function* () {
|
|
4465
|
-
|
|
4466
|
-
|
|
4467
|
-
|
|
4468
|
-
|
|
4469
|
-
|
|
4470
|
-
|
|
4471
|
-
|
|
4472
|
-
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4610
|
+
return {
|
|
4611
|
+
config: {
|
|
4612
|
+
nodeManager: createNodeManager({
|
|
4613
|
+
nodeUrls: [],
|
|
4614
|
+
}),
|
|
4615
|
+
endpointPool: [],
|
|
4616
|
+
blockchainRid: "0000000000000000000000000000000000000000000000000000000000000000",
|
|
4617
|
+
statusPollInterval: 5000,
|
|
4618
|
+
statusPollCount: 5,
|
|
4619
|
+
failoverStrategy: exports.FailoverStrategy.AbortOnError,
|
|
4620
|
+
attemptsPerEndpoint: 3,
|
|
4621
|
+
attemptInterval: 5000,
|
|
4622
|
+
unreachableDuration: 30000,
|
|
4623
|
+
directoryChainRid: "1111111111111111111111111111111111111111111111111111111111111111",
|
|
4624
|
+
},
|
|
4625
|
+
query() {
|
|
4626
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4627
|
+
return Promise.reject("query rejected");
|
|
4628
|
+
});
|
|
4629
|
+
},
|
|
4630
|
+
signTransaction() {
|
|
4631
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4632
|
+
return Promise.reject("signTransaction rejected");
|
|
4633
|
+
});
|
|
4634
|
+
},
|
|
4635
|
+
sendTransaction() {
|
|
4636
|
+
return new Web3PromiEvent((_resolve, reject) => reject("sendTransaction rejected"));
|
|
4637
|
+
},
|
|
4638
|
+
signAndSendUniqueTransaction() {
|
|
4639
|
+
return new Web3PromiEvent((_resolve, reject) => reject("signAndSendUniqueTransaction rejected"));
|
|
4640
|
+
},
|
|
4641
|
+
getTransaction() {
|
|
4642
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4643
|
+
return Promise.reject("getTransaction rejected");
|
|
4644
|
+
});
|
|
4645
|
+
},
|
|
4646
|
+
getTransactionStatus() {
|
|
4647
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4648
|
+
return Promise.reject("getTransactionStatus rejected");
|
|
4649
|
+
});
|
|
4650
|
+
},
|
|
4651
|
+
addNop() {
|
|
4652
|
+
throw new Error("addNop error");
|
|
4653
|
+
},
|
|
4654
|
+
getTransactionRid() {
|
|
4655
|
+
throw new Error("getTransactionRid error");
|
|
4656
|
+
},
|
|
4657
|
+
getTransactionsInfo() {
|
|
4658
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4659
|
+
return Promise.reject("getTransactionsInfo rejected");
|
|
4660
|
+
});
|
|
4661
|
+
},
|
|
4662
|
+
getTransactionInfo() {
|
|
4663
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4664
|
+
return Promise.reject("getTransactionInfo rejected");
|
|
4665
|
+
});
|
|
4666
|
+
},
|
|
4667
|
+
getTransactionConfirmationLevel() {
|
|
4668
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4669
|
+
return Promise.reject("getTransactionConfirmationLevel rejected");
|
|
4670
|
+
});
|
|
4671
|
+
},
|
|
4672
|
+
getTransactionCount() {
|
|
4673
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4674
|
+
return Promise.reject("getTransactionCount rejected");
|
|
4675
|
+
});
|
|
4676
|
+
},
|
|
4677
|
+
getBlocks() {
|
|
4678
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4679
|
+
return Promise.reject("getBlockInfo rejected");
|
|
4680
|
+
});
|
|
4681
|
+
},
|
|
4682
|
+
getBlockInfo() {
|
|
4683
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4684
|
+
return Promise.reject("getBlockInfo rejected");
|
|
4685
|
+
});
|
|
4686
|
+
},
|
|
4687
|
+
getLatestBlock() {
|
|
4688
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4689
|
+
return Promise.reject("getLatestBlock rejected");
|
|
4690
|
+
});
|
|
4691
|
+
},
|
|
4692
|
+
getBlocksInfo() {
|
|
4693
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4694
|
+
return Promise.reject("getBlocksInfo rejected");
|
|
4695
|
+
});
|
|
4696
|
+
},
|
|
4697
|
+
encodeTransaction() {
|
|
4698
|
+
throw new Error("encodeTransaction error");
|
|
4699
|
+
},
|
|
4700
|
+
decodeTransactionToGtx() {
|
|
4701
|
+
throw new Error("decodeTransactionToGtx error");
|
|
4702
|
+
},
|
|
4703
|
+
getClientNodeUrlPool() {
|
|
4704
|
+
return [];
|
|
4705
|
+
},
|
|
4706
|
+
getConfirmationProof() {
|
|
4707
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4708
|
+
return Promise.reject("getConfirmationProof rejected");
|
|
4709
|
+
});
|
|
4710
|
+
},
|
|
4711
|
+
getClusterAnchoringTransactionConfirmation() {
|
|
4712
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4713
|
+
return Promise.reject("getClusterAnchoringTransactionConfirmation rejected");
|
|
4714
|
+
});
|
|
4715
|
+
},
|
|
4716
|
+
getSystemAnchoringTransactionConfirmation() {
|
|
4717
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
4718
|
+
return Promise.reject("getSystemAnchoringTransactionConfirmation rejected");
|
|
4719
|
+
});
|
|
4720
|
+
},
|
|
4721
|
+
getAppStructure() {
|
|
4722
|
+
return Promise.reject("getAppStructure rejected");
|
|
4723
|
+
},
|
|
4724
|
+
};
|
|
4482
4725
|
});
|
|
4483
4726
|
}
|
|
4484
4727
|
|
|
@@ -4519,13 +4762,11 @@ function dumpGtx(gtxTx) {
|
|
|
4519
4762
|
var _a;
|
|
4520
4763
|
return `blockchainRid:\n${toString(gtxTx.blockchainRid)}\n
|
|
4521
4764
|
operations:
|
|
4522
|
-
${gtxTx.operations
|
|
4523
|
-
.map((op) => ` - ${op.opName}(${op.args.map(dumpGtv).join(", ")})\n`)
|
|
4524
|
-
.join("")}
|
|
4765
|
+
${gtxTx.operations.map(op => ` - ${op.opName}(${op.args.map(dumpGtv).join(", ")})\n`).join("")}
|
|
4525
4766
|
signers:
|
|
4526
|
-
${gtxTx.signers.map(
|
|
4767
|
+
${gtxTx.signers.map(s => ` - ${toString(s)}\n`).join("")}
|
|
4527
4768
|
signatures:
|
|
4528
|
-
${(_a = gtxTx.signatures) === null || _a === void 0 ? void 0 : _a.map(
|
|
4769
|
+
${(_a = gtxTx.signatures) === null || _a === void 0 ? void 0 : _a.map(s => ` - ${toString(s)}\n`).join("")}`;
|
|
4529
4770
|
}
|
|
4530
4771
|
function dumpGtv(rawGtv) {
|
|
4531
4772
|
return JSON.stringify(rawGtv, (_key, value) => {
|
|
@@ -4592,6 +4833,7 @@ exports.formatter = formatter;
|
|
|
4592
4833
|
exports.getAnchoringClient = getAnchoringClient;
|
|
4593
4834
|
exports.getBlockAnchoringTransaction = getBlockAnchoringTransaction;
|
|
4594
4835
|
exports.getDigestToSignFromRawGtxBody = getDigestToSignFromRawGtxBody;
|
|
4836
|
+
exports.getSystemClient = getSystemClient;
|
|
4595
4837
|
exports.gtv = index;
|
|
4596
4838
|
exports.gtx = gtx;
|
|
4597
4839
|
exports.gtxClient = gtxclient;
|