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

BUGFIX: Skipping accounts if none exist. #5

Merged
merged 1 commit into from
Apr 9, 2024

Conversation

kilogold
Copy link
Contributor

@kilogold kilogold commented Apr 9, 2024

⚠️ NOTE: Use notes like this to emphasize something important about the PR.

This could include other PRs this PR is built on top of; API breaking changes; reasons for why the PR is on hold; or anything else you would like to draw attention to.

Status Type ⚠️ Core Change Issue
Ready Bug No (N/A)

Problem

Unhandled exception. System.NullReferenceException: Object reference not set to an instance of an object.
   at AnchorSourceGenerator.<>c.<Main>b__0_1(CommandLineOptions opts) in /Users/gabrielepicco/Documents/Solana/Solana.Unity.Anchor/Solana.Unity.Anchor.Tool/AnchorSourceGenerator.cs:line 102
   at CommandLine.ParserResultExtensions.MapResult[TSource,TResult](ParserResult`1 result, Func`2 parsedFunc, Func`2 notParsedFunc)
   at AnchorSourceGenerator.Main(String[] args) in /Users/gabrielepicco/Documents/Solana/Solana.Unity.Anchor/Solana.Unity.Anchor.Tool/AnchorSourceGenerator

Building simple Anchor programs solely using token accounts from anchor-spl will require no additional structs with
#[account] attribute. The parser throws an exception when unable to find the "accounts" attribute in the JSON IDL.

Even an empty Anchor project may be affected (not tested).

Workaround

Add a dummy struct to the Anchor program for populating the IDL fields. For example:

#[account]
pub struct Dummy{
    pub data: u64,
}

Solution

Skip "accounts" token if missing in the IDL.

@kilogold
Copy link
Contributor Author

kilogold commented Apr 9, 2024

If could have done a simple "if" check, but I chose the least invasive change for simpler review.

@GabrielePicco
Copy link
Collaborator

Thanks @kilogold , LGTM

@GabrielePicco GabrielePicco merged commit 12dd70f into magicblock-labs:master Apr 9, 2024
1 check passed
@kilogold kilogold deleted the fix_zero_account branch April 9, 2024 22:29
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.

2 participants