我的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之后在我的代码中模式化语法和间距。是什么导致了这些错误?
你的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
关键字很难推理,所以除非绝对必要,否则最好避免使用。