gagliardetto / anchor-go

Generate Go clients from anchor IDLs for Solana blockchain programs
MIT License
138 stars 31 forks source link

IDLs with 'account' suffixes cause duplicate methods #1

Closed Willyham closed 2 years ago

Willyham commented 2 years ago

Assume an IDL with this structure:

{
  "version": "0.0.0",
  "name": "program",
  "instructions": [
      "name": "bar",
      "accounts": [
        {
          "name": "foo",
          "isMut": false,
          "isSigner": true
        },
        {
          "name": "fooAccount",
          "isMut": true,
          "isSigner": false
        }
      ]
  ]
}

As Account is stripped from the latter name, duplicate GetFoo and SetFoo receiver methods are created. I'm running into this in the real world with an existing project.

Happy to contribute a fix but not sure what the solution should be. Possibilities:

gagliardetto commented 2 years ago

That's a tricky issue.

Let's see what happens in each case:

Don't strip Account entirely

Drop strip if conflict exists.

That's reasonable.

Add extra suffix if conflict exists

I feel this is the same as the first scenario, with a different suffix.

Error out and don't generate code

This also would make sense.


How about this:

Willyham commented 2 years ago

Yep, that sounds like a good solution.

gagliardetto commented 2 years ago

Release v0.2.2