shank icon indicating copy to clipboard operation
shank copied to clipboard

shank/solita doesn't handle zero sized structs

Open billythedummy opened this issue 2 years ago • 1 comments

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 avatar Dec 07 '22 09:12 billythedummy

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)

billythedummy avatar Dec 07 '22 09:12 billythedummy