Skip to content

Commit

Permalink
- allows write a ctor with contract type param and select the contract
Browse files Browse the repository at this point in the history
to use as a param in the transaction dialog.
  • Loading branch information
yann300 committed Apr 21, 2015
1 parent d8226e7 commit d22a0f0
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 3 deletions.
13 changes: 13 additions & 0 deletions ClientModel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
{
try
{
map<Address, QString> deployedContracts;
onStateReset();
for (TransactionSettings const& transaction: _sequence)
{
Expand All @@ -248,6 +249,7 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
TransactionSettings stdTransaction = transaction;
stdTransaction.gasAuto = true;
Address address = deployContract(stdContractCode, stdTransaction);
deployedContracts.insert(make_pair(address, transaction.contractId));
m_stdContractAddresses[stdTransaction.contractId] = address;
m_stdContractNames[address] = stdTransaction.contractId;
}
Expand Down Expand Up @@ -280,6 +282,16 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
{
QSolidityType const* type = p->type();
QVariant value = transaction.parameterValues.value(p->name());
if (type->type().type == SolidityType::Type::Address && value.toString().startsWith("<"))
{
for (auto it = deployedContracts.begin(); it != deployedContracts.end(); ++it)
{
if (value.toString().remove("<").remove(">") == it->second)
{
value = QVariant(QString::fromStdString(toHex(it->first.ref())));
}
}
}
encoder.encode(value, type->type());
}

Expand All @@ -288,6 +300,7 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
bytes param = encoder.encodedData();
contractCode.insert(contractCode.end(), param.begin(), param.end());
Address newAddress = deployContract(contractCode, transaction);
deployedContracts.insert(make_pair(newAddress, transaction.contractId));
auto contractAddressIter = m_contractAddresses.find(transaction.contractId);
if (contractAddressIter == m_contractAddresses.end() || newAddress != contractAddressIter->second)
{
Expand Down
87 changes: 87 additions & 0 deletions qml/QAddressView.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import QtQuick 2.0
import QtQuick.Controls 1.3

Item
{
property alias value: textinput.text
property alias contractCreationTr: ctrModel
id: editRoot
height: 30
width: 200

SourceSansProBold
{
id: boldFont
}

function init()
{
if (value.indexOf("<") === 0)
{
for (var k = 0; k < ctrModel.count; k++)
{
if ("<" + ctrModel.get(k).functionId + ">" === value)
{
trCombobox.currentIndex = k;
return;
}
}
trCombobox.currentIndex = 0;
value = "";
}
}

Rectangle {
anchors.fill: parent
radius: 4
TextInput {
id: textinput
text: value
width: parent.width
height: 30
wrapMode: Text.WrapAnywhere
clip: true
font.family: boldFont.name
MouseArea {
id: mouseArea
anchors.fill: parent
hoverEnabled: true
onClicked: textinput.forceActiveFocus()
}
onTextChanged:
{
if (trCombobox.selected)
{
trCombobox.currentIndex = 0;
trCombobox.selected = false;
}
}
}
}

ListModel
{
id: ctrModel
}

ComboBox
{
property bool selected: false
id: trCombobox
model: ctrModel
textRole: "functionId"
anchors.verticalCenter: parent.verticalCenter
anchors.left: textinput.parent.right
onCurrentIndexChanged: {
if (currentText === "")
return;
else if (currentText !== " - ")
{
textinput.text = "<" + currentText + ">";
trCombobox.selected = true;
}
else if (textinput.text.indexOf("<") === 0)
textinput.text = "";
}
}
}
24 changes: 21 additions & 3 deletions qml/StructView.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ Column
id: root
property alias members: repeater.model //js array
property var value: ({})
property int transactionIndex
Layout.fillWidth: true

spacing: 10
Repeater
{
id: repeater
visible: model.length > 0
Layout.fillWidth: true

RowLayout
{
id: row
Expand Down Expand Up @@ -51,10 +53,12 @@ Column
return Qt.createComponent("qrc:/qml/QBoolTypeView.qml");
else if (t === QSolidityType.Bytes)
return Qt.createComponent("qrc:/qml/QStringTypeView.qml");
else if (t === QSolidityType.Hash || t === QSolidityType.Address)
else if (t === QSolidityType.Hash)
return Qt.createComponent("qrc:/qml/QHashTypeView.qml");
else if (t === QSolidityType.Struct)
return Qt.createComponent("qrc:/qml/StructView.qml");
else if (t === QSolidityType.Address)
return Qt.createComponent("qrc:/qml/QAddressView.qml");
else
return undefined;
}
Expand All @@ -63,7 +67,21 @@ Column
var ptype = members[index].type;
var pname = members[index].name;
var vals = value;
if (ptype.category === QSolidityType.Struct && !item.members)
if (ptype.category === QSolidityType.Address)
{
item.contractCreationTr.append({"functionId": " - "});
for (var k = 0; k < transactionsModel.count; k++)
{
if (k >= transactionIndex)
break;
var tr = transactionsModel.get(k);
if (tr.functionId === tr.contractId && modelData.type.name === qsTr("contract") + " " + tr.contractId)
item.contractCreationTr.append(tr);
}
item.value = getValue();
item.init();
}
else if (ptype.category === QSolidityType.Struct && !item.members)
{
item.value = getValue();
item.members = ptype.members;
Expand Down
2 changes: 2 additions & 0 deletions qml/TransactionDialog.qml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ Dialog {
rowGasPrice.visible = !useTransactionDefaultValue;

transactionIndex = index;
typeLoader.transactionIndex = index;

gasValueEdit.gasValue = item.gas;
gasAutoCheck.checked = item.gasAuto ? true : false;
gasPriceField.value = item.gasPrice;
Expand Down
1 change: 1 addition & 0 deletions res.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -67,5 +67,6 @@
<file>qml/img/stop_button2x.png</file>
<file>qml/img/warningicon.png</file>
<file>qml/img/[email protected]</file>
<file>qml/QAddressView.qml</file>
</qresource>
</RCC>

0 comments on commit d22a0f0

Please sign in to comment.