@solana/web3.js 1.3.1 → 1.4.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
@@ -840,6 +840,57 @@ declare module '@solana/web3.js' {
840
840
  /** stake inactive during the epoch */
841
841
  inactive: number;
842
842
  };
843
+ /**
844
+ * Data slice argument for getProgramAccounts
845
+ */
846
+ export type DataSlice = {
847
+ /** offset of data slice */
848
+ offset: number;
849
+ /** length of data slice */
850
+ length: number;
851
+ };
852
+ /**
853
+ * Memory comparison filter for getProgramAccounts
854
+ */
855
+ export type MemcmpFilter = {
856
+ memcmp: {
857
+ /** offset into program account data to start comparison */
858
+ offset: number;
859
+ /** data to match, as base-58 encoded string and limited to less than 129 bytes */
860
+ bytes: string;
861
+ };
862
+ };
863
+ /**
864
+ * Data size comparison filter for getProgramAccounts
865
+ */
866
+ export type DataSizeFilter = {
867
+ /** Size of data for program account data length comparison */
868
+ dataSize: number;
869
+ };
870
+ /**
871
+ * A filter object for getProgramAccounts
872
+ */
873
+ export type GetProgramAccountsFilter = MemcmpFilter | DataSizeFilter;
874
+ /**
875
+ * Configuration object for getProgramAccounts requests
876
+ */
877
+ export type GetProgramAccountsConfig = {
878
+ /** Optional commitment level */
879
+ commitment?: Commitment;
880
+ /** Optional encoding for account data (default base64) */
881
+ encoding?: 'base64' | 'jsonParsed';
882
+ /** Optional data slice to limit the returned account data */
883
+ dataSlice?: DataSlice;
884
+ /** Optional array of filters to apply to accounts */
885
+ filters?: GetProgramAccountsFilter[];
886
+ };
887
+ /**
888
+ * Configuration object for getParsedProgramAccounts
889
+ */
890
+ export type GetParsedProgramAccountsConfig = Exclude<
891
+ GetProgramAccountsConfig,
892
+ 'encoding' | 'dataSlice'
893
+ >;
843
894
  /**
844
895
  * Information describing an account
845
896
  */
@@ -1125,7 +1176,7 @@ declare module '@solana/web3.js' {
1125
1176
  */
1126
1177
  getProgramAccounts(
1127
1178
  programId: PublicKey,
1128
- commitment?: Commitment,
1179
+ configOrCommitment?: GetProgramAccountsConfig | Commitment,
1129
1180
  ): Promise<
1130
1181
  Array<{
1131
1182
  pubkey: PublicKey;
@@ -1139,7 +1190,7 @@ declare module '@solana/web3.js' {
1139
1190
  */
1140
1191
  getParsedProgramAccounts(
1141
1192
  programId: PublicKey,
1142
- commitment?: Commitment,
1193
+ configOrCommitment?: GetParsedProgramAccountsConfig | Commitment,
1143
1194
  ): Promise<
1144
1195
  Array<{
1145
1196
  pubkey: PublicKey;
package/lib/index.esm.js CHANGED
@@ -3505,8 +3505,29 @@ class Connection {
3505
3505
  */
3506
3506
 
3507
3507
 
3508
- async getProgramAccounts(programId, commitment) {
3509
- const args = this._buildArgs([programId.toBase58()], commitment, 'base64');
3508
+ async getProgramAccounts(programId, configOrCommitment) {
3509
+ const extra = {};
3510
+ let commitment;
3511
+ let encoding;
3512
+
3513
+ if (configOrCommitment) {
3514
+ if (typeof configOrCommitment === 'string') {
3515
+ commitment = configOrCommitment;
3516
+ } else {
3517
+ commitment = configOrCommitment.commitment;
3518
+ encoding = configOrCommitment.encoding;
3519
+
3520
+ if (configOrCommitment.dataSlice) {
3521
+ extra.dataSlice = configOrCommitment.dataSlice;
3522
+ }
3523
+
3524
+ if (configOrCommitment.filters) {
3525
+ extra.filters = configOrCommitment.filters;
3526
+ }
3527
+ }
3528
+ }
3529
+
3530
+ const args = this._buildArgs([programId.toBase58()], commitment, encoding || 'base64', extra);
3510
3531
 
3511
3532
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
3512
3533
  const res = create(unsafeRes, jsonRpcResult(array(KeyedAccountInfoResult)));
@@ -3524,8 +3545,23 @@ class Connection {
3524
3545
  */
3525
3546
 
3526
3547
 
3527
- async getParsedProgramAccounts(programId, commitment) {
3528
- const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed');
3548
+ async getParsedProgramAccounts(programId, configOrCommitment) {
3549
+ const extra = {};
3550
+ let commitment;
3551
+
3552
+ if (configOrCommitment) {
3553
+ if (typeof configOrCommitment === 'string') {
3554
+ commitment = configOrCommitment;
3555
+ } else {
3556
+ commitment = configOrCommitment.commitment;
3557
+
3558
+ if (configOrCommitment.filters) {
3559
+ extra.filters = configOrCommitment.filters;
3560
+ }
3561
+ }
3562
+ }
3563
+
3564
+ const args = this._buildArgs([programId.toBase58()], commitment, 'jsonParsed', extra);
3529
3565
 
3530
3566
  const unsafeRes = await this._rpcRequest('getProgramAccounts', args);
3531
3567
  const res = create(unsafeRes, jsonRpcResult(array(KeyedParsedAccountInfoResult)));