This is my data model:
pub struct RaffleDetails {
prize: Balance,
start: Timestamp,
end: Timestamp,
participants: UnorderedMap<AccountId, Balance>,
}
pub struct RaffleDapp {
raffles: UnorderedMap<AccountId, RaffleDetails>,
}
How can I insert a key-value pair in the 'participants' variable?
I tried self.raffles.get(&raffle_account_id).unwrap().participants.insert(&env::predecessor_account_id(), &confidence); but it's not persistent.
References: UnorderedMap NEAR Rust SDK
You need to make sure you are updating the
RaffleDetailsinstance that is in the map, not a copy/clone of it.I'm not familiar with
UnorderedMap, but it seems to me theget()method returns a copy of the value that is in the map, so you are only updating the copied value. I don't know ifUnorderedMapallows you to mutate a value in it directly (skimming through the docs, I don't see such a method). What you can do though is re-insert the modifiedRaffleDetailsinto therafflesmap (so as to replace the old one with the modified one).I'm talking about something like this (I haven't tested compiling it):