@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.browser.cjs.js +112 -46
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +112 -46
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +112 -46
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +14 -2
- package/lib/index.esm.js +112 -46
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +112 -46
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +2 -2
- package/lib/index.iife.min.js.map +1 -1
- package/lib/index.native.js +112 -46
- package/lib/index.native.js.map +1 -1
- package/package.json +1 -1
- package/src/connection.ts +15 -9
- package/src/errors.ts +70 -3
- package/src/utils/send-and-confirm-raw-transaction.ts +8 -0
- package/src/utils/send-and-confirm-transaction.ts +8 -0
package/lib/index.browser.esm.js
CHANGED
|
@@ -2121,6 +2121,91 @@ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111
|
|
|
2121
2121
|
const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
|
|
2122
2122
|
const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
2123
2123
|
|
|
2124
|
+
class SendTransactionError extends Error {
|
|
2125
|
+
constructor({
|
|
2126
|
+
action,
|
|
2127
|
+
signature,
|
|
2128
|
+
transactionMessage,
|
|
2129
|
+
logs: logs
|
|
2130
|
+
}) {
|
|
2131
|
+
let message;
|
|
2132
|
+
switch (action) {
|
|
2133
|
+
case 'send':
|
|
2134
|
+
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.';
|
|
2135
|
+
break;
|
|
2136
|
+
case 'simulate':
|
|
2137
|
+
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.';
|
|
2138
|
+
break;
|
|
2139
|
+
default:
|
|
2140
|
+
message = 'Unknown action';
|
|
2141
|
+
}
|
|
2142
|
+
super(message);
|
|
2143
|
+
this.signature = void 0;
|
|
2144
|
+
this.transactionMessage = void 0;
|
|
2145
|
+
this.logs = void 0;
|
|
2146
|
+
this.signature = signature;
|
|
2147
|
+
this.transactionMessage = transactionMessage;
|
|
2148
|
+
this.logs = logs ? logs : undefined;
|
|
2149
|
+
}
|
|
2150
|
+
get transactionError() {
|
|
2151
|
+
return {
|
|
2152
|
+
message: this.transactionMessage,
|
|
2153
|
+
logs: Array.isArray(this.logs) ? this.logs : undefined
|
|
2154
|
+
};
|
|
2155
|
+
}
|
|
2156
|
+
async getLogs(connection) {
|
|
2157
|
+
if (!Array.isArray(this.logs)) {
|
|
2158
|
+
this.logs = new Promise((resolve, reject) => {
|
|
2159
|
+
connection.getTransaction(this.signature).then(tx => {
|
|
2160
|
+
if (tx && tx.meta && tx.meta.logMessages) {
|
|
2161
|
+
const logs = tx.meta.logMessages;
|
|
2162
|
+
this.logs = logs;
|
|
2163
|
+
resolve(logs);
|
|
2164
|
+
} else {
|
|
2165
|
+
reject(new Error('Log messages not found'));
|
|
2166
|
+
}
|
|
2167
|
+
}).catch(reject);
|
|
2168
|
+
});
|
|
2169
|
+
}
|
|
2170
|
+
return await this.logs;
|
|
2171
|
+
}
|
|
2172
|
+
}
|
|
2173
|
+
|
|
2174
|
+
// Keep in sync with client/src/rpc_custom_errors.rs
|
|
2175
|
+
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
2176
|
+
const SolanaJSONRPCErrorCode = {
|
|
2177
|
+
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
2178
|
+
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
2179
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
2180
|
+
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
2181
|
+
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
2182
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
2183
|
+
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
2184
|
+
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
2185
|
+
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
2186
|
+
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
2187
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
2188
|
+
JSON_RPC_SCAN_ERROR: -32012,
|
|
2189
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
2190
|
+
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
2191
|
+
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
|
|
2192
|
+
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
|
|
2193
|
+
};
|
|
2194
|
+
class SolanaJSONRPCError extends Error {
|
|
2195
|
+
constructor({
|
|
2196
|
+
code,
|
|
2197
|
+
message,
|
|
2198
|
+
data
|
|
2199
|
+
}, customMessage) {
|
|
2200
|
+
super(customMessage != null ? `${customMessage}: ${message}` : message);
|
|
2201
|
+
this.code = void 0;
|
|
2202
|
+
this.data = void 0;
|
|
2203
|
+
this.code = code;
|
|
2204
|
+
this.data = data;
|
|
2205
|
+
this.name = 'SolanaJSONRPCError';
|
|
2206
|
+
}
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2124
2209
|
/**
|
|
2125
2210
|
* Sign, send and confirm a transaction.
|
|
2126
2211
|
*
|
|
@@ -2167,6 +2252,13 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
2167
2252
|
status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2168
2253
|
}
|
|
2169
2254
|
if (status.err) {
|
|
2255
|
+
if (signature != null) {
|
|
2256
|
+
throw new SendTransactionError({
|
|
2257
|
+
action: 'send',
|
|
2258
|
+
signature: signature,
|
|
2259
|
+
transactionMessage: `Status: (${JSON.stringify(status)})`
|
|
2260
|
+
});
|
|
2261
|
+
}
|
|
2170
2262
|
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
2171
2263
|
}
|
|
2172
2264
|
return signature;
|
|
@@ -3424,49 +3516,6 @@ class EpochSchedule {
|
|
|
3424
3516
|
}
|
|
3425
3517
|
}
|
|
3426
3518
|
|
|
3427
|
-
class SendTransactionError extends Error {
|
|
3428
|
-
constructor(message, logs) {
|
|
3429
|
-
super(message);
|
|
3430
|
-
this.logs = void 0;
|
|
3431
|
-
this.logs = logs;
|
|
3432
|
-
}
|
|
3433
|
-
}
|
|
3434
|
-
|
|
3435
|
-
// Keep in sync with client/src/rpc_custom_errors.rs
|
|
3436
|
-
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
3437
|
-
const SolanaJSONRPCErrorCode = {
|
|
3438
|
-
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
3439
|
-
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
3440
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
3441
|
-
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
3442
|
-
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
3443
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
3444
|
-
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
3445
|
-
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
3446
|
-
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
3447
|
-
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
3448
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
3449
|
-
JSON_RPC_SCAN_ERROR: -32012,
|
|
3450
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
3451
|
-
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
3452
|
-
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
|
|
3453
|
-
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
|
|
3454
|
-
};
|
|
3455
|
-
class SolanaJSONRPCError extends Error {
|
|
3456
|
-
constructor({
|
|
3457
|
-
code,
|
|
3458
|
-
message,
|
|
3459
|
-
data
|
|
3460
|
-
}, customMessage) {
|
|
3461
|
-
super(customMessage != null ? `${customMessage}: ${message}` : message);
|
|
3462
|
-
this.code = void 0;
|
|
3463
|
-
this.data = void 0;
|
|
3464
|
-
this.code = code;
|
|
3465
|
-
this.data = data;
|
|
3466
|
-
this.name = 'SolanaJSONRPCError';
|
|
3467
|
-
}
|
|
3468
|
-
}
|
|
3469
|
-
|
|
3470
3519
|
var fetchImpl = globalThis.fetch;
|
|
3471
3520
|
|
|
3472
3521
|
class RpcWebSocketClient extends RpcWebSocketCommonClient {
|
|
@@ -7217,7 +7266,12 @@ class Connection {
|
|
|
7217
7266
|
console.error(res.error.message, logTrace);
|
|
7218
7267
|
}
|
|
7219
7268
|
}
|
|
7220
|
-
throw new SendTransactionError(
|
|
7269
|
+
throw new SendTransactionError({
|
|
7270
|
+
action: 'simulate',
|
|
7271
|
+
signature: '',
|
|
7272
|
+
transactionMessage: res.error.message,
|
|
7273
|
+
logs: logs
|
|
7274
|
+
});
|
|
7221
7275
|
}
|
|
7222
7276
|
return res.result;
|
|
7223
7277
|
}
|
|
@@ -7318,11 +7372,16 @@ class Connection {
|
|
|
7318
7372
|
const unsafeRes = await this._rpcRequest('sendTransaction', args);
|
|
7319
7373
|
const res = create(unsafeRes, SendTransactionRpcResult);
|
|
7320
7374
|
if ('error' in res) {
|
|
7321
|
-
let logs;
|
|
7375
|
+
let logs = undefined;
|
|
7322
7376
|
if ('data' in res.error) {
|
|
7323
7377
|
logs = res.error.data.logs;
|
|
7324
7378
|
}
|
|
7325
|
-
throw new SendTransactionError(
|
|
7379
|
+
throw new SendTransactionError({
|
|
7380
|
+
action: skipPreflight ? 'send' : 'simulate',
|
|
7381
|
+
signature: '',
|
|
7382
|
+
transactionMessage: res.error.message,
|
|
7383
|
+
logs: logs
|
|
7384
|
+
});
|
|
7326
7385
|
}
|
|
7327
7386
|
return res.result;
|
|
7328
7387
|
}
|
|
@@ -10310,6 +10369,13 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
10310
10369
|
const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
|
|
10311
10370
|
const status = (await confirmationPromise).value;
|
|
10312
10371
|
if (status.err) {
|
|
10372
|
+
if (signature != null) {
|
|
10373
|
+
throw new SendTransactionError({
|
|
10374
|
+
action: sendOptions?.skipPreflight ? 'send' : 'simulate',
|
|
10375
|
+
signature: signature,
|
|
10376
|
+
transactionMessage: `Status: (${JSON.stringify(status)})`
|
|
10377
|
+
});
|
|
10378
|
+
}
|
|
10313
10379
|
throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
10314
10380
|
}
|
|
10315
10381
|
return signature;
|