Browse Source

- allows write a ctor with contract type param and select the contract

to use as a param in the transaction dialog.
cl-refactor
yann300 10 years ago
parent
commit
b1bcf9c40d
  1. 13
      mix/ClientModel.cpp
  2. 87
      mix/qml/QAddressView.qml
  3. 24
      mix/qml/StructView.qml
  4. 2
      mix/qml/TransactionDialog.qml
  5. 1
      mix/res.qrc

13
mix/ClientModel.cpp

@ -237,6 +237,7 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
{ {
try try
{ {
map<Address, QString> deployedContracts;
onStateReset(); onStateReset();
for (TransactionSettings const& transaction: _sequence) for (TransactionSettings const& transaction: _sequence)
{ {
@ -248,6 +249,7 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
TransactionSettings stdTransaction = transaction; TransactionSettings stdTransaction = transaction;
stdTransaction.gasAuto = true; stdTransaction.gasAuto = true;
Address address = deployContract(stdContractCode, stdTransaction); Address address = deployContract(stdContractCode, stdTransaction);
deployedContracts.insert(make_pair(address, transaction.contractId));
m_stdContractAddresses[stdTransaction.contractId] = address; m_stdContractAddresses[stdTransaction.contractId] = address;
m_stdContractNames[address] = stdTransaction.contractId; m_stdContractNames[address] = stdTransaction.contractId;
} }
@ -280,6 +282,16 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
{ {
QSolidityType const* type = p->type(); QSolidityType const* type = p->type();
QVariant value = transaction.parameterValues.value(p->name()); 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()); encoder.encode(value, type->type());
} }
@ -288,6 +300,7 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
bytes param = encoder.encodedData(); bytes param = encoder.encodedData();
contractCode.insert(contractCode.end(), param.begin(), param.end()); contractCode.insert(contractCode.end(), param.begin(), param.end());
Address newAddress = deployContract(contractCode, transaction); Address newAddress = deployContract(contractCode, transaction);
deployedContracts.insert(make_pair(newAddress, transaction.contractId));
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)
{ {

87
mix/qml/QAddressView.qml

@ -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
mix/qml/StructView.qml

@ -8,13 +8,15 @@ Column
id: root id: root
property alias members: repeater.model //js array property alias members: repeater.model //js array
property var value: ({}) property var value: ({})
property int transactionIndex
Layout.fillWidth: true Layout.fillWidth: true
spacing: 10
Repeater Repeater
{ {
id: repeater id: repeater
visible: model.length > 0 visible: model.length > 0
Layout.fillWidth: true Layout.fillWidth: true
RowLayout RowLayout
{ {
id: row id: row
@ -51,10 +53,12 @@ Column
return Qt.createComponent("qrc:/qml/QBoolTypeView.qml"); return Qt.createComponent("qrc:/qml/QBoolTypeView.qml");
else if (t === QSolidityType.Bytes) else if (t === QSolidityType.Bytes)
return Qt.createComponent("qrc:/qml/QStringTypeView.qml"); 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"); return Qt.createComponent("qrc:/qml/QHashTypeView.qml");
else if (t === QSolidityType.Struct) else if (t === QSolidityType.Struct)
return Qt.createComponent("qrc:/qml/StructView.qml"); return Qt.createComponent("qrc:/qml/StructView.qml");
else if (t === QSolidityType.Address)
return Qt.createComponent("qrc:/qml/QAddressView.qml");
else else
return undefined; return undefined;
} }
@ -63,7 +67,21 @@ Column
var ptype = members[index].type; var ptype = members[index].type;
var pname = members[index].name; var pname = members[index].name;
var vals = value; 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.value = getValue();
item.members = ptype.members; item.members = ptype.members;

2
mix/qml/TransactionDialog.qml

@ -39,6 +39,8 @@ Dialog {
rowGasPrice.visible = !useTransactionDefaultValue; rowGasPrice.visible = !useTransactionDefaultValue;
transactionIndex = index; transactionIndex = index;
typeLoader.transactionIndex = index;
gasValueEdit.gasValue = item.gas; gasValueEdit.gasValue = item.gas;
gasAutoCheck.checked = item.gasAuto ? true : false; gasAutoCheck.checked = item.gasAuto ? true : false;
gasPriceField.value = item.gasPrice; gasPriceField.value = item.gasPrice;

1
mix/res.qrc

@ -67,5 +67,6 @@
<file>qml/img/stop_button2x.png</file> <file>qml/img/stop_button2x.png</file>
<file>qml/img/warningicon.png</file> <file>qml/img/warningicon.png</file>
<file>qml/img/warningicon@2x.png</file> <file>qml/img/warningicon@2x.png</file>
<file>qml/QAddressView.qml</file>
</qresource> </qresource>
</RCC> </RCC>

Loading…
Cancel
Save