如何重置 Rust 智能合约中的变量?

How to reset a variable in rust smart contract?

我有一个 lookupMap

pub struct App {
   update_user_ids: LookupMap<u128, u128>,
}

我想重置 update_user_ids,我应该怎么做?

如果我给 key_prefix id "f657bf68" 与在 #[init] pub fn new().

pub fn reset (&mut self) {
        self.update_user_ids = LookupMap::new(b"f657bf68".to_vec());
    }

好吧,根据设计,LookupMap does not have a way to delete all its entries since it does not know the keys. You can only insert and delete entries by known keys. If you know the keys, you can call self.update_user_ids.remove() in a loop. If your intention is to start from scratch, I recommend you recreate an account to wipe the state completely; otherwise, use UnorderedMap or TreeMapclear() 实现。