-
Notifications
You must be signed in to change notification settings - Fork 85
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
struct as mapping key #49
Conversation
mod StructAsMappingKey { | ||
use starknet::get_caller_address; | ||
use starknet::ContractAddress; | ||
use poseidon::poseidon_hash_span; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the correct function that I should use? @enitrat
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
|
||
#[external] | ||
fn set(key: User, value: felt252) { | ||
_map::write(poseidon_hash_span(key.span()), value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does not work as it expects a span, but span is only for arrays and key is not an array (it's a struct), so I guess we have to use another function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
your struct needs to derive Serde
and then you can call Serde::<User>::serialize(key,serialized_struct)
to make it an array (check corelib to see the correct syntax to use Serde
Awesome! It works when deriving the
This would be the perfect recipe for an easy-to-understand and meaningful example! |
4ccf1a5
to
3ac2965
Compare
3ac2965
to
64aa1fa
Compare
No description provided.