I copied the code of Lab1, and Main under a project but got an error. Same thing happened when using the code in “Navigator” course.
How to deal with this?
Code in Lab1.daml
module Lab1 where
import DA.Optional
import DA.Date (toDateUTC)
template CLPApplication
with
customer: Party
airline: Party
id: Text --this is external id that is unique for a customer, e.g. driving-license no., SSN, etc.
name: Text
address: Text
email: Text
phone: Optional Text
timestamp: Time
dob: Date
where
signatory customer
observer airline
choice SubmitApplication: ContractId CLPApplication
with
appCustomer: Party
appAirline: Party
customerId: Text
customerName: Text
customerAddress: Text
customerEmail: Text
customerPhone: Text
appTimeStamp: Time
customerDob: Date
controller customer
do
create CLPApplication
with
customer = appCustomer
airline = appAirline
id = customerId
name = customerName
address = customerAddress
email = customerEmail
phone = Some customerPhone
timestamp = appTimeStamp
dob = customerDob
choice ReviewApplication: Optional (ContractId CLPAccount)
controller airline
do
account <- lookupByKey @CLPAccount (airline, id)
now <- getTime
if (isSome account) then
return None
else do
account <- create CLPAccount with
timestamp = now
points = 0
..
return (Some account)
template CLPAccount
with
customer: Party
airline: Party
id: Text
name: Text
address: Text
email: Text
phone: Optional Text
timestamp: Time
dob: Date
points: Int
where
signatory customer, airline
key (airline, id): (Party, Text)
maintainer key._1
choice AddPoints : ContractId CLPAccount
with
newPoints: Int
controller airline
do
create CLPAccount with
points = points + newPoints
..
template AirlineService
with
customer: Party
airline: Party
where
signatory airline
observer customer
nonconsuming choice CreateBlankApplication: ContractId CLPApplication
controller customer
do
now <- getTime
create CLPApplication
with
customer
airline
id = ""
name = ""
address = ""
email = ""
phone = Some ""
timestamp = now
dob = toDateUTC now
Code in Main.daml
module Main where
import Daml.Script
import Lab1
-- Lab1 Problem 1
setup: Script ()
setup = script do
-- allocate parties with the given display name
airline <- allocatePartyWithHint "Epic Airlines" (PartyIdHint "EA")
customer <- allocatePartyWithHint "Customer" (PartyIdHint "Cust")
-- construct user-ids from text
airlineId <- validateUserId "Epic"
aliceId <- validateUserId "Alice"
-- create users with the given rights
createUser (User airlineId (Some airline)) [CanActAs airline]
createUser (User aliceId (Some customer)) [CanActAs customer]
submit airline do
createCmd AirlineService with
customer = customer
airline = airline
return ()
Error I got:
Script execution failed:
Unhandled exception: Daml.Script:InvalidUserId@1784e0500b69eb19eb1995f7ea11cb9ba0133f339dc0cf4da16a9e72e6c9e30f with
m =
“User ID “Epic” does not match regex “[a-z0-9@^$.!`-#+'~_|:]{1,128}””
Ledger time: 1970-01-01T00:00:00Z