-
Notifications
You must be signed in to change notification settings - Fork 907
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(experimental): decouple @solana/accounts from @solana/rpc-co…
…re (#2051) This PR removes the `@solana/rpc-core` dependency from `@solana/accounts` which avoids ending up with unused nested dependencies such as `@solana/transactions` when we only need the `GetAccountInfoApi` and `GetMultipleAccountsApi` types. It does this by simply duplicating the types locally in the `@solana/accounts` package.
- Loading branch information
1 parent
098806e
commit 35de86b
Showing
10 changed files
with
223 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { Address } from '@solana/addresses'; | ||
import type { | ||
Base58EncodedBytes, | ||
Base58EncodedDataResponse, | ||
Base64EncodedDataResponse, | ||
Base64EncodedZStdCompressedDataResponse, | ||
LamportsUnsafeBeyond2Pow53Minus1, | ||
U64UnsafeBeyond2Pow53Minus1, | ||
} from '@solana/rpc-types'; | ||
|
||
export type DataSlice = Readonly<{ | ||
offset: number; | ||
length: number; | ||
}>; | ||
|
||
export type AccountInfoBase = Readonly<{ | ||
/** indicates if the account contains a program (and is strictly read-only) */ | ||
executable: boolean; | ||
/** number of lamports assigned to this account */ | ||
lamports: LamportsUnsafeBeyond2Pow53Minus1; | ||
/** pubkey of the program this account has been assigned to */ | ||
owner: Address; | ||
/** the epoch at which this account will next owe rent */ | ||
rentEpoch: U64UnsafeBeyond2Pow53Minus1; | ||
}>; | ||
|
||
/** @deprecated */ | ||
export type AccountInfoWithBase58Bytes = Readonly<{ | ||
data: Base58EncodedBytes; | ||
}>; | ||
|
||
/** @deprecated */ | ||
export type AccountInfoWithBase58EncodedData = Readonly<{ | ||
data: Base58EncodedDataResponse; | ||
}>; | ||
|
||
export type AccountInfoWithBase64EncodedData = Readonly<{ | ||
data: Base64EncodedDataResponse; | ||
}>; | ||
|
||
export type AccountInfoWithBase64EncodedZStdCompressedData = Readonly<{ | ||
data: Base64EncodedZStdCompressedDataResponse; | ||
}>; | ||
|
||
export type AccountInfoWithJsonData = Readonly<{ | ||
data: | ||
| JsonParsedDataResponse | ||
// If `jsonParsed` encoding is requested but a parser cannot be found for the given | ||
// account the `data` field falls back to `base64`. | ||
| Base64EncodedDataResponse; | ||
}>; | ||
|
||
export type JsonParsedDataResponse<TData = object> = Readonly<{ | ||
// Name of the program that owns this account. | ||
program: string; | ||
parsed: { | ||
info?: TData; | ||
type: string; | ||
}; | ||
space: U64UnsafeBeyond2Pow53Minus1; | ||
}>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { Address } from '@solana/addresses'; | ||
import type { Commitment, IRpcApiMethods, RpcResponse, Slot } from '@solana/rpc-types'; | ||
|
||
import { | ||
AccountInfoBase, | ||
AccountInfoWithBase58Bytes, | ||
AccountInfoWithBase58EncodedData, | ||
AccountInfoWithBase64EncodedData, | ||
AccountInfoWithBase64EncodedZStdCompressedData, | ||
AccountInfoWithJsonData, | ||
DataSlice, | ||
} from './common'; | ||
|
||
type GetAccountInfoApiResponseBase = RpcResponse<AccountInfoBase | null>; | ||
|
||
type NestInRpcResponseOrNull<T> = Readonly<{ | ||
value: T | null; | ||
}>; | ||
|
||
type GetAccountInfoApiCommonConfig = Readonly<{ | ||
// Defaults to `finalized` | ||
commitment?: Commitment; | ||
// The minimum slot that the request can be evaluated at | ||
minContextSlot?: Slot; | ||
}>; | ||
|
||
type GetAccountInfoApiSliceableCommonConfig = Readonly<{ | ||
// Limit the returned account data using the provided "offset: <usize>" and "length: <usize>" fields. | ||
dataSlice?: DataSlice; | ||
}>; | ||
|
||
export interface GetAccountInfoApi extends IRpcApiMethods { | ||
/** | ||
* Returns all information associated with the account of provided public key | ||
*/ | ||
getAccountInfo( | ||
address: Address, | ||
config: GetAccountInfoApiCommonConfig & | ||
GetAccountInfoApiSliceableCommonConfig & | ||
Readonly<{ | ||
encoding: 'base64'; | ||
}>, | ||
): GetAccountInfoApiResponseBase & NestInRpcResponseOrNull<AccountInfoWithBase64EncodedData>; | ||
getAccountInfo( | ||
address: Address, | ||
config: GetAccountInfoApiCommonConfig & | ||
GetAccountInfoApiSliceableCommonConfig & | ||
Readonly<{ | ||
encoding: 'base64+zstd'; | ||
}>, | ||
): GetAccountInfoApiResponseBase & NestInRpcResponseOrNull<AccountInfoWithBase64EncodedZStdCompressedData>; | ||
getAccountInfo( | ||
address: Address, | ||
config: GetAccountInfoApiCommonConfig & | ||
Readonly<{ | ||
encoding: 'jsonParsed'; | ||
}>, | ||
): GetAccountInfoApiResponseBase & NestInRpcResponseOrNull<AccountInfoWithJsonData>; | ||
getAccountInfo( | ||
address: Address, | ||
config: GetAccountInfoApiCommonConfig & | ||
GetAccountInfoApiSliceableCommonConfig & | ||
Readonly<{ | ||
encoding: 'base58'; | ||
}>, | ||
): GetAccountInfoApiResponseBase & NestInRpcResponseOrNull<AccountInfoWithBase58EncodedData>; | ||
getAccountInfo( | ||
address: Address, | ||
config?: GetAccountInfoApiCommonConfig, | ||
): GetAccountInfoApiResponseBase & NestInRpcResponseOrNull<AccountInfoWithBase58Bytes>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import type { Address } from '@solana/addresses'; | ||
import type { Commitment, IRpcApiMethods, RpcResponse, Slot } from '@solana/rpc-types'; | ||
|
||
import { | ||
AccountInfoBase, | ||
AccountInfoWithBase58EncodedData, | ||
AccountInfoWithBase64EncodedData, | ||
AccountInfoWithBase64EncodedZStdCompressedData, | ||
AccountInfoWithJsonData, | ||
DataSlice, | ||
} from './common'; | ||
|
||
type GetMultipleAccountsApiResponseBase = AccountInfoBase | null; | ||
|
||
type GetMultipleAccountsApiCommonConfig = Readonly<{ | ||
/** Defaults to `finalized` */ | ||
commitment?: Commitment; | ||
/** The minimum slot that the request can be evaluated at */ | ||
minContextSlot?: Slot; | ||
}>; | ||
|
||
type GetMultipleAccountsApiSliceableCommonConfig = Readonly<{ | ||
/** Limit the returned account data */ | ||
dataSlice?: DataSlice; | ||
}>; | ||
|
||
export interface GetMultipleAccountsApi extends IRpcApiMethods { | ||
/** | ||
* Returns the account information for a list of Pubkeys. | ||
*/ | ||
getMultipleAccounts( | ||
/** An array of up to 100 Pubkeys to query */ | ||
addresses: Address[], | ||
config: GetMultipleAccountsApiCommonConfig & | ||
GetMultipleAccountsApiSliceableCommonConfig & | ||
Readonly<{ | ||
encoding: 'base64'; | ||
}>, | ||
): RpcResponse<(GetMultipleAccountsApiResponseBase & (AccountInfoWithBase64EncodedData | null))[]>; | ||
getMultipleAccounts( | ||
/** An array of up to 100 Pubkeys to query */ | ||
addresses: Address[], | ||
config: GetMultipleAccountsApiCommonConfig & | ||
GetMultipleAccountsApiSliceableCommonConfig & | ||
Readonly<{ | ||
encoding: 'base64+zstd'; | ||
}>, | ||
): RpcResponse<(GetMultipleAccountsApiResponseBase & (AccountInfoWithBase64EncodedZStdCompressedData | null))[]>; | ||
getMultipleAccounts( | ||
/** An array of up to 100 Pubkeys to query */ | ||
addresses: Address[], | ||
config: GetMultipleAccountsApiCommonConfig & | ||
Readonly<{ | ||
encoding: 'jsonParsed'; | ||
}>, | ||
): RpcResponse<(GetMultipleAccountsApiResponseBase & (AccountInfoWithJsonData | null))[]>; | ||
getMultipleAccounts( | ||
/** An array of up to 100 Pubkeys to query */ | ||
addresses: Address[], | ||
config: GetMultipleAccountsApiCommonConfig & | ||
GetMultipleAccountsApiSliceableCommonConfig & | ||
Readonly<{ | ||
encoding: 'base58'; | ||
}>, | ||
): RpcResponse<(GetMultipleAccountsApiResponseBase & (AccountInfoWithBase58EncodedData | null))[]>; | ||
getMultipleAccounts( | ||
/** An array of up to 100 Pubkeys to query */ | ||
addresses: Address[], | ||
config?: GetMultipleAccountsApiCommonConfig, | ||
): RpcResponse<(GetMultipleAccountsApiResponseBase & (AccountInfoWithBase64EncodedData | null))[]>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export * from './common'; | ||
export * from './getAccountInfo'; | ||
export * from './getMultipleAccounts'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.