@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.
- package/lib/index.browser.cjs.js +115 -46
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +115 -46
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +115 -46
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +15 -2
- package/lib/index.esm.js +115 -46
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +115 -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 +115 -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,94 @@ 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
|
+
transactionLogs
|
|
2130
|
+
}) {
|
|
2131
|
+
let message;
|
|
2132
|
+
switch (action) {
|
|
2133
|
+
case 'send':
|
|
2134
|
+
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.';
|
|
2135
|
+
break;
|
|
2136
|
+
case 'simulate':
|
|
2137
|
+
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.';
|
|
2138
|
+
break;
|
|
2139
|
+
default:
|
|
2140
|
+
message = 'Unknown action';
|
|
2141
|
+
}
|
|
2142
|
+
super(message);
|
|
2143
|
+
this.signature = void 0;
|
|
2144
|
+
this.transactionMessage = void 0;
|
|
2145
|
+
this.transactionLogs = void 0;
|
|
2146
|
+
this.resolvedLogs = void 0;
|
|
2147
|
+
this.signature = signature;
|
|
2148
|
+
this.transactionMessage = transactionMessage;
|
|
2149
|
+
this.transactionLogs = transactionLogs;
|
|
2150
|
+
this.resolvedLogs = transactionLogs ? transactionLogs : undefined;
|
|
2151
|
+
}
|
|
2152
|
+
get transactionError() {
|
|
2153
|
+
return {
|
|
2154
|
+
message: this.transactionMessage,
|
|
2155
|
+
logs: this.transactionLogs
|
|
2156
|
+
};
|
|
2157
|
+
}
|
|
2158
|
+
async getLogs(connection) {
|
|
2159
|
+
if (this.resolvedLogs === undefined) {
|
|
2160
|
+
this.resolvedLogs = new Promise((resolve, reject) => {
|
|
2161
|
+
connection.getTransaction(this.signature).then(tx => {
|
|
2162
|
+
if (tx && tx.meta && tx.meta.logMessages) {
|
|
2163
|
+
const logs = tx.meta.logMessages;
|
|
2164
|
+
this.resolvedLogs = logs;
|
|
2165
|
+
this.transactionLogs = logs;
|
|
2166
|
+
resolve(logs);
|
|
2167
|
+
} else {
|
|
2168
|
+
reject(new Error('Log messages not found'));
|
|
2169
|
+
}
|
|
2170
|
+
}).catch(reject);
|
|
2171
|
+
});
|
|
2172
|
+
}
|
|
2173
|
+
return await this.resolvedLogs;
|
|
2174
|
+
}
|
|
2175
|
+
}
|
|
2176
|
+
|
|
2177
|
+
// Keep in sync with client/src/rpc_custom_errors.rs
|
|
2178
|
+
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
2179
|
+
const SolanaJSONRPCErrorCode = {
|
|
2180
|
+
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
2181
|
+
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
2182
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
2183
|
+
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
2184
|
+
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
2185
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
2186
|
+
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
2187
|
+
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
2188
|
+
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
2189
|
+
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
2190
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
2191
|
+
JSON_RPC_SCAN_ERROR: -32012,
|
|
2192
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
2193
|
+
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
2194
|
+
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
|
|
2195
|
+
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
|
|
2196
|
+
};
|
|
2197
|
+
class SolanaJSONRPCError extends Error {
|
|
2198
|
+
constructor({
|
|
2199
|
+
code,
|
|
2200
|
+
message,
|
|
2201
|
+
data
|
|
2202
|
+
}, customMessage) {
|
|
2203
|
+
super(customMessage != null ? `${customMessage}: ${message}` : message);
|
|
2204
|
+
this.code = void 0;
|
|
2205
|
+
this.data = void 0;
|
|
2206
|
+
this.code = code;
|
|
2207
|
+
this.data = data;
|
|
2208
|
+
this.name = 'SolanaJSONRPCError';
|
|
2209
|
+
}
|
|
2210
|
+
}
|
|
2211
|
+
|
|
2124
2212
|
/**
|
|
2125
2213
|
* Sign, send and confirm a transaction.
|
|
2126
2214
|
*
|
|
@@ -2167,6 +2255,13 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
2167
2255
|
status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2168
2256
|
}
|
|
2169
2257
|
if (status.err) {
|
|
2258
|
+
if (signature != null) {
|
|
2259
|
+
throw new SendTransactionError({
|
|
2260
|
+
action: 'send',
|
|
2261
|
+
signature: signature,
|
|
2262
|
+
transactionMessage: `Status: (${JSON.stringify(status)})`
|
|
2263
|
+
});
|
|
2264
|
+
}
|
|
2170
2265
|
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
2171
2266
|
}
|
|
2172
2267
|
return signature;
|
|
@@ -3424,49 +3519,6 @@ class EpochSchedule {
|
|
|
3424
3519
|
}
|
|
3425
3520
|
}
|
|
3426
3521
|
|
|
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
3522
|
var fetchImpl = globalThis.fetch;
|
|
3471
3523
|
|
|
3472
3524
|
class RpcWebSocketClient extends RpcWebSocketCommonClient {
|
|
@@ -7217,7 +7269,12 @@ class Connection {
|
|
|
7217
7269
|
console.error(res.error.message, logTrace);
|
|
7218
7270
|
}
|
|
7219
7271
|
}
|
|
7220
|
-
throw new SendTransactionError(
|
|
7272
|
+
throw new SendTransactionError({
|
|
7273
|
+
action: 'simulate',
|
|
7274
|
+
signature: '',
|
|
7275
|
+
transactionMessage: res.error.message,
|
|
7276
|
+
transactionLogs: logs
|
|
7277
|
+
});
|
|
7221
7278
|
}
|
|
7222
7279
|
return res.result;
|
|
7223
7280
|
}
|
|
@@ -7318,11 +7375,16 @@ class Connection {
|
|
|
7318
7375
|
const unsafeRes = await this._rpcRequest('sendTransaction', args);
|
|
7319
7376
|
const res = create(unsafeRes, SendTransactionRpcResult);
|
|
7320
7377
|
if ('error' in res) {
|
|
7321
|
-
let logs;
|
|
7378
|
+
let logs = undefined;
|
|
7322
7379
|
if ('data' in res.error) {
|
|
7323
7380
|
logs = res.error.data.logs;
|
|
7324
7381
|
}
|
|
7325
|
-
throw new SendTransactionError(
|
|
7382
|
+
throw new SendTransactionError({
|
|
7383
|
+
action: skipPreflight ? 'send' : 'simulate',
|
|
7384
|
+
signature: '',
|
|
7385
|
+
transactionMessage: res.error.message,
|
|
7386
|
+
transactionLogs: logs
|
|
7387
|
+
});
|
|
7326
7388
|
}
|
|
7327
7389
|
return res.result;
|
|
7328
7390
|
}
|
|
@@ -10310,6 +10372,13 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
10310
10372
|
const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
|
|
10311
10373
|
const status = (await confirmationPromise).value;
|
|
10312
10374
|
if (status.err) {
|
|
10375
|
+
if (signature != null) {
|
|
10376
|
+
throw new SendTransactionError({
|
|
10377
|
+
action: sendOptions?.skipPreflight ? 'send' : 'simulate',
|
|
10378
|
+
signature: signature,
|
|
10379
|
+
transactionMessage: `Status: (${JSON.stringify(status)})`
|
|
10380
|
+
});
|
|
10381
|
+
}
|
|
10313
10382
|
throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
10314
10383
|
}
|
|
10315
10384
|
return signature;
|