@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.cjs.js
CHANGED
|
@@ -2157,6 +2157,91 @@ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111
|
|
|
2157
2157
|
const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
|
|
2158
2158
|
const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
2159
2159
|
|
|
2160
|
+
class SendTransactionError extends Error {
|
|
2161
|
+
constructor({
|
|
2162
|
+
action,
|
|
2163
|
+
signature,
|
|
2164
|
+
transactionMessage,
|
|
2165
|
+
logs: logs
|
|
2166
|
+
}) {
|
|
2167
|
+
let message;
|
|
2168
|
+
switch (action) {
|
|
2169
|
+
case 'send':
|
|
2170
|
+
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.';
|
|
2171
|
+
break;
|
|
2172
|
+
case 'simulate':
|
|
2173
|
+
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.';
|
|
2174
|
+
break;
|
|
2175
|
+
default:
|
|
2176
|
+
message = 'Unknown action';
|
|
2177
|
+
}
|
|
2178
|
+
super(message);
|
|
2179
|
+
this.signature = void 0;
|
|
2180
|
+
this.transactionMessage = void 0;
|
|
2181
|
+
this.logs = void 0;
|
|
2182
|
+
this.signature = signature;
|
|
2183
|
+
this.transactionMessage = transactionMessage;
|
|
2184
|
+
this.logs = logs ? logs : undefined;
|
|
2185
|
+
}
|
|
2186
|
+
get transactionError() {
|
|
2187
|
+
return {
|
|
2188
|
+
message: this.transactionMessage,
|
|
2189
|
+
logs: Array.isArray(this.logs) ? this.logs : undefined
|
|
2190
|
+
};
|
|
2191
|
+
}
|
|
2192
|
+
async getLogs(connection) {
|
|
2193
|
+
if (!Array.isArray(this.logs)) {
|
|
2194
|
+
this.logs = new Promise((resolve, reject) => {
|
|
2195
|
+
connection.getTransaction(this.signature).then(tx => {
|
|
2196
|
+
if (tx && tx.meta && tx.meta.logMessages) {
|
|
2197
|
+
const logs = tx.meta.logMessages;
|
|
2198
|
+
this.logs = logs;
|
|
2199
|
+
resolve(logs);
|
|
2200
|
+
} else {
|
|
2201
|
+
reject(new Error('Log messages not found'));
|
|
2202
|
+
}
|
|
2203
|
+
}).catch(reject);
|
|
2204
|
+
});
|
|
2205
|
+
}
|
|
2206
|
+
return await this.logs;
|
|
2207
|
+
}
|
|
2208
|
+
}
|
|
2209
|
+
|
|
2210
|
+
// Keep in sync with client/src/rpc_custom_errors.rs
|
|
2211
|
+
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
2212
|
+
const SolanaJSONRPCErrorCode = {
|
|
2213
|
+
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
2214
|
+
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
2215
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
2216
|
+
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
2217
|
+
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
2218
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
2219
|
+
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
2220
|
+
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
2221
|
+
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
2222
|
+
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
2223
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
2224
|
+
JSON_RPC_SCAN_ERROR: -32012,
|
|
2225
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
2226
|
+
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
2227
|
+
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
|
|
2228
|
+
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
|
|
2229
|
+
};
|
|
2230
|
+
class SolanaJSONRPCError extends Error {
|
|
2231
|
+
constructor({
|
|
2232
|
+
code,
|
|
2233
|
+
message,
|
|
2234
|
+
data
|
|
2235
|
+
}, customMessage) {
|
|
2236
|
+
super(customMessage != null ? `${customMessage}: ${message}` : message);
|
|
2237
|
+
this.code = void 0;
|
|
2238
|
+
this.data = void 0;
|
|
2239
|
+
this.code = code;
|
|
2240
|
+
this.data = data;
|
|
2241
|
+
this.name = 'SolanaJSONRPCError';
|
|
2242
|
+
}
|
|
2243
|
+
}
|
|
2244
|
+
|
|
2160
2245
|
/**
|
|
2161
2246
|
* Sign, send and confirm a transaction.
|
|
2162
2247
|
*
|
|
@@ -2203,6 +2288,13 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
2203
2288
|
status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2204
2289
|
}
|
|
2205
2290
|
if (status.err) {
|
|
2291
|
+
if (signature != null) {
|
|
2292
|
+
throw new SendTransactionError({
|
|
2293
|
+
action: 'send',
|
|
2294
|
+
signature: signature,
|
|
2295
|
+
transactionMessage: `Status: (${JSON.stringify(status)})`
|
|
2296
|
+
});
|
|
2297
|
+
}
|
|
2206
2298
|
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
2207
2299
|
}
|
|
2208
2300
|
return signature;
|
|
@@ -4119,49 +4211,6 @@ class EpochSchedule {
|
|
|
4119
4211
|
}
|
|
4120
4212
|
}
|
|
4121
4213
|
|
|
4122
|
-
class SendTransactionError extends Error {
|
|
4123
|
-
constructor(message, logs) {
|
|
4124
|
-
super(message);
|
|
4125
|
-
this.logs = void 0;
|
|
4126
|
-
this.logs = logs;
|
|
4127
|
-
}
|
|
4128
|
-
}
|
|
4129
|
-
|
|
4130
|
-
// Keep in sync with client/src/rpc_custom_errors.rs
|
|
4131
|
-
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
4132
|
-
const SolanaJSONRPCErrorCode = {
|
|
4133
|
-
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
4134
|
-
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
4135
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
4136
|
-
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
4137
|
-
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
4138
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
4139
|
-
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
4140
|
-
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
4141
|
-
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
4142
|
-
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
4143
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
4144
|
-
JSON_RPC_SCAN_ERROR: -32012,
|
|
4145
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
4146
|
-
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
4147
|
-
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
|
|
4148
|
-
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
|
|
4149
|
-
};
|
|
4150
|
-
class SolanaJSONRPCError extends Error {
|
|
4151
|
-
constructor({
|
|
4152
|
-
code,
|
|
4153
|
-
message,
|
|
4154
|
-
data
|
|
4155
|
-
}, customMessage) {
|
|
4156
|
-
super(customMessage != null ? `${customMessage}: ${message}` : message);
|
|
4157
|
-
this.code = void 0;
|
|
4158
|
-
this.data = void 0;
|
|
4159
|
-
this.code = code;
|
|
4160
|
-
this.data = data;
|
|
4161
|
-
this.name = 'SolanaJSONRPCError';
|
|
4162
|
-
}
|
|
4163
|
-
}
|
|
4164
|
-
|
|
4165
4214
|
var fetchImpl = typeof globalThis.fetch === 'function' ?
|
|
4166
4215
|
// The Fetch API is supported experimentally in Node 17.5+ and natively in Node 18+.
|
|
4167
4216
|
globalThis.fetch :
|
|
@@ -7942,7 +7991,12 @@ class Connection {
|
|
|
7942
7991
|
console.error(res.error.message, logTrace);
|
|
7943
7992
|
}
|
|
7944
7993
|
}
|
|
7945
|
-
throw new SendTransactionError(
|
|
7994
|
+
throw new SendTransactionError({
|
|
7995
|
+
action: 'simulate',
|
|
7996
|
+
signature: '',
|
|
7997
|
+
transactionMessage: res.error.message,
|
|
7998
|
+
logs: logs
|
|
7999
|
+
});
|
|
7946
8000
|
}
|
|
7947
8001
|
return res.result;
|
|
7948
8002
|
}
|
|
@@ -8043,11 +8097,16 @@ class Connection {
|
|
|
8043
8097
|
const unsafeRes = await this._rpcRequest('sendTransaction', args);
|
|
8044
8098
|
const res = superstruct.create(unsafeRes, SendTransactionRpcResult);
|
|
8045
8099
|
if ('error' in res) {
|
|
8046
|
-
let logs;
|
|
8100
|
+
let logs = undefined;
|
|
8047
8101
|
if ('data' in res.error) {
|
|
8048
8102
|
logs = res.error.data.logs;
|
|
8049
8103
|
}
|
|
8050
|
-
throw new SendTransactionError(
|
|
8104
|
+
throw new SendTransactionError({
|
|
8105
|
+
action: skipPreflight ? 'send' : 'simulate',
|
|
8106
|
+
signature: '',
|
|
8107
|
+
transactionMessage: res.error.message,
|
|
8108
|
+
logs: logs
|
|
8109
|
+
});
|
|
8051
8110
|
}
|
|
8052
8111
|
return res.result;
|
|
8053
8112
|
}
|
|
@@ -11035,6 +11094,13 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
11035
11094
|
const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
|
|
11036
11095
|
const status = (await confirmationPromise).value;
|
|
11037
11096
|
if (status.err) {
|
|
11097
|
+
if (signature != null) {
|
|
11098
|
+
throw new SendTransactionError({
|
|
11099
|
+
action: sendOptions?.skipPreflight ? 'send' : 'simulate',
|
|
11100
|
+
signature: signature,
|
|
11101
|
+
transactionMessage: `Status: (${JSON.stringify(status)})`
|
|
11102
|
+
});
|
|
11103
|
+
}
|
|
11038
11104
|
throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
11039
11105
|
}
|
|
11040
11106
|
return signature;
|