@clonegod/ttd-sol-common 1.0.69 → 1.0.71

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,44 @@ 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
+ const slot = result.slot;
55
+ console.log({ _txid, txid: this.txid, slot });
56
+ result.transaction.transaction.signatures = [_txid];
57
+ let tx_result = {
58
+ slot,
59
+ transaction: result.transaction.transaction,
60
+ meta: result.transaction.meta,
61
+ blockTime: Date.now() / 1000,
62
+ version: result.transaction.version
63
+ };
64
+ let swap_result = this.transactionParser.parse_transaction_data(tx_result, this.pool_info);
65
+ let trade_result = this.map_swap_result_to_tx_result(swap_result);
66
+ if (trade_result.success) {
67
+ this.event_emitter.emit(dist_1.TRANSACTION_STATE_SUCCESS, trade_result);
68
+ }
69
+ else {
70
+ this.event_emitter.emit(dist_1.TRANSACTION_STATE_FAILED, trade_result);
71
+ }
72
+ setTimeout(() => {
73
+ console.log('<----------------------------------------------------');
74
+ console.dir(trade_result, { depth: 8 });
75
+ console.log('----------------------------------------------------');
76
+ }, 0);
77
+ }
78
+ catch (err) {
79
+ (0, dist_1.log_error)('parse geyser stream message error!', err);
80
+ return;
81
+ }
44
82
  });
45
83
  }
46
84
  check_tx_result_interval() {
@@ -53,15 +91,15 @@ class TransactionResultChecker {
53
91
  (0, dist_1.log_info)(`check transaction start: seq=[${this.check_count}], txhash= ${this.txid}, trace_id=${this.trace_id}`);
54
92
  try {
55
93
  if (Date.now() - check_start_time < check_timeout) {
56
- let tx_info = yield this.connection.getParsedTransaction(this.txid, {
94
+ let tx_result = yield this.connection.getParsedTransaction(this.txid, {
57
95
  commitment: constants_1.COMMITMENT_LEVEL.CONFIRMED,
58
96
  maxSupportedTransactionVersion: 0,
59
97
  });
60
- if ((0, dist_1.isEmpty)(tx_info)) {
98
+ if ((0, dist_1.isEmpty)(tx_result)) {
61
99
  return;
62
100
  }
63
101
  clearInterval(intervalId);
64
- let swap_result = this.transactionParser.parse_transaction_data(tx_info, this.pool_info);
102
+ let swap_result = this.transactionParser.parse_transaction_data(tx_result, this.pool_info);
65
103
  let trade_result = this.map_swap_result_to_tx_result(swap_result);
66
104
  if (trade_result.success) {
67
105
  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.71",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "types/index.d.ts",