From ab75743fcf8490457c676eaea1daf5d40e056b79 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 7 Aug 2014 17:32:07 +0100 Subject: [PATCH] DnsReg integration. --- alethzero/MainWin.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++- alethzero/MainWin.h | 2 ++ stdserv.js | 3 ++- 3 files changed, 48 insertions(+), 2 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index fab200b89..efa026b66 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -459,6 +459,40 @@ Address Main::fromString(QString const& _a) const return Address(); } +QString Main::lookup(QString const& _a) const +{ + if (!_a.endsWith(".eth")) + return _a; + + string sn = _a.mid(0, _a.size() - 4).toStdString(); + if (sn.size() > 32) + sn = sha3(sn, false); + h256 n; + memcpy(n.data(), sn.data(), sn.size()); + +/* string sn2 = _a.toStdString(); + if (sn2.size() > 32) + sn2 = sha3(sn2, false); + h256 n2; + memcpy(n2.data(), sn2.data(), sn2.size()); +*/ + + h256 ret; + if (h160 dnsReg = (u160)m_client->stateAt(c_config, 4, 0)) + ret = m_client->stateAt(dnsReg, n); +/* if (!ret) + if (h160 nameReg = (u160)m_client->stateAt(c_config, 0, 0)) + ret = m_client->stateAt(nameReg, n2); +*/ + if (ret && !((u256)ret >> 32)) + return QString("%1.%2.%3.%4").arg((int)ret[28]).arg((int)ret[29]).arg((int)ret[30]).arg((int)ret[31]); + // TODO: support IPv6. + else if (ret) + return fromRaw(ret); + else + return _a; +} + void Main::on_about_triggered() { QMessageBox::about(this, "About AlethZero PoC-" + QString(eth::EthVersion).section('.', 1, 1), QString("AlethZero/v") + eth::EthVersion + "/" ETH_QUOTED(ETH_BUILD_TYPE) "/" ETH_QUOTED(ETH_BUILD_PLATFORM) "\n" ETH_QUOTED(ETH_COMMIT_HASH) + (ETH_CLEAN_REPO ? "\nCLEAN" : "\n+ LOCAL CHANGES") + "\n\nBy Gav Wood, 2014.\nBased on a design by Vitalik Buterin.\n\nThanks to the various contributors including: Alex Leverington, Tim Hughes, caktux, Eric Lombrozo, Marko Simovic."); @@ -575,7 +609,16 @@ void Main::on_exportKey_triggered() void Main::on_urlEdit_returnPressed() { - ui->webView->setUrl(ui->urlEdit->text()); + QString s = ui->urlEdit->text(); + QRegExp r("([a-z]+://)?([^/]*)(.*)"); + if (r.exactMatch(s)) + if (r.cap(2).isEmpty()) + s = (r.cap(1).isEmpty() ? "file://" : r.cap(1)) + r.cap(3); + else + s = (r.cap(1).isEmpty() ? "http://" : r.cap(1)) + lookup(r.cap(2)) + r.cap(3); + else{} + qDebug() << s; + ui->webView->setUrl(s); } void Main::on_nameReg_textChanged() diff --git a/alethzero/MainWin.h b/alethzero/MainWin.h index ac3d442d6..825e05456 100644 --- a/alethzero/MainWin.h +++ b/alethzero/MainWin.h @@ -146,6 +146,8 @@ private: QString pretty(eth::Address _a) const; QString prettyU256(eth::u256 _n) const; + QString lookup(QString const& _n) const; + void populateDebugger(eth::bytesConstRef r); void initDebugger(); void updateDebugger(); diff --git a/stdserv.js b/stdserv.js index 705320eb0..b9006ae76 100644 --- a/stdserv.js +++ b/stdserv.js @@ -240,10 +240,11 @@ var exchangeCode = eth.lll(" (when (= $0 'delete) { (set 'offer $32) (set 'want $64) + (set 'rate $96) (set 'list (sha3pair @offer @want)) (set 'last @list) (set 'item @@ @last) - (for {} (&& @item (!= (idof @item) (caller))) { (set 'last @item) (inc item) } {}) + (for {} (&& @item (!= (idof @item) (caller)) (!= (rateof @item) @rate)) { (set 'last @item) (inc item) } {}) (when @item { (set 'xoffer (fpmul (wantof @item) (rateof @item))) [[ @last ]] @@ @item