@solana/web3.js 1.76.0 → 1.77.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.
@@ -1938,6 +1938,29 @@ class VersionedTransaction {
1938
1938
  }
1939
1939
  }
1940
1940
 
1941
+ // TODO: These constants should be removed in favor of reading them out of a
1942
+ // Syscall account
1943
+
1944
+ /**
1945
+ * @internal
1946
+ */
1947
+ const NUM_TICKS_PER_SECOND = 160;
1948
+
1949
+ /**
1950
+ * @internal
1951
+ */
1952
+ const DEFAULT_TICKS_PER_SLOT = 64;
1953
+
1954
+ /**
1955
+ * @internal
1956
+ */
1957
+ const NUM_SLOTS_PER_SECOND = NUM_TICKS_PER_SECOND / DEFAULT_TICKS_PER_SLOT;
1958
+
1959
+ /**
1960
+ * @internal
1961
+ */
1962
+ const MS_PER_SLOT = 1000 / NUM_SLOTS_PER_SECOND;
1963
+
1941
1964
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
1942
1965
  const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
1943
1966
  const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
@@ -2952,9 +2975,37 @@ class Loader {
2952
2975
  programId,
2953
2976
  data
2954
2977
  });
2955
- await sendAndConfirmTransaction(connection, transaction, [payer, program], {
2956
- commitment: 'confirmed'
2978
+ const deployCommitment = 'processed';
2979
+ const finalizeSignature = await connection.sendTransaction(transaction, [payer, program], {
2980
+ preflightCommitment: deployCommitment
2957
2981
  });
2982
+ const {
2983
+ context,
2984
+ value
2985
+ } = await connection.confirmTransaction({
2986
+ signature: finalizeSignature,
2987
+ lastValidBlockHeight: transaction.lastValidBlockHeight,
2988
+ blockhash: transaction.recentBlockhash
2989
+ }, deployCommitment);
2990
+ if (value.err) {
2991
+ throw new Error(`Transaction ${finalizeSignature} failed (${JSON.stringify(value)})`);
2992
+ }
2993
+ // We prevent programs from being usable until the slot after their deployment.
2994
+ // See https://github.com/solana-labs/solana/pull/29654
2995
+ while (true // eslint-disable-line no-constant-condition
2996
+ ) {
2997
+ try {
2998
+ const currentSlot = await connection.getSlot({
2999
+ commitment: deployCommitment
3000
+ });
3001
+ if (currentSlot > context.slot) {
3002
+ break;
3003
+ }
3004
+ } catch {
3005
+ /* empty */
3006
+ }
3007
+ await new Promise(resolve => setTimeout(resolve, Math.round(MS_PER_SLOT / 2)));
3008
+ }
2958
3009
  }
2959
3010
 
2960
3011
  // success
@@ -3240,29 +3291,6 @@ class RpcWebSocketClient extends RpcWebSocketCommonClient {
3240
3291
  }
3241
3292
  }
3242
3293
 
3243
- // TODO: These constants should be removed in favor of reading them out of a
3244
- // Syscall account
3245
-
3246
- /**
3247
- * @internal
3248
- */
3249
- const NUM_TICKS_PER_SECOND = 160;
3250
-
3251
- /**
3252
- * @internal
3253
- */
3254
- const DEFAULT_TICKS_PER_SLOT = 64;
3255
-
3256
- /**
3257
- * @internal
3258
- */
3259
- const NUM_SLOTS_PER_SECOND = NUM_TICKS_PER_SECOND / DEFAULT_TICKS_PER_SLOT;
3260
-
3261
- /**
3262
- * @internal
3263
- */
3264
- const MS_PER_SLOT = 1000 / NUM_SLOTS_PER_SECOND;
3265
-
3266
3294
  /**
3267
3295
  * @internal
3268
3296
  */
@@ -4694,7 +4722,7 @@ class Connection {
4694
4722
  /**
4695
4723
  * Fetch all the token accounts owned by the specified account
4696
4724
  *
4697
- * @return {Promise<RpcResponseAndContext<Array<{pubkey: PublicKey, account: AccountInfo<Buffer>}>>>}
4725
+ * @return {Promise<RpcResponseAndContext<GetProgramAccountsResponse>}
4698
4726
  */
4699
4727
  async getTokenAccountsByOwner(ownerAddress, filter, commitmentOrConfig) {
4700
4728
  const {
@@ -4891,6 +4919,8 @@ class Connection {
4891
4919
  *
4892
4920
  * @return {Promise<Array<{pubkey: PublicKey, account: AccountInfo<Buffer>}>>}
4893
4921
  */
4922
+
4923
+ // eslint-disable-next-line no-dupe-class-members
4894
4924
  async getProgramAccounts(programId, configOrCommitment) {
4895
4925
  const {
4896
4926
  commitment,
@@ -4902,7 +4932,8 @@ class Connection {
4902
4932
  } = config || {};
4903
4933
  const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', configWithoutEncoding);
4904
4934
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
4905
- const res = create(unsafeRes, jsonRpcResult(array(KeyedAccountInfoResult)));
4935
+ const baseSchema = array(KeyedAccountInfoResult);
4936
+ const res = configWithoutEncoding.withContext === true ? create(unsafeRes, jsonRpcResultAndContext(baseSchema)) : create(unsafeRes, jsonRpcResult(baseSchema));
4906
4937
  if ('error' in res) {
4907
4938
  throw new SolanaJSONRPCError(res.error, `failed to get accounts owned by program ${programId.toBase58()}`);
4908
4939
  }