metaplex-foundation / shank

Extracts IDL from Solana Rust contracts
https://docs.rs/crate/shank_macro/latest
116 stars 23 forks source link

shank/solita doesn't handle zero sized structs #47

Open billythedummy opened 1 year ago

billythedummy commented 1 year ago

With:

#[derive(BorshDeserialize)]
struct MyEmptyStruct {}

shank runs fine, but the resulting idl contains

  {
    "name": "MyEmptyStruct",
    "type": {
      "kind": "struct",
      "fields": []
    }
  }

causing solita to crash with

AssertionError [ERR_ASSERTION]: Rendering struct for MyEmptyStruct should have at least 1 field

On the other hand, with:

#[derive(BorshDeserialize)]
struct MyEmptyStruct;

shank crashes with

failed to parse fields make sure they are all named

Which is fine if shank/solita doesn't intend to support zero-sized structs but it attempts to do every single struct that impl BorshSerialize even if its not pub or part of the solana program instruction interface.

billythedummy commented 1 year ago

but it attempts to do every single struct that impl BorshSerialize

nevermind i lied, it only does it for structs where BorshSerialize is auto-derived (#[derive(BorshSerialize)]). My current workaround is to implement BorshSerialize manually for the zero-sized struct (which is just a no-op anw)