mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #2732 from ethereum/statemutability-abi
Add statemutability field to ABI
This commit is contained in:
commit
29cf3d9c58
@ -1,6 +1,7 @@
|
|||||||
### 0.4.16 (unreleased)
|
### 0.4.16 (unreleased)
|
||||||
|
|
||||||
Features:
|
Features:
|
||||||
|
* ABI JSON: Include new field ``statemutability`` with values ``view``, ``nonpayable`` and ``payable``.
|
||||||
* Parser: Display previous visibility specifier in error if multiple are found.
|
* Parser: Display previous visibility specifier in error if multiple are found.
|
||||||
* Syntax Checker: Support ``pragma experimental <feature>;`` to turn on experimental features.
|
* Syntax Checker: Support ``pragma experimental <feature>;`` to turn on experimental features.
|
||||||
* Static Analyzer: Warn about large storage structures.
|
* Static Analyzer: Warn about large storage structures.
|
||||||
|
@ -294,7 +294,8 @@ The JSON format for a contract's interface is given by an array of function and/
|
|||||||
* `type`: the canonical type of the parameter.
|
* `type`: the canonical type of the parameter.
|
||||||
- `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 <constant-functions>`);
|
- `constant`: `true` if function is :ref:`specified to not modify blockchain state <constant-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: `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"`.
|
||||||
|
|
||||||
|
@ -38,6 +38,7 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
|
|||||||
method["name"] = it.second->declaration().name();
|
method["name"] = it.second->declaration().name();
|
||||||
method["constant"] = it.second->isConstant();
|
method["constant"] = it.second->isConstant();
|
||||||
method["payable"] = it.second->isPayable();
|
method["payable"] = it.second->isPayable();
|
||||||
|
method["statemutability"] = stateMutabilityToString(it.second->stateMutability());
|
||||||
method["inputs"] = formatTypeList(
|
method["inputs"] = formatTypeList(
|
||||||
externalFunctionType->parameterNames(),
|
externalFunctionType->parameterNames(),
|
||||||
externalFunctionType->parameterTypes(),
|
externalFunctionType->parameterTypes(),
|
||||||
@ -57,6 +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["inputs"] = formatTypeList(
|
method["inputs"] = formatTypeList(
|
||||||
externalFunction->parameterNames(),
|
externalFunction->parameterNames(),
|
||||||
externalFunction->parameterTypes(),
|
externalFunction->parameterTypes(),
|
||||||
@ -71,6 +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());
|
||||||
abi.append(method);
|
abi.append(method);
|
||||||
}
|
}
|
||||||
for (auto const& it: _contractDef.interfaceEvents())
|
for (auto const& it: _contractDef.interfaceEvents())
|
||||||
|
@ -76,6 +76,7 @@ BOOST_AUTO_TEST_CASE(basic_test)
|
|||||||
"name": "f",
|
"name": "f",
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
@ -119,6 +120,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods)
|
|||||||
"name": "f",
|
"name": "f",
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
@ -137,6 +139,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods)
|
|||||||
"name": "g",
|
"name": "g",
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
@ -169,6 +172,7 @@ BOOST_AUTO_TEST_CASE(multiple_params)
|
|||||||
"name": "f",
|
"name": "f",
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
@ -207,6 +211,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods_order)
|
|||||||
"name": "c",
|
"name": "c",
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
@ -225,6 +230,7 @@ BOOST_AUTO_TEST_CASE(multiple_methods_order)
|
|||||||
"name": "f",
|
"name": "f",
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
@ -258,6 +264,7 @@ BOOST_AUTO_TEST_CASE(const_function)
|
|||||||
"name": "foo",
|
"name": "foo",
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
@ -280,6 +287,7 @@ BOOST_AUTO_TEST_CASE(const_function)
|
|||||||
"name": "boo",
|
"name": "boo",
|
||||||
"constant": true,
|
"constant": true,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "view",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"inputs": [{
|
"inputs": [{
|
||||||
"name": "a",
|
"name": "a",
|
||||||
@ -311,6 +319,7 @@ BOOST_AUTO_TEST_CASE(events)
|
|||||||
"name": "f",
|
"name": "f",
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
@ -392,6 +401,7 @@ BOOST_AUTO_TEST_CASE(inherited)
|
|||||||
"name": "baseFunction",
|
"name": "baseFunction",
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"inputs":
|
"inputs":
|
||||||
[{
|
[{
|
||||||
@ -408,6 +418,7 @@ BOOST_AUTO_TEST_CASE(inherited)
|
|||||||
"name": "derivedFunction",
|
"name": "derivedFunction",
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"inputs":
|
"inputs":
|
||||||
[{
|
[{
|
||||||
@ -463,6 +474,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",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
@ -505,6 +517,7 @@ BOOST_AUTO_TEST_CASE(empty_name_return_parameter)
|
|||||||
"name": "f",
|
"name": "f",
|
||||||
"constant": false,
|
"constant": false,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"type": "function",
|
"type": "function",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{
|
{
|
||||||
@ -548,12 +561,44 @@ BOOST_AUTO_TEST_CASE(constructor_abi)
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"payable": false,
|
"payable": false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"type": "constructor"
|
"type": "constructor"
|
||||||
}
|
}
|
||||||
])";
|
])";
|
||||||
checkInterface(sourceCode, interface);
|
checkInterface(sourceCode, interface);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BOOST_AUTO_TEST_CASE(payable_constructor_abi)
|
||||||
|
{
|
||||||
|
char const* sourceCode = R"(
|
||||||
|
contract test {
|
||||||
|
function test(uint param1, test param2, bool param3) payable {}
|
||||||
|
}
|
||||||
|
)";
|
||||||
|
|
||||||
|
char const* interface = R"([
|
||||||
|
{
|
||||||
|
"inputs": [
|
||||||
|
{
|
||||||
|
"name": "param1",
|
||||||
|
"type": "uint256"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "param2",
|
||||||
|
"type": "address"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "param3",
|
||||||
|
"type": "bool"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"payable": true,
|
||||||
|
"statemutability": "payable",
|
||||||
|
"type": "constructor"
|
||||||
|
}
|
||||||
|
])";
|
||||||
|
checkInterface(sourceCode, interface);
|
||||||
|
}
|
||||||
|
|
||||||
BOOST_AUTO_TEST_CASE(return_param_in_abi)
|
BOOST_AUTO_TEST_CASE(return_param_in_abi)
|
||||||
{
|
{
|
||||||
@ -574,6 +619,7 @@ BOOST_AUTO_TEST_CASE(return_param_in_abi)
|
|||||||
{
|
{
|
||||||
"constant" : false,
|
"constant" : false,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"inputs" : [],
|
"inputs" : [],
|
||||||
"name" : "ret",
|
"name" : "ret",
|
||||||
"outputs" : [
|
"outputs" : [
|
||||||
@ -592,6 +638,7 @@ BOOST_AUTO_TEST_CASE(return_param_in_abi)
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"payable": false,
|
"payable": false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"type": "constructor"
|
"type": "constructor"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -613,6 +660,7 @@ BOOST_AUTO_TEST_CASE(strings_and_arrays)
|
|||||||
{
|
{
|
||||||
"constant" : false,
|
"constant" : false,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"name": "f",
|
"name": "f",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{ "name": "a", "type": "string" },
|
{ "name": "a", "type": "string" },
|
||||||
@ -641,6 +689,7 @@ BOOST_AUTO_TEST_CASE(library_function)
|
|||||||
{
|
{
|
||||||
"constant" : false,
|
"constant" : false,
|
||||||
"payable" : false,
|
"payable" : false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"name": "f",
|
"name": "f",
|
||||||
"inputs": [
|
"inputs": [
|
||||||
{ "name": "b", "type": "test.StructType storage" },
|
{ "name": "b", "type": "test.StructType storage" },
|
||||||
@ -670,6 +719,7 @@ BOOST_AUTO_TEST_CASE(include_fallback_function)
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"payable": false,
|
"payable": false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"type" : "fallback"
|
"type" : "fallback"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -691,6 +741,7 @@ BOOST_AUTO_TEST_CASE(payable_function)
|
|||||||
{
|
{
|
||||||
"constant" : false,
|
"constant" : false,
|
||||||
"payable": false,
|
"payable": false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"inputs": [],
|
"inputs": [],
|
||||||
"name": "f",
|
"name": "f",
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@ -699,6 +750,7 @@ BOOST_AUTO_TEST_CASE(payable_function)
|
|||||||
{
|
{
|
||||||
"constant" : false,
|
"constant" : false,
|
||||||
"payable": true,
|
"payable": true,
|
||||||
|
"statemutability": "payable",
|
||||||
"inputs": [],
|
"inputs": [],
|
||||||
"name": "g",
|
"name": "g",
|
||||||
"outputs": [],
|
"outputs": [],
|
||||||
@ -721,6 +773,7 @@ BOOST_AUTO_TEST_CASE(payable_fallback_function)
|
|||||||
[
|
[
|
||||||
{
|
{
|
||||||
"payable": true,
|
"payable": true,
|
||||||
|
"statemutability": "payable",
|
||||||
"type" : "fallback"
|
"type" : "fallback"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
@ -741,6 +794,7 @@ BOOST_AUTO_TEST_CASE(function_type)
|
|||||||
{
|
{
|
||||||
"constant" : false,
|
"constant" : false,
|
||||||
"payable": false,
|
"payable": false,
|
||||||
|
"statemutability": "nonpayable",
|
||||||
"inputs": [{
|
"inputs": [{
|
||||||
"name": "x",
|
"name": "x",
|
||||||
"type": "function"
|
"type": "function"
|
||||||
|
Loading…
Reference in New Issue
Block a user