Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/rpc-core/src/types/jsonRpcApi.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { GetAccountInfoApi } from './rpc-methods/getAccountInfo';
import { GetBlockHeightApi } from './rpc-methods/getBlockHeight';
import { GetBlocksApi } from './rpc-methods/getBlocks';

declare interface JsonRpcApi extends GetBlockHeightApi, GetBlocksApi {}
declare interface JsonRpcApi extends GetAccountInfoApi, GetBlockHeightApi, GetBlocksApi {}
5 changes: 5 additions & 0 deletions packages/rpc-core/src/types/rpc-methods/common.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
declare type DataSlice = readonly {
offset: number;
length: number;
};

// TODO: Eventually move this into whatever package implements transactions
declare type Finality = 'confirmed' | 'finalized' | 'processed';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Is Finality the new term? If so, we should probably update the docs and all that. I'd prefer to keep this Commitment to make mental mapping easier, but I won't put up a big fight about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooh. I thought these three were what we're calling finality, as opposed to the olde deprecated suite of commitments.

From web3.js today:

https://github.com/solana-labs/solana-web3.js/blob/ad23683e8a42c726995cf0c1f0f903b20152854f/packages/library-legacy/src/connection.ts#L476-L501

So yeah, I have this wrong, somehow. I'll rename it.


Expand Down
92 changes: 92 additions & 0 deletions packages/rpc-core/src/types/rpc-methods/getAccountInfo.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
import { Base58EncodedAddress } from '@solana/keys';
import { IJsonRPCTransport } from '../../rpc';

type Base64EncodedBytes = string & { readonly __base64EncodedBytes: unique symbol };
type Base64EncodedZStdCompressedBytes = string & { readonly __base64EncodedZStdCompressedBytes: unique symbol };

type Base64EncodedDataResponse = [Base64EncodedBytes, 'base64'];
type Base64EncodedZStdCompressedDataResponse = [Base64EncodedZStdCompressedBytes, 'base64+zstd'];

type GetAccountInfoApiResponseBase = Readonly<{
context: Readonly<{
slot: Slot;
}>;
value: Readonly<{
executable: boolean;
lamports: number; // TODO(solana-labs/solana/issues/30341) Represent as bigint
owner: Base64EncodedAddress;
rentEpoch: number; // TODO(solana-labs/solana/issues/30341) Represent as bigint
space: number; // TODO(solana-labs/solana/issues/30341) Represent as bigint
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe I'm missing something, but in testing I didn't see space returned here. Here's a token account:

{
  "jsonrpc": "2.0",
  "result": {
    "context": {
      "apiVersion": "1.13.6",
      "slot": 181671824
    },
    "value": {
      "data": [
        "xvp6877brTo9ZfNqq8l0MbG75MLS9uDkfKYCA0UvXWEs07wIp7mh6Iz0YahgZDSe/Psf+oXDeVKNALXKNdFOFAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
        "base64"
      ],
      "executable": false,
      "lamports": 2039280,
      "owner": "TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA",
      "rentEpoch": 0
    }
  },
  "id": 1
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haha. In the docs, this is called size, in the docs' example it's called space, in the current web3.js implementation it's absent, and in the server implementation it's space and it's an Option<u64>.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like this is only in v1.15.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah gotcha

}> | null;
}>;

type GetAccountInfoApiResponseWithEncodedData = Readonly<{
value: Readonly<{
data: Base64EncodedDataResponse;
}> | null;
}>;

type GetAccountInfoApiResponseWithEncodedZStdCompressedData = Readonly<{
value: Readonly<{
data: Base64EncodedZStdCompressedDataResponse;
}> | null;
}>;

type GetAccountInfoApiResponseWithJsonData = Readonly<{
value: Readonly<{
data:
| Readonly<{
// Name of the program that owns this account.
program: string;
parsed: unknown;
space: number; // TODO(solana-labs/solana/issues/30341) Represent as bigint
}>
// If `jsonParsed` encoding is requested but a parser cannot be found for the given
// account the `data` field falls back to `base64`.
| Base64EncodedDataResponse;
}> | null;
}>;

type GetAccountInfoApiCommonConfig = readonly {
// Defaults to `finalized`
commitment?: Finality;
// The minimum slot that the request can be evaluated at
minContextSlot?: Slot;
};

type GetAccountInfoApiBase64EncodingCommonConfig = readonly {
// Limit the returned account data using the provided "offset: <usize>" and "length: <usize>" fields.
dataSlice?: DataSlice;
};

declare interface GetAccountInfoApi {
/**
* Returns all information associated with the account of provided public key
*/
getAccountInfo(
transport: IJsonRPCTransport,
address: Base58EncodedAddress,
config?: readonly {
encoding: 'base64';
} &
GetAccountInfoApiCommonConfig &
GetAccountInfoApiBase64EncodingCommonConfig
): Promise<GetAccountInfoApiResponseBase & GetAccountInfoApiResponseWithEncodedData>;
getAccountInfo(
transport: IJsonRPCTransport,
address: Base58EncodedAddress,
config?: readonly {
encoding: 'base64+zstd';
} &
GetAccountInfoApiCommonConfig &
GetAccountInfoApiBase64EncodingCommonConfig
): Promise<GetAccountInfoApiResponseBase & GetAccountInfoApiResponseWithEncodedZStdCompressedData>;
getAccountInfo(
transport: IJsonRPCTransport,
address: Base58EncodedAddress,
config?: readonly {
encoding: 'jsonParsed';
} &
GetAccountInfoApiCommonConfig
): Promise<GetAccountInfoApiResponseBase & GetAccountInfoApiResponseWithJsonData>;
Comment on lines +66 to +91
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a much more complicated example, where you can see how modulating the inputs changes the output type (eg. specifying different encoding results in the output being different.

Things to pay attention to:

  • jsonParsed encoding results in data being a parsed data structure or [bytes, encoding] as a fallback if no parser is available.
  • only base64 encoding accepts dataSlice as an input

See https://docs.solana.com/api/http#getaccountinfo.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is extremely cool, and not nearly as complicated to read as I feared when I first opened the file 😅

}