Skip to content

ts: add getAccountInfo helper method to account namespace/client#1084

Merged
paul-schaaf merged 5 commits into
otter-sec:masterfrom
dominictwlee:ts/add-get-account-info-helper
Dec 8, 2021
Merged

ts: add getAccountInfo helper method to account namespace/client#1084
paul-schaaf merged 5 commits into
otter-sec:masterfrom
dominictwlee:ts/add-get-account-info-helper

Conversation

@dominictwlee

@dominictwlee dominictwlee commented Nov 30, 2021

Copy link
Copy Markdown
Contributor

Closes #640

This exposes connection.getAccountInfo to the namespace client's public API.

I've written an integration test separately but wasn't sure how to symlink a locally built anchor cli to run the tests. It seems all the integration tests run against the published/installed version of anchor. Should I just do that separately when this change is merged and published?

Comment thread ts/src/program/namespace/account.ts Outdated
return await pubkeyUtil.associated(this._programId, ...args);
}

async getAccountInfo(address: Address, commitment?: Commitment) {

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.

I think this async can be removed?

@fanatid fanatid Dec 1, 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.

Interesting, connection.getAccountInfo return Promise, but no await inside the function.
Q: function return promise or result? 🙂

A: promise will be resolved with async or without async. But for clarity better leave async with await.

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.

yea you dont need async if you just return sth and theres no await inside the function. if it returns a promise the caller can await. I get the clarity argument but wouldnt it be more idiomatic to have an explicit return type then instead of inference and async which implies there is an await.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

cool happy to amend that, wasn't sure what the convention was for this repo.

Would it make sense to add an eslint rule to enforce it in the future if that's the case?

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.

my answer was a question. not sure what the convention is myself. dont think we have one except "make prettier happy" for now. but I think that can be a discussion for a different issue

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.

I'd prefer to have async getAccountInfo with inner await.

@dominictwlee dominictwlee Dec 3, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If it helps, there are subtle differences to return Vs return await besides just syntactic ones.

https://eslint.org/docs/rules/no-return-await
p.s. this just has a good description of the subtle differences, not saying I support this particular rule.

https://jakearchibald.com/2017/await-vs-return-vs-return-await/

Don't mind either way, but something to take into consideration perhaps? I think another difference is that the V8 engine provides better stack traces with return await

@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.

I think another difference is that the V8 engine provides better stack traces with return await

so it would seem!
goldbergyoni/nodebestpractices#737

let's do return await then

Comment thread ts/src/program/namespace/account.ts Outdated
const accountInfo = await this._provider.connection.getAccountInfo(
translateAddress(address)
);
const accountInfo = await this.getAccountInfo(translateAddress(address));

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.

your getAccountInfo translates the address inside so no need to do it here

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

@dominictwlee dominictwlee changed the title add getAccountInfo helper to client ts: add getAccountInfo helper to client Dec 7, 2021
@dominictwlee dominictwlee changed the title ts: add getAccountInfo helper to client ts: add getAccountInfo helper method to account namespace/client Dec 7, 2021
@dominictwlee dominictwlee force-pushed the ts/add-get-account-info-helper branch from f32ca82 to 03fd1ab Compare December 7, 2021 09:59
@paul-schaaf paul-schaaf merged commit bef1bd8 into otter-sec:master Dec 8, 2021
Otter-0x4ka5h pushed a commit to Otter-0x4ka5h/anchor that referenced this pull request Mar 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ts: Add accountInfo to account namespace/client

3 participants