feat: add token methods (#11303)

This commit is contained in:
Justin Starry
2020-07-31 12:33:54 +08:00
committed by GitHub
parent a5b6fd3d9b
commit 5a69c66877
7 changed files with 509 additions and 1 deletions

40
web3.js/module.d.ts vendored
View File

@ -50,6 +50,14 @@ declare module '@solana/web3.js' {
skipPreflight?: boolean;
};
export type TokenAccountsFilter =
| {
mint: PublicKey;
}
| {
programId: PublicKey;
};
export type RpcResponseAndContext<T> = {
context: Context;
value: T;
@ -150,6 +158,23 @@ declare module '@solana/web3.js' {
root: number;
};
export type TokenAccountInfo = {
mint: PublicKey;
owner: PublicKey;
amount: number;
delegate: null | PublicKey;
delegatedAmount: number;
isInitialized: boolean;
isNative: boolean;
};
export type TokenAccount = {
executable: boolean;
owner: PublicKey;
lamports: number;
data: TokenAccountInfo;
};
export type AccountChangeCallback = (
accountInfo: AccountInfo,
context: Context,
@ -239,6 +264,21 @@ declare module '@solana/web3.js' {
getMinimumLedgerSlot(): Promise<number>;
getFirstAvailableBlock(): Promise<number>;
getSupply(commitment?: Commitment): Promise<RpcResponseAndContext<Supply>>;
getTokenSupply(
tokenMintAddress: PublicKey,
commitment?: Commitment,
): Promise<RpcResponseAndContext<number>>;
getTokenAccountBalance(
tokenAddress: PublicKey,
commitment?: Commitment,
): Promise<RpcResponseAndContext<number>>;
getTokenAccountsByOwner(
ownerAddress: PublicKey,
filter: TokenAccountsFilter,
commitment?: Commitment,
): Promise<
RpcResponseAndContext<Array<{pubkey: PublicKey; account: TokenAccount}>>
>;
getLargestAccounts(
config?: GetLargestAccountsConfig,
): Promise<RpcResponseAndContext<Array<AccountBalancePair>>>;