Drop constant and payable fields from ABI.

This commit is contained in:
Daniel Kirchner 2019-09-06 12:21:54 +02:00
parent 10830d2401
commit f4d990e5be
28 changed files with 4 additions and 74 deletions

View File

@ -1,6 +1,7 @@
### 0.6.0 (unreleased)
Breaking changes:
* ABI: remove the deprecated ``constant`` and ``payable`` fields.
* Commandline interface: remove the text-based ast printer (``--ast``).
* General: Disallow explicit conversions from external function types to ``address`` and add a member called ``address`` to them as replacement.
* Type checker: Resulting type of exponentiation is equal to the type of the base. Also allow signed types for the base.

View File

@ -454,16 +454,11 @@ A function description is a JSON object with the fields:
- ``outputs``: an array of objects similar to ``inputs``, can be omitted if function doesn't return anything;
- ``stateMutability``: a string with one of the following values: ``pure`` (:ref:`specified to not read blockchain state <pure-functions>`), ``view`` (:ref:`specified to not modify the blockchain state <view-functions>`), ``nonpayable`` (function does not accept Ether) and ``payable`` (function accepts Ether);
- ``payable``: ``true`` if function accepts Ether, ``false`` otherwise;
- ``constant``: ``true`` if function is either ``pure`` or ``view``, ``false`` otherwise.
``type`` can be omitted, defaulting to ``"function"``, likewise ``payable`` and ``constant`` can be omitted, both defaulting to ``false``.
``type`` can be omitted, defaulting to ``"function"``.
Constructor and fallback function never have ``name`` or ``outputs``. Fallback function doesn't have ``inputs`` either.
.. warning::
The fields ``constant`` and ``payable`` are deprecated and will be removed in the future. Instead, the ``stateMutability`` field can be used to determine the same properties.
.. note::
Sending non-zero Ether to non-payable function will revert the transaction.

View File

