Merge pull request #2798 from ethereum/statemutability

Rename statemutability to stateMutability in ABI/AST
This commit is contained in:
chriseth 2017-08-24 18:27:08 +02:00 committed by GitHub
commit 71294b2872
5 changed files with 35 additions and 35 deletions

View File

@ -2,7 +2,7 @@
Features: Features:
* Introduce ``pure`` functions. The pureness is not enforced yet, use with care. * Introduce ``pure`` functions. The pureness is not enforced yet, use with care.
* ABI JSON: Include new field ``statemutability`` with values ``pure``, ``view``, ``nonpayable`` and ``payable``. * ABI JSON: Include new field ``stateMutability`` with values ``pure``, ``view``, ``nonpayable`` and ``payable``.
* Analyzer: Experimental partial support for Z3 SMT checker. * Analyzer: Experimental partial support for Z3 SMT checker.
* Parser: Display previous visibility specifier in error if multiple are found. * Parser: Display previous visibility specifier in error if multiple are found.
* Parser: Introduce ``view`` keyword on functions (``constant`` remains an alias for ``view``). * Parser: Introduce ``view`` keyword on functions (``constant`` remains an alias for ``view``).

View File

@ -295,7 +295,7 @@ The JSON format for a contract's interface is given by an array of function and/
- `outputs`: an array of objects similar to `inputs`, can be omitted if function doesn't return anything; - `outputs`: an array of objects similar to `inputs`, can be omitted if function doesn't return anything;
- `constant`: `true` if function is :ref:`specified to not modify blockchain state <view-functions>`); - `constant`: `true` if function is :ref:`specified to not modify blockchain state <view-functions>`);
- `payable`: `true` if function accepts ether, defaults to `false`; - `payable`: `true` if function accepts ether, defaults to `false`;
- `statemutability`: a string with one of the following values: `pure` (:ref:`specified to not read blockchain state <pure-functions>`), `view` (same as `constant` above), `nonpayable` and `payable` (same as `payable` above). - `stateMutability`: a string with one of the following values: `pure` (:ref:`specified to not read blockchain state <pure-functions>`), `view` (same as `constant` above), `nonpayable` and `payable` (same as `payable` above).
`type` can be omitted, defaulting to `"function"`. `type` can be omitted, defaulting to `"function"`.

View File

