Merge pull request #7335 from ethereum/abiSorting

Change ABI sorting order.
This commit is contained in:
chriseth 2019-09-04 17:18:27 +02:00 committed by GitHub
commit 7dd77784b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 130 additions and 123 deletions

View File

@ -5,6 +5,7 @@ Language Features:
Compiler 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. * 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. * Yul Optimizer: Take side-effect-freeness of user-defined functions into account.

View File

@ -40,7 +40,10 @@ bool anyDataStoredInStorage(TypePointers const& _pointers)
Json::Value ABI::generate(ContractDefinition const& _contractDef) 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()) for (auto it: _contractDef.interfaceFunctions())
{ {
@ -71,7 +74,7 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
it.second->returnParameterTypes(), it.second->returnParameterTypes(),
_contractDef.isLibrary() _contractDef.isLibrary()
); );
abi.append(std::move(method)); abi.emplace(std::move(method));
} }
if (_contractDef.constructor()) if (_contractDef.constructor())
{ {
@ -88,7 +91,7 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
constrType.parameterTypes(), constrType.parameterTypes(),
_contractDef.isLibrary() _contractDef.isLibrary()
); );
abi.append(std::move(method)); abi.emplace(std::move(method));
} }
if (_contractDef.fallbackFunction()) if (_contractDef.fallbackFunction())
{ {
@ -98,7 +101,7 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
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(std::move(method)); abi.emplace(std::move(method));
} }
for (auto const& it: _contractDef.interfaceEvents()) for (auto const& it: _contractDef.interfaceEvents())
{ {
@ -117,10 +120,13 @@ Json::Value ABI::generate(ContractDefinition const& _contractDef)
params.append(std::move(param)); params.append(std::move(param));
} }
event["inputs"] = std::move(params); 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( Json::Value ABI::formatTypeList(

View File

@ -9,29 +9,6 @@ contract test {
// :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, // "anonymous": false,
// "inputs": // "inputs":
// [ // [
@ -76,5 +53,28 @@ contract test {
// "inputs": [], // "inputs": [],
// "name": "e3", // "name": "e3",
// "type": "event" // "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"
// } // }
// ] // ]

View File

@ -10,6 +10,20 @@ contract Derived is Base {
// :Base // :Base
// [ // [
// { // {
// "anonymous": false,
// "inputs":
// [
// {
// "indexed": true,
// "internalType": "bytes32",
// "name": "evtArgBase",
// "type": "bytes32"
// }
// ],
// "name": "baseEvent",
// "type": "event"
// },
// {
// "constant": false, // "constant": false,
// "inputs": // "inputs":
// [ // [
@ -31,7 +45,12 @@ contract Derived is Base {
// "payable": false, // "payable": false,
// "stateMutability": "nonpayable", // "stateMutability": "nonpayable",
// "type": "function" // "type": "function"
// }, // }
// ]
//
//
// :Derived
// [
// { // {
// "anonymous": false, // "anonymous": false,
// "inputs": // "inputs":
@ -45,12 +64,21 @@ contract Derived is Base {
// ], // ],
// "name": "baseEvent", // "name": "baseEvent",
// "type": "event" // "type": "event"
// } // },
// ] // {
// // "anonymous": false,
// // "inputs":
// :Derived // [
// [ // {
// "indexed": true,
// "internalType": "uint256",
// "name": "evtArgDerived",
// "type": "uint256"
// }
// ],
// "name": "derivedEvent",
// "type": "event"
// },
// { // {
// "constant": false, // "constant": false,
// "inputs": // "inputs":
@ -96,33 +124,5 @@ contract Derived is Base {
// "payable": false, // "payable": false,
// "stateMutability": "nonpayable", // "stateMutability": "nonpayable",
// "type": "function" // "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"
// } // }
// ] // ]

View File

@ -6,6 +6,29 @@ contract test {
// :test // :test
// [ // [
// { // {
// "constant": true,
// "inputs":
// [
// {
// "internalType": "uint32",
// "name": "a",
// "type": "uint32"
// }
// ],
// "name": "boo",
// "outputs":
// [
// {
// "internalType": "uint256",
// "name": "b",
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "pure",
// "type": "function"
// },
// {
// "constant": false, // "constant": false,
// "inputs": // "inputs":
// [ // [
@ -32,28 +55,5 @@ contract test {
// "payable": false, // "payable": false,
// "stateMutability": "nonpayable", // "stateMutability": "nonpayable",
// "type": "function" // "type": "function"
// },
// {
// "constant": true,
// "inputs":
// [
// {
// "internalType": "uint32",
// "name": "a",
// "type": "uint32"
// }
// ],
// "name": "boo",
// "outputs":
// [
// {
// "internalType": "uint256",
// "name": "b",
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "pure",
// "type": "function"
// } // }
// ] // ]

View File

@ -11,6 +11,19 @@ contract test {
// :test // :test
// [ // [
// { // {
// "inputs":
// [
// {
// "internalType": "enum test.ActionChoices",
// "name": "param",
// "type": "uint8"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "constructor"
// },
// {
// "constant": false, // "constant": false,
// "inputs": [], // "inputs": [],
// "name": "ret", // "name": "ret",
@ -25,18 +38,5 @@ contract test {
// "payable": false, // "payable": false,
// "stateMutability": "nonpayable", // "stateMutability": "nonpayable",
// "type": "function" // "type": "function"
// },
// {
// "inputs":
// [
// {
// "internalType": "enum test.ActionChoices",
// "name": "param",
// "type": "uint8"
// }
// ],
// "payable": false,
// "stateMutability": "nonpayable",
// "type": "constructor"
// } // }
// ] // ]

View File

@ -6,6 +6,29 @@ contract test {
// :test // :test
// [ // [
// { // {
// "constant": true,
// "inputs":
// [
// {
// "internalType": "uint32",
// "name": "a",
// "type": "uint32"
// }
// ],
// "name": "boo",
// "outputs":
// [
// {
// "internalType": "uint256",
// "name": "b",
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "view",
// "type": "function"
// },
// {
// "constant": false, // "constant": false,
// "inputs": // "inputs":
// [ // [
@ -32,28 +55,5 @@ contract test {
// "payable": false, // "payable": false,
// "stateMutability": "nonpayable", // "stateMutability": "nonpayable",
// "type": "function" // "type": "function"
// },
// {
// "constant": true,
// "inputs":
// [
// {
// "internalType": "uint32",
// "name": "a",
// "type": "uint32"
// }
// ],
// "name": "boo",
// "outputs":
// [
// {
// "internalType": "uint256",
// "name": "b",
// "type": "uint256"
// }
// ],
// "payable": false,
// "stateMutability": "view",
// "type": "function"
// } // }
// ] // ]