Skip to content

Commit bd7dd66

Browse files
committed
Keep gas values as a string in CompilerStack::gasEstimate
1 parent 1b66b13 commit bd7dd66

File tree

3 files changed

+38
-17
lines changed

3 files changed

+38
-17
lines changed

libsolidity/interface/CompilerStack.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -847,10 +847,10 @@ namespace {
847847

848848
Json::Value gasToJson(GasEstimator::GasConsumption const& _gas)
849849
{
850-
if (_gas.isInfinite || _gas.value > std::numeric_limits<Json::LargestUInt>::max())
851-
return Json::Value(Json::nullValue);
850+
if (_gas.isInfinite)
851+
return Json::Value("infinite");
852852
else
853-
return Json::Value(Json::LargestUInt(_gas.value));
853+
return Json::Value(toString(_gas.value));
854854
}
855855

856856
}

solc/CommandLineInterface.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -322,18 +322,18 @@ void CommandLineInterface::handleGasEstimation(string const& _contract)
322322
{
323323
Json::Value creation = estimates["creation"];
324324
cout << "construction:" << endl;
325-
if (creation["executionCost"].isNull())
325+
if (creation["executionCost"] == "infinite")
326326
cout << " infinite";
327327
else
328-
cout << " " << creation["executionCost"];
329-
if (creation["codeDepositCost"].isNull())
328+
cout << " " << u256(creation["executionCost"].asString());
329+
if (creation["codeDepositCost"] == "infinite")
330330
cout << " + infinite";
331331
else
332-
cout << " + " << creation["codeDepositCost"];
333-
if (creation["totalCost"].isNull())
332+
cout << " + " << u256(creation["codeDepositCost"].asString());
333+
if (creation["totalCost"] == "infinite")
334334
cout << " = infinite";
335335
else
336-
cout << " = " << creation["totalCost"] << endl;
336+
cout << " = " << u256(creation["totalCost"].asString()) << endl;
337337
}
338338

339339
if (estimates["external"].isObject())
@@ -346,10 +346,10 @@ void CommandLineInterface::handleGasEstimation(string const& _contract)
346346
cout << " fallback:\t";
347347
else
348348
cout << " " << name << ":\t";
349-
if (externalFunctions[name].isNull())
349+
if (externalFunctions[name] == "infinite")
350350
cout << "infinite" << endl;
351351
else
352-
cout << externalFunctions[name] << endl;
352+
cout << u256(externalFunctions[name].asString()) << endl;
353353
}
354354
}
355355

@@ -360,10 +360,10 @@ void CommandLineInterface::handleGasEstimation(string const& _contract)
360360
for (auto const& name: internalFunctions.getMemberNames())
361361
{
362362
cout << " " << name << ":\t";
363-
if (internalFunctions[name].isNull())
363+
if (internalFunctions[name] == "infinite")
364364
cout << "infinite" << endl;
365365
else
366-
cout << internalFunctions[name] << endl;
366+
cout << u256(internalFunctions[name].asString()) << endl;
367367
}
368368
}
369369
}

solc/jsonCompiler.cpp

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,27 @@ Json::Value functionHashes(ContractDefinition const& _contract)
5858
return functionHashes;
5959
}
6060

61+
/// Translates a gas value as a string to a JSON number or null
62+
Json::Value gasToJson(Json::Value const& _value)
63+
{
64+
if (_value.isObject())
65+
{
66+
Json::Value ret = Json::objectValue;
67+
for (auto const& sig: _value.getMemberNames())
68+
ret[sig] = gasToJson(_value[sig]);
69+
return ret;
70+
}
71+
72+
if (_value == "infinite")
73+
return Json::Value(Json::nullValue);
74+
75+
u256 value(_value.asString());
76+
if (value > std::numeric_limits<Json::LargestUInt>::max())
77+
return Json::Value(Json::nullValue);
78+
else
79+
return Json::Value(Json::LargestUInt(value));
80+
}
81+
6182
Json::Value estimateGas(CompilerStack const& _compiler, string const& _contract)
6283
{
6384
Json::Value estimates = _compiler.gasEstimates(_contract);
@@ -66,14 +87,14 @@ Json::Value estimateGas(CompilerStack const& _compiler, string const& _contract)
6687
if (estimates["creation"].isObject())
6788
{
6889
Json::Value creation(Json::arrayValue);
69-
creation[0] = estimates["creation"]["executionCost"];
70-
creation[1] = estimates["creation"]["codeDepositCost"];
90+
creation[0] = gasToJson(estimates["creation"]["executionCost"]);
91+
creation[1] = gasToJson(estimates["creation"]["codeDepositCost"]);
7192
output["creation"] = creation;
7293
}
7394
else
7495
output["creation"] = Json::objectValue;
75-
output["external"] = estimates.get("external", Json::objectValue);
76-
output["internal"] = estimates.get("internal", Json::objectValue);
96+
output["external"] = gasToJson(estimates.get("external", Json::objectValue));
97+
output["internal"] = gasToJson(estimates.get("internal", Json::objectValue));
7798

7899
return output;
79100
}

0 commit comments

Comments
 (0)