@clonegod/ttd-sui-common 1.0.88 → 1.0.90

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.
@@ -317,7 +317,7 @@ class AbstractSuiDexTradePlus extends dist_1.AbastrcatTrade {
317
317
  (0, dist_1.log_info)(`✅ ${tokenSymbol} 进行对象合并,涉及 ${other_objects.length} 个对象`);
318
318
  }
319
319
  try_refresh_wallet_objects(wallet_1, txid_1, context_1) {
320
- return __awaiter(this, arguments, void 0, function* (wallet, txid, context, initial_delay_ms = 0, try_times = 5, try_delay_ms = 300) {
320
+ return __awaiter(this, arguments, void 0, function* (wallet, txid, context, initial_delay_ms = 0, try_times = 2, try_delay_ms = 600) {
321
321
  for (let i = 0; i < try_times; i++) {
322
322
  let delay_ms = initial_delay_ms + i * try_delay_ms;
323
323
  setTimeout(() => {
@@ -6,7 +6,7 @@ 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, send_type: string, read_mask_fields?: string[]) => Promise<void>;
9
+ send_tx: (signedTxBytes: string, signature: string, txDigest: string, send_type: string, read_mask_fields?: string[], timeoutMs?: number) => Promise<void>;
10
10
  private sendTxByGrpc;
11
11
  private sendTxByRpc;
12
12
  }
@@ -13,19 +13,19 @@ exports.SuiTxSender = void 0;
13
13
  const dist_1 = require("@clonegod/ttd-core/dist");
14
14
  class SuiTxSender {
15
15
  constructor(appConfig, sui_client, grpcClient) {
16
- this.send_tx = (signedTxBytes_1, signature_1, txDigest_1, send_type_1, ...args_1) => __awaiter(this, [signedTxBytes_1, signature_1, txDigest_1, send_type_1, ...args_1], void 0, function* (signedTxBytes, signature, txDigest, send_type, read_mask_fields = ['transaction']) {
16
+ this.send_tx = (signedTxBytes_1, signature_1, txDigest_1, send_type_1, ...args_1) => __awaiter(this, [signedTxBytes_1, signature_1, txDigest_1, send_type_1, ...args_1], void 0, function* (signedTxBytes, signature, txDigest, send_type, read_mask_fields = ['transaction'], timeoutMs = 3000) {
17
17
  const start_time = Date.now();
18
18
  send_type = (send_type || 'ALL').toUpperCase();
19
19
  if (send_type === 'GRPC') {
20
- yield this.sendTxByGrpc(signedTxBytes, signature, txDigest, read_mask_fields);
20
+ yield this.sendTxByGrpc(signedTxBytes, signature, txDigest, read_mask_fields, timeoutMs);
21
21
  }
22
22
  else if (send_type === 'RPC') {
23
- yield this.sendTxByRpc(signedTxBytes, signature, txDigest);
23
+ yield this.sendTxByRpc(signedTxBytes, signature, txDigest, timeoutMs);
24
24
  }
25
25
  else {
26
26
  yield Promise.race([
27
- this.sendTxByGrpc(signedTxBytes, signature, txDigest, read_mask_fields),
28
- this.sendTxByRpc(signedTxBytes, signature, txDigest)
27
+ this.sendTxByGrpc(signedTxBytes, signature, txDigest, read_mask_fields, timeoutMs),
28
+ this.sendTxByRpc(signedTxBytes, signature, txDigest, timeoutMs)
29
29
  ]);
30
30
  }
31
31
  (0, dist_1.log_info)(`send_tx, txid=${txDigest}, send_type=${send_type}, cost=${Date.now() - start_time}ms`);
@@ -35,12 +35,28 @@ class SuiTxSender {
35
35
  this.grpcClient = grpcClient;
36
36
  }
37
37
  sendTxByGrpc(signedTxBytes_1, signature_1, txDigest_1) {
38
- return __awaiter(this, arguments, void 0, function* (signedTxBytes, signature, txDigest, read_mask_fields = ['transaction']) {
38
+ return __awaiter(this, arguments, void 0, function* (signedTxBytes, signature, txDigest, read_mask_fields = ['transaction'], timeoutMs = 3000) {
39
39
  const bcsBytes = Buffer.from(signedTxBytes, 'base64');
40
40
  const signatureBytes = Buffer.from(signature, 'base64');
41
41
  try {
42
- let response = yield this.grpcClient.transactionService.executeTransaction(bcsBytes, signatureBytes, read_mask_fields);
43
- this.appConfig.emit(`SUI_TX_RESULT_${txDigest}`, response);
42
+ const GRPC_TIMEOUT_SENTINEL = Symbol('grpc-timeout');
43
+ let timer;
44
+ const timeoutPromise = new Promise((resolve) => {
45
+ timer = setTimeout(() => {
46
+ resolve(GRPC_TIMEOUT_SENTINEL);
47
+ }, timeoutMs);
48
+ });
49
+ const execPromise = this.grpcClient.transactionService
50
+ .executeTransaction(bcsBytes, signatureBytes, read_mask_fields);
51
+ const result = yield Promise.race([execPromise, timeoutPromise]);
52
+ if (timer) {
53
+ clearTimeout(timer);
54
+ timer = null;
55
+ }
56
+ if (result === GRPC_TIMEOUT_SENTINEL) {
57
+ throw new Error(`grpc executeTransaction timeout after ${timeoutMs}ms`);
58
+ }
59
+ this.appConfig.emit(`SUI_TX_RESULT_${txDigest}`, result);
44
60
  }
45
61
  catch (error) {
46
62
  (0, dist_1.log_warn)(`send tx by grpc failed!!! txid=${txDigest}, error=${error.message}`);
@@ -48,10 +64,17 @@ class SuiTxSender {
48
64
  }
49
65
  });
50
66
  }
51
- sendTxByRpc(signedTxBytes, signature, txDigest) {
52
- return __awaiter(this, void 0, void 0, function* () {
67
+ sendTxByRpc(signedTxBytes_1, signature_1, txDigest_1) {
68
+ return __awaiter(this, arguments, void 0, function* (signedTxBytes, signature, txDigest, timeoutMs = 3000) {
53
69
  try {
54
- let _response = yield this.sui_client.executeTransactionBlock({
70
+ const RPC_TIMEOUT_SENTINEL = Symbol('rpc-timeout');
71
+ let timer;
72
+ const timeoutPromise = new Promise((resolve) => {
73
+ timer = setTimeout(() => {
74
+ resolve(RPC_TIMEOUT_SENTINEL);
75
+ }, timeoutMs);
76
+ });
77
+ const execPromise = this.sui_client.executeTransactionBlock({
55
78
  transactionBlock: signedTxBytes,
56
79
  signature: signature,
57
80
  options: {
@@ -61,6 +84,14 @@ class SuiTxSender {
61
84
  showEffects: true
62
85
  }
63
86
  });
87
+ const result = yield Promise.race([execPromise, timeoutPromise]);
88
+ if (timer) {
89
+ clearTimeout(timer);
90
+ timer = null;
91
+ }
92
+ if (result === RPC_TIMEOUT_SENTINEL) {
93
+ throw new Error(`rpc executeTransactionBlock timeout after ${timeoutMs}ms`);
94
+ }
64
95
  this.appConfig.emit(`SUI_TX_RESULT_${txDigest}`, txDigest);
65
96
  }
66
97
  catch (error) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sui-common",
3
- "version": "1.0.88",
3
+ "version": "1.0.90",
4
4
  "description": "Sui common library",
5
5
  "license": "UNLICENSED",
6
6
  "main": "dist/index.js",