@solana/web3.js 1.91.9 → 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.
@@ -2149,6 +2149,94 @@ 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
+ transactionLogs
2158
+ }) {
2159
+ let message;
2160
+ switch (action) {
2161
+ case 'send':
2162
+ 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.';
2163
+ break;
2164
+ case 'simulate':
2165
+ 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.';
2166
+ break;
2167
+ default:
2168
+ message = 'Unknown action';
2169
+ }
2170
+ super(message);
2171
+ this.signature = void 0;
2172
+ this.transactionMessage = void 0;
2173
+ this.transactionLogs = void 0;
2174
+ this.resolvedLogs = void 0;
2175
+ this.signature = signature;
2176
+ this.transactionMessage = transactionMessage;
2177
+ this.transactionLogs = transactionLogs;
2178
+ this.resolvedLogs = transactionLogs ? transactionLogs : undefined;
2179
+ }
2180
+ get transactionError() {
2181
+ return {
2182
+ message: this.transactionMessage,
2183
+ logs: this.transactionLogs
2184
+ };
2185
+ }
2186
+ async getLogs(connection) {
2187
+ if (this.resolvedLogs === undefined) {
2188
+ this.resolvedLogs = new Promise((resolve, reject) => {
2189
+ connection.getTransaction(this.signature).then(tx => {
2190
+ if (tx && tx.meta && tx.meta.logMessages) {
2191
+ const logs = tx.meta.logMessages;
2192
+ this.resolvedLogs = logs;
2193
+ this.transactionLogs = logs;
2194
+ resolve(logs);
2195
+ } else {
2196
+ reject(new Error('Log messages not found'));
2197
+ }
2198
+ }).catch(reject);
2199
+ });
2200
+ }
2201
+ return await this.resolvedLogs;
2202
+ }
2203
+ }
2204
+
2205
+ // Keep in sync with client/src/rpc_custom_errors.rs
2206
+ // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
2207
+ const SolanaJSONRPCErrorCode = {
2208
+ JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
2209
+ JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
2210
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
2211
+ JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
2212
+ JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
2213
+ JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
2214
+ JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
2215
+ JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
2216
+ JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
2217
+ JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
2218
+ JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
2219
+ JSON_RPC_SCAN_ERROR: -32012,
2220
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
2221
+ JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
2222
+ JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
2223
+ JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
2224
+ };
2225
+ class SolanaJSONRPCError extends Error {
2226
+ constructor({
2227
+ code,
2228
+ message,
2229
+ data
2230
+ }, customMessage) {
2231
+ super(customMessage != null ? `${customMessage}: ${message}` : message);
2232
+ this.code = void 0;
2233
+ this.data = void 0;
2234
+ this.code = code;
2235
+ this.data = data;
2236
+ this.name = 'SolanaJSONRPCError';
2237
+ }
2238
+ }
2239
+
2152
2240
  /**
2153
2241
  * Sign, send and confirm a transaction.
2154
2242
  *
@@ -2195,6 +2283,13 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
2195
2283
  status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
2196
2284
  }
2197
2285
  if (status.err) {
2286
+ if (signature != null) {
2287
+ throw new SendTransactionError({
2288
+ action: 'send',
2289
+ signature: signature,
2290
+ transactionMessage: `Status: (${JSON.stringify(status)})`
2291
+ });
2292
+ }
2198
2293
  throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
2199
2294
  }
2200
2295
  return signature;
@@ -3452,49 +3547,6 @@ class EpochSchedule {
3452
3547
  }
3453
3548
  }
3454
3549
 
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
3550
  var fetchImpl = globalThis.fetch;
3499
3551
 
3500
3552
  class RpcWebSocketClient extends RpcWebSocketCommonClient__default.default {
@@ -7245,7 +7297,12 @@ class Connection {
7245
7297
  console.error(res.error.message, logTrace);
7246
7298
  }
7247
7299
  }
7248
- throw new SendTransactionError('failed to simulate transaction: ' + res.error.message, logs);
7300
+ throw new SendTransactionError({
7301
+ action: 'simulate',
7302
+ signature: '',
7303
+ transactionMessage: res.error.message,
7304
+ transactionLogs: logs
7305
+ });
7249
7306
  }
7250
7307
  return res.result;
7251
7308
  }
@@ -7346,11 +7403,16 @@ class Connection {
7346
7403
  const unsafeRes = await this._rpcRequest('sendTransaction', args);
7347
7404
  const res = superstruct.create(unsafeRes, SendTransactionRpcResult);
7348
7405
  if ('error' in res) {
7349
- let logs;
7406
+ let logs = undefined;
7350
7407
  if ('data' in res.error) {
7351
7408
  logs = res.error.data.logs;
7352
7409
  }
7353
- throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs);
7410
+ throw new SendTransactionError({
7411
+ action: skipPreflight ? 'send' : 'simulate',
7412
+ signature: '',
7413
+ transactionMessage: res.error.message,
7414
+ transactionLogs: logs
7415
+ });
7354
7416
  }
7355
7417
  return res.result;
7356
7418
  }
@@ -10338,6 +10400,13 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
10338
10400
  const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
10339
10401
  const status = (await confirmationPromise).value;
10340
10402
  if (status.err) {
10403
+ if (signature != null) {
10404
+ throw new SendTransactionError({
10405
+ action: sendOptions?.skipPreflight ? 'send' : 'simulate',
10406
+ signature: signature,
10407
+ transactionMessage: `Status: (${JSON.stringify(status)})`
10408
+ });
10409
+ }
10341
10410
  throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
10342
10411
  }
10343
10412
  return signature;