@ -327,7 +327,7 @@ bool ASTJsonConverter::visit(FunctionDefinition const& _node)
// FIXME: remove with next breaking release // FIXME: remove with next breaking release
make_pair(m_legacy ? "constant" : "isDeclaredConst", _node.stateMutability() <= StateMutability::View), make_pair(m_legacy ? "constant" : "isDeclaredConst", _node.stateMutability() <= StateMutability::View),
make_pair("payable", _node.isPayable()), make_pair("payable", _node.isPayable()),
make_pair("statemutability", stateMutabilityToString(_node.stateMutability())), make_pair("stateMutability", stateMutabilityToString(_node.stateMutability())),
make_pair("visibility", Declaration::visibilityToString(_node.visibility())), make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
make_pair("parameters", toJson(_node.parameterList())), make_pair("parameters", toJson(_node.parameterList())),
make_pair("isConstructor", _node.isConstructor()), make_pair("isConstructor", _node.isConstructor()),
@ -416,7 +416,7 @@ bool ASTJsonConverter::visit(FunctionTypeName const& _node)
setJsonNode(_node, "FunctionTypeName", { setJsonNode(_node, "FunctionTypeName", {
make_pair("payable", _node.isPayable()), make_pair("payable", _node.isPayable()),
make_pair("visibility", Declaration::visibilityToString(_node.visibility())), make_pair("visibility", Declaration::visibilityToString(_node.visibility())),
make_pair("statemutability", stateMutabilityToString(_node.stateMutability())), make_pair("stateMutability", stateMutabilityToString(_node.stateMutability())),
// FIXME: remove with next breaking release // FIXME: remove with next breaking release
make_pair(m_legacy ? "constant" : "isDeclaredConst", _node.stateMutability() <= StateMutability::View), make_pair(m_legacy ? "constant" : "isDeclaredConst", _node.stateMutability() <= StateMutability::View),
make_pair("parameterTypes", toJson(*_node.parameterTypeList())), make_pair("parameterTypes", toJson(*_node.parameterTypeList())),

View File

@ -38,7 +38,7 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
// TODO: deprecate constant in a future release // TODO: deprecate constant in a future release
method["constant"] = it.second->stateMutability() == StateMutability::Pure || it.second->stateMutability() == StateMutability::View; method["constant"] = it.second->stateMutability() == StateMutability::Pure || it.second->stateMutability() == StateMutability::View;
method["payable"] = it.second->isPayable(); method["payable"] = it.second->isPayable();
method["statemutability"] = stateMutabilityToString(it.second->stateMutability()); method["stateMutability"] = stateMutabilityToString(it.second->stateMutability());
method["inputs"] = formatTypeList( method["inputs"] = formatTypeList(
externalFunctionType->parameterNames(), externalFunctionType->parameterNames(),
externalFunctionType->parameterTypes(), externalFunctionType->parameterTypes(),
@ -58,7 +58,7 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
auto externalFunction = FunctionType(*_contractDef.constructor(), false).interfaceFunctionType(); auto externalFunction = FunctionType(*_contractDef.constructor(), false).interfaceFunctionType();
solAssert(!!externalFunction, ""); solAssert(!!externalFunction, "");
method["payable"] = externalFunction->isPayable(); method["payable"] = externalFunction->isPayable();
method["statemutability"] = stateMutabilityToString(externalFunction->stateMutability()); method["stateMutability"] = stateMutabilityToString(externalFunction->stateMutability());
method["inputs"] = formatTypeList( method["inputs"] = formatTypeList(
externalFunction->parameterNames(), externalFunction->parameterNames(),
externalFunction->parameterTypes(), externalFunction->parameterTypes(),
@ -73,7 +73,7 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
Json::Value method; Json::Value method;
method["type"] = "fallback"; method["type"] = "fallback";
method["payable"] = externalFunctionType->isPayable(); method["payable"] = externalFunctionType->isPayable();
method["statemutability"] = stateMutabilityToString(externalFunctionType->stateMutability()); method["stateMutability"] = stateMutabilityToString(externalFunctionType->stateMutability());
abi.append(method); abi.append(method);
} }
for (auto const& it: _contractDef.interfaceEvents()) for (auto const& it: _contractDef.interfaceEvents())

View File

@ -76,7 +76,7 @@ BOOST_AUTO_TEST_CASE(basic_test)
"name": "f", "name": "f",
"constant": false, "constant": false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function", "type": "function",
"inputs": [ "inputs": [
{ {
@ -120,7 +120,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods)
"name": "f", "name": "f",
"constant": false, "constant": false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function", "type": "function",
"inputs": [ "inputs": [
{ {
@ -139,7 +139,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods)
"name": "g", "name": "g",
"constant": false, "constant": false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function", "type": "function",
"inputs": [ "inputs": [
{ {
@ -172,7 +172,7 @@ BOOST_AUTO_TEST_CASE(multiple_params)
"name": "f", "name": "f",
"constant": false, "constant": false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function", "type": "function",
"inputs": [ "inputs": [
{ {
@ -211,7 +211,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods_order)
"name": "c", "name": "c",
"constant": false, "constant": false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function", "type": "function",
"inputs": [ "inputs": [
{ {
@ -230,7 +230,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods_order)
"name": "f", "name": "f",
"constant": false, "constant": false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function", "type": "function",
"inputs": [ "inputs": [
{ {
@ -264,7 +264,7 @@ BOOST_AUTO_TEST_CASE(view_function)
"name": "foo", "name": "foo",
"constant": false, "constant": false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function", "type": "function",
"inputs": [ "inputs": [
{ {
@ -287,7 +287,7 @@ BOOST_AUTO_TEST_CASE(view_function)
"name": "boo", "name": "boo",
"constant": true, "constant": true,
"payable" : false, "payable" : false,
"statemutability": "view", "stateMutability": "view",
"type": "function", "type": "function",
"inputs": [{ "inputs": [{
"name": "a", "name": "a",
@ -320,7 +320,7 @@ BOOST_AUTO_TEST_CASE(constant_function)
"name": "foo", "name": "foo",
"constant": false, "constant": false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function", "type": "function",
"inputs": [ "inputs": [
{ {
@ -343,7 +343,7 @@ BOOST_AUTO_TEST_CASE(constant_function)
"name": "boo", "name": "boo",
"constant": true, "constant": true,
"payable" : false, "payable" : false,
"statemutability": "view", "stateMutability": "view",
"type": "function", "type": "function",
"inputs": [{ "inputs": [{
"name": "a", "name": "a",
@ -375,7 +375,7 @@ BOOST_AUTO_TEST_CASE(pure_function)
"name": "foo", "name": "foo",
"constant": false, "constant": false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function", "type": "function",
"inputs": [ "inputs": [
{ {
@ -398,7 +398,7 @@ BOOST_AUTO_TEST_CASE(pure_function)
"name": "boo", "name": "boo",
"constant": true, "constant": true,
"payable" : false, "payable" : false,
"statemutability": "pure", "stateMutability": "pure",
"type": "function", "type": "function",
"inputs": [{ "inputs": [{
"name": "a", "name": "a",
@ -430,7 +430,7 @@ BOOST_AUTO_TEST_CASE(events)
"name": "f", "name": "f",
"constant": false, "constant": false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function", "type": "function",
"inputs": [ "inputs": [
{ {
@ -512,7 +512,7 @@ BOOST_AUTO_TEST_CASE(inherited)
"name": "baseFunction", "name": "baseFunction",
"constant": false, "constant": false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function", "type": "function",
"inputs": "inputs":
[{ [{
@ -529,7 +529,7 @@ BOOST_AUTO_TEST_CASE(inherited)
"name": "derivedFunction", "name": "derivedFunction",
"constant": false, "constant": false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function", "type": "function",
"inputs": "inputs":
[{ [{
@ -585,7 +585,7 @@ BOOST_AUTO_TEST_CASE(empty_name_input_parameter_with_named_one)
"name": "f", "name": "f",
"constant": false, "constant": false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function", "type": "function",
"inputs": [ "inputs": [
{ {
@ -628,7 +628,7 @@ BOOST_AUTO_TEST_CASE(empty_name_return_parameter)
"name": "f", "name": "f",
"constant": false, "constant": false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "function", "type": "function",
"inputs": [ "inputs": [
{ {
@ -672,7 +672,7 @@ BOOST_AUTO_TEST_CASE(constructor_abi)
} }
], ],
"payable": false, "payable": false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "constructor" "type": "constructor"
} }
])"; ])";
@ -704,7 +704,7 @@ BOOST_AUTO_TEST_CASE(payable_constructor_abi)
} }
], ],
"payable": true, "payable": true,
"statemutability": "payable", "stateMutability": "payable",
"type": "constructor" "type": "constructor"
} }
])"; ])";
@ -730,7 +730,7 @@ BOOST_AUTO_TEST_CASE(return_param_in_abi)
{ {
"constant" : false, "constant" : false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"inputs" : [], "inputs" : [],
"name" : "ret", "name" : "ret",
"outputs" : [ "outputs" : [
@ -749,7 +749,7 @@ BOOST_AUTO_TEST_CASE(return_param_in_abi)
} }
], ],
"payable": false, "payable": false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type": "constructor" "type": "constructor"
} }
] ]
@ -771,7 +771,7 @@ BOOST_AUTO_TEST_CASE(strings_and_arrays)
{ {
"constant" : false, "constant" : false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"name": "f", "name": "f",
"inputs": [ "inputs": [
{ "name": "a", "type": "string" }, { "name": "a", "type": "string" },
@ -800,7 +800,7 @@ BOOST_AUTO_TEST_CASE(library_function)
{ {
"constant" : false, "constant" : false,
"payable" : false, "payable" : false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"name": "f", "name": "f",
"inputs": [ "inputs": [
{ "name": "b", "type": "test.StructType storage" }, { "name": "b", "type": "test.StructType storage" },
@ -830,7 +830,7 @@ BOOST_AUTO_TEST_CASE(include_fallback_function)
[ [
{ {
"payable": false, "payable": false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"type" : "fallback" "type" : "fallback"
} }
] ]
@ -852,7 +852,7 @@ BOOST_AUTO_TEST_CASE(payable_function)
{ {
"constant" : false, "constant" : false,
"payable": false, "payable": false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"inputs": [], "inputs": [],
"name": "f", "name": "f",
"outputs": [], "outputs": [],
@ -861,7 +861,7 @@ BOOST_AUTO_TEST_CASE(payable_function)
{ {
"constant" : false, "constant" : false,
"payable": true, "payable": true,
"statemutability": "payable", "stateMutability": "payable",
"inputs": [], "inputs": [],
"name": "g", "name": "g",
"outputs": [], "outputs": [],
@ -884,7 +884,7 @@ BOOST_AUTO_TEST_CASE(payable_fallback_function)
[ [
{ {
"payable": true, "payable": true,
"statemutability": "payable", "stateMutability": "payable",
"type" : "fallback" "type" : "fallback"
} }
] ]
@ -905,7 +905,7 @@ BOOST_AUTO_TEST_CASE(function_type)
{ {
"constant" : false, "constant" : false,
"payable": false, "payable": false,
"statemutability": "nonpayable", "stateMutability": "nonpayable",
"inputs": [{ "inputs": [{
"name": "x", "name": "x",
"type": "function" "type": "function"