Browse Source

misc changes

cl-refactor
yann300 10 years ago
parent
commit
bce5486554
  1. 51
      mix/ClientModel.cpp
  2. 2
      mix/ClientModel.h
  3. 54
      mix/qml/BlockChain.qml
  4. 9
      mix/qml/ScenarioButton.qml
  5. 88
      mix/qml/ScenarioLoader.qml

51
mix/ClientModel.cpp

@ -211,6 +211,7 @@ QVariantList ClientModel::gasCosts() const
void ClientModel::setupScenario(QVariantMap _scenario)
{
WriteGuard(x_queueTransactions);
m_queueTransactions.clear();
m_running = true;
@ -220,7 +221,6 @@ void ClientModel::setupScenario(QVariantMap _scenario)
m_accounts.clear();
std::vector<KeyPair> userAccounts;
for (auto const& b: stateAccounts)
{
QVariantMap account = b.toMap();
@ -239,23 +239,29 @@ void ClientModel::setupScenario(QVariantMap _scenario)
m_accounts[address] = Account(qvariant_cast<QEther*>(account.value("balance"))->toU256Wei(), Account::NormalCreation);
}
m_ethAccounts->setAccounts(userAccounts);
bool trToExecute = false;
for (auto const& b: blocks)
{
QVariantList transactions = b.toMap().value("transactions").toList();
m_queueTransactions.push_back(transactions);
trToExecute = transactions.size() > 0;
}
m_client->resetState(m_accounts, Secret(m_currentScenario.value("miner").toMap().value("secret").toString().toStdString()));
connect(this, &ClientModel::newBlock, this, &ClientModel::processNextBlock, Qt::QueuedConnection);
connect(this, &ClientModel::runFailed, this, &ClientModel::stopExecution, Qt::QueuedConnection);
connect(this, &ClientModel::runStateChanged, this, &ClientModel::finalizeBlock, Qt::QueuedConnection);
processNextBlock();
if (m_queueTransactions.count() > 0 && trToExecute)
{
connect(this, &ClientModel::newBlock, this, &ClientModel::processNextTransactions, Qt::QueuedConnection);
connect(this, &ClientModel::runFailed, this, &ClientModel::stopExecution, Qt::QueuedConnection);
connect(this, &ClientModel::runStateChanged, this, &ClientModel::finalizeBlock, Qt::QueuedConnection);
processNextTransactions();
}
else
m_running = false;
}
void ClientModel::stopExecution()
{
disconnect(this, &ClientModel::newBlock, this, &ClientModel::processNextBlock);
disconnect(this, &ClientModel::newBlock, this, &ClientModel::processNextTransactions);
disconnect(this, &ClientModel::runStateChanged, this, &ClientModel::finalizeBlock);
disconnect(this, &ClientModel::runFailed, this, &ClientModel::stopExecution);
m_running = false;
@ -263,26 +269,19 @@ void ClientModel::stopExecution()
void ClientModel::finalizeBlock()
{
m_queueTransactions.pop_front();// pop last execution group. The last block is never mined (pending block)
if (m_queueTransactions.size() > 0)
mine();
else
{
disconnect(this, &ClientModel::newBlock, this, &ClientModel::processNextBlock);
disconnect(this, &ClientModel::runStateChanged, this, &ClientModel::finalizeBlock);
disconnect(this, &ClientModel::runFailed, this, &ClientModel::stopExecution);
m_running = false;
stopExecution();
emit runComplete();
}
}
void ClientModel::processNextBlock()
{
processNextTransactions();
}
void ClientModel::processNextTransactions()
{
WriteGuard(x_queueTransactions);
vector<TransactionSettings> transactionSequence;
for (auto const& t: m_queueTransactions.front())
{
@ -311,7 +310,6 @@ void ClientModel::processNextTransactions()
transactionSequence.push_back(transactionSettings);
}
m_queueTransactions.pop_front();
executeSequence(transactionSequence);
}
@ -322,18 +320,13 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence)
qWarning() << "Waiting for current execution to complete";
m_runFuture.waitForFinished();
}
emit runStarted();
//emit runStateChanged();
//run sequence
m_runFuture = QtConcurrent::run([=]()
{
try
{
vector<Address> deployedContracts;
//onStateReset();
m_gasCosts.clear();
for (TransactionSettings const& transaction: _sequence)
{
@ -397,8 +390,8 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence)
}
m_gasCosts.append(m_client->lastExecution().gasUsed);
onNewTransaction();
emit runComplete();
}
emit runComplete();
}
catch(boost::exception const&)
{
@ -416,10 +409,16 @@ void ClientModel::executeSequence(vector<TransactionSettings> const& _sequence)
void ClientModel::executeTr(QVariantMap _tr)
{
WriteGuard(x_queueTransactions);
QVariantList trs;
trs.push_back(_tr);
m_queueTransactions.push_back(trs);
processNextTransactions();
if (!m_running)
{
m_running = true;
connect(this, &ClientModel::runFailed, this, &ClientModel::stopExecution, Qt::QueuedConnection);
processNextTransactions();
}
}

2
mix/ClientModel.h

@ -256,7 +256,6 @@ private:
std::pair<QString, int> resolvePair(QString const& _contractId);
QVariant formatStorageValue(SolidityType const& _type, std::unordered_map<dev::u256, dev::u256> const& _storage, unsigned _offset, dev::u256 const& _slot);
void processNextTransactions();
void processNextBlock();
void finalizeBlock();
void stopExecution();
@ -276,6 +275,7 @@ private:
CodeModel* m_codeModel = nullptr;
QList<QVariantList> m_queueTransactions;
QVariantMap m_currentScenario;
mutable boost::shared_mutex x_queueTransactions;
};
}

