Browse Source

Draft of indirect ICAP algo.

cl-refactor
Gav Wood 10 years ago
parent
commit
6b7aa1773f
  1. 0
      libethcore/ABI.cpp
  2. 0
      libethcore/ABI.h
  3. 54
      libethcore/ICAP.cpp
  4. 4
      libethcore/ICAP.h
  5. 2
      libethereum/Client.h

0
libethereum/ABI.cpp → libethcore/ABI.cpp

0
libethereum/ABI.h → libethcore/ABI.h

54
libethcore/ICAP.cpp

@ -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");
}
}

4
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<bytes(Address, bytes)> const& _call, Address const& _reg) const { return m_type == Direct ? direct() : m_type == Indirect ? lookup(_call, _reg) : Address(); }
std::pair<Address, bytes> address(std::function<bytes(Address, bytes)> 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<bytes(Address, bytes)> const& _call, Address const& _reg) const;
std::pair<Address, bytes> lookup(std::function<bytes(Address, bytes)> const& _call, Address const& _reg) const;
private:
Type m_type = Invalid;

2
libethereum/Client.h

@ -35,12 +35,12 @@
#include <libdevcore/Guards.h>
#include <libdevcore/Worker.h>
#include <libethcore/Params.h>
#include <libethcore/ABI.h>
#include <libp2p/Common.h>
#include "CanonBlockChain.h"
#include "TransactionQueue.h"
#include "State.h"
#include "CommonNet.h"
#include "ABI.h"
#include "Farm.h"
#include "ClientBase.h"

Loading…
Cancel
Save