@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.
package/lib/index.d.ts CHANGED
@@ -1326,6 +1326,8 @@ export class VoteProgram {
1326
1326
  * This is generated from the solana-vote-program VoteState struct as
1327
1327
  * `VoteState::size_of()`:
1328
1328
  * https://docs.rs/solana-vote-program/1.9.5/solana_vote_program/vote_state/struct.VoteState.html#method.size_of
1329
+ *
1330
+ * KEEP IN SYNC WITH `VoteState::size_of()` in https://github.com/solana-labs/solana/blob/a474cb24b9238f5edcc982f65c0b37d4a1046f7e/sdk/program/src/vote/state/mod.rs#L340-L342
1329
1331
  */
1330
1332
  static space: number;
1331
1333
  /**
@@ -2827,7 +2829,14 @@ type GetProgramAccountsConfig = {
2827
2829
  filters?: GetProgramAccountsFilter[];
2828
2830
  /** The minimum slot that the request can be evaluated at */
2829
2831
  minContextSlot?: number;
2832
+ /** wrap the result in an RpcResponse JSON object */
2833
+ withContext?: boolean;
2830
2834
  };
2835
+ type GetProgramAccountsResponse = readonly Readonly<{
2836
+ account: AccountInfo<Buffer>;
2837
+ /** the account Pubkey as base-58 encoded string */
2838
+ pubkey: PublicKey;
2839
+ }>[];
2831
2840
  /**
2832
2841
  * Configuration object for getParsedProgramAccounts
2833
2842
  */
@@ -3128,12 +3137,9 @@ export class Connection {
3128
3137
  /**
3129
3138
  * Fetch all the token accounts owned by the specified account
3130
3139
  *
3131
- * @return {Promise<RpcResponseAndContext<Array<{pubkey: PublicKey, account: AccountInfo<Buffer>}>>>}
3140
+ * @return {Promise<RpcResponseAndContext<GetProgramAccountsResponse>}
3132
3141
  */
3133
- getTokenAccountsByOwner(ownerAddress: PublicKey, filter: TokenAccountsFilter, commitmentOrConfig?: Commitment | GetTokenAccountsByOwnerConfig): Promise<RpcResponseAndContext<Array<{
3134
- pubkey: PublicKey;
3135
- account: AccountInfo<Buffer>;
3136
- }>>>;
3142
+ getTokenAccountsByOwner(ownerAddress: PublicKey, filter: TokenAccountsFilter, commitmentOrConfig?: Commitment | GetTokenAccountsByOwnerConfig): Promise<RpcResponseAndContext<GetProgramAccountsResponse>>;
3137
3143
  /**
3138
3144
  * Fetch parsed token accounts owned by the specified account
3139
3145
  *
@@ -3185,10 +3191,10 @@ export class Connection {
3185
3191
  *
3186
3192
  * @return {Promise<Array<{pubkey: PublicKey, account: AccountInfo<Buffer>}>>}
3187
3193
  */
3188
- getProgramAccounts(programId: PublicKey, configOrCommitment?: GetProgramAccountsConfig | Commitment): Promise<Array<{
3189
- pubkey: PublicKey;
3190
- account: AccountInfo<Buffer>;
3191
- }>>;
3194
+ getProgramAccounts(programId: PublicKey, configOrCommitment?: GetProgramAccountsConfig & Readonly<{
3195
+ withContext: true;
3196
+ }>): Promise<RpcResponseAndContext<GetProgramAccountsResponse>>;
3197
+ getProgramAccounts(programId: PublicKey, configOrCommitment?: GetProgramAccountsConfig | Commitment): Promise<GetProgramAccountsResponse>;
3192
3198
  /**
3193
3199
  * Fetch and parse all the accounts owned by the specified program id
3194
3200
  *
package/lib/index.esm.js CHANGED
@@ -1945,6 +1945,29 @@ class VersionedTransaction {
1945
1945
  }
1946
1946
  }
1947
1947
 
1948
+ // TODO: These constants should be removed in favor of reading them out of a
1949
+ // Syscall account
1950
+
1951
+ /**
1952
+ * @internal
1953
+ */
1954
+ const NUM_TICKS_PER_SECOND = 160;
1955
+
1956
+ /**
1957
+ * @internal
1958
+ */
1959
+ const DEFAULT_TICKS_PER_SLOT = 64;
1960
+
1961
+ /**
1962
+ * @internal
1963
+ */
1964
+ const NUM_SLOTS_PER_SECOND = NUM_TICKS_PER_SECOND / DEFAULT_TICKS_PER_SLOT;
1965
+
1966
+ /**
1967
+ * @internal
1968
+ */
1969
+ const MS_PER_SLOT = 1000 / NUM_SLOTS_PER_SECOND;
1970
+
1948
1971
  const SYSVAR_CLOCK_PUBKEY = new PublicKey('SysvarC1ock11111111111111111111111111111111');
1949
1972
  const SYSVAR_EPOCH_SCHEDULE_PUBKEY = new PublicKey('SysvarEpochSchedu1e111111111111111111111111');
1950
1973
  const SYSVAR_INSTRUCTIONS_PUBKEY = new PublicKey('Sysvar1nstructions1111111111111111111111111');
@@ -2959,9 +2982,37 @@ class Loader {
2959
2982
  programId,
2960
2983
  data
2961
2984
  });
