Tickets
The following functions are available under the Tezos.
namespace.
let Tezos.create_ticket: 'value => nat => option<ticket<'value>>
To create a ticket, the value and the amount of tickets to be created needs to be provided.
The ticket will also contain the contract address it originated from (which corresponds to Tezos.self
).
The resulting value is None
if the amount is zero.
let Tezos.read_ticket: ticket<'value> => <<address, <'value , nat>> , ticket<'value>>
Reading a ticket will return a tuple with the ticket address, the value and the same ticket for later use.
A ticket is only consumed when it is dropped (e.g. DROP
-ed from the Michelson stack) so if the returned ticket isn't stored in some form by your contract, it will be fully consumed.
To read the content of a ticket, you need to use tuple destructuring:
let Tezos.split_ticket: ticket<'value> => <nat , nat> => option <<ticket<'value>, ticket<'value>>>
To partially use/consume a ticket, you have to split it. Provided a ticket and two amounts, two new tickets will be returned to you if, and only if, the sum equals to the amount of the original ticket.
let Tezos.join_tickets = <ticket<'value>, ticket<'value>> => option <ticket<'value>>
To add two tickets, you have to join them. This works as the inverse
of Tezos.split_ticket
. Provided two tickets with the same ticketer
and content, they are deleted and a new ticket will be returned with
an amount equal to the sum of the amounts of the input tickets.