@clonegod/ttd-sui-common 1.0.87 → 1.0.89
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.
|
@@ -100,13 +100,13 @@ class SuiTransactionParser {
|
|
|
100
100
|
const storageRebate = new decimal_js_1.default(gasUsed.storage_rebate || 0);
|
|
101
101
|
const nonRefundableStorageFee = new decimal_js_1.default(gasUsed.non_refundable_storage_fee || 0);
|
|
102
102
|
const actualStorageCost = storageCost.minus(storageRebate).plus(nonRefundableStorageFee);
|
|
103
|
-
const
|
|
104
|
-
const
|
|
105
|
-
const
|
|
103
|
+
const baseFee = actualStorageCost.div(Math.pow(10, 9));
|
|
104
|
+
const priorityFee = computationCost.div(Math.pow(10, 9));
|
|
105
|
+
const totalFee = baseFee.plus(priorityFee);
|
|
106
106
|
return {
|
|
107
|
-
base_fee,
|
|
108
|
-
priority_fee,
|
|
109
|
-
total_fee
|
|
107
|
+
base_fee: baseFee.toNumber(),
|
|
108
|
+
priority_fee: priorityFee.toNumber(),
|
|
109
|
+
total_fee: totalFee.toNumber()
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
112
|
calc_tx_price(tokenAChange, tokenBChange, pool_info) {
|
|
@@ -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
|
-
|
|
43
|
-
|
|
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(
|
|
52
|
-
return __awaiter(this,
|
|
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
|
-
|
|
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) {
|