solana-go icon indicating copy to clipboard operation
solana-go copied to clipboard

Check for malformed responses in getAccountInfo/getMultipleAccounts

Open archseer opened this issue 2 years ago • 3 comments

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.

archseer avatar Mar 17 '22 07:03 archseer

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

For example https://github.com/gagliardetto/solana-go/blob/7de08b22f3afd588a275212aff05fa5f2580f356/rpc/getBalance.go#L25-L34 could return GetBalanceResult rather than *GetBalanceResult?

archseer avatar Mar 17 '22 07:03 archseer

See https://github.com/gagliardetto/solana-go/issues/45

gagliardetto avatar Mar 22 '22 14:03 gagliardetto

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

For example

https://github.com/gagliardetto/solana-go/blob/7de08b22f3afd588a275212aff05fa5f2580f356/rpc/getBalance.go#L25-L34

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.

gagliardetto avatar Mar 22 '22 14:03 gagliardetto