-
Notifications
You must be signed in to change notification settings - Fork 64
Generate parsers for instructions with optional accounts #438
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
Generate parsers for instructions with optional accounts #438
Conversation
|
|
I am not really qualified to review the domain logic of this renderer so pinging @kespinola so he can take a look. 🙏 |
Nagaprasadvr
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
few changes to fix logic
| let ix_accounts = {{ instruction.name | pascalCase }}IxAccounts{ | ||
| {% for account in instruction.accounts %} | ||
| {% if account.isOptional %} | ||
| {{ account.name | snakeCase }}: Some(Pubkey::new_from_array(ix.accounts[{{ account.index }}].0)).into(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
u also need to check if accounts_len == instruction.accounts.len() then we can decide that optional account was passed and can set it to Some(...) or else we set it to None
also need to be careful with indexes of accounts depending on optional accounts
i guess u can do
let expected_ix_accounts_len = {{ instruction.accounts | length }};
let ix_accounts = if accounts_len == expected_ix_accounts_len {
{{ instruction.name | pascalCase }}IxAccounts{
{% for account in instruction.accounts %}
{% if account.isOptional %}
{{ account.name | snakeCase }}: Some(Pubkey::new_from_array(ix.accounts[{{ account.index }}].0)).into(),
{% else %}
{{ account.name | snakeCase }}: ix.accounts[{{ account.index }}].0.into(),
{% endif %}
{% endfor %}
}
}
else {
{{ instruction.name | pascalCase }}IxAccounts{
{% for account in instruction.accounts %}
{% if account.isOptional %}
{{ account.name | snakeCase }}: None
{% else %}
{{ account.name | snakeCase }}: ix.accounts[{{ account.index }}].0.into(),
{% endif %}
{% endfor %}
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@slimeonmyhead do you have the time to implement these changes? We can also update.
|
just checked rust sdk logic - which is defaulting to program id whn processing optional accounts , so we need to add checks for program id as well here |
|
hey @slimeonmyhead any updates on this ? |
Not sure if I'm missing anything with this fix, but it works with the parsers that I tested it on.
The
check_min_accounts_reqis still in place at the top, so it will only parse if the account is defined.My solana knowledge is lacking here: Is there a situation where an instruction has an optional account in the sdk and doesn't default to some value in the on-chain call?
In the cases that I checked (such as meteora swap and jupiter route) the optional accounts are defaulted to the program.