Open DianaLease opened 4 years ago
Good issue! But I think the description is a bit misleading. At the moment every clause is stateful, in the sense that there is no way to know if the state will or will not be changed except by looking at the logic for that clause (i.e., does it use set state
or not).
It would be nice if the contract type or clause type was able to make that distinction.
This is a bit similar to the issue opened by @mttrbrts on emitted obligations here: https://github.com/accordproject/ergo/issues/714
For the sake of argument, here is a contract which is stateful and for which getStateTypes()
returns org.accordproject.cicero.contract.AccordContractState
namespace org.accordproject.helloworld
import org.accordproject.cicero.contract.AccordContractState
contract HelloWorld over HelloWorldClause {
// Simple Clause
clause helloworld(request : MyRequest) : MyResponse {
set state AccordContractState{ stateId : "FOOBAR" };
return MyResponse{ output: "Hello " ++ contract.name ++ " " ++ request.input }
}
}
With the corresponding execution:
bash-3.2$ cicero trigger
15:06:15 - info: Using current directory as template folder
15:06:15 - info: Loading a default text/sample.md file.
15:06:15 - info: Loading a default request.json file.
15:06:16 - warn: A state file was not provided, initializing state. Try the --state flag or create a state.json in the root folder of your template.
15:06:16 - info:
{
"clause": "helloworld@0.12.0-c0d3909d5b62ea58596f0e38e0f4362eca2b42be88585ce0d4cd5a6c6b9c1b15",
"request": {
"$class": "org.accordproject.helloworld.MyRequest",
"input": "Accord Project"
},
"response": {
"$class": "org.accordproject.helloworld.MyResponse",
"output": "Hello Fred Blogs Accord Project",
"transactionId": "5e2fdfce-c31c-4836-9ca7-22b7218f890f",
"timestamp": "2019-11-27T20:06:16.684Z"
},
"state": {
"$class": "org.accordproject.cicero.contract.AccordContractState",
"stateId": "FOOBAR"
},
"emit": []
}
Describe the bug
getStateTypes()
returnsorg.accordproject.cicero.contract.AccordContractState
for clause templates that do not utilize stateExpected behavior The distinction between stateful and stateless clauses should be more clear.