@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.d.ts
CHANGED
|
@@ -3753,8 +3753,20 @@ export class BpfLoader {
|
|
|
3753
3753
|
}
|
|
3754
3754
|
|
|
3755
3755
|
export class SendTransactionError extends Error {
|
|
3756
|
-
|
|
3757
|
-
|
|
3756
|
+
private signature;
|
|
3757
|
+
private transactionMessage;
|
|
3758
|
+
private logs;
|
|
3759
|
+
constructor({ action, signature, transactionMessage, logs: logs, }: {
|
|
3760
|
+
action: 'send' | 'simulate';
|
|
3761
|
+
signature: TransactionSignature;
|
|
3762
|
+
transactionMessage: string;
|
|
3763
|
+
logs?: string[];
|
|
3764
|
+
});
|
|
3765
|
+
get transactionError(): {
|
|
3766
|
+
message: string;
|
|
3767
|
+
logs?: string[];
|
|
3768
|
+
};
|
|
3769
|
+
getLogs(connection: Connection): Promise<string[]>;
|
|
3758
3770
|
}
|
|
3759
3771
|
export const SolanaJSONRPCErrorCode: {
|
|
3760
3772
|
readonly JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001;
|
package/lib/index.esm.js
CHANGED
|
@@ -2125,6 +2125,91 @@ const SYSVAR_SLOT_HASHES_PUBKEY = new PublicKey('SysvarS1otHashes111111111111111
|
|
|
2125
2125
|
const SYSVAR_SLOT_HISTORY_PUBKEY = new PublicKey('SysvarS1otHistory11111111111111111111111111');
|
|
2126
2126
|
const SYSVAR_STAKE_HISTORY_PUBKEY = new PublicKey('SysvarStakeHistory1111111111111111111111111');
|
|
2127
2127
|
|
|
2128
|
+
class SendTransactionError extends Error {
|
|
2129
|
+
constructor({
|
|
2130
|
+
action,
|
|
2131
|
+
signature,
|
|
2132
|
+
transactionMessage,
|
|
2133
|
+
logs: logs
|
|
2134
|
+
}) {
|
|
2135
|
+
let message;
|
|
2136
|
+
switch (action) {
|
|
2137
|
+
case 'send':
|
|
2138
|
+
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.';
|
|
2139
|
+
break;
|
|
2140
|
+
case 'simulate':
|
|
2141
|
+
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.';
|
|
2142
|
+
break;
|
|
2143
|
+
default:
|
|
2144
|
+
message = 'Unknown action';
|
|
2145
|
+
}
|
|
2146
|
+
super(message);
|
|
2147
|
+
this.signature = void 0;
|
|
2148
|
+
this.transactionMessage = void 0;
|
|
2149
|
+
this.logs = void 0;
|
|
2150
|
+
this.signature = signature;
|
|
2151
|
+
this.transactionMessage = transactionMessage;
|
|
2152
|
+
this.logs = logs ? logs : undefined;
|
|
2153
|
+
}
|
|
2154
|
+
get transactionError() {
|
|
2155
|
+
return {
|
|
2156
|
+
message: this.transactionMessage,
|
|
2157
|
+
logs: Array.isArray(this.logs) ? this.logs : undefined
|
|
2158
|
+
};
|
|
2159
|
+
}
|
|
2160
|
+
async getLogs(connection) {
|
|
2161
|
+
if (!Array.isArray(this.logs)) {
|
|
2162
|
+
this.logs = new Promise((resolve, reject) => {
|
|
2163
|
+
connection.getTransaction(this.signature).then(tx => {
|
|
2164
|
+
if (tx && tx.meta && tx.meta.logMessages) {
|
|
2165
|
+
const logs = tx.meta.logMessages;
|
|
2166
|
+
this.logs = logs;
|
|
2167
|
+
resolve(logs);
|
|
2168
|
+
} else {
|
|
2169
|
+
reject(new Error('Log messages not found'));
|
|
2170
|
+
}
|
|
2171
|
+
}).catch(reject);
|
|
2172
|
+
});
|
|
2173
|
+
}
|
|
2174
|
+
return await this.logs;
|
|
2175
|
+
}
|
|
2176
|
+
}
|
|
2177
|
+
|
|
2178
|
+
// Keep in sync with client/src/rpc_custom_errors.rs
|
|
2179
|
+
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
2180
|
+
const SolanaJSONRPCErrorCode = {
|
|
2181
|
+
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
2182
|
+
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
2183
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
2184
|
+
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
2185
|
+
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
2186
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
2187
|
+
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
2188
|
+
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
2189
|
+
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
2190
|
+
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
2191
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
2192
|
+
JSON_RPC_SCAN_ERROR: -32012,
|
|
2193
|
+
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
2194
|
+
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
2195
|
+
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
|
|
2196
|
+
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
|
|
2197
|
+
};
|
|
2198
|
+
class SolanaJSONRPCError extends Error {
|
|
2199
|
+
constructor({
|
|
2200
|
+
code,
|
|
2201
|
+
message,
|
|
2202
|
+
data
|
|
2203
|
+
}, customMessage) {
|
|
2204
|
+
super(customMessage != null ? `${customMessage}: ${message}` : message);
|
|
2205
|
+
this.code = void 0;
|
|
2206
|
+
this.data = void 0;
|
|
2207
|
+
this.code = code;
|
|
2208
|
+
this.data = data;
|
|
2209
|
+
this.name = 'SolanaJSONRPCError';
|
|
2210
|
+
}
|
|
2211
|
+
}
|
|
2212
|
+
|
|
2128
2213
|
/**
|
|
2129
2214
|
* Sign, send and confirm a transaction.
|
|
2130
2215
|
*
|
|
@@ -2171,6 +2256,13 @@ async function sendAndConfirmTransaction(connection, transaction, signers, optio
|
|
|
2171
2256
|
status = (await connection.confirmTransaction(signature, options && options.commitment)).value;
|
|
2172
2257
|
}
|
|
2173
2258
|
if (status.err) {
|
|
2259
|
+
if (signature != null) {
|
|
2260
|
+
throw new SendTransactionError({
|
|
2261
|
+
action: 'send',
|
|
2262
|
+
signature: signature,
|
|
2263
|
+
transactionMessage: `Status: (${JSON.stringify(status)})`
|
|
2264
|
+
});
|
|
2265
|
+
}
|
|
2174
2266
|
throw new Error(`Transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
2175
2267
|
}
|
|
2176
2268
|
return signature;
|
|
@@ -4087,49 +4179,6 @@ class EpochSchedule {
|
|
|
4087
4179
|
}
|
|
4088
4180
|
}
|
|
4089
4181
|
|
|
4090
|
-
class SendTransactionError extends Error {
|
|
4091
|
-
constructor(message, logs) {
|
|
4092
|
-
super(message);
|
|
4093
|
-
this.logs = void 0;
|
|
4094
|
-
this.logs = logs;
|
|
4095
|
-
}
|
|
4096
|
-
}
|
|
4097
|
-
|
|
4098
|
-
// Keep in sync with client/src/rpc_custom_errors.rs
|
|
4099
|
-
// Typescript `enums` thwart tree-shaking. See https://bargsten.org/jsts/enums/
|
|
4100
|
-
const SolanaJSONRPCErrorCode = {
|
|
4101
|
-
JSON_RPC_SERVER_ERROR_BLOCK_CLEANED_UP: -32001,
|
|
4102
|
-
JSON_RPC_SERVER_ERROR_SEND_TRANSACTION_PREFLIGHT_FAILURE: -32002,
|
|
4103
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_VERIFICATION_FAILURE: -32003,
|
|
4104
|
-
JSON_RPC_SERVER_ERROR_BLOCK_NOT_AVAILABLE: -32004,
|
|
4105
|
-
JSON_RPC_SERVER_ERROR_NODE_UNHEALTHY: -32005,
|
|
4106
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_PRECOMPILE_VERIFICATION_FAILURE: -32006,
|
|
4107
|
-
JSON_RPC_SERVER_ERROR_SLOT_SKIPPED: -32007,
|
|
4108
|
-
JSON_RPC_SERVER_ERROR_NO_SNAPSHOT: -32008,
|
|
4109
|
-
JSON_RPC_SERVER_ERROR_LONG_TERM_STORAGE_SLOT_SKIPPED: -32009,
|
|
4110
|
-
JSON_RPC_SERVER_ERROR_KEY_EXCLUDED_FROM_SECONDARY_INDEX: -32010,
|
|
4111
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_HISTORY_NOT_AVAILABLE: -32011,
|
|
4112
|
-
JSON_RPC_SCAN_ERROR: -32012,
|
|
4113
|
-
JSON_RPC_SERVER_ERROR_TRANSACTION_SIGNATURE_LEN_MISMATCH: -32013,
|
|
4114
|
-
JSON_RPC_SERVER_ERROR_BLOCK_STATUS_NOT_AVAILABLE_YET: -32014,
|
|
4115
|
-
JSON_RPC_SERVER_ERROR_UNSUPPORTED_TRANSACTION_VERSION: -32015,
|
|
4116
|
-
JSON_RPC_SERVER_ERROR_MIN_CONTEXT_SLOT_NOT_REACHED: -32016
|
|
4117
|
-
};
|
|
4118
|
-
class SolanaJSONRPCError extends Error {
|
|
4119
|
-
constructor({
|
|
4120
|
-
code,
|
|
4121
|
-
message,
|
|
4122
|
-
data
|
|
4123
|
-
}, customMessage) {
|
|
4124
|
-
super(customMessage != null ? `${customMessage}: ${message}` : message);
|
|
4125
|
-
this.code = void 0;
|
|
4126
|
-
this.data = void 0;
|
|
4127
|
-
this.code = code;
|
|
4128
|
-
this.data = data;
|
|
4129
|
-
this.name = 'SolanaJSONRPCError';
|
|
4130
|
-
}
|
|
4131
|
-
}
|
|
4132
|
-
|
|
4133
4182
|
var fetchImpl = typeof globalThis.fetch === 'function' ?
|
|
4134
4183
|
// The Fetch API is supported experimentally in Node 17.5+ and natively in Node 18+.
|
|
4135
4184
|
globalThis.fetch :
|
|
@@ -7910,7 +7959,12 @@ class Connection {
|
|
|
7910
7959
|
console.error(res.error.message, logTrace);
|
|
7911
7960
|
}
|
|
7912
7961
|
}
|
|
7913
|
-
throw new SendTransactionError(
|
|
7962
|
+
throw new SendTransactionError({
|
|
7963
|
+
action: 'simulate',
|
|
7964
|
+
signature: '',
|
|
7965
|
+
transactionMessage: res.error.message,
|
|
7966
|
+
logs: logs
|
|
7967
|
+
});
|
|
7914
7968
|
}
|
|
7915
7969
|
return res.result;
|
|
7916
7970
|
}
|
|
@@ -8011,11 +8065,16 @@ class Connection {
|
|
|
8011
8065
|
const unsafeRes = await this._rpcRequest('sendTransaction', args);
|
|
8012
8066
|
const res = create(unsafeRes, SendTransactionRpcResult);
|
|
8013
8067
|
if ('error' in res) {
|
|
8014
|
-
let logs;
|
|
8068
|
+
let logs = undefined;
|
|
8015
8069
|
if ('data' in res.error) {
|
|
8016
8070
|
logs = res.error.data.logs;
|
|
8017
8071
|
}
|
|
8018
|
-
throw new SendTransactionError(
|
|
8072
|
+
throw new SendTransactionError({
|
|
8073
|
+
action: skipPreflight ? 'send' : 'simulate',
|
|
8074
|
+
signature: '',
|
|
8075
|
+
transactionMessage: res.error.message,
|
|
8076
|
+
logs: logs
|
|
8077
|
+
});
|
|
8019
8078
|
}
|
|
8020
8079
|
return res.result;
|
|
8021
8080
|
}
|
|
@@ -11003,6 +11062,13 @@ async function sendAndConfirmRawTransaction(connection, rawTransaction, confirma
|
|
|
11003
11062
|
const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
|
|
11004
11063
|
const status = (await confirmationPromise).value;
|
|
11005
11064
|
if (status.err) {
|
|
11065
|
+
if (signature != null) {
|
|
11066
|
+
throw new SendTransactionError({
|
|
11067
|
+
action: sendOptions?.skipPreflight ? 'send' : 'simulate',
|
|
11068
|
+
signature: signature,
|
|
11069
|
+
transactionMessage: `Status: (${JSON.stringify(status)})`
|
|
11070
|
+
});
|
|
11071
|
+
}
|
|
11006
11072
|
throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
|
|
11007
11073
|
}
|
|
11008
11074
|
return signature;
|