solana-labs / solana-web3.js

Solana JavaScript SDK
https://solana-labs.github.io/solana-web3.js
MIT License
2.21k stars 878 forks source link

account info type missing typed fields and config values #3569

Open nickfrosty opened 3 days ago

nickfrosty commented 3 days ago

Overview

the rpc.getAccountInfo() function is:

image 1 image 2

Steps to reproduce

use the getAccountInfo rpc method:

const rpc = createSolanaRpc("https://api.devnet.solana.com");
let { value: accountInfo } = await rpc
  .getAccountInfo(address("nick6zJc6HpW3kfBm4xS2dmbuVRyb5F3AnUvj5ymzR5"), {
    // encoding does not appear
  })
  .send();
// shows a type error due to not finding `space`
console.log("accountInfo:", accountInfo.space);

Description of bug

the rpc.getAccountInfo() function should accept all the config settings for the getAccountInfo rpc method

and the response value should be typed to all response fields

steveluscher commented 3 days ago

Interesting.

This gives encoding in the autocomplete:

.getAccountInfo("nick6zJc6HpW3kfBm4xS2dmbuVRyb5F3AnUvj5ymzR5", {})

This does not:

.getAccountInfo(address("nick6zJc6HpW3kfBm4xS2dmbuVRyb5F3AnUvj5ymzR5"), {})
steveluscher commented 3 days ago

space is missing from AccountInfoBase https://github.com/solana-labs/solana-web3.js/blob/a5a3690fdd63849a85b8f582f2351237cbddde9d/packages/rpc-types/src/account-info.ts#L11-L20 cc/ @lorisleiva who last touched this.

steveluscher commented 3 days ago

These docs say size when presumably they mean space, @nickfrosty?

lorisleiva commented 3 days ago

@steveluscher Oh weird, I've checked everywhere and I can't find record of us ever using the size or space attribute on base account types. Doing a quick call to mainnet and I can see the attribute as space. Should I add it?

steveluscher commented 2 days ago

Yeah, so long as it’s actually there, everywhere we use AccountInfoBase, I guess it’s time, @lorisleiva!

lorisleiva commented 2 days ago

Okay I've just checked everywhere we use this AccountInfoBase in the code and compared each one with the docs. The conclusion is: they all return a space attribute of type u64 and some of them are mislabelled in the docs (not in the code example but in the written documentation on the left column). Here's the exhaustive list:

I'll now work on a PR that adds the space attribute to AccountInfoBase. Thank you for raising this!

nickfrosty commented 2 days ago

These docs say size when presumably they mean space, @nickfrosty?

looks like it, I will get those docs updated today!

nickfrosty commented 2 days ago

@lorisleiva I will get these updated in the docs. I have had it on the todo list to comb through all the rpc docs and validate the inputs and responses for too long now. https://github.com/solana-labs/solana-web3.js/issues/3569#issuecomment-2478289388 - I will get all these specific ones updated now :)