2962
- await sendAndConfirmTransaction(connection, transaction, [payer, program], {
2963
- commitment: 'confirmed'
2985
+ const deployCommitment = 'processed';
2986
+ const finalizeSignature = await connection.sendTransaction(transaction, [payer, program], {
2987
+ preflightCommitment: deployCommitment
2964
2988
  });
2989
+ const {
2990
+ context,
2991
+ value
2992
+ } = await connection.confirmTransaction({
2993
+ signature: finalizeSignature,
2994
+ lastValidBlockHeight: transaction.lastValidBlockHeight,
2995
+ blockhash: transaction.recentBlockhash
2996
+ }, deployCommitment);
2997
+ if (value.err) {
2998
+ throw new Error(`Transaction ${finalizeSignature} failed (${JSON.stringify(value)})`);
2999
+ }
3000
+ // We prevent programs from being usable until the slot after their deployment.
3001
+ // See https://github.com/solana-labs/solana/pull/29654
3002
+ while (true // eslint-disable-line no-constant-condition
3003
+ ) {
3004
+ try {
3005
+ const currentSlot = await connection.getSlot({
3006
+ commitment: deployCommitment
3007
+ });
3008
+ if (currentSlot > context.slot) {
3009
+ break;
3010
+ }
3011
+ } catch {
3012
+ /* empty */
3013
+ }
3014
+ await new Promise(resolve => setTimeout(resolve, Math.round(MS_PER_SLOT / 2)));
3015
+ }
2965
3016
  }
2966
3017
 
2967
3018
  // success
@@ -5734,29 +5785,6 @@ class RpcWebSocketClient extends RpcWebSocketCommonClient {
5734
5785
  }
5735
5786
  }
5736
5787
 
5737
- // TODO: These constants should be removed in favor of reading them out of a
5738
- // Syscall account
5739
-
5740
- /**
5741
- * @internal
5742
- */
5743
- const NUM_TICKS_PER_SECOND = 160;
5744
-
5745
- /**
5746
- * @internal
5747
- */
5748
- const DEFAULT_TICKS_PER_SLOT = 64;
5749
-
5750
- /**
5751
- * @internal
5752
- */
5753
- const NUM_SLOTS_PER_SECOND = NUM_TICKS_PER_SECOND / DEFAULT_TICKS_PER_SLOT;
5754
-
5755
- /**
5756
- * @internal
5757
- */
5758
- const MS_PER_SLOT = 1000 / NUM_SLOTS_PER_SECOND;
5759
-
5760
5788
  /**
5761
5789
  * @internal
5762
5790
  */
@@ -7211,7 +7239,7 @@ class Connection {
7211
7239
  /**
7212
7240
  * Fetch all the token accounts owned by the specified account
7213
7241
  *
7214
- * @return {Promise<RpcResponseAndContext<Array<{pubkey: PublicKey, account: AccountInfo<Buffer>}>>>}
7242
+ * @return {Promise<RpcResponseAndContext<GetProgramAccountsResponse>}
7215
7243
  */
7216
7244
  async getTokenAccountsByOwner(ownerAddress, filter, commitmentOrConfig) {
7217
7245
  const {
@@ -7408,6 +7436,8 @@ class Connection {
7408
7436
  *
7409
7437
  * @return {Promise<Array<{pubkey: PublicKey, account: AccountInfo<Buffer>}>>}
7410
7438
  */
7439
+
7440
+ // eslint-disable-next-line no-dupe-class-members
7411
7441
  async getProgramAccounts(programId, configOrCommitment) {
7412
7442
  const {
7413
7443
  commitment,
@@ -7419,7 +7449,8 @@ class Connection {
7419
7449
  } = config || {};
7420
7450
  const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', configWithoutEncoding);
7421
7451
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
7422
- const res = create(unsafeRes, jsonRpcResult(array(KeyedAccountInfoResult)));
7452
+ const baseSchema = array(KeyedAccountInfoResult);
7453
+ const res = configWithoutEncoding.withContext === true ? create(unsafeRes, jsonRpcResultAndContext(baseSchema)) : create(unsafeRes, jsonRpcResult(baseSchema));
7423
7454
  if ('error' in res) {
7424
7455
  throw new SolanaJSONRPCError(res.error, `failed to get accounts owned by program ${programId.toBase58()}`);
7425
7456
  }