Hi Team,
In the following choice, Can you explain this in term of DAML, As we already have Ticket contract than why we have “create ticket” here? And how it will execute in this choice?
It’s important to note that Ticket is not being created (or written into the ledger at this moment, it is simply being used as a record type)
We know that in order for the contract Ticket to be created, we need the airline party and the passenger party.
What is happening is that FlightInvite is being created by the airline (as the signatory is only ticket.ariline)
The observer here is ticket.passenger, meaning this FlightInvite is visible to the passenger.
With the FlightInvite contract created, we have the signature of the airline.
When the passenger sees this contract, and exercises Accept_Invite, the signature is passed down to AddPassengers, which a new flight contract is created with the additional passenger,
When the FlightInvite contract is created, it is created with a field called ticket of type Ticket. That type is the record type that corresponds to the Ticket template. As I explained in my previous message, this record may or may not correspond to an actual Ticket contract on the ledger.
In other words, you can create a TicketInvite with any random data as the ticket field (provided it has the right “shape”).
The Accept_Invite choice is then going to validate that ticket data against data that is actually on the ledger (namely the data fetched from the ledger based on a Contract ID for a given flight), and, if this all checks out, the line
ticketCid <- create ticket
actually creates a Ticket contract on the ledger with the data that was in ticket.
Values in Daml are immutable. The value of ticket is set by the party that created the FlightInvite and never changes after that.
If you just said create, how would Daml know what to do? What template to use, which values to fill it with? create needs an argument in order to create an entry on the ledger; entries on the ledger have to be contracts, and create needs to know what type of contract and with what data.