Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: User defined types not provided #785

Open
naveed949 opened this issue Sep 23, 2021 · 4 comments
Open

Error: User defined types not provided #785

naveed949 opened this issue Sep 23, 2021 · 4 comments
Labels
question Further information is requested

Comments

@naveed949
Copy link

while testing program, getting following error.
CMD: anchor test
ErrorLog:

0 passing (10s)
1 failing

  1. blindbox
    Is initialized!:
    Error: User defined types not provided
    at Function.fieldLayout (node_modules/@project-serum/anchor/dist/cjs/coder/idl.js:96:31)
    at typeDef.type.fields.map (node_modules/@project-serum/anchor/dist/cjs/coder/idl.js:126:36)
    at Array.map ()
    at Function.typeDefLayout (node_modules/@project-serum/anchor/dist/cjs/coder/idl.js:125:54)
    at AccountsCoder.idl.accounts.map (node_modules/@project-serum/anchor/dist/cjs/coder/accounts.js:20:46)
    at Array.map ()
    at new AccountsCoder (node_modules/@project-serum/anchor/dist/cjs/coder/accounts.js:19:38)
    at new Coder (node_modules/@project-serum/anchor/dist/cjs/coder/index.js:32:25)
    at new Program (node_modules/@project-serum/anchor/dist/cjs/program/index.js:54:23)
    at fs.readdirSync.forEach (node_modules/@project-serum/anchor/dist/cjs/workspace.js:71:44)
    at Array.forEach ()
    at Object.get (node_modules/@project-serum/anchor/dist/cjs/workspace.js:64:39)
    at Context.it (tests/blindbox.js:16:38)
    at processImmediate (internal/timers.js:443:21)

    After debugging I've found following struct is causing issue.
    IDL json formatt:
    { "name": "Boxes", "type": { "kind": "struct", "fields": [ { "name": "authority", "type": "publicKey" }, { "name": "boxes", "type": { "defined": "HashMap<u32,NftBox>" } } ] } }

Program version of same struct:
`

#[account]
pub struct Boxes {

pub authority: Pubkey,
pub boxes: HashMap<u32, NftBox>,
} `

Note: I've also tried BTreeMap instead of HashMap but getting same issue.
Please help me

@armaniferrante
Copy link
Member

HashMaps aren't currently supported in the IDL.

@naveed949
Copy link
Author

okay @armaniferrante can you please tell what collections are implemented from std::collections as I need to store key-value data in my program ?
or please suggest me any for this purpose.

@armaniferrante
Copy link
Member

You can approximate a map by using program-derived addresses PDAs. Seeds are your keys, values are your accounts.

@naveed949
Copy link
Author

naveed949 commented Sep 23, 2021

Trying to understand @armaniferrante
For example:
I want to store n number of Boxes in my account where each Box is a kind of NFT and identified by its ID.
so how will an PDA will store these all n number of Boxes.
OR
are you saying I'll need n number of PDAs to store 1 Box per PDA.
As for now what I can understand one PDA/account can store only one Box, due to the unavailability of map.

please correct me if missing anything

@paul-schaaf paul-schaaf added the question Further information is requested label Jan 10, 2022
@acheroncrypto acheroncrypto mentioned this issue Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants