postchain-client 1.9.0 → 1.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/built/cjs/index.js +42 -34
- package/built/cjs/index.js.map +1 -1
- package/built/esm/index.js +42 -34
- package/built/esm/index.js.map +1 -1
- package/built/src/blockchainClient/blockchainClient.js +38 -32
- package/built/src/blockchainClient/blockchainClient.js.map +1 -1
- package/built/src/blockchainClient/interface.d.ts +15 -5
- package/built/src/blockchainClient/types.d.ts +11 -2
- package/built/src/blockchainClient/utils.js +2 -1
- package/built/src/blockchainClient/utils.js.map +1 -1
- package/built/src/gtx/types.d.ts +0 -1
- package/built/src/restclient/restclientutil.js +2 -1
- package/built/src/restclient/restclientutil.js.map +1 -1
- package/built/umd/index.js +42 -34
- package/built/umd/index.js.map +1 -1
- package/changelog.md +33 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -36,7 +36,7 @@ const blockchainRid =
|
|
|
36
36
|
"7d565d92fd15bd1cdac2dc276cbcbc5581349d05a9e94ba919e1155ef4daf8f9";
|
|
37
37
|
```
|
|
38
38
|
|
|
39
|
-
Next, create a Chromia client instance and configure it with a specific set of base URLs, the `blockchainRID`, and so forth. If you connect to a local node, the `
|
|
39
|
+
Next, create a Chromia client instance and configure it with a specific set of base URLs, the `blockchainRID`, and so forth. If you connect to a local node, the `nodeUrlPool` property accepts an array or a string of URLs to nodes running the target dapp.
|
|
40
40
|
|
|
41
41
|
```typescript
|
|
42
42
|
const chromiaClient = await createClient({
|
package/built/cjs/index.js
CHANGED
|
@@ -2536,10 +2536,10 @@ function createClient(settings) {
|
|
|
2536
2536
|
const transactionObject = {
|
|
2537
2537
|
tx: gtxBytes.toString("hex"),
|
|
2538
2538
|
};
|
|
2539
|
-
const { error
|
|
2539
|
+
const { error, statusCode, rspBody } = yield requestWithRetry(Method.POST, `tx/${this.config.blockchainRid}`, this.config, transactionObject);
|
|
2540
2540
|
const transactionRid = getDigestToSign(gtx$1);
|
|
2541
2541
|
try {
|
|
2542
|
-
yield handlePostResponsePromisified(error
|
|
2542
|
+
yield handlePostResponsePromisified(error, statusCode, rspBody);
|
|
2543
2543
|
if (typeof callback === "function") {
|
|
2544
2544
|
callback(null, {
|
|
2545
2545
|
status: exports.ResponseStatus.Waiting,
|
|
@@ -2559,36 +2559,21 @@ function createClient(settings) {
|
|
|
2559
2559
|
statusCode: statusCode,
|
|
2560
2560
|
transactionRid: transactionRid,
|
|
2561
2561
|
});
|
|
2562
|
-
const
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
case exports.ResponseStatus.Unknown:
|
|
2578
|
-
reject(new LostMessageError());
|
|
2579
|
-
break;
|
|
2580
|
-
case exports.ResponseStatus.Waiting:
|
|
2581
|
-
setTimeout(() => waitConfirmation(txRID).then(resolve, reject), this.config.pollingInterval);
|
|
2582
|
-
break;
|
|
2583
|
-
default:
|
|
2584
|
-
error(status);
|
|
2585
|
-
reject(new UnexpectedResponseError());
|
|
2586
|
-
}
|
|
2587
|
-
}
|
|
2588
|
-
});
|
|
2589
|
-
});
|
|
2590
|
-
};
|
|
2591
|
-
const confirmationStatus = yield waitConfirmation(getDigestToSign(gtx$1));
|
|
2562
|
+
const awaitConfirmation = (txRID) => __awaiter$6(this, void 0, void 0, function* () {
|
|
2563
|
+
let lastKnownResult;
|
|
2564
|
+
for (let i = 0; i < this.config.statusPollCount; i++) {
|
|
2565
|
+
lastKnownResult = yield this.getTransactionStatus(txRID);
|
|
2566
|
+
if (lastKnownResult.status === exports.ResponseStatus.Confirmed) {
|
|
2567
|
+
return exports.ResponseStatus.Confirmed;
|
|
2568
|
+
}
|
|
2569
|
+
else if (lastKnownResult.status === exports.ResponseStatus.Rejected) {
|
|
2570
|
+
throw new TxRejectedError(lastKnownResult.rejectReason);
|
|
2571
|
+
}
|
|
2572
|
+
yield sleep(this.config.statusPollInterval);
|
|
2573
|
+
}
|
|
2574
|
+
return lastKnownResult.status;
|
|
2575
|
+
});
|
|
2576
|
+
const confirmationStatus = yield awaitConfirmation(getDigestToSign(gtx$1));
|
|
2592
2577
|
resolve({
|
|
2593
2578
|
status: confirmationStatus,
|
|
2594
2579
|
statusCode: statusCode,
|
|
@@ -2705,6 +2690,27 @@ function createClient(settings) {
|
|
|
2705
2690
|
});
|
|
2706
2691
|
});
|
|
2707
2692
|
},
|
|
2693
|
+
getBlockInfo(blockIdentifier, txs = false, callback) {
|
|
2694
|
+
return __awaiter$6(this, void 0, void 0, function* () {
|
|
2695
|
+
if (typeof blockIdentifier !== "string" &&
|
|
2696
|
+
typeof blockIdentifier !== "number") {
|
|
2697
|
+
throw new TypeError(`Invalid "blockIdentifier" type. Expected string or number, but received ${typeof blockIdentifier}.`);
|
|
2698
|
+
}
|
|
2699
|
+
else if (typeof blockIdentifier === "string" &&
|
|
2700
|
+
!/^[0-9a-fA-F]{64}$/.test(blockIdentifier)) {
|
|
2701
|
+
throw new TypeError("Parameter 'blockIdentifier' does not have the correct format (64-character hexadecimal string).");
|
|
2702
|
+
}
|
|
2703
|
+
const queryString = typeof blockIdentifier === "string"
|
|
2704
|
+
? blockIdentifier
|
|
2705
|
+
: `height/${blockIdentifier}`;
|
|
2706
|
+
const { error, statusCode, rspBody } = yield requestWithRetry(Method.GET, `blocks/${this.config.blockchainRid}/${queryString}?txs=${txs}`, this.config);
|
|
2707
|
+
return new Promise((resolve, reject) => {
|
|
2708
|
+
handleGetResponse(error, statusCode, statusCode === 200 && rspBody !== null
|
|
2709
|
+
? formatBlockInfoResponse(rspBody)
|
|
2710
|
+
: rspBody, callbackPromiseBuilder(reject, resolve, callback));
|
|
2711
|
+
});
|
|
2712
|
+
});
|
|
2713
|
+
},
|
|
2708
2714
|
getBlocksInfo(limit = 25, beforeTime, beforeHeight, txs, callback) {
|
|
2709
2715
|
return __awaiter$6(this, void 0, void 0, function* () {
|
|
2710
2716
|
let filteringQueryParam = "";
|
|
@@ -2827,7 +2833,8 @@ function getClientConfigFromSettings(settings) {
|
|
|
2827
2833
|
return {
|
|
2828
2834
|
endpointPool: nodeUrlPoolToUse,
|
|
2829
2835
|
blockchainRid: blockchainRidToUse,
|
|
2830
|
-
|
|
2836
|
+
statusPollInterval: settings.statusPollInterval || 500,
|
|
2837
|
+
statusPollCount: settings.statusPollCount || 20,
|
|
2831
2838
|
failoverStrategy: ((_a = settings.failOverConfig) === null || _a === void 0 ? void 0 : _a.strategy) || defaultFailoverConfig.strategy,
|
|
2832
2839
|
attemptsPerEndpoint: ((_b = settings.failOverConfig) === null || _b === void 0 ? void 0 : _b.attemptsPerEndpoint) ||
|
|
2833
2840
|
defaultFailoverConfig.attemptsPerEndpoint,
|
|
@@ -3029,7 +3036,8 @@ function getBlockchainRidFromIid(endpointPool, chainId, failOverConfig = default
|
|
|
3029
3036
|
const config = {
|
|
3030
3037
|
endpointPool,
|
|
3031
3038
|
blockchainRid: undefined,
|
|
3032
|
-
|
|
3039
|
+
statusPollInterval: 500,
|
|
3040
|
+
statusPollCount: 20,
|
|
3033
3041
|
failoverStrategy: failOverConfig.strategy || defaultFailoverConfig.strategy,
|
|
3034
3042
|
attemptsPerEndpoint: failOverConfig.attemptsPerEndpoint ||
|
|
3035
3043
|
defaultFailoverConfig.attemptsPerEndpoint,
|