@ -58,9 +58,6 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
Json::Value method;
method["type"] = "function";
method["name"] = it.second->declaration().name();
// TODO: deprecate constant in a future release
method["constant"] = externalFunctionType->stateMutability() == StateMutability::Pure || it.second->stateMutability() == StateMutability::View;
method["payable"] = externalFunctionType->isPayable();
method["stateMutability"] = stateMutabilityToString(externalFunctionType->stateMutability());
method["inputs"] = formatTypeList(
externalFunctionType->parameterNames(),
@ -83,7 +80,6 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
solAssert(!!externalFunctionType, "");
Json::Value method;
method["type"] = "constructor";
method["payable"] = externalFunctionType->isPayable();
method["stateMutability"] = stateMutabilityToString(externalFunctionType->stateMutability());
method["inputs"] = formatTypeList(
externalFunctionType->parameterNames(),
@ -99,7 +95,6 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
solAssert(!!externalFunctionType, "");
Json::Value method;
method["type"] = "fallback";
method["payable"] = externalFunctionType->isPayable();
method["stateMutability"] = stateMutabilityToString(externalFunctionType->stateMutability());
abi.emplace(std::move(method));
}

View File

@ -5,7 +5,6 @@ contract test {
// :test
// [
// {
// "constant": false,
// "inputs":
// [
// {
@ -23,7 +22,6 @@ contract test {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -23,7 +23,6 @@ contract test {
// "type": "bool"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "constructor"
// }

View File

@ -9,7 +9,6 @@ contract test {
// :test
// [
// {
// "constant": false,
// "inputs":
// [
// {
@ -37,7 +36,6 @@ contract test {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -7,7 +7,6 @@ contract test {
// :test
// [
// {
// "constant": false,
// "inputs":
// [
// {
@ -25,7 +24,6 @@ contract test {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -55,7 +55,6 @@ contract test {
// "type": "event"
// },
// {
// "constant": false,
// "inputs":
// [
// {
@ -73,7 +72,6 @@ contract test {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -5,7 +5,6 @@ contract test {
// :test
// [
// {
// "constant": false,
// "inputs":
// [
// {
@ -16,7 +15,6 @@ contract test {
// ],
// "name": "g",
// "outputs": [],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -5,7 +5,6 @@ contract test {
// :test
// [
// {
// "constant": false,
// "inputs":
// [
// {
@ -16,7 +15,6 @@ contract test {
// ],
// "name": "g",
// "outputs": [],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -8,7 +8,6 @@ contract C {
// :C
// [
// {
// "constant": true,
// "inputs":
// [
// {
@ -27,12 +26,10 @@ contract C {
// ],
// "name": "f",
// "outputs": [],
// "payable": false,
// "stateMutability": "view",
// "type": "function"
// },
// {
// "constant": true,
// "inputs":
// [
// {
@ -51,7 +48,6 @@ contract C {
// ],
// "name": "g",
// "outputs": [],
// "payable": false,
// "stateMutability": "view",
// "type": "function"
// }

View File

@ -5,7 +5,6 @@ contract test {
// :test
// [
// {
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "fallback"
// }

View File

@ -24,7 +24,6 @@ contract Derived is Base {
// "type": "event"
// },
// {
// "constant": false,
// "inputs":
// [
// {
@ -42,7 +41,6 @@ contract Derived is Base {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }
@ -80,7 +78,6 @@ contract Derived is Base {
// "type": "event"
// },
// {
// "constant": false,
// "inputs":
// [
// {
@ -98,12 +95,10 @@ contract Derived is Base {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// },
// {
// "constant": false,
// "inputs":
// [
// {
@ -121,7 +116,6 @@ contract Derived is Base {
// "type": "bytes32"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -7,7 +7,6 @@ library test {
// :test
// [
// {
// "constant": true,
// "inputs":
// [
// {
@ -30,7 +29,6 @@ library test {
// "type": "uint256[]"
// }
// ],
// "payable": false,
// "stateMutability": "pure",
// "type": "function"
// }

View File

@ -6,7 +6,6 @@ contract test {
// :test
// [
// {
// "constant": false,
// "inputs":
// [
// {
@ -24,12 +23,10 @@ contract test {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// },
// {
// "constant": false,
// "inputs":
// [
// {
@ -47,7 +44,6 @@ contract test {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -7,7 +7,6 @@ contract test {
// :test
// [
// {
// "constant": false,
// "inputs":
// [
// {
@ -25,12 +24,10 @@ contract test {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// },
// {
// "constant": false,
// "inputs":
// [
// {
@ -48,7 +45,6 @@ contract test {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -5,7 +5,6 @@ contract test {
// :test
// [
// {
// "constant": false,
// "inputs":
// [
// {
@ -28,7 +27,6 @@ contract test {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -5,7 +5,6 @@ contract test {
// :test
// [
// {
// "payable": true,
// "stateMutability": "payable",
// "type": "fallback"
// }

View File

@ -23,7 +23,6 @@ contract test {
// "type": "bool"
// }
// ],
// "payable": true,
// "stateMutability": "payable",
// "type": "constructor"
// }

View File

@ -6,20 +6,16 @@ contract test {
// :test
// [
// {
// "constant": false,
// "inputs": [],
// "name": "f",
// "outputs": [],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// },
// {
// "constant": false,
// "inputs": [],
// "name": "g",
// "outputs": [],
// "payable": true,
// "stateMutability": "payable",
// "type": "function"
// }

View File

@ -6,7 +6,6 @@ contract test {
// :test
// [
// {
// "constant": true,
// "inputs":
// [
// {
@ -24,12 +23,10 @@ contract test {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "pure",
// "type": "function"
// },
// {
// "constant": false,
// "inputs":
// [
// {
@ -52,7 +49,6 @@ contract test {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -19,12 +19,10 @@ contract test {
// "type": "uint8"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "constructor"
// },
// {
// "constant": false,
// "inputs": [],
// "name": "ret",
// "outputs":
@ -35,7 +33,6 @@ contract test {
// "type": "uint8"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -9,7 +9,6 @@ contract C {
// :C
// [
// {
// "constant": false,
// "inputs": [],
// "name": "f",
// "outputs":
@ -46,7 +45,6 @@ contract C {
// "type": "tuple"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -8,7 +8,6 @@ contract C {
// :C
// [
// {
// "constant": false,
// "inputs": [],
// "name": "f",
// "outputs":
@ -37,7 +36,6 @@ contract C {
// "type": "address"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -6,7 +6,6 @@ contract test {
// :test
// [
// {
// "constant": false,
// "inputs":
// [
// {
@ -27,7 +26,6 @@ contract test {
// ],
// "name": "f",
// "outputs": [],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -9,7 +9,6 @@ library L {
// :L
// [
// {
// "constant": true,
// "inputs":
// [
// {
@ -46,7 +45,6 @@ library L {
// ],
// "name": "g",
// "outputs": [],
// "payable": false,
// "stateMutability": "view",
// "type": "function"
// }

View File

@ -6,7 +6,6 @@ contract test {
// :test
// [
// {
// "constant": true,
// "inputs":
// [
// {
@ -24,12 +23,10 @@ contract test {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "view",
// "type": "function"
// },
// {
// "constant": false,
// "inputs":
// [
// {
@ -52,7 +49,6 @@ contract test {
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }

View File

@ -615,7 +615,7 @@ BOOST_AUTO_TEST_CASE(output_selection_dependent_contract)
Json::Value contract = getContractResult(result, "fileA", "A");
BOOST_CHECK(contract.isObject());
BOOST_CHECK(contract["abi"].isArray());
BOOST_CHECK_EQUAL(dev::jsonCompactPrint(contract["abi"]), "[{\"constant\":false,\"inputs\":[],\"name\":\"f\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]");
BOOST_CHECK_EQUAL(dev::jsonCompactPrint(contract["abi"]), "[{\"inputs\":[],\"name\":\"f\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]");
}
BOOST_AUTO_TEST_CASE(output_selection_dependent_contract_with_import)
@ -647,7 +647,7 @@ BOOST_AUTO_TEST_CASE(output_selection_dependent_contract_with_import)
Json::Value contract = getContractResult(result, "fileA", "A");
BOOST_CHECK(contract.isObject());
BOOST_CHECK(contract["abi"].isArray());
BOOST_CHECK_EQUAL(dev::jsonCompactPrint(contract["abi"]), "[{\"constant\":false,\"inputs\":[],\"name\":\"f\",\"outputs\":[],\"payable\":false,\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]");
BOOST_CHECK_EQUAL(dev::jsonCompactPrint(contract["abi"]), "[{\"inputs\":[],\"name\":\"f\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}]");
}
BOOST_AUTO_TEST_CASE(filename_with_colon)