@clonegod/ttd-sol-common 1.0.69 → 1.0.70

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.
@@ -21,6 +21,7 @@ export declare class TransactionResultChecker {
21
21
  constructor(env_args: any, event_emitter: EventEmitter, context: TradeContext, txid: string);
22
22
  init_tx_status(): this;
23
23
  check(): Promise<void>;
24
+ on_subscibe_transaction(): void;
24
25
  check_tx_result_interval(): Promise<void>;
25
26
  map_swap_result_to_tx_result(swap_result: StandardSwapDetailType): TradeResultType;
26
27
  }
@@ -41,6 +41,36 @@ class TransactionResultChecker {
41
41
  check() {
42
42
  return __awaiter(this, void 0, void 0, function* () {
43
43
  this.check_tx_result_interval();
44
+ this.on_subscibe_transaction();
45
+ });
46
+ }
47
+ on_subscibe_transaction() {
48
+ this.event_emitter.once(constants_1.LOCAL_EVENT_NAME.EVENT_WALLET_TRANSACTION + '#' + this.txid, (messageStr) => {
49
+ try {
50
+ (0, dist_1.log_debug)('on events: EVENT_WALLET_TRANSACTION', messageStr);
51
+ const messageObj = JSON.parse(messageStr);
52
+ const result = messageObj.params.result;
53
+ const _txid = result.signature;
54
+ console.log({ _txid, txid: this.txid, });
55
+ let tx_result = result.transaction;
56
+ let swap_result = this.transactionParser.parse_transaction_data(tx_result, this.pool_info);
57
+ let trade_result = this.map_swap_result_to_tx_result(swap_result);
58
+ if (trade_result.success) {
59
+ this.event_emitter.emit(dist_1.TRANSACTION_STATE_SUCCESS, trade_result);
60
+ }
61
+ else {
62
+ this.event_emitter.emit(dist_1.TRANSACTION_STATE_FAILED, trade_result);
63
+ }
64
+ setTimeout(() => {
65
+ console.log('<----------------------------------------------------');
66
+ console.dir(trade_result, { depth: 8 });
67
+ console.log('----------------------------------------------------');
68
+ }, 0);
69
+ }
70
+ catch (err) {
71
+ (0, dist_1.log_error)('parse geyser stream message error!', err);
72
+ return;
73
+ }
44
74
  });
45
75
  }
46
76
  check_tx_result_interval() {
@@ -53,15 +83,15 @@ class TransactionResultChecker {
53
83
  (0, dist_1.log_info)(`check transaction start: seq=[${this.check_count}], txhash= ${this.txid}, trace_id=${this.trace_id}`);
54
84
  try {
55
85
  if (Date.now() - check_start_time < check_timeout) {
56
- let tx_info = yield this.connection.getParsedTransaction(this.txid, {
86
+ let tx_result = yield this.connection.getParsedTransaction(this.txid, {
57
87
  commitment: constants_1.COMMITMENT_LEVEL.CONFIRMED,
58
88
  maxSupportedTransactionVersion: 0,
59
89
  });
60
- if ((0, dist_1.isEmpty)(tx_info)) {
90
+ if ((0, dist_1.isEmpty)(tx_result)) {
61
91
  return;
62
92
  }
63
93
  clearInterval(intervalId);
64
- let swap_result = this.transactionParser.parse_transaction_data(tx_info, this.pool_info);
94
+ let swap_result = this.transactionParser.parse_transaction_data(tx_result, this.pool_info);
65
95
  let trade_result = this.map_swap_result_to_tx_result(swap_result);
66
96
  if (trade_result.success) {
67
97
  this.event_emitter.emit(dist_1.TRANSACTION_STATE_SUCCESS, trade_result);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@clonegod/ttd-sol-common",
3
- "version": "1.0.69",
3
+ "version": "1.0.70",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",