@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.cjs.js
CHANGED
|
@@ -2157,6 +2157,94 @@ 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
|
+
transactionLogs
|
|
2166
|
+
}) {
|
|
2167
|
+
let message;
|
|
2168
|
+
switch (action) {
|
|
2169
|
+
case 'send':
|
|
2170
|
+
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.';
|
|
2171
|
+
break;
|
|
2172
|
+
case 'simulate':
|
|
2173
|
+
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.';
|
|
2174
|
+
break;
|
|
2175
|
+
default:
|
|
2176
|
+
message = 'Unknown action';
|
|
2177
|
+
}
|
|
2178
|
+
super(message);
|
|
2179
|
+
this.signature = void 0;
|
|
2180
|
+
this.transactionMessage = void 0;
|
|
2181
|
+
this.transactionLogs = void 0;
|
|
2182
|
+
this.resolvedLogs = void 0;
|
|
2183
|
+
this.signature = signature;
|
|
2184
|
+
this.transactionMessage = transactionMessage;
|
|
2185
|
+
this.transactionLogs = transactionLogs;
|
|
2186
|
+
this.resolvedLogs = transactionLogs ? transactionLogs : undefined;
|
|
2187
|
+
}
|
|
2188
|
+
get transactionError() {
|
|
2189
|
+
return {
|
|
2190
|
+
message: this.transactionMessage,
|
|
2191
|
+
logs: this.transactionLogs
|
|
2192
|
+
};
|
|
2193
|
+
}
|
|
2194
|
+
async getLogs(connection) {
|
|
2195
|
+
if (this.resolvedLogs === undefined) {
|
|
2196
|
+
this.resolvedLogs = new Promise((resolve, reject) => {
|
|
2197
|
+
connection.getTransaction(this.signature).then(tx => {
|
|
2198
|
+
if (tx && tx.meta && tx.meta.logMessages) {
|
|
2199
|
+
const logs = tx.meta.logMessages;
|
|
2200
|
+
this.resolvedLogs = logs;
|
|
2201
|
+
this.transactionLogs = logs;
|
|
2202
|
+
resolve(logs);
|
|
2203
|
+
} else {
|
|
2204
|
+
reject(new Error('Log messages not found'));
|
|
2205
|
+
}
|
|
2206
|
+
}).catch(reject);
|
|
2207
|
+
});
|
|
2208
|
+
}
|
|
2209
|
+
return await this.resolvedLogs;
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2213
|
+
// Keep in sync with client/src/rpc_custom_errors.rs
|
|
2214
|
+
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
2215
|
+
const SolanaJSONRPCErrorCode = {
|
|
2216
|
+
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
2217
|
+
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
2218
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
2219
|
+
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
2220
|
+
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
2221
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
2222
|
+
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
2223
|
+
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
2224
|
+
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
2225
|
+
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
2226
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
2227
|
+
JSON_RPC_SCAN_ERROR: -32012,
|
|
2228
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
2229
|
+
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
2230
|
+
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
|
|
2231
|
+
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
|
|
2232
|
+
};
|
|
2233
|
+
class SolanaJSONRPCError extends Error {
|
|
2234
|
+
constructor({
|
|
2235
|
+
code,
|
|
2236
|
+
message,
|
|
2237
|
+
data
|
|
2238
|
+
}, customMessage) {
|
|
2239
|
+
super(customMessage != null ? `${customMessage}: ${message}` : message);
|
|
2240
|
+
this.code = void 0;
|
|
2241
|
+
this.data = void 0;
|
|
2242
|
+
this.code = code;
|
|
2243
|
+
this.data = data;
|
|
2244
|
+
this.name = 'SolanaJSONRPCError';
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2160
2248
|
/**
|
|
2161
2249
|
* Sign, send and confirm a transaction.
|
|
2162
2250
|
*
|
|
@@ -2203,6 +2291,13 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
2203
2291
|
status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2204
2292
|
}
|
|
2205
2293
|
if (status.err) {
|
|
2294
|
+
if (signature != null) {
|
|
2295
|
+
throw new SendTransactionError({
|
|
2296
|
+
action: 'send',
|
|
2297
|
+
signature: signature,
|
|
2298
|
+
transactionMessage: `Status: (${JSON.stringify(status)})`
|
|
2299
|
+
});
|
|
2300
|
+
}
|
|
2206
2301
|
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
2207
2302
|
}
|
|
2208
2303
|
return signature;
|
|
@@ -4119,49 +4214,6 @@ class EpochSchedule {
|
|
|
4119
4214
|
}
|
|
4120
4215
|
}
|
|
4121
4216
|
|
|
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
4217
|
var fetchImpl = typeof globalThis.fetch === 'function' ?
|
|
4166
4218
|
// The Fetch API is supported experimentally in Node 17.5+ and natively in Node 18+.
|
|
4167
4219
|
globalThis.fetch :
|
|
@@ -7942,7 +7994,12 @@ class Connection {
|
|
|
7942
7994
|
console.error(res.error.message, logTrace);
|
|
7943
7995
|
}
|
|
7944
7996
|
}
|
|
7945
|
-
throw new SendTransactionError(
|
|
7997
|
+
throw new SendTransactionError({
|
|
7998
|
+
action: 'simulate',
|
|
7999
|
+
signature: '',
|
|
8000
|
+
transactionMessage: res.error.message,
|
|
8001
|
+
transactionLogs: logs
|
|
8002
|
+
});
|
|
7946
8003
|
}
|
|
7947
8004
|
return res.result;
|
|
7948
8005
|
}
|
|
@@ -8043,11 +8100,16 @@ class Connection {
|
|
|
8043
8100
|
const unsafeRes = await this._rpcRequest('sendTransaction', args);
|
|
8044
8101
|
const res = superstruct.create(unsafeRes, SendTransactionRpcResult);
|
|
8045
8102
|
if ('error' in res) {
|
|
8046
|
-
let logs;
|
|
8103
|
+
let logs = undefined;
|
|
8047
8104
|
if ('data' in res.error) {
|
|
8048
8105
|
logs = res.error.data.logs;
|
|
8049
8106
|
}
|
|
8050
|
-
throw new SendTransactionError(
|
|
8107
|
+
throw new SendTransactionError({
|
|
8108
|
+
action: skipPreflight ? 'send' : 'simulate',
|
|
8109
|
+
signature: '',
|
|
8110
|
+
transactionMessage: res.error.message,
|
|
8111
|
+
transactionLogs: logs
|
|
8112
|
+
});
|
|
8051
8113
|
}
|
|
8052
8114
|
return res.result;
|
|
8053
8115
|
}
|
|
@@ -11035,6 +11097,13 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
11035
11097
|
const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
|
|
11036
11098
|
const status = (await confirmationPromise).value;
|
|
11037
11099
|
if (status.err) {
|
|
11100
|
+
if (signature != null) {
|
|
11101
|
+
throw new SendTransactionError({
|
|
11102
|
+
action: sendOptions?.skipPreflight ? 'send' : 'simulate',
|
|
11103
|
+
signature: signature,
|
|
11104
|
+
transactionMessage: `Status: (${JSON.stringify(status)})`
|
|
11105
|
+
});
|
|
11106
|
+
}
|
|
11038
11107
|
throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
11039
11108
|
}
|
|
11040
11109
|
return signature;
|