@solana/web3.js 1.91.8 → 1.92.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@solana/web3.js",
3
- "version": "1.91.8",
3
+ "version": "1.92.0",
4
4
  "description": "Solana Javascript API",
5
5
  "keywords": [
6
6
  "api",
@@ -55,7 +55,7 @@
55
55
  "test:unit:node": "cross-env NODE_ENV=test NODE_OPTIONS='--import tsx' mocha './test/**/*.test.ts'"
56
56
  },
57
57
  "dependencies": {
58
- "@babel/runtime": "^7.24.5",
58
+ "@babel/runtime": "^7.24.6",
59
59
  "@noble/curves": "^1.4.0",
60
60
  "@noble/hashes": "^1.4.0",
61
61
  "@solana/buffer-layout": "^4.0.1",
@@ -68,7 +68,7 @@
68
68
  "fast-stable-stringify": "^1.0.0",
69
69
  "jayson": "^4.1.0",
70
70
  "node-fetch": "^2.7.0",
71
- "rpc-websockets": "^7.11.0",
72
- "superstruct": "^0.14.2"
71
+ "rpc-websockets": "^7.11.1",
72
+ "superstruct": "^1.0.4"
73
73
  }
74
74
  }
@@ -1 +1 @@
1
- export {default} from 'rpc-websockets/dist/lib/client/websocket.browser';
1
+ export {default} from 'rpc-websockets/dist/lib/client/websocket.browser.cjs';
@@ -1 +1 @@
1
- export {default} from 'rpc-websockets/dist/lib/client/websocket.browser';
1
+ export {default} from 'rpc-websockets/dist/lib/client/websocket.browser.cjs';
package/src/connection.ts CHANGED
@@ -5782,10 +5782,13 @@ export class Connection {
5782
5782
  console.error(res.error.message, logTrace);
5783
5783
  }
5784
5784
  }
5785
- throw new SendTransactionError(
5786
- 'failed to simulate transaction: ' + res.error.message,
5787
- logs,
5788
- );
5785
+
5786
+ throw new SendTransactionError({
5787
+ action: 'simulate',
5788
+ signature: '',
5789
+ transactionMessage: res.error.message,
5790
+ transactionLogs: logs,
5791
+ });
5789
5792
  }
5790
5793
  return res.result;
5791
5794
  }
@@ -5916,14 +5919,17 @@ export class Connection {
5916
5919
  const unsafeRes = await this._rpcRequest('sendTransaction', args);
5917
5920
  const res = create(unsafeRes, SendTransactionRpcResult);
5918
5921
  if ('error' in res) {
5919
- let logs;
5922
+ let logs = undefined;
5920
5923
  if ('data' in res.error) {
5921
5924
  logs = res.error.data.logs;
5922
5925
  }
5923
- throw new SendTransactionError(
5924
- 'failed to send transaction: ' + res.error.message,
5925
- logs,
5926
- );
5926
+
5927
+ throw new SendTransactionError({
5928
+ action: skipPreflight ? 'send' : 'simulate',
5929
+ signature: '',
5930
+ transactionMessage: res.error.message,
5931
+ transactionLogs: logs,
5932
+ });
5927
5933
  }
5928
5934
  return res.result;
5929
5935
  }
