anchor icon indicating copy to clipboard operation
anchor copied to clipboard

Hashmaps arent supported in anchor idl

Open anoushk1234 opened this issue 2 years ago • 10 comments

getting this error in logs when running anchor deployELF error: Found writable section (.bss._ZN3std11collections4hash3map11RandomState3new4KEYS7__getit5__KEY17h9d3c0f65754b98d3E) in ELF, read-write data not supported code

credit to @abishekk92 for pointing this out

anoushk1234 avatar Jan 08 '22 13:01 anoushk1234

solana has no support for the hashmap type, so anchor doesn't either

It has a hash function though so maybe we could roll our own hashmap. @armaniferrante wdyt?

paul-schaaf avatar Jan 08 '22 23:01 paul-schaaf

Having a mapping function would be super useful, right now we have to use custom structs and arrays for everything and arrays aren't really a safe replacement for maps

Highly request this @armaniferrante

anoushk1234 avatar Jan 09 '22 09:01 anoushk1234

Second on this, hashmaps seem to be quite useful

daweth avatar Apr 01 '22 16:04 daweth

solana has no support for the hashmap type, so anchor doesn't either

It has a hash function though so maybe we could roll our own hashmap. @armaniferrante wdyt?

https://docs.solana.com/implemented-proposals/persistent-account-storage

I think, Solana has support HashMap

xuanlongvts avatar Apr 23 '22 16:04 xuanlongvts

solana has no support for the hashmap type, so anchor doesn't either It has a hash function though so maybe we could roll our own hashmap. @armaniferrante wdyt?

https://docs.solana.com/implemented-proposals/persistent-account-storage

I think, Solana has support HashMap

i think the anchor team prefers using PDAs as hashmaps as Paul mentioned in the anchor book so traditional hashmaps might never be implemented

anoushk1234 avatar Apr 25 '22 06:04 anoushk1234

@anoushk1234 what about size bounded BTreeMap? @armaniferrante ???

yourarj avatar May 04 '22 04:05 yourarj

solana has no support for the hashmap type, so anchor doesn't either It has a hash function though so maybe we could roll our own hashmap. @armaniferrante wdyt?

https://docs.solana.com/implemented-proposals/persistent-account-storage I think, Solana has support HashMap

i think the anchor team prefers using PDAs as hashmaps as Paul mentioned in the anchor book so traditional hashmaps might never be implemented

PDA's also come with the additional cost associated with creating and rent-exempting accounts on-demand. If you know your HashMap won't exceed a certain size, serializing and deserializing it in one account makes a lot of sense.

If Anchor could:

  • Use normal borsh serialize / deserialize for HashMap data types
  • give the user the ability to assign whatever type they want on the client side (perhaps by typing the property that is a HashMap with unknown)

Then I'm sure developers could figure out the rest

ndrewtl avatar Jun 29 '22 22:06 ndrewtl

solana has no support for the hashmap type, so anchor doesn't either It has a hash function though so maybe we could roll our own hashmap. @armaniferrante wdyt?

https://docs.solana.com/implemented-proposals/persistent-account-storage I think, Solana has support HashMap

i think the anchor team prefers using PDAs as hashmaps as Paul mentioned in the anchor book so traditional hashmaps might never be implemented

PDA's also come with the additional cost associated with creating and rent-exempting accounts on-demand. If you know your HashMap won't exceed a certain size, serializing and deserializing it in one account makes a lot of sense.

If Anchor could:

* Use normal borsh serialize / deserialize for HashMap data types

* give the user the ability to assign whatever type they want on the client side (perhaps by typing the property that is a HashMap with `unknown`)

Then I'm sure developers could figure out the rest

It's a good idea, wdyt @paul-schaaf ?

anoushk1234 avatar Jun 30 '22 04:06 anoushk1234

Solana has support BtreeMap, but anchor has not support

IdlError: Type not found: {"name":"participants","type":{"defined":"BTreeMap<Pubkey,u64>"}}

and anchor has not support tuple type

IdlError: Type not found: {"type":{"defined":"(Pubkey,u64)"}}

icodezjb avatar Jul 25 '22 10:07 icodezjb

I meet the same problem, but the differentence is i defined an struct,but it also can not work. IdlError: Type not found: {"type":{"defined":"Tick"}}

ccbond avatar Aug 10 '22 04:08 ccbond

I meet the same problem, but the differentence is i defined an struct,but it also can not work.

IdlError: Type not found: {"type":{"defined":"Tick"}}

You have to use Anchor serialise and deserialise macros

anoushk1234 avatar Nov 08 '22 14:11 anoushk1234

You have to use Anchor serialise and deserialise macros

@anoushk1234 hey where do i have to use them?

#[account]
#[derive(AnchorSerialise, AnchorDeserialise)]
pub struct List {
    pub list: Vec<TodoItem>,
}

Here?

raghav-rama avatar Feb 05 '23 18:02 raghav-rama