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

Add discriminator to the account and allow encoding/decoding of non-account types #672

Merged
merged 1 commit into from
Apr 25, 2024

Conversation

nolag
Copy link
Contributor

@nolag nolag commented Apr 19, 2024

When an account is stored from an Anchor contract on Solana, a discriminator is added as the first 8 bytes to ensure that the right data is being loaded. This was missed when decoding the account.

Additionally, users can define types and should be able to encode them to either sign or write to chain. This PR adds that ability as well.

@nolag nolag requested a review from a team as a code owner April 19, 2024 15:03
@nolag nolag force-pushed the rtinianov_lenient branch from fe9bc90 to 9a44563 Compare April 23, 2024 13:39
@nolag nolag requested a review from a team as a code owner April 23, 2024 13:39
@nolag nolag force-pushed the rtinianov_lenient branch from 9a44563 to fc974f2 Compare April 23, 2024 13:40
@nolag nolag force-pushed the rtinianov_discriminator branch from 13cfae3 to 0f5ebb4 Compare April 23, 2024 15:37
Base automatically changed from rtinianov_lenient to develop April 23, 2024 17:41
@nolag nolag force-pushed the rtinianov_discriminator branch from 0f5ebb4 to ea5f04f Compare April 23, 2024 17:44
@nolag nolag force-pushed the rtinianov_discriminator branch from ea5f04f to 4585c2f Compare April 24, 2024 16:31
@nolag nolag requested a review from jmank88 April 24, 2024 17:33
Copy link
Collaborator

@aalu1418 aalu1418 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overall looks good to me, just one small concern

if includeDiscriminator {
desLen = 1
}
named := make([]encodings.NamedTypeCodec, len(*def.Type.Fields)+desLen)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a nil pointer concern for dereferencing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add it in this PR, but I don't think so. The call only gets made if the type is a struct so I expect the fields would be present but empty if there are no fields.

There are a few derefs later on as well.

@nolag nolag requested a review from aalu1418 April 24, 2024 18:11
aalu1418
aalu1418 previously approved these changes Apr 24, 2024
Copy link
Collaborator

@aalu1418 aalu1418 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm for the solana specifics!

ideally someone from the chainreader side can also approve

pkg/solana/codec/solana.go Outdated Show resolved Hide resolved
@nolag nolag force-pushed the rtinianov_discriminator branch from d6720af to 558dbd8 Compare April 25, 2024 15:38
@nolag nolag requested a review from aalu1418 April 25, 2024 15:38
@aalu1418 aalu1418 enabled auto-merge (squash) April 25, 2024 15:39
@aalu1418 aalu1418 merged commit 5a8659f into develop Apr 25, 2024
26 checks passed
@aalu1418 aalu1418 deleted the rtinianov_discriminator branch April 25, 2024 17:00
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