@clonegod/ttd-sui-common 1.0.89 → 1.0.91
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.
|
@@ -325,7 +325,7 @@ class AbstractSuiDexTradePlus extends dist_1.AbastrcatTrade {
|
|
|
325
325
|
let coin_types = [context.pool_info.tokenA.address, context.pool_info.tokenB.address];
|
|
326
326
|
this.appConfig.arb_cache.redis_event_publisher.publish_wallet_raw_tx_event(group_id, wallet, { group_id, wallet, txid, coin_types, remark: `PRE_REFRESH_OBJECTS_${i}` });
|
|
327
327
|
}, delay_ms);
|
|
328
|
-
(0, dist_1.log_info)(`try_refresh_wallet_objects, txid=${txid}, i=${i}, delay_ms
|
|
328
|
+
(0, dist_1.log_info)(`try_refresh_wallet_objects, txid=${txid}, i=${i}, delay_ms=${delay_ms}ms`);
|
|
329
329
|
}
|
|
330
330
|
});
|
|
331
331
|
}
|
|
@@ -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[]
|
|
9
|
+
send_tx: (signedTxBytes: string, signature: string, txDigest: string, send_type: string, read_mask_fields?: string[]) => Promise<void>;
|
|
10
10
|
private sendTxByGrpc;
|
|
11
11
|
private sendTxByRpc;
|
|
12
12
|
}
|
|
@@ -13,50 +13,40 @@ 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']) {
|
|
17
17
|
const start_time = Date.now();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
try {
|
|
19
|
+
send_type = (send_type || 'ALL').toUpperCase();
|
|
20
|
+
if (send_type === 'GRPC') {
|
|
21
|
+
yield this.sendTxByGrpc(signedTxBytes, signature, txDigest, read_mask_fields);
|
|
22
|
+
}
|
|
23
|
+
else if (send_type === 'RPC') {
|
|
24
|
+
yield this.sendTxByRpc(signedTxBytes, signature, txDigest);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
yield Promise.race([
|
|
28
|
+
this.sendTxByGrpc(signedTxBytes, signature, txDigest, read_mask_fields),
|
|
29
|
+
this.sendTxByRpc(signedTxBytes, signature, txDigest)
|
|
30
|
+
]);
|
|
31
|
+
}
|
|
32
|
+
(0, dist_1.log_info)(`send_tx success, txid=${txDigest}, send_type=${send_type}, cost=${Date.now() - start_time}ms`);
|
|
24
33
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
this.sendTxByRpc(signedTxBytes, signature, txDigest, timeoutMs)
|
|
29
|
-
]);
|
|
34
|
+
catch (error) {
|
|
35
|
+
(0, dist_1.log_warn)(`send_tx failed, txid=${txDigest}, send_type=${send_type}, cost=${Date.now() - start_time}ms, error=${error.message}`);
|
|
36
|
+
throw error;
|
|
30
37
|
}
|
|
31
|
-
(0, dist_1.log_info)(`send_tx, txid=${txDigest}, send_type=${send_type}, cost=${Date.now() - start_time}ms`);
|
|
32
38
|
});
|
|
33
39
|
this.appConfig = appConfig;
|
|
34
40
|
this.sui_client = sui_client;
|
|
35
41
|
this.grpcClient = grpcClient;
|
|
36
42
|
}
|
|
37
43
|
sendTxByGrpc(signedTxBytes_1, signature_1, txDigest_1) {
|
|
38
|
-
return __awaiter(this, arguments, void 0, function* (signedTxBytes, signature, txDigest, read_mask_fields = ['transaction']
|
|
44
|
+
return __awaiter(this, arguments, void 0, function* (signedTxBytes, signature, txDigest, read_mask_fields = ['transaction']) {
|
|
39
45
|
const bcsBytes = Buffer.from(signedTxBytes, 'base64');
|
|
40
46
|
const signatureBytes = Buffer.from(signature, 'base64');
|
|
41
47
|
try {
|
|
42
|
-
|
|
43
|
-
|
|
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);
|
|
48
|
+
let response = yield this.grpcClient.transactionService.executeTransaction(bcsBytes, signatureBytes, read_mask_fields);
|
|
49
|
+
this.appConfig.emit(`SUI_TX_RESULT_${txDigest}`, response);
|
|
60
50
|
}
|
|
61
51
|
catch (error) {
|
|
62
52
|
(0, dist_1.log_warn)(`send tx by grpc failed!!! txid=${txDigest}, error=${error.message}`);
|
|
@@ -64,17 +54,10 @@ class SuiTxSender {
|
|
|
64
54
|
}
|
|
65
55
|
});
|
|
66
56
|
}
|
|
67
|
-
sendTxByRpc(
|
|
68
|
-
return __awaiter(this,
|
|
57
|
+
sendTxByRpc(signedTxBytes, signature, txDigest) {
|
|
58
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
59
|
try {
|
|
70
|
-
|
|
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({
|
|
60
|
+
let _response = yield this.sui_client.executeTransactionBlock({
|
|
78
61
|
transactionBlock: signedTxBytes,
|
|
79
62
|
signature: signature,
|
|
80
63
|
options: {
|
|
@@ -84,14 +67,6 @@ class SuiTxSender {
|
|
|
84
67
|
showEffects: true
|
|
85
68
|
}
|
|
86
69
|
});
|
|
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
|
-
}
|
|
95
70
|
this.appConfig.emit(`SUI_TX_RESULT_${txDigest}`, txDigest);
|
|
96
71
|
}
|
|
97
72
|
catch (error) {
|