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

How to decode account data into custom object? #140

Closed
nukec opened this issue Jul 3, 2021 · 3 comments
Closed

How to decode account data into custom object? #140

nukec opened this issue Jul 3, 2021 · 3 comments
Labels
help wanted Extra attention is needed

Comments

@nukec
Copy link

nukec commented Jul 3, 2021

Seems that I cant find an example for that. I'm using base64.

@hoakbuilds
Copy link
Member

hoakbuilds commented Jul 3, 2021

This depends on the kind of object you're trying to decode but here's a general idea of what to do to try and decode the data:

First and foremost decode the data from base64 into a byte[] a Span<byte> or whatever your preferred type for this is going to be, you can check some examples of this being done in the Serum code here (note: this code is still under development and subject to changes)

Afterwards, it depends on the type of account you're trying to decode, certain accounts will have a certain data layout, i.e. Serum Market accounts have a certain layout (Serum Market account layouts), and they have to be decoded according to that layout, by using offsets and reading the desired data type for the account type/layout at the specific offset, as you can see by the static Deserialize method on the Market class here.

Does this answer your question?

@hoakbuilds hoakbuilds added the help wanted Extra attention is needed label Jul 3, 2021
@hoakbuilds
Copy link
Member

To add more context to this, the latest v0.3.1 release features additions of utility methods that can be used to make encoding and decoding of program and account data much easier, the implementations of SPL and Native programs inside Solnet.Programs have already been refactored to use these methods, while the refactoring of Solnet.Serum to use these same methods is underway. You can check those methods here:

Encoding
Decoding

They should make the program and account data encoding and decoding much cleaner and easy to implement, they are also open to additions :)

@nukec
Copy link
Author

nukec commented Jul 3, 2021

thanks that helped

@nukec nukec closed this as completed Jul 3, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants