0

I have defined a map and in a entry point i try to verify if the value of a key exists or not. I am getting error : Missing item in map: 'param' is not in {} while evaluating self.data.links[params]. This error is from the sp.verify(self.data.links[link] == True) line. As the map doesn’t contains a key 'link' it is giving this error. Is there any way to call sp.verify(self.data.links[link] == True) even if there is no existing key.

class Test(sp.Contract):
    def __init__(self):
        self.update_initial_storage(
            links=sp.map(tkey=sp.TString, tvalue=sp.TBool))

    @sp.entry_point
    def remove(self, link):
        sp.verify(self.data.links[link] == True)
        del self.data.links[link]

1 Answer 1

0
  • No need to check if a key exists before deleting it.
  • To check if a map contains a key you have the .contains(key) instruction. Example: sp.verify(self.data.links.contains(link))

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.