我的Main.daml代码如下:
daml 1.2
module Main where
type CarId = ContractId Car -- for return type on controller actions
template Car
with
dealer : Party
insurer : Party
vin: Text
date_vehicle_added: Date
daily_insurance_rate: Decimal
daily_rate_APD: Decimal
covered: Bool --initialize to false and set to true when added
observers : [Party]
where
signatory dealer
agreement
toText dealer <> " agrees to pay " <> toText insurer <> " at daily rate of "
controller dealer can
Add_Car : CarId
with
startCoverage: Date
do
-- Return this car with the start date provided by the dealer
create this with date_vehicle_added = startCoverage, covered = True
Remove_Car
do
archive this
setup = scenario do
dealer1 <- getParty "Clevland_Heights"
insurance1 <- getParty "Ins"
car1AddCid <- submit dealer1 do
carCid <- create Car with
dealer = dealer1
insurer = insurance1
vin = "1A"
daily_insurance_rate = 1.5
daily_rate_APD = 0.16
covered = False
observers = [insurance1]
date_vehicle_added = "date 1970 Jan 1" -- must be initialized
exercise carCid Add_Car with startCoverage = "date 2019 Apr 5"
submit dealer1 do
exercise car1AddCid Remove_Car
我在“问题”窗口中看到两个错误”
1. error: parse error on input 'do' (43,9).
这是“ Remove_Car”选项之后的行。
2. error: Data contructor not in scope:Remove_Car
这是程序的最后一行。
我试图在快速入门应用程序的Main.daml和Ion.daml之后设置代码中的语法和间距。是什么导致这些错误?
答案 0 :(得分:4)
您的Remove_Car
选择有两个问题。
Unit
,写为()
:Return_Car : ()
。this
不是合约,而是行使选择权的合约的主体。由于它不是合同,因此无法存档。实际上,还有另一个关键字self
,它确实指向当前合同,但是使用该关键字也不起作用。您将在一个可供选择的选择中归档合同,从而两次使用该合同-这种双重花费的DAML不再发生。要修复2.,您有三个选择:
Archive
选择,并由所有签署者授权。由于您选择的Remove_Car
的控制者与合同的签署人相同,因此它仅复制了Archive
。Remove_Car : ()
do return ()
nonconsuming
选项和self
关键字:
nonconsuming Remove_Car : ()
do archive self
通常,我会尽可能选择选项1,如果需要给签署人的子集提供一种归档合同的方式,则选择选项2。使用self
关键字很难说清楚,因此除非绝对必要,否则最好避免使用它。