Browse Source

- bug fixes

- support for old projects
cl-refactor
yann300 10 years ago
parent
commit
a96ed0da18
  1. 19
      mix/ClientModel.cpp
  2. 2
      mix/qml/Block.qml
  3. 45
      mix/qml/BlockChain.qml
  4. 34
      mix/qml/StateListModel.qml
  5. 2
      mix/qml/TransactionDialog.qml

19
mix/ClientModel.cpp

@ -431,12 +431,16 @@ std::pair<QString, int> ClientModel::resolvePair(QString const& _contractId)
QStringList values = ret.first.remove("<").remove(">").split(" - ");
ret = std::make_pair(values[0], values[1].toUInt());
}
if (_contractId.startsWith("0x"))
ret = std::make_pair(_contractId, -2);
return ret;
}
QString ClientModel::resolveToken(std::pair<QString, int> const& _value)
{
if (m_contractAddresses.size() > 0)
if (_value.second == -2)
return _value.first;
else if (m_contractAddresses.size() > 0)
return QString::fromStdString("0x" + dev::toHex(m_contractAddresses[_value].ref()));
else
return _value.first;
@ -737,6 +741,8 @@ void ClientModel::onNewTransaction()
CompiledContract const& compilerRes = m_codeModel->contract(contractAddressIter->second);
const QContractDefinition* def = compilerRes.contract();
contract = def->name();
if (creation)
function = contract;
if (abi)
{
QFunctionDefinition const* funcDef = def->getFunction(functionHash);
@ -818,6 +824,17 @@ void ClientModel::onNewTransaction()
label = contract + "." + function + "()";
else
label = contract;
if (!creation)
for (auto const& ctr: m_contractAddresses)
{
if (ctr.second == tr.address)
{
contract = "<" + ctr.first.first + " - " + QString::number(ctr.first.second) + ">";
break;
}
}
RecordLogEntry* log = new RecordLogEntry(recordIndex, transactionIndex, contract, function, value, address, returned, tr.isCall(), RecordLogEntry::RecordType::Transaction,
gasUsed, sender, label, inputParameters, logs);
QQmlEngine::setObjectOwnership(log, QQmlEngine::JavaScriptOwnership);

2
mix/qml/Block.qml

@ -297,7 +297,7 @@ ColumnLayout
anchors.fill: parent
onClicked:
{
if (transactions.get(index).recordIndex)
if (transactions.get(index).recordIndex !== undefined)
{
debugTrRequested = [ blockIndex, index ]
clientModel.debugRecord(transactions.get(index).recordIndex);

45
mix/qml/BlockChain.qml

@ -230,7 +230,9 @@ ColumnLayout {
if (ensureNotFuturetime.running)
return;
reBuildNeeded.stop()
console.log("model block length " + model.blocks.length)
var retBlocks = [];
var bAdded = 0;
for (var j = 0; j < model.blocks.length; j++)
{
var b = model.blocks[j];
@ -243,13 +245,30 @@ ColumnLayout {
for (var k = 0; k < model.blocks[j].transactions.length; k++)
{
if (blockModel.get(j).transactions.get(k).saveStatus)
block.transactions.push(model.blocks[j].transactions[k]);
{
var tr = model.blocks[j].transactions[k]
tr.saveStatus = true
block.transactions.push(tr);
}
}
if (block.transactions.length > 0)
{
bAdded++
block.number = bAdded
block.status = "mined"
retBlocks.push(block)
}
}
if (retBlocks.length === 0)
retBlocks.push(projectModel.stateListModel.createEmptyBlock())
else
{
var last = retBlocks[retBlocks.length - 1]
last.number = -1
last.status = "pending"
}
model.blocks = retBlocks
blockModel.clear()
@ -289,8 +308,14 @@ ColumnLayout {
onClicked:
{
var lastBlock = model.blocks[model.blocks.length - 1];
console.log(lastBlock.status + "!!!")
if (lastBlock.status === "mined")
model.blocks.push(projectModel.stateListModel.createEmptyBlock());
{
var newblock = projectModel.stateListModel.createEmptyBlock()
blockModel.appendBlock(newblock)
model.blocks.push(newblock);
}
var item = TransactionHelper.defaultTransaction()
transactionDialog.stateAccounts = model.accounts
transactionDialog.execute = true
@ -352,6 +377,7 @@ ColumnLayout {
target: clientModel
onNewBlock:
{
console.log("new Block!!")
if (!clientModel.running)
{
var lastBlock = model.blocks[model.blocks.length - 1]
@ -370,15 +396,12 @@ ColumnLayout {
{
var blockIndex = parseInt(_r.transactionIndex.split(":")[0]) - 1
var trIndex = parseInt(_r.transactionIndex.split(":")[1])
console.log("kkkk" + blockIndex)
console.log(trIndex)
if (blockIndex <= model.blocks.length - 1)
{
var item = model.blocks[blockIndex]
if (trIndex <= item.transactions.length - 1)
{
var tr = item.transactions[trIndex]
console.log(JSON.stringify(_r))
tr.returned = _r.returned
tr.recordIndex = _r.recordIndex
tr.logs = _r.logs
@ -408,6 +431,7 @@ ColumnLayout {
itemTr.sender = _r.sender
itemTr.recordIndex = _r.recordIndex
itemTr.logs = _r.logs
console.log(JSON.stringify(itemTr))
model.blocks[model.blocks.length - 1].transactions.push(itemTr)
blockModel.appendTransaction(itemTr)
}
@ -421,7 +445,6 @@ ColumnLayout {
text: qsTr("New Account")
onClicked: {
model.accounts.push(projectModel.stateListModel.newAccount("1000000", QEther.Ether))
chainChanged()
}
Layout.preferredWidth: 100
Layout.preferredHeight: 30
@ -438,11 +461,15 @@ ColumnLayout {
var item = transactionDialog.getItem()
if (execute)
{
console.log("cc " + model.blocks.length)
var lastBlock = model.blocks[model.blocks.length - 1];
console.log("mined?" + lastBlock.status)
if (lastBlock.status === "mined")
model.blocks.push(projectModel.stateListModel.createEmptyBlock());
model.blocks[model.blocks.length - 1].transactions.push(item)
blockModel.appendTransaction(item)
{
var newBlock = projectModel.stateListModel.createEmptyBlock();
model.blocks.push(newBlock);
blockModel.appendBlock(newBlock)
}
if (!clientModel.running)
clientModel.executeTr(item)
}

34
mix/qml/StateListModel.qml

@ -16,19 +16,32 @@ Item {
property string defaultAccount: "cb73d9408c4720e230387d956eb0f829d8a4dd2c1055f96257167e14e7169074" //support for old project
function fromPlainStateItem(s) {
console.log("ggg " + s)
if (!s.accounts)
s.accounts = [stateListModel.newAccount("1000000", QEther.Ether, defaultAccount)]; //support for old project
if (!s.contracts)
s.contracts = [];
return {
title: s.title,
transactions: s.transactions.filter(function(t) { return !t.stdContract; }).map(fromPlainTransactionItem), //support old projects by filtering std contracts
blocks: s.blocks.map(fromPlainBlockItem),
accounts: s.accounts.map(fromPlainAccountItem),
contracts: s.contracts.map(fromPlainAccountItem),
miner: s.miner
};
var ret = {};
ret.title = s.title;
ret.transactions = s.transactions.filter(function(t) { return !t.stdContract; }).map(fromPlainTransactionItem); //support old projects by filtering std contracts
if (s.blocks)
ret.blocks = s.blocks.map(fromPlainBlockItem);
ret.accounts = s.accounts.map(fromPlainAccountItem);
ret.contracts = s.contracts.map(fromPlainAccountItem);
ret.miner = s.miner;
// support old projects
if (!ret.blocks)
{
ret.blocks = [{
hash: "",
number: -1,
transactions: [],
status: "pending"
}]
for (var j in ret.transactions)
ret.blocks[0].transactions.push(fromPlainTransactionItem(toPlainTransactionItem(ret.transactions[j])))
}
}
function fromPlainAccountItem(t)
@ -64,6 +77,9 @@ Item {
saveStatus: t.saveStatus
};
if (r.saveStatus === undefined)
r.saveStatus = true
if (r.isFunctionCall === undefined)
r.isFunctionCall = true;

2
mix/qml/TransactionDialog.qml

@ -64,7 +64,7 @@ Dialog {
for (var c in contracts) {
contractsModel.append({ cid: c, text: contracts[c].contract.name });
if (contracts[c].contract.name === contractId)
contractIndex = contractsModel.count - 1;
contractIndex = contractsModel.count - 1;
}
if (contractIndex == -1 && contractsModel.count > 0)

Loading…
Cancel
Save