RFC: add discriminator to idl#2138
RFC: add discriminator to idl#2138seanyoung wants to merge 1 commit intosolana-foundation:masterfrom
Conversation
Signed-off-by: Sean Young <[email protected]>
|
@seanyoung is attempting to deploy a commit to the coral-xyz Team on Vercel. A member of the Team first needs to authorize it. |
|
|
||
| /// A marker attribute used to override the discriminator value that should be used. | ||
| #[proc_macro_attribute] | ||
| pub fn discriminator( |
There was a problem hiding this comment.
Can you elaborate on the use case for this macro? When would an anchor program use it?
There was a problem hiding this comment.
So the plan was that #[discriminator(x)] would you allow you to override the discriminator, so that we can test an idl with different discriminator than the standard discriminator created with hashing.
As for a use case,I did imagine a usecase where you can specify a single byte as a discriminator, but this syntax does not allow this yet. This would allow you to just use a single byte rather than 8 bytes for discriminator.
What do you think of:
#[discriminator([42])]
fn foo(..)
or for two byte discriminators:
#[discriminator([42,12])]
fn foo(..)
There was a problem hiding this comment.
If you don't think the attribute is useful, I can create a test using a non-anchor rust contract and a hand-written idl, which is then used from rust and ts.
There was a problem hiding this comment.
I think this could be interesting. How would you handle potential collisions and/or ambiguity with discriminators of different lengths?
|
Closing as stale + implemented in 0.31 |
This adds the following syntax:
This PR is not complete yet - the code generation does not use the discriminator yet, and the client should also use the new value.