Browse Source

cosmetic changes

cl-refactor
yann300 10 years ago
parent
commit
ec62858be1
  1. 2
      mix/ClientModel.cpp
  2. 5
      mix/ClientModel.h
  3. 26
      mix/MachineStates.h
  4. 55
      mix/MixClient.cpp
  5. 3
      mix/MixClient.h
  6. 5
      mix/qml/BlockChain.qml
  7. 3
      mix/qml/QAddressView.qml
  8. 5
      mix/qml/StateListModel.qml

2
mix/ClientModel.cpp

@ -438,7 +438,7 @@ std::pair<QString, int> ClientModel::resolvePair(QString const& _contractId)
QString ClientModel::resolveToken(std::pair<QString, int> const& _value) QString ClientModel::resolveToken(std::pair<QString, int> const& _value)
{ {
if (_value.second == -2) if (_value.second == -2) //-2: first contains a real address
return _value.first; return _value.first;
else if (m_contractAddresses.size() > 0) else if (m_contractAddresses.size() > 0)
return QString::fromStdString("0x" + dev::toHex(m_contractAddresses[_value].ref())); return QString::fromStdString("0x" + dev::toHex(m_contractAddresses[_value].ref()));

5
mix/ClientModel.h

@ -185,13 +185,10 @@ public:
Q_INVOKABLE QString toHex(QString const& _int); Q_INVOKABLE QString toHex(QString const& _int);
public slots: public slots:
/// Setup state, run transaction sequence, show debugger for the last transaction
/// @param _state JS object with state configuration
//void setupState(QVariantMap _state);
/// Setup scenario, run transaction sequence, show debugger for the last transaction /// Setup scenario, run transaction sequence, show debugger for the last transaction
/// @param _state JS object with state configuration /// @param _state JS object with state configuration
void setupScenario(QVariantMap _scenario); void setupScenario(QVariantMap _scenario);
/// Execute the given @param _tr on the curret state /// Execute the given @param _tr on the current state
void executeTr(QVariantMap _tr); void executeTr(QVariantMap _tr);
/// Show the debugger for a specified record /// Show the debugger for a specified record
Q_INVOKABLE void debugRecord(unsigned _index); Q_INVOKABLE void debugRecord(unsigned _index);

26
mix/MachineStates.h

@ -37,11 +37,11 @@ namespace dev
namespace mix namespace mix
{ {
/** /**
* @brief Store information about a machine state. * @brief Store information about a machine state.
*/ */
struct MachineState struct MachineState
{ {
uint64_t steps; uint64_t steps;
dev::u256 curPC; dev::u256 curPC;
dev::eth::Instruction inst; dev::eth::Instruction inst;
@ -54,22 +54,22 @@ namespace mix
std::vector<unsigned> levels; std::vector<unsigned> levels;
unsigned codeIndex; unsigned codeIndex;
unsigned dataIndex; unsigned dataIndex;
}; };
/** /**
* @brief Executed conract code info * @brief Executed conract code info
*/ */
struct MachineCode struct MachineCode
{ {
dev::Address address; dev::Address address;
bytes code; bytes code;
}; };
/** /**
* @brief Store information about a machine states. * @brief Store information about a machine states.
*/ */
struct ExecutionResult struct ExecutionResult
{ {
ExecutionResult(): transactionIndex(std::numeric_limits<unsigned>::max()) {} ExecutionResult(): transactionIndex(std::numeric_limits<unsigned>::max()) {}
std::vector<MachineState> machineStates; std::vector<MachineState> machineStates;
@ -88,8 +88,8 @@ namespace mix
bool isCall() const { return transactionIndex == std::numeric_limits<unsigned>::max(); } bool isCall() const { return transactionIndex == std::numeric_limits<unsigned>::max(); }
bool isConstructor() const { return !isCall() && !address; } bool isConstructor() const { return !isCall() && !address; }
}; };
using ExecutionResults = std::vector<ExecutionResult>; using ExecutionResults = std::vector<ExecutionResult>;
} }
} }

55
mix/MixClient.cpp

