diff --git a/libethereum/ABI.cpp b/libethcore/ABI.cpp similarity index 100% rename from libethereum/ABI.cpp rename to libethcore/ABI.cpp diff --git a/libethereum/ABI.h b/libethcore/ABI.h similarity index 100% rename from libethereum/ABI.h rename to libethcore/ABI.h diff --git a/libethcore/ICAP.cpp b/libethcore/ICAP.cpp index d4c4f9c46..1c38bf921 100644 --- a/libethcore/ICAP.cpp +++ b/libethcore/ICAP.cpp @@ -21,9 +21,11 @@ #include "ICAP.h" #include +#include #include #include #include "Exceptions.h" +#include "ABI.h" using namespace std; using namespace dev; using namespace dev::eth; @@ -113,44 +115,46 @@ std::string ICAP::encoded() const m_asset.find_first_not_of("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890") != string::npos || m_institution.find_first_not_of("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890") != string::npos || m_client.find_first_not_of("qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM1234567890") != string::npos || - m_asset.size() != 3 + m_asset.size() != 3 || + (boost::to_upper_copy(m_asset) != "XET" && boost::to_upper_copy(m_asset) != "ETH") || + m_institution.size() != 4 || + m_client.size() != 9 ) throw InvalidICAP(); - if (boost::to_upper_copy(m_asset) == "XET") - { - if (m_institution.size() != 4 || m_client.size() != 9) - throw InvalidICAP(); - } - else if (boost::to_upper_copy(m_asset) == "ETH") - { - if (m_client.size() != 13) - throw InvalidICAP(); - } - else - throw InvalidICAP(); return iban("XE", m_asset + m_institution + m_client); } else throw InvalidICAP(); } -Address ICAP::lookup(std::function const& _call, Address const& _reg) const +pair ICAP::lookup(std::function const& _call, Address const& _reg) const { - (void)_call; - (void)_reg; + auto toString32 = [](string const& s) + { + string32 ret; + bytesConstRef(&s).populate(bytesRef((byte*)ret.data(), 32)); + return ret; + }; + + auto resolve = [&](string const& s) + { + vector ss; + boost::algorithm::split(ss, s, boost::is_any_of("/")); + Address r = _reg; + for (unsigned i = 0; i < ss.size() - 1; ++i) + r = abiOut
(_call(r, abiIn("subRegistrar(bytes)", toString32(ss[i])))); + return abiOut
(_call(r, abiIn("primary(bytes)", toString32(ss.back())))); + }; if (m_asset == "XET") { - // TODO - throw InterfaceNotSupported("ICAP::lookup(), XET asset"); + Address a = resolve(m_institution); + bytes d = abiIn("deposit(uint64)", fromBase36<8>(m_client)); + return make_pair(a, d); } else if (m_asset == "ETH") - { - // TODO -// return resolve(m_institution + "/" + m_client).primary(); - throw InterfaceNotSupported("ICAP::lookup(), ETH asset"); - } - else - throw InterfaceNotSupported("ICAP::lookup(), non XET asset"); + return make_pair(resolve(m_institution + "/" + m_client), bytes()); + + throw InterfaceNotSupported("ICAP::lookup(), bad asset"); } } diff --git a/libethcore/ICAP.h b/libethcore/ICAP.h index fd5db2f0a..eec729f2e 100644 --- a/libethcore/ICAP.h +++ b/libethcore/ICAP.h @@ -88,10 +88,10 @@ public: /// @returns client name. Only valid when type() == Indirect and asset() == "XET". std::string const& client() const { return m_type == Indirect && m_asset == "XET" ? m_client : EmptyString; } /// @returns target address. Always valid, but requires the Registry address and a function to make calls. - Address address(std::function const& _call, Address const& _reg) const { return m_type == Direct ? direct() : m_type == Indirect ? lookup(_call, _reg) : Address(); } + std::pair address(std::function const& _call, Address const& _reg) const { return m_type == Direct ? make_pair(direct(), bytes()) : m_type == Indirect ? lookup(_call, _reg) : make_pair(Address(), bytes()); } /// @returns target address. Looks up through the given Registry and call function. Only valid when type() == Indirect. - Address lookup(std::function const& _call, Address const& _reg) const; + std::pair lookup(std::function const& _call, Address const& _reg) const; private: Type m_type = Invalid; diff --git a/libethereum/Client.h b/libethereum/Client.h index d4c55ef55..48ca9f821 100644 --- a/libethereum/Client.h +++ b/libethereum/Client.h @@ -35,12 +35,12 @@ #include #include #include +#include #include #include "CanonBlockChain.h" #include "TransactionQueue.h" #include "State.h" #include "CommonNet.h" -#include "ABI.h" #include "Farm.h" #include "ClientBase.h"