diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-04-12 19:06:01 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-04-13 09:18:29 +0800 |
commit | 54dcb0e11be09caf35e02792d47695685ba1f4cb (patch) | |
tree | 3e027108539be90a11e65b5b560506bd97e8216a /solc/jsonCompiler.cpp | |
parent | fe4fccaaf21dbb7cbfed9b758a3d8f12f979c6dc (diff) | |
download | dexon-solidity-54dcb0e11be09caf35e02792d47695685ba1f4cb.tar.gz dexon-solidity-54dcb0e11be09caf35e02792d47695685ba1f4cb.tar.zst dexon-solidity-54dcb0e11be09caf35e02792d47695685ba1f4cb.zip |
Keep gas values as a string in CompilerStack::gasEstimate
Diffstat (limited to 'solc/jsonCompiler.cpp')
-rw-r--r-- | solc/jsonCompiler.cpp | 29 |
1 files changed, 25 insertions, 4 deletions
diff --git a/solc/jsonCompiler.cpp b/solc/jsonCompiler.cpp index accbc13c..fd375ce3 100644 --- a/solc/jsonCompiler.cpp +++ b/solc/jsonCompiler.cpp @@ -58,6 +58,27 @@ Json::Value functionHashes(ContractDefinition const& _contract) 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 estimates = _compiler.gasEstimates(_contract); @@ -66,14 +87,14 @@ Json::Value estimateGas(CompilerStack const& _compiler, string const& _contract) if (estimates["creation"].isObject()) { Json::Value creation(Json::arrayValue); - creation[0] = estimates["creation"]["executionCost"]; - creation[1] = estimates["creation"]["codeDepositCost"]; + creation[0] = gasToJson(estimates["creation"]["executionCost"]); + creation[1] = gasToJson(estimates["creation"]["codeDepositCost"]); output["creation"] = creation; } else output["creation"] = Json::objectValue; - output["external"] = estimates.get("external", Json::objectValue); - output["internal"] = estimates.get("internal", Json::objectValue); + output["external"] = gasToJson(estimates.get("external", Json::objectValue)); + output["internal"] = gasToJson(estimates.get("internal", Json::objectValue)); return output; } |