@solana/web3.js 1.91.9 → 1.92.1

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.
@@ -2149,6 +2149,91 @@ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111
2149
2149
  const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
2150
2150
  const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
2151
2151
 
2152
+ class SendTransactionError extends Error {
2153
+ constructor({
2154
+ action,
2155
+ signature,
2156
+ transactionMessage,
2157
+ logs: logs
2158
+ }) {
2159
+ let message;
2160
+ switch (action) {
2161
+ case 'send':
2162
+ message = `Transaction ${signature} resulted in an error. \n` + `${transactionMessage}. ` + (logs ? `Logs: \n${JSON.stringify(logs.slice(-10), null, 2)}. ` : '') + '\nCatch the SendTransactionError and call `getLogs()` on it for full details.';
2163
+ break;
2164
+ case 'simulate':
2165
+ message = `Simulation failed. \nMessage: ${transactionMessage}. \n` + (logs ? `Logs: \n${JSON.stringify(logs.slice(-10), null, 2)}. ` : '') + '\nCatch the SendTransactionError and call `getLogs()` on it for full details.';
2166
+ break;
2167
+ default:
2168
+ message = 'Unknown action';
2169
+ }
2170
+ super(message);
2171
+ this.signature = void 0;
2172
+ this.transactionMessage = void 0;
2173
+ this.logs = void 0;
2174
+ this.signature = signature;
2175
+ this.transactionMessage = transactionMessage;
2176
+ this.logs = logs ? logs : undefined;
2177
+ }
2178
+ get transactionError() {
2179
+ return {
2180
+ message: this.transactionMessage,
2181
+ logs: Array.isArray(this.logs) ? this.logs : undefined
2182
+ };
2183
+ }
2184
+ async getLogs(connection) {
2185
+ if (!Array.isArray(this.logs)) {
2186
+ this.logs = new Promise((resolve, reject) => {
2187
+ connection.getTransaction(this.signature).then(tx => {
2188
+ if (tx && tx.meta && tx.meta.logMessages) {
2189
+ const logs = tx.meta.logMessages;
2190
+ this.logs = logs;
2191
+ resolve(logs);
2192
+ } else {
2193
+ reject(new Error('Log messages not found'));
2194
+ }
2195
+ }).catch(reject);
2196
+ });
2197
+ }
2198
+ return await this.logs;
2199
+ }
2200
+ }
2201
+
2202
+ // Keep in sync with client/src/rpc_custom_errors.rs
2203
+ // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
2204
+ const SolanaJSONRPCErrorCode = {
2205
+ JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
2206
+ JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
2207
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
2208
+ JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
2209
+ JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
2210
+ JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
2211
+ JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
2212
+ JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
2213
+ JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
2214
+ JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
2215
+ JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
2216
+ JSON_RPC_SCAN_ERROR: -32012,
2217
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
2218
+ JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
2219
+ JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
2220
+ JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
2221
+ };
2222
+ class SolanaJSONRPCError extends Error {
2223
+ constructor({
2224
+ code,
2225
+ message,
2226
+ data
2227
+ }, customMessage) {
2228
+ super(customMessage != null ? `${customMessage}: ${message}` : message);
2229
+ this.code = void 0;
2230
+ this.data = void 0;
2231
+ this.code = code;
2232
+ this.data = data;
2233
+ this.name = 'SolanaJSONRPCError';
2234
+ }
2235
+ }
2236
+
2152
2237
  /**
2153
2238
  * Sign, send and confirm a transaction.
2154
2239
  *
@@ -2195,6 +2280,13 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
2195
2280
  status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
2196
2281
  }
2197
2282
  if (status.err) {
2283
+ if (signature != null) {
2284
+ throw new SendTransactionError({
2285
+ action: 'send',
2286
+ signature: signature,
2287
+ transactionMessage: `Status: (${JSON.stringify(status)})`
2288
+ });
2289
+ }
2198
2290
  throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
2199
2291
  }
2200
2292
  return signature;
@@ -3452,49 +3544,6 @@ class EpochSchedule {
3452
3544
  }
3453
3545
  }
3454
3546
 
3455
- class SendTransactionError extends Error {
3456
- constructor(message, logs) {
3457
- super(message);
3458
- this.logs = void 0;
3459
- this.logs = logs;
3460
- }
3461
- }
3462
-
3463
- // Keep in sync with client/src/rpc_custom_errors.rs
3464
- // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
3465
- const SolanaJSONRPCErrorCode = {
3466
- JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
3467
- JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
3468
- JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
3469
- JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
3470
- JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
3471
- JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
3472
- JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
3473
- JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
3474
- JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
3475
- JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
3476
- JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
3477
- JSON_RPC_SCAN_ERROR: -32012,
3478
- JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
3479
- JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
3480
- JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
3481
- JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
3482
- };
3483
- class SolanaJSONRPCError extends Error {
3484
- constructor({
3485
- code,
3486
- message,
3487
- data
3488
- }, customMessage) {
3489
- super(customMessage != null ? `${customMessage}: ${message}` : message);
3490
- this.code = void 0;
3491
- this.data = void 0;
3492
- this.code = code;
3493
- this.data = data;
3494
- this.name = 'SolanaJSONRPCError';
3495
- }
3496
- }
3497
-
3498
3547
  var fetchImpl = globalThis.fetch;
3499
3548
 
3500
3549
  class RpcWebSocketClient extends RpcWebSocketCommonClient__default.default {
@@ -7245,7 +7294,12 @@ class Connection {
7245
7294
  console.error(res.error.message, logTrace);
7246
7295
  }
7247
7296
  }
7248
- throw new SendTransactionError('failed to simulate transaction: ' + res.error.message, logs);
7297
+ throw new SendTransactionError({
7298
+ action: 'simulate',
7299
+ signature: '',
7300
+ transactionMessage: res.error.message,
7301
+ logs: logs
7302
+ });
7249
7303
  }
7250
7304
  return res.result;
7251
7305
  }
@@ -7346,11 +7400,16 @@ class Connection {
7346
7400
  const unsafeRes = await this._rpcRequest('sendTransaction', args);
7347
7401
  const res = superstruct.create(unsafeRes, SendTransactionRpcResult);
7348
7402
  if ('error' in res) {
7349
- let logs;
7403
+ let logs = undefined;
7350
7404
  if ('data' in res.error) {
7351
7405
  logs = res.error.data.logs;
7352
7406
  }
7353
- throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs);
7407
+ throw new SendTransactionError({
7408
+ action: skipPreflight ? 'send' : 'simulate',
7409
+ signature: '',
7410
+ transactionMessage: res.error.message,
7411
+ logs: logs
7412
+ });
7354
7413
  }
7355
7414
  return res.result;
7356
7415
  }
@@ -10338,6 +10397,13 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
10338
10397
  const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
10339
10398
  const status = (await confirmationPromise).value;
10340
10399
  if (status.err) {
10400
+ if (signature != null) {
10401
+ throw new SendTransactionError({
10402
+ action: sendOptions?.skipPreflight ? 'send' : 'simulate',
10403
+ signature: signature,
10404
+ transactionMessage: `Status: (${JSON.stringify(status)})`
10405
+ });
10406
+ }
10341
10407
  throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
10342
10408
  }
10343
10409
  return signature;