";
for (auto const& i: _d.accounts)
{
s << ""; eth::AccountDiff const& ad = i.second; s << "
" << ad.lead() << "
" << " " << render(i.first).toStdString() << "";
if (!ad.exist.to())
continue;
if (ad.balance)
{
s << "" << indent << "Balance " << std::dec << formatBalance(ad.balance.to()); s << " " << std::showpos << (((eth::bigint)ad.balance.to()) - ((eth::bigint)ad.balance.from())) << std::noshowpos << ""; } if (ad.nonce) { s << "
" << indent << "Count #" << std::dec << ad.nonce.to(); s << " " << std::showpos << (((eth::bigint)ad.nonce.to()) - ((eth::bigint)ad.nonce.from())) << std::noshowpos << ""; } if (ad.code) { s << "
" << indent << "Code " << std::hex << ad.code.to().size() << " bytes"; if (ad.code.from().size()) s << " (" << ad.code.from().size() << " bytes)"; } for (pair
";
if (!i.second.from())
s << " + ";
else if (!i.second.to())
s << "XXX";
else
s << " * ";
s << "
";
s << prettyU256(i.first).toStdString();
/* if (i.first > u256(1) << 246)
s << (h256)i.first;
else if (i.first > u160(1) << 150)
s << (h160)(u160)i.first;
else
s << std::hex << i.first;
*/
if (!i.second.from())
s << ": " << prettyU256(i.second.to()).toStdString();
else if (!i.second.to())
s << " (" << prettyU256(i.second.from()).toStdString() << ")";
else
s << ": " << prettyU256(i.second.to()).toStdString() << " (" << prettyU256(i.second.from()).toStdString() << ")";
}
}
return s.str();
}
void Main::on_transactionQueue_currentItemChanged()
{
ui->pendingInfo->clear();
eth::ClientGuard g(m_client.get());
stringstream s;
int i = ui->transactionQueue->currentRow();
if (i >= 0)
{
Transaction tx(m_client->postState().pending()[i]);
auto ss = tx.safeSender();
h256 th = sha3(rlpList(ss, tx.nonce));
s << "" << th << "
"; s << "From: " << pretty(ss).toStdString() << " " << ss; if (tx.isCreation()) s << "Creates: " << pretty(right160(th)).toStdString() << " " << right160(th); else s << "
To: " << pretty(tx.receiveAddress).toStdString() << " " << tx.receiveAddress; s << "
Value: " << formatBalance(tx.value) << ""; s << " #" << tx.nonce << ""; s << "
Gas price: " << formatBalance(tx.gasPrice) << ""; s << "
Gas: " << tx.gas << ""; if (tx.isCreation()) { if (tx.data.size()) s << "
Code
" << disassemble(tx.data); } else { if (tx.data.size()) s << eth::memDump(tx.data, 16, true); } s << ""; // s << "Pre: " << fs.rootHash() << "
"; // s << "Post: " << ts.rootHash() << ""; s << renderDiff(m_client->postState().pendingDiff(i)); } ui->pendingInfo->setHtml(QString::fromStdString(s.str())); } void Main::ourAccountsRowsMoved() { QList
" << h << "
"; s << "#" << info.number; s << " " << timestamp << "
"; s << "D/TD: 2^" << log2((double)info.difficulty) << "/2^" << log2((double)details.totalDifficulty) << ""; s << " Children: " << details.children.size() << ""; s << "
Gas used/limit: " << info.gasUsed << "/" << info.gasLimit << ""; s << " Minimum gas price: " << formatBalance(info.minGasPrice) << ""; s << "
Coinbase: " << pretty(info.coinbaseAddress).toHtmlEscaped().toStdString() << " " << info.coinbaseAddress; s << "
Nonce: " << info.nonce << ""; s << "
Parent: " << info.parentHash << ""; s << "
Transactions: " << block[1].itemCount() << " @" << info.transactionsRoot << ""; s << "
Uncles: " << block[2].itemCount() << " @" << info.sha3Uncles << ""; s << "
Pre: " << BlockInfo(m_client->blockChain().block(info.parentHash)).stateRoot << ""; for (auto const& i: block[1]) s << "
" << sha3(i[0].data()).abridged() << ": " << i[1].toHash
Post: " << info.stateRoot << ""; } else { unsigned txi = item->data(Qt::UserRole + 1).toInt(); Transaction tx(block[1][txi][0].data()); auto ss = tx.safeSender(); h256 th = sha3(rlpList(ss, tx.nonce)); s << "
" << th << "
"; s << "" << h << "[" << txi << "]
"; s << "From: " << pretty(ss).toHtmlEscaped().toStdString() << " " << ss; if (tx.isCreation()) s << "
Creates: " << pretty(right160(th)).toHtmlEscaped().toStdString() << " " << right160(th); else s << "
To: " << pretty(tx.receiveAddress).toHtmlEscaped().toStdString() << " " << tx.receiveAddress; s << "
Value: " << formatBalance(tx.value) << ""; s << " #" << tx.nonce << ""; s << "
Gas price: " << formatBalance(tx.gasPrice) << ""; s << "
Gas: " << tx.gas << ""; s << "
V: " << hex << nouppercase << (int)tx.vrs.v << ""; s << "
R: " << hex << nouppercase << tx.vrs.r << ""; s << "
S: " << hex << nouppercase << tx.vrs.s << ""; s << "
Msg: " << tx.sha3(false) << ""; if (tx.isCreation()) { if (tx.data.size()) s << "
Code
" << disassemble(tx.data); } else { if (tx.data.size()) s << eth::memDump(tx.data, 16, true); } auto st = eth::State(m_client->state().db(), m_client->blockChain(), h); eth::State before = st.fromPending(txi); eth::State after = st.fromPending(txi + 1); s << renderDiff(before.diff(after)); ui->debugCurrent->setEnabled(true); ui->debugDumpState->setEnabled(true); ui->debugDumpStatePre->setEnabled(true); } ui->info->appendHtml(QString::fromStdString(s.str())); } } void Main::on_debugCurrent_triggered() { eth::ClientGuard g(m_client.get()); if (auto item = ui->blocks->currentItem()) { auto hba = item->data(Qt::UserRole).toByteArray(); assert(hba.size() == 32); auto h = h256((byte const*)hba.data(), h256::ConstructFromPointer); if (!item->data(Qt::UserRole + 1).isNull()) { eth::State st(m_client->state().db(), m_client->blockChain(), h); unsigned txi = item->data(Qt::UserRole + 1).toInt(); m_executiveState = st.fromPending(txi); m_currentExecution = unique_ptr"; s << "
Body Code
" << disassemble(state().code(h)); ui->contractInfo->appendHtml(QString::fromStdString(s.str())); } catch (eth::InvalidTrie) { ui->contractInfo->appendHtml("Corrupted trie."); } } } void Main::on_idealPeers_valueChanged() { if (m_client->peerServer()) m_client->peerServer()->setIdealPeerCount(ui->idealPeers->value()); } void Main::on_ourAccounts_doubleClicked() { auto hba = ui->ourAccounts->currentItem()->data(Qt::UserRole).toByteArray(); auto h = Address((byte const*)hba.data(), Address::ConstructFromPointer); qApp->clipboard()->setText(QString::fromStdString(toHex(h.asArray()))); } void Main::on_log_doubleClicked() { qApp->clipboard()->setText(ui->log->currentItem()->text()); } void Main::on_accounts_doubleClicked() { auto hba = ui->accounts->currentItem()->data(Qt::UserRole).toByteArray(); auto h = Address((byte const*)hba.data(), Address::ConstructFromPointer); qApp->clipboard()->setText(QString::fromStdString(toHex(h.asArray()))); } void Main::on_contracts_doubleClicked() { auto hba = ui->contracts->currentItem()->data(Qt::UserRole).toByteArray(); auto h = Address((byte const*)hba.data(), Address::ConstructFromPointer); qApp->clipboard()->setText(QString::fromStdString(toHex(h.asArray()))); } void Main::on_destination_currentTextChanged() { if (ui->destination->currentText().size() && ui->destination->currentText() != "(Create Contract)") if (Address a = fromString(ui->destination->currentText())) ui->calculatedName->setText(render(a)); else ui->calculatedName->setText("Unknown Address"); else ui->calculatedName->setText("Create Contract"); on_data_textChanged(); // updateFee(); } void Main::on_data_textChanged() { m_pcWarp.clear(); if (isCreation()) { string src = ui->data->toPlainText().toStdString(); vectorOpt
" + QString::fromStdString(asmcodeopt).toHtmlEscaped() + "
Pre
" + QString::fromStdString(asmcode).toHtmlEscaped() + ""; } QString errs; if (errors.size()) { errs = "
Errors
"; for (auto const& i: errors) errs.append("Code
" + QString::fromStdString(disassemble(m_data)).toHtmlEscaped()); ui->gas->setMinimum((qint64)state().createGas(m_data.size(), 0)); if (!ui->gas->isEnabled()) ui->gas->setValue(m_backupGas); ui->gas->setEnabled(true); } else { m_data.clear(); QString s = ui->data->toPlainText(); while (s.size()) { QRegExp r("(@|\\$)?\"([^\"]*)\"(.*)"); QRegExp h("(@|\\$)?(0x)?(([a-fA-F0-9])+)(.*)"); if (r.exactMatch(s)) { for (auto i: r.cap(2)) m_data.push_back((byte)i.toLatin1()); if (r.cap(1) != "$") for (int i = r.cap(2).size(); i < 32; ++i) m_data.push_back(0); else m_data.push_back(0); s = r.cap(3); } else if (h.exactMatch(s)) { bytes bs = fromHex((((h.cap(3).size() & 1) ? "0" : "") + h.cap(3)).toStdString()); if (h.cap(1) != "$") for (auto i = bs.size(); i < 32; ++i) m_data.push_back(0); for (auto b: bs) m_data.push_back(b); s = h.cap(5); } else s = s.mid(1); } ui->code->setHtml(QString::fromStdString(eth::memDump(m_data, 8, true))); if (m_client->postState().addressHasCode(fromString(ui->destination->currentText()))) { ui->gas->setMinimum((qint64)state().callGas(m_data.size(), 1)); if (!ui->gas->isEnabled()) ui->gas->setValue(m_backupGas); ui->gas->setEnabled(true); } else { if (ui->gas->isEnabled()) m_backupGas = ui->gas->value(); ui->gas->setValue((qint64)state().callGas(m_data.size())); ui->gas->setEnabled(false); } } updateFee(); } void Main::on_killBlockchain_triggered() { writeSettings(); ui->mine->setChecked(false); ui->net->setChecked(false); m_client.reset(); m_client.reset(new Client("AlethZero", Address(), string(), true)); m_client->start(); readSettings(); } bool Main::isCreation() const { return ui->destination->currentText().isEmpty() || ui->destination->currentText() == "(Create Contract)"; } u256 Main::fee() const { return ui->gas->value() * gasPrice(); } u256 Main::value() const { if (ui->valueUnits->currentIndex() == -1) return 0; return ui->value->value() * units()[units().size() - 1 - ui->valueUnits->currentIndex()].first; } u256 Main::gasPrice() const { if (ui->gasPriceUnits->currentIndex() == -1) return 0; return ui->gasPrice->value() * units()[units().size() - 1 - ui->gasPriceUnits->currentIndex()].first; } u256 Main::total() const { return value() + fee(); } void Main::updateFee() { ui->fee->setText(QString("(gas sub-total: %1)").arg(formatBalance(fee()).c_str())); auto totalReq = total(); ui->total->setText(QString("Total: %1").arg(formatBalance(totalReq).c_str())); bool ok = false; for (auto i: m_myKeys) if (state().balance(i.address()) >= totalReq) { ok = true; break; } ui->send->setEnabled(ok); QPalette p = ui->total->palette(); p.setColor(QPalette::WindowText, QColor(ok ? 0x00 : 0x80, 0x00, 0x00)); ui->total->setPalette(p); } void Main::on_net_triggered() { ui->port->setEnabled(!ui->net->isChecked()); ui->clientName->setEnabled(!ui->net->isChecked()); string n = string("AlethZero/v") + eth::EthVersion; if (ui->clientName->text().size()) n += "/" + ui->clientName->text().toStdString(); n += "/" ETH_QUOTED(ETH_BUILD_TYPE) "/" ETH_QUOTED(ETH_BUILD_PLATFORM); m_client->setClientVersion(n); if (ui->net->isChecked()) { m_client->startNetwork(ui->port->value(), string(), 0, NodeMode::Full, ui->idealPeers->value(), std::string(), ui->upnp->isChecked()); if (m_peers.size() && ui->usePast->isChecked()) m_client->peerServer()->restorePeers(bytesConstRef((byte*)m_peers.data(), m_peers.size())); } else m_client->stopNetwork(); } void Main::on_connect_triggered() { if (!ui->net->isChecked()) { ui->net->setChecked(true); on_net_triggered(); } bool ok = false; QString s = QInputDialog::getItem(this, "Connect to a Network Peer", "Enter a peer to which a connection may be made:", m_servers, m_servers.count() ? rand() % m_servers.count() : 0, true, &ok); if (ok && s.contains(":")) { string host = s.section(":", 0, 0).toStdString(); unsigned short port = s.section(":", 1).toInt(); m_client->connect(host, port); } } void Main::on_verbosity_valueChanged() { g_logVerbosity = ui->verbosity->value(); ui->verbosityLabel->setText(QString::number(g_logVerbosity)); } void Main::on_mine_triggered() { if (ui->mine->isChecked()) { m_client->setAddress(m_myKeys.last().address()); m_client->startMining(); } else m_client->stopMining(); } void Main::on_send_clicked() { u256 totalReq = value() + fee(); eth::ClientGuard l(&*m_client); for (auto i: m_myKeys) if (m_client->postState().balance(i.address()) >= totalReq) { debugFinished(); Secret s = i.secret(); if (isCreation()) m_client->transact(s, value(), m_data, ui->gas->value(), gasPrice()); else m_client->transact(s, value(), fromString(ui->destination->currentText()), m_data, ui->gas->value(), gasPrice()); refresh(); return; } statusBar()->showMessage("Couldn't make transaction: no single account contains at least the required amount."); } void Main::on_debug_clicked() { debugFinished(); try { u256 totalReq = value() + fee(); eth::ClientGuard l(&*m_client); for (auto i: m_myKeys) if (m_client->state().balance(i.address()) >= totalReq) { Secret s = i.secret(); m_executiveState = state(); m_currentExecution = unique_ptrOUT-OF-GAS
"); else if (ws.inst == Instruction::RETURN && ws.stack.size() >= 2) { unsigned from = (unsigned)ws.stack.back(); unsigned size = (unsigned)ws.stack[ws.stack.size() - 2]; unsigned o = 0; bytes out(size, 0); for (; o < size && from + o < ws.memory.size(); ++o) out[o] = ws.memory[from + o]; ui->debugMemory->setHtml("RETURN
" + QString::fromStdString(eth::memDump(out, 16, true))); } else if (ws.inst == Instruction::STOP) ui->debugMemory->setHtml("STOP
"); else if (ws.inst == Instruction::SUICIDE && ws.stack.size() >= 1) ui->debugMemory->setHtml("SUICIDE
0x" + QString::fromStdString(toString(right160(ws.stack.back())))); else ui->debugMemory->setHtml("EXCEPTION
"); ostringstream ss; ss << dec << "EXIT | GAS: " << dec << max"; ui->debugStorage->setHtml(QString::fromStdString(s.str())); } } } // extra bits needed to link on VS #ifdef _MSC_VER // include moc file, ofuscated to hide from automoc #include\ "moc_MainWin.cpp" #include\ "moc_MiningView.cpp" #endif