|
|
@ -21,9 +21,11 @@ |
|
|
|
|
|
|
|
#include "ICAP.h" |
|
|
|
#include <boost/algorithm/string/case_conv.hpp> |
|
|
|
#include <boost/algorithm/string.hpp> |
|
|
|
#include <libdevcore/Base64.h> |
|
|
|
#include <libdevcrypto/SHA3.h> |
|
|
|
#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<bytes(Address, bytes)> const& _call, Address const& _reg) const |
|
|
|
pair<Address, bytes> ICAP::lookup(std::function<bytes(Address, bytes)> 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<string> ss; |
|
|
|
boost::algorithm::split(ss, s, boost::is_any_of("/")); |
|
|
|
Address r = _reg; |
|
|
|
for (unsigned i = 0; i < ss.size() - 1; ++i) |
|
|
|
r = abiOut<Address>(_call(r, abiIn("subRegistrar(bytes)", toString32(ss[i])))); |
|
|
|
return abiOut<Address>(_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"); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|