Open naveed949 opened 3 years ago
HashMaps aren't currently supported in the IDL.
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.
You can approximate a map by using program-derived addresses PDAs. Seeds are your keys, values are your accounts.
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
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)
[account]
pub struct Boxes {
pub authority: Pubkey, pub boxes: HashMap<u32, NftBox>, } `
Note: I've also tried
BTreeMap
instead ofHashMap
but getting same issue. Please help me