mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Keep gas values as a string in CompilerStack::gasEstimate
This commit is contained in:
parent
fe4fccaaf2
commit
54dcb0e11b
@ -848,10 +848,10 @@ namespace
|
|||||||
|
|
||||||
Json::Value gasToJson(GasEstimator::GasConsumption const& _gas)
|
Json::Value gasToJson(GasEstimator::GasConsumption const& _gas)
|
||||||
{
|
{
|
||||||
if (_gas.isInfinite || _gas.value > std::numeric_limits<Json::LargestUInt>::max())
|
if (_gas.isInfinite)
|
||||||
return Json::Value(Json::nullValue);
|
return Json::Value("infinite");
|
||||||
else
|
else
|
||||||
return Json::Value(Json::LargestUInt(_gas.value));
|
return Json::Value(toString(_gas.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -322,18 +322,9 @@ void CommandLineInterface::handleGasEstimation(string const& _contract)
|
|||||||
{
|
{
|
||||||
Json::Value creation = estimates["creation"];
|
Json::Value creation = estimates["creation"];
|
||||||
cout << "construction:" << endl;
|
cout << "construction:" << endl;
|
||||||
if (creation["executionCost"].isNull())
|
cout << " " << creation["executionCost"].asString();
|
||||||
cout << " infinite";
|
cout << " + " << creation["codeDepositCost"].asString();
|
||||||
else
|
cout << " = " << creation["totalCost"].asString() << endl;
|
||||||
cout << " " << creation["executionCost"];
|
|
||||||
if (creation["codeDepositCost"].isNull())
|
|
||||||
cout << " + infinite";
|
|
||||||
else
|
|
||||||
cout << " + " << creation["codeDepositCost"];
|
|
||||||
if (creation["totalCost"].isNull())
|
|
||||||
cout << " = infinite";
|
|
||||||
else
|
|
||||||
cout << " = " << creation["totalCost"] << endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (estimates["external"].isObject())
|
if (estimates["external"].isObject())
|
||||||
@ -346,10 +337,7 @@ void CommandLineInterface::handleGasEstimation(string const& _contract)
|
|||||||
cout << " fallback:\t";
|
cout << " fallback:\t";
|
||||||
else
|
else
|
||||||
cout << " " << name << ":\t";
|
cout << " " << name << ":\t";
|
||||||
if (externalFunctions[name].isNull())
|
cout << externalFunctions[name].asString() << endl;
|
||||||
cout << "infinite" << endl;
|
|
||||||
else
|
|
||||||
cout << externalFunctions[name] << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -360,10 +348,7 @@ void CommandLineInterface::handleGasEstimation(string const& _contract)
|
|||||||
for (auto const& name: internalFunctions.getMemberNames())
|
for (auto const& name: internalFunctions.getMemberNames())
|
||||||
{
|
{
|
||||||
cout << " " << name << ":\t";
|
cout << " " << name << ":\t";
|
||||||
if (internalFunctions[name].isNull())
|
cout << internalFunctions[name].asString() << endl;
|
||||||
cout << "infinite" << endl;
|
|
||||||
else
|
|
||||||
cout << internalFunctions[name] << endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,6 +58,27 @@ Json::Value functionHashes(ContractDefinition const& _contract)
|
|||||||
return functionHashes;
|
return functionHashes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Translates a gas value as a string to a JSON number or null
|
||||||
|
Json::Value gasToJson(Json::Value const& _value)
|
||||||
|
{
|
||||||
|
if (_value.isObject())
|
||||||
|
{
|
||||||
|
Json::Value ret = Json::objectValue;
|
||||||
|
for (auto const& sig: _value.getMemberNames())
|
||||||
|
ret[sig] = gasToJson(_value[sig]);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_value == "infinite")
|
||||||
|
return Json::Value(Json::nullValue);
|
||||||
|
|
||||||
|
u256 value(_value.asString());
|
||||||
|
if (value > std::numeric_limits<Json::LargestUInt>::max())
|
||||||
|
return Json::Value(Json::nullValue);
|
||||||
|
else
|
||||||
|
return Json::Value(Json::LargestUInt(value));
|
||||||
|
}
|
||||||
|
|
||||||
Json::Value estimateGas(CompilerStack const& _compiler, string const& _contract)
|
Json::Value estimateGas(CompilerStack const& _compiler, string const& _contract)
|
||||||
{
|
{
|
||||||
Json::Value estimates = _compiler.gasEstimates(_contract);
|
Json::Value estimates = _compiler.gasEstimates(_contract);
|
||||||
@ -66,14 +87,14 @@ Json::Value estimateGas(CompilerStack const& _compiler, string const& _contract)
|
|||||||
if (estimates["creation"].isObject())
|
if (estimates["creation"].isObject())
|
||||||
{
|
{
|
||||||
Json::Value creation(Json::arrayValue);
|
Json::Value creation(Json::arrayValue);
|
||||||
creation[0] = estimates["creation"]["executionCost"];
|
creation[0] = gasToJson(estimates["creation"]["executionCost"]);
|
||||||
creation[1] = estimates["creation"]["codeDepositCost"];
|
creation[1] = gasToJson(estimates["creation"]["codeDepositCost"]);
|
||||||
output["creation"] = creation;
|
output["creation"] = creation;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
output["creation"] = Json::objectValue;
|
output["creation"] = Json::objectValue;
|
||||||
output["external"] = estimates.get("external", Json::objectValue);
|
output["external"] = gasToJson(estimates.get("external", Json::objectValue));
|
||||||
output["internal"] = estimates.get("internal", Json::objectValue);
|
output["internal"] = gasToJson(estimates.get("internal", Json::objectValue));
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user