anchorpy
anchorpy copied to clipboard
Client-gen (python) fails when there are types with same `name`
Below error occurs when running anchorpy client-gen on an IDL where there are types with the same name due to this constraint. Quick fix solution was to manually make each type name unique, but would be great to handle this dynamically later.
generating package...
generating program_id.py...
generating errors.py...
generating instructions...
generating types...
Traceback (most recent call last):
File "/opt/homebrew/bin/anchorpy", line 8, in <module>
sys.exit(app())
File "/opt/homebrew/lib/python3.9/site-packages/typer/main.py", line 214, in __call__
return get_command(self)(*args, **kwargs)
File "/opt/homebrew/lib/python3.9/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
File "/opt/homebrew/lib/python3.9/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
File "/opt/homebrew/lib/python3.9/site-packages/click/core.py", line 1657, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/homebrew/lib/python3.9/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/homebrew/lib/python3.9/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
File "/opt/homebrew/lib/python3.9/site-packages/typer/main.py", line 500, in wrapper
return callback(**use_params) # type: ignore
File "/opt/homebrew/lib/python3.9/site-packages/anchorpy/cli.py", line 138, in client_gen
gen_types(idl_obj, out)
File "/opt/homebrew/lib/python3.9/site-packages/anchorpy/clientgen/types.py", line 65, in gen_types
gen_type_files(idl, types_dir)
File "/opt/homebrew/lib/python3.9/site-packages/anchorpy/clientgen/types.py", line 101, in gen_type_files
types_code = gen_types_code(idl, types_dir)
File "/opt/homebrew/lib/python3.9/site-packages/anchorpy/clientgen/types.py", line 123, in gen_types_code
else gen_enum(idl, ty.name, ty_type.variants)
File "/opt/homebrew/lib/python3.9/site-packages/anchorpy/clientgen/types.py", line 467, in gen_enum
rec_unnamed = _make_unnamed_field_record(
File "/opt/homebrew/lib/python3.9/site-packages/anchorpy/clientgen/types.py", line 315, in _make_unnamed_field_record
encodable = _field_to_encodable(
File "/opt/homebrew/lib/python3.9/site-packages/anchorpy/clientgen/common.py", line 231, in _field_to_encodable
raise ValueError(f"Type not found {defined}")
ValueError: Type not found Swap
@enzoampil how should types with the same name be handled? Perhaps I am misunderstanding but I don't see what we can do with duplicate types
@enzoampil just checking in here
@kevinheavey slr - well what I manually did was I just added indices to the subsequent ones. This way the script works, but just need to keep note of the new type names.
There are probably better ways to account for this though - was just a quick implementation to get the script to work on my side.
It may be an edge case but the fact it happens with the jupiter IDL makes me think it's something to address.
@enzoampil can you share the IDL? I'm still not sure how an IDL with duplicate types makes sense
@kevinheavey I am having the same issue. Here is a link to the IDL:
https://solscan.io/account/JUP2jxvXaqu7NQY1GmNF4m1vodw12LVXYxbFL2uJvfo#anchorProgramIDL
Closing this as an IDL with duplicate types is simply invalid. This is an issue with Anchor and/or Jupiter