coral-xyz / anchor

⚓ Solana Sealevel Framework
https://anchor-lang.com
Apache License 2.0
3.69k stars 1.35k forks source link

Seed Parser Missing Path: function call with arguments #2170

Open GuidoDipietro opened 2 years ago

GuidoDipietro commented 2 years ago

Description

Something like this throws an annoying long warning:

seeds = [
   pda.field.checked_add(1).unwrap().to_le_bytes().as_ref()
]

Since the parser takes everything before the () in unwrap (see this line), therefore generating a long path which can't be found as a name for nothing, just breaking everything.

Current workaround

The current solution for developers is to implement a trait / method for the type in order to have a call like:

seeds = [
   pda.field.checked_add_one().to_le_bytes().as_ref()
]

Basically, have the first method call use no arguments.

Proposed change

Add the missing seed path to pda.rs.

Henry-E commented 1 year ago

Interesting, so you can't have functions which take arguments on top of the pda seed variables. It kind of makes sense because you don't really want to be doing all sorts of weird stuff with your seeds tbh, they should be pretty clear as to what they are and how you obtain them. If you wanted to make a pr to make the seed parsing more robust (so long as it doesn't break anything or introduce vulnerabilities) it's something I could possibly review.