54
mix/qml/BlockChain.qml

@ -104,7 +104,6 @@ ColumnLayout {
{
Layout.preferredHeight: 500
Layout.preferredWidth: parent.width
//height: 500
border.color: "#cccccc"
border.width: 2
color: "white"
@ -209,9 +208,10 @@ ColumnLayout {
Layout.preferredWidth: parent.width
RowLayout
{
width: parent.width
width: 4 * 100
anchors.top: parent.top
anchors.topMargin: 10
spacing: 0
ScenarioButton {
id: rebuild
text: qsTr("Rebuild")
@ -219,22 +219,40 @@ ColumnLayout {
{
if (ensureNotFuturetime.running)
return;
var retBlocks = [];
for (var j = 0; j < model.blocks.length; j++)
{
var b = model.blocks[j];
var block = {
hash: b.hash,
number: b.number,
transactions: [],
status: b.status
}
for (var k = 0; k < model.blocks[j].transactions.length; k++)
{
if (!blockModel.get(j).transactions.get(k).saveStatus)
if (blockModel.get(j).transactions.get(k).saveStatus)
{
model.blocks[j].transactions.splice(k, 1)
blockModel.removeTransaction(j, k)
if (model.blocks[j].transactions.length === 0)
{
model.blocks.splice(j, 1);
blockModel.removeBlock(j);
}
block.transactions.push(model.blocks[j].transactions[k]);
}
}
if (block.transactions.length > 0)
{
retBlocks.push(block)
}
}
if (retBlocks.length === 0)
{
retBlocks.push(projectModel.stateListModel.createEmptyBlock())
}
model.blocks = retBlocks
blockModel.clear()
for (var j = 0; j < model.blocks.length; j++)
{
blockModel.append(model.blocks[j])
}
ensureNotFuturetime.start()
clientModel.setupScenario(model);
}
@ -280,14 +298,21 @@ ColumnLayout {
return
if (clientModel.mining || clientModel.running)
return
var lastBlock = model.blocks[model.blocks.length - 1]
if (lastBlock.status === "pending")
console.log("lllll");
if (model.blocks.length > 0)
{
ensureNotFuturetime.start()
clientModel.mine()
var lastBlock = model.blocks[model.blocks.length - 1]
if (lastBlock.status === "pending")
{
ensureNotFuturetime.start()
clientModel.mine()
}
else
addNewBlock()
}
else
addNewBlock()
}
function addNewBlock()
@ -355,6 +380,7 @@ ColumnLayout {
itemTr.isFunctionCall = itemTr.functionId !== ""
itemTr.returned = _r.returned
itemTr.value = QEtherHelper.createEther(_r.value, QEther.Wei)
console.log("sender " + _r.sender)
itemTr.sender = _r.sender
itemTr.recordIndex = _r.recordIndex
itemTr.logs = _r.logs

9
mix/qml/ScenarioButton.qml

@ -19,9 +19,12 @@ Rectangle {
Image {
id: debugImage
anchors {
centerIn: parent
bottomMargin: debugImg.pressed ? 0 : 1;
topMargin: debugImg.pressed ? 1 : 0;
left: parent.left
right: parent.right
top: parent.top
bottom: parent.bottom
bottomMargin: debugImg.pressed ? 0 : 2;
topMargin: debugImg.pressed ? 2 : 0;
}
source: sourceImg
fillMode: Image.PreserveAspectFit

88
mix/qml/ScenarioLoader.qml

@ -14,7 +14,7 @@ RowLayout
signal saved(variant scenario)
signal duplicated(variant scenario)
signal loaded(variant scenario)
spacing: 0
function init()
{
scenarioList.load()
@ -38,51 +38,57 @@ RowLayout
}
}
ScenarioButton {
id: restoreScenario
Layout.preferredWidth: 100
Row
{
Layout.preferredWidth: 100 * 3
Layout.preferredHeight: 30
buttonShortcut: ""
sourceImg: "qrc:/qml/img/restoreIcon@2x.png"
onClicked: {
restore()
}
text: qsTr("Restore")
function restore()
{
var state = projectModel.stateListModel.reloadStateFromFromProject(scenarioList.currentIndex)
restored(state)
loaded(state)
spacing: 0
ScenarioButton {
id: restoreScenario
width: 100
height: 30
buttonShortcut: ""
sourceImg: "qrc:/qml/img/restoreIcon@2x.png"
onClicked: {
restore()
}
text: qsTr("Restore")
function restore()
{
var state = projectModel.stateListModel.reloadStateFromFromProject(scenarioList.currentIndex)
restored(state)
loaded(state)
}
}
}
ScenarioButton {
id: saveScenario
text: qsTr("Save")
onClicked: {
projectModel.saveProjectFile()
saved(state)
ScenarioButton {
id: saveScenario
text: qsTr("Save")
onClicked: {
projectModel.saveProjectFile()
saved(state)
}
width: 100
height: 30
buttonShortcut: ""
sourceImg: "qrc:/qml/img/saveIcon@2x.png"
}
Layout.preferredWidth: 100
Layout.preferredHeight: 30
buttonShortcut: ""
sourceImg: "qrc:/qml/img/saveIcon@2x.png"
}
ScenarioButton
{
id: duplicateScenario
text: qsTr("Duplicate")
onClicked: {
var state = JSON.parse(JSON.stringify(projectModel.stateListModel.getState(scenarioList.currentIndex)))
state.title = qsTr("Copy of ") + state.title;
projectModel.stateListModel.appendState(state)
projectModel.stateListModel.save()
duplicated(state)
ScenarioButton
{
id: duplicateScenario
text: qsTr("Duplicate")
onClicked: {
var state = JSON.parse(JSON.stringify(projectModel.stateListModel.getState(scenarioList.currentIndex)))
state.title = qsTr("Copy of ") + state.title;
projectModel.stateListModel.appendState(state)
projectModel.stateListModel.save()
duplicated(state)
}
width: 100
height: 30
buttonShortcut: ""
sourceImg: "qrc:/qml/img/duplicateIcon@2x.png"
}
Layout.preferredWidth: 100
Layout.preferredHeight: 30
buttonShortcut: ""
sourceImg: "qrc:/qml/img/duplicateIcon@2x.png"
}
}

Loading…
Cancel
Save