From 15afb23e5ad044bd4a5c1a60c7380ab4a574ca41 Mon Sep 17 00:00:00 2001 From: Gav Wood Date: Thu, 25 Dec 2014 11:36:55 +0000 Subject: [PATCH] More integration with SolNameReg --- alethzero/MainWin.cpp | 57 +++++++++++++++++++++++++++++++------------ libethereum/Client.h | 1 + 2 files changed, 43 insertions(+), 15 deletions(-) diff --git a/alethzero/MainWin.cpp b/alethzero/MainWin.cpp index 324868022..dbcd0f493 100644 --- a/alethzero/MainWin.cpp +++ b/alethzero/MainWin.cpp @@ -450,25 +450,23 @@ static Public stringToPublic(QString const& _a) return Public(); } +static Address g_newNameReg; + QString Main::pretty(dev::Address _a) const { static std::map s_memos; if (!s_memos.count(_a)) { - static Address s_newNameReg; - - if (!s_newNameReg) - s_newNameReg = abiOut
(ethereum()->call(c_newConfig, abiIn(1, (u256)1))); + if (!g_newNameReg) + g_newNameReg = abiOut
(ethereum()->call(c_newConfig, abiIn(1, (u256)1))); - if (s_newNameReg) + if (g_newNameReg) { - QString s = QString::fromStdString(toString(abiOut(ethereum()->call(s_newNameReg, abiIn(2, _a))))); + QString s = QString::fromStdString(toString(abiOut(ethereum()->call(g_newNameReg, abiIn(2, _a))))); + s_memos[_a] = s; if (s.size()) - { - s_memos[_a] = s; return s; - } } } else @@ -494,19 +492,47 @@ QString Main::render(dev::Address _a) const return QString::fromStdString(_a.abridged()); } -Address Main::fromString(QString const& _a) const +string32 fromString(std::string const& _s) +{ + string32 ret; + for (unsigned i = 0; i < 32 && i <= _s.size(); ++i) + ret[i] = i < _s.size() ? _s[i] : 0; + return ret; +} + +Address Main::fromString(QString const& _n) const { - if (_a == "(Create Contract)") + if (_n == "(Create Contract)") return Address(); - string sn = _a.toStdString(); + static std::map s_memos; + + if (!s_memos.count(_n)) + { + if (!g_newNameReg) + g_newNameReg = abiOut
(ethereum()->call(c_newConfig, abiIn(1, (u256)1))); + + if (g_newNameReg) + { + Address a = abiOut
(ethereum()->call(g_newNameReg, abiIn(0, ::fromString(_n.toStdString())))); + s_memos[_n] = a; + if (a) + return a; + } + } + else + if (s_memos[_n]) + return s_memos[_n]; + + string sn = _n.toStdString(); if (sn.size() > 32) sn.resize(32); h256 n; memcpy(n.data(), sn.data(), sn.size()); memset(n.data() + sn.size(), 0, 32 - sn.size()); - if (_a.size()) + if (_n.size()) { + if (h160 nameReg = (u160)ethereum()->stateAt(c_config, 0)) if (h256 a = ethereum()->stateAt(nameReg, n)) return right160(a); @@ -514,8 +540,9 @@ Address Main::fromString(QString const& _a) const if (h256 a = ethereum()->stateAt(m_nameReg, n)) return right160(a); } - if (_a.size() == 40) - return Address(fromHex(_a.toStdString())); + + if (_n.size() == 40) + return Address(fromHex(_n.toStdString())); else return Address(); } diff --git a/libethereum/Client.h b/libethereum/Client.h index a68a3ecd8..06c504355 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -111,6 +111,7 @@ template struct ABISerialiser {}; template struct ABISerialiser> { static bytes serialise(FixedHash const& _t) { return _t.asBytes(); } }; template <> struct ABISerialiser { static bytes serialise(u256 const& _t) { return h256(_t).asBytes(); } }; template <> struct ABISerialiser { static bytes serialise(u160 const& _t) { return h160(_t).asBytes(); } }; +template <> struct ABISerialiser { static bytes serialise(string32 const& _t) { return bytesConstRef((byte const*)_t.data(), 32).toBytes(); } }; inline bytes abiInAux() { return {}; } template bytes abiInAux(T const& _t, U const& ... _u)