The following question has been asked on Telegram:
If I want to have a ticket that is being created in the contract, to be stored in storage, what should my storage init look like? especially if it is supposed to be empty at deployment? Do I need / can I define the types and how to define an empty storage of certain type?
The options system lets you represent things that can be
None (empty) or
For example if you want to initialize an empty ticket of type
sp.ticket[sp.nat] you can write:
self.data.my_ticket = sp.cast(None, sp.option[sp.ticket[sp.nat]])
You can then set the value like this:
def receive_ticket(self, my_ticket):
self.data.my_ticket = sp.Some(my_ticket)
And unwrap it to get the value like that:
def withdraw(self, receiver):
# Unwrap the ticket and fetch its value
my_ticket = self.data.my_ticket.unwrap_some(error="NoTicket")
What is the best way/practice to store multiple different tickets (lets imagine sort of wallet contract that stores different tickets) - should it be a map, or a record etc? Anything note worthy that should be considered here (besides that you cannot make a copy) when handling tickets?
I generalized your question here: How do I decide between using map, big_map, and record?.
There is no difference to this answer when we want to store tickets.