@clonegod/ttd-sui-common 1.0.51 → 1.0.53

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.
@@ -70,7 +70,7 @@ class SimpleRedisClient {
70
70
  });
71
71
  }
72
72
  withLock(lock_identifier_1, callback_1) {
73
- return __awaiter(this, arguments, void 0, function* (lock_identifier, callback, release_lock_delay_ms = 2000) {
73
+ return __awaiter(this, arguments, void 0, function* (lock_identifier, callback, release_lock_delay_ms = 500) {
74
74
  const lock_key = this.getLockKey(lock_identifier);
75
75
  const lock_value = `${Date.now()}-${Math.random().toString(36).substring(2, 15)}`;
76
76
  let retries = 0;
@@ -96,6 +96,7 @@ class SimpleRedisClient {
96
96
  if (acquired) {
97
97
  const release_delay = parseInt(process.env.NONCE_LOCK_RELEASE_DELAY_MS || String(release_lock_delay_ms));
98
98
  if (release_delay > 0) {
99
+ (0, dist_1.log_warn)(`withLock release_lock_delay_ms=${release_delay}ms`);
99
100
  yield (0, dist_1.sleep)(release_delay);
100
101
  }
101
102
  yield this.releaseLock(lock_key, lock_value);
@@ -7,4 +7,6 @@ export declare class SuiTxSender {
7
7
  grpcClient: SuiGrpcClient;
8
8
  constructor(appConfig: AppConfig, sui_client: SuiClient, grpcClient: SuiGrpcClient);
9
9
  send_tx: (signedTxBytes: string, signature: string, txDigest: string, send_grpc?: boolean) => Promise<void>;
10
+ private sendTxByGrpc;
11
+ private sendTxByRpc;
10
12
  }
@@ -14,14 +14,34 @@ const dist_1 = require("@clonegod/ttd-core/dist");
14
14
  class SuiTxSender {
15
15
  constructor(appConfig, sui_client, grpcClient) {
16
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_grpc = false) {
17
+ (0, dist_1.log_info)(`send tx:txid=${txDigest}, send_grpc=${send_grpc}`);
18
+ if (send_grpc) {
19
+ yield this.sendTxByGrpc(signedTxBytes, signature, txDigest);
20
+ }
21
+ else {
22
+ yield this.sendTxByRpc(signedTxBytes, signature, txDigest);
23
+ }
24
+ });
25
+ this.appConfig = appConfig;
26
+ this.sui_client = sui_client;
27
+ this.grpcClient = grpcClient;
28
+ }
29
+ sendTxByGrpc(signedTxBytes, signature, txDigest) {
30
+ return __awaiter(this, void 0, void 0, function* () {
17
31
  const bcsBytes = Buffer.from(signedTxBytes, 'base64');
18
32
  const signatureBytes = Buffer.from(signature, 'base64');
19
- if (send_grpc) {
20
- setTimeout(() => __awaiter(this, void 0, void 0, function* () {
21
- let response = yield this.grpcClient.transactionService.executeTransaction(bcsBytes, signatureBytes);
22
- this.appConfig.emit(`SUI_TX_RESULT_${txDigest}`, response);
23
- }), 0);
33
+ try {
34
+ let response = yield this.grpcClient.transactionService.executeTransaction(bcsBytes, signatureBytes);
35
+ this.appConfig.emit(`SUI_TX_RESULT_${txDigest}`, response);
36
+ }
37
+ catch (error) {
38
+ (0, dist_1.log_error)(`send tx by grpc failed!!! txid=${txDigest}`, error);
39
+ yield this.sendTxByRpc(signedTxBytes, signature, txDigest);
24
40
  }
41
+ });
42
+ }
43
+ sendTxByRpc(signedTxBytes, signature, txDigest) {
44
+ return __awaiter(this, void 0, void 0, function* () {
25
45
  try {
26
46
  let _response = yield this.sui_client.executeTransactionBlock({
27
47
  transactionBlock: signedTxBytes,
@@ -39,9 +59,6 @@ class SuiTxSender {
39
59
  (0, dist_1.log_error)(`send tx by rpc failed!!! txid=${txDigest}`, error);
40
60
  }
41
61
  });
42
- this.appConfig = appConfig;
43
- this.sui_client = sui_client;
44
- this.grpcClient = grpcClient;
45
62
  }
46
63
  }
47
64
  exports.SuiTxSender = SuiTxSender;
package/package.json CHANGED
@@ -1,38 +1,38 @@
1
1
  {
2
- "name": "@clonegod/ttd-sui-common",
3
- "version": "1.0.51",
4
- "description": "Sui common library",
5
- "license": "UNLICENSED",
6
- "main": "dist/index.js",
7
- "types": "dist/index.d.ts",
8
- "files": [
9
- "dist"
10
- ],
11
- "scripts": {
12
- "clean": "rm -rf dist node_modules",
13
- "build": "yarn tsc --outDir ./dist && yarn copy-protos",
14
- "copy-protos": "cp -r src/grpc/protos dist/grpc/",
15
- "push": "npm run build && npm publish"
16
- },
17
- "dependencies": {
18
- "@clonegod/ttd-core": "2.0.63",
19
- "@grpc/grpc-js": "^1.13.4",
20
- "@grpc/proto-loader": "^0.8.0",
21
- "@mysten/sui": "^1.37.5",
22
- "axios": "^1.11.0",
23
- "dotenv": "^16.4.7",
24
- "google-protobuf": "^4.0.0",
25
- "protobufjs": "^7.5.4"
26
- },
27
- "devDependencies": {
28
- "@types/google-protobuf": "^3.15.12",
29
- "@types/node": "^22.14.0",
30
- "grpc-tools": "^1.13.0",
31
- "protoc-gen-ts": "^0.8.7",
32
- "typescript": "^5.8.2"
33
- },
34
- "overrides": {},
35
- "publishConfig": {
36
- "access": "public"
37
- }
2
+ "name": "@clonegod/ttd-sui-common",
3
+ "version": "1.0.53",
4
+ "description": "Sui common library",
5
+ "license": "UNLICENSED",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "files": [
9
+ "dist"
10
+ ],
11
+ "scripts": {
12
+ "clean": "rm -rf dist node_modules",
13
+ "build": "yarn tsc --outDir ./dist && yarn copy-protos",
14
+ "copy-protos": "cp -r src/grpc/protos dist/grpc/",
15
+ "push": "npm run build && npm publish"
16
+ },
17
+ "dependencies": {
18
+ "@clonegod/ttd-core": "2.0.63",
19
+ "@grpc/grpc-js": "^1.13.4",
20
+ "@grpc/proto-loader": "^0.8.0",
21
+ "@mysten/sui": "^1.37.5",
22
+ "axios": "^1.11.0",
23
+ "dotenv": "^16.4.7",
24
+ "google-protobuf": "^4.0.0",
25
+ "protobufjs": "^7.5.4"
26
+ },
27
+ "devDependencies": {
28
+ "@types/google-protobuf": "^3.15.12",
29
+ "@types/node": "^22.14.0",
30
+ "grpc-tools": "^1.13.0",
31
+ "protoc-gen-ts": "^0.8.7",
32
+ "typescript": "^5.8.2"
33
+ },
34
+ "overrides": {},
35
+ "publishConfig": {
36
+ "access": "public"
37
+ }
38
38
  }