@ -73,25 +73,11 @@ MixClient::MixClient(std::string const& _dbPath):
resetState(std::unordered_map<Address, Account>()); resetState(std::unordered_map<Address, Account>());
} }
MixClient::~MixClient()
{
}
LocalisedLogEntries MixClient::logs()
{
return m_watches.at(0).changes;
}
void MixClient::resetState(std::unordered_map<Address, Account> const& _accounts, Secret const& _miner) void MixClient::resetState(std::unordered_map<Address, Account> const& _accounts, Secret const& _miner)
{ {
WriteGuard l(x_state); WriteGuard l(x_state);
Guard fl(x_filtersWatches); Guard fl(x_filtersWatches);
m_filters.clear();
m_watches.clear();
//LogFilter filter;
//m_filters.insert(std::make_pair(filter.sha3(), filter));
//m_watches.insert(std::make_pair(0, ClientWatch(filter.sha3(), Reaping::Automatic)));
m_stateDB = OverlayDB(); m_stateDB = OverlayDB();
SecureTrieDB<Address, MemoryDB> accountState(&m_stateDB); SecureTrieDB<Address, MemoryDB> accountState(&m_stateDB);
@ -261,39 +247,15 @@ void MixClient::executeTransaction(Transaction const& _t, State& _state, bool _c
if (t.isCreation() && _state.code(d.contractAddress).empty()) if (t.isCreation() && _state.code(d.contractAddress).empty())
BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Not enough gas for contract deployment")); BOOST_THROW_EXCEPTION(OutOfGas() << errinfo_comment("Not enough gas for contract deployment"));
d.gasUsed = er.gasUsed + er.gasRefunded + er.gasForDeposit + c_callStipend; d.gasUsed = er.gasUsed + er.gasRefunded + er.gasForDeposit + c_callStipend;
// collect watches
h256Set changed;
Guard l(x_filtersWatches);
LocalisedLogEntries logs; LocalisedLogEntries logs;
//for (unsigned i = 0; i < _state.pending().size(); ++i)
//{
TransactionReceipt const& tr = _state.receipt(_state.pending().size() - 1); TransactionReceipt const& tr = _state.receipt(_state.pending().size() - 1);
auto trHash = _state.pending().at(_state.pending().size() - 1).sha3(); auto trHash = _state.pending().at(_state.pending().size() - 1).sha3();
//for (std::pair<h256 const, eth::InstalledFilter>& installedFilter: m_filters) LogEntries le = tr.log();
//{
LogEntries le = tr.log(); // installedFilter.second.filter.matches(tr);
if (le.size()) if (le.size())
for (unsigned j = 0; j < le.size(); ++j) for (unsigned j = 0; j < le.size(); ++j)
logs.insert(logs.begin(), LocalisedLogEntry(le[j], bc().number() + 1, trHash)); logs.insert(logs.begin(), LocalisedLogEntry(le[j], bc().number() + 1, trHash));
//}
//}
/*if ((unsigned)i.second.filter.latest() > bc().number())
{
// acceptable number.
auto m = i.second.filter.matches(_state.receipt(_state.pending().size() - 1));
if (m.size())
{
// filter catches them
for (LogEntry const& l: m)
i.second.changes.push_back(LocalisedLogEntry(l, bc().number() + 1));
changed.insert(i.first);
}
}*/
changed.insert(dev::eth::PendingChangedFilter);
d.logs = logs; d.logs = logs;
//noteChanged(changed);
} }
WriteGuard l(x_executions); WriteGuard l(x_executions);
m_executions.emplace_back(std::move(d)); m_executions.emplace_back(std::move(d));
@ -308,7 +270,6 @@ void MixClient::mine()
m_state.sync(bc()); m_state.sync(bc());
m_startState = m_state; m_startState = m_state;
h256Set changed { dev::eth::PendingChangedFilter, dev::eth::ChainChangedFilter }; h256Set changed { dev::eth::PendingChangedFilter, dev::eth::ChainChangedFilter };
//noteChanged(changed);
} }
ExecutionResult MixClient::lastExecution() const ExecutionResult MixClient::lastExecution() const
@ -395,20 +356,6 @@ dev::eth::ExecutionResult MixClient::create(Address const& _from, u256 _value, b
return lastExecution().result; return lastExecution().result;
} }
/*void MixClient::noteChanged(h256Set const& _filters)
{
for (auto& i: m_watches)
if (_filters.count(i.second.id))
{
if (m_filters.count(i.second.id))
i.second.changes += m_filters.at(i.second.id).changes;
else
i.second.changes.push_back(LocalisedLogEntry(SpecialLogEntry, 0));
}
for (auto& i: m_filters)
i.second.changes.clear();
}*/
eth::BlockInfo MixClient::blockInfo() const eth::BlockInfo MixClient::blockInfo() const
{ {
ReadGuard l(x_state); ReadGuard l(x_state);

3
mix/MixClient.h

@ -77,8 +77,6 @@ public:
using Interface::blockInfo; // to remove warning about hiding virtual function using Interface::blockInfo; // to remove warning about hiding virtual function
eth::BlockInfo blockInfo() const; eth::BlockInfo blockInfo() const;
dev::eth::LocalisedLogEntries logs();
protected: protected:
/// ClientBase methods /// ClientBase methods
using ClientBase::asOf; using ClientBase::asOf;
@ -91,7 +89,6 @@ protected:
private: private:
void executeTransaction(dev::eth::Transaction const& _t, eth::State& _state, bool _call, bool _gasAuto, dev::Secret const& _secret = dev::Secret()); void executeTransaction(dev::eth::Transaction const& _t, eth::State& _state, bool _call, bool _gasAuto, dev::Secret const& _secret = dev::Secret());
//void noteChanged(h256Set const& _filters);
dev::eth::Transaction replaceGas(dev::eth::Transaction const& _t, dev::u256 const& _gas, dev::Secret const& _secret = dev::Secret()); dev::eth::Transaction replaceGas(dev::eth::Transaction const& _t, dev::u256 const& _gas, dev::Secret const& _secret = dev::Secret());
eth::State m_state; eth::State m_state;

5
mix/qml/BlockChain.qml

@ -307,7 +307,6 @@ ColumnLayout {
onClicked: onClicked:
{ {
var lastBlock = model.blocks[model.blocks.length - 1]; var lastBlock = model.blocks[model.blocks.length - 1];
console.log(lastBlock.status + "!!!")
if (lastBlock.status === "mined") if (lastBlock.status === "mined")
{ {
var newblock = projectModel.stateListModel.createEmptyBlock() var newblock = projectModel.stateListModel.createEmptyBlock()
@ -376,7 +375,6 @@ ColumnLayout {
target: clientModel target: clientModel
onNewBlock: onNewBlock:
{ {
console.log("new Block!!")
if (!clientModel.running) if (!clientModel.running)
{ {
var lastBlock = model.blocks[model.blocks.length - 1] var lastBlock = model.blocks[model.blocks.length - 1]
@ -430,7 +428,6 @@ ColumnLayout {
itemTr.sender = _r.sender itemTr.sender = _r.sender
itemTr.recordIndex = _r.recordIndex itemTr.recordIndex = _r.recordIndex
itemTr.logs = _r.logs itemTr.logs = _r.logs
console.log(JSON.stringify(itemTr))
model.blocks[model.blocks.length - 1].transactions.push(itemTr) model.blocks[model.blocks.length - 1].transactions.push(itemTr)
blockModel.appendTransaction(itemTr) blockModel.appendTransaction(itemTr)
} }
@ -460,9 +457,7 @@ ColumnLayout {
var item = transactionDialog.getItem() var item = transactionDialog.getItem()
if (execute) if (execute)
{ {
console.log("cc " + model.blocks.length)
var lastBlock = model.blocks[model.blocks.length - 1]; var lastBlock = model.blocks[model.blocks.length - 1];
console.log("mined?" + lastBlock.status)
if (lastBlock.status === "mined") if (lastBlock.status === "mined")
{ {
var newBlock = projectModel.stateListModel.createEmptyBlock(); var newBlock = projectModel.stateListModel.createEmptyBlock();

3
mix/qml/QAddressView.qml

@ -39,9 +39,6 @@ Item
{ {
accountRef.clear(); accountRef.clear();
accountRef.append({"itemid": " - "}); accountRef.append({"itemid": " - "});
console.log(blockIndex)
console.log(transactionIndex)
if (subType === "contract" || subType === "address") if (subType === "contract" || subType === "address")
{ {
var trCr = 0; var trCr = 0;

5
mix/qml/StateListModel.qml

@ -42,6 +42,7 @@ Item {
for (var j in ret.transactions) for (var j in ret.transactions)
ret.blocks[0].transactions.push(fromPlainTransactionItem(toPlainTransactionItem(ret.transactions[j]))) ret.blocks[0].transactions.push(fromPlainTransactionItem(toPlainTransactionItem(ret.transactions[j])))
} }
return ret;
} }
function fromPlainAccountItem(t) function fromPlainAccountItem(t)
@ -377,8 +378,8 @@ Item {
function runState(index) { function runState(index) {
var item = stateList[index]; var item = stateList[index];
//clientModel.setupState(item); clientModel.setupScenario(item);
//stateRun(index); stateRun(index);
} }
function deleteState(index) { function deleteState(index) {

Loading…
Cancel
Save