@solana/web3.js 1.41.10 → 1.43.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 +137 -27
- package/lib/index.browser.cjs.js.map +1 -1
- package/lib/index.browser.esm.js +136 -25
- package/lib/index.browser.esm.js.map +1 -1
- package/lib/index.cjs.js +137 -27
- package/lib/index.cjs.js.map +1 -1
- package/lib/index.d.ts +62 -19
- package/lib/index.esm.js +136 -25
- package/lib/index.esm.js.map +1 -1
- package/lib/index.iife.js +11948 -12260
- package/lib/index.iife.js.map +1 -1
- package/lib/index.iife.min.js +4 -2
- package/lib/index.iife.min.js.map +1 -1
- package/package.json +3 -3
- package/src/compute-budget.ts +92 -3
- package/src/connection.ts +47 -32
- package/src/system-program.ts +1 -1
- package/src/transaction.ts +0 -1
- package/src/util/bigint.ts +43 -0
- package/src/util/send-and-confirm-raw-transaction.ts +52 -7
package/lib/index.browser.esm.js
CHANGED
|
@@ -4,7 +4,8 @@ import BN from 'bn.js';
|
|
|
4
4
|
import bs58 from 'bs58';
|
|
5
5
|
import { serialize, deserialize, deserializeUnchecked } from 'borsh';
|
|
6
6
|
import * as BufferLayout from '@solana/buffer-layout';
|
|
7
|
-
import {
|
|
7
|
+
import { blob } from '@solana/buffer-layout';
|
|
8
|
+
import { toBigIntLE, toBufferLE } from 'bigint-buffer';
|
|
8
9
|
import { coerce, instance, string, tuple, literal, unknown, union, type, optional, any, number, array, nullable, create, boolean, record, assert as assert$7 } from 'superstruct';
|
|
9
10
|
import { Client } from 'rpc-websockets';
|
|
10
11
|
import RpcClient from 'jayson/lib/client/browser';
|
|
@@ -2796,8 +2797,6 @@ class Transaction {
|
|
|
2796
2797
|
const message = this._compile();
|
|
2797
2798
|
|
|
2798
2799
|
this._partialSign(message, ...uniqueSigners);
|
|
2799
|
-
|
|
2800
|
-
this._verifySignatures(message.serialize(), true);
|
|
2801
2800
|
}
|
|
2802
2801
|
/**
|
|
2803
2802
|
* Partially sign a transaction with the specified accounts. All accounts must
|
|
@@ -3177,6 +3176,38 @@ class NonceAccount {
|
|
|
3177
3176
|
|
|
3178
3177
|
}
|
|
3179
3178
|
|
|
3179
|
+
const encodeDecode = layout => {
|
|
3180
|
+
const decode = layout.decode.bind(layout);
|
|
3181
|
+
const encode = layout.encode.bind(layout);
|
|
3182
|
+
return {
|
|
3183
|
+
decode,
|
|
3184
|
+
encode
|
|
3185
|
+
};
|
|
3186
|
+
};
|
|
3187
|
+
|
|
3188
|
+
const bigInt = length => property => {
|
|
3189
|
+
const layout = blob(length, property);
|
|
3190
|
+
const {
|
|
3191
|
+
encode,
|
|
3192
|
+
decode
|
|
3193
|
+
} = encodeDecode(layout);
|
|
3194
|
+
const bigIntLayout = layout;
|
|
3195
|
+
|
|
3196
|
+
bigIntLayout.decode = (buffer, offset) => {
|
|
3197
|
+
const src = decode(buffer, offset);
|
|
3198
|
+
return toBigIntLE(Buffer.from(src));
|
|
3199
|
+
};
|
|
3200
|
+
|
|
3201
|
+
bigIntLayout.encode = (bigInt, buffer, offset) => {
|
|
3202
|
+
const src = toBufferLE(bigInt, length);
|
|
3203
|
+
return encode(src, buffer, offset);
|
|
3204
|
+
};
|
|
3205
|
+
|
|
3206
|
+
return bigIntLayout;
|
|
3207
|
+
};
|
|
3208
|
+
|
|
3209
|
+
const u64 = bigInt(8);
|
|
3210
|
+
|
|
3180
3211
|
/**
|
|
3181
3212
|
* Create account system transaction params
|
|
3182
3213
|
*/
|
|
@@ -4155,6 +4186,34 @@ class ComputeBudgetInstruction {
|
|
|
4155
4186
|
bytes
|
|
4156
4187
|
};
|
|
4157
4188
|
}
|
|
4189
|
+
/**
|
|
4190
|
+
* Decode set compute unit limit compute budget instruction and retrieve the instruction params.
|
|
4191
|
+
*/
|
|
4192
|
+
|
|
4193
|
+
|
|
4194
|
+
static decodeSetComputeUnitLimit(instruction) {
|
|
4195
|
+
this.checkProgramId(instruction.programId);
|
|
4196
|
+
const {
|
|
4197
|
+
units
|
|
4198
|
+
} = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitLimit, instruction.data);
|
|
4199
|
+
return {
|
|
4200
|
+
units
|
|
4201
|
+
};
|
|
4202
|
+
}
|
|
4203
|
+
/**
|
|
4204
|
+
* Decode set compute unit price compute budget instruction and retrieve the instruction params.
|
|
4205
|
+
*/
|
|
4206
|
+
|
|
4207
|
+
|
|
4208
|
+
static decodeSetComputeUnitPrice(instruction) {
|
|
4209
|
+
this.checkProgramId(instruction.programId);
|
|
4210
|
+
const {
|
|
4211
|
+
microLamports
|
|
4212
|
+
} = decodeData(COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitPrice, instruction.data);
|
|
4213
|
+
return {
|
|
4214
|
+
microLamports
|
|
4215
|
+
};
|
|
4216
|
+
}
|
|
4158
4217
|
/**
|
|
4159
4218
|
* @internal
|
|
4160
4219
|
*/
|
|
@@ -4183,6 +4242,14 @@ const COMPUTE_BUDGET_INSTRUCTION_LAYOUTS = Object.freeze({
|
|
|
4183
4242
|
RequestHeapFrame: {
|
|
4184
4243
|
index: 1,
|
|
4185
4244
|
layout: BufferLayout.struct([BufferLayout.u8('instruction'), BufferLayout.u32('bytes')])
|
|
4245
|
+
},
|
|
4246
|
+
SetComputeUnitLimit: {
|
|
4247
|
+
index: 2,
|
|
4248
|
+
layout: BufferLayout.struct([BufferLayout.u8('instruction'), BufferLayout.u32('units')])
|
|
4249
|
+
},
|
|
4250
|
+
SetComputeUnitPrice: {
|
|
4251
|
+
index: 3,
|
|
4252
|
+
layout: BufferLayout.struct([BufferLayout.u8('instruction'), u64('microLamports')])
|
|
4186
4253
|
}
|
|
4187
4254
|
});
|
|
4188
4255
|
/**
|
|
@@ -4219,6 +4286,28 @@ class ComputeBudgetProgram {
|
|
|
4219
4286
|
});
|
|
4220
4287
|
}
|
|
4221
4288
|
|
|
4289
|
+
static setComputeUnitLimit(params) {
|
|
4290
|
+
const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitLimit;
|
|
4291
|
+
const data = encodeData(type, params);
|
|
4292
|
+
return new TransactionInstruction({
|
|
4293
|
+
keys: [],
|
|
4294
|
+
programId: this.programId,
|
|
4295
|
+
data
|
|
4296
|
+
});
|
|
4297
|
+
}
|
|
4298
|
+
|
|
4299
|
+
static setComputeUnitPrice(params) {
|
|
4300
|
+
const type = COMPUTE_BUDGET_INSTRUCTION_LAYOUTS.SetComputeUnitPrice;
|
|
4301
|
+
const data = encodeData(type, {
|
|
4302
|
+
microLamports: BigInt(params.microLamports)
|
|
4303
|
+
});
|
|
4304
|
+
return new TransactionInstruction({
|
|
4305
|
+
keys: [],
|
|
4306
|
+
programId: this.programId,
|
|
4307
|
+
data
|
|
4308
|
+
});
|
|
4309
|
+
}
|
|
4310
|
+
|
|
4222
4311
|
}
|
|
4223
4312
|
ComputeBudgetProgram.programId = new PublicKey('ComputeBudget111111111111111111111111111111');
|
|
4224
4313
|
|
|
@@ -5997,7 +6086,7 @@ class Connection {
|
|
|
5997
6086
|
this._disableBlockhashCaching = false;
|
|
5998
6087
|
this._pollingBlockhash = false;
|
|
5999
6088
|
this._blockhashInfo = {
|
|
6000
|
-
|
|
6089
|
+
latestBlockhash: null,
|
|
6001
6090
|
lastFetch: 0,
|
|
6002
6091
|
transactionSignatures: [],
|
|
6003
6092
|
simulatedSignatures: []
|
|
@@ -6960,7 +7049,7 @@ class Connection {
|
|
|
6960
7049
|
}
|
|
6961
7050
|
/**
|
|
6962
7051
|
* Fetch the latest blockhash from the cluster
|
|
6963
|
-
* @return {Promise<
|
|
7052
|
+
* @return {Promise<BlockhashWithExpiryBlockHeight>}
|
|
6964
7053
|
*/
|
|
6965
7054
|
|
|
6966
7055
|
|
|
@@ -6974,7 +7063,7 @@ class Connection {
|
|
|
6974
7063
|
}
|
|
6975
7064
|
/**
|
|
6976
7065
|
* Fetch the latest blockhash from the cluster
|
|
6977
|
-
* @return {Promise<
|
|
7066
|
+
* @return {Promise<BlockhashWithExpiryBlockHeight>}
|
|
6978
7067
|
*/
|
|
6979
7068
|
|
|
6980
7069
|
|
|
@@ -7557,7 +7646,7 @@ class Connection {
|
|
|
7557
7646
|
*/
|
|
7558
7647
|
|
|
7559
7648
|
|
|
7560
|
-
async
|
|
7649
|
+
async _blockhashWithExpiryBlockHeight(disableCache) {
|
|
7561
7650
|
if (!disableCache) {
|
|
7562
7651
|
// Wait for polling to finish
|
|
7563
7652
|
while (this._pollingBlockhash) {
|
|
@@ -7568,8 +7657,8 @@ class Connection {
|
|
|
7568
7657
|
|
|
7569
7658
|
const expired = timeSinceFetch >= BLOCKHASH_CACHE_TIMEOUT_MS;
|
|
7570
7659
|
|
|
7571
|
-
if (this._blockhashInfo.
|
|
7572
|
-
return this._blockhashInfo.
|
|
7660
|
+
if (this._blockhashInfo.latestBlockhash !== null && !expired) {
|
|
7661
|
+
return this._blockhashInfo.latestBlockhash;
|
|
7573
7662
|
}
|
|
7574
7663
|
}
|
|
7575
7664
|
|
|
@@ -7585,20 +7674,20 @@ class Connection {
|
|
|
7585
7674
|
|
|
7586
7675
|
try {
|
|
7587
7676
|
const startTime = Date.now();
|
|
7677
|
+
const cachedLatestBlockhash = this._blockhashInfo.latestBlockhash;
|
|
7678
|
+
const cachedBlockhash = cachedLatestBlockhash ? cachedLatestBlockhash.blockhash : null;
|
|
7588
7679
|
|
|
7589
7680
|
for (let i = 0; i < 50; i++) {
|
|
7590
|
-
const
|
|
7591
|
-
blockhash
|
|
7592
|
-
} = await this.getRecentBlockhash('finalized');
|
|
7681
|
+
const latestBlockhash = await this.getLatestBlockhash('finalized');
|
|
7593
7682
|
|
|
7594
|
-
if (
|
|
7683
|
+
if (cachedBlockhash !== latestBlockhash.blockhash) {
|
|
7595
7684
|
this._blockhashInfo = {
|
|
7596
|
-
|
|
7685
|
+
latestBlockhash,
|
|
7597
7686
|
lastFetch: Date.now(),
|
|
7598
7687
|
transactionSignatures: [],
|
|
7599
7688
|
simulatedSignatures: []
|
|
7600
7689
|
};
|
|
7601
|
-
return
|
|
7690
|
+
return latestBlockhash;
|
|
7602
7691
|
} // Sleep for approximately half a slot
|
|
7603
7692
|
|
|
7604
7693
|
|
|
@@ -7620,13 +7709,11 @@ class Connection {
|
|
|
7620
7709
|
|
|
7621
7710
|
if (transactionOrMessage instanceof Transaction) {
|
|
7622
7711
|
let originalTx = transactionOrMessage;
|
|
7623
|
-
transaction = new Transaction(
|
|
7624
|
-
|
|
7625
|
-
nonceInfo: originalTx.nonceInfo,
|
|
7626
|
-
feePayer: originalTx.feePayer,
|
|
7627
|
-
signatures: [...originalTx.signatures]
|
|
7628
|
-
});
|
|
7712
|
+
transaction = new Transaction();
|
|
7713
|
+
transaction.feePayer = originalTx.feePayer;
|
|
7629
7714
|
transaction.instructions = transactionOrMessage.instructions;
|
|
7715
|
+
transaction.nonceInfo = originalTx.nonceInfo;
|
|
7716
|
+
transaction.signatures = originalTx.signatures;
|
|
7630
7717
|
} else {
|
|
7631
7718
|
transaction = Transaction.populate(transactionOrMessage); // HACK: this function relies on mutating the populated transaction
|
|
7632
7719
|
|
|
@@ -7639,7 +7726,9 @@ class Connection {
|
|
|
7639
7726
|
let disableCache = this._disableBlockhashCaching;
|
|
7640
7727
|
|
|
7641
7728
|
for (;;) {
|
|
7642
|
-
|
|
7729
|
+
const latestBlockhash = await this._blockhashWithExpiryBlockHeight(disableCache);
|
|
7730
|
+
transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
|
|
7731
|
+
transaction.recentBlockhash = latestBlockhash.blockhash;
|
|
7643
7732
|
if (!signers) break;
|
|
7644
7733
|
transaction.sign(...signers);
|
|
7645
7734
|
|
|
@@ -7723,7 +7812,9 @@ class Connection {
|
|
|
7723
7812
|
let disableCache = this._disableBlockhashCaching;
|
|
7724
7813
|
|
|
7725
7814
|
for (;;) {
|
|
7726
|
-
|
|
7815
|
+
const latestBlockhash = await this._blockhashWithExpiryBlockHeight(disableCache);
|
|
7816
|
+
transaction.lastValidBlockHeight = latestBlockhash.lastValidBlockHeight;
|
|
7817
|
+
transaction.recentBlockhash = latestBlockhash.blockhash;
|
|
7727
7818
|
transaction.sign(...signers);
|
|
7728
7819
|
|
|
7729
7820
|
if (!transaction.signature) {
|
|
@@ -10164,16 +10255,36 @@ VoteProgram.space = 3731;
|
|
|
10164
10255
|
*
|
|
10165
10256
|
* @param {Connection} connection
|
|
10166
10257
|
* @param {Buffer} rawTransaction
|
|
10258
|
+
* @param {BlockheightBasedTransactionConfirmationStrategy} confirmationStrategy
|
|
10167
10259
|
* @param {ConfirmOptions} [options]
|
|
10168
10260
|
* @returns {Promise<TransactionSignature>}
|
|
10169
10261
|
*/
|
|
10170
|
-
|
|
10262
|
+
|
|
10263
|
+
/**
|
|
10264
|
+
* @deprecated Calling `sendAndConfirmRawTransaction()` without a `confirmationStrategy`
|
|
10265
|
+
* is no longer supported and will be removed in a future version.
|
|
10266
|
+
*/
|
|
10267
|
+
// eslint-disable-next-line no-redeclare
|
|
10268
|
+
// eslint-disable-next-line no-redeclare
|
|
10269
|
+
async function sendAndConfirmRawTransaction(connection, rawTransaction, confirmationStrategyOrConfirmOptions, maybeConfirmOptions) {
|
|
10270
|
+
let confirmationStrategy;
|
|
10271
|
+
let options;
|
|
10272
|
+
|
|
10273
|
+
if (confirmationStrategyOrConfirmOptions && Object.prototype.hasOwnProperty.call(confirmationStrategyOrConfirmOptions, 'lastValidBlockHeight')) {
|
|
10274
|
+
confirmationStrategy = confirmationStrategyOrConfirmOptions;
|
|
10275
|
+
options = maybeConfirmOptions;
|
|
10276
|
+
} else {
|
|
10277
|
+
options = confirmationStrategyOrConfirmOptions;
|
|
10278
|
+
}
|
|
10279
|
+
|
|
10171
10280
|
const sendOptions = options && {
|
|
10172
10281
|
skipPreflight: options.skipPreflight,
|
|
10173
10282
|
preflightCommitment: options.preflightCommitment || options.commitment
|
|
10174
10283
|
};
|
|
10175
10284
|
const signature = await connection.sendRawTransaction(rawTransaction, sendOptions);
|
|
10176
|
-
const
|
|
10285
|
+
const commitment = options && options.commitment;
|
|
10286
|
+
const confirmationPromise = confirmationStrategy ? connection.confirmTransaction(confirmationStrategy, commitment) : connection.confirmTransaction(signature, commitment);
|
|
10287
|
+
const status = (await confirmationPromise).value;
|
|
10177
10288
|
|
|
10178
10289
|
if (status.err) {
|
|
10179
10290
|
throw new Error(`Raw transaction ${signature} failed (${JSON.stringify(status)})`);
|