Browse Source

bug fix

cl-refactor
yann300 10 years ago
parent
commit
7802a9e00c
  1. 36
      mix/ClientModel.cpp
  2. 11
      mix/ClientModel.h
  3. 5
      mix/qml/QAddressView.qml
  4. 4
      mix/qml/StateDialog.qml
  5. 14
      mix/qml/StateListModel.qml
  6. 92
      mix/qml/TransactionDialog.qml
  7. 3
      mix/qml/js/TransactionHelper.js

36
mix/ClientModel.cpp

@ -256,9 +256,9 @@ void ClientModel::setupState(QVariantMap _state)
u256 gasPrice = (qvariant_cast<QEther*>(transaction.value("gasPrice")))->toU256Wei(); u256 gasPrice = (qvariant_cast<QEther*>(transaction.value("gasPrice")))->toU256Wei();
QString sender = transaction.value("sender").toString(); QString sender = transaction.value("sender").toString();
bool isStdContract = transaction.value("stdContract").toBool(); bool isStdContract = transaction.value("stdContract").toBool();
bool isContractCall; bool isContractCreation;
if (!transaction.value("isContractCall").isNull()) if (!transaction.value("isContractCreation").isNull())
isContractCall = transaction.value("isContractCall").toBool(); isContractCreation = transaction.value("isContractCreation").toBool();
if (isStdContract) if (isStdContract)
{ {
if (contractId.isEmpty()) //TODO: This is to support old project files, remove later if (contractId.isEmpty()) //TODO: This is to support old project files, remove later
@ -274,7 +274,7 @@ void ClientModel::setupState(QVariantMap _state)
{ {
if (contractId.isEmpty() && m_codeModel->hasContract()) //TODO: This is to support old project files, remove later if (contractId.isEmpty() && m_codeModel->hasContract()) //TODO: This is to support old project files, remove later
contractId = m_codeModel->contracts().keys()[0]; contractId = m_codeModel->contracts().keys()[0];
TransactionSettings transactionSettings(contractId, functionId, value, gas, gasAuto, gasPrice, Secret(sender.toStdString()), isContractCall); TransactionSettings transactionSettings(contractId, functionId, value, gas, gasAuto, gasPrice, Secret(sender.toStdString()), isContractCreation);
transactionSettings.parameterValues = transaction.value("parameters").toMap(); transactionSettings.parameterValues = transaction.value("parameters").toMap();
if (contractId == functionId || functionId == "Constructor") if (contractId == functionId || functionId == "Constructor")
@ -310,9 +310,10 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
m_gasCosts.clear(); m_gasCosts.clear();
for (TransactionSettings const& transaction: _sequence) for (TransactionSettings const& transaction: _sequence)
{ {
if (!transaction.isContractCall) QString contractName = resolveContractName(transaction.contractId);
QString address = resolveToken(transaction.contractId, deployedContracts);
if (transaction.functionId == "(transfert)")
{ {
QString address = resolveToken(transaction.contractId, deployedContracts);
callAddress(Address(address.toStdString()), bytes(), transaction); callAddress(Address(address.toStdString()), bytes(), transaction);
onNewTransaction(); onNewTransaction();
continue; continue;
@ -332,7 +333,7 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
else else
{ {
//encode data //encode data
CompiledContract const& compilerRes = m_codeModel->contract(transaction.contractId); CompiledContract const& compilerRes = m_codeModel->contract(contractName);
QFunctionDefinition const* f = nullptr; QFunctionDefinition const* f = nullptr;
bytes contractCode = compilerRes.bytes(); bytes contractCode = compilerRes.bytes();
shared_ptr<QContractDefinition> contractDef = compilerRes.sharedContract(); shared_ptr<QContractDefinition> contractDef = compilerRes.sharedContract();
@ -363,7 +364,7 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
encoder.encode(value, type->type()); encoder.encode(value, type->type());
} }
if (transaction.functionId.isEmpty() || transaction.functionId == transaction.contractId) if (transaction.functionId.isEmpty() || transaction.functionId == contractName)
{ {
bytes param = encoder.encodedData(); bytes param = encoder.encodedData();
contractCode.insert(contractCode.end(), param.begin(), param.end()); contractCode.insert(contractCode.end(), param.begin(), param.end());
@ -372,8 +373,9 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
auto contractAddressIter = m_contractAddresses.find(transaction.contractId); auto contractAddressIter = m_contractAddresses.find(transaction.contractId);
if (contractAddressIter == m_contractAddresses.end() || newAddress != contractAddressIter->second) if (contractAddressIter == m_contractAddresses.end() || newAddress != contractAddressIter->second)
{ {
m_contractAddresses[transaction.contractId] = newAddress; QString contractToken = "<" + transaction.contractId + " - " + QString::number(deployedContracts.size() - 1) + ">";
m_contractNames[newAddress] = transaction.contractId; m_contractAddresses[contractToken] = newAddress;
m_contractNames[newAddress] = contractToken;
contractAddressesChanged(); contractAddressesChanged();
} }
gasCostsChanged(); gasCostsChanged();
@ -388,7 +390,7 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
emit runStateChanged(); emit runStateChanged();
return; return;
} }
callAddress(contractAddressIter->second, encoder.encodedData(), transaction); callAddress(Address(address.toStdString()), encoder.encodedData(), transaction);
} }
m_gasCosts.append(m_client->lastExecution().gasUsed); m_gasCosts.append(m_client->lastExecution().gasUsed);
} }
@ -423,6 +425,14 @@ QString ClientModel::resolveToken(QString const& _value, vector<Address> const&
return ret; return ret;
} }
QString ClientModel::resolveContractName(QString const& _value)
{
QString ret = _value;
if (_value.startsWith("<") && _value.endsWith(">"))
ret = ret.remove("<").remove(">").split(" - ").first();
return ret;
}
void ClientModel::showDebugger() void ClientModel::showDebugger()
{ {
ExecutionResult last = m_client->lastExecution(); ExecutionResult last = m_client->lastExecution();
@ -446,7 +456,7 @@ void ClientModel::showDebuggerForTransaction(ExecutionResult const& _t)
//try to resolve contract for source level debugging //try to resolve contract for source level debugging
auto nameIter = m_contractNames.find(code.address); auto nameIter = m_contractNames.find(code.address);
CompiledContract const* compilerRes = nullptr; CompiledContract const* compilerRes = nullptr;
if (nameIter != m_contractNames.end() && (compilerRes = m_codeModel->tryGetContract(nameIter->second))) //returned object is guaranteed to live till the end of event handler in main thread if (nameIter != m_contractNames.end() && (compilerRes = m_codeModel->tryGetContract(resolveContractName(nameIter->second)))) //returned object is guaranteed to live till the end of event handler in main thread
{ {
eth::AssemblyItems assemblyItems = !_t.isConstructor() ? compilerRes->assemblyItems() : compilerRes->constructorAssemblyItems(); eth::AssemblyItems assemblyItems = !_t.isConstructor() ? compilerRes->assemblyItems() : compilerRes->constructorAssemblyItems();
codes.back()->setDocument(compilerRes->documentId()); codes.back()->setDocument(compilerRes->documentId());
@ -707,7 +717,7 @@ void ClientModel::onNewTransaction()
auto contractAddressIter = m_contractNames.find(contractAddress); auto contractAddressIter = m_contractNames.find(contractAddress);
if (contractAddressIter != m_contractNames.end()) if (contractAddressIter != m_contractNames.end())
{ {
CompiledContract const& compilerRes = m_codeModel->contract(contractAddressIter->second); CompiledContract const& compilerRes = m_codeModel->contract(resolveContractName(contractAddressIter->second));
const QContractDefinition* def = compilerRes.contract(); const QContractDefinition* def = compilerRes.contract();
contract = def->name(); contract = def->name();
if (abi) if (abi)

11
mix/ClientModel.h

@ -53,10 +53,10 @@ struct SolidityType;
struct TransactionSettings struct TransactionSettings
{ {
TransactionSettings() {} TransactionSettings() {}
TransactionSettings(QString const& _contractId, QString const& _functionId, u256 _value, u256 _gas, bool _gasAuto, u256 _gasPrice, Secret _sender, int _isContractCall): TransactionSettings(QString const& _contractId, QString const& _functionId, u256 _value, u256 _gas, bool _gasAuto, u256 _gasPrice, Secret _sender, int _isContractCreation):
contractId(_contractId), functionId(_functionId), value(_value), gas(_gas), gasAuto(_gasAuto), gasPrice(_gasPrice), sender(_sender), isContractCall(_isContractCall) {} contractId(_contractId), functionId(_functionId), value(_value), gas(_gas), gasAuto(_gasAuto), gasPrice(_gasPrice), sender(_sender), isContractCreation(_isContractCreation) {}
TransactionSettings(QString const& _stdContractName, QString const& _stdContractUrl): TransactionSettings(QString const& _stdContractName, QString const& _stdContractUrl):
contractId(_stdContractName), gasAuto(true), stdContractUrl(_stdContractUrl), isContractCall(true) {} contractId(_stdContractName), gasAuto(true), stdContractUrl(_stdContractUrl), isContractCreation(true) {}
/// Contract name /// Contract name
QString contractId; QString contractId;
@ -76,8 +76,8 @@ struct TransactionSettings
QString stdContractUrl; QString stdContractUrl;
/// Sender /// Sender
Secret sender; Secret sender;
/// Is a call to a contract /// Tr deploys a contract
bool isContractCall; bool isContractCreation;
}; };
@ -231,6 +231,7 @@ private:
QVariant formatValue(SolidityType const& _type, dev::u256 const& _value); QVariant formatValue(SolidityType const& _type, dev::u256 const& _value);
QVariant formatStorageValue(SolidityType const& _type, std::map<dev::u256, dev::u256> const& _storage, unsigned _offset, dev::u256 const& _slot); QVariant formatStorageValue(SolidityType const& _type, std::map<dev::u256, dev::u256> const& _storage, unsigned _offset, dev::u256 const& _slot);
QString resolveToken(QString const& _value, std::vector<Address> const& _contracts); QString resolveToken(QString const& _value, std::vector<Address> const& _contracts);
QString resolveContractName(QString const& _value);
std::atomic<bool> m_running; std::atomic<bool> m_running;
std::atomic<bool> m_mining; std::atomic<bool> m_mining;

5
mix/qml/QAddressView.qml

@ -30,6 +30,11 @@ Item
return accountRef.get(trCombobox.currentIndex).type; return accountRef.get(trCombobox.currentIndex).type;
} }
function current()
{
return accountRef.get(trCombobox.currentIndex);
}
function load() function load()
{ {
accountRef.clear(); accountRef.clear();

4
mix/qml/StateDialog.qml

@ -436,7 +436,7 @@ Dialog {
model: transactionsModel model: transactionsModel
headerVisible: false headerVisible: false
TableViewColumn { TableViewColumn {
role: "name" role: "label"
title: qsTr("Name") title: qsTr("Name")
width: 150 width: 150
delegate: Item { delegate: Item {
@ -476,7 +476,7 @@ Dialog {
text: { text: {
if (styleData.row >= 0) if (styleData.row >= 0)
return transactionsModel.get( return transactionsModel.get(
styleData.row).functionId styleData.row).label
else else
return "" return ""
} }

14
mix/qml/StateListModel.qml

@ -57,10 +57,15 @@ Item {
stdContract: t.stdContract ? true : false, stdContract: t.stdContract ? true : false,
parameters: {}, parameters: {},
sender: t.sender, sender: t.sender,
isContractCall: t.isContractCall isContractCreation: t.isContractCreation,
label: t.label
}; };
if (r.isContractCall === undefined)
r.isContractCall = true; //support for old project if (!r.label)
r.label = r.contractId + " " + r.functionId;
if (r.isContractCreation === undefined)
r.isContractCreation = true; //support for old project
for (var key in t.parameters) for (var key in t.parameters)
r.parameters[key] = t.parameters[key]; r.parameters[key] = t.parameters[key];
@ -115,7 +120,8 @@ Item {
stdContract: t.stdContract, stdContract: t.stdContract,
sender: t.sender, sender: t.sender,
parameters: {}, parameters: {},
isContractCall: t.isContractCall isContractCreation: t.isContractCreation,
label: t.label
}; };
for (var key in t.parameters) for (var key in t.parameters)
r.parameters[key] = t.parameters[key]; r.parameters[key] = t.parameters[key];

92
mix/qml/TransactionDialog.qml

@ -66,34 +66,46 @@ Dialog {
contractIndex = 0; //@todo suggest unused contract contractIndex = 0; //@todo suggest unused contract
contractComboBox.currentIndex = contractIndex; contractComboBox.currentIndex = contractIndex;
loadFunctions(contractComboBox.currentValue()); recipients.accounts = senderComboBox.model;
recipients.subType = "address";
recipients.load();
recipients.init();
recipients.select(contractId);
if (item.isContractCreation)
loadFunctions(contractComboBox.currentValue());
else
loadFunctions(contractFromToken(recipients.currentValue()))
selectFunction(functionId); selectFunction(functionId);
trType.checked = item.isContractCreation
trType.init();
paramsModel = []; paramsModel = [];
if (functionId !== contractComboBox.currentValue()) if (item.isContractCreation)
loadCtorParameters();
else
loadParameters(); loadParameters();
else {
var contract = codeModel.contracts[contractId];
if (contract) {
var params = contract.contract.constructor.parameters;
for (var p = 0; p < params.length; p++)
loadParameter(params[p]);
}
}
initTypeLoader();
trType.checked = item.isContractCall
trType.init();
recipients.accounts = senderComboBox.model;
recipients.subType = "address";
recipients.load();
recipients.init();
recipients.select(contractId);
visible = true; visible = true;
valueField.focus = true; valueField.focus = true;
} }
function loadCtorParameters(contractId)
{
paramsModel = [];
console.log(contractId);
var contract = codeModel.contracts[contractId];
if (contract) {
var params = contract.contract.constructor.parameters;
for (var p = 0; p < params.length; p++)
loadParameter(params[p]);
}
initTypeLoader();
}
function loadFunctions(contractId) function loadFunctions(contractId)
{ {
functionsModel.clear(); functionsModel.clear();
@ -104,9 +116,7 @@ Dialog {
functionsModel.append({ text: functions[f].name }); functionsModel.append({ text: functions[f].name });
} }
} }
//append constructor functionsModel.append({ text: "(transfert)" });
functionsModel.append({ text: contractId });
} }
function selectContract(contractName) function selectContract(contractName)
@ -144,7 +154,7 @@ Dialog {
function loadParameters() { function loadParameters() {
paramsModel = [] paramsModel = []
if (functionComboBox.currentIndex >= 0 && functionComboBox.currentIndex < functionsModel.count) { if (functionComboBox.currentIndex >= 0 && functionComboBox.currentIndex < functionsModel.count) {
var contract = codeModel.contracts[contractComboBox.currentValue()]; var contract = codeModel.contracts[contractFromToken(recipients.currentValue())];
if (contract) { if (contract) {
var func = contract.contract.functions[functionComboBox.currentIndex]; var func = contract.contract.functions[functionComboBox.currentIndex];
if (func) { if (func) {
@ -201,17 +211,32 @@ Dialog {
item.functionId = transactionDialog.functionId; item.functionId = transactionDialog.functionId;
} }
item.isContractCall = trType.checked; item.isContractCreation = trType.checked;
if (!item.isContractCall) if (!item.isContractCreation)
{ {
item.functionId = recipients.currentText;
item.contractId = recipients.currentText; item.contractId = recipients.currentText;
item.label = item.contractId + " " + item.functionId;
if (recipients.current().type === "address")
item.functionId = "(transfert)";
}
else
{
item.functionId = item.contractId;
item.label = qsTr("Deploy") + " " + item.contractId;
} }
item.sender = senderComboBox.model[senderComboBox.currentIndex].secret; item.sender = senderComboBox.model[senderComboBox.currentIndex].secret;
item.parameters = paramValues; item.parameters = paramValues;
return item; return item;
} }
function contractFromToken(token)
{
if (token.indexOf('<') === 0)
return token.replace("<", "").replace(">", "").split(" - ")[0];
return token;
}
contentItem: Rectangle { contentItem: Rectangle {
color: transactionDialogStyle.generic.backgroundColor color: transactionDialogStyle.generic.backgroundColor
ColumnLayout { ColumnLayout {
@ -267,14 +292,17 @@ Dialog {
function init() function init()
{ {
rowFunction.visible = checked; rowFunction.visible = !checked;
rowContract.visible = checked; rowContract.visible = checked;
rowRecipient.visible = !checked; rowRecipient.visible = !checked;
paramLabel.visible = checked; paramLabel.visible = checked;
paramScroll.visible = checked; paramScroll.visible = checked;
functionComboBox.enabled = !checked;
if (checked)
loadCtorParameters(contractComboBox.currentValue());
} }
text: qsTr("is contract call") text: qsTr("is contract creation")
checked: true checked: true
} }
} }
@ -292,6 +320,14 @@ Dialog {
QAddressView QAddressView
{ {
id: recipients id: recipients
onIndexChanged:
{
rowFunction.visible = current().type === "contract";
paramLabel.visible = current().type === "contract";
paramScroll.visible = current().type === "contract";
if (!rowIsContract.checked)
loadFunctions(contractFromToken(recipients.currentValue()))
}
} }
} }
@ -317,7 +353,7 @@ Dialog {
id: contractsModel id: contractsModel
} }
onCurrentIndexChanged: { onCurrentIndexChanged: {
loadFunctions(currentValue()); loadCtorParameters(currentValue());
} }
} }
} }

3
mix/qml/js/TransactionHelper.js

@ -10,7 +10,8 @@ function defaultTransaction()
gasPrice: createEther("100000", QEther.Wei), gasPrice: createEther("100000", QEther.Wei),
parameters: {}, parameters: {},
stdContract: false, stdContract: false,
isContractCall: true isContractCreation: true,
label: ""
}; };
} }

Loading…
Cancel
Save