Browse Source

Merge pull request #1603 from yann300/bugFix

Mix - Bug Fix
cl-refactor
Arkadiy Paronyan 10 years ago
parent
commit
a06ceb944b
  1. 14
      mix/ClientModel.cpp
  2. 8
      mix/ClientModel.h
  3. 4
      mix/MixClient.cpp
  4. 2
      mix/MixClient.h
  5. 22
      mix/Web3Server.h
  6. 44
      mix/qml/StateDialog.qml
  7. 15
      mix/qml/StateListModel.qml

14
mix/ClientModel.cpp

@ -134,12 +134,17 @@ void ClientModel::mine()
});
}
QString ClientModel::newAddress()
QString ClientModel::newSecret()
{
KeyPair a = KeyPair::create();
return QString::fromStdString(toHex(a.secret().ref()));
}
QString ClientModel::address(QString const& _secret)
{
return QString::fromStdString(toHex(KeyPair(Secret(_secret.toStdString())).address().ref()));
}
QString ClientModel::encodeAbiString(QString _string)
{
ContractCallDataEncoder encoder;
@ -210,10 +215,10 @@ void ClientModel::setupState(QVariantMap _state)
transactionSequence.push_back(transactionSettings);
}
}
executeSequence(transactionSequence, accounts);
executeSequence(transactionSequence, accounts, Secret(_state.value("miner").toMap().value("secret").toString().toStdString()));
}
void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence, map<Secret, u256> const& _balances)
void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence, map<Secret, u256> const& _balances, Secret const& _miner)
{
if (m_running)
{
@ -225,12 +230,13 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence,
emit runStarted();
emit runStateChanged();
m_client->resetState(_balances, _miner);
m_web3Server->setAccounts(m_client->userAccounts());
//run sequence
m_runFuture = QtConcurrent::run([=]()
{
try
{
m_client->resetState(_balances);
onStateReset();
for (TransactionSettings const& transaction: _sequence)
{

8
mix/ClientModel.h

@ -162,8 +162,10 @@ public slots:
Q_INVOKABLE void debugRecord(unsigned _index);
/// Show the debugger for an empty record
Q_INVOKABLE void emptyRecord();
/// Generate new adress
Q_INVOKABLE QString newAddress();
/// Generate new secret
Q_INVOKABLE QString newSecret();
/// retrieve the address of @arg _secret
Q_INVOKABLE QString address(QString const& _secret);
/// Encode a string to ABI parameter. Returns a hex string
Q_INVOKABLE QString encodeAbiString(QString _string);
@ -207,7 +209,7 @@ private:
RecordLogEntry* lastBlock() const;
QVariantMap contractAddresses() const;
QVariantMap gasCosts() const;
void executeSequence(std::vector<TransactionSettings> const& _sequence, std::map<Secret, u256> const& _balances);
void executeSequence(std::vector<TransactionSettings> const& _sequence, std::map<Secret, u256> const& _balances, Secret const& _miner);
dev::Address deployContract(bytes const& _code, TransactionSettings const& _tr = TransactionSettings());
void callContract(Address const& _contract, bytes const& _data, TransactionSettings const& _tr);
void onNewTransaction();

4
mix/MixClient.cpp

@ -67,7 +67,7 @@ MixClient::~MixClient()
{
}
void MixClient::resetState(std::map<Secret, u256> _accounts)
void MixClient::resetState(std::map<Secret, u256> _accounts, Secret _miner)
{
WriteGuard l(x_state);
Guard fl(x_filtersWatches);
@ -91,7 +91,7 @@ void MixClient::resetState(std::map<Secret, u256> _accounts)
h256 stateRoot = accountState.root();
m_bc.reset();
m_bc.reset(new MixBlockChain(m_dbPath, stateRoot));
m_state = eth::State(m_stateDB, BaseState::PreExisting, genesisState.begin()->first);
m_state = eth::State(m_stateDB, BaseState::PreExisting, KeyPair(_miner).address());
m_state.sync(bc());
m_startState = m_state;
WriteGuard lx(x_executions);

2
mix/MixClient.h

@ -48,7 +48,7 @@ public:
MixClient(std::string const& _dbPath);
virtual ~MixClient();
/// Reset state to the empty state with given balance.
void resetState(std::map<Secret, u256> _accounts);
void resetState(std::map<Secret, u256> _accounts, Secret _miner = Secret());
void mine();
ExecutionResult lastExecution() const;
ExecutionResult execution(unsigned _index) const;

22
mix/Web3Server.h

@ -1,18 +1,18 @@
/*
This file is part of cpp-ethereum.
This file is part of cpp-ethereum.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
cpp-ethereum is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with cpp-ethereum. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file Web3Server.h
* @author Arkadiy Paronyan arkadiy@ethdev.com

44
mix/qml/StateDialog.qml

@ -14,7 +14,7 @@ Dialog {
modality: Qt.ApplicationModal
width: 630
height: 480
height: 500
title: qsTr("Edit State")
visible: false
@ -45,16 +45,22 @@ Dialog {
accountsModel.clear();
stateAccounts = [];
var miner = 0;
for (var k = 0; k < item.accounts.length; k++)
{
accountsModel.append(item.accounts[k]);
stateAccounts.push(item.accounts[k]);
if (item.accounts[k].name === item.miner.name)
miner = k;
}
visible = true;
isDefault = setDefault;
titleField.focus = true;
defaultCheckBox.enabled = !isDefault;
comboMiner.model = stateAccounts;
comboMiner.currentIndex = miner;
forceActiveFocus();
}
@ -75,6 +81,14 @@ Dialog {
}
item.transactions = stateTransactions;
item.accounts = stateAccounts;
for (var k = 0; k < stateAccounts.length; k++)
{
if (stateAccounts[k].name === comboMiner.currentText)
{
item.miner = stateAccounts[k];
break;
}
}
return item;
}
contentItem: Rectangle {
@ -159,7 +173,7 @@ Dialog {
TableViewColumn {
role: "name"
title: qsTr("Name")
width: 150
width: 230
delegate: Item {
RowLayout
{
@ -190,7 +204,12 @@ Dialog {
anchors.verticalCenter: parent.verticalCenter
onTextChanged: {
if (styleData.row > -1)
stateAccounts[styleData.row].name = text;
{
stateAccounts[styleData.row].name = text
var index = comboMiner.currentIndex;
comboMiner.model = stateAccounts;
comboMiner.currentIndex = index;
}
}
text: {
return styleData.value
@ -226,6 +245,25 @@ Dialog {
Layout.fillWidth: true
}
RowLayout
{
Layout.fillWidth: true
DefaultLabel {
Layout.preferredWidth: 85
text: qsTr("Miner")
}
ComboBox {
id: comboMiner
textRole: "name"
Layout.fillWidth: true
}
}
CommonSeparator
{
Layout.fillWidth: true
}
RowLayout
{
Layout.fillWidth: true

15
mix/qml/StateListModel.qml

@ -21,7 +21,8 @@ Item {
return {
title: s.title,
transactions: s.transactions.map(fromPlainTransactionItem),
accounts: s.accounts.map(fromPlainAccountItem)
accounts: s.accounts.map(fromPlainAccountItem),
miner: s.miner
};
}
@ -37,6 +38,7 @@ Item {
function fromPlainTransactionItem(t) {
if (!t.sender)
t.sender = defaultAccount; //support for old project
var r = {
contractId: t.contractId,
functionId: t.functionId,
@ -59,7 +61,8 @@ Item {
return {
title: s.title,
transactions: s.transactions.map(toPlainTransactionItem),
accounts: s.accounts.map(toPlainAccountItem)
accounts: s.accounts.map(toPlainAccountItem),
miner: s.miner
};
}
@ -81,7 +84,7 @@ Item {
balance: {
value: t.balance.value,
unit: t.balance.unit
}
},
};
}
@ -95,6 +98,7 @@ Item {
gasAuto: t.gasAuto,
gasPrice: { value: t.gasPrice.value, unit: t.gasPrice.unit },
stdContract: t.stdContract,
sender: t.sender,
parameters: {}
};
for (var key in t.parameters)
@ -176,8 +180,9 @@ Item {
function newAccount(_balance, _unit, _secret)
{
if (!_secret)
_secret = clientModel.newAddress();
var name = qsTr("Account") + "-" + _secret.substring(0, 4);
_secret = clientModel.newSecret();
var address = clientModel.address(_secret);
var name = qsTr("Account") + "-" + address.substring(0, 4);
return { name: name, secret: _secret, balance: QEtherHelper.createEther(_balance, _unit) };
}

Loading…
Cancel
Save