@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.
package/lib/index.iife.js CHANGED
@@ -13352,6 +13352,91 @@ var solanaWeb3 = (function (exports) {
13352
13352
  const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
13353
13353
  const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
13354
13354
 
13355
+ class SendTransactionError extends Error {
13356
+ constructor({
13357
+ action,
13358
+ signature,
13359
+ transactionMessage,
13360
+ logs: logs
13361
+ }) {
13362
+ let message;
13363
+ switch (action) {
13364
+ case 'send':
13365
+ 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.';
13366
+ break;
13367
+ case 'simulate':
13368
+ 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.';
13369
+ break;
13370
+ default:
13371
+ message = 'Unknown action';
13372
+ }
13373
+ super(message);
13374
+ this.signature = void 0;
13375
+ this.transactionMessage = void 0;
13376
+ this.logs = void 0;
13377
+ this.signature = signature;
13378
+ this.transactionMessage = transactionMessage;
13379
+ this.logs = logs ? logs : undefined;
13380
+ }
13381
+ get transactionError() {
13382
+ return {
13383
+ message: this.transactionMessage,
13384
+ logs: Array.isArray(this.logs) ? this.logs : undefined
13385
+ };
13386
+ }
13387
+ async getLogs(connection) {
13388
+ if (!Array.isArray(this.logs)) {
13389
+ this.logs = new Promise((resolve, reject) => {
13390
+ connection.getTransaction(this.signature).then(tx => {
13391
+ if (tx && tx.meta && tx.meta.logMessages) {
13392
+ const logs = tx.meta.logMessages;
13393
+ this.logs = logs;
13394
+ resolve(logs);
13395
+ } else {
13396
+ reject(new Error('Log messages not found'));
13397
+ }
13398
+ }).catch(reject);
13399
+ });
13400
+ }
13401
+ return await this.logs;
13402
+ }
13403
+ }
13404
+
13405
+ // Keep in sync with client/src/rpc_custom_errors.rs
13406
+ // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
13407
+ const SolanaJSONRPCErrorCode = {
13408
+ JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
13409
+ JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
13410
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
13411
+ JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
13412
+ JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
13413
+ JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
13414
+ JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
13415
+ JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
13416
+ JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
13417
+ JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
13418
+ JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
13419
+ JSON_RPC_SCAN_ERROR: -32012,
13420
+ JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
13421
+ JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
13422
+ JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
13423
+ JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
13424
+ };
13425
+ class SolanaJSONRPCError extends Error {
13426
+ constructor({
13427
+ code,
13428
+ message,
13429
+ data
13430
+ }, customMessage) {
13431
+ super(customMessage != null ? `${customMessage}: ${message}` : message);
13432
+ this.code = void 0;
13433
+ this.data = void 0;
13434
+ this.code = code;
13435
+ this.data = data;
13436
+ this.name = 'SolanaJSONRPCError';
13437
+ }
13438
+ }
13439
+
13355
13440
  /**
13356
13441
  * Sign, send and confirm a transaction.
13357
13442
  *
@@ -13398,6 +13483,13 @@ var solanaWeb3 = (function (exports) {
13398
13483
  status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
13399
13484
  }
13400
13485
  if (status.err) {
13486
+ if (signature != null) {
13487
+ throw new SendTransactionError({
13488
+ action: 'send',
13489
+ signature: signature,
13490
+ transactionMessage: `Status: (${JSON.stringify(status)})`
13491
+ });
13492
+ }
13401
13493
  throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
13402
13494
  }
13403
13495
  return signature;
@@ -16086,49 +16178,6 @@ var solanaWeb3 = (function (exports) {
16086
16178
  }
16087
16179
  }
16088
16180
 
16089
- class SendTransactionError extends Error {
16090
- constructor(message, logs) {
16091
- super(message);
16092
- this.logs = void 0;
16093
- this.logs = logs;
16094
- }
16095
- }
16096
-
16097
- // Keep in sync with client/src/rpc_custom_errors.rs
16098
- // Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
16099
- const SolanaJSONRPCErrorCode = {
16100
- JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
16101
- JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
16102
- JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
16103
- JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
16104
- JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
16105
- JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
16106
- JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
16107
- JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
16108
- JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
16109
- JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
16110
- JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
16111
- JSON_RPC_SCAN_ERROR: -32012,
16112
- JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
16113
- JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
16114
- JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
16115
- JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
16116
- };
16117
- class SolanaJSONRPCError extends Error {
16118
- constructor({
16119
- code,
16120
- message,
16121
- data
16122
- }, customMessage) {
16123
- super(customMessage != null ? `${customMessage}: ${message}` : message);
16124
- this.code = void 0;
16125
- this.data = void 0;
16126
- this.code = code;
16127
- this.data = data;
16128
- this.name = 'SolanaJSONRPCError';
16129
- }
16130
- }
16131
-
16132
16181
  var fetchImpl = globalThis.fetch;
16133
16182
 
16134
16183
  var client = {};
@@ -20642,7 +20691,12 @@ var solanaWeb3 = (function (exports) {
20642
20691
  console.error(res.error.message, logTrace);
20643
20692
  }
20644
20693
  }
20645
- throw new SendTransactionError('failed to simulate transaction: ' + res.error.message, logs);
20694
+ throw new SendTransactionError({
20695
+ action: 'simulate',
20696
+ signature: '',
20697
+ transactionMessage: res.error.message,
20698
+ logs: logs
20699
+ });
20646
20700
  }
20647
20701
  return res.result;
20648
20702
  }
@@ -20743,11 +20797,16 @@ var solanaWeb3 = (function (exports) {
20743
20797
  const unsafeRes = await this._rpcRequest('sendTransaction', args);
20744
20798
  const res = create(unsafeRes, SendTransactionRpcResult);
20745
20799
  if ('error' in res) {
20746
- let logs;
20800
+ let logs = undefined;
20747
20801
  if ('data' in res.error) {
20748
20802
  logs = res.error.data.logs;
20749
20803
  }
20750
- throw new SendTransactionError('failed to send transaction: ' + res.error.message, logs);
20804
+ throw new SendTransactionError({
20805
+ action: skipPreflight ? 'send' : 'simulate',
20806
+ signature: '',
20807
+ transactionMessage: res.error.message,
20808
+ logs: logs
20809
+ });
20751
20810
  }
20752
20811
  return res.result;
20753
20812
  }
@@ -25039,6 +25098,13 @@ var solanaWeb3 = (function (exports) {
25039
25098
  const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
25040
25099
  const status = (await confirmationPromise).value;
25041
25100
  if (status.err) {
25101
+ if (signature != null) {
25102
+ throw new SendTransactionError({
25103
+ action: sendOptions?.skipPreflight ? 'send' : 'simulate',
25104
+ signature: signature,
25105
+ transactionMessage: `Status: (${JSON.stringify(status)})`
25106
+ });
25107
+ }
25042
25108
  throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
25043
25109
  }
25044
25110
  return signature;