Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for malformed responses in getAccountInfo/getMultipleAccounts #50

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

archseer
Copy link
Contributor

GetObject could unmarshal into nil which would cause a panic when referring to out.Value.

This is unlikely since a node will typically return well formed responses but still worth fixing.

GetObject could unmarshal into nil which would cause a panic when
referring to out.Value.
@archseer
Copy link
Contributor Author

Most RPC calls also have issues: they return pointers which could be deserialized to nil.

For example

// GetBalance returns the balance of the account of provided publicKey.
func (cl *Client) GetBalance(
ctx context.Context,
// Pubkey of account to query. Required.
publicKey solana.PublicKey,
// Commitment requirement. Optional.
commitment CommitmentType,
) (out *GetBalanceResult, err error) {
could return GetBalanceResult rather than *GetBalanceResult?

@gagliardetto
Copy link
Owner

See #45

@gagliardetto
Copy link
Owner

Most RPC calls also have issues: they return pointers which could be deserialized to nil.

For example

// GetBalance returns the balance of the account of provided publicKey.
func (cl *Client) GetBalance(
ctx context.Context,
// Pubkey of account to query. Required.
publicKey solana.PublicKey,
// Commitment requirement. Optional.
commitment CommitmentType,
) (out *GetBalanceResult, err error) {

could return GetBalanceResult rather than *GetBalanceResult?

How would you know that you have a real GetBalanceResult an not just one that was null json? You can only if you use a *GetBalanceResult.

If the response deserializes to nil, that either follows the spec (e.g. getBlock: https://github.com/solana-labs/solana/blob/master/docs/src/developing/clients/jsonrpc-api.md#getblock ) or is an error on the RPC provider part.

I'll leave that to the library user for now to implement given they know best that RPC they are dealing with.

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.

None yet

2 participants