package/src/errors.ts CHANGED
@@ -1,10 +1,77 @@
1
+ import {Connection} from './connection';
2
+ import {TransactionSignature} from './transaction';
3
+
1
4
  export class SendTransactionError extends Error {
2
- logs: string[] | undefined;
5
+ private signature: TransactionSignature;
6
+ private transactionMessage: string;
7
+ private transactionLogs?: string[];
8
+ private resolvedLogs: string[] | Promise<string[]> | undefined;
9
+
10
+ constructor({
11
+ action,
12
+ signature,
13
+ transactionMessage,
14
+ transactionLogs,
15
+ }: {
16
+ action: 'send' | 'simulate';
17
+ signature: TransactionSignature;
18
+ transactionMessage: string;
19
+ transactionLogs?: string[];
20
+ }) {
21
+ let message: string;
3
22
 
4
- constructor(message: string, logs?: string[]) {
23
+ switch (action) {
24
+ case 'send':
25
+ message =
26
+ `Transaction ${signature} resulted in an error. \n` +
27
+ `${transactionMessage}. ` +
28
+ (transactionLogs
29
+ ? `Logs: \n${JSON.stringify(transactionLogs.slice(-10), null, 2)}. `
30
+ : '') +
31
+ '\nCatch the SendTransactionError and call `getLogs()` on it for full details.';
32
+ break;
33
+ case 'simulate':
34
+ message =
35
+ `Simulation failed. \nMessage: ${transactionMessage}. \n` +
36
+ (transactionLogs
37
+ ? `Logs: \n${JSON.stringify(transactionLogs.slice(-10), null, 2)}. `
38
+ : '') +
39
+ '\nCatch the SendTransactionError and call `getLogs()` on it for full details.';
40
+ break;
41
+ default:
42
+ message = 'Unknown action';
43
+ }
5
44
  super(message);
6
45
 
7
- this.logs = logs;
46
+ this.signature = signature;
47
+ this.transactionMessage = transactionMessage;
48
+ this.transactionLogs = transactionLogs;
49
+ this.resolvedLogs = transactionLogs ? transactionLogs : undefined;
50
+ }
51
+
52
+ get transactionError(): {message: string; logs?: string[]} {
53
+ return {message: this.transactionMessage, logs: this.transactionLogs};
54
+ }
55
+
56
+ async getLogs(connection: Connection): Promise<string[]> {
57
+ if (this.resolvedLogs === undefined) {
58
+ this.resolvedLogs = new Promise((resolve, reject) => {
59
+ connection
60
+ .getTransaction(this.signature)
61
+ .then(tx => {
62
+ if (tx && tx.meta && tx.meta.logMessages) {
63
+ const logs = tx.meta.logMessages;
64
+ this.resolvedLogs = logs;
65
+ this.transactionLogs = logs;
66
+ resolve(logs);
67
+ } else {
68
+ reject(new Error('Log messages not found'));
69
+ }
70
+ })
71
+ .catch(reject);
72
+ });
73
+ }
74
+ return await this.resolvedLogs;
8
75
  }
9
76
  }
10
77
 
@@ -1,4 +1,4 @@
1
- import {ICommonWebSocketFactory} from 'rpc-websockets/dist/lib/client/client.types';
2
- import WebsocketFactory from 'rpc-websockets/dist/lib/client/websocket';
1
+ import {ICommonWebSocketFactory} from 'rpc-websockets/dist/lib/client/client.types.cjs';
2
+ import WebsocketFactory from 'rpc-websockets/dist/lib/client/websocket.cjs';
3
3
 
4
4
  export default WebsocketFactory as ICommonWebSocketFactory;
@@ -1,11 +1,11 @@
1
- import RpcWebSocketCommonClient from 'rpc-websockets/dist/lib/client';
2
- import RpcWebSocketBrowserFactory from 'rpc-websockets/dist/lib/client/websocket.browser';
1
+ import RpcWebSocketCommonClient from 'rpc-websockets/dist/lib/client.cjs';
2
+ import WebSocketBrowserImpl from 'rpc-websockets/dist/lib/client/websocket.cjs';
3
3
  import {
4
4
  ICommonWebSocket,
5
5
  IWSClientAdditionalOptions,
6
6
  NodeWebSocketType,
7
7
  NodeWebSocketTypeOptions,
8
- } from 'rpc-websockets/dist/lib/client/client.types';
8
+ } from 'rpc-websockets/dist/lib/client/client.types.cjs';
9
9
 
10
10
  import createRpc from './rpc-websocket-factory';
11
11
 
@@ -32,9 +32,9 @@ export default class RpcWebSocketClient extends RpcWebSocketCommonClient {
32
32
  ...options,
33
33
  });
34
34
  if ('socket' in rpc) {
35
- this.underlyingSocket = (
36
- rpc as ReturnType<typeof RpcWebSocketBrowserFactory>
37
- ).socket;
35
+ this.underlyingSocket = rpc.socket as ReturnType<
36
+ typeof WebSocketBrowserImpl
37
+ >;
38
38
  } else {
39
39
  this.underlyingSocket = rpc as NodeWebSocketType;
40
40
  }
@@ -17,7 +17,7 @@ export function makeWebsocketUrl(endpoint: string) {
17
17
  const websocketPort =
18
18
  // Only shift the port by +1 as a convention for ws(s) only if given endpoint
19
19
  // is explicitly specifying the endpoint port (HTTP-based RPC), assuming
20
- // we're directly trying to connect to solana-validator's ws listening port.
20
+ // we're directly trying to connect to agave-validator's ws listening port.
21
21
  // When the endpoint omits the port, we're connecting to the protocol
22
22
  // default ports: http(80) or https(443) and it's assumed we're behind a reverse
23
23
  // proxy which manages WebSocket upgrade and backend port redirection.
@@ -8,6 +8,7 @@ import {
8
8
  } from '../connection';
9
9
  import type {TransactionSignature} from '../transaction';
10
10
  import type {ConfirmOptions} from '../connection';
11
+ import {SendTransactionError} from '../errors';
11
12
 
12
13
  /**
13
14
  * Send and confirm a raw transaction
@@ -93,6 +94,13 @@ export async function sendAndConfirmRawTransaction(
93
94
  const status = (await confirmationPromise).value;
94
95
 
95
96
  if (status.err) {
97
+ if (signature != null) {
98
+ throw new SendTransactionError({
99
+ action: sendOptions?.skipPreflight ? 'send' : 'simulate',
100
+ signature: signature,
101
+ transactionMessage: `Status: (${JSON.stringify(status)})`,
102
+ });
103
+ }
96
104
  throw new Error(
97
105
  `Raw transaction ${signature} failed (${JSON.stringify(status)})`,
98
106
  );
@@ -3,6 +3,7 @@ import {Transaction} from '../transaction';
3
3
  import type {ConfirmOptions} from '../connection';
4
4
  import type {Signer} from '../keypair';
5
5
  import type {TransactionSignature} from '../transaction';
6
+ import {SendTransactionError} from '../errors';
6
7
 
7
8
  /**
8
9
  * Sign, send and confirm a transaction.
@@ -89,6 +90,13 @@ export async function sendAndConfirmTransaction(
89
90
  }
90
91
 
91
92
  if (status.err) {
93
+ if (signature != null) {
94
+ throw new SendTransactionError({
95
+ action: 'send',
96
+ signature: signature,
97
+ transactionMessage: `Status: (${JSON.stringify(status)})`,
98
+ });
99
+ }
92
100
  throw new Error(
93
101
  `Transaction ${signature} failed (${JSON.stringify(status)})`,
94
102
  );