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

Allowing to specify a different Encoding on GetAccountInfoWithConfig #122

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

pegartillo95
Copy link

This will keep the base GetAccount info to still use base64 encoding but allow users to specify a different one if they want to do so.

@yihau
Copy link
Collaborator

yihau commented Jan 18, 2023

Thanks for the contributing. GetAccountInfoWithConfig will convert encoded data into []byte. If we would like to make this happen, we will need to update here as well

Also, could you share the use case with me? I'm not sure why users need to specify the attribute cuz the data will be transferred into bytes eventually. No matter what users pass, the output data always be []byte

If you would like to get the encoded data, I think you can either

  1. encode the data by yourself
    or
  2. use c.RpcClient. GetAccountInfoWithConfig to query

@pedro-seedcx
Copy link

So maybe I understood wrong the Encoding field for that RPC method. Does it change the way the whole returned payload is encoded or it only does for the Data field of the response?

@yihau
Copy link
Collaborator

yihau commented Jan 18, 2023

@pedro-seedcx
Copy link

And out of curiosity how would you get the json information from the base64 data if you do not specify parsing to be jsonParsed?
What I need to get is the owner inside the data. This is an example of the result of the call when executing it with jsonParsed and I would need to get the inner owner, the one with value DhEsUaJkT1DzkFUWLCkU21VruJQZk1es4zBRhU9QjK9R in this case:
{"context":{"apiVersion":"1.13.5","slot":173125432},"value":{"data":{"parsed":{"info":{"isNative":false,"mint":"Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB","owner":"DhEsUaJkT1DzkFUWLCkU21VruJQZk1es4zBRhU9QjK9R","state":"initialized","tokenAmount":{"amount":"5000000","decimals":6,"uiAmount":5.0,"uiAmountString":"5"}},"type":"account"},"program":"spl-token","space":165},"executable":false,"lamports":2039280,"owner":"TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA","rentEpoch":361}},"id":1}

@pedro-seedcx
Copy link

Added the parsing of the response when you specify it to be jsonParsed. I still think it is needed but I might be missing something

@yihau
Copy link
Collaborator

yihau commented Jan 18, 2023

You can decode data to get it. Seems you would like to get a token account. You can either
https://portto.github.io/solana-go-sdk/tour/get-token-account.html
or
use this function https://github.com/portto/solana-go-sdk/blob/main/client/token.go#L9 directlly

jsonParsed not only decodes for token account but also mint, vote, stake ...
so your InfoStruct only works when the account is token account.

@pedro-seedcx
Copy link

I got it, thanks a lot for your help. Then you are completely right and there is no need to add my code.

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.

3 participants