@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/lib/index.d.ts CHANGED
@@ -3753,8 +3753,21 @@ export class BpfLoader {
3753
3753
  }
3754
3754
 
3755
3755
  export class SendTransactionError extends Error {
3756
- logs: string[] | undefined;
3757
- constructor(message: string, logs?: string[]);
3756
+ private signature;
3757
+ private transactionMessage;
3758
+ private transactionLogs?;
3759
+ private resolvedLogs;
3760
+ constructor({ action, signature, transactionMessage, transactionLogs, }: {
3761
+ action: 'send' | 'simulate';
3762
+ signature: TransactionSignature;
3763
+ transactionMessage: string;
3764
+ transactionLogs?: string[];
3765
+ });
3766
+ get transactionError(): {
3767
+ message: string;
3768
+ logs?: string[];
3769
+ };
3770
+ getLogs(connection: Connection): Promise<string[]>;
3758
3771
  }
3759
3772
  export const SolanaJSONRPCErrorCode: {
3760
3773
  readonly JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001;
package/lib/index.esm.js CHANGED
@@ -13,8 +13,8 @@ import require$$0$2, { Agent as Agent$1 } from 'https';
13
13
  import { coerce, instance, string, tuple, literal, unknown, type, number, array, nullable, optional, boolean, record, union, create, any, assert as assert$1 } from 'superstruct';
14
14
  import RpcClient from 'jayson/lib/client/browser';
15
15
  import * as nodeFetch from 'node-fetch';
16
- import RpcWebSocketCommonClient from 'rpc-websockets/dist/lib/client';
17
- import WebsocketFactory from 'rpc-websockets/dist/lib/client/websocket';
16
+ import RpcWebSocketCommonClient from 'rpc-websockets/dist/lib/client.cjs';
17
+ import WebsocketFactory from 'rpc-websockets/dist/lib/client/websocket.cjs';
18
18
  import { keccak_256 } from '@noble/hashes/sha3';
19
19
  import { secp256k1 } from '@noble/curves/secp256k1';
20
20
 
@@ -2125,6 +2125,94 @@ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111
2125
2125
  const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2126
2126
  const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2127
2127
 
2128
+ class SendTransactionError extends Error {
2129
+ constructor({
2130
+ action,
2131
+ signature,
2132
+ transactionMessage,
2133
+ transactionLogs
2134
+ }) {
2135
+ let message;
2136
+ switch (action) {
2137
+ case 'send':
2138
+ message = `Transaction ${signature} resulted in an error. \n` + `${transactionMessage}. ` + (transactionLogs ? `Logs: \n${JSON.stringify(transactionLogs.slice(-10), null, 2)}. ` : '') + '\nCatch the SendTransactionError and call `getLogs()` on it for full details.';
2139
+ break;
2140
+ case 'simulate':
2141
+ message = `Simulation failed. \nMessage: ${transactionMessage}. \n` + (transactionLogs ? `Logs: \n${JSON.stringify(transactionLogs.slice(-10), null, 2)}. ` : '') + '\nCatch the SendTransactionError and call `getLogs()` on it for full details.';
2142
+ break;
2143
+ default:
2144
+ message = 'Unknown action';
2145
+ }
2146
+ super(message);
2147
+ this.signature = void 0;
2148
+ this.transactionMessage = void 0;
2149
+ this.transactionLogs = void 0;
2150
+ this.resolvedLogs = void 0;
2151
+ this.signature = signature;
2152
+ this.transactionMessage = transactionMessage;
2153
+ this.transactionLogs = transactionLogs;
2154
+ this.resolvedLogs = transactionLogs ? transactionLogs : undefined;
2155
+ }
2156
+ get transactionError() {
2157
+ return {
2158
+ message: this.transactionMessage,
2159
+ logs: this.transactionLogs
2160
+ };
2161
+ }
2162
+ async getLogs(connection) {
2163
+ if (this.resolvedLogs === undefined) {
2164
+ this.resolvedLogs = new Promise((resolve, reject) => {
2165
+ connection.getTransaction(this.signature).then(tx => {
2166
+ if (tx && tx.meta && tx.meta.logMessages) {
2167
+ const logs = tx.meta.logMessages;
2168
+ this.resolvedLogs = logs;
2169
+ this.transactionLogs = logs;
2170
+ resolve(logs);
2171
+ } else {
2172
+ reject(new Error('Log messages not found'));
2173
+ }
2174
+ }).catch(reject);
2175
+ });
2176
+ }
2177
+ return await this.resolvedLogs;
2178
+ }
2179
+ }
2180
+
2181
+ // Keep in sync with client/src/rpc_custom_errors.rs
2182
+ // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
2183
+ const SolanaJSONRPCErrorCode = {
2184
+ JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
2185
+ JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
2186
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
2187
+ JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
2188
+ JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
2189
+ JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
2190
+ JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
2191
+ JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
2192
+ JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
2193
+ JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
2194
+ JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
2195
+ JSON_RPC_SCAN_ERROR: -32012,
2196
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
2197
+ JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
2198
+ JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
2199
+ JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
2200
+ };
2201
+ class SolanaJSONRPCError extends Error {
2202
+ constructor({
2203
+ code,
2204
+ message,
2205
+ data
2206
+ }, customMessage) {
2207
+ super(customMessage != null ? `${customMessage}: ${message}` : message);
2208
+ this.code = void 0;
2209
+ this.data = void 0;
2210
+ this.code = code;
2211
+ this.data = data;
2212
+ this.name = 'SolanaJSONRPCError';
2213
+ }
2214
+ }
2215
+
2128
2216
  /**
2129
2217
  * Sign, send and confirm a transaction.
2130
2218
  *
@@ -2171,6 +2259,13 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
2171
2259
  status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
2172
2260
  }
2173
2261
  if (status.err) {
2262
+ if (signature != null) {
2263
+ throw new SendTransactionError({
2264
+ action: 'send',
2265
+ signature: signature,
2266
+ transactionMessage: `Status: (${JSON.stringify(status)})`
2267
+ });
2268
+ }
2174
2269
  throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
2175
2270
  }
2176
2271
  return signature;
@@ -4087,49 +4182,6 @@ class EpochSchedule {
4087
4182
  }
4088
4183
  }
4089
4184
 
4090
- class SendTransactionError extends Error {
4091
- constructor(message, logs) {
4092
- super(message);
4093
- this.logs = void 0;
4094
- this.logs = logs;
4095
- }
4096
- }
4097
-
4098
- // Keep in sync with client/src/rpc_custom_errors.rs
4099
- // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
4100
- const SolanaJSONRPCErrorCode = {
4101
- JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
4102
- JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
4103
- JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
4104
- JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
4105
- JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
4106
- JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
4107
- JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
4108
- JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
4109
- JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
4110
- JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
4111
- JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
4112
- JSON_RPC_SCAN_ERROR: -32012,
4113
- JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
4114
- JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
4115
- JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
4116
- JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
4117
- };
4118
- class SolanaJSONRPCError extends Error {
4119
- constructor({
4120
- code,
4121
- message,
4122
- data
4123
- }, customMessage) {
4124
- super(customMessage != null ? `${customMessage}: ${message}` : message);
4125
- this.code = void 0;
4126
- this.data = void 0;
4127
- this.code = code;
4128
- this.data = data;
4129
- this.name = 'SolanaJSONRPCError';
4130
- }
4131
- }
4132
-
4133
4185
  var fetchImpl = typeof globalThis.fetch === 'function' ?
4134
4186
  // The Fetch API is supported experimentally in Node 17.5+ and natively in Node 18+.
4135
4187
  globalThis.fetch :
@@ -4248,7 +4300,7 @@ function makeWebsocketUrl(endpoint) {
4248
4300
  const websocketPort =
4249
4301
  // Only shift the port by +1 as a convention for ws(s) only if given endpoint
4250
4302
  // is explicitly specifying the endpoint port (HTTP-based RPC), assuming
4251
- // we're directly trying to connect to solana-validator's ws listening port.
4303
+ // we're directly trying to connect to agave-validator's ws listening port.
4252
4304
  // When the endpoint omits the port, we're connecting to the protocol
4253
4305
  // default ports: http(80) or https(443) and it's assumed we're behind a reverse
4254
4306
  // proxy which manages WebSocket upgrade and backend port redirection.
@@ -7910,7 +7962,12 @@ class Connection {
7910
7962
  console.error(res.error.message, logTrace);
7911
7963
  }
7912
7964
  }
7913
- throw new SendTransactionError('failed to simulate transaction: ' + res.error.message, logs);
7965
+ throw new SendTransactionError({
7966
+ action: 'simulate',
7967
+ signature: '',
7968
+ transactionMessage: res.error.message,
7969
+ transactionLogs: logs
7970
+ });
7914
7971
  }
7915
7972
  return res.result;
7916
7973
  }
@@ -8011,11 +8068,16 @@ class Connection {
8011
8068
  const unsafeRes = await this._rpcRequest('sendTransaction', args);
8012
8069
  const res = create(unsafeRes, SendTransactionRpcResult);
8013
8070
  if ('error' in res) {
8014
- let logs;
8071
+ let logs = undefined;
8015
8072
  if ('data' in res.error) {
8016
8073
  logs = res.error.data.logs;
8017
8074
  }
8018
- throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs);
8075
+ throw new SendTransactionError({
8076
+ action: skipPreflight ? 'send' : 'simulate',
8077
+ signature: '',
8078
+ transactionMessage: res.error.message,
8079
+ transactionLogs: logs
8080
+ });
8019
8081
  }
8020
8082
  return res.result;
8021
8083
  }
@@ -11003,6 +11065,13 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
11003
11065
  const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
11004
11066
  const status = (await confirmationPromise).value;
11005
11067
  if (status.err) {
11068
+ if (signature != null) {
11069
+ throw new SendTransactionError({
11070
+ action: sendOptions?.skipPreflight ? 'send' : 'simulate',
11071
+ signature: signature,
11072
+ transactionMessage: `Status: (${JSON.stringify(status)})`
11073
+ });
11074
+ }
11006
11075
  throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
11007
11076
  }
11008
11077
  return signature;