anchor icon indicating copy to clipboard operation
anchor copied to clipboard

Anchor 0.28.0 IDL Events Do Not Correctly Refer to Account Types

Open sol-mocha opened this issue 1 year ago • 1 comments

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.

sol-mocha avatar Sep 10 '23 19:09 sol-mocha

Yes, this is kind of an edge case that has existed for a while(https://github.com/coral-xyz/anchor/issues/1971).

acheroncrypto avatar Sep 10 '23 19:09 acheroncrypto

Fixed by https://github.com/coral-xyz/anchor/pull/2824.

acheroncrypto avatar Mar 10 '24 18:03 acheroncrypto