IDL: Update discriminants to u32 instead of u8#54
Conversation
#### Problem The IDL used to generate the stake program client declares the instruction discriminant as a `u8`, when the program actually uses `u32`s for the discriminant. #### Summary of changes Update the IDL, update the generate script, then regenerate all of the clients. NOTE: This doesn't cover the `StakeState` and `StakeStateV2` enums, which both use a `u32` discriminant too. I wasn't sure how to do that in the IDL, so omitted it.
|
Looks like there some codegen messing up for Rust -- do I need to update something? I tried updating all of the codama deps, but it didn't resolve the issue. I then removed the trait overrides from the generate script, but that caused other issues because of |
|
It looks like the new default traits for Rust items are causing an issue in this upgrade. You could use the following base traits to avoid using const traitOptions = {
baseDefaults: [
'borsh::BorshSerialize',
'borsh::BorshDeserialize',
'serde::Serialize',
'serde::Deserialize',
'Clone',
'Debug',
// 'Eq', <- Remove 'Eq' from the default traits.
'PartialEq',
],
};You can also be more granular with this if you wanted to (see option docs). Regarding updating the [2min later] Looking at the current script though it looks like something like this already exists. Is is not materialising as a u32 in the generated code? codama.update(
c.bottomUpTransformerVisitor([
{
// enum discriminator -> u32
select: '[definedTypeNode]stakeStateV2.[enumTypeNode]',
transform: (node) => {
c.assertIsNode(node, 'enumTypeNode');
return {
...node,
size: c.numberTypeNode('u32'),
};
},
},
])
); |
Ah ok great, done!
You're right, it's correct for |
|
Oh, but note that the u32 enum discriminant on structs isn't possible with Rust, since it's just using the normal derive macro for borsh |
|
Oh yeah. We really need Rust codecs so anything doable in JS can be done in Rust. Aside from that is this okay to merge? I'm gonna rebase my |
|
Yeah it's ready from my side! So if you approve, I'll merge |
Problem
The IDL used to generate the stake program client declares the instruction discriminant as a
u8, when the program actually usesu32s for the discriminant.Summary of changes
Update the IDL, update the generate script, then regenerate all of the clients.
NOTE: This doesn't cover the
StakeStateandStakeStateV2enums, which both use au32discriminant too. I wasn't sure how to do that in the IDL, so I omitted it.