anchor
anchor copied to clipboard
Anchor 0.28.0 IDL Events Do Not Correctly Refer to Account Types
Example IDL Event:
"events": [
{
"name": "InitializeEvent",
"fields": [
{
"name": "state",
"type": {
"defined": "State"
},
"index": false
},
{
"name": "payer",
"type": "publicKey",
"index": false
}
]
},
{
"name": "Initialize2Event",
"fields": [
{
"name": "state",
"type": {
"defined": "State2"
},
"index": false
},
{
"name": "payer",
"type": "publicKey",
"index": false
}
]
}
],
From the following definition:
/// An account containing various fields
#[account]
pub struct State {
...
}
#[account]
pub struct State2 {
...
}
#[event]
pub struct InitializeEvent {
state: State,
payer: Pubkey,
}
#[event]
pub struct Initialize2Event {
state: State2,
payer: Pubkey,
}
The IDL lists the state
and state2
types as defined
but these types are actually accounts and don't exist in idl.types
. IDL parsers must guess that the types are either in types
or accounts
, or try with types
first and fall-back on accounts
if the definition does not exist.
Yes, this is kind of an edge case that has existed for a while(https://github.com/coral-xyz/anchor/issues/1971).
Fixed by https://github.com/coral-xyz/anchor/pull/2824.