@clonegod/ttd-sui-common 1.0.28 → 1.0.29

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.
@@ -6,5 +6,5 @@ export declare class SuiTxSender {
6
6
  sui_client: SuiClient;
7
7
  grpcClient: SuiGrpcClient;
8
8
  constructor(appConfig: AppConfig, sui_client: SuiClient, grpcClient: SuiGrpcClient);
9
- send_tx: (signedTxBytes: string, signature: string, txDigest: string) => void;
9
+ send_tx: (signedTxBytes: string, signature: string, txDigest: string, send_type?: string, max_retry?: number) => Promise<void>;
10
10
  }
@@ -1,45 +1,56 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
2
11
  Object.defineProperty(exports, "__esModule", { value: true });
3
12
  exports.SuiTxSender = void 0;
4
13
  const dist_1 = require("@clonegod/ttd-core/dist");
5
14
  class SuiTxSender {
6
15
  constructor(appConfig, sui_client, grpcClient) {
7
- this.send_tx = (signedTxBytes, signature, txDigest) => {
8
- const promises = [];
16
+ this.send_tx = (signedTxBytes_1, signature_1, txDigest_1, ...args_1) => __awaiter(this, [signedTxBytes_1, signature_1, txDigest_1, ...args_1], void 0, function* (signedTxBytes, signature, txDigest, send_type = 'grpc', max_retry = 3) {
9
17
  const bcsBytes = Buffer.from(signedTxBytes, 'base64');
10
18
  const signatureBytes = Buffer.from(signature, 'base64');
11
- const grpcPromise = this.grpcClient.transactionService.executeTransaction(bcsBytes, signatureBytes)
12
- .then((response) => { return { type: 'grpc', success: true, response }; })
13
- .catch((error) => {
14
- (0, dist_1.log_error)(`submit tx to grpc failed`, error);
15
- return { type: 'grpc', success: false, error };
16
- });
17
- promises.push(grpcPromise);
18
- const rpcPromise = this.sui_client.executeTransactionBlock({
19
- transactionBlock: signedTxBytes,
20
- signature: signature,
21
- options: {
22
- showEvents: true,
23
- showBalanceChanges: true,
24
- showObjectChanges: true,
25
- showEffects: true
19
+ if (send_type.toLowerCase() === 'grpc') {
20
+ for (let i = 0; i < max_retry; i++) {
21
+ try {
22
+ let response = yield this.grpcClient.transactionService.executeTransaction(bcsBytes, signatureBytes);
23
+ this.appConfig.emit(`SUI_TX_RESULT_${txDigest}`, response);
24
+ }
25
+ catch (error) {
26
+ (0, dist_1.log_error)(`submit tx to grpc failed`, error);
27
+ }
26
28
  }
27
- }).then((response) => {
28
- return { type: 'rpc', success: true, response };
29
- }).catch((error) => {
30
- (0, dist_1.log_error)(`submit tx to sui_client failed`, error);
31
- return { type: 'rpc', success: false, error };
32
- });
33
- promises.push(rpcPromise);
34
- Promise.race(promises).then((result) => {
35
- if (result.type === 'rpc') {
36
- this.appConfig.emit(`SUI_TX_RESULT_${txDigest}`, txDigest);
29
+ }
30
+ else if (send_type.toLowerCase() === 'rpc') {
31
+ for (let i = 0; i < max_retry; i++) {
32
+ try {
33
+ let _response = yield this.sui_client.executeTransactionBlock({
34
+ transactionBlock: signedTxBytes,
35
+ signature: signature,
36
+ options: {
37
+ showEvents: true,
38
+ showBalanceChanges: true,
39
+ showObjectChanges: true,
40
+ showEffects: true
41
+ }
42
+ });
43
+ this.appConfig.emit(`SUI_TX_RESULT_${txDigest}`, txDigest);
44
+ }
45
+ catch (error) {
46
+ (0, dist_1.log_error)(`submit tx to sui_client failed`, error);
47
+ }
37
48
  }
38
- if (result.type === 'grpc') {
39
- this.appConfig.emit(`SUI_TX_RESULT_${txDigest}`, result.response);
40
- }
41
- });
42
- };
49
+ }
50
+ else {
51
+ throw new Error(`not support send type: ${send_type}`);
52
+ }
53
+ });
43
54
  this.appConfig = appConfig;
44
55
  this.sui_client = sui_client;
45
56
  this.grpcClient = grpcClient;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sui-common",
3
- "version": "1.0.28",
3
+ "version": "1.0.29",
4
4
  "description": "Sui common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",