@clonegod/ttd-sui-common 1.0.49 → 1.0.51
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.
|
@@ -7,6 +7,7 @@ export declare class TransactionResultChecker extends AbstractTransactionResultC
|
|
|
7
7
|
transactionParser: SuiTransactionParser;
|
|
8
8
|
leadgerService: LedgerService;
|
|
9
9
|
constructor(env_args: EnvArgs, event_emitter: EventEmitter, wallet_address: string, ledgerService: LedgerService);
|
|
10
|
+
private isValidTransactionResult;
|
|
10
11
|
check_tx_result_interval(): Promise<void>;
|
|
11
12
|
on_subscibe_transaction(): void;
|
|
12
13
|
private processTransactionResult;
|
|
@@ -20,6 +20,12 @@ class TransactionResultChecker extends trade_1.AbstractTransactionResultCheck {
|
|
|
20
20
|
this.transactionParser = new sui_tx_parser_1.SuiTransactionParser(wallet_address);
|
|
21
21
|
this.leadgerService = ledgerService;
|
|
22
22
|
}
|
|
23
|
+
isValidTransactionResult(txReceipt) {
|
|
24
|
+
var _a, _b, _c, _d;
|
|
25
|
+
const success = (_c = (_b = (_a = txReceipt.transaction) === null || _a === void 0 ? void 0 : _a.effects) === null || _b === void 0 ? void 0 : _b.status) === null || _c === void 0 ? void 0 : _c.success;
|
|
26
|
+
const balance_changes = (_d = txReceipt.transaction) === null || _d === void 0 ? void 0 : _d.balance_changes;
|
|
27
|
+
return !success || (success && balance_changes && balance_changes.length > 0);
|
|
28
|
+
}
|
|
23
29
|
check_tx_result_interval() {
|
|
24
30
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
31
|
const check_start_time = Date.now();
|
|
@@ -40,8 +46,10 @@ class TransactionResultChecker extends trade_1.AbstractTransactionResultCheck {
|
|
|
40
46
|
txReceipt['transaction']['signatures'] = [];
|
|
41
47
|
txReceipt = (0, index_1.decodeBytes)(txReceipt);
|
|
42
48
|
(0, dist_1.log_info)(`Received transaction result via polling: ${this.txid}`);
|
|
43
|
-
|
|
44
|
-
|
|
49
|
+
if (this.isValidTransactionResult(txReceipt)) {
|
|
50
|
+
clearInterval(intervalId);
|
|
51
|
+
yield this.processTransactionResult(txReceipt, 'interval');
|
|
52
|
+
}
|
|
45
53
|
}
|
|
46
54
|
else {
|
|
47
55
|
clearInterval(intervalId);
|
|
@@ -57,7 +65,6 @@ class TransactionResultChecker extends trade_1.AbstractTransactionResultCheck {
|
|
|
57
65
|
}
|
|
58
66
|
on_subscibe_transaction() {
|
|
59
67
|
this.event_emitter.once(`SUI_TX_RESULT_${this.txid}`, (response) => __awaiter(this, void 0, void 0, function* () {
|
|
60
|
-
var _a, _b, _c, _d;
|
|
61
68
|
(0, dist_1.log_info)(`receive tx result notification, txid=${this.txid}`);
|
|
62
69
|
if (response.transaction) {
|
|
63
70
|
this.processTransactionResult(response, 'grpc');
|
|
@@ -71,10 +78,7 @@ class TransactionResultChecker extends trade_1.AbstractTransactionResultCheck {
|
|
|
71
78
|
console.log('txReceipt is empty', txReceipt);
|
|
72
79
|
continue;
|
|
73
80
|
}
|
|
74
|
-
|
|
75
|
-
const balance_changes = (_d = txReceipt.transaction) === null || _d === void 0 ? void 0 : _d.balance_changes;
|
|
76
|
-
const isValidResult = !success || (success && balance_changes && balance_changes.length > 0);
|
|
77
|
-
if (isValidResult) {
|
|
81
|
+
if (this.isValidTransactionResult(txReceipt)) {
|
|
78
82
|
this.processTransactionResult(txReceipt, 'grpc2');
|
|
79
83
|
break;
|
|
80
84
|
}
|
|
@@ -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) => Promise<void>;
|
|
9
|
+
send_tx: (signedTxBytes: string, signature: string, txDigest: string, send_grpc?: boolean) => Promise<void>;
|
|
10
10
|
}
|
|
@@ -13,9 +13,15 @@ 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 = (
|
|
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
17
|
const bcsBytes = Buffer.from(signedTxBytes, 'base64');
|
|
18
18
|
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);
|
|
24
|
+
}
|
|
19
25
|
try {
|
|
20
26
|
let _response = yield this.sui_client.executeTransactionBlock({
|
|
21
27
|
transactionBlock: signedTxBytes,
|
|
@@ -31,13 +37,6 @@ class SuiTxSender {
|
|
|
31
37
|
}
|
|
32
38
|
catch (error) {
|
|
33
39
|
(0, dist_1.log_error)(`send tx by rpc failed!!! txid=${txDigest}`, error);
|
|
34
|
-
try {
|
|
35
|
-
let response = yield this.grpcClient.transactionService.executeTransaction(bcsBytes, signatureBytes);
|
|
36
|
-
this.appConfig.emit(`SUI_TX_RESULT_${txDigest}`, response);
|
|
37
|
-
}
|
|
38
|
-
catch (error) {
|
|
39
|
-
(0, dist_1.log_error)(`send tx by grpc failed!!! txid=${txDigest}`, error);
|
|
40
|
-
}
|
|
41
40
|
}
|
|
42
41
|
});
|
|
43
42
|
this.appConfig = appConfig;
|