Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change ABI sorting order. #7335

Merged
merged 1 commit into from Sep 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Changelog.md
Expand Up @@ -5,6 +5,7 @@ Language Features:


Compiler Features:
* ABI Output: Change sorting order of functions from selector to kind, name.
* Optimizer: Add rule that replaces the BYTE opcode by 0 if the first argument is larger than 31.
* Yul Optimizer: Take side-effect-freeness of user-defined functions into account.

Expand Down
18 changes: 12 additions & 6 deletions libsolidity/interface/ABI.cpp
Expand Up @@ -40,7 +40,10 @@ bool anyDataStoredInStorage(TypePointers const& _pointers)

Json::Value ABI::generate(ContractDefinition const& _contractDef)
{
Json::Value abi(Json::arrayValue);
auto compare = [](Json::Value const& _a, Json::Value const& _b) -> bool {
return make_tuple(_a["type"], _a["name"]) < make_tuple(_b["type"], _b["name"]);
};
multiset<Json::Value, decltype(compare)> abi(compare);

for (auto it: _contractDef.interfaceFunctions())
{
Expand Down Expand Up @@ -71,7 +74,7 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
it.second->returnParameterTypes(),
_contractDef.isLibrary()
);
abi.append(std::move(method));
abi.emplace(std::move(method));
}
if (_contractDef.constructor())
{
Expand All @@ -88,7 +91,7 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
constrType.parameterTypes(),
_contractDef.isLibrary()
);
abi.append(std::move(method));
abi.emplace(std::move(method));
}
if (_contractDef.fallbackFunction())
{
Expand All @@ -98,7 +101,7 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
method["type"] = "fallback";
method["payable"] = externalFunctionType->isPayable();
method["stateMutability"] = stateMutabilityToString(externalFunctionType->stateMutability());
abi.append(std::move(method));
abi.emplace(std::move(method));
}
for (auto const& it: _contractDef.interfaceEvents())
{
Expand All @@ -117,10 +120,13 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
params.append(std::move(param));
}
event["inputs"] = std::move(params);
abi.append(std::move(event));
abi.emplace(std::move(event));
}

return abi;
Json::Value abiJson{Json::arrayValue};
for (auto& f: abi)
abiJson.append(std::move(f));
return abiJson;
}

Json::Value ABI::formatTypeList(
Expand Down
46 changes: 23 additions & 23 deletions test/libsolidity/ABIJson/events.sol
Expand Up @@ -9,29 +9,6 @@ contract test {
// :test
// [
// {
// "constant": false,
// "inputs":
// [
// {
// "internalType": "uint256",
// "name": "a",
// "type": "uint256"
// }
// ],
// "name": "f",
// "outputs":
// [
// {
// "internalType": "uint256",
// "name": "d",
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// },
// {
// "anonymous": false,
// "inputs":
// [
Expand Down Expand Up @@ -76,5 +53,28 @@ contract test {
// "inputs": [],
// "name": "e3",
// "type": "event"
// },
// {
// "constant": false,
// "inputs":
// [
// {
// "internalType": "uint256",
// "name": "a",
// "type": "uint256"
// }
// ],
// "name": "f",
// "outputs":
// [
// {
// "internalType": "uint256",
// "name": "d",
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// }
// ]
70 changes: 35 additions & 35 deletions test/libsolidity/ABIJson/inherited.sol
Expand Up @@ -10,6 +10,20 @@ contract Derived is Base {
// :Base
// [
// {
// "anonymous": false,
// "inputs":
// [
// {
// "indexed": true,
// "internalType": "bytes32",
// "name": "evtArgBase",
// "type": "bytes32"
// }
// ],
// "name": "baseEvent",
// "type": "event"
// },
// {
// "constant": false,
// "inputs":
// [
Expand All @@ -31,7 +45,12 @@ contract Derived is Base {
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// },
// }
// ]
//
//
// :Derived
// [
// {
// "anonymous": false,
// "inputs":
Expand All @@ -45,12 +64,21 @@ contract Derived is Base {
// ],
// "name": "baseEvent",
// "type": "event"
// }
// ]
//
//
// :Derived
// [
// },
// {
// "anonymous": false,
// "inputs":
// [
// {
// "indexed": true,
// "internalType": "uint256",
// "name": "evtArgDerived",
// "type": "uint256"
// }
// ],
// "name": "derivedEvent",
// "type": "event"
// },
// {
// "constant": false,
// "inputs":
Expand Down Expand Up @@ -96,33 +124,5 @@ contract Derived is Base {
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// },
// {
// "anonymous": false,
// "inputs":
// [
// {
// "indexed": true,
// "internalType": "uint256",
// "name": "evtArgDerived",
// "type": "uint256"
// }
// ],
// "name": "derivedEvent",
// "type": "event"
// },
// {
// "anonymous": false,
// "inputs":
// [
// {
// "indexed": true,
// "internalType": "bytes32",
// "name": "evtArgBase",
// "type": "bytes32"
// }
// ],
// "name": "baseEvent",
// "type": "event"
// }
// ]
34 changes: 17 additions & 17 deletions test/libsolidity/ABIJson/pure_function.sol
Expand Up @@ -6,54 +6,54 @@ contract test {
// :test
// [
// {
// "constant": false,
// "constant": true,
// "inputs":
// [
// {
// "internalType": "uint256",
// "internalType": "uint32",
// "name": "a",
// "type": "uint256"
// },
// {
// "internalType": "uint256",
// "name": "b",
// "type": "uint256"
// "type": "uint32"
// }
// ],
// "name": "foo",
// "name": "boo",
// "outputs":
// [
// {
// "internalType": "uint256",
// "name": "d",
// "name": "b",
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "stateMutability": "pure",
// "type": "function"
// },
// {
// "constant": true,
// "constant": false,
// "inputs":
// [
// {
// "internalType": "uint32",
// "internalType": "uint256",
// "name": "a",
// "type": "uint32"
// "type": "uint256"
// },
// {
// "internalType": "uint256",
// "name": "b",
// "type": "uint256"
// }
// ],
// "name": "boo",
// "name": "foo",
// "outputs":
// [
// {
// "internalType": "uint256",
// "name": "b",
// "name": "d",
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "pure",
// "stateMutability": "nonpayable",
// "type": "function"
// }
// ]
18 changes: 9 additions & 9 deletions test/libsolidity/ABIJson/return_param_in_abi.sol
Expand Up @@ -11,32 +11,32 @@ contract test {
// :test
// [
// {
// "constant": false,
// "inputs": [],
// "name": "ret",
// "outputs":
// "inputs":
// [
// {
// "internalType": "enum test.ActionChoices",
// "name": "",
// "name": "param",
// "type": "uint8"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "function"
// "type": "constructor"
// },
// {
// "inputs":
// "constant": false,
// "inputs": [],
// "name": "ret",
// "outputs":
// [
// {
// "internalType": "enum test.ActionChoices",
// "name": "param",
// "name": "",
// "type": "uint8"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "constructor"
// "type": "function"
// }
// ]