metaplex-foundation / solita

Genrates an SDK API from solana contract IDL.
Apache License 2.0
142 stars 33 forks source link

feat: fix anchor maps via transform #76

Closed thlorenz closed 2 years ago

thlorenz commented 2 years ago

Anchor does not support map types like HashMap and thus treats them as user defined types basically just copy/pasting the type from the Rust code, i.e. HashMap<String,DataItem>.

This PR adds a transformer function that runs before types are processed. This transformer tries to detect these cases and converts them to proper map type definitions. This won't work for 100% of the cases and thus is a stop gap for the cases we encounter for our anchor programs. Additionaly at this point it only transforms fields for structs, i.e. if such an invalid map definition is nested somehow, it will go undetected. These limitations can be improved on with each new case we need to handle.

FIXES: #75