Use new gasEstimate in CLI

This commit is contained in:
Alex Beregszaszi 2017-04-10 14:52:13 +01:00
parent d90fd439e2
commit 328f2b0a8e

View File

@ -315,49 +315,55 @@ void CommandLineInterface::handleMeta(DocumentationType _type, string const& _co
void CommandLineInterface::handleGasEstimation(string const& _contract) void CommandLineInterface::handleGasEstimation(string const& _contract)
{ {
using Gas = GasEstimator::GasConsumption; Json::Value estimates = m_compiler->gasEstimates(_contract);
if (!m_compiler->assemblyItems(_contract) && !m_compiler->runtimeAssemblyItems(_contract))
return;
cout << "Gas estimation:" << endl; cout << "Gas estimation:" << endl;
if (eth::AssemblyItems const* items = m_compiler->assemblyItems(_contract))
if (estimates["creation"].isObject())
{ {
Gas gas = GasEstimator::functionalEstimation(*items); Json::Value creation = estimates["creation"];
u256 bytecodeSize(m_compiler->runtimeObject(_contract).bytecode.size());
cout << "construction:" << endl; cout << "construction:" << endl;
cout << " " << gas << " + " << (bytecodeSize * eth::GasCosts::createDataGas) << " = "; if (creation["executionCost"].isNull())
gas += bytecodeSize * eth::GasCosts::createDataGas; cout << " infinite";
cout << gas << endl; else
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 (eth::AssemblyItems const* items = m_compiler->runtimeAssemblyItems(_contract))
if (estimates["external"].isObject())
{ {
ContractDefinition const& contract = m_compiler->contractDefinition(_contract); Json::Value externalFunctions = estimates["external"];
cout << "external:" << endl; cout << "external:" << endl;
for (auto it: contract.interfaceFunctions()) for (auto const& name: externalFunctions.getMemberNames())
{ {
string sig = it.second->externalSignature(); if (name.empty())
GasEstimator::GasConsumption gas = GasEstimator::functionalEstimation(*items, sig); cout << " fallback:\t";
cout << " " << sig << ":\t" << gas << endl; else
} cout << " " << name << ":\t";
if (contract.fallbackFunction()) if (externalFunctions[name].isNull())
{ cout << "infinite" << endl;
GasEstimator::GasConsumption gas = GasEstimator::functionalEstimation(*items, "INVALID"); else
cout << " fallback:\t" << gas << endl; cout << externalFunctions[name] << endl;
} }
}
if (estimates["internal"].isObject())
{
Json::Value internalFunctions = estimates["internal"];
cout << "internal:" << endl; cout << "internal:" << endl;
for (auto const& it: contract.definedFunctions()) for (auto const& name: internalFunctions.getMemberNames())
{ {
if (it->isPartOfExternalInterface() || it->isConstructor()) cout << " " << name << ":\t";
continue; if (internalFunctions[name].isNull())
size_t entry = m_compiler->functionEntryPoint(_contract, *it); cout << "infinite" << endl;
GasEstimator::GasConsumption gas = GasEstimator::GasConsumption::infinite(); else
if (entry > 0) cout << internalFunctions[name] << endl;
gas = GasEstimator::functionalEstimation(*items, entry, *it);
FunctionType type(*it);
cout << " " << it->name() << "(";
auto paramTypes = type.parameterTypes();
for (auto it = paramTypes.begin(); it != paramTypes.end(); ++it)
cout << (*it)->toString() << (it + 1 == paramTypes.end() ? "" : ",");
cout << "):\t" << gas << endl;
} }
} }
} }