Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ incremented for features.

* lang: Add `ErrorCode::AccountNotInitialized` error to separate the situation when the account has the wrong owner from when it does not exist (#[1024](https://github.com/project-serum/anchor/pull/1024))
* lang: Called instructions now log their name by default. This can be turned off with the `no-log-ix-name` flag ([#1057](https://github.com/project-serum/anchor/pull/1057))
* ts: Add `getAccountInfo` helper method to account namespace/client ([#1084](https://github.com/project-serum/anchor/pull/1084))
* lang: `ProgramData` and `UpgradableLoaderState` can now be passed into `Account` as generics. see [UpgradeableLoaderState](https://docs.rs/solana-program/latest/solana_program/bpf_loader_upgradeable/enum.UpgradeableLoaderState.html). `UpgradableLoaderState` can also be matched on to get `ProgramData`, but when `ProgramData` is used instead, anchor does the serialization and checking that it is actually program data for you ([#1095](https://github.com/project-serum/anchor/pull/1095))
* ts: Add better error msgs in the ts client if something wrong (i.e. not a pubkey or a string) is passed in as an account in an instruction accounts object ([#1098](https://github.com/project-serum/anchor/pull/1098))


## [0.18.2] - 2021-11-14

* cli: Replace global JavaScript dependency installs with local.
Expand Down
15 changes: 12 additions & 3 deletions ts/src/program/namespace/account.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
TransactionInstruction,
Commitment,
GetProgramAccountsFilter,
AccountInfo,

@paul-schaaf paul-schaaf Dec 6, 2021

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please add a line about the feature to the changelog as well

} from "@solana/web3.js";
import Provider from "../../provider.js";
import { Idl, IdlTypeDef } from "../../idl.js";
Expand Down Expand Up @@ -137,9 +138,7 @@ export class AccountClient<
* @param address The address of the account to fetch.
*/
async fetchNullable(address: Address): Promise<T | null> {
const accountInfo = await this._provider.connection.getAccountInfo(
translateAddress(address)
);
const accountInfo = await this.getAccountInfo(address);
if (accountInfo === null) {
return null;
}
Expand Down Expand Up @@ -345,6 +344,16 @@ export class AccountClient<
): Promise<PublicKey> {
return await pubkeyUtil.associated(this._programId, ...args);
}

async getAccountInfo(
address: Address,
commitment?: Commitment
): Promise<AccountInfo<Buffer> | null> {
return await this._provider.connection.getAccountInfo(
translateAddress(address),
commitment
);
}
}

/**
Expand Down