场景执行失败
Scenario execution fails
伙计们,这段代码抛出了一个错误
daml 1.2
module PaidService where
template Service
with
provider : Party
beneficiary : Party
description : Text
cost : Decimal
currency : Text
where
signatory provider,beneficiary
controller beneficiary can
Transer : ContractId Service
with nextbeneficiary : Party
do
create this with beneficiary = nextbeneficiary
test_1 = scenario do
beth <- getParty "beth"
manish <- getParty "manish"
harsha <- getParty "harsha"
cid <- manish submit do
create Service
with
provider = manish
beneficiary = manish
description = "Yay"
cost = 1000.00
currency = "USD"
{
"resource": "/home/Daml/learning/hackathon/daml/PaidService.daml",
"owner": "_generated_diagnostic_collection_name_#0",
"severity": 8,
"message": "/home//Daml/learning/hackathon/daml/PaidService.daml:27:3: 错误:\n 'do' 块中的最后一条语句必须是 expression\n cid <- manish\n submit\n do create\n Service\n {provider = manish, beneficiary = manish, description = \"Yay\",\n cost = 1000.00, currency = \"USD\"}",
"source": "typecheck",
"startLineNumber": 27,
"startColumn": 3,
"endLineNumber": 34,
"endColumn": 25
}
为什么会这样?
do
块中的最后一行不能是 a <- action
的形式。相反,在您的示例中,它必须是 f a
和 f = Scenario
类型的表达式。整个 do
块也将是 Scenario a
类型。有两种方法可以修复您的示例。
- 在末尾添加另一行
pure ()
。 pure
允许您将任意值 a
嵌入到 do
块的上下文中(从技术上讲,它不限于 do
块,但我不会深入探讨在这里)所以在这里它允许你将 ()
嵌入到 Scenario
上下文中,给你一个 Scenario ()
. 类型的值
- 改变
cid <- manish `submit` …
进入
manish `submit` …
在您的示例中,do
-块的类型为 Scenario (ContractId Service)
。
1 和 2 的主要区别在于,1 test_1
的类型为 Scenario ()
,而 2 test_1
的类型为 Scenario (ContractId Service)
。对于您的示例,这种差异并不重要,因为您没有在任何地方引用 test_1
,因此两种解决方案都是合理的。
伙计们,这段代码抛出了一个错误
daml 1.2
module PaidService where
template Service
with
provider : Party
beneficiary : Party
description : Text
cost : Decimal
currency : Text
where
signatory provider,beneficiary
controller beneficiary can
Transer : ContractId Service
with nextbeneficiary : Party
do
create this with beneficiary = nextbeneficiary
test_1 = scenario do
beth <- getParty "beth"
manish <- getParty "manish"
harsha <- getParty "harsha"
cid <- manish submit do
create Service
with
provider = manish
beneficiary = manish
description = "Yay"
cost = 1000.00
currency = "USD"
{ "resource": "/home/Daml/learning/hackathon/daml/PaidService.daml", "owner": "_generated_diagnostic_collection_name_#0", "severity": 8, "message": "/home//Daml/learning/hackathon/daml/PaidService.daml:27:3: 错误:\n 'do' 块中的最后一条语句必须是 expression\n cid <- manish\n submit\n do create\n Service\n {provider = manish, beneficiary = manish, description = \"Yay\",\n cost = 1000.00, currency = \"USD\"}", "source": "typecheck", "startLineNumber": 27, "startColumn": 3, "endLineNumber": 34, "endColumn": 25 }
为什么会这样?
do
块中的最后一行不能是 a <- action
的形式。相反,在您的示例中,它必须是 f a
和 f = Scenario
类型的表达式。整个 do
块也将是 Scenario a
类型。有两种方法可以修复您的示例。
- 在末尾添加另一行
pure ()
。pure
允许您将任意值a
嵌入到do
块的上下文中(从技术上讲,它不限于do
块,但我不会深入探讨在这里)所以在这里它允许你将()
嵌入到Scenario
上下文中,给你一个Scenario ()
. 类型的值
- 改变
cid <- manish `submit` …
进入
manish `submit` …
在您的示例中,do
-块的类型为 Scenario (ContractId Service)
。
1 和 2 的主要区别在于,1 test_1
的类型为 Scenario ()
,而 2 test_1
的类型为 Scenario (ContractId Service)
。对于您的示例,这种差异并不重要,因为您没有在任何地方引用 test_1
,因此两种解决方案都是合理的。