Tickets โ
Tickets of content type t
have type sp.TTicket(t
).
The corresponding type in Michelson is
See reference Tickets template
Create a ticket โ
sp.ticket(content, amount)
Create a ticket with content
and amount
. If content
is of type t
, the return type is sp.TTicket(t
). The amount
has to be of type sp.TNat.
Example โ
ticket = sp.ticket("Can be a string", sp.nat(1))
High Level Functions โ
Read ticket โ
sp.read_ticket(ticket)
Read the data of a ticket
and return a Python object with four fields ticketer
, content
, amount
, and copy
.
Example โ
read_ticket = sp.read_ticket(ticket)
The output read_ticket
object is not a SmartPy expression and cannot be passed as an expression to regular SmartPy functions. However, it can be passed to regular Python functions thanks to meta-programming.
WARNING
It is an error to access ticket
again after this command, and read_ticket.copy
must be used instead.
If ticket
is of type sp.TTicket(t
), then read_ticket.ticketer
is of type sp.TAddress, read_ticket.content
of type t
, and read_ticket.amount
of type sp.TNat.
Split ticket โ
sp.split_ticket(ticket, q1, q2)
Split ticket
into two tickets of amounts q1
and q2
. These two amounts must sum up to ticket
's value, otherwise sp.none
is returned.
Example โ
sp.split_ticket(ticket, q1, q2)
If ticket
is of type sp.TTicket(t
), this returns a value of type sp.TOption(sp.TPair(sp.TTicket(t
), sp.TTicket(t
))).
Join tickets โ
sp.join_tickets(ticket1, ticket2)
Return a new ticket with the sum of the amounts in ticket1
and ticket2
. The two tickets must have the same contents, or an error is raised.
Example โ
sp.join_tickets(ticket1, ticket2)
Both tickets must have the same type sp.TTicket(t
), which is also the return type.
Low Level Functions โ
Read ticket โ
sp.read_ticket_raw(ticket)
Like sp.read_ticket(ticket)
when the output is two elements.
Example โ
sp.read_ticket_raw(ticket)
Split ticket โ
sp.split_ticket_raw(ticket, q1, q2)
Like sp.split_ticket(ticket, q1, q2)
when the output is two elements.
Example โ
sp.split_ticket_raw(ticket, q1, q2)
Join tickets โ
sp.join_tickets_raw(tickets)
Like sp.join_tickets(ticket1, ticket2)
where tickets
is a pair of tickets.
Example โ
sp.join_tickets_raw(tickets)
Testing Tickets โ
sp.test_ticket(ticketer, content, amount)
Create a new ticket issued by the locally defined contract ticketer
. This is meant to be used for testing purposes in scenarios.
Example โ
ticket = sp.test_ticket(ticketer, content, amount)