@atomiqlabs/chain-solana 10.0.0-dev.9 → 12.0.0

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.
@@ -48,6 +48,10 @@ export declare class SolanaChainInterface implements ChainInterface<SolanaTx, So
48
48
  deserializeTx(txData: string): Promise<SolanaTx>;
49
49
  getTxIdStatus(txId: string): Promise<"not_found" | "pending" | "success" | "reverted">;
50
50
  getTxStatus(tx: string): Promise<"not_found" | "pending" | "success" | "reverted">;
51
+ getFinalizedBlock(): Promise<{
52
+ height: number;
53
+ blockHash: string;
54
+ }>;
51
55
  offBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): boolean;
52
56
  onBeforeTxReplace(callback: (oldTx: string, oldTxId: string, newTx: string, newTxId: string) => Promise<void>): void;
53
57
  onBeforeTxSigned(callback: (tx: SolanaTx) => Promise<void>): void;
@@ -76,6 +76,13 @@ class SolanaChainInterface {
76
76
  getTxStatus(tx) {
77
77
  return this.Transactions.getTxStatus(tx);
78
78
  }
79
+ async getFinalizedBlock() {
80
+ const { block } = await this.Blocks.findLatestParsedBlock("finalized");
81
+ return {
82
+ height: block.blockHeight,
83
+ blockHash: block.blockhash
84
+ };
85
+ }
79
86
  ///////////////////////////////////
80
87
  //// Callbacks & handlers
81
88
  offBeforeTxReplace(callback) {
@@ -6,6 +6,7 @@ const SolanaModule_1 = require("../SolanaModule");
6
6
  const bs58 = require("bs58");
7
7
  const Utils_1 = require("../../../utils/Utils");
8
8
  const buffer_1 = require("buffer");
9
+ const base_1 = require("@atomiqlabs/base");
9
10
  class SolanaTransactions extends SolanaModule_1.SolanaModule {
10
11
  /**
11
12
  * Sends raw solana transaction, first through the cbkSendTransaction callback (for e.g. sending the transaction
@@ -54,7 +55,7 @@ class SolanaTransactions extends SolanaModule_1.SolanaModule {
54
55
  resolve(signature);
55
56
  }
56
57
  if (status === "reverted")
57
- reject(new Error("Transaction reverted!"));
58
+ reject(new base_1.TransactionRevertedError("Transaction reverted!"));
58
59
  clearInterval(watchdogInterval);
59
60
  }, this.retryPolicy?.transactionResendInterval || 3000);
60
61
  if (abortSignal != null)
@@ -95,7 +96,7 @@ class SolanaTransactions extends SolanaModule_1.SolanaModule {
95
96
  if (status === "success")
96
97
  return signature;
97
98
  if (status === "reverted")
98
- throw new Error("Transaction reverted!");
99
+ throw new base_1.TransactionRevertedError("Transaction reverted!");
99
100
  if (err instanceof web3_js_1.TransactionExpiredBlockheightExceededError || err.toString().startsWith("TransactionExpiredBlockheightExceededError")) {
100
101
  throw new Error("Transaction expired before confirmation, please try again!");
101
102
  }
@@ -104,7 +105,7 @@ class SolanaTransactions extends SolanaModule_1.SolanaModule {
104
105
  }
105
106
  }
106
107
  if (result.value.err != null)
107
- throw new Error("Transaction reverted!");
108
+ throw new base_1.TransactionRevertedError("Transaction reverted!");
108
109
  return signature;
109
110
  }
110
111
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atomiqlabs/chain-solana",
3
- "version": "10.0.0-dev.9",
3
+ "version": "12.0.0",
4
4
  "description": "Solana specific base implementation",
5
5
  "main": "./dist/index.js",
6
6
  "types:": "./dist/index.d.ts",
@@ -22,7 +22,7 @@
22
22
  "author": "adambor",
23
23
  "license": "ISC",
24
24
  "dependencies": {
25
- "@atomiqlabs/base": "^10.0.0-dev.18",
25
+ "@atomiqlabs/base": "^12.0.0",
26
26
  "@noble/hashes": "^1.7.1",
27
27
  "bn.js": "5.2.1",
28
28
  "bs58": "4.0.1",
@@ -134,6 +134,14 @@ export class SolanaChainInterface implements ChainInterface<
134
134
  return this.Transactions.getTxStatus(tx);
135
135
  }
136
136
 
137
+ async getFinalizedBlock(): Promise<{ height: number; blockHash: string }> {
138
+ const {block} = await this.Blocks.findLatestParsedBlock("finalized");
139
+ return {
140
+ height: block.blockHeight,
141
+ blockHash: block.blockhash
142
+ };
143
+ }
144
+
137
145
 
138
146
  ///////////////////////////////////
139
147
  //// Callbacks & handlers
@@ -9,6 +9,7 @@ import * as bs58 from "bs58";
9
9
  import {tryWithRetries} from "../../../utils/Utils";
10
10
  import {Buffer} from "buffer";
11
11
  import {SolanaSigner} from "../../wallet/SolanaSigner";
12
+ import {TransactionRevertedError} from "@atomiqlabs/base";
12
13
 
13
14
  export type SolanaTx = {tx: Transaction, signers: Signer[]};
14
15
 
@@ -74,7 +75,7 @@ export class SolanaTransactions extends SolanaModule {
74
75
  this.logger.info("txConfirmationAndResendWatchdog(): transaction confirmed from HTTP polling, signature: "+signature);
75
76
  resolve(signature);
76
77
  }
77
- if(status==="reverted") reject(new Error("Transaction reverted!"));
78
+ if(status==="reverted") reject(new TransactionRevertedError("Transaction reverted!"));
78
79
  clearInterval(watchdogInterval);
79
80
  }, this.retryPolicy?.transactionResendInterval || 3000);
80
81
 
@@ -119,14 +120,14 @@ export class SolanaTransactions extends SolanaModule {
119
120
  );
120
121
  this.logger.info("txConfirmFromWebsocket(): transaction status: "+status+" signature: "+signature);
121
122
  if(status==="success") return signature;
122
- if(status==="reverted") throw new Error("Transaction reverted!");
123
+ if(status==="reverted") throw new TransactionRevertedError("Transaction reverted!");
123
124
  if(err instanceof TransactionExpiredBlockheightExceededError || err.toString().startsWith("TransactionExpiredBlockheightExceededError")) {
124
125
  throw new Error("Transaction expired before confirmation, please try again!");
125
126
  } else {
126
127
  throw err;
127
128
  }
128
129
  }
129
- if(result.value.err!=null) throw new Error("Transaction reverted!");
130
+ if(result.value.err!=null) throw new TransactionRevertedError("Transaction reverted!");
130
131
  return signature;
131
132
  }
132
133